akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>//pow(x,y)=x^y
#define rep(i,n) for (int i=0; i <(n);i++)
using namespace std;


int main() {
int X,N;
cin>>X>>N;
vector<int> p(N);

int q=0;
int r=0;
if(N!=0){
rep(i,N){cin>>p.at(i);}
rep(i,201){
  r=0;
  if(i==0){q=0;}
  else if(i%2==1){q=(pow((-1),i))*((i+1)/2);}
  else{q=(pow((-1),i))*(i/2);}
  rep(j,N){
    if(p.at(j)==(X+q)){break;}
    if(j==N-1){r=1;}
  }
if(r==1){break;}
}
cout << X+q << endl;
}
else{cout << X << endl;}
}


Measured memory_bytes: 3980
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n, l; cin >> n >> l;
    int sum = 0;
    int mini = 1000000;
    rep(i, n) {
        sum += l + i;
        if(abs(l + i) < abs(mini)) {
            mini = l + i;
        }
    }
    cout << sum - mini << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, i, ans;
    scanf("%d", &n);
    int b[n-1];

    for (i = 0; i < n - 1; i++) {
        scanf("%d", &b[i]);
    }
    ans = b[0] + b[n - 2];
    
    for (i = 1; i < n - 1; i++) {
        if (b[i-1] < b[i]) ans += b[i - 1];
        else ans += b[i];
    }

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

   int n;
   cin >> n;
   int cur = 1, x;
   for(int i = 0; i < n; i++){
       cin >> x;
       if(x == cur) cur++;
   }
   if(cur == 1){
       cout << -1 << endl;
   } else{
       --cur;
       cout << n - cur << endl;
   }
   return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, k;

