akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define m 1000000007
int main(){
	int n  , k ;
	cin >> n >> k ;
	int arr[n + 1] ;
	for(int i = 1 ; i <= n ; i++)
		cin >> arr[i] ;
	ll dp[n + 1][k + 1] ;
	ll ps[ n + 1][k + 1] ;
	memset(dp , 0 , sizeof(dp)) ;
	memset(ps , 0 , sizeof(ps)) ;
	for(int i = 0 ; i <= k ; i++){
		if(i <= arr[1]){
			dp[1][i] = 1 ;
			// cout << dp[1][i] << " ";
		}
		ps[1][0] = 1 ;
		if(i > 0){
			ps[1][i] += dp[1][i] + ps[1][i - 1] ;
			ps[1][i] %= m ;
		}
		// cout << ps[1][i] << " ";
		
		// cout << dp[1][i] << " " <<ps[1][i - 1] << " " << ps[1][i] << "\n" ;}
	}
	// cout << '\n' ;
	for(int i = 2 ; i <= n ; i++){
		for(int j = 0 ; j <= k ; j++){
			// if(j == 0){
			// 	dp[i][j] = dp[i - 1][j] ;
			// 	// cout << dp[i][j] << " " ;
			// 	continue ;
			// }
			ll ans =  0 ; 
			if(j - arr[i] - 1 >= 0){
				ans = ps[i - 1][j - arr[i] - 1]%m ;
			}
			dp[i][j] = (ps[i - 1][j] - ans + m)%m;
			// dp[i][j] = ps[i - 1][j] ;
			// cout << dp[i][j] << " ";
		}
		for(int j = 0 ; j <= k ; j++){
			if(j == 0){
				ps[i][j] = dp[i][j]%m ;
				// cout << ps[i][j] << " " ;
				continue ;
			}
			ps[i][j] += (ps[i][j - 1]%m + dp[i][j]%m) ;
			ps[i][j] %= m ;
			// cout << ps[i][j] << " " ;
		}
		// cout << '\n' ;
	}
	
	cout << dp[n][k] ;
}

Measured memory_bytes: 158080
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;

