akhauriyash/Code-Regression huggingface dataset:
import sys
k=int(input())
ans=[""]
for i in range(1,13):
    ans.append(i)
for i in range(1,8):
    a=10*(i+1)+(i)
    for j in range(3):
        ans.append(a)
        a+=1
ans.append(98)
ans.append(99)
#print(ans)
#print(len(ans))
if k<=35:
    print(ans[k])
else:
    def search(i,j):
        total=0
        if i==1:
            #print(j)
            return 1
        for m in range(10):
            if abs(j-m)<=1:
                total+=search(i-1,m)
        return total
    def search2(i,j,anss):
        global plus,aaa
        if i==1:
            plus+=1
            #print(kind)
            #print(anss)
            #print(aaa+plus)
            if k==aaa+plus:
                #print(aaa+plus)
                print(anss)
            return 
        for m in range(10):
            if abs(j-m)<=1:
                search2(i-1,m,anss+str(m))
    num=[35] #各桁の種類(累計
    for i in range(3,11): #桁数
        for j in range(1,10): #先頭の数字
            count=search(i,j)
            num.append(num[-1]+count)
    #print(num)
    ab=0
    while num[ab]<k:
        ab+=1
    #print(ab)
    rank=ab//9
    sento=ab%9
    if sento==0:
        sento=9
    #where=sento*(10**(2+rank))
    #print(where)
    aaa=num[ab-1]
    plus=0
    search2(3+rank,sento,str(sento))

Measured memory_bytes: 52956
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
int main() {

	int c,N,C;
	cin >> N;

	C = 0;

	for (int i = 1; i <= N; i++)
	{
		c = 0;

		if (i % 2 == 0)
		{
			continue;
		}

		for (int j = 1; j <= N; j++)
		{
			if (i % j == 0)
			{
				c++;
			}
		}

		if (c == 8)
		{
			C++;
		}

	}

	cout << C << endl;

}


Measured memory_bytes: 256
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<int> C;
#define X real()
#define Y imag()
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima 1000000001
#define imi -1000000001
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
si s;
for(int i=0;i<n;i++)
s.in(a[i]);
int dp[k+1]={0};
for(int i=0;i<=k;i++)
{if(s.find(i)!=s.end())
	dp[i]=1;
	for(int j=0;j<n;j++)
	{
		if(i+a[j]<=k&&dp[i+a[j]]!=1)
	dp[i+a[j]]=1-dp[i];	
	}
	
}

for(int i=0;i<n;i++)
dp[a[i]]=1;



if(dp[k]==0)
cout<<"Second";
else
cout<<"First";

}return 0;}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc114/tasks/abc114_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int minv = 1e9;
    REP(i, s.length() - 2) {
        int t = abs(753 - stoi(s.substr(i, 3)));
        minv = min(minv, t);
    }
    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 256
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("YES\n")
#define no printf("NO\n")
#define push_back pb
int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    long long a,b,c,d=0,e=0;
    cin>>a>>b>>c;
    if(a==5)
        d++;
    else
        e++;
    if(b==5)
        d++;
    else
        e++;
    if(c==5)
        d++;
    else
        e++;
    if(d==2 && e==1)
        yes;
    else
        no;
}


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

int main(void){
    int n,q;
    cin >> n >> q;
    vector< vector<int> > a(n);

    for(int i=0; i<q; i++){
        int cmd;
        cin >> cmd;
        if(cmd==0){
            int t,x;
            cin >> t >> x;
            a[t].push_back(x);
        }
        else if(cmd==1){
            int t;
            cin >> t;
            for(int i=0; i<a[t].size(); i++){
                if(i==a[t].size()-1) cout << a[t][i];
                else cout << a[t][i] << " ";
            }
            cout << "\n";
        }
        else if(cmd==2){
             int t;
             cin >> t;
             a[t].clear();
        }
    }
    return 0;
}