void solve(){
    cin >> n >> k;
    ll arr[n + 1];
    for(ll i = 1; i <= n; i++)
        cin >> arr[i];
    vector<bool> vis(n + 1, false);
    vis[1] = true;
    vector<ll> steps;
    steps.push_back(1);
    ll curr = 1, cycle = -1;
    while(steps.size() <= k){
        // trace(curr);
        curr = arr[curr];
        if(vis[curr]){
            cycle = arr[curr];
            k -= steps.size();
            break;
        }
        vis[curr] = true;
        steps.push_back(curr);
    }
    // for(auto i : steps)
    //     trace(i);
    // trace(curr);
    if(cycle == -1){
        cout << steps.back() << endl;
    }else if(k == 0){
        cout << curr << endl;
    }else{
        // trace(cycle);
        steps.clear();
        ll cpy = arr[cycle];
        fill(vis.begin(), vis.end(), false);
        steps.push_back(cycle);
        while(cpy != cycle){
            steps.push_back(cpy);
            cpy = arr[cpy];
        }
        // for(auto i : steps)
        //     trace(i);
        ll t = steps.size();
        k--;
        cout << steps[k % t] << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

const int N = 3;

int a[N + 2];

int main()
{
    for(int i = 1; i <= N; i++)
        cin >> a[i];

    sort(a + 1, a + N + 1);

    cout << a[3] * 10 + a[2] + a[1] << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**21

def main():
    bingo = []
    punched = [[0 for i in range(3)] for j in range(3)]
    for i in range(3):
        bingo.append(getlist())

    n = getN()
    for ball in range(n):
        num = getN()
        for i, row in enumerate(bingo):
            for j, cell in enumerate(row):
                if num == cell:
                    punched[i][j] = 1

    for row in punched:
        if sum(row) == 3:
            print("Yes")
            return

    for i in range(3):
        if punched[0][i] and punched[1][i] and punched[2][i]:
            print("Yes")
            return

    if punched[0][0] and punched[1][1] and punched[2][2]:
        print("Yes")
        return

    if punched[0][2] and punched[1][1] and punched[2][0]:
        print("Yes")
        return

    print("No")
    return

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 38384
from collections import OrderedDict as d
a = list(map(str,input().split()))
m1 = d()
l = list(map(int,input().split()))
m1[a[0]]= l[0]
m1[a[1]] = l[1]
temp = input()
m1[temp]=m1[temp]-1
for i in m1.values():
  print(i,end=" ")

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

//https://atcoder.jp/contests/keyence2020/tasks/keyence2020_d

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9 + 7;

ll n;

ll uValue(ll v) {
	ll upper = v;
	while (true) {
		if (upper / 10 == 0) break;
		upper /= 10;
	}
	return upper;

}

ll dump() {
	ll c = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			auto u1 = uValue(i);
			auto u2 = uValue(j);
			auto l1 = i % 10;
			auto l2 = j % 10;
			if (u1 == l2 && u2 == l1) {
				//cout << i << " " << j << endl;
				c++;
			}

		}
	}
	return c;	
}

ll solve() {
	ll sum = 0;
	vector<vector<ll>> dp(10, vector<ll>(10, 0));
	for (int i = 1; i <= n; i++) {
		if (i % 10 == 0) continue;
		ll low = i % 10;
		ll upper = uValue(i);
		ll add = 0;
		if (upper == low) {
			add = 2 * dp[upper][low] + 1;
		}
		else {
			add = 2 * dp[upper][low];
		}
		dp[low][upper]++;
		sum += add;
		//cout << i << " " << add << " " << sum << endl;
	}
	return sum;
}

int main(void)
{
	cin >> n;
	ll sum = solve();
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
import Text.Printf(printf)

main :: IO ()
main = putStrLn . doubleListToStr . areaCircumf =<< readLn

areaCircumf :: Double -> [Double]
areaCircumf r = [pi * r ** 2, 2 * pi * r]

doubleListToStr :: [Double] -> String
doubleListToStr = unwords . map (printf "%.8f" :: Double -> String)

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
  int a,x,n,y;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> row(n);
  for(int i=0;i<n;i++){
    cin >> row[i];
  }
  int sa[3]={0,-1,1};
  for(int i=0;i<100;i++){
    for(int j=0;j<=2;j++){
      for(int k=0;k<n;k++){
        int y = x + sa[j] * i ;
        a = count(row.begin(), row.end(), y);
        if(a == 0){
          cout << y << endl;
          return 0;
        }
      }
    }
  }
  
}                                                                                                                                                     

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int n,k,sum=0;
int count(int x,vector<int> a){
    vector<int> c(n);
    int s=0;
    for(int i=0;i<n;i++){
        s+=a[i]%x;
        c[i]=x-a[i]%x;
    }
    sort(c.begin(),c.end());
    int ret=0;
    for(int i=0;i<s/x;i++){
        ret+=c[i];
    }
    return ret;
}
int main(){
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)sum+=a[i];
    int ret=0;
    for(int i=1;i<=(int)sqrt(sum);i++){
        if(sum%i==0){
            if(count(i,a)<=k)ret=max(ret,i);
            if(count(sum/i,a)<=k)ret=max(ret,sum/i);
        }
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define size(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using namespace std;


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

	if(X-A <= B && A <= X) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int h,w;
  cin >> h >> w;

  vector<vector<char>> b(h,vector<char>(w));
  for(int i = 0;i < h;i++) {
    for(int j = 0;j < w;j++) {
      cin >> b[i][j];
    }
  }

  vector<vector<int>> dp(h,vector<int>(w,MOD));
  if(b[0][0] == '.') dp[0][0] = 0;
  else dp[0][0] = 1;

  queue<pair<int,int>> Q;
  Q.push(make_pair(0,0));
  int dx[] = {1,0},dy[] = {0,1};
  bool seen[100][100] = {};
  while(!Q.empty()) {
    pair<int,int> q = Q.front();
    Q.pop();
    for(int i = 0;i < 2;i++) {
      int Y = q.first+dy[i],X = q.second+dx[i];
      if(Y >= h || X >= w) continue;
      if(b[Y][X] == '#' && b[q.first][q.second] == '.') dp[Y][X] = min(dp[Y][X],dp[q.first][q.second]+1);
      else dp[Y][X] = min(dp[Y][X],dp[q.first][q.second]);
      if(!seen[Y][X]) {
        Q.push(make_pair(Y,X));
        seen[Y][X] = true;
      }
    }
  }

  cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod = M) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

int main(void) {
  int p,q,r; cin >> p >> q >> r;
  cout << min(min(p+q,p+r),q+r) << "\n";
  return 0;
}


Measured memory_bytes: 256
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
#define endl '\n'
#define debug(x)  cerr<<"[ "<<#x<<" : "<<x<<" ]"<<endl
#define debugp(x) cerr<<"[ "<<#x<<".ff : "<<x.first<<", "<<#x<<".ss : "<<x.second<<" ]"<<endl
#define debugs(x) cerr<<"[ "; for(auto i:x) cerr<<i<<" "; cerr<<" ]"<<endl;
#define debugm(x) cerr<<"----------"<<endl; for(auto i:x) cerr<<i.ff<<":"<<i.ss<<endl; cerr<<"----------"; 
#define PI 3.14159265359
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int dxk[]={0,0,1,-1,1,1,-1,-1};
int dyk[]={1,-1,0,0,1,-1,1,-1};
const int inf = 1e+18;
const int mod = 1e+9 + 7;

void solve()
{
	int n;
	cin>>n;
	map<string, int> mp;
	while(n--){
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
}

int32_t main()
{
  fast;
  //test
  solve();
  return 0;
}


Measured memory_bytes: 3616
using System;
using System.IO;
using System.Linq;

namespace Atcoder {
    class abc043c {
        public static void Main(){
            int n = int.Parse(Console.ReadLine());

            string[] ss = Console.ReadLine().Split(' ');

            var arri = ss.Select(s => int.Parse(s));

            int min_total = arri.Select(i => pow(i - 100)).Sum();
            for(int i = -100; i < 100; i++){
                min_total = Math.Min(min_total, arri.Select(x => pow(x - i)).Sum());
            }

            Console.WriteLine(min_total);
        }

        static int pow(int n){
            return n * n;
        }
    }
}


Measured memory_bytes: 2904
while True:
    num = int(input())
    if num==0:
        break
    L = []
    for i in range(num):
        n, *k = input().split()
        L.append( (n, k.count("0"), k.count("1"), i) )
    L.sort(key=lambda x:(-x[1],x[2],x[3]) )
    
    for x in L:
        print(x[0])
    


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;


int main(){
  ld R;
  cin >> R;
  cout << 2*M_PI*R << endl;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
template<typename T>
inline T GET() {
	T val;
	cin >> val;
	return val;
}

void init();
void solve();

signed main()
{
    init();
    solve();
}

int N, W;
vector<vector<ll> > dp;
vector<int> v, w;

void init()
{
	cin >> N >> W;
	dp.RS(N+1, vector<ll>(W+1, 0));
	rep(i, N) {
		w.PB(GET<int>());
		v.PB(GET<int>());
	}
}

void solve()
{
	rep(i, N) {
		rep(j, W+1) dp[i+1][j] = dp[i][j];
		reps(j, w[i], W+1) {
			dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;
}



Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<char> form(string s) {
	vector<char> res;
	for (char c: s) {
		res.push_back(c);
	}
	sort(res.begin(),res.end());
	return res;
}

int main()
{
	int N; cin >> N;
	map<vector<char>,int> mp;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		auto p = form(s);
		ans += mp[p];
		mp[p]++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using P = pair<int, int>;
const int INF = 1001001001;
int dp[1000005][2];

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += '0';
    int n = s.size();
    rep(i, n+1)rep(j, 2) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, n)rep(j, 2){
        int x = s[i] - '0';
        x += j;
        rep(a, 10){
            int ni = i+1, nj = 0;
            int b = a-x;
            if(b < 0){
                nj = 1;
                b += 10;
            }
            dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b);
        }
    }
    int ans = dp[n][0];
    cout << ans << endl;

    // rep(i, 10)rep(j, 10){
    //     cout << i << j << " " << dp[i][j] << endl;
    // }
    return 0;
}

Measured memory_bytes: 12136
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

vector<pair<int,ll>> factorization(ll N) {
    vector<pair<int,ll>> ans;
    for (ll i = 2;i*i <= N; ++i) {
        ll e = 1;
        while (N%i == 0) {
            e *= i;
            N /= i;
        }
        if (e > 1) ans.emplace_back(i,e);
    }
    if (N > 1) ans.emplace_back(N,N);
    return ans;
}

template<class T> T gcd(T a,T b) {return (b ? gcd(b,a%b): a);}
long long x,y;
long long extGCD(long long a,long long b,long long &x,long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b,a%b,y,x);
    y -= a/b * x;
    return d;
}

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

    ll N; cin >> N;
    N *= (ll)2;
    auto facter = factorization(N);
    ll ans = HINF;
    int s = facter.size();
    rep(i,1<<s) {
        ll l = 1,r = 1;
        rep(j,s) {
            if ((i>>j)&1) l *= facter[j].second;
            else r *= facter[j].second;
        }
        debug(l,r);
        extGCD(l,r,x,y);
        while (x < 0) {
            x += r;
            y -= l;
        }
        x -= r;
        y += l;
        ans = min(ans,-l*x);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;
//#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}




int main() {
	int n,sma=2000000004;
	cin >> n;
	vector<int>vec(n);
	vecin(vec);
	for (int i = n - 1; i >= 0; i--){
		if (vec[i] - 2 >= sma) {
			cout << "No" << endl;
			return 0;
		}
		sma = min(sma, vec[i]);
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
string a;
vector<int> v;
lld dp[1000001];
int main(void){
	int n;
	cin >> n >> a;
	dp[0] = 0;
	for(int e=1;e<1000001;e++) {
		int num = 0,now = e;
		while(now%2==0){
			now/=2;
			num++;
		}
		dp[e] = dp[e-1] + num;
	}
	for(int e=0;e<n-1;e++) v.push_back(abs(a[e]-a[e+1]));
	int tot = 0,nt = 0;
	for(int e=0;e<n-1;e++){
		if(v[e]==1){
			nt++;
			int nn = n-2, rr = e;
			int diff = dp[nn] - dp[rr] - dp[nn-rr];
			if(diff==0) tot ^= 1;
		}
	}
	if(tot) printf("1");
	else{
		if(nt) printf("0");
		else{
			for(int e=0;e<n-1;e++) v[e]/=2;
			int tot = 0;
			for(int e=0;e<n-1;e++){
				if(v[e]==1){
					int nn = n-2,rr = e;
					int diff = dp[nn] - dp[rr] - dp[nn-rr];
					if(diff==0) tot ^= 1;	
				}
			}
			if(tot) printf("2");
			else printf("0");
		}
	}
}

Measured memory_bytes: 15484
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] b = new int[n-1];
		for(int i = 0; i < n-1; i++){
			b[i] = sc.nextInt();
		}
		int sum = b[0];
		for(int i = 1; i < n-1; i++){
			sum += Math.min(b[i-1],b[i]);
		}
		sum += b[n-2];
		System.out.println(sum);
	}
}


Measured memory_bytes: 23764
#include <cstdio>

int main(){
    int m,f,r;
    while(true){
        scanf("%d%d%d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1)
             break;
        else if(m == -1 || f == -1)
            printf("F");
        else if(m + f >=80)
            printf("A");
        else if(m + f >=65 && m + f < 80)
            printf("B");
        else if(m + f >=50 && m + f < 65)
            printf("C");
        else if(m + f >=30 && m + f < 50 && r >= 50)
            printf("C");
        else if(m + f >=30 && m + f < 50 && r < 50)
            printf("D");
        else
            printf("F");
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2688
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    b = LI()
    b = b[::-1]
    ans = deque([])
    while len(b) != 0:
        for num, i in enumerate(b):
            if n - num == i:
                ans.appendleft(i)
                n -= 1
                del b[num]
                break
        else:
            print(-1)
            return
    for i in ans:
        print(i)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lli s;
  cin >> s;
  vector< lli > v;
  REPS(i, 1000000) {
    if (find(ALL(v), s) != v.end()) {
      cout << i << "\n";
      return 0;
    }
    v.push_back(s);
    s = (s % 2 == 0) ? s / 2 : s * 3 + 1;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	cout << N * N*N << endl;

	return 0;
}



Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ABC = il()
    mx = max(ABC)
    sm = sum(ABC)
    m = mx * 3 - sm
    while m % 2 != 0:
        m += 3
    print(m//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10152
#!/usr/bin/env python3
n = input()
N = len(n)
k = int(input())
dp = [[[0] * 2 for j in range(k + 1)] for i in range(N + 1)]
dp[0][0][0] = 1
for i in range(N):
    for j in range(k + 1):
        d = int(n[i])
        
        # i 桁目に "0" を配置したとき
        if d > 0:
            dp[i + 1][j][1] += dp[i][j][0]
        else:
            dp[i + 1][j][0] += dp[i][j][0]
        dp[i + 1][j][1] += dp[i][j][1]

        # i 桁目に "1", ..., "9" を配置したとき
        if j < k:
            if d > 0:
                dp[i + 1][j + 1][0] += dp[i][j][0]
                dp[i + 1][j + 1][1] += dp[i][j][0] * (d - 1)
            dp[i + 1][j + 1][1] += dp[i][j][1] * 9

print(dp[N][k][0] + dp[N][k][1])


Measured memory_bytes: 3064
def main():
    N=int(input())
    xy=[[int(_) for _ in input().split()] for _ in range(N)]
    distance = 0
    for i in range(N-1):
        for j in range(i, N):
            distance += ( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 ) ** 0.5
    print(distance / (N/2))

main()

Measured memory_bytes: 3060
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
struct edge {
	int to, cost;
};
int n; 
int a[100005], b[100005], c[100005];
int dp[100006];
vector<edge>G[100006];

int subtree[100006];
vector<int>centor;

int memo(int now, int par) {
	if (dp[now])return dp[now];
	int sum = 1;
	for (edge E : G[now]) {
		int e = E.to;
		if (e == par)continue;
		sum += memo(e, now);
	}
	return dp[now] = sum;
}
void dfs(int now, int par) {
	subtree[now] = 1;
	bool isc = true;
	for (edge E : G[now]) {
		int e = E.to;
		if (e == par)continue;
		dfs(e, now);
		if (subtree[e] > n / 2)isc = false;
		subtree[now] += subtree[e];
	}
	if (n - subtree[now] > n / 2)isc = false;
	if (isc)centor.push_back(now);
}

signed main() {
	cin >> n;
	rep(i, n - 1) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		if (a[i] > b[i])swap(a[i], b[i]);
		G[a[i]].push_back({ b[i],c[i] });
		G[b[i]].push_back({ a[i],c[i] });
	}
	dfs(0, -1);
	memo(0, -1);

	int sum = 0;
	rep(i, n - 1) {
		int r = min(dp[a[i]], dp[b[i]]), l = n - r;
		sum += c[i] * min(l, r) * 2;
	}

	if (centor.size() == 2) {
		rep(i, n - 1) {
			if (a[i] == centor[0] && b[i] == centor[1]) {
				sum -= c[i];
				cout << sum << endl;
				return 0;
			}
			if (a[i] == centor[1] && b[i] == centor[0]) {
				sum -= c[i];
				cout << sum << endl;
				return 0;
			}
		}
	}
	else {
		int mx = inf;
		for(edge E : G[centor[0]])mx = min(mx, E.cost);
		cout << sum - mx << endl;
	}

}


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

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

  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }

  vector<int> a(n);
  bool flag = true;

  for (int i = 0; i < n; i++) {
    a.at(i) = 0;
  }

  if (n > 1) {
    a.at(0) = 1;
  }

  if (m > 0) {
    for (int i = 0; i < m; i++) {
      if (a.at(s.at(i) - 1) == 0 || a.at(s.at(i) - 1) == c.at(i) ||
          (s.at(i) - 1) == 0 && n > 1 && a.at(s.at(i) - 1) == 1) {
        a.at(s.at(i) - 1) = c.at(i);
      } else {
        flag = false;
        break;
      }
    }
  }

  if (a.at(0) == 0 && n > 1) {
    flag = false;
  }

  if (flag) {
    for (int i = 0; i < n; i++) {
      cout << a.at(i);
    }
  } else {
    cout << -1;
  }
  cout << endl;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())
if b-a<k*2:
  for i in range(a,b+1,1):
    print(i)
else:
  for i in range(a,a+k,1):
    print(i)
  for j in range(b-k+1,b+1,1):
    print(j)


Measured memory_bytes: 3060
N = int(input())                                                                                                                                             
h = list(map(int,input().split()))                                                                                                                           
dp = [float('inf')] * N                                                                                                                                      
dp[0] = 0                                                                                                                                                    
                                                                                                                                                             
def chmin(lst,a,b):                                                                                                                                          
    if lst[a]>b:                                                                                                                                             
        lst[a]=b                                                                                                                                             
                                                                                                                                                             
def chmax(lst,a,b):                                                                                                                                          
    if lst[a]<b:                                                                                                                                             
        lst[a]=b                                                                                                                                             
                                                                                                                                                             
for i in range(1,N):                                                                                                                                         
    chmin(dp,i,dp[i-1]+abs(h[i-1]-h[i]))                                                                                                                     
    if i>1:                                                                                                                                                  
        chmin(dp,i,dp[i-2]+abs(h[i-2]-h[i]))                                                                                                                 
                                                                                                                                                             
print(dp[N-1])                                                                                                                                               
                      

Measured memory_bytes: 13908
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

long long int N, A, B;

long long int h[200000];

bool check(long long int num){
	
	long long int count = 0;
	
	for(int i = 0; i < N; i++){
		if(h[i] - B * num <= 0){
			continue;
		}
		count += (h[i] - B * num - 1) / (A - B) + 1;
	}
	
	//cout << num << " " << count << endl;
	
	return count <= num;
}

long long int binary_search_2(long long int lef, long long int rig){
	long long int middle = (lef + rig) / 2;
	if(rig - lef <= 1){
		if(check(lef)){
			return lef;
		}else{
			return rig;
		}
	}
	if(check(middle)){
		rig = middle;
	}else{
		lef = middle;
	}
	return binary_search_2(lef, rig);
}

int main(){
	
	cin >> N >> A >> B;
	
	for(int i = 0; i < N; i++){
		cin >> h[i];
	}
	
	long long int ans = binary_search_2(1, 10000000000);
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	vector<string> ans;
	if (s.size() < t.size())
	{
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (int i = 0; i <= s.size() - t.size(); i++)
	{
		bool ok = true;
		for (int j = 0; j < t.size(); j++)
			if (s[i + j] != '?' && s[i + j] != t[j])
				ok = false;
		if (ok)
		{
			string tmp = s;
			for (int j = 0; j < t.size(); j++)
				tmp[i + j] = t[j];
			for (int j = 0; j < s.size(); j++)
				if (tmp[j] == '?')
					tmp[j] = 'a';
			ans.push_back(tmp);
		}
	}

	if (ans.size() == 0)
		cout << "UNRESTORABLE" << endl;
	else
	{
		sort(ans.begin(), ans.end());
		cout << ans[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char c,a,e,i,o,u;
	
	int x=0;
	
	scanf("%c",&c);
	
	char vowel[]={'a','e','i','o','u'};
	
	for(int i=0;i<5;i++){
		if(vowel[i]==c){
			x++;
		}
	}
	
	if(x!=0){
		printf("vowel\n");
	}else{
		printf("consonant\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int times(int n){
       int times=0;
       while(n%2==0){
             n/=2;
             times++;
       }
       return times;
}
int main(){
       int n;
       scanf("%d",&n);
       int max=0,maxn=1;
       for(int i=1;i<=n;i++){
              if(times(i)>max){
                     max=times(i);
                     maxn=i;
              }
       }
       printf("%d",maxn);
       return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    
   int n;
   cin>>n;
   vector<ll> A(n), sum(n+1, 0);
   rep(i,n){
       cin>>A[i];
       sum[i+1] = sum[i] + A[i];
   }
   sort(sum.begin(), sum.end());
    
    map<ll, ll> mp;
   for(auto s:sum){
    //    cout<<s<<" ";
       mp[s]++;
   }
//    cout<<endl;
    ll ans=0;
    for(auto m:mp){
        ans+=m.second*(m.second-1)/2;
    }
    
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 18624
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

struct rng {
    struct A {
        int n;
        const bool operator!=(A r) { return n != r.n; }
        A& operator++() { n++; return *this; }
        int operator*() { return n; }
    };
    int l, r;
    rng(int r) : l(0), r(max(0, r)) {}
    rng(int l, int r) : l(l), r(max(l, r)) {}
    A begin() { return A{l}; }
    A end() { return A{r}; }
};

const int MD = 2000 * 2000 + 100;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    int n;
    cin >> n;
    V<int> a(n);
    int sm = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sm += a[i];
    }

    bitset<MD> bs;
    bs[0] = true;
    for (int d: a) {
        bs |= bs << d;
    }

    for (int i = (sm+1)/2; i <= sm; i++) {
        if (!bs[i]) continue;
        cout << i << endl;
        return 0;
    }
    assert(false);
    return 0;
}


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

int main()
{
    char s[105];
    scanf("%s",s);
    int lens=strlen(s);
   int i;
   for(i=0;i<lens;i++)
    {
        printf("x");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int a, b, c, x; cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000005

int A[MAX], G[MAX], n, cnt=0, m=1;

void insertSort(int g){
	int i,j,v;
	
    for(i=g+1; i<=n; i++){
		v=A[i];
		j=i-g;
		while(j>=1 && A[j]>v){
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}


int main(){
  int i;	
  scanf("%d",&n);
  
  for(i=1; i<=n; i++)
        scanf("%d", &A[i]);
        
  G[1]=1;
  while(G[m]*3+1<n){
	m++;
	G[m]=G[m-1]*3+1;
  }
  
  for(i=m; i>=1; i--)
	  insertSort(G[i]);
  printf("%d\n",m);
  
  for(i=m; i>=1; i--)
	  printf("%d ",G[i]);
	  
  printf("\n");
  printf("%d\n",cnt);
  
  for(i=1; i<=n; i++)
	  printf("%d\n",A[i]);
 
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;

}


Measured memory_bytes: 3608
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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


    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vl A(X); REP(i, X) cin >> A[i];
    vl B(Y); REP(i, Y) cin >> B[i];
    vl C(Z); REP(i, Z) cin >> C[i];
    //sort(A.begin(), A.end(), greater<ll>());
    //sort(B.begin(), B.end(), greater<ll>());
    //sort(C.begin(), C.end(), greater<ll>());

    vl ab;
    REP(i,X) {
        REP(j,Y) {
            ab.push_back(A[i] + B[j]);
        }
    }    
    sort(ab.begin(), ab.end(), greater<ll>());

    vl ans;
    REP(i, min((int)ab.size(),K)) {
        REP(j,Z) {
            ans.push_back(ab[i] + C[j]);
        }
    }

    sort(ans.begin(), ans.end(), greater<ll>());
    REP(i,K) cout << ans[i] << endl;    

    return 0;
}

Measured memory_bytes: 43112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    map<int, ll> cnt;
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    vector<ll> vec;
    for (auto p : cnt) {
        vec.push_back(p.second);
    }
    sort(all(vec));
    vector<ll> sum(sz(vec) + 1);
    rep(i, sz(vec)) sum[i + 1] = sum[i] + vec[i];

    for (ll k = 1; k <= n; k++) {
        ll ok = 0, ng = INF;
        while (ng - ok > 1) {
            ll mid = (ok + ng) / 2;
            ll idx = (ll)(lower_bound(all(vec), mid) - vec.begin());
            if (sum[idx] + mid * (ll)(sz(vec) - idx) >= mid * k) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << ok << endl;
    }
}


Measured memory_bytes: 23532
n, m = map(int,input().split())

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,b+1):
        ans *= (i%mod)
        ans %= mod
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    print((2*ans)%mod)

Measured memory_bytes: 38768
#include<iostream>

using namespace std;

int main()
{
  int K;
  int A,B;
  cin >> K >> A >> B;
  for(int i=A;i<=B;i++)
  {
    if(i%K == 0)
    {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC020
{
    class IceRinkGame
    {
        public static void Main()
        {
            var k = int.Parse(ReadLine().Trim());
            var a = ReadLine().Trim().Split(' ').Select(_ => long.Parse(_)).Reverse();
            long min_rest = 2, max_rest = 2;
            foreach(var ar in a)
            {
                var temp = MinChildren(ar, min_rest, max_rest);
                max_rest = MaxChildren(ar, min_rest, max_rest);
                min_rest = temp;
            }
            if (min_rest == -1) WriteLine(-1);
            else WriteLine($"{min_rest} {max_rest}");
        }
        //脱落する人数は高々Ai - 1人
        //突破する人数はN * Ai人
        static long MinChildren(long group, long min_rest, long max_rest)
        {
            if (min_rest == -1) return -1;
            if (min_rest % group == 0) return min_rest;
            return (min_rest / group != max_rest / group) ? group * (min_rest / group + 1) : -1;
        }
        static long MaxChildren(long group, long min_rest, long max_rest)
        {
            if (min_rest == -1) return -1;
            return max_rest / group * group + group - 1;
        }

    }
}


Measured memory_bytes: 28636