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

vector<int>MOD={1000000021,
1000000033,
1000000087,
1000000093,
1000000097,
1000000103,
1000000123,
1000000181};


struct Edge{
  int to;
  long long int cost;
  Edge(const int t,const int c){
    to=t,cost=c;
  }
};

struct Stedge{
  int a,b,cost;
  Stedge(const int aa,const int bb,const int cc){
    a=aa,b=bb,cost=cc;
  }
};

ll binpow(ll x, ll e, ll mod) {
  ll ret = 1, p = x;
  while(e > 0) {
    if(e%2 == 0) { (p *= p) %= mod; e /= 2; }
    else { (ret *= p) %= mod; e--; }
  }
  return ret;
}

signed main() {

  int N,M;
  cin>>N>>M;
  vector<Stedge>stedge;
  for(int i=0;i<M;i++){
    int l,r,k;
    cin>>l>>r>>k;
    l--;
    r--;
    stedge.push_back(Stedge(l,r,k));
  }
  for(auto md:MOD){
    vector<vector<Edge>>edge(N);
    for(auto i:stedge){
     edge[i.a].push_back(Edge(i.b,i.cost));
     edge[i.b].push_back(Edge(i.a,binpow(i.cost,md-2,md)));
    }
  //  cout<<"md "<<md<<endl;
    vector<int>used(N);
    vector<long long int>ans(N,-1);
    for(int i=0;i<N;i++){
      if(used[i])continue;
     // cout<<"st "<<i<<endl;
      queue<int>Q;
      Q.push(i);
      ans[i]=1;
      used[i]=1;
      while(!Q.empty()){
        int cn=Q.front();
        used[cn]=1;
        Q.pop();
        for(auto j:edge[cn]){
          //cout<<ans[cn]<<" "<<j.to<<" "<<j.cost<<" "<<ans[cn]<<" "<<ans[cn]*j.cost%md<<" "<<ans[j.to]<<endl;
          if((ans[cn]*j.cost)%md!=ans[j.to]&&ans[j.to]!=-1){
            cout<<"No\n";
            return 0;
          }
          if(ans[j.to]==-1)Q.push(j.to);
          ans[j.to]=(ans[cn]*j.cost)%md;
        }
      }
    }
  }
  cout<<"Yes\n";
  return 0;
}


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

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    stack = [u[0]-1]
    answer = [-1]*N
    tree = [{} for _ in range(N)]
    for i in range(N-1):
        is_even = (w[i] % 2 == 0)
        tree[u[i]-1][v[i]-1] = is_even
        tree[v[i]-1][u[i]-1] = is_even
    answer[u[0]-1]=0
    #1なら訪問済み
    while stack:
        p = stack.pop()
        neighbors = tree[p]
        for n in neighbors:
            if answer[n]<0:
                answer[n] = answer[p] if neighbors[n] else 1-answer[p]
                stack.append(n)

    for a in answer:
        print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53756
def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0

a, b = map(int, input().split())
print(f(a-1) ^ f(b))

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

bool comp(const pair<string,int> &a,const pair<string,int> &b){
    if(a.second==b.second){
        return a.first<b.first;
    }
    return a.second>b.second;
}

int main() {
 int n;
 cin>>n;
 int i=0;
 map<string,int> m;
 string temp;
 while(i<n){
     cin>>temp;
     m[temp]++;
     i++;
 }
 vector<pair<string,int>> p;

for(auto it=m.begin();it!=m.end();it++){
    string w; int y;
    w=it->first;
    y=it->second;
    p.push_back(make_pair(w,y));
}

 
 sort(p.begin(),p.end(),comp);
 

cout<<p[0].first<<endl;
int prev=p[0].second;
for(int i=1;i<p.size();i++){
    if(m[p[i].first]==prev){
        cout<<p[i].first<<endl;
    }
}

 

 
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    VI L(N); REP(i,N) cin >> L[i];
    SORT(L); REVERSE(L);
    int ans = 0;
    REP(i,N-1)FOR(j,i+1,N){
        int l = j, r = N, n = (l+r)/2;
        while(r-l>1){
            if(L[n] + L[j] <= L[i]) r = n;
            else l = n;
            n = (l+r)/2;
        }
        ans += r-j-1;
    }
    cout << ans << endl;
    return 0;
}

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