Measured memory_bytes: 5748
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	vvi val(d, vi(n));
	REP(i, d)
		REP(j, n)
		cin >> val[i][j];
	vvi dp(d, vi(100001));
	REP(i, x + 1) {
		dp[0][i] = i;
	}
	int ma = x;
	int tmp;
	FOR(i, 1, d) {
		tmp = 0;
		REP(k, ma + 1)
			dp[i][k] = k;
		REP(k, ma + 1) {
			REP(j, n)
				if (k - val[i - 1][j] >= 0) {
					dp[i][k] = max(dp[i][k], dp[i][k - val[i - 1][j]] + val[i][j]);
					tmp = max(tmp, dp[i][k]);
				}
		}
		ma = max(ma,tmp);
	}
	int ans = 0;
	REP(i, dp[d - 1].size())
		ans = max(ans, dp[d - 1][i]);
	cout << ans << endl;
}

Measured memory_bytes: 7004
import itertools
import math

N = int(input())
p = [list(map(int, input().split())) for _ in range(N)]

def dis(p):
  d = 0
  for i in range(len(p)-1):
    d += ((p[i][0] - p[i+1][0]) ** 2 + (p[i][1] - p[i+1][1]) ** 2) ** 0.5
  return d

perm = itertools.permutations(p, N)
d = 0
for l in perm:
  #print(l, dis(l))
  d += dis(l)
  
print(d / math.factorial(N))

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

int main()
{
    int n ,m;
    cin>>n>>m;
    int num1=0,num2=0;
    if(n>=2)
        num1=n*(n-1)/2;
    if(m>=2)
        num2=m*(m-1)/2;
    cout<<num1+num2;
}


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

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long H = l[0], W = l[1];

        var w1 = W % 2 == 0 ? W / 2 : W / 2 + 1;
        var w2 = W / 2;

        var h1 = H % 2 == 0 ? H / 2 : H / 2 + 1;
        var h2 = H - h1;

        var ans = w1 * h1 + w2 * h2;

        Console.WriteLine(H == 1 || W == 1 ? 1 : ans);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int n,T;
    cin>>n>>T;
    int c,t;
    int ans=100000;
    for(int i=0;i<n;i++){
        cin>>c>>t;
        if(t<=T) ans=min(ans,c);
    }
    if(ans<=1000) cout<<ans<<endl;
    else cout<<"TLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n=int(input())
print(s[n-1])

Measured memory_bytes: 3060
N = int(input())
A = [int(_n) for _n in input().split()]
A.sort(reverse=True)
# print(A)
N -= 2
i = 1
res = A[0]
while N  > 0:
    if N >= 2:
        N -= 2
        res += A[i]*2
        i+=1
    else:
        N -= 1
        res += A[i]
print(res)

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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;
    f(n){
        cout << s1[i] << s2[i];
    }
}

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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n;
	string s;
	cin >> n >> s;
	int w[n];
	int b[n];
	b[0] = 0;
	for(int i = 1; i < n; i++){
		if(s[i - 1] == '#')b[i] = b[i - 1] + 1;
		else b[i] = b[i - 1];

		//cout << b[i] << endl;
	}
	//cout << endl;
	w[n - 1] = 0;
	for(int i = n - 2; i >= 0; i--){
		if(s[i + 1] == '.')w[i] = w[i + 1] + 1;
		else w[i] = w[i + 1];

		//cout << w[i] << endl;
	}
	//cout << endl;
	int mini = 99999999;
	for(int i = 0; i < n; i++){
		mini = min(mini,b[i] + w[i]);
	}
	cout << mini << endl;
	return 0;
}
//g++ AtCoder.cpp

Measured memory_bytes: 2180
#include <stdio.h>

