akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

'''
全箱にボールを入れてしまうと、2**N時間かかってしまうので無理
後ろから見たほうが絶対良い
最後の箱には、1であればボールが入るし、、0であればいれない
その次に、その数の約数を大きい方から確認していく
例えば、800が最後だとするとその次は400になる

'''


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = [None for _ in range(N)]
divisor_data = [None for _ in range(N)]
for n in reversed(range(0, N)):
    #  print('n', n)
    if divisor_data[n] == None:
        #  print('none')
        # 約数ではない数字
        if A[n] == 0:
            # ボールは入れない
            ans[n] = 0
        else:
            # ボール入れる
            ans[n] = 1
            divisors = sorted(make_divisors(n+1))
            #  print('divisors', divisors)
            for d in divisors[:-1]:
                if divisor_data[d-1] == None:
                    divisor_data[d-1] = 1
                else:
                    divisor_data[d-1] ^= 1
    else:
        #  print('yakusu')
        # 上の数字の約数
        if divisor_data[n] == A[n]:
            # ボールを入れない
            ans[n] = 0
        else:
            # 玉を追加
            ans[n] = 1
            divisors = sorted(make_divisors(n+1))
            #  print('divisors', divisors)
            for d in divisors[:-1]:
                if divisor_data[d-1] == None:
                    divisor_data[d-1] = 1
                else:
                    divisor_data[d-1] ^= 1
    #  print('div_data', divisor_data)

#  print('ans', ans)
#  print('div_data', divisor_data)
if all(a == 0 for a in ans):
    print(0)
else:
    print(ans.count(1))
    for aidx, a in enumerate(ans):
        if a == 1:
            print(aidx+1, end=' ')




Measured memory_bytes: 99480
#include<iostream>
using namespace std;
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
def judge(mygp,yourgp):
  if mygp=='g' and yourgp=='p':
    return -1
  elif mygp=='p' and yourgp=='g':
    return 1
  else:
    return 0

s=[x for x in input()]
t=[['g','p'][x%2] for x in range(len(s))]
print(sum([judge(a,b) for a,b in zip(t,s)]))

Measured memory_bytes: 11172
import java.util.Scanner;
class Main{
	   public static void main(String[] args){
	  Scanner scan =  new Scanner(System.in);
	   long a = scan.nextLong();
	   long e =0;
	   long f = a;
	   for(long i=1;i*i<=a;i++){ 
		   long b=0;
		   if(a%i==0){
			   b = a/i;
			   int d = String.valueOf( b ).length();
	           int c = String.valueOf(i).length();
	           e =  Math.max(d,c);
		   }
		   if(e<f){
			   f=e;
		   }
		   
	   }
	   System.out.println(f);
	   }
	}

Measured memory_bytes: 22996
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef pair<int, int> ii;