import numpy as np
S=int(input())

MOD=10**9+7

D=[0]*(S+1)
D[0]=1

L=0
for i in range(3,S+1):
    L+=D[i-3]
    D[i]=L
    D[i]%=MOD

ans=D[S]

print(int(ans))

Measured memory_bytes: 27240
#include<bits/stdc++.h>
using namespace std;
int s[505][505];
int n,m,l,x,y;
int main()
{
  
    scanf("%d%d%d",&n,&m,&l);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        s[x][y]++;
    }
    for(int i = 1;i <= n;i++)
        for(int j = i + 1;j <= n;j++)
            s[i][j] += s[i][j - 1];
    for(int i = 1;i <= n;i++)
        for(int j = i - 1;j >= 1;j--)
            s[j][i] += s[j + 1][i];
    for(int i = 1;i <= l;i++)
    {
        scanf("%d%d",&x,&y);
        printf("%d\n",s[x][y]);
    }
    return 0;
}

Measured memory_bytes: 1920
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
  int N, A;
  cin >> N >> A;
  N = pow(N, 2);
  N = N - A;

  cout << N << endl;
}

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

int main() {
    int N; cin >> N;
    vector<int64_t> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<int64_t>());
    int64_t a = 0;
    rep(i, N - 1) {
        if(A[i] == A[i + 1]) {
            if(a) {
                cout << a * A[i] << '\n';;
                return 0;
            } else {
                a = A[i];
                i++;
            }
        }
    }
    cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()


int main(){
    int N;
    cin >> N;
    while(N > 0){
        if(N %10 == 7){
            cout << "Yes" << endl;
            return 0;
        }
        N = N/10;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define mo 1000000007
int n,ans;
char s[M];
int pre[M][2],f[M],g[M];
void work() {
    for(int i=n;i>=1;i--)
	{
	    if(s[i]=='a')
		{
		    pre[i-1][0]=i;
		    pre[i-1][1]=pre[i][0];
		    if(i==n) pre[i-1][1]=-1;
		}
	    else
		{
		    pre[i-1][1]=i;
		    pre[i-1][0]=pre[i][1];
		    if(i==n) pre[i-1][0]=-1;
		}
	}
    f[0]=1;
    for(int i=0;i<n;i++)
	{
	    if(pre[i][0]!=-1) f[pre[i][0]]=(f[pre[i][0]]+f[i])%mo;
	    if(pre[i][1]!=-1) f[pre[i][1]]=(f[pre[i][1]]+f[i])%mo;
	}
    for(int i=n;i>=1;i--) g[i]=(g[i+1]+(s[i]=='a'?1:2))%3;
    for(int i=1;i<=n;i++) if(!g[i+1]) ans=(ans+f[i])%mo;
    cout<<ans<<'\n';
}
int main()
{
    int tp=0;
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++) if(s[i]==s[i-1]) tp=1;
    if(tp) work();
    else cout<<1<<'\n';
    return 0;
}

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

int main(){
  int n;cin >> n;
  vector<int> a(n),b={};
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++){
    if(i%2==0)b.insert(b.begin(),a[i]);
    else b.push_back(a[i]);
  }
  if(n%2==1){
    for(int i=0;i<n;i++)cout << b[i] << " ";
  }else{
    for(int i=n-1;i>=0;i--)cout << b[i] << " ";
  }
}

Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int r = scanner.nextInt();


        System.out.println(r + 100 * (10 - Math.min(n, 10)));
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	long long int n[t];
	for(int i = 0; i < t; i++){
		long long int a;
		cin>>a;
		n[i] = a;
	}
	long long int cost[t];
	fill(cost, cost + t, LLONG_MAX);
	cost[0] = 0;
	for(int i = 0; i < t - 1; i++) {
		if(i < t - 2) {
			cost[i + 1] = min(cost[i + 1], cost[i] + abs(n[i] - n[i + 1]));
			cost[i + 2] = min(cost[i + 2], cost[i] + abs(n[i] - n[i + 2]));
		} else cost[i + 1] = min(cost[i + 1], cost[i] + abs(n[i] - n[i + 1]));
	}
	cout<<cost[t - 1];
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;
typedef unsigned long long ll;
bitset<61> a[100005];