int main() {
    int a, b, c, x, count=0;
    scanf("%d%d%d", &a, &b, &c);
    for (x = a; x <= b; x++) {
        if (c % x == 0) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

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

using namespace std;

int main(void)
{
    int ans;
    for(int i = 0; i < 5; i++){
        int temp;
        cin >> temp;
        if(temp == 0) ans = i + 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long mod_pow(long x, int k) {
    long ret = 1;
    while (k > 0) {
        if (k & 1)
            ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        k >>= 1;
    }
    return ret;
}

long inv(long x) {
    return mod_pow(x, MOD - 2);
}

long combi(long n, long r) {
    long ret = 1;
    for (long i = 0; i < r; i++) {
        ret *= n - i;
        ret %= MOD;
        ret *= inv(i + 1);
        ret %= MOD;
    }
    return ret;
}

int main() {
    long n, m, k;
    cin >> n >> m >> k;
    long ans = (n * n * (m + 1) * m * (m - 1) + m * m * (n + 1) * n * (n - 1)) / 6 % MOD;
    ans = (ans * combi(n * m - 2, k - 2)) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b): to(to), a(a), b(b) {}
};

struct Data {
  int v, s;
  ll time;
  Data(int v, int s, ll time): v(v), s(s), time(time) {};
  bool operator<(const Data& a) const {
    return time > a.time;
  }
};

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];

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

  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    int a, b;
    cin >> a >> b;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; ++i) cin >> c[i] >> d[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < MAX_S+5; ++j) {
      dp[i][j] = INF;
    }
  }
  
  priority_queue<Data> q;
  auto push = [&](int v, int s, ll time) {
    if (s < 0) return;
    if (dp[v][s] <=  time) return;
    dp[v][s] = time;
    q.emplace(v, s, time);
  };
  s = min(s, MAX_S);
  push(0, s, 0);
  while (!q.empty()) {
    Data tmp = q.top(); q.pop();
    int v = tmp.v;
    int s = tmp.s;
    ll time = tmp.time;
    if (time != dp[v][s]) continue;
    {
      int ns = min(s + c[v], MAX_S);
      push(v, ns, time+d[v]);
    }

    for(Edge e : g[v]) {
      push(e.to, s-e.a, time+e.b);
    }
  }

  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    for (int j = 0; j < MAX_S+5; ++j) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long lint;

lint countBit(lint x, lint b)
{
  // 1, 2, 4 => 2, 4, 8;
  lint cnt = 0;
  lint s = b * 2;
  if(x >= s){
    lint a = x / s;
    x -= s * a;
    a = a * b;
    cnt = a;
  }
  x -= b;
  if(x <= 0){
    return cnt;
  }
  else{
    return cnt + x;
  }
}

int main(void)
{
  lint A, B;
  cin >> A >> B;
  lint ans = 0;
  for(lint i = 1; i <= B+1; i*=2){
    //cout << i << endl;
    lint num = countBit(B+1, i) -  countBit(A, i);
    //lcout << countBit(B+1, i) << " " << countBit(A, i) << endl;
    if(num % 2 == 1)
      ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define mod 1000000007
#define G2 500000004
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn=3E3+5;
int n,q,a[maxn],X[maxn],Y[maxn];
ll f[maxn][maxn],g[maxn][maxn];
inline void add(ll&x,ll y)
{
	x=(x+y)%mod;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=q;++i)
		cin>>X[i]>>Y[i];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			f[i][j]=a[i]>a[j];
	for(int k=1;k<=q;++k)
	{
		int x=X[k],y=Y[k];
		/*
		memset(g,0,sizeof(g));
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
			{
				if(i!=x&&i!=y&&j!=x&&j!=y)
					add(g[i][j],f[i][j]*2);
				else
				{
					add(g[i][j],f[i][j]);
					if((i==x&&j==y)||(i==y&&j==x))
						add(g[i][j],f[j][i]);
					else if(i==j)
						continue;
					else if(i==x)
						add(g[i][j],f[y][j]);
					else if(i==y)
						add(g[i][j],f[x][j]);
					else if(j==x)
						add(g[i][j],f[i][y]);
					else if(j==y)
						add(g[i][j],f[i][x]);
				}
			}
		*/
		for(int i=1;i<=n;++i)
		{
			if(i==x||i==y)
				continue;
			f[x][i]=(f[x][i]+f[y][i])*G2%mod;
			f[y][i]=f[x][i];
			f[i][x]=(f[i][x]+f[i][y])*G2%mod;
			f[i][y]=f[i][x];
		}
		f[y][x]=f[x][y]=(f[x][y]+f[y][x])*G2%mod;
	}
	ll ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			add(ans,f[i][j]);
	for(int i=1;i<=q;++i)
		ans=ans*2%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 71680
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, M;
vector <int> G[100005];

bool visited[100005][3];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
//        G[b].push_back(a);
    }

    int S, T;
    cin >> S >> T;

    queue <pair<int, int>> q;
    q.push({S, 0});

    while(!q.empty()) {
        int v = q.front().first;
        int dis = q.front().second;
        q.pop();
        if(visited[v][dis % 3])
            continue;
        visited[v][dis % 3] = true;
        if(v == T && dis % 3 == 0) {
            cout << dis / 3 << endl;
            return 0;
        }

        for(auto u: G[v]) if(!visited[u][(dis + 1) % 3]) {
            q.push({u, dis + 1});
        }
    }
    cout << -1;
}

Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <cstdio>
#include <vector>
using namespace std;
 