int main() {
    int n, m;
    cin >> n >> m;
    P nums[m];
    rep(i, m) cin >> nums[i].first >> nums[i].second;
    int min = 1;
    if (n == 1) {
        min = 0;
    } else {
        rep(i, n - 1) min = min * 10;
    }
    int max = 1;
    rep(i, n) max = max * 10;
    auto c = [&](int num) {
        rep(i, m) {
            int t = num;
            int a = 1;
            int d = (n - nums[i].first);
            rep(j, d) a = a * 10;
            t = t / a;
            t = t % 10;
            if (t != nums[i].second) {
                return false;
            }
        }
        return true;
    };
    int ans = -1;
    for (int i = min; i < max; i++) {
        if (c(i)) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 500001

typedef struct cell{
 int id;
 struct cell *right;
 struct cell *left;
}cell;


void preorder(cell *root){
cell *p=root;
printf(" %d",p->id);

if(p->left!=NULL){preorder(p->left);}
if(p->right!=NULL){preorder(p->right);}

return;
}

void inorder(cell *root){
cell *p=root;
if(p->left!=NULL){inorder(p->left);}
printf(" %d",p->id);
if(p->right!=NULL){inorder(p->right);}

return;
}


cell* makecell(int x){
cell *new=malloc(sizeof(cell));
new->id=x;
new->left=NULL;
new->right=NULL;

return new;
}

void insert(cell **p,cell *new){

cell *temp;

if((*p)==NULL){(*p)=new;return;}
else{

 if( (*p)->left==NULL && (*p)->right==NULL ){/*子なし*/
   if((*p)->id < new->id){
     (*p)->right=new;return;}
   else{
     (*p)->left=new;return;}
  }
  else if((*p)->left==NULL&&(*p)->right!=NULL){/*左なし右あり*/
   if( (*p)->id > new->id ){
     (*p)->left=new;return;}
   else{insert(&((*p)->right),new);}
  }
  else if((*p)->left!=NULL&&(*p)->right==NULL){/*左あり右なし*/
   if( (*p)->id < new->id){
     (*p)->right=new;return;}
   else{insert(&((*p)->left),new);}
  }
  else{/*どっちも子あり*/
   if((*p)->id < new->id){
     insert(&((*p)->right),new);
   }
   else{insert(&((*p)->left),new);}
 }
}

return;
}
     


int find(cell *root,int x){
cell *p=root;

while(p!=NULL){
 if(p->id==x){return 1;}
 else if(p->id <x){p=p->right;}
 else{p=p->left;}
}

return 2;
}







int main(){
int n,i,x,j,k;
char com[7];
cell *root=NULL;
cell *new;
int F[MAX]={0};

scanf("%d",&n);


for(i=0;i<n;i++){
 scanf("%s",com);

 switch(com[0]){
  case 'i':scanf("%d",&x);
           new=makecell(x);
           insert(&root,new);
           break;

  case 'p':inorder(root);
           printf("\n");
           preorder(root);
           printf("\n");
           break;

  case 'f':scanf("%d",&x);
           F[i]=find(root,x);
           if(F[i]==1){printf("yes\n");}
 else if(F[i]==2){printf("no\n");}
 }/*switch end*/

}/*for end*/




return 0;
}


Measured memory_bytes: 14228
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,arr[105],i,count=0,sum=0;
 double a;
cin>>n;
cin>>m;
for(i=0;i<n;i++){
cin>>arr[i];}
for(i=0;i<n;i++){
sum=sum+arr[i];}
a=sum/(4.0*m);
for(i=0;i<n;i++){
if(arr[i]>=a){
count++;}}
if(count>=m){
cout<<"Yes"<<endl;}
else{
cout<<"No"<<endl;}}

Measured memory_bytes: 256
tak_hp, tak_atk, aoki_hp, aoki_atk = readline.split(" ").map { |x| x.to_i }

def fight(tak_hp, tak_atk, aoki_hp, aoki_atk)
  max_round = [ tak_hp / aoki_atk, aoki_hp / tak_atk ].min + 1
  for i in 1..max_round
    aoki_hp -= tak_atk
    return "Yes" if aoki_hp <= 0

    tak_hp -= aoki_atk
    return "No" if tak_hp <= 0
  end
end
puts fight(tak_hp, tak_atk, aoki_hp, aoki_atk)

Measured memory_bytes: 14376
a,b,c=map(int,input().split())
list=a,b,c

if int(list[0])>int(list[1]):
    list=[list[1],list[0],list[2]]
if int(list[1])>int(list[2]):
    list=[list[0],list[2],list[1]]
if int(list[0])>int(list[1]):
    list=[list[1],list[0],list[2]]

a,b,c=list

print(a,b,c)


Measured memory_bytes: 5600
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int N,M;
	cin>>N>>M;
	bool isPossible = true;
	int *numArray = new int[N];
	for(int i = 0; i < N; i++){
		numArray[i] = -1;
	}
	for(int i =0;i < M; i++){
		int si,ci;
		cin>>si>>ci;
		if(numArray[si-1] == -1 || numArray[si-1] == ci){
			numArray[si-1] = ci;
		}else{
			isPossible = false;
		}
	}

	if( N!=1 && numArray[0] == -1){
		numArray[0] = 1;
	}else if(numArray[0] == -1){
		numArray[0] = 0;
	}
	for(int i = 1; i < N; i++){
		if(numArray[i] == -1) numArray[i] = 0;
	}
	if( isPossible == false || (N > 1 && numArray[0] == 0)){
		cout<<-1<<endl;
	}else{
		for(int i = 0; i < N; i++){
			cout<<numArray[i];
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change)


if __name__ == "__main__":
    N = input()
    a = map(int, raw_input().split())
    result, change = bubble_sort(a, N)
    print ' '.join(map(str, result))
    print change

Measured memory_bytes: 6416
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    T = ''
    for s in S:
        T = T + chr((ord(s) + N - ord('A')) % 26 + ord('A'))
    print(T)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

void solve(int N, vector<int> A, int x, int y) {
  for (auto a : A) {
    if (a == x) {
      printf("%d\n", y);
    } else {
      printf("%d\n", x);
    }
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = a;
    B[i] = a;
  }
  sort(B.begin(), B.end());
  int x = B[N - 1];
  int y = B[N - 2];
  solve(N, A, x, y);
  return 0;
}


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

int NEGMIN = -101;
int POSMAX = 101;

void solver() {
  int x, n;
  cin >> x >> n;
  vector<bool> posps(101);
  vector<bool> negps(101);

  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    if (p < 0) {
      negps[-p] = true;
    } else {
      posps[p] = true;
    }
  }

  int offset = 0;
  while(true) {
    int negIdx = x - offset;
    int posIdx = x + offset;
    if (negIdx >= NEGMIN) {
      int idx;
      if (negIdx < 0) {
        idx = -negIdx;
        if (!negps[idx]) {
          cout << negIdx << "\n";
          return;
        }
      } else {
        idx = negIdx;
        if (!posps[idx]) {
          cout << negIdx << "\n";
          return;
        }
      }
    }

    if (posIdx <= POSMAX) {
      int idx;
      if (posIdx < 0) {
        idx = -posIdx;
        if (!negps[idx]) {
          cout << posIdx << "\n";
          return;
        }
      } else {
        idx = posIdx;
        if (!posps[idx]) {
          cout << posIdx << "\n";
          return;
        }
      }
    }

    offset++;
  }
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, m;
vector<int> G[2005];
int par[2005], dep[2005];
int eu[2005], ev[2005];
int eid[2005][2005];
bool hv[2005][2005];
int qu[2005], qv[2005];
int cnt[2005], xv[2005];

void dfs(int v, int p, int d)
{
	par[v] = p;
	dep[v] = d;
	rep(i, G[v].size()) {
		int u = G[v][i];
		if(u == p) continue;
		dfs(u, v, d + 1);
	}
}

bool vis[2005], dir[2005];
void dfs2(int cur)
{
	vis[cur] = true;
	int u = qu[cur], v = qv[cur];
	while(u != v) {
		if(dep[u] > dep[v]) {
			cnt[eid[u][par[u]]] --;
			xv[eid[u][par[u]]] ^= eu[eid[u][par[u]]] == u ? cur : ~cur;
			if(dir[cur]) hv[par[u]][u] = true; else hv[u][par[u]] = true;
			u = par[u];
		} else {
			cnt[eid[v][par[v]]] --;
			xv[eid[v][par[v]]] ^= eu[eid[v][par[v]]] == v ? ~cur : cur;
			if(dir[cur]) hv[v][par[v]] = true; else hv[par[v]][v] = true;
			v = par[v];
		}
	}
	u = qu[cur]; v = qv[cur];
	while(u != v) {
		if(dep[u] > dep[v]) {
			if(cnt[eid[u][par[u]]] == 1) {
				int nc = xv[eid[u][par[u]]];
				if(nc < 0) nc = ~nc;
				if(!hv[u][par[u]] || !hv[par[u]][u]) {
					dir[nc] = dir[cur] ^ 1 ^ (xv[eid[u][par[u]]] < 0) ^ eu[eid[u][par[u]]] != u;
					dfs2(nc);
				}
			}
			u = par[u];
		} else {
			if(cnt[eid[v][par[v]]] == 1) {
				int nc = xv[eid[v][par[v]]];
				if(nc < 0) nc = ~nc;
				if(!hv[v][par[v]] || !hv[par[v]][v]) {
					dir[nc] = dir[cur] ^ 1 ^ (xv[eid[v][par[v]]] < 0) ^ eu[eid[v][par[v]]] == v;
					dfs2(nc);
				}
			}
			v = par[v];
		}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	rep(i, n - 1) {
		scanf("%d%d", &eu[i], &ev[i]);
		G[eu[i]].push_back(ev[i]);
		G[ev[i]].push_back(eu[i]);
		eid[eu[i]][ev[i]] = eid[ev[i]][eu[i]] = i;
	}
	rep(i, m) scanf("%d%d", &qu[i], &qv[i]);
	dfs(1, -1, 0);
	
	rep(i, m) {
		int u = qu[i], v = qv[i];
		while(u != v) {
			if(dep[u] > dep[v]) {
				cnt[eid[u][par[u]]] ++;
				xv[eid[u][par[u]]] ^= eu[eid[u][par[u]]] == u ? i : ~i;
				u = par[u];
			} else {
				cnt[eid[v][par[v]]] ++;
				xv[eid[v][par[v]]] ^= eu[eid[v][par[v]]] == v ? ~i : i;
				v = par[v];
			}
		}
	}
	
	int ans = 0;
	rep(i, n - 1) ans += min(cnt[i], 2);
	printf("%d\n", ans);
	rep(i, m) if(!vis[i]) dfs2(i);
	rep(i, m) {
		if(dir[i]) swap(qu[i], qv[i]);
		printf("%d %d\n", qu[i], qv[i]);
	}
	return 0;
}

Measured memory_bytes: 19712
i = input()

flag = i[2:-1].count("C")

if i[0] is not "A":
    flag = 0

import re
if re.findall("A[a-z][a-z,C]{"+str(len(i)-3)+"}[a-z]",i) and (flag == 1):
    print("AC")

else:
    print("WA")


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;


int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll bottle_neck = min(a,min(b,min(c,min(d,e))));
  if(n<=bottle_neck)cout<<5<<endl;
  else cout<<(n-1)/bottle_neck+5<<endl;
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;

const int INF = 10000000;
int dp[101][101];//dp[i][j]?????§??????????????¢???

int DP(int x,int y){//x,y????????????????????¢????????????
	if(x <= 0 || y <= 0)return 0;
	if(dp[x][y] == INF)return 0;
	if(dp[x][y] != 0)return dp[x][y];
	
	dp[x][y] = DP(x-1,y) + DP(x,y-1);
	
	return dp[x][y];
}

int main(){
	while(1){
		int a,b;
		cin >> a >> b;
		if(a == 0 && b == 0)break;
		int n;
		cin >> n;
		
		for(int i=0;i<101;i++)for(int j=0;j<101;j++)dp[i][j] = 0;
		
		for(int i=0;i<n;i++){
			int x,y;
			cin >> x >> y;
			dp[x][y] = INF;
		}
		
		dp[1][1] = 1;
		
		cout << DP(a,b) << endl;
//
//		for(int i=1;i<=a;i++){
//			for(int j=1;j<=b;j++){
//				if(dp[i][j] == -1)continue;
//				if(dp[i][j] == INF){
//					dp[i+1][j] = 0;
//					dp[i+1][j] =
//				}
//				dp[i+1][j] = dp[i][j] + 1;
//				dp[i][j] = dp[i][j] + 1;
//			}
//		}
//		cout << dp[a][b] << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 2010, MOD = 1e9 + 7;

int f[MAXN * MAXN], dp[MAXN][MAXN], fm1[MAXN * MAXN];

inline int add(int x, int y){
	return (x + y) % MOD;
}

inline int mul(int x, int y){
	return (x * y) % MOD;
}

int p(int x, int y){
	//cerr << x << endl;
	if(y == 0)
		return 1;
	if(y == 1)
		return x;
	int f = p(x, y / 2);
	if(y % 2 == 0)
		return mul(f, f);
	else
		return mul(mul(f, f), x);
}

int c(int x, int y){
	return mul(f[y], mul(fm1[x], fm1[y - x]));
}

int32_t main(){
	int n, k;
	cin >> n >> k;
	if(k == 1){
		cout << 1 << endl;
		return 0;
	}
	f[1] = 1, fm1[1] = 1, f[0] = 1, fm1[0] = 1;
	for(int i = 2; i < MAXN * MAXN; i++){
		//cerr << i << endl;
		f[i] = mul(i, f[i - 1]);
		fm1[i] = p(f[i], MOD - 2);
	}
	//cerr << c(2, 2) << endl;
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			//cerr << j << "    " << c(k - 2, i + j * (k - 1) - 1) << "     " << dp[i][j - 1] << endl;
			if(i > 0)
				dp[i][j] = dp[i - 1][j];
			if(j > i && k > 1)
				dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], c(k - 2, i + j * (k - 1) - 1)) );
			//cerr << j << endl;
			//cerr << dp[i][j] << endl;
		}
	}
	cout << mul(dp[n][n], f[n]) << endl;
	return 0;
}

