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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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

int isMonth(int x)
{
  return 1 <= x && x <= 12;
}

int main()
{
  string S; cin >> S;
  int a = 0, b = 0;
  a = 10*(S[0] - '0') + (S[1] - '0');
  b = 10*(S[2] - '0') + (S[3] - '0');
  bool fa = isMonth(a);
  bool fb = isMonth(b);
  if (fa && fb) cout << "AMBIGUOUS" << endl;
  else if (!fa && fb) cout << "YYMM" << endl;
  else if (fa && !fb) cout << "MMYY" << endl;
  else cout << "NA" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll a[100010],b[100010];

int main(void){
	          int i;

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

	          ll c=0;
	          for(i=N;i>=1;i--){
	        	  a[i]+=c;
	        	  if(a[i]%b[i]==0) continue;
	        	  ll x=(a[i]+b[i]-1)/b[i];
	        	  c+=b[i]*x-a[i];
	          }

	          cout << c << endl;

	          return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void init() {

}

const int MAX = 18;
int dp[1 << MAX];
int t[MAX][MAX];

void solve(int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            scanf("%d", &t[i][j]);
        }
    }
    fill(begin(dp), end(dp), INF);
    dp[0] = 0;
    for (int i = 1; i < (1 << n); i++) {
        vector<int> v{0};
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                v.emplace_back(j + 1);
            }
        }
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                for (int e : v) {
                    if (j != e - 1) {
                        chmin(dp[i], dp[i & (~(1 << j))] + t[j][e]);
                    }
                }
            }
        }
    }
    printf("%d\n", dp[(1 << n) - 1]);
}

int main(void) {
	int a, b, c, x, y, z, n, m, p;
	string s;
	while (cin >> n, n) {
		solve(n);
		//break;
	}
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  string s, t;
  cin >> s >> t;

  int ans = 0;
  rep(i,0,sz(s)) if (s[i] != t[i]) ++ans;
  cout << ans << '\n';
}


Measured memory_bytes: 3880
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==c && a!=b || a==b && a!=c || b==c && b!=a)
        puts("Yes");
    else
        puts("No");
    return 0;
    
    
}

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

import sys
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

Q = INT()
_, a, b = MAP()
mid = a
asm = 0
bsm = b
ln = 1
que1, que2 = [-a], [INF]
for _ in range(Q-1):
    li = LIST()
    if li[0] == 1:
        a, b = li[1:]
        bsm += b
        l = -que1[0]
        r = que2[0]
        if ln % 2 == 1:
            asm += abs(a - l)
            if a < mid:
                heappush(que1, -a)
                heappush(que2, -que1[0])
                heappop(que1)
            else:
                heappush(que2, a)
        else:
            if a < l:
                asm += abs(a - l)
            elif a > r:
                asm += abs(a - r)
            if a > mid:
                heappush(que2, a)
                heappush(que1, -que2[0])
                heappop(que2)
            else:
                heappush(que1, -a)
        ln += 1
        mid = -que1[0]
    else:
        print(mid, asm + bsm)


Measured memory_bytes: 11128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

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

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define TEST 0

	if (TEST) {
		test;
		solve();
	} else {
		solve();
	}

	return 0;
}

Measured memory_bytes: 3636
n,m=map(int,input().split())
p=list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
#uf = UnionFind(n) #初期化
#uf.union(0, 2)#グループを併合
#uf.find(0) #親要素が変える

uf=UnionFind(n)
for _ in range(m):
    x,y=map(int,input().split())
    uf.union(x-1,y-1)
cnt=0
for i in range(n):
    
    if uf.find(i)==uf.find(p[i]-1):
        cnt+=1

print(cnt)

Measured memory_bytes: 89964
#include<stdio.h>

int main(){
	char string[15];
	scanf("%s", &string);
	int i=0, length=0, max=0;
	while(string[i] != '\0'){
		if((string[i]=='A') || (string[i]=='C') || (string[i]=='G') || (string[i]=='T')){
			length++;
		}
		else{
			if(max < length) max = length;
			length = 0;
		}
		i++;
	}
	if(max < length) max = length;
	printf("%d", max);
	
	return 0;
}