int main (void) {
  string s;
  cin >> s;
  int box[200]={0};
  for (int i=0; i<=s.size()-1; i++) {
    char c1=s[i];
    int code1= (int)c1;
    box[code1]++;
  }
  for (int i=97; i<=123; i++) {
    if (i==123) {
      cout << "None";
      break;
    }
    if (box[i] == 0){
      int c2 = i;
      printf("%c", c2);
      break;
    }
  }
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int H = s.nextInt();
		int R = s.nextInt();
		
		int A = H + R;
		if(A>0){
			System.out.println("1");
		}else if(A==0){
			System.out.println("0");
		}else{
			System.out.println("-1");
		}
	}
}

Measured memory_bytes: 26320
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 
char c[] = "MUJIN";

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 6; i++) {
		if (s[i] == '1')ans++;

	}
	print(ans);


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    ll n , m;
    cin >> n >> m;
    cout << abs(n - 2) * abs(m - 2) << endl;
}


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

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  ll a,b;
  a = stoi(S.substr(0,2));
  b = stoi(S.substr(2,2));
  if((a >= 13 || a==0) && (b==0 || b >= 13))
    cout << "NA" << endl;
  else if(a >= 13 || a==0)
    cout << "YYMM" << endl;
  else if(b >= 13 || b==0)
    cout << "MMYY" << endl;
  else
    cout << "AMBIGUOUS" << endl;
}


Measured memory_bytes: 256
import bisect
R = 100001/2
p = [1]*R
p[0] = p[1] = 0
for i in range(2,int(R**0.5)+1):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
p = [i for i in range(R) if p[i]]
n = len(p)
pxp = []
for i in range(n):
    for j in range(i,n):
        if p[i]*p[j] > 100000: break
        pxp.append([p[i]*p[j],p[i],p[j]])
pxp = sorted(pxp)
p,xy = [ele[0] for ele in pxp],[[ele[1],ele[2]] for ele in pxp]

while 1:
    m,a,b = map(int,raw_input().split())
    if m == 0: break
    ab = a*1.0/b

    sp = bisect.bisect(p,m)
    for i in range(sp)[::-1]:
        x,y = xy[i]
        if 1 >= x*1.0/y >= ab:
            print x,y
            break