int main() {
  int n;
  cin >> n;
  bitset<61> tmp(0);
  for(int i = 0; i < n; i++) {
    ll A; cin >> A;
    a[i] = A;
    tmp ^= A;
  
  }
  
   for(int i = 0; i < n; i++) {
    for(int j = 0; j <= 65; j++) {
      if(tmp[j] == 1) {
	a[i][j] = 0;
      }
    }
  }

  
   int rank = 0;
   for(int i = 60; i >= 0; i--) {
     int j = rank;
     while(j < n && a[j][i] == 0) j++;
     if(j == n) continue;
     swap(a[rank],a[j]);
     for(int k = 0; k < n; k++) {
       if(k == rank) continue;
       if(a[k][i] == 0) continue;
       a[k] ^= a[rank];
     }
     rank++;
   }

   for(int i = 1; i < n; i++) a[0] ^= a[i];
     a[0] <<= 1;
     cout << a[0].to_ullong() + tmp.to_ullong() << endl;
      
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[] args){

  Scanner sc = new Scanner(System.in);
  int i = 1;
  while(true){
;
    int x = sc.nextInt();
    if(x == 0){
      break;
    }else{

      System.out.println("Case "+ i+": "+x);
    }
    i++;
    }
  }
}



Measured memory_bytes: 41372
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;


    public static long count, N;
    public static HashMap<Long, Integer> map;
    static void solve(InputReader in, PrintWriter out){
        map = new HashMap<>();
        map.put(1l,1);
        N = in.nl();
        map.put(N,1);
        count = 1;
        for (long i = 2; i*i <= N; i++) {
            if(N%i==0){
                check(i);
                check(N/i);
            }
        }
        N--;
        for (long i = 1; i*i <= N; i++) {
            if(N%i==0){
                if(!map.containsKey(i)){
                    map.put(i,1);
                    count++;
                }
                if(!map.containsKey(N/i)){
                    map.put(N/i,1);
                    count++;
                }
            }
        }
        out.println(count);
    }
    public static void check(long x){
        long n = N;
        while(n%x==0) n /= x;
        if((n-1)%x==0){
            if(!map.containsKey(x)){
                map.put(x,1);
                count++;
            }
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    int n;  cin>>n;
    mk(a, n+1, int);    forI(i, 1, n)   cin>>a[i];

    int dp[n+1][n+1];
    
    forD(i, 1, n)   forI(j, i, n){
        if(i == j)  dp[i][j] = a[i];
        else{
            dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]);
        }
    }
    cout<<dp[1][n]<<endl;
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 49768
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    cout << (1000-n%1000)%1000 << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

ll mod=1000000007;

ll func(ll x,ll y){
    ll r=1;
    for(ll i=0;i<x;i++){
        r=r*y%mod;
    }
    return r;
}

