akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

char ss[3] = {'A', 'B', 'C'};

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;// A, B, C; cin >> N >> A >> B >> C;
    vector<int> abc(3);
    rep(i, 3) cin >> abc[i];
    string ans;
    vector<string> sinp(N);
    rep(i, N) {
        cin >> sinp[i];
    }

    rep(i, N) {
        // string s; cin >> s;
        int l, r;
        rep(j, 3) {
            if (sinp[i][0] == ss[j]) {
                l = j;
            }
            if (sinp[i][1] == ss[j]) {
                r = j;
            }
        }
        if (abc[l] == 0 && abc[r] == 0) {
            cout << "No" << endl;
            return 0;
        }
        if (abc[l] == 1 && abc[r] == 1 && i < N-1) {
            int nl, nr;
            rep(j, 3) {
                if (sinp[i+1][0] == ss[j]) {
                    nl = j;
                }
                if (sinp[i+1][1] == ss[j]) {
                    nr = j;
                }
            }
            if (l == nl || l == nr) {
                abc[l] += 1;
                abc[r] -= 1;
                ans += ss[l];
            } else {
                abc[r] += 1;
                abc[l] -= 1;
                ans += ss[r];
            }
        } else if (abc[l] < abc[r]) {
            abc[l] += 1;
            abc[r] -= 1;
            ans += ss[l];
        } else {
            abc[l] -= 1;
            abc[r] += 1;
            ans += ss[r];
        }
    }
    cout << "Yes" << endl;
    rep(i, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6700
//#define anjn
//      Anjan Agarwala - anjn98

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, 
                  tree_order_statistics_node_update> ordered_set;

//ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

#define PR(x) cout<<#x<<": "<<x<<"\n";
#define PR1(x,y) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"\n";
#define PR2(x,y,z) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"  |  "<<#z<<": "<<z<<"\n";
#define ED cout<<'\n';

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define endl            '\n'
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define PB              push_back
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007


const int N=2e5+99;


int32_t main() 
{
	IO

    int n,l;
    cin>>n>>l;

    vector<ll> v;
    ll ans=0;
    fr(n)
    {
        ll x=l+i;
        ans+=x;
        v.PB(x);
    }
    ll ab=INT_MAX,an=-1;

    fr(n)
    {
        ll ta=ans-v[i];
        if(abs(ans-ta) < ab) ab=abs(ans-ta),an=ta;
    }


    cout<<an<<endl;

}




 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main()
{
    ll n, x=1, y=1, z=1;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        x*=10,y*=9,z*=8;
        x%=MOD,y%=MOD,z%=MOD;
    }
    x -= y;
    x = (x+MOD)%MOD;
    x -= y;
    x = (x+MOD)%MOD;
    x +=z;
    x %= MOD;
    x = (x+MOD)%MOD;
    cout << x << endl;
}


Measured memory_bytes: 3632
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    
def Koch(n, x1,y1, x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)
    
n=int(input())
Koch(n, 0,0, 100,0)

plot(100,0)


Measured memory_bytes: 5752
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll cnt = 0;
  string s,str ; cin >> s >> str;
  rep(i,3){
    if(s[i] == str[i]) cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
ll INF=200000;
ll MAX_N=2600;
ll MAX_M=5500;
vector<vector<ll>> Way(MAX_N, vector<ll>(0));
vector<ll> Coin(MAX_N, -5000*INF);
vector<bool> visit(MAX_N, false);
vector<bool> Alive(MAX_M, true);

void dfs(ll v){
	visit[v] = true;//到達印
	for (ll e: Way[v]){
		if (visit[e] ) continue;
		dfs(e);
	}
}

int main(){
    ll N, M, P;
    cin>>N>>M>>P;
    vector<ll> A(M), B(M), C(M);
    for(int i=0; i<M; i++){
        cin>>A[i]>>B[i]>>C[i];
        A[i]--; B[i]--; 
        C[i]-=P;
        Way[B[i]].push_back(A[i]);
    }
    bool Ch=true;
    ll Update=0;
    ll Nth;
  	Coin[0]=0;
  	bool EndN=true;
  	dfs(N-1);
  	for(ll i=0; i<M; i++){
      	if(visit[A[i]]==false||visit[B[i]]==false){
         Alive[i]=false;
        }
    }
    while(Ch){
        Ch=false;
        for(ll i=0; i<M; i++){
          	if(!(Alive[i]))continue;
            if(Coin[A[i]]!=-5000*INF&&Coin[B[i]]<Coin[A[i]]+C[i]){
                Coin[B[i]]=Coin[A[i]]+C[i];
                Ch=true;
            }
        }
        Update ++;
        if(Update==N*2){
          	EndN=false;
            Ch=false;
        }
        
    }
  	
    if(EndN){
      if(Coin[N-1]<0)Coin[N-1]=0;
      cout<<Coin[N-1]<<endl;
      return 0;
    }
  	cout<<-1<<endl;
  	return 0;
}

Measured memory_bytes: 512
N = int(input(""))

if N >= 1800:
    print("1")
elif N >= 1600:
    print("2")
elif N >= 1400:
    print("3")
elif N >= 1200:
    print("4")
elif N >= 1000:
    print("5")
elif N >= 800:
    print("6")
elif N >= 600:
    print("7")
elif N >= 400:
    print("8")


Measured memory_bytes: 9176
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int W, a, b; cin >> W >> a >> b;
    cout << (0> max(b - (a + W), a - (b + W)) ? 0: max(b - (a + W), a - (b + W))) << endl;
}

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