Measured memory_bytes: 11436
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let ans = a.iter().fold(0, |sum, x| sum + x - 1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define BUGAVOID(x) x
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define unq(v) v.erase(unique(v.begin(),v.end()),v.end());
#define mp make_pair
#define write(x) cout<<(x)<<endl
#ifdef LOCAL
#define debug(...) debug_vars(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 10;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int pattern[15];
int getPattern(const int n) {
    if (n < 2) return 1;
    if (pattern[n]) return pattern[n];
    ll cnt = 0;
    rep(flen, 1, n + 1) {
        cnt += getPattern(n - flen);
    }
    pattern[n] = cnt;
    return cnt;
}

int num[15];

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    rep(i, len) num[i] = s[i] & 0x0F;
    
    ll sum = 0;
    rep(i, 0, len) {
        rep(l, 1, len - i + 1) {
            ll val = stoll(s.substr(i, l));
            sum += val * getPattern(i) * getPattern(len - i - l);
        }
    }
    write(sum);
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // sqrt()
#include <stdbool.h>

#define MAX_N 10000
#define MAX_R 5000

bool prime[MAX_N];

void
prepare()
{
	for (int i = 2; i < MAX_N; ++i)
		prime[i] = true;

	int e = sqrt(MAX_N);
	for (int i = 2; i <= e; ++i)
	{
		if (prime[i])
		{
			for (int j = i + i; j < MAX_N; j += i)
				prime[j] = false;
		}
	}
}

void
solve(int n)
{
	int bins[MAX_N / 2];
	int remains[MAX_R];
	bool p[MAX_N];

	int m = (n - 1) / 2;
	if (prime[n] && n % 4 == 3)
	{
		for (int i = 1; i <= m; ++i)
			printf("%d\n", (n - 3) / 2);

		return;
	}

	for (int i = 0; i < n; ++i)
	{
		p[i] = false;
		if (i <= m)
			bins[i] = 0;
	}

	for (int i = 1; i < n; ++i)
		p[(i * i) % n] = true;

	int ix = 0;
	for (int i = 0; i < n; ++i)
	{
		if (p[i])
			remains[ix++] = i;
	}

	for (int i = 0; i < ix; ++i)
	{
		for (int j = i + 1; j < ix; ++j)
		{
			if (i != j)
			{
				int d = remains[i] - remains[j];
				if (d < 0)
					d += n;

				if (d > m)
					d = n - d;

				bins[d]++;
			}
		}
	}

	for (int i = 1; i <= m; ++i)
		printf("%d\n", 2 * bins[i]);
}

int
main(int argc, char **argv)
{
	prepare();
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		solve(n);
	}

	return 0;
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	map<ll, int> mp;
	FOR(i, n) {
		ll a;
		cin >> a;
		mp[a]++;
	}
	vector<ll> v;
	for (auto itr : mp) {
		FOR(cnt, itr.second/2) {
			v.push_back(itr.first);
		}
	}
	sort(v.begin(), v.end());
	int sz = v.size();
	cout << (sz < 2 ? 0 : v[sz-1]*v[sz-2]) << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <string.h>
 
int main(){
	char a[26] ,b[26], c[26];
	scanf("%s %s %s", &a, &b, &c);
 
	int x = strlen(a), y = strlen(b);
	if(a[x-1] == b[0] && b[y-1] == c[0]){
		printf("YES \n");
	}else {
		printf("NO \n");
	}
	return 0;
}

Measured memory_bytes: 1656
N, K = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

ans = 10 ** 12
for i in range(1, 2 ** N):
    if bin(i)[2:].count('1') != K: continue
    tmp = 0
    hmax = a[0]
    for j in range(1, N):
        if (i >> j) & 1:
            h = max(hmax + 1, a[j])
            tmp += h - a[j]
            hmax = h
        else:
            hmax = max(hmax, a[j])
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3064
//from PKU1125
main(){
	int i,j,n,k,K,a,b,d,dist[10][10];
	for(;scanf("%d",&k),k;printf("%d %d\n",K,k)){
		/*initialize*/
		memset(dist,11,sizeof(dist));
		for(i=0;i<=9;i++)dist[i][i]=0;
		for(n=0;k;k--){
			scanf("%d%d%d",&a,&b,&d);
			if(n<b)n=b;
			dist[a][b]=d,dist[b][a]=d;
		}

		{/*warshall-floyd*/
			int k,i,j;
			for(k=0;k<=n;k++)
				for(i=0;i<=n;i++)
					for(j=0;j<=n;j++)
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j];
		}

		for(k=99999999,i=0;i<=n;i++){
			for(d=j=0;j<=n;j++)d+=dist[i][j];
			if(k>d)k=d,K=i;
		}
	}
	exit(0);
}

Measured memory_bytes: 600
import numpy as np
n,h = map(int,input().split())
amax = 0
lst = []
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append(b)
lst.sort(reverse = True)

rui = np.cumsum(lst)
cnt = 10**10

for k in range(n):
    if rui[k] > h:
        cnt = min(cnt,k+1)
        break
    else:
        tmp = (h - rui[k]) // amax
        if (h - rui[k]) % amax != 0:
            tmp += 1
        cnt = min(cnt,k+tmp+1)
print(cnt)

