akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] parent;//union-find用
	static int[] rank;//union-find用

	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N+1];
		for(int i = 1;i<=N ; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 1;i<=N ; i++) {
			if(i%2==1 && a[i]%2==1) {
				ans++;
			}
		}




		System.out.println(ans);
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
	static void ufInit(int n){
		parent = new int[n];
		rank = new int[n];
	}

	//Union-Findの要素の最上位の親（グループ名）を返す
	static int ufFind(int a) {
		if(parent[a]==a) {
			return a;
		}else {
			return ufFind(parent[a]);
		}
	}

	//Union-Find木を連結する
	static void ufUnite(int a, int b) {
		a = parent[a];
		b = parent[b];

		if(a==b) {
			return;
		}
		if(rank[a] > rank[b]){
			parent[b]=a;
		}else {
			parent[a]=b;
			if(rank[a]==rank[b]) {
				rank[b]++;
			}
		}
	}

	static boolean ufSame(int a, int b) {
		return ufFind(a)==ufFind(b);
	}
}


Measured memory_bytes: 35736
//jinhaonan
#include<set>
#include<map>
#include<list>
#include<ctime>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define For(i,x,y) for(int i=x,_y=y;i<=_y;++i)
#define Rep(i,x,y) for(int i=x,_y=y;i>=_y;--i)
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
inline int read()
{
	int x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
int main()
{
	int a=read(),b=read();
	write((a-1)*(b-1));puts("");
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a=[0 for _ in range(n)]
b=[0 for _ in range(n)]
c=[0 for _ in range(m)]
d=[0 for _ in range(m)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())
for i in range(n):
    ans=0
    mi=float('inf')
    for j in range(m):
        if(mi>abs(a[i]-c[j])+abs(b[i]-d[j])):
            ans=j+1
            mi=abs(a[i]-c[j])+abs(b[i]-d[j])
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int sum = 0;
  for(int i=0;cin >> ch;i++){
    if(ch == '\\') S1.push(i);
    else if(ch == '/' && S1.size() > 0){
      int j = S1.top(); S1.pop();
      sum += i -j;
      int a = i - j;
      while(S2.size() > 0 && S2.top().first > j){
	a+= S2.top().second; S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }

  vector<int> ans;
  int t = 0;
  while(S2.size() > 0){
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i = 0;i<ans.size();i++){
    cout << " ";
    t+=ans[i];
    cout << ans[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3216
def main():
    s = input()
    flag = True

    for i in range(len(s)):
        if i % 2 == 0:  # 奇数文字目
            if s[i] not in ["R", "U", "D"]:
                flag = False
                break
        else:  # 偶数文字目
            if s[i] not in ["L", "U", "D"]:
                flag = False
                break

    if flag:
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62012
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll cnt[1111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  for(int i=0;i<n;i++){
    ll k;cin>>k;
    for(int j=0;j<k;j++){
      ll a;cin>>a;
      cnt[--a]++;
    }
  }ll ans=0;
  for(int i=0;i<1111;i++)
    if(cnt[i]==n)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a=new int[N];
        for(int i=0; i<N; i++){
            a[i]=sc.nextInt();
        }

        int count=0;
        for(int i=0; i<N; i++){
            if(i%2==1 || a[i]%2==0){
                continue;
            }
            count++;
        }
        
        System.out.println(count);
        
        
        
        
        
        }
    }

Measured memory_bytes: 35804
#include <stdio.h>
int main(void)
{
	int a, b;
	scanf("%d", &a);
	scanf("%d", &b);
	if((a < b) && (-1000 <= a) && (b <= 1000))
	{
		printf("a < b\n");
	}
	else
	{
		if((a == b) && (-1000 <= a) && (b <= 1000))
		{
			printf("a == b\n");
		}
		else
		{
			printf("a > b\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,a=1,max=0;
    cin >> N;
    for(int i=1;i<N+1;i++){
        int kaisu=0;
        int copy=i;
        while(copy%2==0){
            copy=copy/2;
            kaisu++;
        }
        if(kaisu>max){
            max=kaisu;
            a=i;
        }
    }
    cout << a;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
const int mod = 1e9 + 7;
int fac[N], inv[N];
int n, x, y, tot, fa[N], tong[N];
struct ddd{
    int c, w;
    bool operator < (const ddd &X) const{
        if(c != X.c)return c < X.c;
        return w < X.w;
    }
}b[N];
int find(int x){
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y){
    int fx = find(x), fy = find(y);
    if(fx == fy)return ;
    fa[fx] = fy;
}
int main(){
    //freopen("agc012d.in", "r", stdin);
    inv[0] = inv[1] = fac[0] = fac[1] = 1;
    for(int i = 2;i <= 2e5; i++){
        fac[i] = 1LL * fac[i-1] * i % mod;
        inv[i] = (mod - 1LL * mod / i * inv[mod%i] % mod);
    }
    for(int i = 1;i <= 2e5; i++)inv[i] = 1LL * inv[i-1] * inv[i] % mod;
    cin>>n>>x>>y;
    int pmi = 1;
    for(int i = 1;i <= n; i++){
        fa[i] = i;
        scanf("%d%d", &b[i].c, &b[i].w);
    }
    sort(b + 1, b + 1 + n);
    for(int i = 1;i <= n; i++)if(b[i].w < b[pmi].w)pmi = i;
    for(int i = 1;i <= n; i++){
        if(b[i].c == b[pmi].c)continue;
        if(b[i].w + b[pmi].w <= y)merge(i, pmi);
    }
    int mi, smi = 1;
    for(int i = 1;i <= n; i++){
        if(b[i].c != b[i-1].c)mi = i;
        else{
            if(b[i].w + b[mi].w <= x)merge(i, mi);
        }
        if(b[i].c != b[pmi].c && b[i].w < b[smi].w)smi = i;
    }
    for(int i = pmi + 1;i <= n && b[i].c == b[i-1].c; i++)if(b[i].w + b[smi].w <= y)merge(i, smi);
    for(int i = 1;i <= n; i++){
        if(find(i) == find(pmi))tong[b[i].c]++;
    }
    int ans = 0, pai = 1;
    for(int i = 1;i <= n; i++){
        if(!tong[i])continue;
        ans += tong[i];
        pai = 1LL * pai * inv[tong[i]] % mod;
        //printf("i=%d tong=%d\n", i, tong[i]);
    }
    ans = 1LL * fac[ans] * pai % mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;


int main() {
  int R[MAX], n;
  cin >>n;
  for(int i=0;i<n;i++)cin >>R[i];
  int maxv=-2000000001;
  int minv=R[0];

  for(int i=1;i<n;i++){
	  maxv=max(maxv,R[i]-minv);
	  minv=min(minv,R[i]);
  }
  cout << maxv <<endl;

	return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  string s;
  cin>>s;
  string ans;
  if(s=="AAA"||s=="BBB"){
    ans="No";
  }
  else{
    ans="Yes";
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
import sys
S = list(input())
N = len(S)
if S[0] == "A":
    s = 0
    for i in S[2:len(S)-1]:
        if i == "C":
            s += 1
    if s == 1:
        c = 0
        for i in S:
            if i.islower():
                 c += 1
        if c == N-2:
            print("AC")
            sys.exit()
print("WA")




Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

ll dp[45][45][45];
int n,a[45][45];

ll rec(int l,int r,int x){
	if(l > r || (l == x && r == x)) return 1;
	if(l == x || r == x) return 0;
	if(dp[l][r][x] >= 0) return dp[l][r][x] ;
	ll ret = 0;
	for(int i=l;i<x;i++){
		for(int j=x+1;j<=r;j++){
			if(a[i][j] == 0) continue;
			for(int ii=i;ii<x;ii++){
				for(int jj=x+1;jj<=j;jj++){
					ret += rec(l,ii,i) * rec(ii+1,jj-1,x) * rec(jj,r,j);
				}
			}
		}
	}
	return dp[l][r][x] = ret;
}
int main(){
	cin >> n;
	rep(i,2*n){
		string s; cin >> s;
		rep(j,2*n){
			a[i][j] = s[j]-'0';
		}
	}
	memset(dp,-1,sizeof(dp));
	ll ans = 0;
	for(int i=1;i<2*n;i++){
	    if(a[0][i] == 0) continue;
		ans += rec(1,2*n-1,i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
arr = []
for _ in range(n):
    arr.append(list(map(int, input().split()[1:])))

ans = 0
tmp = 0
for i in range(31):
    for j in arr:
        if i in j:
            tmp += 1
        else:
            break
    if tmp == n:
        ans += 1
    tmp = 0

print(ans)


Measured memory_bytes: 3060
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll a[200005],s[200005];
int main(){
	std::ios::sync_with_stdio(false);
	ll n,i,b,val,val1,minn=inf;
	minn*=inf;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(a,a+n);
	rep(i,n){
		s[i]=i>0?s[i-1]+a[i]:a[i];
	}
	rep(i,n){
		b=a[i];
		val=b*(i+1)-s[i];
		val1=s[n-1]-s[i];
		val+=val1;
		val-=(n-i-1)*b;
		minn=min(minn,val);
	}
	cout<<minn<<endl;
} 
	

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    stack<int>s1;
    stack<pair<int,int> >s2;
    char ch;
    int sum=0;
    for(int i=0;cin>>ch;i++){
        if(ch=='\\'){//注意\的格式
            s1.push(i);
        }else if(ch=='/'&&!s1.empty()){
            int j=s1.top();
            s1.pop();
            sum+=i-j;
            int a=i-j;
            while(!s2.empty()&&s2.top().first>j){
                a+=s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j,a));
        }
    }
    vector<int>ans;
    while(!s2.empty()){
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++){
        cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}
/*
\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\
*/



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

int main()
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	if (K <= A) {
		cout << K << endl;
	}
	else if (K <= A + B) {
		cout << A << endl;
	}
	else {
		cout << A - (K - A - B) << endl;
	}


}






Measured memory_bytes: 3684
N = int(input())
S = input()
e = S.count('E')
X = [0]*(N+1)
X[0] = e
Y = [0]*(N+1)
Y[N] = N-e
for i in range(1, N+1):
    X[i] = X[i-1]-(S[i-1] == 'E')
for i in range(N, 0, -1):
    Y[i-1] = Y[i]-(S[i-1] == 'W')
ans = [X[i+1]+Y[i] for i in range(N)]
# print(X)
# print(Y)
print(min(ans))

Measured memory_bytes: 98092
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

a=I()
b=I()
c=I()
x=I()
count=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                count+=1
print(count)

Measured memory_bytes: 3316
N=input()
nlist= [int(l) for l in raw_input().split(' ')]

rate= [0,0,0,0,0,0,0,0]
up = 0
for n in nlist:
	if n/400>=8:
		up += 1
	else:
		rate[n/400]=1

print max(1,sum(rate)),sum(rate)+up

Measured memory_bytes: 2568
from itertools import accumulate

N = int(input())
S = input()

turn_E = [0] + list(accumulate([s=="W" for s in S[:-1]]))
turn_W = list(reversed(list(accumulate([s=="E" for s in S[:0:-1]])))) + [0]

ans = [e+w for e, w in zip(turn_E, turn_W)]
print(min(ans))

Measured memory_bytes: 40092
//ΔARC083F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
const int MO = 1e9+7;
int mul(int x,int y){
	return (LL)x*y%MO;
}
int fpow(int x,int y=MO-2){
	int z=1;
	while(y){
		if(y&1)
			z=mul(z,x);
		y>>=1;
		x=mul(x,x);
	}
	return z;
}
int fac[N];
int n,a[N],b[N],c[N],p[N],r[N],t[N];
vector<int> v[N],h[N],g[N],w,e;
int tx,ty,tz;
void dfs1(int u,int fa){
	int i,x;
	c[u]=1;
	w.push_back(u);
	for(i=0;i<v[u].size();i=i+1){
		x=v[u][i];
		if(x==fa)
			continue;
		if(c[x]){
			if(u<x)
				e.push_back(h[u][i]);
			tx=u,ty=x,tz=h[u][i];
			continue;
		}
		e.push_back(h[u][i]);
		dfs1(x,u);
	}
}
void dfs2(int u,int fa){
	int i,x;
	for(i=0;i<v[u].size();i=i+1){
		x=v[u][i];
		if(x<0||x==fa)
			continue;
		p[h[u][i]]=x;
		r[x]=h[u][i];
		dfs2(x,u);
	}
}
void dfs3(int u){
	if(t[u])
		return;
	int i,x;
	t[u]=1;
	for(i=0;i<g[u].size();i=i+1){
		x=g[u][i];
		dfs3(x);
		t[u]+=t[x];
	}
}
int solve(){
	int i,x,y;
	for(i=0;i<w.size();i=i+1){
		x=r[w[i]];
		if(w[i]<=n){
			y=r[n+b[x]];
			if(a[y]>a[x])
				g[y].push_back(x);
		}
		else{
			y=r[a[x]];
			if(b[y]>b[x])
				g[y].push_back(x);
		}
	}
	for(i=0;i<e.size();i=i+1)
		t[e[i]]=0;
	for(i=0;i<e.size();i=i+1)
		if(!t[e[i]])
			dfs3(e[i]);
	x=1;
	for(i=0;i<e.size();i=i+1)
		x=mul(x,t[e[i]]),g[e[i]].clear();
	return fpow(x);
}
int main()
{
	int i,j,s,o;
	scanf("%d",&n);
	for(i=1;i<=n+n;i=i+1){
		scanf("%d%d",a+i,b+i);
		v[a[i]].push_back(n+b[i]);
		h[a[i]].push_back(i);
		v[n+b[i]].push_back(a[i]);
		h[n+b[i]].push_back(i);
	}
	fac[0]=1;
	for(i=1;i<=n+n;i=i+1)
		fac[i]=mul(fac[i-1],i);
	s=fac[n+n];
	for(i=1;i<=n+n;i=i+1){
		if(!c[i]){
			w.clear();
			e.clear();
			tx=0,ty=0,tz=0;
			dfs1(i,0);
			if(w.size()!=e.size()){
				cout<<0;
				return 0;
			}
			for(j=0;j<v[tx].size();j=j+1)
				if(v[tx][j]==ty)
					v[tx][j]=-1;
			for(j=0;j<v[ty].size();j=j+1)
				if(v[ty][j]==tx)
					v[ty][j]=-1;
			p[tz]=tx,r[tx]=tz;
			dfs2(tx,0);
			o=solve();
			p[tz]=ty,r[ty]=tz;
			dfs2(ty,0);
			o+=solve();
			s=mul(s,o);
		}
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 42524
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<string> s(N);
	vector<int> t(N);
	string X;
	for (int i=0; i<N; i++)
		cin>>s[i]>>t[i];
	cin>>X;
	int idx=-1;
	for (int i=0; i<N; i++)
		if(s[i]==X) {
			idx=i;
			break;
		}

	int ret=0;
	for (int i=idx+1; i<N; i++)
		ret+=t[i];
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), sum = 0;
        
        for (int i = 0; i <= N; i++) {
            sum += i;
        }

        System.out.println(sum);

        sc.close();
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <iomanip>
#include <cmath>
#define ll long long int
using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	cout << setprecision(15);
	int *a = new int[n];
	int *b = new int[n];
	for(int i = 0; i < n; i++){
			int x;
			cin >> x;
			a[i] = x;
	}
	for(int i = 0; i < n; i++){
			int x;
			cin >> x;
			b[i] = x;
	}
	int sum1 = 0;
	int sum2 = 0;
	ll sum3 = 0;
	int max = 0;
	for(int i = 0; i < n; i++){
			sum1 += abs(a[i] - b[i]);
			sum2 += (a[i] - b[i])*(a[i] - b[i]);
			sum3 += abs((a[i] - b[i])*(a[i] - b[i])*(a[i] - b[i]));
			if(max < abs(a[i] - b[i]))max = abs(a[i] - b[i]);
	}
	cout << sum1 << endl;
	cout << sqrt((double)sum2) << endl;
	cout << pow((double)sum3, 1./3) << endl;
	cout << max << endl;
	return 0;
}



Measured memory_bytes: 3396
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


int main(){
    // input
    lint H;
    cin >> H;

    // calc
    lint ans           = 0;
    lint monster_count = 1;
    while( H > 0 ){
        ans += monster_count;
        monster_count *= 2;
        H /= 2;
    }

    // out
    cout << ans << endl;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
	    Scanner std = new Scanner(System.in);
	    double r = std.nextDouble();
	    double s = r * r * Math.PI;
	    double l = 2 * r * Math.PI;
	    System.out.println(String.format("%.6f", s)+" "+String.format("%.6f", l));
	}
}

Measured memory_bytes: 27824
#include <bits/stdc++.h>
#define fi first
#define se second
#define fo(name,start,end) for(int (name)=(start);(name)<(end);(name)++)
#define mkpr(fir,sec) make_pair((fir),(sec))
#define lo long
#define sz(a) int((a).size())
#define pb push_back
#define all(cont) (cont).begin(),(cont).end()
#define foit(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mspre(cont,name) ((cont).find(name) != (cont).end())
#define cpre(cont,name) (find(all(cont),name) != (cont).end())
#define ist istringstream
#define ost ostringstream
#define vi  vector<int>
#define pii pair<int,int>
#define ret return
using namespace std;
int x,a,b;
main()
{
    ios::sync_with_stdio(0);
    cin >> x >> a >> b;
    x-=a;
    cout << x%b;
}

Measured memory_bytes: 256
#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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main() {
    string s;
    cin>>s;
    int a=0;
    REP(i,4) {
        if(s[i]=='+') a=a+1;
        else a=a-1;

    }
    cout<<a<<endl;
}

Measured memory_bytes: 384
#include <iostream>
int main() {
	int S;
	std::cin >> S;
	int a = S / 3600;
	int b = S % 3600;
	int c = b / 60;
	int d = b % 60;
	int e = d;
	std::cout << a << ":" << c << ":" << e << std::endl;
	return 0;
}


Measured memory_bytes: 3108
def insertionSort(A,n,g):
    global cnt
    for i in range(g,n):
        v = A[i]
        j = i-g
        while j >=0 and A[j] > v:
            A[j+g] = A[j]
            j =j-g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1+3*G[-1])
m =len(G)
G.reverse()
for i in range(m):
    insertionSort(A,n,G[i])

print(m)
print(*G)
print(cnt)
print(*A,sep="\n")


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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; ++i)
    cin >> s[i] >> t[i];
  string X;
  cin >> X;

  int ans = 0;
  bool flag = false;
  for (int i = 0; i < N; ++i) {
    if (flag)
      ans += t[i];
    if (X == s[i])
      flag = true;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int asi[n];
  for(int i=0;i<n;i++){
    cin>>asi[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(asi[0]-asi[1]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(asi[i-1]-asi[i]),dp[i-2]+abs(asi[i-2]-asi[i]));
  }
  cout<<dp[n-1]<<endl;
  return(0);
}


Measured memory_bytes: 1024
num, points_num = list(map(int, input().split(' ')))
points = list(map(int, input().split(' ')))

if num >= points_num:
    print("0")
else:
    points.sort()
    points = list(map(lambda x: [x], points))
    index = 0
    step = 1
    while num < len(points):
        # print(points, index, step)
        if index + 1 >= len(points):
            step = step + 1
            index = 0

        if points[index + 1][0] - points[index][-1] <= step:
            concat_arr = points.pop(index + 1)
            points[index].extend(concat_arr)
        else:
            index = index + 1
    # print(points)
    move_num = sum(list(map(lambda x: x[-1] - x[0], points)))
    print(move_num)

Measured memory_bytes: 17416
n = int(input())
s = []
t = []
for i in range(n):
    temp1,temp2 = input().split()
    s.append(temp1)
    t.append(int(temp2))

x = input()
sum = 0
for i in range(s.index(x)+1,n):
    sum +=t[i]

print(sum)

Measured memory_bytes: 38384
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<sstream>
#include<stack>
#include<map>
#include<vector>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	if (n < 1200)printf("ABC");
	else if (n < 2800)printf("ARC");
	else printf("AGC");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

h = (a.inject(:+).to_f)/n
dif = 10**9
idx = -1
a.each.with_index{|t,i|
  if (t-h).abs < dif
    idx = i
    dif = (t-h).abs
  end
}

p idx

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<vector<int> > A(3, vector<int>(N, 0));
	rep (i, N) cin >> A[1][i];
	rep (i, N){
		A[0][i] = A[1][i] - 1;
		A[2][i] = A[1][i] + 1;
	} // end rep

	int maxN = pow(3,N);
//	cerr << "maxN: " << maxN << endl;

	int res = 0;
	for (int i = 0; i < maxN; ++i){
		int a[N] = {0};
		rep (j, N) a[j] = i;
		rep (j, N){
			rep (k, j){
				a[k] /= 3;
			} // end rep
		} // end rep
/*		
		cerr << i << ':' << ' ';
		rep (j, N){
			cerr << a[j] % 3 << ' ';
		} // end rep
		cerr << endl;
*/
		ll ans = 1LL;
		rep (j, N){
			ans *= (ll)A[a[j] % 3][j];
		} // end rep
		if (ans % 2LL == 0){
			++res;
		} // end if
	} // end for
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define inf 2000000007
using namespace std;

int n;

int Binary_search(int l,int r,int k)
{
	if (l+1==r||l==r)
	{
		if (l*l*l*l*l==k)  return l;
		else if (r*r*r*r*r==k)  return r;
		else return inf;
	}
	int mid=(l+r)>>1;
	if (mid*mid*mid*mid*mid==k)  return mid;
	else if (mid*mid*mid*mid*mid<k)  return Binary_search(mid,r,k);
	else if (mid*mid*mid*mid*mid>k)  return Binary_search(l,mid,k);
}

signed main()
{
	cin>>n;
	for (int i=-6178;i<=6178;i++)
	{
		int a=i,b=Binary_search(-10000ll,10000ll,a*a*a*a*a-n);
		if (b!=inf)  return cout<<a<<' '<<b<<endl,0;
	}
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

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


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> xs;
  function<void(int, int)> dfs_fn = [&](int d, int m) {
    if (d == n) {
      for (int x : xs) {
        cout << static_cast<char>('a' + x);
      }
      cout << endl;
      return;
    }

    for (int k = 0; k < m; k++) {
      xs.push_back(k);
      dfs_fn(d + 1, m);
      xs.pop_back();
    }
    xs.push_back(m);
    dfs_fn(d + 1, m + 1);
    xs.pop_back();
  };
  dfs_fn(0, 0);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define M 500005
#define mod 1000000007
#define inf LLONG_MAX
#include<string>
using namespace std;
ll n,a[100008],dp[100008],k;
ll f(ll i)
{
	if(i>=n-1)
		return 0;
	if(dp[i]==-1)
	{
		dp[i]=INT_MAX;
		ll temp=0;
		for(ll j=i+1;j<=min(n-1,i+k);j++)
		{
			dp[i]=min(dp[i],abs(a[i]-a[j])+f(j));
		}
	}
	return dp[i];
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	for(ll i=0;i<n;i++)
		cin>>a[i];
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 6912
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

vector<int> fall(vector<int> B, vector<int> A){
  int hb = B.size(), ha = A.size();
  B.push_back(0);
  B.push_back(0);
  for(int i = hb; i >= 0; --i){
    bool f = false;
    if(i > 0){
      for(int j = 0; j < ha; ++j){
        if(B[i-1+j]&A[j]){
          f = true;
          break;
        }
      }
    }else{
      f = true;
    }
    if(f){
      for(int j = 0; j < ha; ++j){
        B[i+j] |= A[j];
      }
      while(B.back() == 0) B.pop_back();
      return B;
    }
  }
  assert(false);
  return B;
}

int erase(vector<int>& B){
  vector<int> B_;
  int ret = 0;
  for(auto b : B){
    if(b == 15){
      ++ret;
      continue;
    }
    B_.push_back(b);
  }
  swap(B,B_);
  return ret;
}

// 0 1
// 2 3

int dfs(vector<int> B, const vector<vector<int>>& C, int idx){
  if(idx == C.size()) return 0;

  vector<int> c = C[idx];
  vector<vector<int>> c_(c.size());
  for(size_t i = 0; i < c.size(); ++i){
    for(int j = 0; j < 4; ++j){
      if((c[i]>>j)&1) c_[i].push_back(j);
    }
  }

  int ret = 0;
  int mask_x[] = {5,0,10}, mask_y[] = {3,0,12};
  int dx[] = {-1,0,1}, dy[] = {-2,0,2};
  for(int i = 0; i < 3; ++i){
    {
      bool f = true;
      for(auto e : c){
        if(e&mask_x[i]){
          f = false;
          break;
        }
      }
      if(!f) continue;
    }
    for(int j = 0; j < 3; ++j){
      {
        bool f = true;
        for(auto e : c){
          if(e&mask_y[j]){
            f = false;
            break;
          }
        }
        if(!f) continue;
      }
      vector<int> cc;
      for(auto e : c_){
        int t = 0;
        for(auto ee : e){
          ee += dx[i]+dy[j];
          t |= 1<<ee;
        }
        cc.push_back(t);
      }
      auto B_ = fall(B,cc);
      int ret_ = erase(B_);
      ret_ += dfs(B_,C,idx+1);
      ret = max(ret,ret_);
    }
  }
  return ret;
}

int main(){
  int H, N;
  while(cin >> H >> N, H){
    vector<int> B;
    for(int i = 0; i < H; ++i){
      int t = 0;
      for(int j = 0; j < 2; ++j){
        string s;
        cin >> s;
        for(int k = 0; k < 2; ++k){
          if(s[k] == '#')
            t |= 1<<(j*2+k);
        }
      }
      B.push_back(t);
    }
    vector<vector<int>> C;
    for(int i = 0; i < N; ++i){
      vector<int> b;
      for(int j = 0; j < 2; ++j){
        int t = 0;
        for(int k = 0; k < 2; ++k){
          string s;
          cin >> s;
          for(int l = 0; l < 2; ++l){
            if(s[l] == '#')
              t |= 1<<(k*2+l);
          }
        }
        if(t) b.push_back(t);
      }
      C.push_back(b);
    }
    int ans = dfs(B,C,0);
    cout << ans << endl;
  }
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        int n;
        scanf("%d", &n);
        ll ans = 0;
        for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) for(int k=1; k<=n; k++) {
                ans += std::gcd(i, std::gcd(j, k));
        }
        printf("%ld\n", ans);
}

Measured memory_bytes: 3760
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	if s == "ABC" {
		fmt.Fprintln(writer, "ARC")
		return
	}
	fmt.Fprintln(writer, "ABC")
}


Measured memory_bytes: 1800
import kotlin.random.Random

fun main() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val list = (0 until d).map { readLine()!!.split(" ").map { it.toInt() } }

    fun score(examList: IntArray): Int {
        val executeDate = IntArray(d) { 0 }
        var last = 0
        return (0 until 26).map { date ->
            val exam = examList[date]
            executeDate[exam] = date

            last += list[date][exam] - (0 until 26).map { i ->
                c[i] * (date + 1 - executeDate[i])
            }.sum()

            last
        }.sum()
    }

    var result = IntArray(d) { Random.nextInt(26) }
    var score = score(result)
    repeat(30000) {
        val copy = result.clone()
        copy[Random.nextInt(d)] = Random.nextInt(26)
        val newScore = score(copy)
        if (newScore > score) {
            result = copy
            score = newScore
        }
    }

    result.forEach {
        println(it + 1)
    }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<bool>isfac(N+1,true);
  isfac[0]=false;
  isfac[1]=false;
  for(int i=2;i<=N;i++){
    if(isfac[i])for(int j=i+i;j<=N;j+=i)isfac[j]=false;
  }
  vector<int>fac;
  for(int i=0;i<=N;i++)if(isfac[i])fac.push_back(i);
  map<int,int>m;
  for(int i=1;i<=N;i++){
    for(auto it:fac){
      if(i<it)break;
      int a=i;
      while(a%it==0)a/=it,m[it]++;
    }
  }

  //for(auto it:m)cout<<it.first<<" "<<it.second<<endl;
  //75 = 5*5*3
  //75 = 15*5
  //75 = 25*5
  //75 = 75
  int seventyfour=0;
  int twentyfour=0;
  int fourteen=0;
  int four=0;
  int two=0;
  for(auto it:m){
    if(it.second>=74)seventyfour++;
    if(it.second>=24)twentyfour++;
    if(it.second>=14)fourteen++;
    if(it.second>=4)four++;
    if(it.second>=2)two++;
  }
  ll ans=0;
  //5-5-3
  ans+=(four*(four-1))/2*(two-2);
  //15-5
  ans+=fourteen*(four-1);
  //25-3
  ans+=twentyfour*(two-1);
  //75
  ans+=seventyfour;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def func(S):
	for i in range(1 << 3):
		v = S[0]
		for j in range(3):
			v += ("+" if i >> j & 0x01 else "-") + S[j + 1]
		if eval(v) == 7:
			return v + "=7"

def main():
	print(func(input()))
	#print(func("1222"))
	#print(func("0290"))
	#print(func("3242"))
	return

if __name__ == '__main__':
	main()


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

int n, a, b;
long long ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> a >> b;
	for(int i=1; i<=n; ++i){
		int tmp = 0;
		int t = i;
		while(t > 0){
			tmp += t % 10;
			t /= 10;
		}
		if(a <= tmp && tmp <= b)
			ans += i;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int main(){
      long long int n;cin >> n;
      long long int i = 1;
      long long int ans = 1;
      while(i <= n){
            ans = ans % ((long long int)1e9 + 7) * i;
            i++;
      }
      cout << ans % ((long long int)1e9 + 7);
}

Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n, m;
int u[N], cnta[N];
char c[N];
set < int > g[N], bad;

int main(){
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; ++i){
    scanf(" %c", c + i);
  }
  for(int i = 1; i <= m; ++i){
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].insert(y);
    g[y].insert(x);
  }
  for(int i = 1; i <= n; ++i){
    for(int j : g[i]){
      cnta[i] += (c[j] == 'A');
    }
    if(cnta[i] == 0 || cnta[i] == sz(g[i])){
      bad.insert(i);
      u[i] = 1;
    }
  }
  while(!bad.empty()){
    int v = *bad.begin();
    bad.erase(bad.begin());
    for(int i : g[v]){
      cnta[i] -= (c[v] == 'A');
      g[i].erase(v);
      if(u[i]) continue;
      if(cnta[i] == 0 || cnta[i] == sz(g[i])){
        u[i] = 1;
        bad.insert(i);
      }
    }
    g[v].clear();
  }
  for(int i = 1; i <= n; ++i){
    if(!u[i]){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");

  return 0;
}


Measured memory_bytes: 34432
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N; cin >> N;
	int ans = mod, min;
	int num;
	for (int i = 0; i <= N; i++) {
		min = 0;
		num = i;
		while (num > 0) {
			min += num % 6;
			num /= 6;
		}
		num = N - i;
		while (num > 0) {
			min += num % 9;
			num /= 9;
		}
		if (min < ans) {
			ans = min;
		}
	}
	cout << ans << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> t(N+1, 0), x(N+1, 0), y(N+1, 0);
    for(int i=1; i<=N; i++){
        cin >> t.at(i) >> x.at(i) >> y.at(i);
    }
    
    int dt=0, distance=0;
    bool frag=true;
    
    for(int i=0; i<N; i++){
        dt=t.at(i+1)-t.at(i);
        distance=abs(x.at(i+1)-x.at(i))+abs(y.at(i+1)-y.at(i));
        if(dt<distance){
            frag=false;
            break;
        }
        if((dt-distance)%2==0){
            frag=true;
            continue;
        }else{
            frag=false;
            break;
        }
    }
    
    if(frag==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int d, t, s; cin>>d>>t>>s;
	if(s*t>=d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
 #include <string.h>
   int main() { 
    char befor[8] = "Hoshino";
     char in[1001],*torget; 
    int n;
    scanf("%d\n",&n);
     for(int i = 0; i < n; i++){
         gets(in);
         while( (torget = strstr(in,befor)) != NULL){     
torget += 6;
             *torget = 'a';
         }         printf("%s\n",in);
     }         
return 0; 
} 

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  bool flag = false;
  rep(i, n) {
    cin >> a[i];
    flag |= (i < a[i] || (i && a[i]-a[i-1] > 1));
  }
  if(flag) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  reps(i, 1, n) {
    if(a[i-1]+1 == a[i]) ++ans;
    else ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<int>a;
    rep(i,n)a.push_back(k + i);
    int s = accumulate(a.begin(),a.end(),0);
    int ma = INT_MAX;
    int ans;
    rep(i,n){
        if(abs(a[i]) < ma){
            ma = abs(a[i]);
            ans = s - a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

A, B, C, D = map(int, input())

for op1, op2, op3 in itertools.product([1, -1], [1, -1], [1, -1]):
  if A + op1 * B + op2 * C + op3 * D == 7:
    print('{}{:+}{:+}{:+}=7'.format(A, op1 * B, op2 * C, op3 * D))
    break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

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


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

int main(){
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> p(n,k-q);
  rep(i,q){
    int a;
    cin >> a;
    a--;
    p[a]++;
  }
  rep(i,n){
    if(p[i]>0) puts("Yes");
    if(p[i]<=0) puts("No");
  }
}

Measured memory_bytes: 1024
N, K = list(map(int, input().split()))
A  = list(map(int, input().split()))
MOD = 10**9+7

#　そのブロック内での転倒数
ans1 = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans1 += 1

#　２つのブロック内での転倒数
ans2 = 0
B = sorted(A)
now = B[0]
cnt = 0
for i in range(1,N):
    if now != B[i]:
        cnt = i
        ans2 += cnt
        now = B[i]
    else:
        ans2 += cnt

ans11 = ans1 * K
ans22 = ans2 * (K * (K-1) // 2)
ans = ans11 + ans22
print(ans % MOD)


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

int main(void) {
  int n;
  cin >> n;
  vector<vector<int>> cnt(n, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      cnt[i][s[j] - 'a']++;
    }
  }

  string ans;
  for (int i = 0; i < 26; i++) {
    int mi = INT_MAX;
    for (int j = 0; j < n; j++) {
      mi = min(mi, cnt[j][i]);
    }
    for (int j = 0; j < mi; j++) {
      ans += ('a' + i);
    }
  }

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

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

Measured memory_bytes: 17780