akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

long long gcd(long long x, long long y) {
  return y ? gcd(y, x % y) : x;
}
long long lcm(long long x, long long y) {
  return x/gcd(x, y)*y;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  long long n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;

  long long a = n/gcd(n, m);
  long long b = m/gcd(n, m);

  rep(i, gcd(n, m)) {
    if (s[i*a] != t[i*b]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << lcm(n, m) << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long const MX = 2e5 + 2, MOD = 1e9 + 7;
long long power(long long a, long long n){
    long long s = 1;
    for(int i = 0; i < n; i++)
        s = (s * a) % MOD;
    return s;
}
int main()
{
    int t= 1;
//    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        long long ans = power(10, n) - (((2 *power(9, n) - power(8, n)) % MOD > 0 ? (2 *power(9, n) - power(8, n)) % MOD : (2 *power(9, n) - power(8, n)) % MOD + MOD));
        //cout<<ans<<"\n";
        if(ans < 0) ans += MOD;
        ans = ans % MOD;
        cout<<ans;
    }
}




Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	int m; cin >> m;
	int a[m]; rep(i,m) cin >> a[i];
	int sum = 0;
	rep(i,m) sum += a[i];
	cout << (n - sum >= 0 ? n - sum : -1) << '\n';
	return 0;
}

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

#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)


void solve() 
{
    int n;cin>>n;
    cout<<(n+1)/2<<endl;
}

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

Measured memory_bytes: 256
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

int cm[200000];

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}
string s;


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
char arr[101][101];
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);



int n=RD(),m=RD();
if(n==m)
cout<<"Draw\n";
else if(n==1)
cout<<"Alice\n";
else if(m==1)
 cout<<"Bob\n";
 else if(n>m)
 cout<<"Alice\n";
 else
 cout<<"Bob\n";


}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>

using namespace std;

int main(){

	int num_man,num_stone,table[50],common,next_mayor,index;

	while(true){
		scanf("%d %d",&num_man,&num_stone);
		if(num_man == 0 && num_stone == 0)break;

		for(int i = 0; i < num_man; i++)table[i] = 0;

		common = num_stone;
		index = 0;

		while(true){
			if(common > 1){
				table[index]++;
				common--;
			}else if(common == 1){
				table[index]++;
				common--;

				if(table[index] == num_stone){
					next_mayor = index;
					break;
				}
			}else{ //common == 0
				common += table[index];
				table[index] = 0;
			}
			index = (index+1)%num_man;
		}
		printf("%d\n",next_mayor);
	}

	return 0;
}

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;

    int ans = 0;
    for(int i = a; i <= b; i++){
        int x = i;
        int a[5];
        int j = 0;
        while(x > 0){
            a[j] = x%10;
            x /= 10;
            j++;
        }
        int y = 10000*a[0] + 1000*a[1] + 100*a[2] + 10*a[3] + a[4];

        if(i == y) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int min(p0,p1){
  return((p0<p1)?p0:p1);
}

int max(p0,p1){
  return((p0>p1)?p0:p1);
}

int main(){
  int i,j,k=1,h,w,m=0,f[105][105][2];
  char s[105];
  scanf("%d",&h);
  scanf("%d",&w);
  for(i=0;i<h;i++){
    scanf("%s",&s);
    for(j=0;j<w;j++){
      f[i][j][0]=(s[j]=='.');
      f[i][j][1]=0;
    }
  }
  while(1){
    if(f[0][0][0]==1) f[0][0][1]=1;
    for(i=0;i<w+h-2;i++){
      for(j=max(i-h+1,0);j<min(i+1,w);j++){
        if((f[i-j][j][0]==1)&&(f[i-j][j][1]==1)){
          if(f[i-j+1][j][0]==1){
            f[i-j+1][j][1]=1;
          }else{
            if(f[i-j+1][j][1]!=1) f[i-j+1][j][1]=2;
          }
          if(f[i-j][j+1][0]==1){
            f[i-j][j+1][1]=1;
          }else{
            if(f[i-j][j+1][1]!=1) f[i-j][j+1][1]=2;
          }
        }
      }
    }
    if(f[h-1][w-1][1]==1) break;
    if(k) m++;
    k^=1;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        f[i][j][0]^=1;
        if(f[i][j][1]==2) f[i][j][1]=1;
      }
    }
  }
  printf("%d",m);
  return(0);
}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    s = S()
    t = S()
    
    dic1 = collections.defaultdict(str)
    dic2 = collections.defaultdict(str)
    
    for i in range(len(s)):
        if dic1[t[i]] == "":
            dic1[t[i]] = s[i]
        else:
            if dic1[t[i]] != s[i]:
                print("No")
                exit(0)

        if dic2[s[i]] == "":
            dic2[s[i]] = t[i]
        else:
            if dic2[s[i]] != t[i]:
                print("No")
                exit(0)
        
    print("Yes")