Measured memory_bytes: 128
import java.io.*;

public class Main{
	public static void main(String[] args){
      try{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String str = br.readLine();
      if(Character.isUpperCase(str.charAt( 0 ))){
      	System.out.println("A");
      }
      else{
        System.out.println("a");
      }
      }
      catch(IOException e){
      	System.out.println("a");
      }
    }
}


Measured memory_bytes: 32540
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, input().split())

al = H * W

if H == 1 or W == 1:
    ans = 1
elif al % 2 == 0:
    ans = al // 2
else:
    ans = (al + 1) // 2

print(ans)


Measured memory_bytes: 3060
use whiteread::parse_line;

fn fight(hp: usize) -> usize {
    let ans = match hp {
        1 => 1,
        _ => fight(hp / 2) * 2 + 1,
    };
    ans
}

fn main() {
    let h: usize = parse_line().unwrap();
    println!("{}", fight(h));
}


Measured memory_bytes: 2192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector <int> a(100001, 0);
  vector <int> b(100001, 0);
  for (int i = 0; i < n; i++) {
	  int v;
	  cin >> v;
	  if (i % 2) {
		  a[v]++;
		} else {
		  b[v]++;
		}
	}
  int ma = 0;
  int na = 0;
  int mb = 0;
  int nb = 0;
  for (int i = 1; i <= 100000; i++) {
	  if (a[i] > a[ma]) {
		  na = ma;
		  ma = i;
		} else if (a[i] > a[na]) {
		  na = i;
		}
	  if (b[i] > b[mb]) {
		  nb = mb;
		  mb = i;
		} else if (b[i] > b[nb]) {
		  nb = i;
		}
	}
  if (ma != mb) {
	  cout << n - a[ma] - b[mb] << endl;
	} else {
	  cout << n - max(a[ma] + b[nb], a[na] + b[mb]) << endl;
	}
  return 0;
}


Measured memory_bytes: 1024
using System;
class D_Rain{
	static void Main(string[] args){
		int N = int.Parse(Console.ReadLine());
		string[] strA = Console.ReadLine().Split(' ');
		int[] A = new int[N];
		for(int i = 0;i < N;i++){
			A[i] = int.Parse(strA[i]);
		}
		int B_b = 0;
		for(int i = 0;i < N;i++){
			B_b += A[i] * ((i % 2 == 0) ? 1 : -1);
		}
		Console.Write(B_b);
		for(int i = 0;i < N - 1;i++){
			B_b = 2 * A[i] - B_b;
			Console.Write(" {0}",B_b);
		}
		Console.WriteLine();
	}
}

Measured memory_bytes: 28372
N, M, Q = map(int, input().split())

T = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

for _ in range(M):
    L, R = map(int, input().split())
    T[L][R] += 1

for L in range(1, N + 1):
    for R in range(1, N + 1):
        T[L][R] += T[L - 1][R]
        T[L][R] += T[L][R - 1]
        T[L][R] -= T[L - 1][R - 1]

for _ in range(Q):
    P, Q = map(int, input().split())
    ans = 0
    ans += T[Q][Q]
    ans -= T[P - 1][Q]
    ans -= T[Q][P - 1]
    ans += T[P - 1][P - 1]
    print(ans)

