akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N; cin>>N;
long long b,c=0;
long long d=0;
long long a1=0;
long long a2=0;
long long a3=0;
long long b1,b2,b3;
long long c1=1;
long long c2=1;
long long c3=1;
long long c4=1;
set<long long> S;
long long a[5]={-1,-1,-1,-1,-1};
for(long long i=0;i<N;i++){
cin>>b;
if(!S.count(b))
{S.insert(b);
 if(b!=0){
 a[d]=b;
 d++;}}
else{
if(b==0){
c4++;}
else if(b==a[0])
c1++;
else if(b==a[1])
c2++;
else if(b==a[2])
c3++;}
if(S.size()==4){
c++;
break;}}
if(c==1){
cout<<"No"<<endl;}
else if(S.count(0)){
if(S.size()==1){
cout<<"Yes"<<endl;}
else if(S.size()==2){
if(c4*2-1==c1||c4*2==c1){
cout<<"Yes"<<endl;}
else{
cout<<"No"<<endl;}}}
else if(S.size()==3){
if(c1==c2&&c2==c3){
while(a[0]>0||a[1]>0){
                   if(a[0]%2!=a[1]%2){
                   a1+=pow(2,a2);
                   } 
                   a[0]/=2; a[1]/=2;
                   a2++;
                   }
a2=0;
while(a1>0||a[2]>0){
                   if(a1%2!=a[2]%2){
                   a3+=pow(2,a2);
                   } 
                   a1/=2; a[2]/=2;
                   a2++;
                   }
if(a3==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;}
else{
cout<<"No"<<endl;}}
else{
cout<<"No"<<endl;}}

Measured memory_bytes: 256
#include<stdio.h>
#define MATRIX_MAX 101
#define LOOP_RESET 0
#define MATRIX_RESET 0
#define RETURN 0