Measured memory_bytes: 94848
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

long long n, a, x;

int main(){

    cin >> n;

    set<long long> s;

    for(int i = 0; i < n; i++){
        cin >> a;
        x = s.size();
        s.insert(a);
        if(s.size() == x){
            s.erase(a);
        }
    }

    cout << s.size();



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 4864
n = int(input())
dict_lst = []
for _ in range(n):
    input_str = input()
    chr_dict = {chr(i):0 for i in range(97,97+26)}
    for s in input_str:
        chr_dict[s] += 1
    dict_lst.append(chr_dict)

ans_dict = {chr(i):100 for i in range(97,97+26)}
for d in dict_lst:
    for k,v in d.items():
        ans_dict[k] = min(ans_dict[k],v)

ans = ''
for k,v in sorted(ans_dict.items()):
    ans += k*v 
print(ans)


Measured memory_bytes: 3064
N = int(input())
D1 =[]
D2 =[]
for i in range(N):
    a,b = map(int,input().split())
    D1.append(a)
    D2.append(b) 
ans = "No"
for i in range(N-2):
    if D1[i]==D2[i]:
        if D1[i+1]==D2[i+1]:
            if D1[i+2]==D2[i+2]:
                ans ="Yes"
print(ans)

Measured memory_bytes: 62404
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long H = sc.nextLong();
		int N = sc.nextInt();
		long[] A = nextLongArray(sc, N);

		sc.close();

		long sum = 0;
		for (long a : A) {
			sum += a;
		}

		if (sum >= H) {
			out.println("Yes");
		} else {
			out.println("No");
		}

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}
}