Measured memory_bytes: 14880
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s),(e),(step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define CINS(x) for(auto&& __E__:(x))cin>>__E__
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))
#define MOD 1000000007

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    CINS(a);

    sort(ALL(a));

    int sum = 0;

    for (int i : range(k)) {
        sum += a[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    if M <= 2 * N:
        print(M // 2)
    else:
        k = (M - 2 * N) // 4
        ans= 0
        for i in range(max(0, k - 4), min(M // 2, k + 4)):
            if (M - 2 * i) <= 2 * (N + i):
                ans = max(ans, (M - 2 * i) // 2)
            else:
                ans = max(ans, N + i)
        print(ans)
    
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 61820
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#include <string>

using namespace std;

int main(){
    int t;
    cin >> t;
    for (int i=0; i<t; i++) {
        int n ,k;
        cin >> n >> k;
        vector<int> x(n);
        vector<int> y(n-1);
        for (int j = 0; j<n; j++) {
            cin >> x[j];
        }
        if (n <= k) {
            cout << 0 << endl;
            continue;
        }
        for (int j=0; j<n-1; j++) {
            y[j]=x[j+1]-x[j];
        }
        sort(y.begin(), y.end());
        int ans = x[n-1]-x[0];
        for (int j=0;j<k-1; j++) {
            ans -= y[n-j-2];
        }
        cout << ans<<endl;
    }
}

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

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

    long long n;
    cin >> n;
    vector<long long> A(n);
    for(long long i = 0; i < n; i++){
        cin >> A[i];
        A[i] -= (i + 1);
    }

    sort(A.begin(), A.end());

    long long ans = 0;
    long long mid = (n % 2 ? A[n / 2] : (A[n / 2] + A[n / 2 - 1]) / 2);
    for(long long i = 0; i < n; i++){
        ans += abs(A[i] - mid);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

#define REP(i, N) for(int i = 0; i < (int)N; ++i)

// 3 ** 11
int N, M;
int num[200000];
int dp[200000];

int encode(string s) {
	int h = 0;
	for(int i = 0; i < s.size(); i++) {
		h = h * 3 + s[i] - '0';
	}
	return h;
}

void decode(int c, string &s) {
	REP(i, M) {
		s[M - 1 - i] = '0' + c % 3;
		c /= 3;
	}
}

int get_num(string str) {
	int state = encode(str);
	if( num[state] >= 0 ) return num[state];
	
	int res = 0;
	for(int i = 0; i < str.size(); i++) {
		if( str[i] == '2' ) {
			str[i] = '0';
			res += get_num(str);
			str[i] = '1';
			res += get_num(str);
			break;
		}
	}
	return num[state] = res;
}

int rec(string s) {
	int state = encode(s);
	if( get_num(s) <= 1 ) return 0;
	if( dp[state] >= 0 ) return dp[state];
	int res = 999999;
	for(int i = 0; i < s.size(); i++) {
		if( s[i] == '2' ) {
			int t = 0;
			s[i] = '0';
			t = max(t, 1 + rec(s));
			s[i] = '1';
			t = max(t, 1 + rec(s));
			s[i] = '2';
			res = min(t, res);
		}
	}
	return dp[state] = res;
}

int main() {
	for(;;) {
		cin >> M >> N;
		if( N == 0 && M == 0 ) break;
		memset(num, -1, sizeof(num));
		memset(dp, -1, sizeof(dp));
		REP(i, N) {
			string str;
			cin >> str;
			int key = encode(str);
			num[key] = 1;
		}
		
		int three = 1;
		REP(i, M) three *= 3;
		
		string s(M, '2');
		int ans = rec(s);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2492
using namespace std;
#include<bits/stdc++.h>
// #include<iostream>
// #include<string>
// #include<vector>
// #include<set>
// #include<map>
// #include<algorithm>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUT4(P1,P2,P3,P4) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<" "<<(P4)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

long H,W,h,w;
inline void solve(void){
  IN4(H,W,h,w);
  OUT((H-h)*(W-w));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

const int amax = 1e6;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());

	vector<int> cnt(amax + 1);
	for (int i = 0; i < n; i++) {
		if (cnt[a[i]] == 0) {
			for (int j = a[i]; j < cnt.size(); j += a[i]) cnt[j] = 1;
		}
		else if (cnt[a[i]] == 1) cnt[a[i]] = 2;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (cnt[a[i]] == 1) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8004
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n ;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ll ans = 1e18;
    rep(i,101){
        if(i==0)continue;
        ll t  = 0;
        rep(j,n){
            t += (i-a[j])*(i-a[j]);
        }
        ans = min(ans,t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
//#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define YES printf("YES\n") ;
#define NO printf("NO\n") ;
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((ll) a.size())
typedef long long ll ;
const int MAXN = 1e6 + 10;
ll inf  = 1e18 ;
using namespace std ;
ll mod = 1e9 + 7;
ll mul(ll a , ll b){return ((a%mod)*(b%mod))%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a) ;}
ll powr(ll a , ll b) {if(b == 0) return 1LL ;ll x = powr(a,b/2) ;x = mul(x,x) ;if(b%2) return mul(a,x);return x;}
int main () {
    
    string s,t ;
    cin >> s >> t ;
    int c = 0;
    for(int i =0 ; i < 3 ;i++)
        if(s[i]==t[i])c++ ;
    cout<<c<<endl;
    return 0 ;
}


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

int main() {
  long long a,b;
  cin>>a>>b;
  long long c=gcd(a,b);
  long long factor=1;
  for(long long i=2;i<=sqrt(c);i++){
    if(c%i==0){
      factor++;
      while(c%i==0){
        c/=i;
      }
    }
  }
  if(c!=1) factor++;
  cout<<factor<<endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (i > 0 && s[i - 1] == 'B' && s[i] == 'C') {
      cnt += 2;
      i -= 1;
    } else if (s[i] == 'A') {
      ans += cnt / 2;
    } else {
      cnt = 0;
    }
  }
  cout << ans << '\n';
  return 0; // :)
}


Measured memory_bytes: 3736
def main():
    A,B,C = (int(_) for _ in input().split())

    moneyInHand = B
    countOfListen = 0
    for i in range(C):
        if moneyInHand < A:
            break
        moneyInHand -= A
        countOfListen += 1

    print(countOfListen)

if __name__ == '__main__':
    main()


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

int main() {
    string N;
    cin>>N;
    int sum=0;
    for (int i = 0; i < N.size(); i++){
        sum+=(int)N[i]-(int)'0';
    }
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// a^n mod を計算する
// O(logn)
ll modpow(ll a, ll n, ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n,m;
    cin>>m>>n;
    cout<<modpow(m,n)<<endl;
}

 


Measured memory_bytes: 3088
#include <bits/stdc++.h>
        using namespace std;
         
        int main() {
          int A, B,C,D,AB,CD;
           
          cin >> A >> B >> C >> D;
          AB= A+B;
          CD= C+D;
          if(AB==CD){cout << "Balanced" << endl;}
          else if(AB>CD){cout << "Left" << endl;}
          else{cout << "Right" << endl;}
        }

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

#define endl '\n'

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

    int n; cin >> n;
    map<pair<int, int>, int> count;

    for (int i=1; i<=n; i++){
        int last = i % 10;
        int first, cpy=i;
        while(cpy > 9){
            cpy /= 10;
        }
        first = cpy;
        count[{first, last}]++;
    }
    int ans = 0;
    for (int i=1; i<=n; i++){
        int last = i % 10;
        int first, cpy=i;
        while(cpy > 9){
            cpy /= 10;
        }
        first = cpy;
        ans += count[{last, first}];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[1010][10010];

int main(){
    int H,N; cin >> H >> N;
    vector<int> A(N),B(N);
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    rep(i,1010)rep(j,10010) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,N)rep(j,H+1){
        if(j-A[i] >= 0) dp[i+1][j] = min(dp[i+1][j],dp[i+1][j-A[i]]+B[i]);
        dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        if(j == H){
            for(int k = j-1; k >= max(0,j-A[i]);k--) dp[i+1][j] = min(dp[i+1][j],dp[i+1][k]+B[i]);
        }
       // cout << i+1 << " " << j << " " << dp[i+1][j] << endl;
    }
    cout << dp[N][H] << endl;

}


Measured memory_bytes: 39808
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

using C = complex<int>;
using V = vector<C>;
#define all(a) a.begin(), a.end()

void shift(V &v) {
	C c = v[0], &d = v[1];
	for_each(all(v), [c](auto &x) {x -= c;});
	C r = d.imag() < 0 ? C{0, 1} : d.imag() > 0 ? C{0, -1} :
		  d.real() < 0 ? C{-1, 0} : C{1, 0};
	for_each(1 + all(v), [r](auto &x) {x *= r;});
}

V read () {
	V v(in());
	for (auto &x: v)
		x = {in(), in()};
	shift(v);
	return move(v);
}

int main() {
	for (int n; (n = in());) {
		V a = read();
		vector<V> v = {a, (reverse(all(a)), shift(a), a)};
		for (int i = 1; i <= n; i++) {
			V b = read();
			if(find(all(v), b) != v.end())
				outl(i);
		}
		outl("+++++");
	}
}


Measured memory_bytes: 2488
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(){

	fastcin
	
	int k, 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: 3600
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

string s;
ll dp[100001][13];

void solve()
{
    int l = s.size();
    dp[0][0] = 1;
    REP(i, l){
        if(s[i] != '?'){
            REP(j, 13){
                dp[i+1][(10*j+s[i]-'0')%13] += dp[i][j];
                dp[i+1][(10*j+s[i]-'0')%13] %= MOD;
            }
        }else{
            REP(j, 13){
                REP(k, 10){
                    dp[i+1][(10*j+k)%13] += dp[i][j];
                    dp[i+1][(10*j+k)%13] %= MOD;
                }
            }
        }
    }
    cout << dp[l][5] << endl;
}

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

// vim:set foldmethod=marker:


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

using namespace std;

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

    int N;
    cin >> N;
    unordered_map<string, int> m;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        sort(begin(s), end(s));
        ++m[s];
    }
    long long res = 0;
    for (const auto p : m) {
        res += 1LL * p.second * (p.second - 1) / 2;
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 10660
#include <stdio.h>

int main(void){

  int time[5];
  for (int i = 0; i < 5; i++) {
    scanf("%d", &time[i]);
  }

  int all = 0;
  int wait;
  int max = 0;
  for (int i = 0; i < 5; i++) {
    wait = 10 - (time[i] % 10);
    if (time[i] % 10 == 0) {
      wait = 0;
    }
    all += time[i] + wait;
    if (wait > max) {
      max = wait;
    }
  }
  int answer = all-max;
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
using namespace std;
main() {
    int N; cin>>N;
    int max_=-1, count_=0;
    for(int n=1; n<=N; ++n) {
        int H; cin>>H;
        if(H>=max_) ++count_;
        max_= max(max_, H);
    }
    cout<< count_ <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	int A = 0;
	int B = 0;
	int AB = 0;
	int ans = 0;
	rep(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'B' && s[s.size() - 1] == 'A') AB++;
		else if (s[0] == 'B') B++;
		else if (s[s.size() - 1] == 'A') A++;
		rep(i, s.size() - 1) {
			if (s[i] == 'A' && s[i + 1] == 'B') ans++;
		}
	}
	// cout << A << endl << B << endl << AB << endl << ans << endl;
	if (!A && !B) {
		cout << ans + max(0, AB - 1) << endl;
		return 0;
	}
	cout << ans + min(A, B) + AB << endl;
	return 0;
}

Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n>>m;
    cout<<n*m;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10620
"use strict"
function main(arg) {
    const S = arg.split("\n")[0].split("").map((x)=>{return parseInt(x)})
    let i, x = 0, y = 0
    for (i = 0; i < S.length; ++i){
        (i%2 == S[i]) ? x++ : y++
    }
    console.log((x<y)?x:y)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9664
fn read_number() -> Result<usize, String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim()
        .parse::<usize>()
        .map_err(|err| format!("Error at read_number(): {}", err.to_string()))
}

fn read_number_each_line(n: usize) -> Result<Vec<i32>, String> {
    (0..n)
        .map(|_| read_number().map(|x| x as i32))
        .collect::<Result<Vec<_>, _>>()
}

fn read_numbers() -> Result<Vec<i32>, String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.split_whitespace()
        .map(|x| {
            x.parse::<i32>()
                .map_err(|err| format!("Error at read_numbers(): {}", err.to_string()))
        })
        .collect::<Result<Vec<_>, _>>()
}

fn generate_adjacency() -> Result<Vec<Vec<i32>>, String> {
    let n = read_number()?;

    let inputs = (0..n)
        .map(|_i| read_numbers())
        .collect::<Result<Vec<Vec<i32>>, String>>()?;

    let n_nodes = inputs.len();
    let mut matrix = vec![vec![0; n_nodes]; n_nodes];

    for line in inputs {
        let i_node = line[0];
        let n_out = line[1];

        for i_out in 0..n_out {
            matrix[(i_node - 1) as usize][(line[2 + i_out as usize] - 1) as usize] = 1;
        }
    }

    Ok(matrix)
}

fn main() {
    let matrix = match generate_adjacency() {
        Ok(mat) => mat,
        Err(err) => panic!("{}", err),
    };

    for row in matrix {
        for (i_col, e) in row.iter().enumerate() {
            print!("{}", e);
            if i_col < row.len() - 1 {
                print!(" ");
            }
        }
        println!("");
    }
}



Measured memory_bytes: 5032
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0;i<n;i++)
typedef long long ll;

const int INF = 1000000000;
int main() {
    int n,k;
    std::cin >> n >> k;
    std::vector<int>h(n);
    rep(i,n){
        std::cin >> h[i];
    }
    std::vector<int>dp(n,INF);
    dp[0]=0;
    rep(i,n){
        for(int j=i+1;j<=k+i;j++){
            if(j>n){
                break;
            }
            dp[j]=std::min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    std::cout << dp[n-1] << std::endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const ll mod=1e9+7;
const ll inf=1e16;
const ll N=1e5+10;

int main()
{
	boost;
	ll a,b;
	cin>>a>>b;
	if(a==b) cout<<"0";
	else if((a+b)%2 == 0) cout<<(a+b)/2;
	else cout<<"IMPOSSIBLE";

	return 0;
} 

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from itertools import permutations


def main():
    n = int(input())
    s = input()
    ind = [[] for _ in range(3)]
    for i in range(n):
        if s[i] == "R":
            ind[0].append(i)
        elif s[i] == "G":
            ind[1].append(i)
        else:
            ind[2].append(i)
    length = [len(ind[i]) for i in range(3)]
    ind_set = [set(ind[i]) for i in range(3)]
    answer = 0
    for p1, p2, p3 in permutations([0, 1, 2]):
        for j in ind[p2]:
            i = bisect_right(ind[p1], j)
            k = bisect_left(ind[p3], j)
            if length[p1] < i or length[p3] <= k:
                continue
            answer += i * (length[p3] - k)
            for ii in ind[p1]:
                target = 2 * j - ii
                t_ind = bisect_left(ind[p3], target)
                if target in ind_set[p3] and k <= t_ind < length[p3]:
                    answer -= 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 69120
#include<stdio.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define chmax(p,q)(p=max(p,q))

int k[210];
int h[210][21];
int s[210][21];
double x[210][210];
double dp[210][210];

int main(){
	int n,v;
	scanf("%d%d",&n,&v);
	rep(i,0,n){
		scanf("%d",k+i);
		rep(j,0,k[i])scanf("%d%d",s[i]+j,h[i]+j);
	}
	
	rep(i,0,n){
		int pos=0,hh=0;
		for(int j=1;j<=200&&pos<k[i];j++){
			x[i][j]=x[i][j-1]+1.0/s[i][pos];
			if(++hh==h[i][pos]*s[i][pos])pos++,hh=0;
		}
	}
	
	rep(i,0,n)rep(j,0,v+1)rep(d,0,v-j+1)chmax(dp[i+1][j+d],dp[i][j]+x[i][d]);
	printf("%.9f\n",dp[n][v]);
}


Measured memory_bytes: 2472
/* Tenka1 Programmer Contest F
   欧拉定理:若a,n互质,则a^phi(n)=1(mod n).
   于是,若a,n互质,则a^m=a^(m mod phi(n)) (mod n). 
   更多地,有指数循环节,
   当m>=phi(n)的时候,有a^m=a^(m%phi(n)+phi(n)) (mod n)
   从而可以降幂求解.
   -------------------------------------------------------
   考虑利用这样的性质递归下去求解,
   已知a^k=k (mod m),则a^(k mod phi(m)+phi(m))=k (mod m)
   找到一个t满足t=k(mod phi(m))且t>=phi(m),
   则有a^t=a^k (mod m).
   由a^t=a^k(mod m),t=k(mod phi(m)),a^k=k (mod m)
   则a^t=t (mod gcd(m,phi(m))).
   这样问题就被规约到了gcd(m,phi(m))规模上,共有logM层.
   现在通过迭代,如果已经找到了一个符合条件的t,考虑如何倒推回k, 
   则x=a^t (mod m)  x=t (mod phi(m))这样的不定方程的解x符合条件,
   于是可化为: x-k*m=(a^t)%m
               x-l*phi(m)=t%phi(m)
    即:k*m+(a^t)%m=l*phi(m)+t%phi(m)
	   k*m-l*phi(m)=t%phi(m)-(a^t)%m
	   可以用exgcd解出一组合法的k,l,
	   由k,l是合法解,
	   显然k+p*phi(m),l+p*m也是一组合法解,
	找到符合条件的最小合法解返回即可. 
	然后通过x=(a^t)%m+k*m得到合法的x,
	x就是一个合法的答案.
*/ 
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll qmul(ll a,ll b,ll p)
{ll res=1,tp=a;
while (b)
{if (b&1ll) {res*=tp;res%=p;}
tp*=tp;tp%=p;b>>=1ll;
}
return res;
}
inline ll phi(ll n)
{ll ret=n;
for (ll i=2;i*i<=n;i++)
{if (n%i==0)
{while (n%i==0) n/=i;
ret=ret/i*(i-1);
}
}
if (n>1) ret=ret/n*(n-1);
return ret;
}
ll gcd(ll a,ll b)
{if (b==0) return a;
return gcd(b,a%b);
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{if (b==0) {x=1;y=0;return a;}
ll g=exgcd(b,a%b,y,x);
y-=a/b*x;
return g;
}
ll solve(ll a,ll m)
{if (m==1) return 1ll;
ll t,at,pm=phi(m),d=gcd(m,pm),k,l;
t=solve(a,d);
at=qmul(a,t,m);
exgcd(m,pm,k,l);
k*=(((t%pm)-at)/d);k%=pm;
if (k<0) k+=pm;
return (k+pm)*m+at;
}
int main (){
	int test;
	ll a,m;
	scanf ("%d",&test);
	while (test--)
	{scanf ("%lld%lld",&a,&m);
	printf ("%lld\n",solve(a,m));
	}
	return 0;
}


 
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype (i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype (i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int m,d,ans;
int main()
{
    scanf("%d%d",&m,&d);
    rep(i,1,m) rep(j,1,d) {
        int a=j/10,b=j%10;
        if(a>=2&&b>=2&&a*b==i) ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;

long long GCD(long long x, long long y)
{
	long long big = max(x, y), small = min(x, y);

	if (small == 0) {
		return big;
	}

	//ユークリッドの互除法
	while (big % small != 0) {//余り0で終了
		long long amari = big % small;
		big = move(small);
		small = move(amari);
	}

	return small;
}

//最小公倍数
long long LCM(long long a, long long b)
{
	//LCM = a*b/GCD

	return a * b / GCD(a, b);
}

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

	long long ans = LCM(A, B);

	cout << ans << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sum_a=0, sum_b=0;
  for(int i=0; i < vec.size(); i++){
    if(i%2 == 0)sum_a += vec.at(i);
    else sum_b += vec.at(i);
  }
  cout << sum_a - sum_b << endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int f[100001],cnt[100001],ans,n,m;
int find(int x)
{
    if(f[x]==x)return x;
    return f[x]=find(f[x]);
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
    }
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        f[find(x)]=find(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!cnt[find(i)])ans++;
        cnt[find(i)]=1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1152
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  int N, X, T;
  cin >> N >> X >> T;

  int ans = N / X;
  if (N % X != 0) ans++;
  ans *= T;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	bool f = false;
	while(true) {
		int tmp = 0, beet = 0, mi = 1 << 30;
		for(auto v : a) tmp ^= (v - 1) % 2;
		for(auto v : a) beet += v % 2;
		for(auto v : a) mi = std::min(mi, v);
		if(mi == 1) {
			if(f) tmp = !tmp;
			if(!tmp) printf("Second\n");
			else printf("First\n");
			break;
		}
		if(tmp) {
			if(f) printf("Second\n");
			else printf("First\n");
			break;
		} else {
			if(beet > 1) {
				if(!f) printf("Second\n");
				else printf("First\n");
				break;
			}
		}
		for(auto &v : a) if(v % 2) v--;
		int g = a.front();
		for(auto v : a) g = std::__gcd(g, v);
		for(auto &v : a) v /= g;
		f = !f;
	}
	return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int n;cin>>n;
  repi(i,1,10){
    int b=n/i;
    if(n%i==0&&n%(n/i)==0&&b>0&&b<10){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

}


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

using namespace std;

int main()
{
	string s;
	cin >> s;

	if (s.size() == 26) {
		string t = s;
		if (next_permutation(s.begin(), s.end()) == 0) {
			cout << -1 << endl;
		} else {
			for (int i = 0; i < 26; i++) {
				cout << s[i];
				if (s[i] != t[i]) {
					cout << endl;
					return 0;
				}
			}
			cout << endl;
		}
	} else {
		bool a[26] = {};
		for (int i = 0; i < s.length(); i++) {
			a[s[i] - 'a'] = true;
		}

		for (int i = 0; i < 26; i++) {
			if (!a[i]) {
				s += ('a' + i);
				cout << s << endl;
				return 0;
			}
		}
	}

	return 0;
}


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

int main(){
  int64_t N;
  cin >> N;
  int64_t Ans=0;
  for(int64_t p=1; p<sqrt(N)+1; p++){
    if((N-p)%p==0 && p<(N-p)/p){
      Ans+=(N-p)/p;
    }
  }
  cout << Ans << endl;
//  (N-p)/p=m && p<m
}

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

#define NMAX 100005
using namespace std;

long long dp[NMAX][3], v[NMAX][3];
int ot[4][2] = {0, 0,
                2, 3,
                1, 3,
                1, 2};

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

    for(int i = 1; i <= n; ++i)
        cin >> v[i][1] >> v[i][2] >> v[i][3];

    dp[1][1] = v[1][1], dp[1][2] = v[1][2], dp[1][3] = v[1][3];
    for(int i = 2; i <= n; ++i)
        for(int wh = 1; wh <= 3; ++wh)
            dp[i][wh] = max(dp[i - 1][ot[wh][0]], dp[i - 1][ot[wh][1]]) + v[i][wh];

    cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << '\n';
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int count = 0;
  for(int i = 1; i <= N; i++){
    if(i % 2 == 0){
      continue;
    }
    int d = 0;
    for(int j = 1; j <= i*2; j++){
      if(i % j == 0){
        d += 1;
      }
    }
    if(d == 8){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <functional>

int main() {
	std::string s;
	int ans = 0x7FFFFFFF;
	std::cin >> s;
	for(int i=0;i<s.size()-2;i++){
		int b = std::abs(std::atoi(s.substr(i,3).c_str())-753);
		if(ans>b){
			ans=b;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 384