Measured memory_bytes: 17880
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int n,m,k;
const int MOD = 998244353;
ll fact[222222];
ll ifact[222222];
ll pws[222222];
ll binom(int n, int k) {
	return fact[n]*ifact[n-k]%MOD*ifact[k]%MOD;
}
ll modpow(ll x, int pw) {
	if(pw == 0)
		return 1;
	ll hf = modpow(x, pw/2);
	hf = (hf*hf)%MOD;
	if(pw&1)
		hf = (hf*x)%MOD;
	return hf;
}
void solve(istream& cin, ostream& cout) {
	cin>>n>>m>>k;
	ll ans = 0;
	fact[0] = ifact[0] = 1;
	pws[0] = 1;
	REP(i, n) {
		pws[i+1] = pws[i]*m%MOD;
		fact[i+1] = fact[i]*(i+1)%MOD;
		ifact[i+1] = modpow(fact[i+1], MOD-2);
	}
	int sgn = -1;
	ll base = m;
	for(int blocks = 1; blocks <= n;blocks++) {
		if(blocks > 1)
			base = (base*(m-1))%MOD;
		ll rem = n-blocks;
		if(rem > k)
			continue;

		ans = (ans+base*binom(blocks+rem-1, rem)%MOD)%MOD;
	}

	cout <<ans<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 7884
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	vector<int> V(N);
	for (int i = 0; i < N; i++) V[i] = S[i] - '0';
	int COUNT = 0;
	for (int i = 0; i < N; i++) {
		if (N - 1 == ((N - 1) | i)) COUNT += V[i], COUNT %= 2;
	}
	if (COUNT % 2 == 1) {
		cout << 1 << endl;
		return 0;
	}
	vector<int> W(N - 1);
	for (int i = 0; i < N - 1; i++) {
		W[i] = abs(V[i] - V[i + 1]);
	}
	bool check = true;
	for (int i = 0; i < N - 1; i++) {
		if (W[i] != 0 && W[i] != 2) check = false;
	}
	if (!check) {
		cout << 0 << endl;
		return 0;
	}
	COUNT = 0;
	for (int i = 0; i < N - 1; i++) {
		W[i] /= 2;
		if (N - 2 == ((N - 2) | i)) COUNT += W[i], COUNT %= 2;
	}
	cout << (COUNT == 0 ? 0 : 2) << endl;
}

Measured memory_bytes: 9220
#include <cstdio>
#include <iostream>

int main()
{
	int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	printf("%d\n", std::max(0, (c * 60 + d) - (a * 60 + b) - e));
}

Measured memory_bytes: 3804
n = int(input())
w = [input() for _ in range(n)]
ng = []
last = ""
for i in range(n):
    if i != 0:
        if w[i] not in ng:
            word = w[i]
            if word[0] == last:
                last = word[len(word)-1]
                ng.append(word)
            else:
                print("No")
                exit()
        else:
            print("No")
            exit()
    else:
        word = w[i]
        last = word[len(word) - 1]
        ng.append(word)
print("Yes")


Measured memory_bytes: 3064
N, A, B,C,D = map(int,input().split())
S = list(input())

a = A-1
b = B-1
c = C-1
d = D-1

ans = 1

for i_a in range(a,C):
  #2連続の##がa~Cにないことを確認
  if S[i_a] == "#":
    if S[i_a+1] == "#":
      ans =0

for i_b in range(b,D):
  #2連続の##がb~Dにないことを確認
  if S[i_b] == "#":
    if S[i_b+1] == "#":
      ans =0

if D < C:
  ans = 0
  for i in range(b,D):
    #3連続があるなら1
    if S[i-1] == ".":
      if S[i] == ".":
        if S[i+1] == ".":
          ans = 1

if ans ==1:
  print("Yes")
else:
  print("No")


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

// keyが降順ソートされるmap
// map<int, int, std::greater<int>> edges;

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

  vector< vector< pair<int,int> > > graph(n);
  int a,b,c;
  for(int i=0;i<n-1;i++){
    cin >> a >> b >> c;
    a--;b--;
    graph[a].emplace_back(b,c);
    graph[b].emplace_back(a,c);
  }
  
  int questions,k;
  cin >> questions >> k;
  k--;
  
  vector<ll> distFromK(n);
  vector<bool> flag(n,false);
  queue<pair<int,ll>> q; q.emplace(k,0);
  while(!q.empty()){
    auto node = q.front(); q.pop();
    flag[node.first] = true;
    distFromK[node.first] = node.second;
    for(auto ed:graph[node.first]){
      if(flag[ed.first]==true)continue;
      q.emplace(ed.first, node.second+ed.second);
    }
  }
  
  int x,y;
  for(int i=0;i<questions;i++){
    cin >> x >> y; x--;y--;
    cout << distFromK[x]+distFromK[y] << endl;
  }
  return 0;
}