Measured memory_bytes: 49672
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL N, M;
    cin >> N >> M;
    if(N >= M / 2) {
        cout << M / 2 << endl;
        return 0;
    }

    LL res = N;
    M -= N * 2;
    cout << res + M / 4 << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>

using namespace std;

void deci_base(int n, int k)
{
    string s="";
    int index = 0;
    while(n>0)
    {
        s += to_string(n%k);
        n/=k;
    }

    reverse(s.begin(),s.end());
    cout << s.length();
}

int main()
{
    int n,k;
    
    cin >> n >> k;
    
    deci_base(n,k);

    return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define N 100009
using namespace std;
const int INF = 0x3f3f3f3f;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};
bool check(int a, int b, int n)
{
    ans[0] = a; ans[1] = b;
    for(int i = 1; i < n - 1; i++)
    {
        if(s[i] == 'o')
        {
            if(ans[i]) ans[i + 1] = ans[i - 1];
            else ans[i + 1] = !ans[i - 1];
        }
        else
        {
            if(ans[i]) ans[i + 1] = !ans[i - 1];
            else ans[i + 1] = ans[i - 1];
        }
    }
    if(s[0] == 'o')
    {
        if(ans[0])
        {
            if(ans[1] != ans[n - 1]) return false;
        }
        else if(ans[1] == ans[n - 1]) return false;
    }
    else
    {
        if(ans[0])
        {
            if(ans[1] == ans[n - 1]) return false;
        }
        else if(ans[1] != ans[n - 1]) return false;
    }
    if(s[n - 1] == 'o')
    {
        if(ans[n - 1])
        {
            if(ans[0] != ans[n - 2]) return false;
        }
        else if(ans[0] == ans[n - 2]) return false;
    }
    else
    {
        if(ans[n - 1])
        {
            if(ans[0] == ans[n - 2]) return false;
        }
        else if(ans[0] != ans[n - 2]) return false;
    }
    return true;
}
int main()
{
    int n;
    scanf("%d %s", &n, s);
    for(int i = 0; i < 4; i++)
    {
        if(check(nx[i], ny[i], n))
        {
            for(int i = 0; i < n; i++)
            {
                if(ans[i]) printf("S");
                else printf("W");
            }
            printf("\n");
            exit(0);
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
  	long long N, A, B;
  	cin >> N >> A >> B;
  	if (A % 2 == B % 2) {
      	cout << (B-A)/2 << endl;
    } else {
      	cout << min((B-A-1)/2+A,(N-(A+N-B+1))/2+N-B+1) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


string s;

int main(){
	cin >> s;
	
	int c = INF;
	for(int i = 0; i+2 < s.size(); i++){
		c = min(c, abs(753 - ((s[i]-'0') * 100 + (s[i+1]-'0') * 10 + (s[i+2]-'0'))));
	}
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int a = (s[5] - '0') * 10 + (s[6] - '0');
	cout << (a >= 5 ? "TBD" : "Heisei") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

map<int, int> p;

map<int, int> prime_factor(int n){
    map<int, int> pf;
    for(int i = 2; i*i <= n; i++){
        if(n%i == 0){
            pf[i] = 1;
            if(i == n/i) continue;
            pf[n/i] = 1;
        }
    }
    return pf;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    int flag = 1;
    int cnt = 0;
    rep(i, 0, n-1){
        if(a[i] != a[i+1]) flag = 0;
        if(a[i] == 1) cnt++;
    }
    if(flag){
        cout << 0 << endl;
        return 0;
    }
    if(cnt == 1){
        cout << 1 << endl;
        return 0;
    }
    if(cnt >= 2){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    rep(i, 0, n){
        if(i < n-1){
            if(a[i] == a[i+1]) p[a[i]] = true;
        }
        flag = 1;
        for(int j = 2; j*j <= a[i]; j++){
            if(a[i]%j == 0){
                if(p[j]) flag = 0;
                if(p[a[i]/j]) flag = 0;
            }
        }
        if(p[a[i]]) flag = 0;
        if(flag){
            ans++;
        }
        p[a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 32596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

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

using namespace std;

int main() {
	int m,n;
	cin >> n>>m;

	int h = n/2;
	if(n%2==1)h++;
	int x = h/2;
	int y = ((h +1)+n)/2 -1;

	int j =0;
	rep(i,m){
		cout << x << " " << x+i*2+1<<endl;
		x--;
		j++;
		if(j==m)break;
		cout << y << " " << y+i*2+1+1<<endl;
		y--;
		j++;
		if(j==m)break;
	}
	return 0;
}

Measured memory_bytes: 3576
n=int(input())
s=list(map(int,input().split()))

q=int(input())
t=list(map(int,input().split()))

cnt=0
for i in range(q):
    left=0
    right=n-1
    center=int((left+right)/2)
    while left<=right:
        center=int((left+right)/2)
        if s[center]==t[i]:
            cnt+=1
            break
        elif s[center]<t[i]:
            left=center+1
        else:
            right=center-1

print(cnt)


Measured memory_bytes: 16708
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
n, k = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

ans = 0
while n:
    ans += 1
    n //= k
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
typedef long long ll;
const int MAX_N = 1<<18;

class BIT{
  
public:
  
  int n;
  ll bit0[MAX_N+1],bit1[MAX_N+1];

  BIT(){
    n=MAX_N;
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }

  BIT(int n){
    this->n=n;
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }

  ll sum(ll *b,int i){
    ll s=0;
    while(i>0){
      s=(s+b[i]);
      i-=i&-i;
    }
    return s;
  }

  void add(ll *b,int i,ll v){
    while(i<=n){
      b[i]=(b[i]+v);
      i+=i&-i;
    }
  }
  
  // [a,b] += x
  void add(int a,int b,ll x){
    add(bit0,a,-x*(a-1));
    add(bit1,a,x);
    add(bit0,b+1,x*b);
    add(bit1,b+1,-x);
  }
  
  // return sum([a,b])
  ll sum(int a,int b){
    ll res=0;
    res+=sum(bit0,b)+sum(bit1,b)*b;
    res-=sum(bit0,a-1)+sum(bit1,a-1)*(a-1);
    return res;
  }

  void init(){
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }
};

BIT seg;

int main(){
  
  int n;
  ll kai[100001];
  kai[0]=1;
  for(int i=1;i<=1e5;i++)
    kai[i]=kai[i-1]*i%M;
  while(cin>>n,n){
    seg.init();
    ll c[100001];
    for(int i=1;i<=n;i++)c[i]=i;
    int R;
    ll ans=0;
    cin>>R;
    for(int s,t,i=0;i<R;i++)
      cin>>s>>t,swap(c[s],c[t]);
    for(int i=1;i<n;i++){
      ans=(ans+(c[i]-seg.sum(1,c[i])-1)*kai[n-i])%M;
      seg.add(c[i],c[i],1);
    }
    cout<<ans<<endl;
  } 
  return 0;
}

Measured memory_bytes: 8708
#include<cstdio>
#include<iostream>
using namespace std;
const int dx[] = { -1,1,-1,0,1,-1,0,1 }, dy[] = { 0,0,1,1,1,-1,-1,-1 };
int n, m;
char a[55][55];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", a[i] + 1);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int s = 0;
				if (a[i][j] != '#') {
				for (int k = 0; k < 8; k++) {
					int nx = i + dx[k], ny = j + dy[k];
					if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] == '#') {
						s++;
						//printf("%d %d\n", nx, ny);
					
					}
				}
				a[i][j] = s + '0';
			}
				

			printf("%c", a[i][j]);
		}
		putchar('\n');
	}
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = 0
ans_c = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        ans_c += 1
        ans = max(ans, ans_c)
    else:
        ans_c = 0
print(ans)


Measured memory_bytes: 14224
from math import ceil
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

low = 0
high = A[-1]*F[0]

while low <= high:
    mid = (low+high)//2
    train = K
    for a, f in zip(A, F):
        if a*f > mid:
            need_train = ceil((a*f-mid)/f)
            if train >= need_train:
                train -= need_train
            else:
                low = mid+1
                break
    else:
        high = mid-1
print(low)


Measured memory_bytes: 108492
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, c; cin >> a >> b >> c;
	if( a+b >= c ) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll L, A, B, M, AM, BM;


struct finfo {
	ll rmul;
	ll amul;
	ll c;
};
finfo fi[100];

/*
	ダブリング
	fi[i] : f(r,a,2^i)の係数を計算する
	f(r,a,2^i,k) = fi[i].rmul*r + fi[i].amul*a + fi[i].c + 
	
	
	2^i = n とする
	i-1 = j 
	2^j = m とする
	
	fi[i].rmul -> rn
	fi[i].amul -> an
	fi[i].cmul -> cn
	fi[j].rmul -> rm
	fi[j].amul -> am
	fi[j].cmul -> cm
	
	f(r,a,m) = rm*r + am*a + cm
	
	f(r,a,2*m) = f(f(r,a,m),a+m*B,m)
	           = f((rm*r + am*a + cm),a+m*B,m)
	           = rm*(rm*r + am*a + cm) + am*(a+m*B) + cm
	           
	           =   r * (rm*rm)
	             + a * (rm*am+am)
	             + rm*cm+cm + am*m*B


*/
void calc_fi( ll r, ll a, ll keta, ll k ){
	fi[0] = { k%M, 1, 0 };
	ll m = 1;
	for ( int i = 1; i < 64; i++ ){
		fi[i].rmul = (fi[i-1].rmul * fi[i-1].rmul)%M;
		fi[i].amul = ((fi[i-1].rmul+1)*fi[i-1].amul)%M;
		fi[i].c    = ((fi[i-1].rmul+1)*fi[i-1].c%M + (((fi[i-1].amul*m)%M)*BM)%M)%M;
		m = (m*2)%M;
	}
	
	
	//cout << "calc" << k << endl;
	//for ( int i = 0; i < 10; i++ ){
	//	cout << fi[i].rmul << "  " << fi[i].amul << "  " << fi[i].c << endl;
	//}
}




/*
	s(i) = a のとき
	r, s(i) .. s(i+n-1) をつなげた数をMで割った余りを返す
*/
ll f( ll r, ll a, ll n, ll keta, ll k ){
	calc_fi( r, a, keta, k );
	
	for ( int i = 0; n; i++ ){
		ll p = 1LL << i;
		if ( n & p ){
			r = (fi[i].rmul*r + fi[i].amul*a + fi[i].c)%M;
			a = (a + BM*(p%M))%M;
			n -= p;
		}
	}
	return r;
}


int main(){
	cin >> L >> A >> B >> M;
	AM = A % M;
	BM = B % M;
	
	ll result = 0;
	for ( ll keta = 1, k = 10; keta <= 18; keta++, k *= 10 ){ // k = 10^keta
		// k/10 <= s < k となる範囲の s を処理する
		if ( k/10 <= A && A < k ){
			// k <= A+nB となるnは?
			// (k-A)/B <= n
			ll n = (k-A+B-1)/B;
			if ( n > L )
				n = L;
			
			//cout << "\n\nrange: " << A << " - " << (A + B * (n-1)) << " : n=" << n << endl;
			//ll rtest = result;
			//for ( int j = 0; j < n; j++ ){
			//	rtest = ((rtest*(k%M))%M + (AM + BM*j%M)%M)%M;
			//}
			//cout << "rtest: " << rtest << endl;
			
			result = f( result, AM, n, keta, k );
			//cout << "result: " << result << endl;
			
			
			A += B * n;
			AM = A % M;
			L -= n;
			if ( L == 0 )
				break;
		}
	}
	
	cout << result << endl;
	return 0;
}



Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()

def make_divisors(n):
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            # √nで無い数についてもう一個プラス
            if i != n // i:
                divisors.append(n // i)
    return sorted(divisors)

div = make_divisors(N)

num = []
alta = set(div)

for split in div:
    opt = (N // split) - 1
    if opt > 1 and N // opt == N % opt:
        num.append(opt)
print(sum(num))

Measured memory_bytes: 61548
from copy import deepcopy
EMP = -1 
BLOCK = -2

input_data = input().split()
h, w = map(int, input_data)

# 迷路情報
maze_map = [[EMP for i in range(w)] for j in range(h)]

# 迷路取得
for i in range(h):
    input_data = input()
    char_data = list(input_data)

    for j in range(len(char_data)):
        # 壁は-1
        if(char_data[j] == "#"):
            maze_map[i][j] = BLOCK

# 最大値取得
max_mass = 0

# 探索
for i in range(h):
    for j in range(w):

        # 迷路、キューを初期化
        tmp_maze_map = deepcopy(maze_map)
        queue_list = []

        # 自身の位置を開始位置とする(壁の時は見ない)
        if(tmp_maze_map[i][j] == BLOCK):
            continue
        tmp_maze_map[i][j] = 0

        # キューに自身を入れる
        queue_list.append([i,j])

        while(len(queue_list) > 0):
            get_x = queue_list[0][0]
            get_y = queue_list[0][1]

            # チェック(上) 範囲を超える、自身が壁、上が空でないのときは処理しない
            if(not ((get_x == 0) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x-1][get_y] != EMP))):
                tmp_maze_map[get_x-1][get_y] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x-1,get_y])

            # チェック(左, 右)
            if(not ((get_y == 0) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x][get_y-1] != EMP))):
                tmp_maze_map[get_x][get_y-1] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x, get_y-1])

            # チェック(右)
            if(not ((get_y == w-1) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x][get_y+1] != EMP))):
                tmp_maze_map[get_x][get_y+1] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x, get_y+1])
            # チェック(下)
            if(not ((get_x == h-1) or (tmp_maze_map[get_x][get_y] == BLOCK) or (tmp_maze_map[get_x+1][get_y] != EMP))):
                tmp_maze_map[get_x+1][get_y] = tmp_maze_map[get_x][get_y] + 1
                queue_list.append([get_x+1,get_y])

            # チェックしたマスを取り除く
            queue_list.pop(0)

        # 最大値を取得
        for k in tmp_maze_map:
            t_sum_list = deepcopy(k)
            t_sum_list += [max_mass]
            max_mass = max(t_sum_list)
            t_sum_list.clear()
        
        # 迷路リセット
        tmp_maze_map.clear()