main()


Measured memory_bytes: 10280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
bool debug=false;
/*---------------------------------------------------*/
 
ll gcd(ll a,ll b){
  if(a>b)swap(a,b);
  ll ret=b;
  while(ret%a!=0){
    ret+=b;
  }
  return ret;
}
 
int main(){
  int n;
  ll t[105];
  cin>>n;
  rep(i,n)cin>>t[i];
  sort(t,t+n);
  ll ans=t[0];
  for(int i=1;i<n;i++){
    ans=gcd(ans,t[i]);
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==0) return 1LL;
	if(b==1) return a;
	if(b%2==0) return POW(a*a%INF,b/2);
	return a*POW(a,b-1)%INF;
}

int main(){
	int n;
	cin >> n;
	int d[2*n];
	d[0] = 1;
	string s;
	cin >> s;
  if(s[0] == 'W' || s[2*n-1] == 'W'){
		cout << 0 << endl;
		return 0;
	}
	REP(i, 2*n-1){
		if(s[i+1] == s[i]) d[i+1] = -d[i];
		else d[i+1] = d[i];
	}
	int c = 0;
	REP(i, 2*n) if(d[i] == 1) c++;
	if(c != n){
		cout << 0 << endl;
		return 0;
	}
	ll fac[250000];
	fac[0] = 1;
	REP(i, 249999){
		fac[i+1] = (fac[i]*(i+1))%INF;
	}
	int p = 0, m = 0;
	ll ans = 1;
	REP(i, 2*n){
		if(d[i] == 1) p++;
		else m++;
		if(p < m){
			cout << 0 << endl;
			return 0;
		}
		if(i == 2*n-1 || (d[i] == -1 && d[i+1] == 1)){
			ans *= fac[p] * POW(fac[p-m], INF-2) %INF;
			ans %= INF;
			p -= m;
			m = 0;
		}
	}
	cout << (ans * fac[n])%INF << endl;
	return 0;
} 


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

int main() {
  char a,b;
  cin >> a >> b;
  (int)(a -= 'A');
  (int)(b -= 'A');
  
  if(a > b) cout << ">" << endl;
  if(a == b) cout << "=" << endl;
  if(a < b) cout << "<" << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
lis = [int(input()) for i in range(n)]
if lis[0] != 0:print(-1);exit()
ans = 0
for i in range(n-1,0,-1):
    if lis[i] - lis[i-1] > 1:print(-1);exit()
    elif lis[i] - lis[i-1] == 1:ans += 1
    else:ans += lis[i]
print(ans)

Measured memory_bytes: 11052
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int K = sc.nextInt();
      if(N%K==0){
        System.out.println(0);
      }else{
        System.out.println(1);
      }
    }
}

Measured memory_bytes: 35868
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  long long X;
  cin>>n>>X;
  long long x[n];
  REP(i,n){
    cin>>x[i];
  }
  long long d;
  long long temp;
  REP(i,n){
    temp = x[i]-X;
    if(i==0){
      d = max(temp,-temp);
    }else{
      d = gcd_(d,max(temp,-temp));
    }
  }
  cout<<d<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  int top = y + r;
  int bottom = y - r;
  int left = x - r;
  int right = x + r;
  if (top <= H && bottom >= 0 && left >= 0 && right <= W)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3132
N,K=map(int,input().split())
A=[int(input()) for i in range(N)]

for i in range(N):
    A[i]-=K

from itertools import accumulate
S=[0]+list(accumulate(A))

SORTED_S=sorted(set(S)|{-1<<63})
compression_dict={a: ind for ind, a in enumerate(SORTED_S)}

LEN=len(compression_dict)

BIT=[0]*(LEN+1) # 1-indexedなtree

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

ANS=0
for i in range(N+1):
    ANS+=getvalue(compression_dict[S[i]])
    update(compression_dict[S[i]],1)

