akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin >> s;
    int diff = 0;
    for(int i = 0; i < s.size() / 2; ++i){
        if(s[i] != s[s.size() - i - 1]) diff++;
    }
    cout << diff << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      cin >> S[i][j];
    }
  }
  vector<vector<int>> R(H + 2, vector<int>(W + 2, 0));
  for (int i = 0; i < H + 2; i++){
    for (int j = W; j >= 0; j--){
      if (S[i][j] == '#'){
        R[i][j] = 0;
      } else {
        R[i][j] = R[i][j + 1] + 1;
      }
    }
  }
  vector<vector<int>> L(H + 2, vector<int>(W + 2, 0));
  for (int i = 0; i < H + 2; i++){
    for (int j = 1; j < W + 2; j++){
      if (S[i][j] == '#'){
        L[i][j] = 0;
      } else {
        L[i][j] = L[i][j - 1] + 1;
      }
    }
  }
  vector<vector<int>> D(H + 2, vector<int>(W + 2, 0));
  for (int i = 0; i < W + 2; i++){
    for (int j = H; j >= 0; j--){
      if (S[j][i] == '#'){
        D[j][i] = 0;
      } else {
        D[j][i] = D[j + 1][i] + 1;
      }
    }
  }
  vector<vector<int>> U(H + 2, vector<int>(W + 2, 0));
  for (int i = 0; i < W + 2; i++){
    for (int j = 1; j < H + 2; j++){
      if (S[j][i] == '#'){
        U[j][i] = 0;
      } else {
        U[j][i] = U[j - 1][i] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      ans = max(ans, R[i][j] + L[i][j] + D[i][j] + U[i][j] - 3);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 67072
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int[] ary = new int[3];
		for(int i = 0; i < 3; i++) {
			ary[i] = scanner.nextInt();
		}
		Arrays.sort(ary);
		// c - b の数 +1 できる
		// b - a が偶数 -> a + 2 1kai
		// false -> bc +1 a +2 2 2kai
		int ans = ary[2] - ary[1];
		ans += (ary[1] - ary[0]) / 2 + (ary[1] - ary[0]) % 2 * 2; 
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 23892
# -*- Coding: utf-8 -*-
import sys
i=0
zeibiki=[0]*50000
zeiari=[0]*50000

for i in range(50000):
    zeibiki[i]=int((i+1))
for i in range(50000):
    zeiari[i]=int((i+1)*1.08)
    #print(zeibiki[i],zeiari[i])
#print(zeibiki[4999])
N=int(input())
#print(1001*1.08)

#x=N/1.08
#print(int(x))
#NN=x*1.08
#print(NN)

i=0
for i in range(50000):
    if N==zeiari[i]:
        print(zeibiki[i])
        sys.exit()
    else:
        pass

print(":(")


Measured memory_bytes: 6900
def isPrime(n):
    for i in range(2,n):
        if n%i == 0:
            return False
    return True
X = int(input())
res=0
if X == 2:
    pass
elif X%2 == 0:
    X = X +1
else:
    pass
for i in range(X, X+10000):
    res = i
    if isPrime(i):
        break
print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007
ll fact[1000001];
ll inv[1000001];

ll fermat(ll v,ll p)
{

    if(p==0)
        return 1;
    ll a=1;
    if(p%2)
        a=v;
    ll x=fermat(v,p/2);
x=(x*x)%M;
x=(x*a)%M;
return x;



}
int main(){
int i,j;
fact[0]=1;

for(i=1;i<=1000000;i++)
     fact[i]=(fact[i-1]*(i))%M;
inv[0]=1;
for(i=1;i<=1000000;i++)
    inv[i]=fermat(fact[i],M-2);

  int n;
  cin>>n;
  ll ans=0;
  int k;
  ll pre=0;
  for(k=1;k<n;k++)
  {

      int o=n-1-k;

      if(o>=k)
        continue;


      ll aux=(fact[k]*fact[n-1-k])%M;


      aux=aux*(((((fact[k-1])*inv[o])%M)*inv[k-1-o])%M);
      aux=(aux%M);

      ll temp=aux;
      aux=aux-pre;
      pre=temp;
      if(aux<0)
        aux+=M;
  aux=(aux*k)%M;
      ans=(ans+aux)%M;


  }



cout<<ans<<endl;



return 0;}


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

using namespace std;
const int Nmax = 1e5 + 5;

int cnts[Nmax][2];
int cntt[Nmax][2];
int q,a,b,c,d;

int main()
{
    //freopen("file.inp","r",stdin);
    string s,t;
    cin >> s;
    cin >> t;
    for (int i = 1; i <= s.size(); i++)
    {
        if (s[i - 1] == 'A') cnts[i][0]++;
        else cnts[i][1]++;
        cnts[i][0] += cnts[i - 1][0];
        cnts[i][1] += cnts[i - 1][1];
    }
    for (int i = 1; i <= t.size(); i++)
    {
        if (t[i - 1] == 'A') cntt[i][0]++;
        else cntt[i][1]++;
        cntt[i][0] += cntt[i - 1][0];
        cntt[i][1] += cntt[i - 1][1];
    }
    cin >> q;
    while (q--)
    {
        cin >> a >> b >> c >> d;
        int cnta,cntb;
        int S, T;
        cnta = cnts[b][0] - cnts[a - 1][0];
        cntb = cnts[b][1] - cnts[a - 1][1];
        if (cnta > cntb)
        {
            cnta -= cntb;
            cnta %= 3;
            S = cnta;
        } else {
            cntb -= cnta;
            cntb %= 3;
            S = (3 - cntb) % 3;
        }
        cnta = cntt[d][0] - cntt[c - 1][0];
        cntb = cntt[d][1] - cntt[c - 1][1];
        if (cnta > cntb)
        {
            cnta -= cntb;
            cnta %= 3;
            T = cnta;
        } else {
            cntb -= cnta;
            cntb %= 3;
            T = (3 - cntb) % 3;
        }
        if (S == T) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#define MOD 1000000007
using namespace std;
int main()
{
int n,m;
char arr[1001][1001] ;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>arr[i][j];
}
}
int dp[n+1][m+1];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
dp[i][j]=0;
}
for(int i=1;i<=n;i++)
{
if(arr[1][i]!='#')
dp[1][i]=1;
else
break;
}
for(int i=1;i<=m;i++)
{
if(arr[i][1]!='#')
dp[i][1]=1;
else
break;
}
for(int i=2;i<=n;i++)
{
for(int j=2;j<=m;j++)
{
if(arr[i][j]!='#')
dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
}
}
cout<<dp[n][m]<<endl;
return 0;
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <math.h>

int main()
{
  double x=0.0, y=0.0;
  int theta=90;
  int a, b;

  for(;;)
    {
      scanf("%d,%d", &a, &b);

      if(a == 0 && b == 0)
	break;

      x += a * cos(theta * M_PI / 180);
      y += a * sin(theta * M_PI / 180);
      theta -= b;
    }

  printf("%d\n%d\n", (int)x, (int)y);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

bool A(string s){
  if(s.size() < 6) return false;
  if(s.size()%2 != 0)return false;
  if(s[0] != '>')return false;
  if(s[1] != '\'')return false;
  if(s[s.size()-1] != '~')return false;
  if(s[s.size()/2] != '#')return false;
  else s[s.size()/2] = '=';
  loop(i,2,s.size()-1){
    if(s[i] != '=')return false;
  }
  return true;
}
bool B(string s){
  if(s.size() < 6) return false;
  if(s[0] != '>')return false;
  if(s[1] != '^')return false;
  loop(i,2,s.size()-2){
    if(i%2){
      if(s[i] != '=')return false;
    }else{
      if(s[i] != 'Q')return false;
    }
  }
  if(s[s.size()-2] != '~')return false;
  if(s[s.size()-1] != '~')return false;
  return true;
}
int main(void){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    if(A(s))cout<<"A";
    else if(B(s))cout<<"B";
    else cout<<"NA";
    cout<<endl;
  }
}

Measured memory_bytes: 1208
import sys

def test():

	n = int(sys.stdin.readline())
	S = list(map(int,sys.stdin.readline().split()))
	q = int(sys.stdin.readline())
	T = list(map(int,sys.stdin.readline().split()))

	for i in range(len(T)):

		for j in range(len(S)):

			if T[i] == S[j]:
				S.pop(j)
				break
	print(f"{n-len(S)}")

if __name__ == "__main__":
	test()



Measured memory_bytes: 6600
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,K;
ll S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>S;
	if(S==1000000000) {
		FOR(i,N) {
			if(i<K) cout<<S<<" ";
			else cout<<(S-1)<<" ";
		}
	}
	else {
		FOR(i,N) {
			if(i<K) cout<<S<<" ";
			else cout<<(S+1)<<" ";
		}
	}
	cout<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1280
import sys,itertools
input = sys.stdin.readline

N,M,Q = list(map(int,input().split()))
abcd = [ list(map(int,input().split())) for _ in range(Q)]
ans = 0

A = itertools.combinations_with_replacement(range(1,M+1),N)

for Ai in A:
    point = 0
    for a,b,c,d in abcd:
        if Ai[b-1] - Ai[a-1] == c:
            point += d
    ans= max(ans,point)
print(ans)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
const int N=200010;
int n,m,k;
int a[N];

int main(){
#ifdef WK
	freopen("in.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	long long sum=0;
	for(int i=1;i<=n-m;i++)sum+=a[i];
	printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

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

        int C = 0;
        int D = 0;

        C = (A+B)/2;
        D = (A+B)%2;

        if(D != 0){
            System.out.println("IMPOSSIBLE");
        }else{
            System.out.println(C);
        }


        

    }
}

Measured memory_bytes: 21588
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

#define N 20
#define Q 200

int A[N],B[Q],n,q;

bool solve(int I,int target){

  int i,j,u,v;
  bool res;
  
  if(target == 0) return true;
  if(I >= n) return false;

  res = solve(I+1,target-A[I]) || solve(I+1,target);
  return res;
}

     

int main(){

  int i,j;
  bool  k;

  scanf("%d",&n);
  
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++) scanf("%d",&B[i]);
  
  for(i=0;i<q;i++){
   k =  solve(0,B[i]);

  if( k == true) printf("yes\n");
    else if( k == false) printf("no\n");
  }

  return 0;
}



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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 300005;
const int mod = 998244353;

int n, a, b, fac[N], inv[N];
LL k;

inline int C(int x, int y) {
  return 1LL * fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(a), Read(b), Read(k);
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
    inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  }
  for (int i = 2; i <= n; ++i) {
    inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
  }
  int ans = 0;
  for (int i = 0; i <= n && k >= 0; ++i, k -= a) {
    if (k % b == 0) {
      LL t = k / b;
      if (t >= 0 && t <= n) {
        ans = (1LL * C(n, i) * C(n, t) + ans) % mod;
      }
    }
  }
  printf("%d\n", ans);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 2560
lst = [input() for i in range(5)]
d = [int(num) for num in lst]
lst_one = [int(list(i)[-1]) for i in lst]
if lst_one.count(0) == len(lst_one):
  print(sum(d))
else:
  if lst_one.count(0) == 0:
    idx = lst_one.index(min(lst_one))
  else:
    no_zero = [i for i in lst_one if i != 0]
    m = min(no_zero)
    idx = lst_one.index(m)

  x = d[idx]
  del d[idx]

  for i in range(len(d)):
    if d[i] % 10 != 0:
      d[i] = 10*(int((d[i]/10))+1)
    else:
      continue
  print(sum(d) + x)

Measured memory_bytes: 62108
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
map<int, int>m;
const int maxn = 1e5 + 5;
int a[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	ll sum = 0;
	for (int i = 0; i < m; i++)
		sum += a[i];
	cout << sum << endl;
}

Measured memory_bytes: 3616
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)

    def show_top(self):
        return self.faces["top"]


def main():
    dice = Dice(input().split())
    dice.rolls(input())
    print(dice.show_top())

if __name__ == "__main__":
    main()

Measured memory_bytes: 7564
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,l,r,s=0;
	cin>>n;
	REP(i,0,n-1){
		cin>>l>>r;
		s=s+(r-l+1);
	}
	cout<<s;
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int sum=0,max=0;
	for(int i=0;i<n;i++){
		int l;
		scanf("%d",&l);
		if(l>max){
			sum+=max;
			max=l;
		}else sum+=l;
	}
	if(max<sum)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
set<string> S;

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

  cin >> N;
  string W;
  char pre = 'a';
  bool flag = true;
  rep(i, N) {
    cin >> W;
    if (i>0) {
      if (pre != W[0]) flag = false;
    }
    pre = W[W.size()-1];
    S.insert(W);
  }
  if (S.size() != N) flag = false;
  string ans = flag?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

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

typedef pair<int, int> P;

P lefttop(P p, int N){
  int i = p.first, j = p.second;
  return min(P(i, j), min(P(i, N-j-1), min(P(N-i-1, j), P(N-i-1, N-j-1))));
}

bool mirr(const vector< vector<int> > &p, P x, int N){
  int i = x.first, j = x.second;
  //cout << i+1 << " " << j+1 << " " << N-i << " " << N-j << endl;
  return p[i][j] == p[i][N-j-1] &&
         p[i][j] == p[N-i-1][j] &&
         p[i][j] == p[N-i-1][N-j-1];
}

void init(vector< vector<int> > &p, int N, set<P> &s){
  s.clear();
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      P point = P(i, j);
      if( !mirr(p, point, N) ){
        s.insert(lefttop(point, N));
      }
    }
  }
}