print(max_mass)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define num 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n;
    cin>>n;
    ll a=1,b=1,c=1;
    rep(i,n) a=a*10%num,b=b*9%num,c=c*8%num;
    ll ans=a-b-b+c;
    ans%=num;
    ans=(ans+num)%num;
    cout<<ans;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main{
	
	int ans, n;
	int [] close ;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		HashSet<Integer> init = new HashSet<Integer>();
		init.add(1);
		close = new int[1024];
		Arrays.fill(close, 1 << 24);
		close[1] = 0;
		solve(1, 0, init);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			System.out.println(close[n]);
		}
	}
	
	private void solve(int now, int step, HashSet<Integer> record) {
		if(step == 13){
			return ;
		}
		for(int value: record){
			for(int i = -1; i <= 1; i+= 2){
				int next = now + value * i;
				if(next <= 0) continue;
				if(record.contains(next)) continue;
				if(next < 1024){
					if(close[next] < step + 1){
						continue;
					}
					close[next] = step + 1;
				}
				HashSet<Integer> nextr = new HashSet<Integer>(record);
				nextr.add(next);
				solve(next, step + 1, nextr);
			}
		}
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;
        if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long int
#define st string
#define be begin
#define en end
#define sr sort
#define sz size
#define lt length
#define URVATULLO_ATOEV
#define LFGS_STUDENTS
#define AUTHOR_URVATULLO_ATOEV
using namespace std;
int main()
{
	URVATULLO_ATOEV
	LFGS_STUDENTS
    AUTHOR_URVATULLO_ATOEV
    int a,b;
    cin>>a>>b;
    if(b<=(a+1)/2)
    {
        cout<<"YES\n";
    }
    else
    {
        cout<<"NO\n";
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		boolean[] isSheep = solve(s);
		
		if(isSheep==null) {
			System.out.println(-1);
		} else {
			char[] ans = new char[N];
			for(int i=0; i<N; i++) {
				ans[i] = isSheep[i] ? 'S' : 'W';
			}
			System.out.println(ans);
		}
		sc.close();
	}
	
	static boolean[] solve(char[] s) {
		int N = s.length;
		boolean[] v = new boolean[N];
		for(int i=0; i<4; i++) {
			boolean ok = true;
			v[0] = i%2==0;
			v[1] = i/2==0;
			for(int j=0; j<N; j++) {
				boolean next = v[j]^v[(j+1)%N]^s[(j+1)%N]=='o';
				if(N-2<=j) {
					if(v[(j+2)%N]!=next) {
						ok = false;
						break;
					}
				}
				v[(j+2)%N] = next;
			}
			if(ok)
				return v;
		}
		return null;
	}
}


Measured memory_bytes: 26592
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	int *line;
	line = new int[N];
	for (int i = 0; i < N; ++i) {
		cin >> line[i];
	}
	sort(line, line + N, greater<int>());
	int *box;
	box = new int[N + 1];
	box[0] = 0;
	for (int i = 0; i < N; ++i) {
		box[i + 1] = box[i] + line[i];
	}
	int *dp;
	dp = new int[N + 1]{ 0 };
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		for (int j = N - 1; j > -1; --j) {
			dp[min(N, j + a)] = max(dp[min(N, j + a)], dp[j] + box[min(N, j + a)] - box[j] - b);
		}
	}
	int ans = 0;
	for (int i = 1, nmax = N + 1; i < nmax; ++i) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3276
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> C(H);
    rep(i, H) cin >> C[i];

    vv<vector<int>> fric = vvec(W, H + 1, vector<int>(H + 1, 0));
    rep(w, W - 1) {
        rep(k, -H + 1, H) {
            // k == i - j
            // A[i:], B[j:]
            int fs = 0;
            for (int i = max(k, 0), j = i - k; i < H && j < H; ++i, ++j) {
                fs += C[i][w] == C[j][w + 1];
                fric[w][H - 1 - i][H - 1 - j] = fs;
            }
        }
    }

    int ans = 0;
    vv<int> dp = vvec(H + 1, H + 1, 0);
    rep(w, W - 1) {
        rep(i, H + 1) dp[i].assign(H + 1, INF);
        dp[0][0] = 0;
        rep(j, H) dp[0][j + 1] = dp[0][j] + fric[w][0][j];
        rep(i, H) dp[i + 1][0] = dp[i][0] + fric[w][i][0];
        rep(i, H) rep(j, H) {
            dp[i + 1][j + 1] = min(dp[i + 1][j] + fric[w][i + 1][j], dp[i][j + 1] + fric[w][i][j + 1]);
        }
        ans += dp[H][H];
    }
    write(ans);
}