print(ANS)

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

using namespace std;
using ll = long long;

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

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

    for(int i = 0; i < k; ++i) {
        if(b <= a) {
            b *= 2;
        } else if(c <= b) {
            c *= 2;
        }
        if(a < b && b < c) {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");

    return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long x = Math.abs(Long.parseLong(sc.next()));
        long k = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        long result = 0;
        long base = d * 2;
        if ((x % d == 0 && k <= x / d) || (x % d != 0 && k <= (x / d + 1))) {
            result = Math.abs(x - k * d);
        } else if (k % 2 == 0) {
            long mlt = (long) Math.ceil((double) x / base);
            long right = base * mlt;
            long left = right - base;
            long plus = Math.min(Math.abs(x + right), Math.abs(x + left));
            long minus = Math.min(Math.abs(x - right), Math.abs(x - left));
            result = Math.min(plus, minus);
        } else if (k == 1) {
            long plus = Math.abs(x + d);
            long minus = Math.abs(x - d);
            result = Math.min(plus, minus);
        } else {
            long mlt = (long) Math.ceil(Math.ceil((double) x / d) / 2.0);
            long right = base * mlt + d;
            long left = right - base;
            long plus = Math.min(Math.abs(x + right), Math.abs(x + left));
            long minus = Math.min(Math.abs(x - right), Math.abs(x - left));
            result = Math.min(plus, minus);
        }

        // 出力
        System.out.println(result);
    }
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m;
string s;

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

    VVl dm(n, Vl(n, 1e18));
    V<V<P<ll, int>>> edges(n);
    REP(i, m) {
        int s,t,d; cin >> s >> t >> d;
        edges[s].push_back({d, t});
        dm[s][t] = d;
    }

    Vl d(n, 1e18);
    unordered_set<int> toUpdate;
    toUpdate.insert(0);
    d[0] = 0;
    REP(i, n) {
        unordered_set<int> toUpdateBuf(toUpdate);
        toUpdate.clear();
        FOR(j, toUpdateBuf) {
            int node = *j;
            FOR(k, edges[node]) {
                int dist = k->second;
                ll cost = k->first;
                if (d[dist] > d[node] + cost) {
                    d[dist] = d[node] + cost;
                    toUpdate.insert(dist);
                    if (i == n - 1) {
                        cout << "NEGATIVE CYCLE" << endl;
                        return 0;
                    }
                }
            }
        }
        if (toUpdate.empty()) break;
    }

    REP(i, n) dm[i][i] = 0;

    REP(k, n) REP(i, n) REP(j, n) {
        if (dm[i][k] == 1e18 || dm[k][j] == 1e18) continue;
        dm[i][j] = min(dm[i][j], dm[i][k] + dm[k][j]);
    }

    REP(i, n) {
        REP(j, n) {
            if (dm[i][j] == 1e18) {
                std::cout << "INF";
            } else {
                std::cout << dm[i][j];
            }
            if (j != n-1) {
                std::cout << ' ';
            }
        }
        std::cout << '\n';
    }

    return 0;
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}


int main() {
    int k,x;
    cin >> k >> x;
    int sum = 500*k;
    if(sum >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3544
using System;
using System.Linq;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var k = int.Parse(_[1]);
            var h = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var count = h.Count(i => i >= k);
            Console.WriteLine(count);
        }
    }
}


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