int rev(int x){
  return (x == 0) ? 1 : 0;
}

void update(P lt, vector< vector<int> >&p, set<P> &s, int N){
  set<P>::iterator it = s.find(lt);
  //cout << "===========" << lt.first << " " << lt.second << endl;
  if(it != s.end() && mirr(p, lt, N)){
    //cout << "A" << endl;
    //cout << it->first << " " << it->second << endl;
    s.erase(it);
  }else{
    s.insert(lt);
  }
}

void print(const vector< vector<int> > &p, int N){
  for(size_t i = 0; i < N; i++){
    for(size_t j = 0; j < N; j++){
      cout << p[i][j];
    }
    cout << endl;
  }
  cout << endl;
}

void prints(set<P> &s){
  for(set<P>::iterator it = s.begin(); it != s.end(); it++){
    cout << "(" << it->first << " " << it->second << ") ";
  }
  cout << endl;
}

int main(void){
  int C, N; cin >> C >> N;
  vector< vector<int> > p(1000, vector<int>(1000));
  for(int i = 0; i < N; i++){
    string str; cin >> str;
    for(int j = 0; j < N; j++){
      p[i][j] = str[j] - '0';
    }
  }

  int ans = 0;
  set<P> s;
  init(p, N, s);

  if(s.size() == 0){
    ans++;
  }
  for(int i = 0; i < C-1; i++){
    int D; cin >> D;
    //prints(s);
    for(int j = 0; j < D; j++){
      int r, c; cin >> r >> c;
      r--; c--;
      p[r][c] = rev(p[r][c]);
      P q = P(r, c);
      P lt = lefttop(q, N);
      //prints(s);
      //cout << lt.first << " " << lt.second << endl;
      update(lt, p, s, N);
      //print(p, N);
    }
    if(s.size() == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15696
def acgt(s)
    continuous_acgt = 0
    
    s.chars.inject(0) {|res, i|
        case i
        when "A", "C", "G", "T" then
            continuous_acgt += 1
        else
            continuous_acgt = 0
        end
        
        res = [res, continuous_acgt].max
    }
end

puts acgt(gets.chomp)

Measured memory_bytes: 1788
while True:
    n,x = map(int, raw_input().split())
    if n == 0 and x == 0: break
    c = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            ij = i + j
            for k in range(j+1, n+1):
                if ij+k == x:
                    c += 1
    print c    

Measured memory_bytes: 4228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <unordered_map>
// #include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int a, b, c, d, k;
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
//freopen("C:\\code\\output.txt","r",stdin);
    cin >> a >> b >> c >> d >> k;
    b += a * 60;
    d += c * 60;
    d -= b;
    d -= k;
    cout << d << endl;
    return 0;
}




Measured memory_bytes: 3640
from heapq import heappop, heappush
N,T = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB = sorted(AB)
#print(AB)
j = 0
ans=0
dp = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
  for t in range(T+1):
    dp[i+1][t]=max(dp[i+1][t],dp[i][t])
    if t<=T-1:
      dp[i+1][min(T,t+AB[i][0])]=max(dp[i+1][min(T,t+AB[i][0])],dp[i][t]+AB[i][1])
print(dp[N][T])


Measured memory_bytes: 118872
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
ll a[100005][2];
vector<int> vec[100005];
bool visit[100005];
int n;
ll dfs(int index,int colour,int f)
{
	//if(f==n)return 1;
	if(a[index][colour]>-1)return max(a[index][colour],1LL);
	visit[index]=true;
	
	a[index][colour]=1;
	if(colour==1)
	{
		For(i,vec[index].size())
		{
			if(visit[vec[index][i]])continue;
			a[index][colour]*=dfs(vec[index][i],1,f+1)+dfs(vec[index][i],0,f+1);
			a[index][colour]%=mod;
			//a[index][colour]*=;
			a[index][colour]%=mod;
		}
		visit[index]=false;
		//cout<<index<<" "<<colour<<" "<<max(a[index][colour],1LL)<<endl;
		return max(a[index][colour],1LL);
	}
	else
	{
		For(i,vec[index].size())
		{
			if(visit[vec[index][i]])continue;
			a[index][colour]*=dfs(vec[index][i],1,f+1);
			a[index][colour]%=mod;
		}
		//cout<<index<<" "<<colour<<" "<<max(a[index][colour],1LL)<<endl;
		visit[index]=false;
		return max(a[index][colour],1LL);
	}
	
}
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	
  	memset(visit,false,sizeof(visit));
  	cin>>n;
  	For(i,n-1)
  	{
  		int u,v;
  		cin>>u>>v;
  		vec[u].pb(v);
  		vec[v].pb(u);
  	}
  	vec[0].pb(1);
  	For(i,n+1)a[i][0]=a[i][1]=-1;
  	cout<<dfs(0,1,0)<<endl;
	return 0;
}

Measured memory_bytes: 14336
// AtCoder template
// 最近sabaがかまってくれないからキレて暴れてる
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    n %= 10;
    int hon[5] = {2,4,5,7,9};
    int pon[5] = {0,1,6,8};
    rep(i,5){
        if(n == hon[i]){
            cout << "hon" << endl;
            return 0;
        }
    }
    rep(i,4){
        if(n == pon[i]){
            cout << "pon" << endl;
            return 0;
        }
    }
    cout << "bon" << endl;
}