Measured memory_bytes: 110080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007 
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;
	vi v(n),dp(k+1,0);
	F(i,0,n){
		cin>>v[i];
		// dp[v[i]]=1;
	}
	F(i,1,k+1){
		F(j,0,n){
			if(i-v[j]>=0)
				dp[i]=dp[i]|!dp[i-v[j]];
		}
	}
	cout<<(dp[k]?"First":"Second");
	return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int i;
	if(n<=104&&n>=1)
	cout<<0<<endl;
	else{
		int w=0;
		for(i=105;i<=n;i+=2){
				int k=0;
			for(int j=1;j<=i;j++){
				if(i%j==0)
				k++;
			}
			if(k==8)
			w++;
		}
		cout<<w<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	int a,b,c; cin >> a >> b>> c;
	if(a <= b*c)cout <<"Yes" << endl;
	else cout <<"No" << endl;

	return 0;
}

Measured memory_bytes: 3668
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var odd int
	for i := 1; i <= N; i++ {
		if i % 2 == 1 {
			odd++
		}
	}

	fmt.Println(float64(odd) / float64(N))
}


Measured memory_bytes: 512
#include<algorithm>
#include<cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

int n, m;
int s[200];
int St, Sh;

int main()
{
  while( scanf( "%d%d", &n, &m ), n|m )
  {
    St = Sh = 0;
    
    rep( i, n+m )
    {
	scanf( "%d", s+i );

	(i<n?St:Sh) += s[i];
    }

    std::sort( s, s+n ); std::sort( s+n, s+n+m );

    bool fl = false;
    
    rep( i, n ) repi( j, n, n+m ) if( St-s[i]+s[j] == Sh-s[j]+s[i] )
    {
      printf( "%d %d\n", s[i], s[j] );
      fl = true;
      
      goto end;
    }

  end:;
    
    if( !fl )
      puts( "-1" );
  }
  
  return 0;
}