int main() {
  int A, B, j;
  j = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    if (A / 10000 == A % 10 && (A / 1000) - ((A / 10000) * 10) == A / 10 % 10) {
      j++;
    }
    A++;
  }
  cout << j << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int bin_pow(int x, int m) {
    int res = 1;
    while (m) {
        if (m & 1) res = res * x;
        x = x * x;
        m >>= 1;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    int ans = 0;
    int cnt = 0;
    int len = 1;
    int p = 26;
    while (cnt + p < n) {
        cnt += p;
        p *= 26;
        len++;
    }
    n -= cnt;
    string s;
    n--;
    while (len) {
        int k = (n / bin_pow(26, len - 1));
        s += char(k + 'a');
        n -= k * bin_pow(26, len - 1);
        len--;
    }
    cout << s << "\n";


    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
#define Repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Inf 1LL<<60
#define All(v) v.begin(),v.end()
#define Mod (ll)(1e9+7)
using namespace std;
typedef long long ll;

int main()
{
    ll n,w[100]={0},sum=0;
    cin>>n;
    Rep(i,n){
        cin>>w[i];
        sum+=w[i];
    }
    ll s1=0,s2=sum,tmp=sum;
    Rep(i,n){
        s1+=w[i];
        s2-=w[i];
        if(abs(s2-s1)<tmp){
            tmp=abs(s2-s1);
        }else{
            break;
        }
    }
    cout<<tmp<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

template<class T> struct  SegTree{
    typedef  function<T(T, T)> F;
    int n = 1;
    vector<T> node;
    T et;
    F f, g;

    SegTree(int n_, T et_, F f_, F g_):
    et(et_), f(f_), g(g_){
        while(n < n_) n *= 2;
        node.resize(n*2-1, et);
    }

    void update(int i, T x){
        i += n-1;
        node[i] = g(node[i], x);
        while(i){
            i = (i-1) / 2;
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }

    T query(int a, int b){
        T vl = et, vr = et;
        for(a+=n-1, b+=n-1; a<b; a=(a-1)/2, b=(b-1)/2){
            if(!(a&1)) vl = f(vl, node[a++]);
            if(!(b&1)) vr = f(node[--b], vr);
        }
        return f(vl, vr);
    }
};

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    auto f = plus<lint>();
    SegTree<lint> st(n, 0, f, f);

    while(q--){
        int c, x, y;
        scanf("%d%d%d", &c, &x, &y);
        if(c == 0) st.update(x-1, y);
        else printf("%d\n", st.query(x-1, y));
    }
}


Measured memory_bytes: 4908
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
bool check(string s)
{
	for (int i=0; i<sz(s); i++)
	{
		if (s[i]!=s[sz(s)-i-1])
			return false;
	}
	return true;
}
void solve()
{
//Read Comments below main
	int h,w,k;
	cin>>h>>w>>k;
	vector<string> arr(h+1);
	for (int i=1; i<=h; i++)
	{
		cin>>arr[i];
		arr[i]="a"+arr[i];
	}
	ll ans=1e9;
	for (int i=0; i<(1<<(h-1)); i++)
	{
		// int counter=0;
		v64 pos(11,0);
		int r=1;
		ll cur=0;
		for (int j=1; j<=h; j++)
		{
			pos[j]=r;
			if (i & (1<<(j-1)))
			{
				r++;
				cur++;
			}
		}
		v64 count(11,0);
		for (int j=1; j<=w; j++)
		{
			v64 temp(11,0);
			bool f=1;
			for (int l=1; l<=h; l++)
			{
				if (arr[l][j]=='1')
				{
					temp[pos[l]]++;
					count[pos[l]]++;
					if (temp[pos[l]]>k)
						cur=1e9;
					if (count[pos[l]]>k)
						f=0;
				}
			}
			if (f==0)
			{
				cur++;
				count=temp;
			}
		}
		ans=min(ans,cur);
	}
	cout<<ans<<endl;
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vi a(n);
    vi con;
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
        if(a[i]%10!=0) con.push_back(a[i]);
    }
    sort(con.begin(),con.end());
    int ans = 0;
    if(sum%10!=0){
        ans = sum;
    }else if(con.size()==0){
        ans = 0;
    }else{
        ans = sum - con[0];
    }
    cout << ans << endl;
}

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

#define PI 3.141592

int main(void){
	int r, deg, c_deg;
	double x, y;

	x = y = 0;
	c_deg = 90;

	while(1){
		scanf("%d,%d", &r, &deg);
		if(r == 0 && deg == 0){
			break;
		}
		x += r*cos(c_deg*PI/180.0);
		y += r*sin(c_deg*PI/180.0);

		c_deg -= deg;
	}
	
	printf("%d\n", (int)x);
	printf("%d\n", (int)y);
	return 0;
}

Measured memory_bytes: 604
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[]
  for i in range(1<<n):
    _l=[]
    for j in range(n):
      _l.append(1 if i&(1<<j) else 0)
    l.append(_l)

  l2=[]
  for _ in range(n):
    a=I()
    _l2=[]
    for __ in range(a):
      _l2.append(LI())
    l2.append(_l2)

  ans=0
  for x in l:
    f=True
    for i,y in enumerate(x):
      if y==1:
        for z1,z2 in l2[i]:
          if x[z1-1]!=z2:
            f=False
            break
        if not f:
          break
    if f:
      ans=max(ans,x.count(1))

  return ans

# main()
print(main())


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

	string s;
	string answer;

	cin >> s;

	answer = s[0];

	for (int i = 1; i < s.size(); i++) { 
		
		if (i % 2 == 0 ) {
			answer = answer + s[i];
		}
	}

	cout << answer << endl;

	return 0;

}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[m];
        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < m; i++) {
            set.add(sc.nextInt());
        }
        
        int cost1 = 0;
        for (int i = x; i <= n; i++) {
            if (set.contains(i)) cost1++;
        }

        int cost2 = 0;
        for (int i = x; i >= 0; i--) {
            if (set.contains(i)) cost2++;
        }

        System.out.println(Math.min(cost1, cost2));
        
    }
}