int main(){
    ll n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    if(n==2){
        cout<<2<<endl;
        return 0;
    }
    ll ans=func(n,10)-func(n,9)*2+func(n,8);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    int N = S.length();
    
    long sum = 0;
    for(int i = 0; i < 1<<(N-1); i++){
      int n = 0;
      for(int j = 0; j < N; j++){
        if((1 & i>>j) == 1){
          sum += Long.parseLong(S.substring(n, j+1));
          n = j+1;
        }
      }
      sum += Long.parseLong(S.substring(n, N));
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 26836
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
sticks = []
for i in c:
    s = c[i]
    if s >= 4:
        sticks.append(i)
    if s >= 2:
        sticks.append(i)
if len(sticks) < 2:
    print(0)
else:
    sticks.sort(reverse=True)
    print(sticks[0]*sticks[1])
 






Measured memory_bytes: 18592
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}


int main(){
    ll dp[210][210];
    int a[210];

    int n;
    cin >> n;
    int x = 0;
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        if(c == 'U'){
            a[x++] = 0;
        }
        else if(c == 'D'){
            a[x++] = 1;
        }

    }

    for(int i = 0; i < 210; i++){
        for(int j = 0; j < 210; j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    for(int i = 1; i <= x; i++){
        for(int j = 0; j <= x; j++){
            if(a[i-1] == 0){
                dp[i][j] = add(dp[i][j], mul(j, dp[i-1][j]));
                dp[i][j+1] = add(dp[i][j+1], dp[i-1][j]);
            }
            else{
                if(j-1 >= 0){
                    dp[i][j-1] = add(dp[i][j-1], mul(j, mul(j, dp[i-1][j])));
                }
                dp[i][j] = add(dp[i][j], mul(dp[i-1][j], j));
            }
        }
    }

    cout << dp[x][0] << endl;


    return 0;
}



Measured memory_bytes: 3456
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n, a, b;
	cin >> n >> a >>b;
	cout << min(n * a, b);
	return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H, W;
  cin >> H >> W;

  vector<string> S(H);

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


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

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){

      if(S[i][j] == '#')
        continue;
      
      int count = 0;
      for(int d = 0; d < 8; d++){
        int ni = i + dx[d];
        int nj = j + dy[d];

        if(ni < 0 || ni >= H)
          continue;
        if(nj < 0 || nj >= W)
          continue;
        if(S[ni][nj] == '#')
          count++; 
      }

      S[i][j] = char(count + '0');
    
    }

  }

  for(int i = 0; i < H; i++)
    cout << S[i] << endl;
  

}


Measured memory_bytes: 256
#include <stdio.h>

#define min(a,b) ((a) < (b) ? (a) : (b))
#define MAX_V 100
#define INF 1e9

int V;
int cost[MAX_V][MAX_V];
int mincost[MAX_V];
int used[MAX_V];

int prim() {
  int i,res,v,u;

  for (i = 0 ; i < V ; i++) {
    mincost[i] = INF;
    used[i] = 0;
  }

  mincost[0] = 0;
  res = 0;

  while (1) {
    v = -1;

    for (u = 0 ; u < V ; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v])) {
	v = u;
      }
    }

    if (v == -1) {
      break;
    }
    used[v] = 1;
    res += mincost[v];

    for (u = 0 ; u < V ; u++) {
      if (cost[v][u] != -1) {
	mincost[u] = min(mincost[u],cost[v][u]);
      }
    }

  }

  return res;
}

int main() {
  int i,j;
  
  scanf("%d" ,&V);
  for (i = 0 ; i < V ; i++) {
    for (j = 0 ; j < V ; j++) {
      scanf("%d" ,&cost[i][j]);
    }
  }

  printf("%d\n" ,prim());

  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define N_MAX 1000

using namespace std;

int main()
{
	int N, W;
	int v[100], w[100], C[101][10005];

	cin >> N >>W;

	for (int i = 1; i <= N; i++) {
		cin >> v[i] >> w[i];
	}

	for (int i = 0; i <= W; i++) C[0][i] = 0;
	for (int i = 1; i <= N; i++) C[i][0] = 0;
	
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			if (w[i] <= j) {
				if (v[i] + C[i - 1][j - w[i]] > C[i - 1][j]) {
					C[i][j] = v[i] + C[i - 1][j - w[i]];
				} else {
					C[i][j] = C[i - 1][j];
				}
			} else {
				C[i][j] = C[i - 1][j];
			}
		}
	}
	cout << C[N][W] << endl;
	return (0);
}

