akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
dp = [0] * n
for i in a:
    dp[i-1] = -1
if n == 1:
    if dp[0] == 0:
        print(1)
        exit()
    elif dp[0] == -1:
        print(0)
        exit()
if dp[1] >= 0 and dp[0] >= 0:
    dp[0] = 1
    dp[1] = 2
elif dp[1] == -1 and dp[0] >= 0:
    dp[0] = 1
elif dp[1] >= 0 and dp[0] == -1:
    dp[1] = 1
else:
    print(0)
    exit()
for j in range(2, n):
    if dp[j] >= 0:
        if dp[j-1] >= 0 and dp[j-2] >= 0:
            dp[j] = dp[j-1] + dp[j-2]
        elif dp[j-1] == -1 and dp[j-2] >= 0:
            dp[j] = dp[j-2]
        elif dp[j-1] >= 0 and dp[j-2] == -1:
            dp[j] = dp[j-1]
        else:
            print(0)
            exit()
print(dp[n-1] % (10**9+7))
        

Measured memory_bytes: 466048
N = int(input())
L = []
for _ in range(N):
  W = str(input())
  if W in L:
    print('No')
    exit()
  L.append(W)
for i in range(N - 1):
  if L[i][len(L[i]) - 1] != L[i+1][0]:
    print('No')
    exit()
print('Yes')
  

Measured memory_bytes: 9140
import queue
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

vals = [float('inf')]*n
vals[0] = 0

c = queue.Queue()
c.put(1)

while not c.empty():
    d = c.get()
    if d == n:
        continue
    if b+vals[d-1] < vals[d]:
        vals[d] = b+vals[d-1]
    if a*(x[d]-x[d-1])+vals[d-1] < vals[d]:
        vals[d] = a*(x[d]-x[d-1])+vals[d-1]
    c.put(d+1)
print(vals[-1])


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N;
	cin >> N;
	int A[N], B[N];
	rep(i,N){
		cin >> A[i];
	}
	priority_queue<P> que;
	rep(i,N){
		cin >> B[i];
		que.push({B[i], i});
	}
	int ans = 0;
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int x = p.first;
		int i = p.second;
		if(A[i] == x) continue;
		else if(A[i] > x){
			cout << -1 << endl;
			return 0;
		}
		int num;
		if(i == N-1){
			num = B[0] + B[N-2];
		}
		else if(i == 0){
			num = B[1] + B[N-1];
		}
		else{
			num = B[i-1] + B[i+1];
		}
		if( (x - A[i]) % num == 0){
			ans += (x - A[i]) / num;
			B[i] = A[i];
			continue;
		}
		else{
			int z = (x - A[i]) / num;
			if(z == 0){
				cout << -1 << endl;
				return 0;
			}
			else{
				x -= z * num;
				ans += z;
			}
		}
		B[i] = x;
		que.push({x, i});
	}
	cout<< ans << endl;
}