Measured memory_bytes: 35788
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define endl "\n"



void solve(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;
    

    
    while(b<=a){
       
        b*=2;
        k--;
    }
    while(c<=b){
        
        c*=2;
        k--;
    }
   
    if(k>=0){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
        
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   solve();
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;

int n;
int b[102];
int ans = 0;

int main() {
   cin >> n;
   b[0] = 100001;
   b[n] = 100001;
   rep(i, n-1) cin >> b[i+1];
   rep(i, n+1) ans += min(b[i], b[i+1]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main() -> int:
    a = next_str()
    b = next_str()
    print(("GREATER", "LESS", "EQUAL")[judge(a, b)])
    return 0


def judge(a: str, b: str) -> int:
    case = len(a) - len(b)
    if case > 0:
        return 0
    elif case < 0:
        return 1
    else:
        for i in range(len(a)):
            case = ord(a[i]) - ord(b[i])
            if case > 0:
                return 0
            elif case < 0:
                return 1
    return 2


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
//Krunal_Mathukiya
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define li long int
#define pb push_back
#define mkp make_pair
#define nikalL return
#define chalavo continue
#define basHo break
#define umap unordered_map
#define fr(i,s,n) for(int i=s;i<=n;++i)
#define frr(i,s,n) for(int i=s;i>=n;--i)
#define jaldiKarNe ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
int n;
int arr[22][22];
int dp[22][3000000];
int vis[22][3000000];
// umap<int,umap<lli,int> >dp,vis;
lli fn(int i,lli bit) {
	if(i>n) return 1;
	if(vis[i][bit]) return dp[i][bit];
	vis[i][bit]=1;
	lli curr=0;
	fr(j,1,n) {
		if(arr[i][j] && !(((lli)1<<(j-1)) & bit))
			curr=(curr+fn(i+1,bit+((lli)1<<(j-1))))%mod;
	}
	return dp[i][bit]=curr;
}
int main(){
	jaldiKarNe;
	cin>>n;
	fr(i,1,n) fr(j,1,n) cin>>arr[i][j];
	cout<<fn(1,0);
}


Measured memory_bytes: 183724
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ll X, t; cin >> X >> t;
  cout << (X < t ? 0 : X - t) << endl;
  return 0;
}


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

int main () {
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
cout <<"YES" << endl;
}
else {
cout <<"NO" << endl;
}

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

typedef pair<int,int> P;

class State{
public:
  int id,del,cost;
  State(){}
  State(int _id,int _del,int _cost){
    id = _id;
    del = _del;
    cost = _cost;
  }

  bool operator<(const State &st)const{
    return cost > st.cost;
  }
};

int n,m,c;
vector<P> t[102];

int main(void){
  while(scanf("%d%d%d",&n,&m,&c),n||m||c){
    rep(i,n+1) t[i].clear();
    rep(i,m){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      t[a].push_back(P(b,c));
    }

    priority_queue<State> open;
    bool closed[102][1002];
    open.push(State(1,0,0));
    memset(closed,0,sizeof(closed));

    int ans = INT_MAX;

    while(!open.empty()){
      State st = open.top(); open.pop();
      if(closed[st.id][st.del]) continue;
      closed[st.id][st.del] = true;

      if(st.id == n){
        ans = min(ans,st.del);
        continue;
      }

      rep(i,t[st.id].size()){
        P e = t[st.id][i];
        if(st.cost + e.second <= c && !closed[e.first][st.del]){
          open.push(State(e.first,st.del,st.cost+e.second));
        }
        if(st.del+1 <= m && !closed[e.first][st.del+1]){
          open.push(State(e.first,st.del+1,st.cost));
        }
      }
    }

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

Measured memory_bytes: 6800
{-# LANGUAGE BangPatterns, MagicHash #-}
import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))
import Data.Tuple
import Data.Ord (Down(..))
import Data.Coerce
                                 
query :: Int -> [(Int,Int)] -> Int
query n =
  fromJust . findIndex M.null
  . iterate (\m -> snd $ M.split (snd (M.findMin m) - 1) m)
  . foldl' (\m (y,x) -> let (_,m') = M.split x m in M.insert x y m') M.empty
  . (coerce :: [(Down Int, Int)] -> [(Int, Int)])
  . sort . (coerce :: [(Int,Int)] -> [(Down Int, Int)])
     
main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  bas <- replicateM m $ (\(x:y:_)->(y,x)) . map read . words  <$> getLine
  putStrLn $ show $ query n bas


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

using namespace std;
 
int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> v(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    queue<int> que;
    que.push(0);

    vector<int> guide(n, -1);
    guide[0] = 0;

    while (!que.empty()) {
        int room = que.front();
        que.pop();
        for (int x : v[room]) {
            if (guide[x] != -1) continue;

            guide[x] = room;
            que.push(x);
        }
    }

    bool flag = true;
    for (int i = 0; i < n; i++) {
        if (guide[i] == -1) {
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i++) cout << guide[i] + 1 << endl;
    }
    else cout << "No" << endl;

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size(); i++){
    if (s.at(i) == 'p') count++;
  }
  cout << s.size() / 2 - count << endl;
}

Measured memory_bytes: 512
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long int

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    vector<ll> sum;
    sum.reserve(n+1);
    sum.push_back(0);
    ll b = 0;
    for(int i = 0;i < n;i++)
    {
        b += a[i];
        sum.push_back(b);
    }
    ll m = 1e16;
    for(int i = 0;i < n-1;i++)
    {
        ll f = sum[i+1];
        ll s = sum[n] - f;
        m = min(m, abs(f-s));
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 3328
S = input()
S = S[::-1]
mod = 10 ** 9 + 7

dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]
dp[0][0] = 1
rem13 = 1
for i in range(len(S)):
    rem13 = (10 ** (i % 6)) % 13
    for j in range(13):
        if S[i] == '?':
            for k in range(10):
                dp[i + 1][j] += dp[i][(j - rem13 * k) % 13]
        else:
            dp[i + 1][j] += dp[i][(j - rem13 * int(S[i])) % 13]
    for j in range(13):
        dp[i+1][j] %= mod

print(dp[-1][5])


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

using namespace std;

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int cnt = 0;
  while(A >= B){
    B *= 2;
    ++cnt;
  }
  
  while(B >= C){
    C *= 2;
    ++cnt;
  }
  
  if(cnt <= K) puts("Yes");
  else puts("No");
  
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h> 
#include<stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


void find(int k){
  Node x=root;
  int flag=0;
  while(x!=NIL){
    if(x->key==k)flag=1;
    if(k<x->key)x=x->left;
    else x=x->right;
  }if(flag)printf("yes\n");
  else printf("no\n");
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  if(x==NIL){
    root=z;
  }else{
    while(x!=NIL){
      if(x->key>=k){
	y=x->left;
      }else {
	y=x->right;
      }
      if(y!=NIL) {
	y->parent=x;
      }else{
	if(x->key>=k) x->left=z;
	else x->right=z;
      }
      x=y;
    }
  }
}
  
void inorder(Node s){
  if(s==NIL)return;
  inorder(s->left);
  printf(" %d",s->key);
  inorder(s->right);
}
void preorder(Node s){
  if(s==NIL)return;
  printf(" %d",s->key);
  preorder(s->left);
  preorder(s->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      find(x);
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
    
    }else if ( com[0] == 'f'){
      scanf("%d",&x);
      find(x);
    }
  }

  return 0;
}





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

int main(){
    int N, K, a[55], sum = 0;
    cin >> N >> K;
    for(int i = 0; i < N; i++)cin >> a[i];

    sort(a, a + N, greater<int>());
    for(int i = 0; i < K; i++){
        sum += a[i];
    }
    cout << sum << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

namespace std{
	template<>
	struct hash<P>{
		size_t operator()(const P &x) const{
			return hash<llong>()(x.first) ^ (hash<llong>()(x.second) << 1);
		}
	};
}

int main(){
	llong N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	bool check = false;
	N--;
	for(int i = 0; i < N; i++){
		llong mini = A + C*i - D*(N-i);
		llong maxi = A + D*i - C*(N-i);
		if(mini <= B && B <= maxi)
			check = true;
	}

	if(check)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#A - Hitachi String
S = list(input())
count = 0
if len(S) % 2 == 1:
    print("No")
    exit()
else:

    for i in range(0,int(len(S)//2),2):
        if S[i]+S[i+1] == "hi":
            pass
        else:
            print("No")
            exit()

    print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h,w,d;
    cin>>h>>w>>d;
    vector<pair<int,int>> vec(h*w);
    rep(i,h) rep(j,w) {
        int a;
        cin>>a;
        a--;
        vec[a]={i,j};
    }
    
    vector<map<int,int>> cost(h*w);
    rep(i,d) {
        int pre=i;
        int now=i+d;
        while(now<h*w) {
            cost[i][now]=cost[i][pre]+abs(vec[pre].first-vec[now].first)+abs(vec[pre].second-vec[now].second);
            pre+=d;
            now+=d;
        }
    }
    int  q;
    cin>>q;
    while(q--) {
        int l,r;
        cin>>l>>r;
        l--;r--;
        cout<<cost[r%d][r]-cost[l%d][l]<<endl;
    }
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       
        string s;cin>>s;
        if(s[1]=='R')
        s[1]='B';
        else
        s[1]='R';
        cout<<s;
}


Measured memory_bytes: 3648
n = int(input())
A = list(map(int, input().split()))
q = int(input())

for i in range(q):
    queryi = list(map(int, input().split()))
    b = queryi[0]
    e = queryi[1]
    t = queryi[2]

    for i in range(e-b):
        temp = A[b+i]
        A[b+i] = A[t+i]
        A[t+i] = temp

print(*A)


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[110000], B[110000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i] >> B[i]; }
    int ans = 0;
    for (int i = N - 1; i >= 0; i--) { ans += (B[i] - (A[i] + ans) % B[i]) % B[i]; }
    cout << ans << endl;
}

Measured memory_bytes: 5136
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;
Int sum[100000+10];
int main(void) {
    Int N,M;
    cin>>N>>M;
    int maxl = -1;
    int minr = 100000+10;
    for(int i = 0;i < M;i++) {
        int l,r;
        cin>>l>>r;
        maxl = max(l,maxl);
        minr = min(r,minr);
    }

    if(maxl <= minr) {
        cout<<minr-maxl+1<<endl;
    } else {
        cout<<0<<endl;
    }

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;


int main() {
	int A,B;
		cin >> A >> B;

		if (A <= 8 && B <= 8)cout <<"Yay!"<< endl;
		else cout << ":(" << endl;
	return 0;
}



Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    for(int i=0; i<n; ++i)
        cin >> x[i] >> y[i] >> h[i];

    for(int cy=0; ; ++cy){
        for(int cx=0; cx<=100; ++cx){
            int height = INT_MAX;
            for(int i=0; i<n; ++i){
                int tmp = h[i] + abs(y[i] - cy) + abs(x[i] - cx);
                height = min(height, tmp);
            }

            bool ok = true;
            for(int i=0; i<n; ++i){
                int tmp = max(0, height - abs(y[i] - cy) - abs(x[i] - cx));
                if(tmp != h[i]){
                    ok = false;
                    break;
                }
            }

            if(ok){
                cout << cx << ' ' << cy << ' ' << height << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import math
a,b,h,m=tuple(map(int,input().split()))
t=60*h+m
ka=min((t*5.5)%360,360-((t*5.5)%360))
c=a**2+b**2-2*a*b*math.cos(math.radians(ka))
l=math.sqrt(c)
print(l)

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    map<char,int> m;
    rep(i,3){
        char c; cin >> c;
        m[c]++;
    }

    if(m['a']==m['b'] && m['b']==m['c']){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3572
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
n = int(input())
#a, b, c, d = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

a = []
for i in range(n):
    a.append(input())

c = collections.Counter(a)
print(len(c))


Measured memory_bytes: 38860