Measured memory_bytes: 11944
n , m = map(int,input().split())
kagi = []
for i in range(m):
    a , b = map(int,input().split())
    c = list(map(int,input().split()))
    k = 0
    for j in c:
        k += 1 << (j-1)
    kagi.append((a,k))
INF = 10 ** 9
dp = [[INF for i in range(m+1)] for i in range(2**n)]
dp[0] = [0 for i in range(m+1)]
for i in range(2**n):
    for j in range(1,m+1):
        dp[i][j] = min(dp[i][j],dp[i][j-1])
        t = i | kagi[j-1][1]
        dp[t][j] = min(dp[t][j],dp[i][j]+kagi[j-1][0])
print(dp[2**n-1][m] if dp[2**n-1][m] != INF else -1)

Measured memory_bytes: 110580
// AOJ 2880 Elevator
// 2018.3.21 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 高速入力関連
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()  // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

// 本問題関連
#define MAX 100005
int N, M;
typedef struct { int d, a, b, id; } T;
T t[MAX * 2]; int sz;
char ans[MAX];

// バイナリサーチ
typedef struct { int a, b; } B;
B data[MAX]; int BN;
void b_init() { BN = 2, data[1].a = data[1].b = MAX; }
int bsch(int x)
{
	int m, l = 0, r = BN;
	while (l < r) {
		m = (l + r) >> 1;
		if (data[m].a == x) return m;
		if (data[m].a < x) l = m + 1; else r = m;
	}
	return l - 1;
}

// ブロック移動（木構造にすればもっと高速になるのに）
static void insert(int l, int r, int a, int b)
{
	if (l > r) memmove(data + l + 1, data + l, sizeof(B)*(BN - l)), BN++;
	else if (l < r) memmove(data + l, data + r, sizeof(B)*(BN - r)), BN -= r - l;
	data[l].a = a, data[l].b = b;
}

// 空間の登録
void update(int a, int b)
{
	int l = bsch(a), r = bsch(b);
	if (b <= data[l].b) return;
	if (data[l].b < a) l++; else a = data[l].a;
	if (b < data[r].b) b = data[r].b;
	insert(l, r, a, b);
}

// a, bが同一空間にあるかどうか
int query(int a, int b)
{
	return b <= data[bsch(a)].b;
}

int cmp(const void *a, const void *b) {
	int t = ((T *)a)->d - ((T *)b)->d; if (t) return t;
	return ((T *)b)->id - ((T *)a)->id;
}

int main()
{
	int i, Q;
	static char *msg[] = { "No", "Yes" };

	N = in(), M = in(), Q = in();
	sz = 0; for (i = 0; i < M; i++) {
		t[sz].d = in(), t[sz].a = in(), t[sz].b = in(), t[sz].id = -1;
		sz++;
	}
	for (i = 0; i < Q; i++) {
		t[sz].d = in(), t[sz].a = in(), t[sz].b = in(), t[sz].id = i;
		sz++;
	}
	qsort(t, sz, sizeof(T), cmp);     // 時間昇順でソート

	b_init();
	for (i = 0; i < sz; i++) {
		if (t[i].id < 0) {            // エレベータの設置
			update(t[i].a, t[i].b);
		}
		else {                        // 移動可能かどうかについての問い合わせ
			if (t[i].a > t[i].b) ans[t[i].id] = 1;
			else ans[t[i].id] = query(t[i].a, t[i].b);
		}
	}
	for (i = 0; i < Q; i++) puts(msg[ans[i]]);
	return 0;
}



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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
using V = vector<int>;
using Vll = vector<ll>;
using Vstr = vector<string>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };
const int perm[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

bool isOK(V v, int index, int key) {
  if (v[index] >= key) return true;
  else return false;
}

int binary_search(V v, int key) {
  int left = -1;
  int right = (int)v.size();

  while (right - left > 1) {
    int mid = left + (right - left) / 2;

    if (isOK(v, mid, key)) right = mid;
    else left = mid;
  }

  return right;
}

/*
int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}
*/

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

  ll N;
  int X,M;
  cin >> N >> X >> M;

  V nextA(M);
  REP(i,M) {
    nextA[i] = (ll)i * i % M;
  }

  V trace(M, 0);
  trace[X] = 1;
  ll ans = X;
  int prev = ans;
  int ai;
  Vll traceans(M+1, 0);
  traceans[1] = ans;

  EACH(i,2,N) {
    ai = nextA[prev];
    if (trace[ai] == 0) {
      trace[ai] = i;
    } else {
      int loop_start = trace[ai];
      int loop_end = i;
      int loop_length = loop_end - loop_start;
      ll loop_sum = (traceans[loop_end-1] - traceans[loop_start-1]);
      ll loop_count = (N - i + 1) / loop_length;
      ll loop_amari = N - (loop_end + loop_length * loop_count) + loop_start;
      ans += loop_count * loop_sum;
      ans += traceans[loop_amari] - traceans[loop_start-1];
      debug(ans);
      break;
    }
    ans += ai;
    traceans[i] = ans;
    prev = ai;
  }

  print(ans);
}



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