Measured memory_bytes: 9584
#include<stdio.h>
#include<string.h>
int main(void)
{
	char buf[127],a[127],b[127],c[127];
	int i,j,la,lb,lc,len;
	int flg,carr,ap,bp,cp;
	int an,bn,cn,s,ans;
	
	while(1)	{
		if(scanf("%s",buf)==EOF)	break;
		len=strlen(buf);
		ap=0;
		for(i=0;i<len;i++)	{
			if(buf[i]!='+')	{
				a[i]=buf[i];
			}
			else {
				a[i]='\0';
				break;
			}
		}
		la=i;
		bp=0;
		for(i=la+1;i<len;i++)	{
			if(buf[i]!='=')	{
				b[bp]=buf[i];
				bp++;
			}
			else {
				b[bp]='\0';
				break;
			}
		}
		lb=bp;
		cp=0;
		for(i=lb+la+2;i<len;i++)	{
			c[cp]=buf[i];
			cp++;
		}
		c[cp]='\0';
		lc=cp;
		
		ans=-1;
		for(i=0;i<10;i++)	{
			if(!(i==0 && ((la>2 && a[0]=='X') || (lb>2 && b[0]=='X'))))	{
				carr=0;
				flg=1;
				ap=la-1;	bp=lb-1;	cp=lc-1;
				while(1)	{
					if(ap<0)	{
						an=0;
					}
					else if(a[ap]=='X')	{
						an=i;
					}
					else {
						an=a[ap]-'0';
					}
					if(bp<0)	{
						bn=0;
					}
					else if(b[bp]=='X')	{
						bn=i;
					}
					else {
						bn=b[bp]-'0';
					}					
					if(cp<0)	{
						flg=0;
						break;
					}
					s=carr+an+bn;
//					printf("s=%d car=%d an=%d bn=%d i=%d\n",s,carr,an,bn,i);
					if(c[cp]=='X')	{
						cn=i;
					}
					else {
						cn=c[cp]-'0';
					}
//					printf("cn=%d\n",cn);
					if(cn!=s%10)	{
						flg=0;
						break;
					}
					carr=s/10;
					ap--;	bp--;	cp--;
					if(ap<0 && bp<0 && carr==0)	break;
				}
				if(flg==1)	{
					ans=i;
					break;
				}
			}			
		}
		if(ans==-1)	{
			printf("NA\n");
		}
		else {
			printf("%d\n",ans);
		}
	}

	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

const int N = 2e5 + 5;

int32_t main()
{
    IOS;
    int t=1;
    // cin>>t;
    while(t--)
    {
        int n,d;
        cin>>n>>d;
        int ans=0;
        for (int i = 0; i < n; ++i)
        {
            int x,y; cin>>x>>y;
            if(x*x+y*y<=d*d) ans++;
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll L, R; cin >> L >> R;
    ll mod_min = 2019;
    for (ll i = L; i < R; i++) {
        for (ll j = i + 1; j <= R; j++) {
            mod_min = min(mod_min, i * j % 2019);
            if (mod_min == 0) break;
        }
        if (mod_min == 0) break;
    }
    cout << mod_min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

long long int fib(int n);

int main(){

  int div = 1000000007;
  int N,M;
  int a[100000];
  int i;
  long long int ans;
  
  scanf("%d %d", &N,&M);

  for(i=0;i<M;i++){
    scanf("%d", &a[i]);
  }

  ans = 1;

  
  if(M==0){
    ans*=fib(N+1);
    printf("%lld\n",ans);
    return 0;
  }

  if(M >=2){
  for(i=1;i<M;i++){
    if(a[i] - a[i-1] == 1){
      ans = 0;
      printf("%lld\n",ans);
      return 0;
    }
  }
  }

  
  if(M != 0){
  ans *= fib(a[0]) ;
  ans = ans % div;
  }

  
  if(M >=2){
  for(i=1;i<M;i++){
    ans *= fib(a[i] - a[i-1] -1) ;
    ans = ans % div;
  }
  }


  
  if(M != 0){
  ans *= fib(N- a[M-1]);
  ans = ans % div;
  //    printf("debug\n");
  }
  
  printf("%lld\n",ans % div);
  
  return 0;

}


long long int fib(int n){
	int i, a, b, c;
	for (i = 0, b = 1, c = 0; i < n; i++) {
		a = b;
		b = c;
		c = a + b;
		c %= 1000000007;
	}
	return c;
}


Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: usize,
        m: usize,
    }

    let ans = {
        let mut count = 0;
        let mut vec = vec![0; m+1];
        vec[x] = 0;
        let mut inv = vec![0; m+1];
        inv[0] = x;
        let mut next = x.pow(2) % m;
        while vec[next] == 0 {
            count += 1;
            inv[count] = next;
            vec[next] = count;
            next = next.pow(2) % m;
        }
        // vec[next]が最初のループ点の出現場所

        let mut ans = 0;
        for i in 0..n.min(vec[next]) {
            ans += inv[i]
        }
        if n > vec[next] {
            let amari = n-vec[next];
            let shuki = count-vec[next]+1;
            let mut aaa = 0;
            for i in 0..shuki {
                aaa += inv[vec[next]+i];
            }
            ans += (amari/shuki)*aaa;
            for i in 0..amari%shuki {
                ans += inv[vec[next]+i];
            }
        }
        ans
    };

    println!("{}",ans)
}

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

using namespace std;

int main(){
    string S;
    int N;
    cin >> N;

    int Bsum[N],Wsum[N],W=0,B=0,ans=1e9;

    cin >> S;

    for(int i=0;i<N;i++){
        if(S[i]=='#'){
            B++;
        }else{
            W++;
        }
        Bsum[i] = B;
        Wsum[i] = W;
    }


    for(int i=0;i<N;i++){
        if(i==0){
            ans = min(ans,W-Wsum[i]);
        }else{
            ans = min(ans,Bsum[i-1]+W-Wsum[i]);
        }
    }

    if(B==0 || W==0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 2180
#include<stdio.h>

int main(){
  int i,j,n,b,k;
  scanf("%d",&n);
  int a[n];
  for(k=0;k<n;k++){
    scanf("%d",&a[k]);
  }
  for(k=0;k<n;k++){
      if(k==n-1){
      printf("%d\n",a[k]);
      }else{
	
    printf("%d ",a[k]);
      
  }
  }
  
  for(i=1;i<=n-1;i++){
    b=a[i];
    j=i-1;
    while(j>=0 && a[j]>b){
      a[j+1]=a[j];
      j--;
      a[j+1]=b;
    }
    
    for(k=0;k<n;k++){
      if(k==n-1){
      printf("%d\n",a[k]);
      }else{
	
    printf("%d ",a[k]);
      
  }
    }
  }
  return 0;
}



Measured memory_bytes: 2072
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

string s;
int d;

int dp[10001][101][2];
int pwr[10001] = {1};

signed main()
{
	
 	FLASH

 	cin>>s>>d;
 	fr(i,1,10001) pwr[i] = (10*pwr[i -1])%d;

 	int l = s.size();
 	reverse(s.begin(), s.end());

 	dp[0][0][0] = dp[0][0][1] = 1;
 	
 	fr(i,1,l + 1)
 	{
 		int dig = s[i-1] - '0';
 		fr(j,0,d)
 		{
 			fr(k,0,dig)
 			{
 				dp[i][j][0] += dp[i-1][(j - k + mod*d)%d][1];
 				dp[i][j][0] %= mod;
 			}

 			dp[i][j][0] += dp[i - 1][(j - dig + mod*d)%d][0];
 			dp[i][j][0] %= mod;
 			
 			fr(k,0,10)
 			{
 				dp[i][j][1] += dp[i - 1][(j - k + mod*d)%d][1];
 				dp[i][j][1] %= mod;
 			}
 		}
 	}
 	int ans = (dp[l][0][0] - 1 + mod)%mod;
 	while(ans >= mod) ans -= mod;
 	while(ans < 0) ans += mod;

 	cout<<ans<<'\n';
}


Measured memory_bytes: 16128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int r = scan.nextInt();
		int D = scan.nextInt();
		int x = scan.nextInt();

		for(int i = 0; i < 10; i++)
		{
			// x = x r -D
			x = x * r - D;
			System.out.println(x);
		}

	}
}

Measured memory_bytes: 21588
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] as = new int[m];
        int[] bs = new int[m];
        for(int i = 0; i < m ; i++){
            as[i] = sc.nextInt() - 1;
            bs[i] = sc.nextInt() - 1;
        }

        solveUnionFindTree(n ,m ,as, bs);
    }

    static void solveUnionFindTree(int N, int M, int[] as, int[] bs){
        int ans = 0;
        for(int r1 = 0; r1 < M; r1++) { //繋がないリンク
            // 木作成
            UnionFindTree road = new UnionFindTree(N);
            for(int r2 = 0; r2 < M; r2++) {
                if(r1 == r2) continue;   //結合しない
                road.union(as[r2], bs[r2]);
            }
            
            //同じ木かどうか
            Set<Integer> root = new HashSet<>();
            for(int n = 0; n < N; n++) {
                root.add(road.find(n));
            }

            //全て同じ木に含まれている場合はSetなのでsizeは1になる
            if(root.size() != 1){
                ans++;
            }
        }
        System.out.println(ans);
    }

    static class UnionFindTree {

        int[] parent; //インデックスにとノードを対応させ、そのルートノードのインデックスを格納
        int[] rank; //parentと同様に、木の高さを格納

        public UnionFindTree(int size) {
            this.parent = new int[size];
            this.rank = new int[size];

            for (int i = 0; i < size; i++) {
                makeSet(i);
            }
        }

        public void makeSet(int i) {
            parent[i] = i;
            rank[i] = 0; //集合の高さ
        }

        public void union(int x, int y) {
            int xRoot = find(x);
            int yRoot = find(y);

            //xが属する木の方が大きい場合
            if (rank[xRoot] > rank[yRoot]) {
                parent[yRoot] = xRoot; //yの親をxに更新

            } else if(rank[xRoot] < rank[yRoot]) {
                parent[xRoot] = yRoot;

            } else if (xRoot != yRoot){
                parent[yRoot] = xRoot;
                rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
            }
        }

        //引数の属する木のルートのidを返す
        public int find(int i) {
            if (i != parent[i]) {
                parent[i] = find(parent[i]);
            }
            return parent[i];
        }

        //同じ木に属しているか
        public boolean same(int x, int y) {
            return find(x) == find(y);
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vvi to;
vi used, vs;

void dfs(int v) {
  if (used[v]) return;
  used[v] = 1;
  for (int u : to[v]) dfs(u);
  vs.pb(v);
}

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  to = vvi(n); used = vi(n);
  rep(i,m) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
  }
  rep(i,n) dfs(i);
  vi dp(n,0);
  int ans = 0;
  for (int v : vs) {
    for (int u : to[v]) {
      maxs(dp[v], dp[u]+1);
    }
    maxs(ans, dp[v]);
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){
  ll N, D, X;
  cin >> N >> D >> X;
  vector<int> t(N);
  for(int i = 0; i < N; i++){
	cin >> t.at(i);
  }
  for(int i = 0; i < N; i++){
    if(D % t.at(i) == 0) X += D/t.at(i);
    else X += (D/t.at(i) + 1);
  }
  cout << X << endl;
}


Measured memory_bytes: 256
# coding: utf-8
d = {"h":0, "i":0}
S = input()
if len(S) % 2 == 1:
    print("No")
    exit()
flag = True
for i in range(0, len(S)-1, 2):
    if S[i:i+2] != "hi":
        flag = False
        break
print("Yes" if flag else "No")

Measured memory_bytes: 3060
s = input()
n = int(input())
i = 0
while s[i]=="1":
    if n==i+1:
        print(1)
        exit()
    i+=1
    if i==len(s):
        break

for i in range(len(s)):
    if s[i]!="1":
        print(s[i])
        exit()


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, W;
	cin >> n >> W;
	vl v(n), w(n);
	REP(i, n)cin >> w[i] >> v[i];
	ll V = 0;
	REP(i, n)V += v[i];
	vl dp(V + 1, INF*INF);
	dp[0] = 0;
	REP(i, n) {
		RREP(j, V + 1) {
			if (j + v[i] <= V) {
				dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
			}
		}
	}
	ll ans = 0;
	REP(i, V + 1)if (dp[i] <= W)ans = max(ans, i);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll int

ll k,n,visit[100005],dp[100005][3],a[101],mini=100005;

void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

ll solve(ll curr,ll d)
{
	ll i,ans;
	if(dp[curr][d]!=-1)
		return dp[curr][d];
	if(visit[curr]==1)
	{
		dp[curr][1-d]=1-d;
		return dp[curr][d]=d;
	}
	if(curr<mini)
	{
		dp[curr][1-d]=d;
		return dp[curr][d]=1-d;
	}
	if(d==0)
		ans = 1;
	else
		ans = 0;
	for(i=0;i<n;i++)
	{
		if((curr-a[i])>0)
		{
			if(d==0)
				ans = min(solve(curr-a[i],1-d),ans);
			if(d==1)
				ans = max(solve(curr-a[i],1-d),ans);
		}
	}
	dp[curr][1-d]=1-ans;
	dp[curr][d]=ans;
	return dp[curr][d];
}

int main()
{
	ll i;
	boost();
	memset(visit,0,sizeof(visit));
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		visit[a[i]]=1;
		mini=min(a[i],mini);
	}
	if(solve(k,0))
		cout<<"Second"<<endl;
	else
		cout<<"First"<<endl;
	
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

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

  ll g=gcd(A,B);

  cout<<(A*B)/g<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く


signed main(){
  int n;cin>>n;
  ivec a(n);
  rep(i,n)cin>>a[i];
  sort(all(a),greater<int>());
  int ans=0;
  rep(i,n)(ans+=prod(a[i],inv(2))*(i+2))%=MOD;
  (ans*=beki(2,2*n-1))%=MOD;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

#include <cstdio>
#include <string>

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int N;

int vec_pos[100100];

int decode(string s){

  if(s == "Vacant"){
    return 0;
  }else if(s == "Male"){
    return 1;
  }else{
    return 2;
  }
}

int get_gen(int pos){

  if(vec_pos[pos] >= 0){
    return vec_pos[pos];
  }

  printf("%d\n", pos);
  fflush(stdout);

  string s;
  cin >> s;

  return vec_pos[pos] = decode(s);

}


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


  scanf("%d", &N);

  rep(i, N){
    vec_pos[i] = -1;
  }

  int left = 0;
  int right = N-1;

  while(right - left > 1){

    int mid = left + (right - left) / 2;

    int L = get_gen(left);
    int M = get_gen(mid);
    int R = get_gen(right);

    if(L == 0){
      cout << left << endl;
      return 0;
    }
    if(M == 0){
      cout << mid << endl;
      return 0;
    }
    if(R == 0){
      cout << right << endl;
      return 0;
    }

    if((mid-left)%2 == abs(L-M)){
      left = mid;
    }else{
      right = mid;
    }
    
  }

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,K; cin>>H>>W>>K;

    vector<vi> a(H, vi(W));
    rep(i,H)rep(j,W){
        char c; cin>>c;
        a[i][j] = c-'0';
    }

    int ans=1e6;
    rep(cut,1<<H-1){
        int cand=0;
        cand = __builtin_popcount(cut);
        int N = cand+1;
        vector<vi> row(N, vi(W));
        int idx=0;
        rep(i,H){
            rep(j,W) row[idx][j]+=a[i][j];
            if (cut>>i&1) idx++;
        }
        bool isok = [&](){
            rep(i,N)rep(j,W)if(row[i][j]>K) return false;
            return true;
        }();
        if (!isok) continue;
        vi now(N);
        rep(j,W){
            bool over=false;
            rep(i,N){
                now[i]+=row[i][j];
                if (now[i]>K) over=true;
            }
            if (over){
                rep(i,N) now[i]=row[i][j];
                cand++;
            }
        }
        chmin(ans,cand);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <random>

using namespace std;

int N;
double T, A;
double H[1010];

int main() {
    cin >> N >> T >> A;
    for (int i = 0; i < N; i++) cin >> H[i];
    
    double min = 100000;
    double c = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (T - H[i] * 0.006 > A) c = T - H[i] * 0.006 - A;
        else c = A - (T - H[i] * 0.006);
        if (c < min) {
            min = c;
            ans = i + 1;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n,p=map(int,input().split())
s=factorization(p) 
ans=1
for i in s:
    ans=ans*(i[0]**(i[1]//n))
print(ans)



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

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int Y, M, D;
		cin >> Y >> M >> D;

		int offset = (10 - M + 1) * 20 - (D - 1);
		if (Y % 3 != 0){
			offset -= (12 - M) / 2; //小の月の分を引く。 int/intだが問題ない
		}

		Y++;
		int uruutime = (1002 - Y) / 3;
		int ans = offset + 195 * (1000 - Y) + uruutime * 5;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
def input():
    return sys.stdin.readline()[:-1]
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

import bisect
from collections import deque

lis = deque()
for i in range(n):
    ind = bisect.bisect_left(lis,a[i])
    if ind==0:
        lis.appendleft(a[i])
    else:
        lis[ind-1] = a[i]

print(len(lis))


Measured memory_bytes: 47708
using System;
class Program
{
	static void Main()
	{
      int a = int.Parse(Console.ReadLine());
      string b = "";
      int c, d, e, f;
      c = d = e = f = 0;
      for(int i=0; i<a; i++)
      {
        b = Console.ReadLine();
        switch (b)
        {
            case "AC":
              c++;
              break;
            case "WA":
              d++;
              break;
            case "TLE":
              e++;
              break;
            case "RE":
              f++;
              break;
            default:
              break;
        }
      }
      Console.WriteLine($"AC x {c}");
      Console.WriteLine($"WA x {d}");
      Console.WriteLine($"TLE x {e}");
      Console.WriteLine($"RE x {f}");
	}
}

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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/home/max/alg/clion_main/input.txt", "rt", stdin);
    freopen("/home/max/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define CD complex<D>
#define ll long long

// ----------------------------- CODE NOW ------------------------



signed main() {
    doRoutine();

    ll n;
    cin >> n;
    cout << (n - 1) * n / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define stpn setprecision
using namespace std;
typedef long long ll;
string a,b,c;
int n,m;
int main()
{
	cin>>a>>b;
	cin>>n>>m;
	cin>>c;
	if (c==a) cout<<n-1<<' '<<m;
	else cout<<n<<' '<<m-1;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string ans="No";
  vi A(3);
  rep(i,0,3) cin>>A[i];
  if(A[0]==A[1]&&A[1]==A[2])
    ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include<stdio.h>

int func(int a[], int i, int m, int n)
{
  int res = 0;
  
  if(m == 0){
    return 1;
  }
  if(i >= n){
    return 0;
  }
  res = func(a, i+1, m, n) || func(a, i+1, m-a[i], n);
  return res;
}
  
int main(){
  int n,q;
  int i;
  int m;
  int a[25];
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);

  for(i=0;i < q;i++){
    scanf("%d",&m);
    if( func(a, 0, m, n) ){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
	int n;
	cin >> n;
	int mill = 1;
	for (int i = 1; i < 1000; i++) {
		if (i % 3 == 0) {
			mill += 20*10;
		} else {
			mill += 20*5 + 19*5;
		}
	}
	
	for (int i = 0; i < n; i++) {
		int y, m, d;
		cin >> y >> m >> d;
		int t = 0;
		for (int i = 1; i < y; i++) {
			if (i % 3 == 0) {
				t += 20*10;
			} else {
				t += 20*5 + 19*5;
			}
		}
		for (int i = 1; i < m; i++) {
			if (i%2) {
				t += 20;
			} else {
				if (y%3 != 0)t += 19;
				else t+=20;
			}
		}
		t += d;
	
		cout << mill - t << endl;
	}

	return 0;
}

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

int main()
{
    string N;
    int sum = 0;

    cin >> N;
    for(int i = 0; i < N.size(); i++)
    {
        sum += (N[i] - '0');
    }

    if((stoi(N) % sum) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <map>

using namespace std;

typedef long long LL;
typedef map<int, int> IIMap;
typedef map<int, IIMap> IIIMap;

int main(int argc, char *argv[]) {
	int H, W, N;
	cin >> H >> W >> N;
	IIIMap m;
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		for (int c = -2; c <= 0; ++c) {
			int p = a + c;
			if (p >= 0 && p <= H - 3) {
				IIMap &x = m[p];
				for (int d = -2; d <= 0; ++d) {
					int q = b + d;
					if (q >= 0 && q <= W - 3) {
						x[q] += 1;
					}
				}
			}
		}
	}
	LL cnt[10] = { (LL)(H - 2) * (W - 2) };
	for (auto x : m) {
		for (auto y : x.second) {
			cnt[y.second] += 1;
			--cnt[0];
		}
	}
	for (int i = 0; i <= 9; ++i) {
		cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 3)
    {
        if (s[i] == t[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] a){

		Scanner sc = new Scanner(System.in);


		int tatebo = sc.nextInt();
		int yokobo = sc.nextInt();

		int num [] = new int[tatebo];
		for(int i = 0; i < tatebo; i++) {
			num[i] = i + 1;
		}


		for(int i = 0; i < yokobo; i++) {

			String tmp1 = sc.next();
			String tmp2 [] = tmp1.split(",");
			int tmp3 = 0;

			int x = Integer.valueOf(tmp2[0]) - 1;
			int y = Integer.valueOf(tmp2[1]) - 1;


			tmp3 = num[x];
			num[x] = num[y];
			num[y] = tmp3;
		}


		for(int i: num) {

			System.out.println(String.valueOf(i));
		}

	}

}

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

int main()
{
    double height, max=0, min=0;
 
    bool i=1;
 
    while (cin >> height)
    {
        if(i)
        {
            max=height;
 
            min=height;
 
            i=0;
        }
 
        if(height>max)
        {
            max = height;
        }
 
        if(height<min)
        {
            min = height;
        }
    }
 
    cout << max-min << endl;
}

Measured memory_bytes: 1280
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

c = np.array(c) # 満足度の下がりやすさ
s = np.array(s) # i日目jコン
s_t = s.T # iコンj日目
last = np.zeros(26)

# 評価関数
# 得になった分+その日の満足度
# n: 日数, 
def eva(n, cc, ss):
    r = np.random.rand()/2+1
    return (d-n)*cc + 30*ss

score = 0

for i in range(d): # i日目(0-indexed)
    last += 1 # 一日分追加
    tow = c * last # 満足下がる値 
    sc = -100000
    M = -1
    for j in range(26):
        k = eva(i, tow[j], s[i][j])
        if sc < k:
            sc = k
            M = j
    last[M] = 0
    score -= np.dot(c,last)
    score += s[i][M]
    print(M+1)

#print(score)

Measured memory_bytes: 27444
N = int(input())

s = []
ans = 0
count = 1

for i in range(N):
    tmp = input()
    s.append("".join(sorted(tmp)))

s.sort()

for i in range(N - 1):
    if s[i] == s[i + 1]:
        count += 1
    else:
        ans += count*(count - 1) / 2
        count = 1
ans += count*(count - 1) / 2

print(int(ans))

Measured memory_bytes: 10584
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 100000
using namespace std;


int V, E, r;
int d[MAX_V];
struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_V];

void Dijkstra(int start) {
	fill(d, d + V, INF);
	priority_queue<P, vector<P>, greater<P>> que;
	d[start] = 0;
	que.push(P(0, start));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	int r;
	cin >> V >> E >> r;
	for (int i = 0, s, t, d; i < E; i++) {
		cin >> s >> t >> d;
		G[s].push_back(edge(t, d));
	}
	Dijkstra(r);
	for (int i = 0; i < V; i++) {
		if (d[i] == INF)
			cout << "INF" << endl;
		else
			cout << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 13008
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    rep(i, h){
        cin >> a[i];
    }

    vector< vector<int> > cost(h, vector<int>(w, IINF));
    cost[0][0] = a[0][0] == '#';
    deque< pair< P, int > > que;
    que.push_back({{0, 0}, cost[0][0]});

    while(!que.empty()){
        auto now = que.front();
        que.pop_front();

        if(cost[now.first.first][now.first.second] < now.second){
            continue;
        }

        if(now.first.first < h - 1){
            int ny = now.first.first + 1;
            int nx = now.first.second;
            int nc = a[ny - 1][nx] != a[ny][nx];
            if(nc == 0 && chmin(cost[ny][nx], now.second)){
                que.push_front({{ny, nx}, now.second});
            }else if(nc == 1 && chmin(cost[ny][nx], now.second + 1)){
                que.push_back({{ny, nx}, now.second + 1});
            }
        }
        if(now.first.second < w - 1){
            int ny = now.first.first;
            int nx = now.first.second + 1;
            int nc = a[ny][nx - 1] != a[ny][nx];
            if(nc == 0 && chmin(cost[ny][nx], now.second)){
                que.push_front({{ny, nx}, now.second});
            }else if(nc == 1 && chmin(cost[ny][nx], now.second + 1)){
                que.push_back({{ny, nx}, now.second + 1});
            }
        }
    }

    cout << (cost[h - 1][w - 1] + 1) / 2 << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
main()
{
  int n,c[100],i,flag,l,k,d,ccount=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
    {
      scanf("%d",&c[i]);
    }
 
  flag = 1;
  k = 0;
  while(flag)
    {
      flag =0; 
      for(i=n-1;i>=k+1;i--)
	{
	  
	  if(c[i-1] > c[i]){
	    d = c[i];
	    c[i] = c[i-1];
	    c[i-1] = d;
	    flag = 1;
	    ccount++;
          }
	  
	}
      k++;
      
    }
     
 for(l=0;l<n;l++)
    {
      printf("%d",c[l]);
      if(l!=n-1) printf(" ");
    }
      printf("\n%d\n",ccount);
      return 0;
 
 
    }

Measured memory_bytes: 604
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

int vis[50][100010];
int n;

void dfs(int rem, int dist){
    if(dist > 45) return;
    if(vis[dist][rem]) return;
    vis[dist][rem] = 1;
    for(int i = 0; i < 10; i++)
        dfs((rem*10+i)%n, dist+i);
}

int main(){

    cin >> n;
    for(int i = 1; i < 10; i++)
        dfs(i, i);

    for(int i = 1; i <= 45; i++)
        if(vis[i][0]){
            cout << i << endl;
            return 0;
        }
    return 0;
}	


Measured memory_bytes: 121088
# include <iostream>
# include <cmath>
# include <string>
# include <vector>

using namespace std;

int main() {
    int n;
    string colors;
    cin >> n;
    cin >> colors;

    int countR=0, countB=0;
    for (int i=0; i<n; i++){
        if (colors[i] == 'R'){
            countR ++;
        }else{
            countB ++;
        }
    }
    if (countR > countB) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl; 
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define M (L+R)/2
using namespace std;
typedef long long LL;
const int N = 2e5;
struct seg_tree
{
    LL seg[4*(N+1)+215];
    LL lazy[4*(N+1)+215];
    int n;
    void build(int L, int R, int node)
    {
        lazy[node] = -1;
        if(L==R)
        {
            seg[node] = n-2;
            return;
        }
        build(L,M,2*node);
        build(M+1,R,2*node+1);
    }
    void assign_n(int n)
    {
        this->n = n;
        build(1,n,1);
    }
    void lazy_update(int L, int R, int node)
    {
        if(lazy[node]!=-1)
        {
            if(L==R)
                seg[node] = lazy[node];
            else
                lazy[2*node] = lazy[2*node+1] = lazy[node];
            
            lazy[node] = -1;
        }
    }
    void range_set(int L, int R, int left, int right, LL val, int node)
    {
        lazy_update(L,R,node);
        if(L > R || L > right || R < left)
            return;
        if(left <= L && R <= right)
            lazy[node] = val;
        else
        {
            range_set(L,M,left,right,val,2*node);
            range_set(M+1,R,left,right,val,2*node+1);
        }
    }
    void range_set(int left, int right, LL val)
    {
        range_set(1,n,left,right,val,1);
    }
    LL query(int L, int R, int pt, int node)
    {
        lazy_update(L,R,node);
        if(L==R)
            return seg[node];
        if(pt <= M)
            return query(L,M,pt,2*node);
        else
            return query(M+1,R,pt,2*node+1);
    }
    LL query(int pt)
    {
        return query(1, n, pt, 1);
    }
};
seg_tree R, C;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    LL n; cin >> n;
    R.assign_n(n);
    C.assign_n(n);

    LL up_bound = n;
    LL left_bound = n;

    LL ans = (n-2)*(n-2);
    int q; cin >> q;
    while(q--)
    {
        int t; LL x;
        cin >> t >> x;
        if(t==1)
        {
            ans -= C.query(x);
            if(x < left_bound)
            {
                left_bound = x;
                R.range_set(1,up_bound,x-2);
            }
            //cout<<C.query(x)<<endl;
        }
        else
        {
            ans -= R.query(x);
            if(x < up_bound)
            {
                up_bound = x;
                C.range_set(1,left_bound,x-2);   
            }
            //cout<<R.query(x)<<endl;
        }
        // cout<<endl;
        // for(int i = 1; i <= n-1; i++)
        //     cout<<R.query(i)<<" "<<C.query(i)<<endl;

    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    string a,b;
    cin >> a >> b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;

	if (a % 2 != 0 && b % 2 != 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>

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

int main()
{
  int n;
  scanf("%d",&n);
  std::vector<int> P(n*n);
  for(int i=0;i<n*n;i++){
    scanf("%d",&P[i]);
    P[i]--;
  }
  std::vector<int> d(n*n);
  std::vector<bool> s(n*n,true);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i*n+j]=std::min(std::min(i,n-i-1),std::min(j,n-j-1))+1;
    }
  }
  int ans=0;
  for(int t=0;t<n*n;t++){
    int p=P[t];
    ans+=d[p]-1;
    d[p]--;
    s[p]=false;
    std::queue<int> Q;
    Q.push(p);
    while(!Q.empty()){
      int i=Q.front()/n,j=Q.front()%n;
      Q.pop();
      for(int v=0;v<4;v++){
	int ni=i+dx[v],nj=j+dy[v];
	if(ni<0||n<=ni||nj<0||n<=nj)continue;
	int nd=d[n*i+j]+(s[n*ni+nj]?1:0);
	if(d[n*ni+nj]>nd){
	  d[n*ni+nj]=nd;
	  Q.push(n*ni+nj);
	}
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<ll> a(N+1);
  vector<ll> b(N);
  
  for(int i=0;i<N+1;++i){
    cin>>a[i];
  }
  for(int i=0;i<N;++i){
    cin>>b[i];
  }
  
  ll ans=0;
  
  for(int i=0;i<N;++i){
    if(a[i]<=b[i]){
      ans+=a[i];
      int x=a[i+1]-(b[i]-a[i]);
      if(x>=0){
        ans+=(b[i]-a[i]);
        a[i+1]=x;
      }
      else{
        ans+=a[i+1];
        a[i+1]=0;
      }
    }
    else
      ans+=b[i];
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
import math
N = int(input())
d = {}

def main(n):
  global d
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        if i in d:
          d[i] += 1
        else:
          d[i] = 1
        temp //= i
      arr.append(i)

  if temp!=1:
    if temp in d:
      d[temp] += 1
    else:
      d[temp] = 1
    arr.append(temp)

  if arr==[]:
    if n in d:
      d[n] += 1
    else:
      d[n] = 1
    
for i in range(2, N+1):
  main(i)
ans = 1
for i in d.values():
  ans *= (i+1)
ans = ans % (10**9+7)
print(ans)

Measured memory_bytes: 9436
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
using ll = long long;

template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> void show(vector<T>v){rep(i,v.size()-1){cout<<v.at(i)<<" ";}cout<<v.at(v.size()-1)<<endl;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
vector<string> split(const string&s,char d){vector<string>r;stringstream ss(s);string k;while(getline(ss,k,d))if(!k.empty())r.pb(k);return r;}

// Template ends here

int main() {
    ll n, cnt = 0;
    cin >> n;
    vector<ll> A;
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        cnt += (tmp != abs(tmp));
        A.pb(abs(tmp));
    }

    if (cnt % 2) {
        ll sum = 0;
        sort(all(A));
        rep(i, n) sum += A.at(i);
        cout << sum - 2 * A.at(0) << endl;
    } else {
        ll sum = 0;
        rep(i, n) sum += A.at(i);
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    long N=gl();
	    long A=gl();
	    long B=gl();
	    long C=gl();
	    long D=gl();
	    long E=gl();

	    long min=Math.min(Math.min(A, B), Math.min(C, Math.min(D, E)));
	    long a=(long)Math.ceil((double)N/(double)min);
        System.out.println(4+a);
//	    if(max>s-max) {
//	    	System.out.println(s-max-1);
//	    }
	}

	public static double f(double r, double n, double m, double i) {
		double a = 0;
		double b=0;
		if(0<i&&i<n) {
			a=Math.abs(r-((2*r/n)*i));
			a= Math.sqrt(Math.pow(r, 2) - Math.pow(a, 2));
		}
		if(0<i-m&&i-m<n) {
			b=Math.abs(r-(2*r*(i-m)/n));
			b=Math.sqrt(Math.pow(r, 2) - Math.pow(b, 2));
		}
		return 2* Math.max(a, b);
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35700
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    prize = set()
    for _ in range(N):
        S = input()
        prize.add(S)

    print(len(prize))


if __name__ == '__main__':
    main()


Measured memory_bytes: 87960