int main(){
	int N, H;
	int Highest = 0;
	int count = 0;
	cin >> N;
	for(int i = 0;i < N;i++){
		cin >> H;
		if(Highest <= H){
			Highest = H;
			count++;
		}
	}
	cout << count << endl;
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int m; cin >> m;
    cout << 48-m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, m;
map<int, int>mp;
void solve() {
	for (int i = 2; i*i <= m; i++) {
		while (m%i == 0) {
			mp[i]++;
			m /= i;
		}
	}
	if (m != 1)mp[m]++;
}
int ans = 1;
signed main() {
	cin >> n >> m;
	solve();
	for (auto a : mp) {
		ans *= comb(n - 1 + a.second, n - 1);
		ans %= moder;
	}
	cout << ans << endl;
	endre;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cstdio>

using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
 
static const double EPS = 1e-8;
 
const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

ll GCD(ll a ,ll b){
  return b > 0 ? GCD(b,a%b) : a;
}

ll LCM(ll a ,ll b){
  return a / GCD(a,b) * b;
}

int main(){
  ll limit;
  int total_requirements;
  while(~scanf("%lld %d",&limit,&total_requirements)){
    if(limit == 0 && total_requirements == 0) break;
    vector<ll> requirements;
    for(int require_i = 0; require_i < total_requirements; require_i++){
      ll num;
      scanf("%lld",&num);
      requirements.push_back(num);
    }
    sort(requirements.begin(),requirements.end());

    ll gain = limit * (1 + limit) / 2LL;
    ll remaining_items = limit;

    for(int S=1;S<(1<<total_requirements);S++){
      ll lcm = 1;
      for(int i=0;i<requirements.size();i++){
        if(S & (1<<i)){
          lcm = LCM(requirements[i],lcm);
          if(lcm > limit) break;
        }
      }
      if(lcm > limit) continue;

      ll sign = 1;
      if(__builtin_popcount(S) & 1){
        sign = -1;
      }
      ll first_item = lcm;
      ll num_of_item = limit / lcm;
      ll last_item = num_of_item * lcm;
      remaining_items += sign * num_of_item;
      gain += sign * num_of_item * (first_item + last_item) / 2LL;
    }
    
    if(remaining_items == 0){
      printf("%.8lf\n",0);
    }
    else{
      printf("%.8lf\n",(double)gain/(double)remaining_items);
    }
  }
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int get(int x, int y) {
    assert(x!=y);
    int b=0;
    while (1) {
	int ix = x>>b&1;
	int iy = y>>b&1;
	if (ix!=iy) {
	    return b+1;
	}
	b++;
    }
}


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

    int n;
    cin>>n;
    for (int i=1; i<n; i++) {
	for (int j=i+1; j<=n; j++) {
	    cout<<get(i,j)<<" ";
	}
	cout<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3656
import math

def main():
    a, b, n = map(int, input().split())
    ans = solve(a, b, n)
    print(ans)

def solve(a, b, n):
    x = min(b -1, n)
    ans = math.floor(a * x / b) - a * math.floor(x / b)
    return ans

if __name__ == '__main__':
    main()

Measured memory_bytes: 61916
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**18
def solve(N,A):
    P = set()

    for i in range(N):
        n = A[i]
        if n % 2 == 0 and 2 in P: break
        while n % 2 == 0:
            P.add(2)
            n //= 2
            
        f = 3
        while f * f <= n:
            if n % f == 0:
                if f in P: break
                P.add(f)
                while n%f == 0:
                    n //= f
            else:
                f += 2
        else:
            if n != 1:
                if n in P: break
                P.add(n)
            
            continue
        break
    else:
        return 0
        
    return 1 



def main():
    N=ii()
    A=np.array(list(mi()))

    flag = solve(N,A)
    if flag == 0:
        print("pairwise coprime")
    else:
        gcd = np.gcd.reduce(A)
        if gcd == 1:
            print("setwise coprime")
        else:
            print("not coprime")
       

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')

    # basic types: https://numba.pydata.org/numba-doc/0.13/types.html
    cc.export('solve', '(i8,i8[:])')(solve)
    cc.compile()

if __name__ == '__main__':
    # cc_export()
    try:
        from my_module import solve
    except:
        cc_export()
        exit()

    main()


Measured memory_bytes: 144860
def B():
    s1 = input()
    s2 = input()
    
    YES = 'Yes'
    NO = 'No'
    
    result = NO
    for i in range(len(s1)):
        p = s1[i:] + s1[:i]
        if(p in s2):
            result = YES
    
    print(result)
        
if __name__ =='__main__':
    B()

Measured memory_bytes: 2940
//abc067_b.cpp
//Wed Oct 31 22:40:04 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int l[n];
	for (int i=0;i<n;i++){
		cin >> l[i];
	}

	sort(l,l+n,greater<int>());

	int ans = 0;
	for (int i=0;i<k;i++){
		ans += l[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












typedef long long ll;
int N; ll A[501010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    map<ll, int> c;
    rep(i, 0, N) c[A[i]]++;

    ll ans = 0;
    fore(p, c) if (4 <= p.second) ans = max(ans, p.first * p.first);
    vector<ll> v;
    fore(p, c) if (2 <= p.second) v.push_back(p.first);
    sort(v.begin(), v.end(), greater<ll>());

    if (2 <= v.size()) {
        ans = max(ans, v[0] * v[1]);
    }

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

Measured memory_bytes: 7296
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << 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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll x;
  cin >> x;
  for (ll i = -300; i <= 300; ++i) {
    for (ll j = -300; j <= 300; ++j) {
      ll a = i*i*i*i*i;
      ll b = j*j*j*j*j;
      if (a-b == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  assert(false); // must not reach here
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
  int A, B, C, D;
  
  do{
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
  }while(A < B);
  
  D = C - A + B;
  if(D < 0){
    D = 0;
  }
  
  printf("%d", D);
  
  return 0;
}

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

int main(){
  	long long int N, K;
  	cin >> N >> K;
  	long long int A[N];
  	for (long long int i = 0; i < N; i++) cin >> A[i];
  
  	long long int count = 0;
  	bool flag[N];
  	for (int i = 0; i < N; i++) flag[i] = false;
  	long long int now = 0;
  	long long int num[N];
  	for (int i = 0; i < N; i++) num[i] = 1000000;
  
  	while (flag[now] == false) {
        flag[now] = true;
      	num[now] = count;
      	count++;
      	now = A[now] - 1;
    }
  	
  	if (K >= num[now]){
  		long long int res = (K - num[now]) % (count - num[now]);
  		long long int res2 = 1000000;
  		for (long long int i = 0; i < N; i++){
      		if (res == num[i] - num[now]) res2 = i;
    	}
  		cout << res2 + 1 << endl;
    }
  	else {
      	now = 0;
      	for (int i = 0; i < K; i++){
          	now = A[now] - 1;
        }
      	cout << now + 1 << endl;
    }
  	
  	
}

Measured memory_bytes: 6956
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll w,a,b;
  cin >> w >> a >> b;
  if(a>b) swap(b,a);
  cout << max(0ll,b-(a+w))<<endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;

    vector<vector<int>> G(n);
    G[x].push_back(y); G[y].push_back(x);

    rep(i, n-1){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }

    vector<int> ans(n);
    rep(i, n){
        vector<int> dist(n, -1);
        queue<int> q;

        dist[i] = 0;
        q.push(i);

        while(!q.empty()){
            int j = q.front(); q.pop();
            for (auto& p : G[j]) {
                if(dist[p] != -1) continue;
                dist[p] = dist[j] + 1;
                q.push(p);
            }
        }

        for (auto& p : dist) {
            ans[p] ++;
        }
    }

    for (int i = 1; i < n; ++i) {
        cout << ans[i] / 2 << endl;
    }


    return 0;
}



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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x, y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x, y, z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define db4(x, y, z, w) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<","<<#w<<"="<<w<<'\n'
#define sz(a) int((a).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define PR(a, n) {cout<<#a<<"="; for(int __=0;__<n;__++)cout<<a[__]<<' '; cout<<"\n"; }
using namespace std;
using ll =  long long;
#define int ll

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for (int &i: v)cin >> i;
    vector<bool> dp(k + 1);
    sort(v.begin(),v.end());
    int m = v.front();
    if(k<m)cout << "Second";
    else {
        for (int i = 0; i < m; ++i)
            dp[i] = false;
        dp[m] = true;
        for (int i = m + 1; i <= k; ++i) {

            for (int x: v) {
                if (i - x < 0){
                    break;
                }
                if (!dp[i - x]) {
                    dp[i] = true;
                    break;
                }
            }
        }
        if (dp[k]) {
            cout << "First";
        } else {
            cout << "Second";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000000
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  int N, M;
  cin >> N >> M;
  if(N == M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int res = 0;
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
      res++;
    }
    else{
      ans = max(ans, res);
      res = 0;
    }
  }
  ans = max(ans, res);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<LN;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<LN;}

int main() {
    ll X;
    cin >> X;
    ll ans = 0;
    ans += X / 500 * 1000;
    ans += (X % 500) / 5 * 5;
    show(ans);
}


Measured memory_bytes: 256
n=int(input())
l=('3','5','7')
def dfs(a,ans):
    if len(a)>=2 and int(''.join(a[1:]))>n:
      return ans
    for i in l:
        a.append(i)
        if all(j in a for j in l) and  int(''.join(a[1:]))<=n:
          ans+=1
        ans+=dfs(a,0)
        a.pop()
    return ans
print(dfs([0],0))

Measured memory_bytes: 3064
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/4;
    public static final int inf = Integer.MAX_VALUE/4;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int count = 0, ans = 0;
        for (int i = 105; i <= n; i += 2) {
            count = 1;
            TreeMap<Long,Integer> map = PrimeFactorization(i);
            for(Long key: map.keySet()){
                count *= map.get(key)+1;
            }
            if(count==8) ans++;
        }
        out.println(ans);
    }
    public static TreeMap<Long, Integer> PrimeFactorization(long n){
        TreeMap<Long, Integer> map = new TreeMap<>();
        for (long i = 2; i*i <= n; i++) {
            while(n%i==0){
                map.put(i, map.containsKey(i)?map.get(i)+1:1);
                n /= i;
            }
        }
        if(n!=1) map.put(n, 1);
        return map;
    }

    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 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: 20564
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;

int main() {
    IOS;
    int a,b;
    cin>>a>>b;
    if(a >= 13) cout<<b<<"\n";
    else if(a >= 6) cout<<b/2<<"\n";
    else cout<<"0\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;

int main() {
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  println((for (_ ← 1 to scala.io.StdIn.readInt) yield (scala.io.StdIn.readInt)).toList.zipWithIndex.sortBy {
    case (f, i) ⇒ f
  }.map { _._2 % 2 == 0 }.foldLeft(true, 0) {
    case ((parity, res), idx) ⇒ if (parity == idx) (!parity, res) else (!parity, res + 1)
  }._2 / 2)
}

Measured memory_bytes: 44500
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  int ans,n,m,i,now;
  int num;//??????????????????
  for(;;){
    cin>>n>>m;
    if(n==0&&m==0)exit(0);
    int order[n]={0};//??????????????????
    for(i=1;i<=n;i++){
      cin>>order[i];
    }
    now=1;//?????¨??????
    ans=0;
    while(now<n){
      cin>>num;
      now+=num;//????????????????????????????§????
      now+=order[now];//?§??????????????????????????§????
      ans++;
    }
    for(i=0;i<(m-ans);i++)cin>>num;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,M,X;
  cin >>N>>M>>X;
  
  long long min=-1;
  
  vector<vector<long long>> sina(20,vector<long long>(20));
  for(int i=0;i<N;i++){
    for(int a=0;a<M+1;a++){
      cin >> sina.at(i).at(a);
    }
  }
  for(long long ma=0;ma<(1 << N);ma++){
    bitset<20>ha(ma);
    vector<long long>total(20);
    bool judge=true;
    
    for(long long k=0;k<N;k++){
      if(ha.test(k)){
        for(long long a=0;a<M+1;a++)
        total.at(a)+=sina.at(k).at(a);
      }
    }
    for(long long p=1;p<M+1;p++){
      if(total.at(p)<X){
        judge=false;
      }
    }
    if(judge){
      if(min==-1){
        min=total.at(0);
      }
      else if(total.at(0)<min){
        min = total.at(0);
      }
    }
  }
  cout << min;
}
      
    
      
    
  

Measured memory_bytes: 3564
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=2e5 + 5;
const int MOD=1e9 + 7;

int a[N];
int b[N];
int prefa[N];
int prefb[N];
int n,m,k;

int check(int x)
{
	rep(i,0,x)
	{
		int f = i;
		int s = x - f;
		if(f>n || s>m)
			continue;
		int cur1 = prefa[f];
		int cur2 = prefb[s];
		if(cur1+cur2<=k)
			return 1;
	}
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi+1)>>1;// makes 7-4, 8-4,3-2 ,1-1.. adding 1 dont forget
		if(check(mid))
			lo=mid;
		else
			hi=mid-1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		cin >> n >> m >> k;
		rep(i,1,n)
			cin >> a[i];
		rep(i,1,m)
			cin >> b[i];
		int tot = 0;
		rep(i,1,n)
		{
			tot += a[i];
			prefa[i] = tot;
		}
		tot = 0;
		rep(i,1,m)
		{
			tot += b[i];
			prefb[i] = tot;
		}
		cout << binsearch(0,n+m) << endl;
	}
}



Measured memory_bytes: 9880
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> pii;

const int MAX = 1e5 + 10 , INF = 1e12;
int n, k, a[3][MAX], dp[MAX][3];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0 ; i < n ; i++){
		for (int j = 0 ; j < 3 ; j++){
			cin >> a[j][i];
		}
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[1][0];
	dp[0][2] = a[2][0];
	for (int i = 1 ; i < n ; i++){
		dp[i][0] = max (dp[i - 1][1] , dp[i - 1][2]) + a[0][i];
		dp[i][1] = max (dp[i - 1][0] , dp[i - 1][2]) + a[1][i];
		dp[i][2] = max (dp[i - 1][0] , dp[i - 1][1]) + a[2][i];
	}
	cout << max (dp[n - 1][0] , max(dp[n - 1][1] , dp[n - 1][2]));
}

Measured memory_bytes: 4992
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
//#define endl "\n"
#define inf 1e18
#define mm 998244353

ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

/*
bool pp[1000001];
 
void func(){
	for(int i=2;i*i<=1000000;i++){
		if(pp[i]){
			for(int j=i*i;j<=1000000;j+=i) pp[j] = false;
		}
	}
}
*/



void solve(){
	long double a,b;
	cin>>a>>b;
	a = a*b;
	ll ans = floor(a);
	cout<<ans<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  string e = "XX", f = "XX";
  e.at(0) = a;
  e.at(1) = b;
  f.at(0) = c;
  f.at(1) = d;
  int g = stoi(e);
  int h = stoi(f);
  string ans;
  if(1<=g && g<=12 && 1<=h && h<=12) ans ="AMBIGUOUS";
  else if(0<=g && g<=99 && 1<=h && h<=12) ans ="YYMM";
  else if(1<=g && g<=12 && 0<=h && h<=99) ans ="MMYY";
  else ans ="NA";
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
const int MAX = 300005;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}

//check modulo
int main(){
	IOS;
	cout.precision(50) ;
	int n;  cin >>  n;
	vi b(n - 1);
	for(int i = 0 ;  i< n - 1 ; i++) cin >> b[i] ;
	vi a(n) ;
	a[0] = b[0] ;
	ll sum = a[0] ;
	for(int i  = 0 ; i < n - 1 ; i++){
		if(i == n - 2) a[i + 1] = b[i] ;
		else a[i + 1] = min(b[i] , b[i + 1]) ;
		
		sum += a[i + 1] ;
	}
	
	cout << sum << endl; 
	
	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
dx=[1,-1,0,0,1,-1,1,-1]
dy=[0,0,1,-1,1,1,-1,-1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x and x<h and 0<=y and y<w and s[x][y]=="#":
                    cnt+=1
            s[i][j]=str(cnt)
for i in range(h):
    print(*s[i],sep="")

Measured memory_bytes: 3572
import           Control.Monad
import           Data.Array.IO

md = 1000000007

type Index = (Int, Int, Int, Int)

solve :: (IOUArray Index Int) -> Index -> IO ()
solve dp idx @ (l, c1, c2, c3) = forM_ [0 .. 3]
  $ \a -> do
    case (a, c1, c2, c3) of
      (2, 1, 0, _) -> return ()
      (2, 0, 1, _) -> return ()
      (1, 2, 0, _) -> return ()
      (2, 1, _, 0) -> return ()
      (2, _, 1, 0) -> return ()
      _ -> do
        let idx' = (l + 1, a, c1, c2)
        a <- readArray dp idx'
        b <- readArray dp idx
        writeArray dp idx' ((a + b) `mod` md)
        return ()

main :: IO ()
main = do
  n <- readLn :: IO Int
  dp <- newArray ((0, 0, 0, 0), (n, 3, 3, 3)) 0 :: IO (IOUArray Index Int)
  writeArray dp (0, 3, 3, 3) 1
  forM_
    [(l, c1, c2, c3)
    | l <- [0 .. n - 1]
    , c1 <- [0 .. 3]
    , c2 <- [0 .. 3]
    , c3 <- [0 .. 3]]
    $ \idx @ (l, c1, c2, c3) -> do
      x <- readArray dp idx
      case x of
        0 -> return ()
        _ -> solve dp idx
  as <- forM [(c1, c2, c3) | c3 <- [0 .. 3], c2 <- [0 .. 3], c1 <- [0 .. 3]]
    $ \(a, b, c) -> do
      readArray dp (n, a, b, c)
  print (sum as `mod` md)


Measured memory_bytes: 1020
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N, K;
    cin >> N >> K;

    llong R = 2 * K;

    vvecllong blackCount(R, vecllong(R, 0));
    FOR(i, N) {
        llong x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W') {
            y += K;
        }
        x %= R;
        y %= R;
        blackCount[x][y]++;
    }

    vvecllong sumBlack(R + 1, vecllong(R + 1, 0));

    FOR(x, R) {
        FOR(y, R) {
            sumBlack[x + 1][y + 1] = sumBlack[x + 1][y] + sumBlack[x][y + 1] - sumBlack[x][y] + blackCount[x][y];
        }
    }

    auto query = [&](llong minX, llong maxX, llong minY, llong maxY){
        if(minX > maxX || minY > maxY){
            return 0LL;
        }
        return sumBlack[maxX][maxY] - sumBlack[minX][maxY] - sumBlack[maxX][minY] + sumBlack[minX][minY];
    };

/*
[0, 2K-1] × [0, 2K - 1]
          x      x+K
    □ □ □ ■ ■ ■ ■ ■ □ □
    □ □ □ ■ ■ ■ ■ ■ □ □
y+K ■ ■ ■ □ □ □ □ □ ■ ■
    ■ ■ ■ □ □ □ □ □ ■ ■
    ■ ■ ■ □ □ □ □ □ ■ ■
    ■ ■ ■ □ □ □ □ □ ■ ■
y   ■ ■ ■ □ □ □ □ □ ■ ■
    □ □ □ ■ ■ ■ ■ ■ □ □
    □ □ □ ■ ■ ■ ■ ■ □ □
    □ □ □ ■ ■ ■ ■ ■ □ □
*/
    llong ans = 0;
    FOR(x, K + 1) {
        FOR(y, K + 1) {
            llong sum = 0;
            sum += query(0, x, 0, y);
            sum += query(0, x, y + K, R);
            sum += query(x + K, R, 0, y);
            sum += query(x, x + K, y, y + K);
            sum += query(x + K, R, y + K, R);

            ans = max({ans, sum, N - sum});
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 62976
import java.util.Scanner;

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

            while (true) {
                if (prime(x)) {
                    System.out.println(x);
                    break;
                }
                ++x;
            }
        }
    }

    private static boolean prime(int x) {
        for (int i = 2; i < x; ++i) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }

}

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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main() {
  int n,m;
  cin>>n>>m;
  mint ans = 1;
  if(abs(n-m) <= 1){
    for(int i=1;i<=n;i++) ans*=i;
    for(int i=1;i<=m;i++) ans*=i;
  }
  if(n==m){
    ans*=2;
  }
  if(abs(n-m) > 1){
    ans = 0;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<cmath>
#define ull unsigned long long int 
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define min_(a,b) ((a)<(b)?(a):(b))
using namespace std;

const int digit[8] = {
	1,10, 100, 1000, 10000, 100000, 1000000, 10000000
};

struct Alfa{
	char c;
	int num;
	int size;
	bool checked;
};



Alfa alfa[13];
char str[12][10];
int N,cnt;
bool calc(){
	int sum = 0;
	int l=0;
	while (alfa[l].c != 0){
		if (alfa[l].num == 0 && alfa[l].checked == true)return(false);
		//cout << alfa[l].c<<endl;
		sum += alfa[l].num*alfa[l].size;
		l++;
	}
	if (sum == 0){
		
	/*	l = 0;
		while (alfa[l].c != 0){
			cout << alfa[l].c << alfa[l].num;
			l++;
		}
		cout << endl;*/
		return true;
	}
	else return false;
}

void set_num(int s){
	int t;
	if (alfa[s].c == 0){
		if (calc())cnt++;
		return;
	}
	rep(i, s, 10){
		t = alfa[s].num;
		alfa[s].num = alfa[i].num;
		alfa[i].num = t;
		set_num(s + 1);
		t = alfa[s].num;
		alfa[s].num = alfa[i].num;
		alfa[i].num = t;
	}
}

int main(void){
	while (true){
		cin >> N;
		if (N == 0)return(0);
		memset(alfa, 0, sizeof(alfa));
		rep(i, 0, N){
			cin >> str[i];
			int p =cnt= 0;
			while (str[i][p] != '\0'){
				int k=0;
				while (alfa[k].c != 0 && alfa[k].c != str[i][p])k++;
				alfa[k].c = str[i][p];
				if (p == 0 && str[i][1] != '\0')alfa[k].checked = true;
				if(i<N-1)alfa[k].size+=digit[strlen(str[i]) - p-1];
				else alfa[k].size -= digit[strlen(str[i]) - p - 1];
				p++;
			}
		}
		int l = 0;
		//while (alfa[l].c != 0){cout << alfa[l].c<<endl;rep(i, 0, alfa[l].size)cout << alfa[l].data[i] << endl;l++;}
		rep(i, 0, 10)alfa[i].num = 9 - i;
		set_num(0);
		cout << cnt << endl;

	}


}

Measured memory_bytes: 1168
/*
  カードゲーム
  (太郎と花子がカードゲームをする。
  二人はそれぞれn枚のカードを持っており、nターンの勝負を行う。
  各ターンではそれぞれ１枚ずつカードを出す。
  カードにはアルファベットからなる動物の名前が書かれており、
  辞書順で大きいものがそのターンの勝者となる。
  勝者には３ポイント、引き分けの場合にはそれぞれ１ポイントが加算される。 )
  2018/03/04
*/

#include<stdio.h>
typedef struct{
  int point;
  char card[100];
} NAME;
int main(void)
{
  NAME taro = {0,{'\0'}};
  NAME hanako = {0,{'\0'}};
  int n;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %s %s",taro.card,hanako.card);
    
    j=0;
    while(taro.card[j] == hanako.card[j] &&
	  (taro.card[j] != '\0' && hanako.card[j] != '\0'))
      j++;
    if(taro.card[j] == '\0' && hanako.card[j] == '\0')
      {
	taro.point++;
	hanako.point++;
      }
    else
      {
	if(taro.card[j] < hanako.card[j])
	  hanako.point += 3;
	else
	  taro.point += 3;
      }
  }
  printf("%d %d\n",taro.point,hanako.point);
  return 0;
}


Measured memory_bytes: 2032