Measured memory_bytes: 3648
from collections import Counter
mod = 10**9+7
mod2 = 998244353
rng = 100100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n = int(input())
s = input()
a = [0]*(2*n)
a[0] = 1
for i in range(1,2*n):
  if s[i-1] == s[i]:
    a[i] = a[i-1]
  else:
    if i == 1:
      a[i] = a[i-1]+1
    else:
      if a[i-1] != a[i-2]:
        a[i] = 2*a[i-1]-a[i-2]
      if (i+a[i-1])%2 == 0:
        a[i] = a[i-1]+1
      else:
        a[i] = a[i-1]-1
if a[-1] != 1 or a.count(0) >= 1 or s[0] != "B" or s[-1] != "B":
  print(0)
  exit()
c = Counter(a)
ans = 1
for i,x in c.items():
  ans = (ans*pow(i,x//2,mod))%mod
ans = ans*fctr[n]%mod
print(ans)

Measured memory_bytes: 56272
def solve(n, k):
    s1 = n * (k + (k + 2 * n - 1))
    s2 = n * ((k + 2 * n) + (k + 3 * n - 1)) // 2
    res = []
    if s1 > s2:
        return None
    if n % 2 == 1:
        m = ((n + 1) // 4) * 2
        for i in range(m):
            a = k + n - 1 - i
            b = k + n + i + (m - 1 - 2 * i)
            c = k + 2 * n + (n - 1) // 2 + (m - 1 - 2 * i)
            res.append([a, b, c])
            # print(1, a, b, c)
        for i in range(n - m):
            a = k + n - 1 - m - i
            b = k + 2 * n - 1 - i
            c = k + 2 * n + (n - 1) // 2 + 2 * ((n - m) // 2 - i)
            res.append([a, b, c])
            # print(2, a, b, c)
        return res
    else:
        m = n // 2
        for i in range(m):
            a = k + n - 1 - i
            b = k + n + i + (m - 1 - 2 * i)
            c = k + 2 * n + m + (m - 2 - 2 * i)
            res.append([a, b, c])
            # print(1, a, b, c)
        for i in range(n - m):
            a = k + n - 1 - m - i
            b = k + 2 * n - 1 - i
            c = k + 3 * n - 1 - 2 * i
            res.append([a, b, c])
            # print(2, a, b, c)
        return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    if res is None:
        print(-1)
    else:
        for r in res:
            print(*r)


if __name__ == "__main__":
    main()


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

int main() {
  int N, Alice = 0, Bob = 0;
  cin >> N;
  vector<int> Card(N);

  for (int i = 0; i < N; i++) {
    cin >> Card.at(i);
  }

  sort(Card.begin(), Card.end());
  reverse(Card.begin(), Card.end());
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) Alice += Card.at(i);
    else Bob += Card.at(i);
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
  S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
  if S1_MAX[0] != S2_MAX[0]:
    print(N - S1_MAX[1] - S2_MAX[1])
  else:
    V2_l.pop(S2_MAX[0])
    S2_MAX_s = [V2_l.index(max(V2_l)),max(V2_l)]
    ans1 = N - S1_MAX[1] - S2_MAX_s[1]
    V1_l.pop(S1_MAX[0])
    S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
    ans2 = N - S1_MAX[1] - S2_MAX[1]
    print(min(ans1,ans2))
                
                         

Measured memory_bytes: 14052
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 1000000000
#define SIZE 100

int main(){
  int n,k,p;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d%d",&k,&p);

    int ans = k%p;

    if(ans==0) ans = p;

    printf("%d\n",ans);
    
  }
  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i, a, b) for(int i=a;i<b;++i)
#define per(i, a, b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

////////////////

int const H = 841;
int const W = 841;
int const INF = 1e9 + 41;

int h, w, k;
int ma[H][W], d[H][W], was[H][W], f[H][W];
int sx, sy;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};

deque<pii> q;

bool canMove(int ny, int nx){
	if(ny >= h || ny < 0) return false;
	if(nx >= w || nx < 0) return false;
	if(ma[ny][nx] == 1) return false;
	return true;
}

int calc(int y, int x){
	int ret1 = min(x, y) / k + (min(x, y) % k != 0 ? 1 : 0);
	int ret2 = min(w-1-x, h-1-y) / k + (min(w-1-x, h-1-y) % k != 0 ? 1 : 0);
	return min(ret1, ret2);
}

void solve(){
	cin >> h >> w >> k;
	rep(i, 0, h){
		string s;
		cin >> s;
		rep(j, 0, w){
			if(s[j] == '.'){
				ma[i][j] = 0;
			}else if(s[j] == '#'){
				ma[i][j] = 1;
			}else{
				sy = i;
				sx = j;
			}
		}
	}

	rep(i, 0, h) rep(j, 0, w) d[i][j] = INF;
	d[sy][sx] = 0;
	q.pb(mp(sy, sx));
	was[sy][sx] = 1;

	while(sz(q)){
		pii cur = q.front();
		q.pop_front();
		int x = cur.second;
		int y = cur.first;
		if(d[y][x] == k) continue;
		rep(i, 0, 4){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(canMove(ny, nx) && !was[ny][nx]){
				d[ny][nx] = 1 + d[y][x];
				was[ny][nx] = 1;
				q.pb(mp(ny, nx));
			}
		}
	}

	int ans = INF;

	rep(i, 0, h) rep(j, 0, w) if(was[i][j]){
		ans = min(ans, 1 + calc(i, j));
	}

	cout << ans << endl;

}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
string s;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>s;
	for (char ch:s){
		int x=ch-'A';
		x+=n;
		x%=26;
		cout<<(char)(x+'A');
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const ll INF=1e13;
ll a[2222][2222];
ll dp[422][222][222];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  rep(i,n)rep(j,m) cin>>a[i][j];
  fill(dp[0][0],dp[0][0]+422*222*222,-INF);
  dp[0][0][0]=0;
  rep(i,n+m-1)rep(j,m)rep(k,j+1){
    if(i-j>=0){
      dp[i][j][k]+=a[i-j][j];
      if(j!=k) dp[i][j][k]+=a[i-k][k];
    }
    rep(a,2)rep(b,2) MX(dp[i+1][j+a][k+b],dp[i][j][k]);
  }
  cout<<dp[n+m-2][m-1][m-1]<<endl;
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
    int64 S, T, D;
    cin >> S >> T >> D;
    vector<int64> w(D), sum(D+1, 0);
    int64 mn = 0;
    REP(i, D) {
        cin >> w[i];
        sum[i+1] += sum[i] + w[i];
        chmin(mn, sum[i+1]);
    }
    if (abs(mn) < S-T && sum[D] >= 0) {
        cout << -1 << endl;
    } else {
        int64 res = (S-T+mn)/abs(sum[D]);
        chmax(res, 0);
        S -= T;
        S -= res * abs(sum[D]);
        res *= D;
        int64 idx = 0;
        while (S > 0) {
            S += w[idx++];
            idx %= D;
            res++;
        }
        cout << res << endl;
    }
}




Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

int n,m,p;
int ds[100000];

int main() {
	cin>>n>>m>>p;
	int dmax = 0, dmin = 1e5;
	REP(i,m){
		int d;
		cin >> d;
		ds[i] = d = (d+n-p)%n;
		dmax = max(dmax, d);
		dmin = min(dmin, d);
	}
	sort(ds, ds + m);
	int ans = 1e9;
	ans = min(ans, dmax);
	if(dmin<n)ans = min(ans, n-dmin);
	FOR(i, 0, m-1){
		ans = min(ans, ds[i]*2 + n - ds[i+1]);
		ans = min(ans, (n-ds[i+1])*2 + ds[i]);
	}
	cout << ans*100 << endl;
}

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

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pll pair<ll,ll>
#define vl vector<ll>
#define vll vector < pll >
#define sl set<ll>
#define mll map<ll,ll>
#define itr :: iterator
#define pf push_front
#define ff first
#define ss second
#define stkl stack <ll>
#define quel queue <ll>
#define pquel priority_queue <ll>
#define rep(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
#define SIZE 100005
#define PI 3.14159265358979323846

#define debug(var) cout << "[" << __LINE__ << "] " << #var << " = " << (var) << endl;

struct edge {
    ll A;
    ll B; 
};

// Implementation of DSU (Union by Rank)
/*
ll parent[SIZE],rank[SIZE];

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(ll v) {
    parent[v] = v;
    rank[v] = 0;
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/
//*********************************************

ll power(ll a, ll b, ll mod){
    ll x = 1, y = a;
    while (b > 0){
        if (b%2){
            x = (x*y)%mod;
        }
        y = (y*y)%mod;
        b /= 2;
    }
    return x%mod;
}   
 
// FOR FINDING MODULAR INVERSE 

ll modular_inverse(ll n, ll mod){
    return power(n, mod-2, mod);
}


bool edgecompare(edge lhs, edge rhs) { if(lhs.B!=rhs.B)return lhs.B < rhs.B;
else return lhs.A<rhs.A;}

ll ans(ll a,ll b,ll c){
    return (b/c) - ((a-1)/c);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(25);

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll i;
    
    ll e;

    e = c*d/__gcd(c,d);

    ll count = 0;

    count+= (ans(a,b,c) + ans(a,b,d) - ans(a,b,e));
    
    cout<<(b-a+1) - count;
    /*ll n,m,i,j,k,flag=0,x;
    ll *a;//[SIZE];
    
    cin>>n;
    a = new ll[n];
    rep(i,n)
    {
        cin>>a[i];
    }

    delete a;*/

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  string A[3];
  cin>>A[0]>>A[1]>>A[2];
  ll ans = 0;
  repeat(i,N){
    int c=2;
    if(A[0][i]==A[1][i]&&A[0][i]==A[2][i]){
      c=0;
    }else if(A[0][i]==A[1][i]||A[1][i]==A[2][i]||A[2][i]==A[0][i]){
      c=1;
    }
    ans += c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		//int answer=0;
		String answer="NO";
		//List<Integer> h=new ArrayList<Integer>();
		//int af=Integer.MAX_VALUE;
		//int ai=0;
		int a[]=new int[3];
		int b[]=new int[3];
		int c[]=new int[4];
		for(int i=0;i<4;i++)
		{
			c[i]=0;
		}
		int max=0;
		int min=0;
		int sum=0;
		//int sub=0;
		//int a=0;
		//int t[]=new int[(int)Math.pow(10,5)];
		
		//入力
		Scanner sc = new Scanner(System.in);
		//ai=sc.nextInt();
		//X=sc.nextDouble();
		for(int i=0;i<3;i++)
		{
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
		}
		//String S=sc.next();
		
		//処理
		for(int i=0;i<3;i++)
		{
			if(a[i]==1)
			{
				c[0]++;
			}
			else if(a[i]==2)
			{
				c[1]++;
			}
			else if(a[i]==3)
			{
				c[2]++;
			}
			else if(a[i]==4)
			{
				c[3]++;
			}
			//
			if(b[i]==1)
			{
				c[0]++;
			}
			else if(b[i]==2)
			{
				c[1]++;
			}
			else if(b[i]==3)
			{
				c[2]++;
			}
			else if(b[i]==4)
			{
				c[3]++;
			}
		}
		//System.out.println(Arrays.toString(c));
		
		for(int i=0;i<4;i++)
		{
			if(c[i]==2)
			{
				count++;
			}
		}
		//System.out.println(count);
		if(count==2)
		{
			answer="YES";
		}
		// 出力
		//System.out.println(Arrays.toString(X))
		//System.out.println(Arrays.deepToString(td));
		System.out.println(answer);
	}
}

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