int main(){
	unsigned long ulW_D_inact[MATRIX_MAX][MATRIX_MAX];	/* 行列Ａの格納用配列 */
	unsigned long ulW_D_act[MATRIX_MAX][MATRIX_MAX];  	/* 行列Ｂの格納用配列 */
	unsigned long ulW_D_ans[MATRIX_MAX][MATRIX_MAX];  	/* 積の格納用変数 */
	unsigned short usW_D_row;                                          	/* 行数の格納用変数 */
	unsigned short usW_D_share;                                        	/*  */
	unsigned short usW_D_col;                                          	
	unsigned short usW_C_i, usW_C_j, usW_C_k;                                      	
	
	for(usW_C_i = LOOP_RESET;usW_C_i < MATRIX_MAX;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < MATRIX_MAX;usW_C_j++){
			ulW_D_inact[usW_C_i][usW_C_j] = MATRIX_RESET;
			ulW_D_act[usW_C_i][usW_C_j] = MATRIX_RESET;
			ulW_D_ans[usW_C_i][usW_C_j] = MATRIX_RESET;
		}
	}
	
	scanf("%d %d %d", &usW_D_row, &usW_D_share, &usW_D_col);
	
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_share;usW_C_j++){
			scanf("%ld", &ulW_D_inact[usW_C_i][usW_C_j]);
		}
	}
	
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_share;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col;usW_C_j++){
			scanf("%ld", &ulW_D_act[usW_C_i][usW_C_j]);
		}
	}
	

	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col;usW_C_j++){
			for(usW_C_k = LOOP_RESET;usW_C_k < MATRIX_MAX;usW_C_k++){
				ulW_D_ans[usW_C_i][usW_C_j] += ulW_D_inact[usW_C_i][usW_C_k] * ulW_D_act[usW_C_k][usW_C_j];
			}
		}
	}
	
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col - 1;usW_C_j++){
			printf("%ld ", ulW_D_ans[usW_C_i][usW_C_j]);
		}
		printf("%ld\n", ulW_D_ans[usW_C_i][usW_D_col - 1]);
	}
	
	return RETURN;
}




Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<int> a(n);
	vector<vector<pair<int, int>>> p(n);
	rep(i, n)
	{
		cin >> a[i];
		rep(j, a[i])
		{
			int x, y; cin >> x >> y;
			--x;
			p[i].push_back({ x,y });
		}
	}
	int cnt = 0;
	rep(i, pow(2, n))
	{
		vector<int> hy(n, 0);
		int tmp = 0;
		bool ok = true;
		rep(j, n)
		{
			if ((i >> j) & 1)
			{
				hy[j] = 1;
				++tmp;
			}
		}
		rep(j, n)
		{
			if (hy[j] == 0)continue;

			rep(k, a[j])
			{
				int x = p[j][k].first;
				int y = p[j][k].second;
				if (hy[x] != y)
				{
					ok = false;
					break;
				}
			}
		}
		if(ok)cnt = max(cnt, tmp);
	}
	cout << cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	vector< int > primes;
	
	vector< bool > isPrime(10000001, true);
	
	for_(i,2,10000001) {
		if (isPrime[i]) {
			primes.push_back(i);
			for (int j = 2 * i; j < 10000001; j += i) isPrime[j] = false;
		}
	}
	
	int n, m = primes.size();
	
	while (cin >> n, n) {
		int ans = 0;
		
		for_(i,3,m) {
			if (primes[i] > n) break;
			
			if (primes[i] - primes[i - 1] == 2 &&
				primes[i - 1] - primes[i - 2] == 4 &&
				primes[i - 2] - primes[i - 3] == 2) {
				ans = primes[i];
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 7340
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int gcd(int a,int b){
   if(a%b==0) return b;
   return gcd(b,a%b);
}

int main(void){
   int N;
   cin>>N;
   vector<long long> A(N);
   for(int i=0;i<N;i++){
      cin>>A[i];
   }
   int cnt=0;
   for(int i=0;i<N;i++){
      if(A[i]%2!=0) cnt++;
   }
   if(cnt%2==0) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
   return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

#define MAX_N 100000
int par[MAX_N];                                                                                                           
int rank[MAX_N];

void init(int n){
  for(int i = 0 ; i < n ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(rank[x] == rank[y]) par[x] = y;
  else par[y] =	x;
  if(rank[x] == rank[y]) rank[x]++;
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n,q;
  cin>>n>>q;
  init(n);
  int i,j;
  rep(i,q){
    int p,a,b;
    cin>>p>>a>>b;
    if(p)
      if(same(a,b))cout<<1<<endl;
      else cout<<0<<endl;
    else
      unite(a,b);
  }
}

Measured memory_bytes: 3272
/*ex3_2
ryo_1129*/
#include <stdio.h>

int main(void){
	int N,r; //変数宣言
	scanf("%d",&N); //入力
	r = N%10; // remainder
	
	//１の位が３の時、bonを出力
	if(r ==3){
		printf("bon\n");
	//１の位が0,1,6,8の時、ponを出力
	}else if(r == 0 || r == 1|| r == 6 || r == 8){
		printf("pon\n");
	//それ以外、honを出力
	}else{
		printf("hon\n");
	}
	
}

Measured memory_bytes: 1608
#include<iostream>
using namespace std;

int main() {
	int a, b, x, y, z, i;
	cin >> a >> b;

	for (i = 0; i <= a; i++) {
		x = i;
		y = a - x;
		z = 4 * x + 2 * y;

		if (b == z) {
			cout << "Yes";
			break;
		}
		else if (b != z && i == a) {
			cout << "No";
		}
	}

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 900000000000000004
signed main(void){
    int n;cin>>n;
    int A[n];
    vector<int>Count(60,0);
    rep(i,n){
        cin>>A[i];
        bitset<60>s(A[i]);
        rep(j,60){
            if(s.test(j))Count[j]++;
        }
    }
    int ans=0;
    int Pow[61];
    Pow[0]=1;
    rep(i,60)Pow[i+1]=(Pow[i]*2)%mod;
    rep(i,60){
        ans=(ans+Pow[i]*Count[i]%mod*(n-Count[i])%mod)%mod;
    }
    cout<<ans<<endl;
    
}
        


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int A, B, ans;
  char C;
  cin >> A >> C >> B;
  if (C == '+')
  {
    ans = A + B;
  }
  else
  {
    ans = A - B;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int n, m;
	cin >> n >> m;
	int sum = 0;
	vec(A)
	fx(n) {
		vecp(A);
		sum += A[x];
	}
	int ans = 0;
	fx(n) {
		if (A[x]*4*m>=sum) {
			ans++;
		}
	}

	if (ans>=m) {
		cey;
	}
	else {
		cen;
	}
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str,str1="s",str2="es";
  //for(int i=0;i<str.length();i++;)
  //{
    //begcin>>str[i];
  //}
  getline(cin,str);
  char ch= *str.rbegin();
  if(ch=='s')
  {
    cout<<(str+str2)<<endl;
  }
  else
  {
    cout<<(str+str1)<<endl;
  }
  return 0;
}
  
  


Measured memory_bytes: 3616
D = int(input())
c = list(map(int, input().split()))
S = []
for i in range(D):
    S.append(list(map(int, input().split())))

nocontest = [1 for i in range(26)]

for i in range(D):
    s = S[i]
    contest = [0 for j in range(26)]
    for j in range(26):
        contest[j] = c[j] * nocontest[j] * s[j]
    #print(contest)
    max_contest = max(contest)
    ans = contest.index(max_contest)
    print(ans + 1)
    
    for i in range(26):
        if i == ans:
            nocontest[i] = 1
        else:
            nocontest[i] += 1
    #print(nocontest)

Measured memory_bytes: 9504
#include <iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	string s;cin>>s;
	vector<int> a(s.size());
	for(int i=0;i<s.size();i++){
		a[i]=int(s[i])-48;
	}
	int pow=1;
	for(int i=0;i<s.size()-1;i++)pow*=2;
	long long ans=0;
	long long temp;
	for(int i=0;i<pow;i++){
		temp=a[0];
		int num=i;
		for(int j=0;j<s.size()-1;j++){

			if(num%2){
				ans+=temp;
//				cout<<i<<' '<<temp<<endl;
				temp=a[j+1];

			}else{
				temp*=10;
				temp+=a[j+1];
			}
			num/=2;
		}
		ans+=temp;
//		cout<<i<<' '<<temp<<endl;
	}
//	ans+=temp;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    string s;
    cin >> s;
    ll ans = 0;
    ll sum = 0;
    int n = (int)s.size();
    rep(i,n){
        if(s[i] == 'W'){
            ans += sum;
        }else{
            sum++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1156
#include<iostream>
#include<string>
using namespace std;


int main(){
  string str_T,str_H;
  int m,b;
  cin >> m;
  int T = 0;
  int H = 0;
  for(int i=0;i<m;i++){
    cin >> str_T;
    cin >> str_H;
    if(str_T.compare(str_H) > 0){
        T = T+3;
    }else if(str_T.compare(str_H) < 0){
        H = H+3;
    }else{
        T = T+1;
        H = H+1;
    }
  }
  cout << T<<" "<<H<< endl; 
}


Measured memory_bytes: 3140
from sys import stdin

readline = stdin.readline


def main():
    readline()
    A = tuple(map(int, readline().split()))
    B = tuple(map(int, readline().split()))
    pre = A[0]
    ans = 0
    for a, b in zip(A[1:], B):
        tmp1 = pre if pre < b else b
        b -= tmp1
        tmp2 = a if a < b else b
        ans += tmp1 + tmp2
        pre = a - tmp2
    print(ans)
    return


main()


Measured memory_bytes: 19228
H,N = map(int,input().split())
magic = [list(map(int,input().split())) for i in range(N)]

INF = 10**10
#print(magic)

AM = 0
for i in range(N):
    AM = max(AM,magic[i][0])
#print(AM)


dp = [INF for i in range(H+AM+1)]
dp[0] = 0

for i in range(1,H+AM+1):
    for j in range(N):
        if magic[j][0] > i:
            dp[i] = min(dp[i],magic[j][1])
        else:
            dp[i] = min(dp[i-magic[j][0]]+magic[j][1],dp[i])
ans = INF
print(dp[H])


Measured memory_bytes: 42988
#include <bits/stdc++.h>
using namespace std;

char toupper(char c)
{
  return (c - 0x20);
}

int main()
{
  vector<string> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  
  string str;
  for(int i = 0; i < 3; i++)
  {
    str += toupper(vec.at(i).at(0));
  }
  
  cout << str << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
//#include <vector>
//#include <functional>
template<typename Abel>
struct WeightedUnionFind {
    using OP = function<Abel(Abel, Abel)>;

    vector<int> parent;
    vector<Abel> diff_weight; // distance from root
    const OP add;
    const OP sub;
    const Abel e;
    
    WeightedUnionFind(int nmemb,
                      const Abel &e = 0,
                      const OP &add = [](Abel x, Abel y){return x+y;},
                      const OP &sub = [](Abel x, Abel y){return x-y;}):
        e(e), add(add), sub(sub)
    {
        parent.assign(nmemb, -1);
        diff_weight.assign(nmemb, e);
    };

    int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        
        int p = root(parent[x]);
        diff_weight[x] = add(diff_weight[x], diff_weight[parent[x]]);
        parent[x] = p;

        return p;
    };

    bool unite(int x, int y, Abel w) {
        Abel wx = weight(x);
        Abel wy = weight(y);
        x = root(x);
        y = root(y);

        if (x == y) return false;
        w = sub(add(w, wx), wy);
        if (size(x) < size(y)) swap(x, y), w = -w;

        parent[x] += parent[y];
        parent[y] = x;
        diff_weight[y] = w;
        
        return true;
    };
    
    bool same(int x, int y) {
        return root(x) == root(y);
    };
    
    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    };

    Abel diff(int x, int y) {
        return sub(weight(y), weight(x));
    };

    int size(int x) {
        return -parent[root(x)];
    };
};
//===

llong n, m;
llong l, r, d;
WeightedUnionFind<llong> uf(100005);

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d;

        if (uf.same(l, r)) {
            if (uf.diff(l, r) != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.unite(l, r, d);
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <string.h>
using namespace std;

#define NMAX 100001

pair <long long, int> distances[NMAX];
long long v[NMAX], dist[NMAX];
int bij[NMAX], par[NMAX], cnt[NMAX];
vector <int> sons[NMAX];
map <long long, int> idx;

void dfs1(int nod) {
    cnt[nod] = 1;
    dist[nod] = 0LL;
    for (const int x : sons[nod]) {
        dfs1(x);
        dist[nod] = 0LL + dist[nod] + dist[x] + (long long)cnt[x];
        cnt[nod] += cnt[x];
    }
}

void dfs2(int nod, long long sump, int cntp) {
    dist[nod] = 0LL + dist[nod] + sump + (long long)cntp;
    cntp += cnt[nod];
    for (const int x : sons[nod]) {
        dfs2(x,  dist[nod] - (dist[x] + (long long)cnt[x]), cntp - cnt[x]);
    }
}

bool solve(const int n) {
    for (int i = 1; i <= n; i++) {
        idx[v[i]] = i;
    }
    for (int i = n; i >= 2; i--) {
        idx.erase(idx.find(v[i]));
        cnt[i]++;
        for (const int son : sons[i]) {
            cnt[i] += cnt[son];
        }
        long long dp = v[i] + 2LL * cnt[i] - (long long)n;
        if (idx.find(dp) == idx.end()) {
            return false;
        }
        int p = idx[dp];
        sons[p].push_back(i);
        par[i] = p;
    }

    memset(cnt, 0, sizeof(cnt));
    dfs1(1);
    dfs2(1, 0LL, 0);

    for (int i = 1; i <= n; i++)
        if (dist[i] != v[i])
            return false;
    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    // ifstream cin("code.in");
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> distances[i].first;
        distances[i].second = i;
    }
    sort(distances + 1, distances + n + 1);

    for (int i = 1; i <= n; i++) {
        v[i] = distances[i].first;
        bij[i] = distances[i].second;
    }

    if (!solve(n)) {
        cout << "-1\n";
        return 0;
    }

    for (int i = 2; i <= n; i++) {
        cout << bij[par[i]] << " " << bij[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i,n) for(int i = 0; i<n; ++i)
#define ff(i,n) for(int i = 1; i<n; ++i)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;

const int N = 1050;
string s[N];
string a[3];
string b[3];
int n,m;

bool check(int i,int j)
{
    if(i + 1 >= n || j + 1 >= m ) return 0;
    for(int x=0; x<2; ++x) for(int y=0; y<2; ++y) if(a[x][y] != s[i+x][j+y]) return false;
    return true;
}

int work(int x,int y,int su , char k)
{
    char h = s[x][y];
    int u = 0;
    for(int i=max(0,x-1);i<=min(n-1,x); ++i)
    for(int j=max(0,y-1);j<=min(m-1,y); ++j)
    {
        if(check(i,j)) u--;
    }
    s[x][y] = k;
    for(int i=max(0,x-1);i<=min(n-1,x); ++i)
    for(int j=max(0,y-1);j<=min(m-1,y); ++j)
    {
        if(check(i,j)) u++;
    }
    s[x][y] = h;
    return su + u;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int ans = 0; cin >> n >> m;
    for(int x=0; x<n; ++x) cin >> s[x];
    for(int x=0; x<2; ++x) cin >> a[x];
    for(int x=0; x<n; ++x) for(int y=0; y<m; ++y)
    {
        if(x + 1 >= n || y + 1 >= m) continue;
        if(check(x,y)) { ans++; }
    }
    int res = ans;
    for(int x=0; x<n; ++x) for(int y=0; y<m; ++y)
    {
        if(s[x][y] != 'O') res = max( res , work(x,y,ans,'O'));
        if(s[x][y] != 'I') res = max( res , work(x,y,ans,'I'));
        if(s[x][y] != 'J') res = max( res , work(x,y,ans,'J'));
    }
    cout << res << endl;
}

Measured memory_bytes: 2268
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    t = input()
    double = t + t
    print('Yes') if s in double else print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, x;
    cin >> k >> x;
    int i = 1;
    int low = max(x-k+1,-1000000);
    int high = min(x+k-1, 1000000);
    //cout << low << " " << high << "\n";
    while(low <= high){
        cout << low << " ";
        low++;
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

int main() {
    string s; cin>>s;
    if((s.front()==s.back())^(s.length()%2==1)){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

 ll n,c=0,mx=0; cin>>n;
 for(int i=0;i<n;i++)
 {
     ll a[n],b[n];
     cin>>a[i]>>b[i];
     if(a[i]==b[i])
     {
         c++;
     }
     else
     {
         c=0;
     }
    mx=max(mx,c);
     //cout<<mx<<endl;
 }

 if(mx>=3)
cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
 }

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/

string get_underscore(string inp)
{
	if (inp.find("_") != string::npos)
	{
		return inp;
	}
	
	if (inp[0] < 'a') inp[0] += 32;
	string ret = "";
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] < 'a')
		{
			char c = inp[i] + 32;
			ret = ret + "_" + c;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string upper_camel_case(string inp)
{
	char c = inp[0] - 32;
	string ret = "";
	
	ret += c;
	
	for (int i=1; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string lower_camel_case(string inp)
{
	string ret = "";
	
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

int main()
{
	string name;
	char type;
	
	while (cin >> name >> type)
	{
		if (type == 'X') break;
		
		name = get_underscore(name);
		
		switch (type)
		{
		case 'U':
			cout << upper_camel_case(name) << endl;
			break;
		case 'L':
			cout << lower_camel_case(name) << endl;
			break;
		case 'D':
			cout << name << endl;
			break;
		}
	}
	
	//cout << upper_camel_case("get_user_name") << endl;
	
	return 0;
}

Measured memory_bytes: 1200
use proconio::input;

fn main() {
    input! {
        n: usize,
        t_l: i64,
        t: [i64; n],
    };
    let mut s = 0;
    for (t_i0, t_i1) in t.windows(2).map(|w| match w {
        &[t_i0, t_i1] => (t_i0, t_i1),
        _ => unreachable!(),
    }) {
        s += std::cmp::min(t_l, t_i1 - t_i0);
    }
    s += t_l;
    let ans = s;
    println!("{}", ans);
}


Measured memory_bytes: 5416
//by Judge
#define HGS_AK_IOI true
#include<cstdio>
#include<cstring>
#include<iostream>
#define Rg register
#define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(Rg int i=head[u],v=e[i].to;i;v=e[i=e[i].nxt].to)
#define open(S) freopen(S".in","r",stdin),freopen(S".out","w",stdout)
#define ll long long
using namespace std;
const int M=2e5+3;
typedef int arr[M];
#ifndef Judge
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#endif
char buf[1<<21],*p1=buf,*p2=buf;
template<class T>inline T Min(T x,T y){return x<y?x:y;}
template<class T>inline T Max(T x,T y){return x>y?x:y;}
template<class T>inline bool cmax(T& a,T b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T& a,T b){return a>b?a=b,1:0;}
inline int read(){ int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
} char sr[1<<21],z[20];int CCF=-1,Z;
inline void Ot(){fwrite(sr,1,CCF+1,stdout),CCF=-1;}
inline void print(int x,char chr='\n'){
	if(CCF>1<<20)Ot();if(x<0)sr[++CCF]=45,x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++CCF]=z[Z],--Z);sr[++CCF]=chr;
} int n,x; arr a,usd;
int main(){ n=read(),x=read();
	if(x>2*(n-1)||x==1) return !printf("No\n");
	else printf("Yes\n");
	if(n>2){ usd[x-1]=usd[x]=usd[x+1]=usd[x-2]=1;
		a[n-1]=x-1,a[n]=x,a[n+1]=x+1,a[n+2]=x-2;
	} else{ usd[x+1]=usd[x]=usd[x-1]=usd[x+2]=1;
		a[n-1]=x+1,a[n]=x,a[n+1]=x-1,a[n+2]=x+2;
	}
	Rg int j=1;
	fp(i,1,n*2-1){
		if(!a[i]){
			while(usd[j]) ++j;
			usd[j]=1,a[i]=j;
		} print(a[i]);
	} return Ot(),0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;
void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main() {
	int A[MAX], n, i;
	cnt = 0;
	cin >> n;
	for (i = 0; i < n; i++) cin >> A[i];
	mergeSort(A, n, 0, n);
	for (i = 0; i < n; i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 6900
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();

    sc.close();

    double ans = 1;

    if (N != 1) {
      int count = N / 2;
      ans = (double) (N - count) / N;
    }
    
    System.out.println(ans);
    
  }

}

Measured memory_bytes: 23124
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << min(a, b) + min(c, d) << endl;

	return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String[] S = sc.next().split(",");

            double[][] point = new double[4][2];
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 2; j++) {
                    point[i][j] = Double.parseDouble(S[i*2+j]);
                }
            }

            int r = 0;
            for (int i = 0; i < 4; i++) {
                if(((point[(i + 1) % 4][0] - point[i][0]) * (point[(i + 2) % 4][1] - point[(i + 1) % 4][1]) -
                        (point[(i + 1) % 4][1] - point[i][1]) * (point[(i + 2) % 4][0] - point[(i + 1) % 4][0])) > 0) {
                    r += 1;
                } else {
                    r -= 1;
                }
            }

            System.out.println((Math.abs(r) == 4)? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 26120
#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        vector<int>V(n);
        REP(i,n)cin>>V[i];
        sort(ALL(V));
        int mi=1e9;
        REP(i,n-1)mi=min(mi,V[i+1]-V[i]);
        cout<<mi<<endl;
    }
}

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#include <random>
std::random_device seed_gen;
std::mt19937_64 engine(seed_gen());
// ull a = engine();
ll D;
vll now, c(26);
vvl s;
vector<set<ll>> st(26);
ll now_score = 0;

void init(ll d){
  D = d;
  now.resize(d, 0);
  s = VV(d, 26, 0, ll);
}
void make_set(vll t){
  for(int i=0;i<D;i++) st[t[i]].insert(i);
  for(int i=0;i<26;i++) st[i].insert(-1);
  for(int i=0;i<26;i++) st[i].insert(D);
}
ll calc(vll t){
  ll score = 0;
  vll cnt(26, 0);
  for(int i=0;i<D;i++){
    ll idx = t[i];
    for(int j=0;j<26;j++){
      if(j==idx) cnt[j] = 0;
      else{
        cnt[j]++;
        score -= cnt[j]*c[j];
      }
    }
    score += s[i][idx];
  }
  return score;
}

ll ch_score(ll day, ll after){
  ll score = now_score;
  ll prev = now[day];//前に選択していたもの
  if(prev==after) return score;

  //prevを消したことで減るスコア
  score -= s[day][prev];

  auto itr = st[prev].find(day);
  auto p = itr, q = itr;
  ll x = day - (*--p) - 1;
  ll y = (*++q) - day - 1;

  ll z = x + y + 1;
  //x, y分増え、z分減る
  score += c[prev]*((x*(x+1))/2 + (y*(y+1))/2);
  score -= c[prev]*((z*(z+1))/2);
  //afterを挿入した事で増えるスコア
  score += s[day][after];
  itr = st[after].upper_bound(day);
  p = itr;
  p--;

  z = (*itr) - (*p) - 1;
  x = day - (*p) - 1;
  y = (*itr) - day - 1;

  score += c[after]*(z*(z+1)/2);
  score -= c[after]*((x*(x+1))/2 + (y*(y+1))/2);
  return score;
}

void change(ll day, ll after){
  ll prev = now[day];
  st[prev].erase(day);
  st[after].insert(day);
  now[day] = after;
  now_score = ch_score(day, after);
}
int main(int argc, char const *argv[]) {
  ll d;scanf("%lld", &d);
  init(d);
  re(i, 26) scanf("%lld", &c[i]);
  re(i, D) re(j, 26) scanf("%lld", &s[i][j]);
  //初期値
  re(i, D) now[i] = i%26;
  //初期化
  make_set(now);
  now_score = calc(now);
  //関数:
  // change(day, after) dayをafterに変更
  // ch_score(day, after) dayをafterに変更した場合の試算
  // 共に計算量10~20くらい
  // シミュレート回数10^7
  ll sim = 20000000;
  while(--sim){
    unsigned long long a = engine();
    unsigned long long b = engine();
    a %= D, b %= 26;
    if(now_score < ch_score(a, b)){
      change(a, b);
    }
  }
  for(int i=0;i<D;i++) std::cout << now[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3380
n, k = map(int, input().split())

mod_num = 10**9 + 7
first = [i for i in range(n+1)]
last = [i for i in range(n, -1, -1)]
for i in range(1, n+1):
    first[i] += first[i-1]
    last[i] += last[i-1]

result = 0
for i in range(k-1, n+1):
    result += (last[i] - first[i] + 1)
print(result%mod_num)


Measured memory_bytes: 94460
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(){}
  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  //区間[a, b)の値を返す
  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

signed main(){

  int n; cin >> n;
  string s; cin >> s;
  int Q; cin >> Q;
  SegmentTree<int> seg[26];
  for(int i = 0; i < 26; i++){
    seg[i] = SegmentTree<int>(vector<int>(n, 0), 0, [&](int x, int y){ return (x + y); });
  }
  for(int i = 0; i < s.size(); i++){
    seg[s[i] - 'a'].update(i, 1);
  }
  for(int i = 0; i < Q; i++){
    int t; cin >> t;
    if(t == 1){
      int q; cin >> q;
      q--;
      char c; cin >> c;
      seg[s[q] - 'a'].update(q, 0);
      seg[c - 'a'].update(q, 1);
      s[q] = c;
    }else{
      int l, r; cin >> l >> r;
      int ans = 0;
      for(int j = 0; j < 26; j++){
        ans += seg[j].getval(l-1, r) > 0;
      }
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 217920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
    string N;
    cin >> N;

    ll sum = 0;
    REP(i, N.length()) {
        sum += ctoi(N[i]);
    }

    if(sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

// 文字列s内に文字列tがいくつ含まれるか
int count(string s, string t) {
  int size_s = s.size();
  int size_t = t.size();
  if (size_s < size_t) return 0;
  int ret = 0;
  for (int i = 0; i < size_s - size_t + 1; i++) {
    if (s.substr(i, size_t) == t) ret++;
  }
  return ret;
}

void solve() {
  string s; cin >> s;
  int s_len = s.size();
  int c0 = count(s, "0");
  int c1 = s_len - c0;
  outl(min(c0, c1) * 2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
K=int(input())

def solve(K):
    f=0
    from collections import defaultdict
    if K==1:
        return 1
    elif K%2==0 or K%5==0:
        return -1
    
    if K%7==0:
        if K==7:
            return 1
        else:
            f=1
            K=K//7

    app = defaultdict(lambda: False)
    broken=False
    for n in range(1,K+1):
        if n==1:
            if f==1:
                amari = 1
            else:
                amari = 7%K
        else:
            if f==1:
                amari = (amari + pow(10,n-1,K) )%K
            else:
                amari = (amari + 7*pow(10,n-1,K) )%K
        #print(n,amari)
        if amari==0:
            broken=True
            break
        if app[amari]:
            broken=True
            break
        else:
            app[amari]=True
    if broken:
        return n
    else:
        return -1
    

print(solve(K))

Measured memory_bytes: 160352
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N;
	scanf("%d", &N);

	ll dp[2][3];
	dp[0][0] = 0;
	dp[0][1] = -1e18;
	dp[0][2] = -1e18;
	dp[1][0] = -1e18;
	dp[1][1] = -1e18;
	dp[1][2] = -1e18;
	int x = 0;
	int y = 1;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a, b;
			scanf("%d %d", &a, &b);
			chmax(dp[1][1], dp[0][0]);
			dp[0][0] += a;
			dp[0][2] += a;
			chmax(dp[0][2], dp[1][1]);
			dp[1][1] += b;
		}
		int a;
		scanf("%d", &a);
		chmax(dp[1][1], dp[0][0]);
		dp[0][2] += a;
		printf("%lld\n", max(dp[0][2], dp[1][1]));
	}
	else {
		rep(i, n) {
			int a, b;
			scanf("%d %d", &a, &b);
			chmax(dp[1][1], dp[0][0]);
			dp[0][0] += a;
			dp[1][1] += b;
		}
		printf("%lld\n", max(dp[1][1], dp[0][0]));
	}


	Would you please return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, K;
	cin >> N >> K;
	vb ans(N, false);
	rep(i, K) {
		int d;
		cin >> d;
		rep(j, d) {
			int A;
			cin >> A;
			ans[A - 1] = 1;
		}
	}
	int n = 0;
	rep(i, N) {
		if (!ans[i])
			n++;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3600
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        final int[][][] house = new int[4][3][10];
        final int n = Integer.parseInt(sc.next());
        for(int i = 0; i<n; i++){
            final int b = Integer.parseInt(sc.next());
            final int f = Integer.parseInt(sc.next());
            final int r = Integer.parseInt(sc.next());
            final int v = Integer.parseInt(sc.next());
            house[b-1][f-1][r-1] += v;
        }
        for(int i = 0; i<4; i++){
            if(i!=0) out.println("####################");
            for(int j = 0; j<3; j++){
                for(int k = 0; k<10; k++){
                    out.print(' ');
                    out.print(house[i][j][k]);
                }
                out.println();
            }
        }
        out.flush();
    }
}

Measured memory_bytes: 28660
#include <iostream>

int main()
{
	int N;
	std::cin >> N;
	char* stone = new char[N];
	for (int i=0; i<N; i++) std::cin >> stone[i];
	int left = 0;
	int right = N-1;
	int cnt = 0;
	while (left < right) {
		while (stone[left] == 'R') {left++;}
		while (stone[right] == 'W') {right--;}
		if (left >= right) break;
		cnt++; left++; right--;
	}
	std::cout << cnt << std::endl;
	delete[] stone;
	return 0;
}


Measured memory_bytes: 3484
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		char[] cs=sc.next().toCharArray();
		boolean ans=true;
		for(int i=0;i+1<cs.length;++i) {
			ans&=cs[i]!=cs[i+1];
		}
		pw.println(ans?"Good":"Bad");
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main(){
	int N,M,X,Y;
	int max=-101,min=101;
	int inX,inY;
	cin>>N>>M>>X>>Y;
	for(int x=0;x<N;x++){
		cin>>inX;
		if(max<inX)max=inX;
	}
	for(int y=0;y<M;y++){
		cin>>inY;
		if(min>inY)min=inY;
	}
	for(int i=X+1;i<=Y;i++){
		if(X<i&&i<=Y&&max<i&&min>=i){
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    string Sa,Sb,Sc;
    cin >> Sa >> Sb >> Sc;
    queue<char> qa,qb,qc;
    REP(i,0,Sa.size()){
        qa.push(Sa[i]);
    }
    REP(i,0,Sb.size()){
        qb.push(Sb[i]);
    }
    REP(i,0,Sc.size()){
        qc.push(Sc[i]);
    }

    char now=qa.front();
    qa.pop();
    while(1){
        switch (now)
        {
            case 'a':
                if(qa.empty()){
                    P('A');
                    return 0;
                }
                now=qa.front();
                qa.pop();
                break;
            case 'b':
                if(qb.empty()){
                    P('B');
                    return 0;
                }
                now=qb.front();
                qb.pop();
                break;
            case 'c':
                if(qc.empty()){
                    P('C');
                    return 0;
                }
                now=qc.front();
                qc.pop();
                break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    vector<int> num(3);
    int k;
    
    cin >> num[0] >> num[1] >> num[2];
    cin >> k;
    
    sort(num.begin(), num.end());
    
    cout << num[0] + num[1] + num[2] * pow(2, k) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>)
{
    val sc=Scanner(System.`in`)
    var a=sc.nextInt();
    if(a>=1800 && a<=1999){
        print("1")
    }
    if(a>=1600 && a<=1799){
        print("2")
    }
    if(a>=1400 && a<=1599){
        print("3")
    }
    if(a>=1200 && a<=1399){
        print("4")
    }
    if(a>=1000 && a<=1199){
        print("5")
    }
    if(a>=800 && a<=999){
        print("6")
    }
    if(a>=600 && a<=799){
        print("7")
    }
    if(a>=400 && a<=599){
        print("8")
    }

}

Measured memory_bytes: 36432