long long count_P_in_nfact(long long n , long long p) {
    long long res = 0;
    while (n) {
        n /= p;
        res += n;
    }
    return res;
}
long long count_5_in_nfact(long long n , long long p) {
    long long res = 0;
    while (n) {
        n /= p;
        res += n / 2;
    }
    return res;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=500100,P=998244353;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
ll ans;
int n,l[N],r[N],ql[N],qr[N],v[N];
bool cmpl(int i,int j){return l[i]<l[j];}
bool cmpr(int i,int j){return r[i]<r[j];}
int mov(int&x,int t){
	int re=0;
	if(x<l[t])re=l[t]-x,x=l[t];
	if(x>r[t])re=x-r[t],x=r[t];
	return re;
}
void solve(){
	ll k=0;int i,il,ir,x;
	for(i=1;i<=n;i++)v[i]=0,ql[i]=qr[i]=i;
	sort(ql+1,ql+n+1,cmpl);
	sort(qr+1,qr+n+1,cmpr);
	ir=1;il=n;x=0;
	for(i=1;i<=n;i++){
		if(i&1){
			while(v[qr[ir]])ir++;
			v[qr[ir]]=1;k+=mov(x,qr[ir]);
		}else{
			while(v[ql[il]])il--;
			v[ql[il]]=1;k+=mov(x,ql[il]);
		}
	}k+=abs(x);
	if(k>ans)ans=k;
}
int main(){
	//freopen("1.out","w",stdout);
	int i;n=read();
	for(i=1;i<=n;i++)l[i]=read(),r[i]=read();
	solve();
	for(i=1;i<=n;i++)swap(l[i],r[i]),l[i]=-l[i],r[i]=-r[i];
	solve();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6912
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
//const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,m,mod,i,j,k;cin>>n>>mod;//m の意味が違う
	static int dp[15005]={};//最大ー最小,和
	m=(n-1)/2;
	dp[0]=1;
	if(n%2==0){
		
		for(k=0;k<=n;k++){
			dp[k+m+1]+=dp[k];
			dp[k+m+1]%=mod;
		}
		
	}
	
	for(i=0;i<m;i++){
		for(k=0;k<=n;k++){
			if(dp[k]==0){continue;}
			dp[k+(m-i)+1]+=dp[k];
			dp[k+(m-i)+1]%=mod;
		}
		for(k=0;k<=n;k++){
			if(dp[k]==0){continue;}
			dp[k+(m-i)]+=dp[k];
			dp[k+(m-i)]%=mod;
		}
		
	}
	llint ans=0;
	
	for(k=0;k<n;k++){
		ans+=max(0,n-k)*((llint)dp[k]);
		ans%=mod;
	}
		
	
	cout<<ans<<endl;
}




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

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    rep(i, N) cin >> s[i];
    int cntA = 0, cntB = 0, cntAB = 0, cntBA = 0;
    rep(i, N) {
        int M = s[i].size();
        if (s[i][0] == 'B') ++cntB;
        if (s[i][M - 1] == 'A') ++cntA;
        if (s[i][0] == 'B' && s[i][M - 1] == 'A') ++cntBA;

        rep(j, M) {
            if (s[i][j] == 'A') {
                if (j + 1 < M && s[i][j + 1] == 'B') ++cntAB;
            }
        }
    }

    ll ans = cntAB + min(cntA, cntB);
    if (cntBA != 0 && max(cntA, cntB) == cntBA) --ans;

    cout << ans << endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

vector<string> split(const string &s,char c=' '){
	vector<string> ret;
	stringstream ss(s);
	string t;
	while(getline(ss,t,c)){
		ret.pb(t);
	}
	return ret;
}

int main(){
	string s;
	while(getline(cin,s)){
		stack<double> st;
		vector<string> ss=split(s,' ');
		rep(i,0,ss.size()){
			double a,b;
			//o(ss[i]);
			if(ss[i]=="+"){
				a=st.top(); st.pop();
				b=st.top(); st.pop();
				st.push(a+b);
			}else if(ss[i]=="-"){
				a=st.top(); st.pop();
				b=st.top(); st.pop();
				st.push(b-a);
			}else if(ss[i]=="*"){
				a=st.top(); st.pop();
				b=st.top(); st.pop();
				st.push(a*b);
			}else if(ss[i]=="/"){
				a=st.top(); st.pop();
				b=st.top(); st.pop();
				st.push(b/a);
			}else{
				a=atof(ss[i].c_str());
				//o(" "<<a);
				st.push(a);
			}
			//o("  "<<st.top());
		}
		double ans=st.top();
		printf("%.8lf\n",ans);
	}
}

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

int K;
int sum = 0;

int gcd(int a, int b);
int main() {
  cin >> K;

  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int n = 1; n <= K; n++) {
        sum += gcd(gcd(i, j), n);
      }
    }
  }

  printf("%d", sum);

  return 0;
}

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

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    int sum = 0;
    for (int i = 0;i < n; i++) {
        cin >> l[i];
        sum += l[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++){
        if (l[i]*4*k >= sum){
            count++;
        }
    }
    if (count >= k){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main() {
  int N,M,i;
  long long int ans,tmp0,tmp1;
  cin >> N >> M;
  vector<long long int> x(N),y(N),z(N),a(N);
  for(i=0;i<N;i++){
    cin>>x.at(i)>>y.at(i)>>z.at(i);
  }
  ans = 0;
  
  tmp0 = 0;
  tmp1 = 0;
  for(i=0;i<N;i++) a.at(i) = x.at(i)+y.at(i)+z.at(i);
  sort(a.begin(),a.end());
  for(i=0;i<M;i++){
    tmp0 += a.at(N-1-i);
    tmp1 -= a.at(i);
  }
  if(tmp0 > ans) ans = tmp0;
  if(tmp1 > ans) ans = tmp1;
  
  tmp0 = 0;
  tmp1 = 0;
  for(i=0;i<N;i++) a.at(i) = x.at(i)+y.at(i)-z.at(i);
  sort(a.begin(),a.end());
  for(i=0;i<M;i++){
    tmp0 += a.at(N-1-i);
    tmp1 -= a.at(i);
  }
  if(tmp0 > ans) ans = tmp0;
  if(tmp1 > ans) ans = tmp1;
  
  tmp0 = 0;
  tmp1 = 0;
  for(i=0;i<N;i++) a.at(i) = x.at(i)-y.at(i)+z.at(i);
  sort(a.begin(),a.end());
  for(i=0;i<M;i++){
    tmp0 += a.at(N-1-i);
    tmp1 -= a.at(i);
  }
  if(tmp0 > ans) ans = tmp0;
  if(tmp1 > ans) ans = tmp1;
  
  tmp0 = 0;
  tmp1 = 0;
  for(i=0;i<N;i++) a.at(i) = x.at(i)-y.at(i)-z.at(i);
  sort(a.begin(),a.end());
  for(i=0;i<M;i++){
    tmp0 += a.at(N-1-i);
    tmp1 -= a.at(i);
  }
  if(tmp0 > ans) ans = tmp0;
  if(tmp1 > ans) ans = tmp1;
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<string> se;
string s;
int n;
int main()
{
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        se.insert(s);
    }
    int ans=se.size();
    cout<<ans;
    return 0;
}

Measured memory_bytes: 19108
import math
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
x = math.floor(avg)
y = math.ceil(avg)
sumx = 0
sumy = 0
for i in a:
    sumx += (i - x) ** 2
    sumy += (i - y) ** 2

print(min([sumx,sumy]))

Measured memory_bytes: 9140
N = int(input())
A = [0]+list(map(int, input().split()))

S = sum(A)
S_odd = 0
for i in range(1, N+1):
    if i==N or i%2==0:
        continue
    S_odd += A[i]

Mn = S - 2*S_odd
M = [0 for _ in range(N+1)]
M[N] = Mn
for i in range(N-1, 0, -1):
    M[i] = 2*A[i] - M[i+1]

M = M[1:]
print(*M)

Measured memory_bytes: 14616
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<50);
template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>A>>B>>N;
    ll x = min(N, B - 1);
    if(x == N){
        cout<<(A * x) / B - A * (x / B)<<endl;
        return 0;
    }
    ll ans = (A * x)/B - A * (x / B);
    x += B;
    while(x <= N && (A * x)%B != (A * (B - 1))%B){
        chmax(ans, (A * x)/B - A * (x / B));
        x += B;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
//#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define re(s) reverse(s.begin(),s.end())

int32_t main()
{
  io
int x;
cin>>x;
if(x)cout<<"0"<<endl;
else cout<<"1"<<endl;

}


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

using namespace std;

int main() {
  int n, q;
  while (cin >> n >> q, n) {
    int v[200] = {};
    for (int i = 0; i < n; ++i) {
      int m;
      cin >> m;
      for (int j = 0; j < m; ++j) {
        int d;
        cin >> d;
        v[d]++;
      }
    }
    int ans = 0;
    int mx = 0;
    for (int i = 0; i < 200; ++i) {
      if (v[i] >= q && mx < v[i]) {
        mx = v[i];
        ans = i;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3072
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
cnt = [0]
def dfs(V, s):
  V[s] = 1
  if sum(V) == N:
    cnt[0] += 1
  else:
    for adj in G[s]:
      if V[adj] == 0:
        dfs(V[:adj] + [1] + V[adj + 1:], adj)
dfs([0] * N, 0)
print(cnt[0])

Measured memory_bytes: 3064
N = int(input())
T = list(map(lambda t: int(t), input().split(" ")))
M = int(input())
P = []
T_new = []
T_diff = []
for i in range(M):
  tmp = input().split(" ")
  P.append(int(tmp[0]) - 1)
  T_new.append(int(tmp[1]))
  T_diff.append(T_new[i] - T[P[i]])

T_sum = sum(T)
print("\n".join([str(T_sum + t_d) for t_d in T_diff]))

Measured memory_bytes: 9076
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int n;
int a[114514] = {};

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	ll ans = 1;
	ll keis = 0;
	for (int i = 1; i < n; ++i)
	{
		//keis + 1個配置したい！
		if ((keis + 1) * 2 - 1 <= a[i - 1] )
		{
			keis++;
		}
		ans *= (keis + 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 5;
const int MID = 1e5;
ll N, A[MAX], BIT[MAX * 2];

void update(ll pos, ll diff){
    for(int i = pos; i < 2 * MAX; i += (i & -i)){
        BIT[i] += diff;
    }
}

ll query(int pos){
    ll ret = 0;
    for(int i = pos; i >= 1; i -= (i & -i)){
        ret += BIT[i];
    }
    return ret;
}

ll conv(ll x){
    return MID + x;
}

bool check(ll x){
    memset(BIT, 0, sizeof(BIT));
    ll sum = 0, piv = 0;
    update(conv(0), 1);
    for(int i = 1; i <= N; i++){
        if(A[i] >= x)   piv++;
        else piv--;
        sum += query(conv(piv));
        update(conv(piv), 1);
    }
    return (2LL * sum < N * (N + 1) / 2);
}

int main(){
    scanf("%lld", &N);
    vector<ll> vt;
    for(int i = 1; i <= N; i++){
        scanf("%lld", A + i);
        vt.push_back(A[i]);
    }
    sort(vt.begin(), vt.end());
    vt.erase(unique(vt.begin(), vt.end()), vt.end());
    ll l = 0, r = vt.size() - 1;
    while(l < r){
        ll mid = (l + r + 1) / 2;
        if(check(vt[mid])){
            r = mid - 1;
        }
        else{
            l = mid;
        }
    }
    printf("%lld\n", vt[l]);
    return 0;
}


Measured memory_bytes: 3444
# cook your dish here
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;

# coding start heres
s=is1()
if s[-1]=='s':
    s+='es'
else:
    s+='s'
print(s)



Measured memory_bytes: 72644
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 101;
const int MAX_W = 1e+5 + 1;

ll w[MAX_N], v[MAX_N], dp[MAX_N][MAX_W];

int main() {
    int N;
    ll W;
    cin >> N >> W;
    for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
    for (int i = 0; i <= W; i++) dp[0][i] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i <= W; i++) ans = max(ans, dp[N][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79104
char s[9];x,l,i;int P(a){
	sprintf(s,"%d",a),l=strlen(s);
	for(x=0;x<l&s[x]==s[l-x-1];x++);
	return x==l;
}
main(n){for(scanf("%d",&n);;i++){
	if(P(n-i))printf("%d\n",n-i),exit(0);
	if(P(n+i))printf("%d\n",n+i),exit(0);
}}

Measured memory_bytes: 616
n=int(input())
a=list(map(int,input().split()))
b=dict()
for x in a:
  if x in b:
    b[x] += 1
  else:
    b[x] = 1
ans = 0
for k, v in b.items():
  if k < v:
    ans += v - k
  elif k > v:
    ans += v
print(ans)

Measured memory_bytes: 98960
n = input()
s = input()


e_cnt = 0
for i in range(1, len(s)):
    if s[i] == 'E':
        e_cnt += 1
res = []
res.append(e_cnt)
for i in range(1, len(s)):
    add = 0
    if s[i-1] == 'W':
        add += 1
    if s[i] == 'E':
        add -= 1
    res.append(res[i-1] + add)

print(min(res))

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a[i];
  
  int cnt=0;
  
  for(int i=0; i<N; i++){
    if(a[a[i]-1]==i+1) cnt++;
  }
  cout << cnt/2 <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(a) cout << #a << " := " << (a) << endl
#define all(a) (a).begin(), (a).end()
#define len(a) ((int) (a).size())
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
using namespace std;
void solve();
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
}


void solve() {
    int n; cin >> n; vector<int> a(n); forn (i, n) cin >> a[i];
    forn (i, n) a[i] -= i + 1;
    sort(all(a)); int sl = 0, sr = 0; for (auto i : a) sr += i;
    int res = (int) 1e18 + 7;
    forn (i, n){
        sl += a[i];
        sr -= a[i];
        int cur = (a[i] * (i + 1) - sl) + (sr - (n - i - 1) * a[i]);
        res = min(res, cur);
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define N 200010
#define M 1010

using namespace std;
char a[N], b[N];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	int ans = 0;
	cin >> a >> b;
	int len = strlen(a);
	for (int i = 0; i < len; i++)
		if (a[i] != b[i]) ans++;
	cout << ans;
}

Measured memory_bytes: 3948
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll X;cin>>X;ll N;cin>>N;
    vector<bool> P(101);REPS(i,100)P[i]=true;
    REP(i,N){
        int p;cin>>p;
        P[p]=false;
    }
    ll idx,ans;
    if(101-X>=X-0){
        idx=0;
        ans=X;
    }else{
        idx=101;
        ans=101-X;
    }
    REPS(i,100){
        if(!P[i])continue;
        if(ans>abs(i-X) or (i<idx and ans==abs(i-X))){
            idx=i;
            ans=abs(i-X);
        }
    }
    cout<<idx<<"\n";
}

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

using namespace std;

#define vt vector
#define llint long long int
#define REP(i,s,l) for(int i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main() {

    //N個の宝石 i番目Vi原価 Ci経費
    int qnt;
    vector<int> genka(qnt);
    vector<int> keihi(qnt);
    int mouke = 0;
    int sagaku;

    cin >> qnt ;
    REP(i,0,qnt){ cin >> genka[i];}
    REP(i,0,qnt){ cin >> keihi[i];}

    REP(i,0,qnt){
        if(genka[i] > keihi[i]) mouke += genka[i] - keihi[i];
    }

    cout << mouke << endl;

    return 0;
}

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

vector<bool>vis;
vector<ll> v;
vector<int> s;
int n;
ll k;
int push(int i){
    s.push_back(i);
    vis[i] = true;
    if(vis[v[i]] == false){
        return push(v[i]);
    }
    else {
        return v[i];
    }
}
int main(void){
    cin>>n>>k;
    v.resize(n);
    vis.resize(n);
    rep(i, n) {
        int a;
        cin>>a;
        --a;
        v[i] = a;
    }
    rep(i, n) vis[i] = false;
    int g = push(0);
    int gidx;
    rep(i, s.size()){
        if(s[i] == g) gidx = i;
    }
    int ans;
    int m = s.size();
    if(k<=gidx) ans = s[k];
    else {
        ll div = (k-(ll)gidx)%((ll)m-(ll)gidx);
        ans = s[gidx+(int)div];
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 11752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	cout << n*n << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

const int N = 1e6 + 5;
int divisors[N];

void pre() {
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) {
      divisors[j]++;
    }
  }
}

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

  int n;
  cin >> n;

  int ans = 0;

  for (int c = 1; c < n; c++) {
    ans += divisors[n - c];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7552
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC\n";
    } else if (r < 2800) {
        cout << "ARC\n";
    } else {
        cout << "AGC\n";
    }

    return 0;
}

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

int main() {
  int n,cnt = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  for(int i = 0;i < n;i++){
    int max = 101,maxpos;
    for(int j = n-1;j >= i;j--){
      if(data[j] <= max){
        max = data[j];
        maxpos = j;
      }
    }
    if(maxpos != i){
      cnt++;
      int a = data[i],b = data[maxpos];
      data[i] = b;
      data[maxpos] = a;
    }
  }
  for(int i = 0;i < n;i++){
    cout << data[i];
    if(i == n-1) cout << "" << endl;
    else cout << " ";
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pi 3.141592653589
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[111111];
set<int>st;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		if(st.find(a[i])==st.end())st.insert(a[i]);
		else st.erase(a[i]);
	}
	int ans=st.size();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,h,w;
  cin>>n>>h>>w;

  cout << (n-w+1)*(n-h+1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int a, h, b;
	cin >> a >> b >> h;
	cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }

int N, C[111];

int main() {
    scanf("%d", &N);
    REP (i, N) {
	int x;
	scanf("%d", &x);
	C[x]++;
    }

    int p = 0;
    REP (i, 111) if (C[i]) p = i;

    int cnt = p + 1;
    REP (i, p+1) C[max(i, p-i)]--;

    REP (i, 111) {
	if (C[i]) {
	    if (C[i] < 0 ||
		    i <= 1 ||
		    i < p - i + 2) 
		cnt = N * 2;
	    else 
		cnt += C[i];
	}
    }


    puts(cnt == N ? "Possible" : "Impossible");

    return 0;
}



Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int gcd(int a, int b){
    if(b==0)return a;
    gcd(b,a%b);
}


void solve(){
   char c;
  cin >> c;
  c++;
  cout << c << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



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

  ll N;
  cin >> N;
  vector<string> S(N);
  REP(i,N){ cin >> S[i]; }  
  
  ll maxc = 0;
  map<string, ll> cnt;
  REP(i,N){
    if (cnt.find(S[i]) == cnt.end()){
      cnt[S[i]] = 1;
    } else {
      cnt[S[i]]++;
    }
    maxc = max(cnt[S[i]], maxc);
  }

  vector<string> L;
  for(pair<string, ll> p : cnt){
    if (cnt[p.first]==maxc){
      L.push_back(p.first);
    }
  }
  std::sort(L.begin(), L.end());
  REP(i,L.size()){
    std::cout << L[i] << "\n";
  }
  return 0;
}


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

int main(){
	string input;
	int ans = 0;
	while(cin >> input){
		bool isPalindrome = true;
		for(int i=0; i < input.size(); i++){
			if(input[i] != input[input.size() - i-1]) isPalindrome = false;
		}
		if(isPalindrome) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1184
n = int(input())
a = list(map(int, input().split()))
q = int(input())
T={}
for i in range(n):
    if a[i] not in T: T[a[i]]=1
    else: T[a[i]]+=1
Sum = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    if b not in T: T[b]=0
    Sum = Sum-(T[b]*b)+(T[b]*c)
    print(Sum)
    if c not in T: T[c]=T[b]
    else: T[c]+=T[b]
    T[b]=0

Measured memory_bytes: 23908
N = int(input())
H = list(map(int,input().split()))

count_list = []
count = 0

for i in range(N-1):
  if H[i] >= H[i+1]:
    count += 1
  else:
    count_list.append(count)
    count = 0
else:
  count_list.append(count)
    
print(max(count_list))


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

using namespace std;

void dfs(int curr, vector<vector<int>>& adj, unordered_set<int>& remaining) {

	remaining.erase(curr);

	for(auto i:adj[curr]) {
		
		if(remaining.count(i) == 1)
			dfs(i, adj, remaining);
	}
}

int main() {

	int n,m,u,v;
	cin>>n>>m;

	vector<vector<int>> adj(n+1);
	for(int i=1; i<=m; i++) {

		cin>>u>>v;

		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	unordered_set<int> remaining;
	for(int i=1; i<=n; i++) remaining.insert(i);
	int ans = 0;

	for(int i=1; i<=n; i++) {

		if(remaining.count(i) == 0) continue;

		int before = remaining.size();

		dfs(i, adj, remaining);

		int after = remaining.size();

		ans = max(ans, before-after);
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 37880
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x - a) < abs(x - b)) cout << "A" << endl;
    else cout << "B" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


const ll MAX = 510000;
const ll MOD =1000000007;

int sz=1;
ll dp[100010][20];

int main(void) {
	string S; cin >> S;
	int n = S.size();
	dp[0][0]=1;
	
	for (int i = 0; i < n; i++) {
		if (S[i] == '?') {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 13; k++) {
				    int m = (10*k+j)%13;
					dp[i + 1][m] += dp[i][k];
					dp[i + 1][m] %= MOD;
				}
			}
		}
		else {
			int c = S[i] - '0';
			for (int k = 0; k < 13; k++) {
				int m = (10*k+c)%13;
				dp[i + 1][m] += dp[i][k];
				dp[i + 1][m] %= MOD;
			}
		}
	}

	cout << dp[n][5] << endl;
	
}


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

int main() {
	int sum = 0, ans = 0;
	string s;
	vector<int> num;
	vector<char> joi;
	
	cin >> s;
	
	for(int i = 0; i < s.size(); i++){
		sum++;
		if(s[i] != s[i + 1]){
			num.push_back(sum);
			joi.push_back(s[i]);
			sum = 0;
		}
	}
	
	for(int i = 1; i < num.size(); i++){
		if(joi[i] == 'O' && joi[i - 1] == 'J' && joi[i + 1] == 'I'){
			if(num[i - 1] >= num[i] && num[i + 1] >= num[i]){
				ans = max(ans, num[i]);
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8892
#include <stdio.h>

int main(void){
  
  int N;
  scanf("%d", &N);
  
  long long A[N];
  long long B[N];
  
  int i;
  
  for( i = 0; i < N; i++ ){
    scanf("%lld %lld", A+i, B+i);
  }
  
  long long ans = 0;
  
  
  for( i = N; i ; i-- ){
    if( (A[i-1]+ans)%B[i-1] ){
      ans += ( B[i-1] - ((A[i-1]+ans) % B[i-1]) );
    }
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n;
    cin >> n;
    
    ll ans = n*(n+1)*(n+2)/6;
    rep(i, n-1) {
        ll u, v;
        cin >> u >> v;
        ans -= min(u, v) * (n+1 - max(u, v));
    }
    
    out(ans);
    re0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n;cin>>n;
    vi a(n);
    FOR(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    cout << a[n/2]-a[n/2-1];

    return 0;
}



Measured memory_bytes: 640
// 7/3
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) res.push_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

// 以下は時間がかかりすぎて却下
int old_main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    map<int, int> mp;
    rep(i, N) {
        vector<ll> divs = divisor(A[i]);
        for (auto d : divs) mp[d]++;
    }

    int res = 1;
    for (auto p : mp) {
        if (p.second == N) {
            res = max(res, p.first);
        }
        else if (p.second == N-1) {
            res = max(res, p.first);
        }
    }

    cout << res << endl;
    return 0;
}

// 開放を変えてチャレンジ
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int res = 0;
    if (N == 2) {
        res = max(A[0], A[1]);
    } else if (N == 3) {
        res = max(gcd(A[0], A[1]), gcd(A[0], A[2]));
        res = max(res, gcd(A[1], A[2]));
    } else {
        res = 1;
        vector<ll> div1 = divisor(gcd(A[0], A[1]));
        vector<ll> div2 = divisor(gcd(A[2], A[3]));

        rep(i, div2.size()) div1.push_back(div2[i]);

        for (auto d : div1) {
            int miss = 0;
            rep(i, N) {
                if (A[i]%d != 0) {
                    miss++;
                    if (miss > 1) {
                        break;
                    }
                }
            }
            if (miss <= 1) {
                res = max(res, (int)d);
            }
        }
    }
    cout << res << endl;
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int n; cin >> n;

	vector <int> a(n);

	vector < vector <int> > x(n), y(n);


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

		x[i].resize(a[i]);
		y[i].resize(a[i]);

		for(int j = 0; j < a[i]; j++){
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}

	int ans = 0;

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

		bitset <20> bit(i);

		bool good = true;
		int cnt = 0;

		for(int j = 0; j < n; j++){
			if(bit[j]){
				cnt++;
				for(int e = 0; e < a[j]; e++){
					if(bit[x[j][e]] ^ y[j][e] != 0){
						good = false;
					}
				}
			}
		}

		if(good){
			ans = max(ans, cnt);
		}
	}


	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
N = int(input())
primes = {}
for i in range(2,N+1):
    n = i
    for j in range(25):
        if n==1 or n<ps[j]:break
        while n%ps[j]==0:
            if ps[j] in primes.keys():
                primes[ps[j]]+=1  
            else:
                primes[ps[j]]=1
            n //= ps[j]
#print(primes)
#3,5,5
#3,25
#5,15
#75
three = len([v for v in primes.values() if v>=3-1])
five = len([v for v in primes.values() if v>=5-1])
fift = len([v for v in primes.values() if v>=15-1])
twfiv = len([v for v in primes.values() if v>=25-1])
sevfiv = len([v for v in primes.values() if v>=75-1])
print(five*(five-1)//2*(three-2) + twfiv*(three-1) + fift*(five-1) + sevfiv)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string>

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORN(i, n, s) for (int i = s; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n) \
  for (int i = 0; i < n; i++) cin >> a[i];
#define PACKN(a, n, s) \
  for (int i = s; i < n; i++) cin >> a[i];
#define LIST(a, n) \
  for (int i = 0; i < n; i++) cout << "[" << i << "] " << a[i] << endl;

using namespace std;

int main() {
  string S;
  IN(S);

  int total = 700;
  if (S[0] == 'o') {
    total += 100;
  }
  if (S[1] == 'o') {
    total += 100;
  }
  if (S[2] == 'o') {
    total += 100;
  }

  OUT(total);
  return 0;
}

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

int main(void)
{
	int n, b, f, r, v;
	int rooms[4][3][10] = {0};

	for (int i1=0; i1<4; i1++){
		for (int i2=0; i2<3; i2++){
			for (int i3=0; i3<10; i3++){
				rooms[i1][i2][i3] = 0;
			}
		}
	}

	cin >> n;
	for (int i=0; i<n; i++){
		cin >> b >> f >> r >> v;
		rooms[b-1][f-1][r-1] += v;
	}

	for (int i1=0; i1<4; i1++){
		for (int i2=0; i2<3; i2++){
			for (int i3=0; i3<10; i3++){
				cout << " " << rooms[i1][i2][i3];
			}
			cout << endl;
		}
		if (i1 != 3)
			cout << string(20, '#') << endl;
	}
	return 0;
}

Measured memory_bytes: 1200