#define F first    
#define S second
#define mp make_pair
#define pii pair<int,int>         
// mikty prikoldar
#define ll long long  
#define pb push_back
#define sz(a) (int)(a.size())
#define Accepted 0
#define endl '\n'
//everything goes according to the plan
#define y1 		 NOT
#define left   NEEDED
#define right  THINGS  
//countdown BEGAN. 10 , 9 , 8 ...
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 9223372036854775807;
const int Sz = 1110111;
// ai dyn dyn dyn dirindai ai dyn dyn dirindai
using namespace std;
// skr skr skr v chernih naikah
inline void Read_rap () {	// smoke weed everyday
  ios_base :: sync_with_stdio(0);
	cin.tie(0);      
}
string s;

int len;
       
int main() 
{
	Read_rap ();
	cin >> s;

	len = sz(s);
  int cnt = 0;
  for (int i = 0;i < sz(s);i ++) {
 		if (s[i] == 'S')	cnt ++;
 		if (s[i] == 'T') {
 			if (cnt)	len -= 2;
 			cnt --;
 		}
 		cnt = max (cnt, 0);
 	}
 	cout << len;


	return Accepted;
}	









// Coded by Z...

Measured memory_bytes: 720
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main()
{
	i64 n, k;
	cin >> n >> k;
	i64 ans = 1;
	ans *= k;
	ff(i, 1, n) {
		ans *= (k - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    s=raw_input()
    if s=="0":break
    L=[s]+[raw_input() for i in range(2)]
    for i in range(3):
        ca,cb=L[i][1:].count("A"),L[i][1:].count("B")
        ca,cb=(ca+1,cb) if ca>cb else (ca,cb+1)
        print ca,cb

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
   // freopen("input.txt", "r", stdin);
    SPEED
    ll n;
    cin >> n;
    ll ans = LLONG_MAX;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i) continue;
        ll j = n / i;
        ans = min(ans, abs(i - 1) + abs(j - 1));
    }
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll p[25];
    rep(i,0,N) cin >> p[i];
    ll ans = 0;
    rep(i,1,N-1){
        vector<ll> tt;
        tt.push_back(p[i-1]);
        tt.push_back(p[i]);
        tt.push_back(p[i+1]);
        sort(tt.begin(), tt.end());
        if(tt[1] == p[i]) ans++;
    }
    print(ans);
    
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc145/tasks/abc145_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    string s1 = s.substr(0, n / 2);
    string s2 = s.substr(n / 2, n / 2);
    if (n % 2 == 0 && s1 == s2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.math.{max,min}

object Main extends App {

  var m = readLine.split(" ").map(_.toInt)
  while( (m(0),m(1)) != (0,0) ){
    val Array(n,x) = m
    println( ( 1 until min(n-1,x/3) ).foldLeft(0) { (sum,i) => sum + max(min(n,(x-i+1)/2)- max(i+1,x-i-n),0)})

    m = readLine.split(" ").map(_.toInt)
  }
}

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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll d,n,ans;
int main()
{
    fast_io;
    cin>>d>>n;
    if(n==100)n++;
    ans=n;
    for(ll i=0;i<d;i++){
        ans*=100;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <string.h>  
#include<math.h>
int main()
{
	long long int i,n,s;
    	while(~scanf("%lld",&n))
	  {
	  	s=1;
	    for(i=1;i<=n;i++)
		{
		s*=i;
		s=s%(1000000007);
	}
		printf("%lld\n",s%1000000007);
	}
		
}

Measured memory_bytes: 128