Measured memory_bytes: 2768
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var input string
	fmt.Scan(&input)

	strNums := strings.Split(input, "")
	var nums []int
	for _, v := range strNums {
		num, _ := strconv.Atoi(v)
		nums = append(nums, num)
	}

	// 数値の間に＋を入れるか
	sum := 0
	for bits := 0; bits < (1 << uint64(len(nums)-1)); bits++ {
		var pluss []int
		for i := 0; i < len(nums)-1; i++ {
			// bitsのi個目の要素の状態がonかどうかチェック
			if (bits>>uint64(i))&1 == 1 {
				pluss = append(pluss, i)
			}
		}
		sum += calcSum(nums, pluss)
	}
	fmt.Println(sum)
}

func calcSum(nums []int, pluss []int) int {
	str := ""
	for i, v := range nums {
		str += strconv.Itoa(v)
		for _, vj := range pluss {
			if i == vj {
				str += "+"
			}
		}
	}
	strs := strings.Split(str, "+")

	sum := 0
	for _, v := range strs {
		num, _ := strconv.Atoi(v)
		sum += num
	}
	return sum
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  int p = N/100;
  int q = N%100;
 
  int ans = 0;
  if((p*5)>= q){
    cout << "1" << endl;
  }
  else{
    cout << "0" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
string s;
int n;
int main()
{
	cin>>n>>s;
	int ans=0;
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

enum FACE { BACK, RIGHT, TOP, BOTTOM, LEFT, FRONT };

template <class T>
class Dice
{
public:
  Dice() {
    id[TOP] = 2; id[FRONT] = 5; id[LEFT] = 4;
    id[RIGHT] = 1; id[BACK] = 0; id[BOTTOM] = 3;
  }

  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const  { return var[id[f]]; }

  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }

  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b];
    id[b] = id[c];
    id[c] = id[d];
    id[d] = tmp;
  }

  T var[6];
  int id[6];
};