Measured memory_bytes: 5108
#include <stdio.h>
int main() {
	int n;
	long int ini[5] = {}, ans1 = 0, ans2 = 0;
	char name[11];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", name);
		switch (name[0])
		{
		case 'M':
			ini[0]++;
			break;
		case 'A':
			ini[1]++;
			break;
		case 'R':
			ini[2]++;
			break;
		case 'C':
			ini[3]++;
			break;
		case 'H':
			ini[4]++;
			break;
		default:
			break;
		}
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = i + 1; j < 4; j++)
		{
			for (int k = j + 1; k < 5; k++)
			{
				ans2 += ini[i] * ini[j] * ini[k];
				ans1 += ans2 / 10000000;
				ans2 %= 10000000;
			}
		}
	}
	if(ans1){
		printf("%lu%07lu", ans1, ans2);
	}
	else{
		printf("%lu", ans2);
    }
	return 0;
}

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

int main()
{
    string s;
    int a, b;

    for( int i = 0; i < 9; i++ )
    {
        cin >> s >> a >> b;
        cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
    }

    return 0;
}



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

while 1:
    n,r = map(int,input().split())
    if n == 0 and r == 0:
        break
    card = [i+1 for i in range(n)]
    for i in range(r):
        p,c = map(int,input().split())
        x = card[n-p-c+1:n-p+1]
        for j in x:
            card.remove(j)
        card += x
    print(card[-1])


Measured memory_bytes: 5620
<?php
fscanf(STDIN, "%d", $n);

switch (substr((string) $n, -1, 1)) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        $answer = 'hon';
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        $answer = 'pon';
        break;
    case 3:
        $answer = 'bon';
        break;
}

echo "{$answer}\n";


Measured memory_bytes: 16112
S = input()

cnt = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == "R" or S[i] == "U" or S[i] == "D":
        cnt += 1
    elif i % 2 == 1 and S[i] == "L" or S[i] == "U" or S[i] == "D":
        cnt += 1

if cnt == len(S):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k, n;
	cin >> k >> n;
	int a[n+1], dis[n+1];
	for (int i=1; i<=n; i++) cin >> a[i];
	for (int i=1; i<n; i++) dis[i]=a[i+1]-a[i];
	dis[n]=a[1]+k-a[n];
	int t=0, maxx=-1;
	for (int i=1; i<=n; i++)
	{
		t+=dis[i];
		maxx=max(maxx, dis[i]);
	}
	cout << t-maxx << endl;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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 V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

string memo[55][55];

string chmax(const string& l,const string& r){
    if(l == "invalid") return r;
    return l.length() > r.length() ? l :( l.length() < r.length() ? r : max(l,r));
}
string get_number(int l,int r,const string& s){
    if(r-l>=1 && s[l] == '0') return "invalid";
    string ret;
    for(int i = l; i <= r;i++){
        if(s[i] != '?' && !isdigit(s[i])) return "invalid";
        ret += (s[i] == '?'?'9':s[i]);
    }
    return ret;
}
string rec(int l,int r,const string& s){
    string& ret = memo[l][r];
    if(ret != "") return ret;
    ret = get_number(l, r, s);
    if(ret != "invalid") return ret;
    
    if((s[l+1] != '(' && s[l+1] != '?') || (s[r] != ')' && s[r] != '?')) return "invalid";
    for(int i = l+3; i <= r-2;i++){
        if(s[i] != ',' && s[i] !='?') continue;
        string lv = rec(l+2,i-1,s), rv = rec(i+1,r-1,s);
        if(lv == "invalid" || rv == "invalid") continue;
        if(s[l] == 'L' || s[l] == '?') ret = chmax(ret,lv);
        if(s[l] == 'R' || s[l] == '?') ret = chmax(ret,rv);
    }
    return ret;
}
template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    res = rec(0,(int)S.length()-1,S);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	string S;
	cin >> S;
	int s = 0, n = 0, w = 0, e = 0;
	rep(i, 0, sz(S)) {
		if(S[i] == 'N') n = 1;
		if(S[i] == 'S') s = 1;
		if(S[i] == 'W') w = 1;
		if(S[i] == 'E') e = 1;
	}
	if((n ^ s) == 1 || (w ^ e) == 1) cout << "No\n";
	else cout << "Yes\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