def solve(N, T, M, P, X):
    for i in range(M):
        print(sum(T) - T[P[i]] + X[i])

if __name__ == '__main__': 
    N = int(input())
    T = [int(t) for t in input().split()]
    M = int(input())
    P, X = [], []
    for i in range(M):
        p, x = map(int, input().split())
        P.append(p-1)
        X.append(x)

    solve(N, T, M, P, X)

Measured memory_bytes: 3064
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    switch(x){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        if (y==1||y==3||y==5||y==7||y==8||y==10||y==12) printf("Yes\n");
        else printf("No\n");
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        if(y==4||y==6||y==9||y==11) printf("Yes\n");
        else printf("No\n");
        break;
        case 2:
        if(y==2) printf("Yes\n");
        else printf("No\n");
        break;
    }
    return 0;   
    
}


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

char teamname[10];
int team[10];

void init()
{
	for(int i=0;i<10;i++){
		teamname[i] = NULL;
		team[i] = 0;
	}
}
int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		init();
		int match;
		for(int i=0;i<n;i++){
			cin >> teamname[i];
			for(int j=0;j<n-1;j++){
				cin >> match;
				switch(match){
					case 0:
						team[i]+=10;
						break;
					case 1:
						team[i]-=1;
						break;
					default:
						break;
				}
			}
		}
		for(int j=0;j<n-1;j++){
			for(int i=0;i<n-1-j;i++){
				if(team[i] < team[i+1]){
					int tmp=team[i+1];char tempp = teamname[i+1];
					team[i+1] = team[i];teamname[i+1] = teamname[i];
					team[i] = tmp;teamname[i] = tempp;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << teamname[i]<< endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
/*   Author : S7a2a7d   */
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define mem(arr,x) memset(arr,x,sizeof(arr))

typedef vector<ll> vi;
typedef vector<char> vc;
     
#define mp make_pair
#define ff first
#define ss second
     
const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
const int inf = 1e9 + 5;
ll lcm(ll a,ll b)
{
        return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
int max(int a,int b)
{
        if(a<b)
        return b;
        return a;
} 

int main()
{
  fast_io;
  int T=1;
 //  cin>>T;
  while(T--)
  { 
     ll n;
     cin>>n;
     ll a,b;
     vector<pair<ll int,ll int>>v;
     for(ll int i=0;i<n;i++)
     {
      cin>>a>>b;
      v.pb(mp(a,b));

     }
    vector<ll>v1,v2;
     for(auto k :v)
     {
       ll dis=k.first+k.second;
        v1.pb(dis);
     }
        for(auto k :v)
     {
       ll dis=k.first-k.second;
        v2.pb(dis);
     }

     sort(v1.begin(), v1.end());
     sort(v2.begin(),v2.end());
     ll dis1=abs(v1[0]-v1[(int)v.size()-1]);
     ll dis2=abs(v2[0]-v2[(int)v.size()-1]);
     cout<<max(dis1,dis2);
  }
}

Measured memory_bytes: 11624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	int n;
	string s;
	int k;
	cin >> n >> s >> k;
	char k_s = s[k-1];
	rep(i,s.size()){
		if(s[i]!=k_s)
			s[i] = '*';
	}
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 256