int repaint(vector<Dice<int> >& cubes) {
  int res = 0, N = cubes.size();
  for(int j=0; j<6; j++) {
    int C[50] = {0}, same = 0;
    for(int i=0; i<N; i++) {
      same = max(same, ++C[cubes[i][(FACE)j]]);
    }

    res += N - same;

  }

  return res;
}

int dfs(int p, int N, vector<Dice<int> >& cubes) {
  if(p == N) return repaint(cubes);

  int res = (1<<28);

  Dice<int>& d = cubes[p];
  for(int k=0; k<6; (k&1?d.roll_y():d.roll_x()),k++) {
    for(int i=0; i<4; d.roll_z(), i++) {
      res = min(res, dfs(p+1, N, cubes));
    }
  }

  return res;
}


int main()
{
  int N;
  while(cin >> N, N) {
    vector<Dice<int> > cubes(N);
    map<string, int> dic;
    int color = 0;

    for(int i=0; i<N; i++) {
      for(int j=0; j<6; j++) {
        string s;
        cin >> s;
        if(!dic.count(s)) dic[s] = color++;

        cubes[i][(FACE)j] = dic[s];
      }
    }

    cout << dfs(0, N, cubes) << endl;
  }
}

Measured memory_bytes: 932
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

        return True
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.parents[self.root(x)]
    
    def members(self, x):
        x_root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == x_root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())

def main():
    N, K, L = map(int, input().split())
    uf_road = UnionFind(N)
    uf_railway = UnionFind(N)
    pq = [tuple(map(int, input().split())) for i in range(K)]
    for p, q in pq:
        uf_road.unite(p-1, q-1)
    rs = [tuple(map(int, input().split())) for i in range(L)]
    for r, s in rs:
        uf_railway.unite(r-1, s-1)
    
    d = defaultdict(int)
    for i in range(N):
        d[(uf_road.root(i), uf_railway.root(i))] += 1
    
    for i in range(N):
        print(d[(uf_road.root(i), uf_railway.root(i))])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 65668
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;

#define ll long long int


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
     int n,m;
     cin>>n>>m;
     cout<<(n*(n-1)/2+m*(m-1)/2);
 }


Measured memory_bytes: 256
program pr2
  implicit none
  integer :: i, j, n, m
  integer,allocatable,dimension(:) :: p, x, t, t1
  
  read(*,*) n
  allocate(t(n),t1(n))
  read(*,*) t
  read(*,*) m
  allocate(p(m),x(m))
  do i = 1, m
     read(*,*) p(i), x(i)
  end do
  t1 = t
  do i = 1, m
     t1(p(i)) = x(i)
     write(*,*) sum(t1)
     t1(p(i)) = t(p(i))
  end do
  stop
  
end program pr2


Measured memory_bytes: 2784