const int INF = 1e9;

int main() {
  int a,b;
  cin>>a>>b;
  b*=2;
  if(a-b<0){
    cout<<0;
  }
  else{
    cout<<a-b;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# coding: utf-8

class dice ():
    def __init__(self, data):
        self.up = data[0]
        self.down = data[5]
        self.left = data[3]
        self.right =data[2]
        self.front = data[1]
        self.back = data[4]

    def turn_s(self):
        tmp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = tmp

    def turn_n(self):
        tmp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = tmp

    def turn_w(self):
        tmp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = tmp

    def turn_e(self):
        tmp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = tmp

    def turn(self, rotate="N"):
        if (rotate == "N"):
            self.turn_n()
        elif (rotate == "E"):
            self.turn_e()
        elif (rotate == "W"):
            self.turn_w()
        elif (rotate == "S"):
            self.turn_s()
        else:
            none

    def get_up(self):
        return self.up



dicedata = input().split()
orderdata = input()

newdice = dice(dicedata)

[newdice.turn(orderdata[idx]) for idx in range(0, len(orderdata))]

print(newdice.get_up())



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

using namespace std;
#define ll long long


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, k;
    cin >> a >> b >> k;
    if (k >= a) cout << 0 << " " << max(0LL, b - (k - a));
    else cout << a - k << " " << b;
    return 0;
}

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

int main(){
  int64_t N,K;
  cin >> N >> K;

  int64_t div= N/K;
  int64_t ans= (K%2 != 0)  ? div* div* div
              :(N%K < K/2) ? div* div* div* 2
                           : div* div* div+ (div+ 1)* (div+ 1)* (div+ 1);
  cout << ans << endl;
}

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

int main(void) {
	char search[16],ring[32];
	int n,i,j,k,c=0,y,l;
	scanf("%s",search);
	l = strlen(search);
	scanf("%d",&n);
	for(i = 1;i <= n;i++){
		scanf("%s",ring);
		for(j = 0;j <= 9;j++){
			ring[10+j] = ring[j];
		}
		for(j = 0;j <= 9;j++){
			y = 0;
			for(k = 0;k < l;k++){
				if(search[k] != ring[j+k]){y = 1;break;}
				if(k == l - 1){c++;break;}
			}
			if(y){continue;}
			break;
		}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

void swap(int array[], int a, int b){
	int c;
	c = array[a];
	array[a] = array[b];
	array[b] = c;
}

int main(){
	int array[50];
	int w,n,a,b;

	for(int i=0 ; i<50 ; i++){
		array[i] = i;
	}
	
	scanf("%d", &w);
	scanf("%d", &n);
	for(int i=0 ; i<n ; i++){
		scanf("%d,%d", &a, &b);
		swap(array,a,b);
	}
	for(int i=1 ; i<=w ; i++){
		printf("%d\n", array[i]);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string s;
  cin >> s;
  ll n = s.size() - 2;

  cout << s[0] << n << s[s.size() - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  int sinseki=0;
  float chip=0;
  char late_s[128];
  char *late_c="BTC";
  float sum=0;
  scanf("%d",&sinseki);
  for(int i=0;i<sinseki;i++)
  {
    scanf("%f",&chip);
    scanf("%127s",late_s);
    
    if(strcmp(late_s,late_c)==0)
    {
      chip*=380000.0;
    }
    sum+=chip;
  }
  printf("%f",sum);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define pb push_back
#define fi first
#define sec second
ll pow(ll a,int x)
{
	ll res = 1ll;
	while(x)
	{
		if(x&1)res*=a;
		a=a*a;
		x>>=1;
	}
	return res;
}
int main()
{
	while(1)
	{
		ll n,N;
		vector<P> fac;
		scanf("%lld",&n);
		if(n==0)break;
		N=n;
		for(ll i=2;i*i<=n;i++)
		{
			int cnt=0;
			while(n%i==0)
			{
				n/=i;
				cnt++;
			}
			if(cnt)fac.pb(P(i,cnt));
		}
		if(n!=1)fac.pb(P(n,1));
		ll S=1;
		for(int i=0;i<fac.size();i++)S *= (pow(fac[i].fi,fac[i].sec+1)-1)/(fac[i].fi-1);
		if(2*N==S)printf("perfect number\n");
		else if(2*N>S)printf("deficient number\n");
		else printf("abundant number\n");
	}
	return 0;
}

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

using namespace std;

int const N = 300006;

int main() {
	int n, K;
	cin >> n >> K;
	if (2 * K > n + 1) {
		puts("-1");
		return 0;
	}
	static bool vis[N];
	auto ans = vector<pair<pair<int, int>, int>>();
	int l = 0, r = n / 2 + n - (n % 2 == 0);
	if (l == r)
		++r;
	for (int i = K + 2 * n; i < K + 3 * n; ++i) {
		if (vis[l])
			++l;
		if (vis[r])
			++r;
		vis[l] = vis[r] = 1;
		ans.push_back({ { K + l, K + r }, i });
		l += 2, r--;
		if (l >= n)
			l -= n;
		if (r < n)
			r += n;
	}
	//cerr << "? " << ' ' << ans.size() << '\n';
	for (auto const& p : ans)
		cout << p.first.first << ' ' << p.first.second << ' ' << p.second << '\n';
}


Measured memory_bytes: 3700
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] x = new int[2 * n];
        int[] y = new int[2 * n];
        int max = 0;
        int max_index = 0;
        int min = 0;
        int min_index = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            if(max < a[i]){
                max = a[i];
                max_index = i;
            }
            if(min > a[i]){
                min = a[i];
                min_index = i;
            }
        }
        if(Math.abs(min) < max){
            for(int i = 0; i < n; i++){
                y[i] = i + 1;
                x[i] = max_index + 1;
            }
            for(int i = n; i < 2 * n - 1; i++){
                x[i] = i - n + 1;
                y[i] = i - n + 2;
            }
        }
        else{
            for(int i = 0; i < n; i++){
                y[i] = i + 1;
                x[i] = min_index + 1;
            }
            for(int i = n; i < 2 * n - 1; i++){
                x[i] =  2 * n  - i ;
                y[i] = 2 * n - 1 - i;
            }    
        }
        System.out.println(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++){
            System.out.println(x[i] + " " + y[i]);
        }
    }
}

Measured memory_bytes: 22608
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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 Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,q;
  cin>>n>>q;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  rep(i,q){
    ll x;cin>>x;
    ll right=0;
    ll ans=0;
    ll sum=0;
    rep(left,n){
      while(right<n && sum+v[right]<=x){
        sum+=v[right];
        right++;
      }
      ans+=right-left;
      if(left==right) right++;
      else sum-=v[left];
    }
    cout<<ans<<endl;
  }
}


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

from copy import deepcopy
MOD = 10 ** 9 + 7

def main():
    h, w, k = map(int, input().split())
    ways = []
    for way in range(2 ** (w - 1)):
        if isvalid(way):
            ways.append(way)
    dp = [0 for i in range(w)]
    dp[0] = 1
    for i in range(h):
        dppre = deepcopy(dp)
        dp = [0 for i in range(w)]
        for j in range(w):
            for way in ways:
                dp[j] += dppre[apply(way, j)]
                dp[j] %= MOD
    print(dp[k - 1])

def apply(way, fr):
    logic = [False]
    for d in range(8):
        logic.append(bool(way & 1))
        way >>= 1
    if logic[fr]:
        to = fr - 1
    elif logic[fr + 1]:
        to = fr + 1
    else:
        to = fr
    return to

def isvalid(way):
    logic = []
    for d in range(7):
        logic.append(bool(way & 1))
        way >>= 1
    for d in range(6):
        if logic[d] & logic[d + 1]:
            return False
    return True

if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
		
        if(Math.abs(a-b)>Math.abs(c-a))
        System.out.println("B");
        else
        System.out.println("A");
        
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
void print(int num,int a[]){
    for(int i=0;i<num;i++) {
        if (i == num - 1)
            cout<<a[i]<<endl;
        else cout << a[i] << " ";

    }
}
int main()
{
    int num;
    cin>>num;
    int a[num];
    for(int i=0;i<num;i++)
        cin>>a[i];
    for(int i=0;i<num;i++)
    {
        int key=a[i];
        int j=i-1;
        while(j>=0&&a[j]>key) {
            a[j + 1] = a[j];
                j--;
            }
            a[j+1]=key;
        print(num,a);
    }
        return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;cin>>n;
  ll rt=ceil(sqrt(n)),div=0;
  for(ll i=rt;i>=1;--i) { if(n%i==0) {div=i;break;}}
  ll a=to_string(div).size(),b=to_string(n/div).size();
  print(max(a,b));
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint p(N);
  rep(i, N) cin >> p[i], p[i]--;
  int ans = 0;
  rep(i, N-1) {
    if(i == p[i] && i+1 == p[i+1]) {
      swap(p[i], p[i+1]);
      ans++;
    }
  }
  rep(i, N) {
    if(p[i] == i) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
        
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 9152
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int r,g,b;
    cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n";
#define CNO cout << "No" \
                 << "\n";
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    double a, b;
    cin >> a >> b;
    for (size_t i = 0; i < 1251; i++)
    {
        double j = (double)i;
        double ka = j * 0.08;
        double kb = j * 0.10;
        if (floor(ka) == a && floor(kb) == b) {
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc104/tasks/abc104_d

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){

    string S;
    cin >> S;

    int N = S.size();

    vector< vector<long long> > DP= vector< vector<long long> >(4, vector<long long>(N + 1));

    string A = "ABC";

    int ans = 0;
    for(int i=N;i>=0;i--){
        for(int j=3;j>=0;j--){
            if(i==N){
                DP[j][i] = (j==3) ? 1:0;
            }else{
                if(j==3){
                    DP[j][i] = (S[i]=='?') ? 3LL*DP[j][i+1]:DP[j][i+1];
                }else{
                    DP[j][i] = (S[i]=='?') ? 3LL*DP[j][i+1]:DP[j][i+1];
                    if(S[i] == A[j] || S[i] == '?'){
                        DP[j][i] += DP[j+1][i+1];
                    }
                }
                DP[j][i] %= (long long)(1000000007);
            }
        }
        
    }

    cout << DP[0][0] << endl;

    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a.at(i);
        if(a.at(i)==0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll cur = 1;
    rep(i,n){
        ll x = a.at(i);
        if(1000000000000000000/cur<x){
            cout << -1 << endl;
            return 0;
        }else{
            cur *= x;
        }
    }
    cout << cur << endl;
}

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

bool echo(int n,char *N){
    bool bl=true;
    if(n%2==0){
        for(int i=0;i<(n/2);i++){
            if (N[i]!=N[i+n/2]){
                bl=false;
            }
        }
    } else{bl=false;}
    return bl;
}

int main() {
    int N;
    char S[100];
    scanf("%d",&N);
    scanf("%s",S);
    if (echo(N,S)){
        printf("Yes");
    } else{printf("No");}

    return 0;
}


Measured memory_bytes: 128