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

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n, m,ans = 0,now=0;

	cin >> n >> m;

	vecll a(m);
	vecbool f(n+1,true);

	forll(i, 0, m)
		cin >> a[i];

	forll(i, 0, m)
	{
		f[a[i]] = false;
	}

	vecll dp(n+1);

	dp[0] = 1;

	forll(i, 0, n)
	{
		forll(j, i+1, min(n+1, i + 3))
		{
			if (f[j])
			{
				dp[j] += dp[i];
				dp[j] %= 1000000007;
			}
		}
	}

	cout << dp[n];

}


Measured memory_bytes: 1792
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1007][1007],t[1007],p[1007];
queue<int>q[2];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
        for(int j=1;j<n;++j)
            cin>>a[i][j];
	for(int i=1;i<=n;++i)
        q[0].push(i);
	int now=1;
	for(int day=1,tot=n*(n-1)/2;day<=n*(n-1)/2;++day){
		now^=1;
		while(!q[now].empty()){
			int x=q[now].front();
            q[now].pop();
			int y=a[x][++t[x]];
			if(p[y]==x){
				tot--;
				q[1-now].push(x);
				q[1-now].push(y);
				p[x]=p[y]=0;
			}
			else
                p[x]=y;
		}
		if(!tot){
			cout<<day<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int dp[2][20020];
const int c=10000;

int main(){
    string s; cin >> s;
    int n=s.size();
    int x,y; cin >> x >> y;
    int first=0;
    for(int i=0;i<n;i++){
        if(s[i]=='F'){
            while(i<n&&s[i]=='F'){
                i++;
            }
            first=i;
            break;
        }
        else break;
    }
    vector<int> nx,ny;
    int now=0;
    for(int i=first;i<n;i++){
        if(s[i]=='T')now^=1;
        else if(s[i]=='F'){
            int cnt=0;
            while(i<n&&s[i]=='F'){
                i++;
                cnt++;
            }
            i--;
            if(now==0)nx.push_back(cnt);
            else ny.push_back(cnt);
        }
    }
    dp[0][c+first]=1;
    for(int ax:nx){
        for(int i=0;i<20020;i++){
            dp[1][i]=0;
        }
        for(int i=0;i<20020;i++){
            if(dp[0][i]){
                dp[1][i+ax]=1;
                dp[1][i-ax]=1;
            }
        }
        for(int i=0;i<20020;i++){
            dp[0][i]=dp[1][i];
        }
    }
    if(dp[0][c+x]==0){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<20020;i++){
        dp[0][i]=0;
    }
    dp[0][c]=1;
    for(int ay:ny){
        for(int i=0;i<20020;i++){
            dp[1][i]=0;
        }
        for(int i=0;i<20020;i++){
            if(dp[0][i]){
                dp[1][i+ay]=1;
                dp[1][i-ay]=1;
            }
        }
        for(int i=0;i<20020;i++){
            dp[0][i]=dp[1][i];
        }
    }
    if(dp[0][c+y]==0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 384
#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 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)

#define ld long double
#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;

int n,U,V;
vector<vi> adj;

vector<pi> save;

void dfs(int v, int par, int dist){
    if (adj[v].size()==1){
        save.emplace_back(v, dist);
    }
    for(auto u:adj[v]){
        if (par!=u){
            dfs(u, v, dist+1);
        }
    }
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>U>>V;
    adj.resize(n+1);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(U,0,0);
    int sz = save.size();

    //青木くんからのbfs
    vi aDist(n+1,1000000);
    aDist[V] = 0;
    queue<int> Q;
    Q.push(V);
    while(Q.size()){
        int v = Q.front(); Q.pop();
        for(auto u:adj[v]){
            if (aDist[u]==1000000){
                aDist[u] = aDist[v]+1;
                Q.push(u);
            }
        }
    }

    int maxi=-1;
    rep(i,sz){
        int v, dist;
        tie(v,dist) = save[i];
        if (aDist[v]>dist && aDist[v]>maxi){
            maxi = aDist[v];
        }
    }
    cout<<maxi-1<<endl;
    return 0;
}


Measured memory_bytes: 9472
import sys
import numpy as np
input = sys.stdin.readline

def convolute(a, b, n, m, M):
    l = 1
    while 2 * l < len(a) + len(b) - 1:
        l *= 2
    l *= 2
    A = np.fft.rfft(a, l)
    B = np.fft.rfft(b, l)
    C = A * B
    c = np.fft.irfft(C, l)
    c = np.rint(c).astype(np.int64)
    return c

def convolute_large(a, b, n, m, M):
    d = 1 << 10
    a1, a2 = np.divmod(a, d*d)
    a2, a3 = np.divmod(a2, d)
    b1, b2 = np.divmod(b, d*d)
    b2, b3 = np.divmod(b2, d)
    aa = convolute(a1, b1, n, m, M) % M
    bb = convolute(a2, b2, n, m, M) % M
    cc = convolute(a3, b3, n, m, M) % M
    dd = (convolute(a1+a2, b1+b2, n, m, M) - (aa+bb)) % M
    ee = (convolute(a2+a3, b2+b3, n, m, M) - (bb+cc)) % M
    ff = (convolute(a1+a3, b1+b3, n, m, M) - (aa+cc)) % M
    h = (((aa*d*d)%M)*d*d + ((dd*d*d)%M)*d + (bb+ff)*d*d + ee*d + cc) % M
    return h

def main():
    n, m = list(map(int, input().split()))  
    a = np.array(input().split(), dtype=np.int64)
    b = np.array(input().split(), dtype=np.int64)

    M = 998244353
    c = convolute_large(a, b, n, m, M)[:n+m-1]
    print(*c)

if __name__ == "__main__":
    main()


Measured memory_bytes: 175724
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int	main()
{
	int	N;
	cin >> N;
	Graph graph(N);
	int	child;
	for (int i = 0; i < N; ++i) {
		cin >> child;
		--child;
		graph.at(i).push_back(child);
	}
	queue<int>	que;
	que.push(0);
	vector<int> dist(N, -1);
	dist.at(0) = 0;
	while (!que.empty()) {
		int	u = que.front();
		que.pop();
		if (u == 1) break;
		for (int v : graph.at(u)) {
			if (dist.at(v) >= 0) continue;
			dist.at(v) = dist.at(u) + 1;
			que.push(v);
		}
	}
	cout << dist.at(1) << endl;
}


Measured memory_bytes: 6144
N = int(input())
W = list(map(int, input().split()))
 
# O(N^2)で解いても間に合う
m = 10**10
for i in range(1, N):
  a, b = 0, 0
  for j in range(i):
    a += W[j]
  for j in range(i, N):
    b += W[j]
  m = min(m, abs(a-b))
print(m)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int w, h;
int c[51][51];
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void dfs(int y, int x){
	c[y][x] = 0;
	for(int i = 0; i < 8; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if(0<=ny and ny<h and 0<=nx and nx<w and c[ny][nx]==1){
			dfs(ny, nx);
		}
	}
}

int solve(){
	int res = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(c[i][j] == 1){
				dfs(i, j);
				res++;
			}
		}
	}

	return res;
}

int main(void){
	while(scanf("%d%d", &w, &h) != EOF){
		if(w == 0 and h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf("%d", &(c[i][j]));
			}
		}
		printf("%d\n", solve());
	}

	return 0;
}



Measured memory_bytes: 3276
#include<stdio.h>
int main(){
  int n,i,j,w,r[300],d[300][2];
  while(scanf("%d",&n),n){
    for(i=0;i<n*2;i+=2){
      scanf("%d %d %d",&w,&d[i][0],&d[i+1][0]);
      d[i  ][1]=w;
      d[i+1][1]=-w;
    }
    d[r[i]=i][0]=2200000000;
    for(i=0;i<n*2;i++){
      r[i]=i;
      for(j=i;j;j--){
	if(d[r[j-1]][0]>d[r[j]][0]){
	  w=r[j-1];
	  r[j-1]=r[j];
	  r[j]=w;
	}
      }
    }
    for(i=w=0;i<n*2;i++){//printf("%d ",d[r[i]][0]);
      while(d[r[i]][0]==d[r[i+1]][0])w+=d[r[i++]][1];
      w+=d[r[i]][1];//printf("%d ",w);
      if(w>150)break;
    }
    if(n*2-i)printf("NG\n");
    else     printf("OK\n");//*/
  }
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

int main(void)
{
	int x;
	int y;
	
	for (x = 1; x <= 9; x++){
		for (y = 1; y <= 9; y++){
			printf("%dx%d=%d\n", x, y, x * y);
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    maxl = -float('inf')
    minr = float('inf')
    for l, r in zip(L, R):
        maxl = max(l, maxl)
        minr = min(r, minr)
    
    return max(0, (minr - maxl + 1))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    result = solve(N, M, L, R)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> D1(N);
  vector<int> D2(N);
  for (int i = 0; i < N; i++) cin >> D1.at(i) >> D2.at(i);
  int count = 0;
  for (int i = 0; i < N; i++){
    if (D1.at(i) == D2.at(i)) count++;
    else count = 0;
    if (count >= 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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


signed main() {
  int N;
  cin >> N;

  vector<int> color(9);
  int rate = 0;
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    cin >> rate;
    if( rate < 400 ){ //灰
      color.at(0)++;
    }else if( 400 <= rate && rate < 800 ){ //茶色
      color.at(1)++;
    }else if( 800 <= rate && rate < 1200 ){ //緑
      color.at(2)++;
    }else if( 1200 <= rate && rate < 1600 ){ //水
      color.at(3)++;
    }else if( 1600 <= rate && rate < 2000 ){ //青
      color.at(4)++;
    }else if( 2000 <= rate && rate < 2400 ){ //黄
      color.at(5)++;
    }else if( 2400 <= rate && rate < 2800 ){ //橙
      color.at(6)++;
    }else if( 2800 <= rate && rate < 3200 ){ //赤
      color.at(7)++;
    }else if( 3200 <= rate ){ //自由色
      color.at(8)++;
    }
  }
  
  for( int i = 0; i < 8; i++ ){
    if( color.at(i) > 0 ) ans++;
  }
  
  if( color.at(8) == 0 ){
    cout << ans << " " << ans << endl;
  }else{ //自由色がいる場合
    if( ans == 0 ){ //もし全員自由色だったら
      cout << 1 << " " << N << endl;
    }else{
      cout << ans << " " << ans + color.at(8) << endl;
    }
  }
        
      
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,j;
    vector<bool> table(100000001,true);
    table[0]=false;
    table[1]=false;
    for(j=4;j<100000001;j+=2)
        table[j]=false;
    for(i=3;i<100000001;i+=2){
        if(table[i]){
            for(j=2*i;j<100000001;j+=i)
                table[j]=false;
        }
    }
    int n,ans=0,x;
    cin>>n;
    for(i=0;i<n;++i){
        cin>>x;
        if(table[x])
            ans++;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 14808
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 3448
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
  char name[21];
  int sc;
  int input;
}score;
int cmp(const void *a,const void *b){
  int c=(*(score *)b).sc-(*(score *)a).sc;
  return c?c:(*(score *)a).input-(*(score *)b).input;
}
int main(){
  int i,n,win,lose,draw,fa;
  char name[21];
  score ss[10];
  fa=1;
  do{
    scanf("%d",&n);
    if(!n) break;
    if(!fa){
      printf("\n");
    }
    for(i=0;i<n;i++){
      scanf("%s %d %d %d",name,&win,&lose,&draw);
      strcpy(ss[i].name,name);
      ss[i].sc=win*3+draw;
      ss[i].input=i;
    }
    qsort(ss,n,sizeof(score),cmp);
    for(i=0;i<n;i++) printf("%s,%d\n",ss[i].name,ss[i].sc);
    fa=0;
  }while(1);
  return 0;
}

Measured memory_bytes: 0
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S, T = input().split()
    A, B = map(int, readline().split())
    U = input()

    if S == U:
        A -= 1
    if T == U:
        B -= 1
    print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61876
#include<iostream>
#include<string>
using namespace std;
char T[1000000]; int length = 500000, n; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < 1000000; i++) {
			T[i] = ' ';
		}
		length = 500000;
		cin >> S;
		for (int i = 0; i <= S.size() / 3; i++) {
			T[length] = S[i * 3];
			if (S.size() != i) {
				if (S[i * 3 + 1] == '-') {
					length++;
				}
				else {
					length--;
				}
			}
		}
		for (int i = 0; i < 1000000; i++) {
			if (T[i] != ' ') {
				cout << T[i];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 2172
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    int L[20];
    for (int i = 0; i < N; i++){
        cin >> L[i];
    }
    sort(L, L + N);
    int total = 0;
    for (int i = 0; i < N -1; i++){
        total += L[i];
    }
    if (total > L[N - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top,S[1000];
 
void push(int x)
{
  S[++top] = x;
}
 
int pop()
{
  top--;
  return S[top+1];
}
 
int main()
{
  int a,b;
  top = 0;
  char s[100];
 
  while(scanf("%s",s) != EOF)
{
    if(s[0] == '+')
{
      a=pop();
      b=pop();
      push(a+b);
    }
 
    else if(s[0] == '-')
{
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0] == '*')
{
      a=pop();
      b=pop();
      push(a*b);
    }
else
{
      push(atoi(s));
  }
}
 
printf("%d\n",pop());
 
return 0;
 
}

Measured memory_bytes: 548
N = int(input())
S = [input() for i in range(N)]

d = {"AC":0, "WA":0, "TLE":0, "RE":0}
for s in S:
    d[s] += 1

print("AC x " + str(d["AC"]))
print("WA x " + str(d["WA"]))
print("TLE x " + str(d["TLE"]))
print("RE x " + str(d["RE"]))

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

long long sum[100010];
long long K[2010];

int N,M,L;
long long f(int a,int b){
	return (sum[max(a,b)] - sum[min(a,b)-1]) / L;
}

long long dp[2010][2010];
long long dfs(int x,int y){
	int z = max(x,y);
	if( z == N-2 ){
		return f(K[N-1],K[x]) + f(K[N-1],K[y]);
	}
	if( dp[x][y] != -1 ) return dp[x][y];
	long long ans = 1e18;
	ans = min(dfs(z+1,y)+f(K[x],K[z+1]),dfs(x,z+1)+f(K[y],K[z+1]));
	return dp[x][y] = ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin >> N >> M >> L;
	for(int i = 0 ; i < N ; i++) cin >> K[i];
	for(int i = 1 ; i <= M ; i++){
		cin >> sum[i];
		sum[i] += sum[i-1];
	}
	sort(K,K+N);
	cout << dfs(0,0) << endl;
}

Measured memory_bytes: 33668
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}	
char mem[114514];
char t[114514];
int a[114514];
int ans[114514];
signed main(){
	ic(n) 
	sc(s)
	int ans=0;
	rep(0,i,n-2){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
	}
	c(ans)
}		

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll H, W, N;
    cin >> H >> W >> N;
    vector < pair<int,int> > vec;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                if (a+j>0 && a+j<H-1 && b+k>0 && b+k<W-1) {
                    vec.push_back(make_pair(a+j, b+k));
                }
            }
        }
    }

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

    ll ans[10];
    fill(ans, ans+10, 0LL);
    int c = 0;
    while (c < vec.size()) {
        int count = 1;
        int x = vec[c].first;
        int y = vec[c].second;
        c++;

        while (vec[c].first == x && vec[c].second == y) {
            count++;
            c++;
            if (c == vec.size()) break;
        }

        ans[count]++;
    }

    ans[0] = 1LL * (H-2) * (W-2);
    for (int i = 1; i < 10; i++) {
        ans[0] -= ans[i];
    }

    for (int i = 0; i < 10; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll MOD = 1000000007;

ll dp[2010][2010];

void solve() {
    ll n;
    cin >> n;
    vector<pair<ll, ll>> a;

    for (ll i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        a.push_back(make_pair(x, i));
    }

    memset(dp, 0, sizeof(dp));
    sort(a.rbegin(), a.rend());

    for (ll l = 0; l < n; ++l) {
        for (ll r = n - 1; r >= l; --r) {
            ll ind = l + (n - 1 - r);  //calculating the index of the element in sorted array for particular l and r;
            ll val = a[ind].first;
            ll pos = a[ind].second;
            ll d1 = val * abs(pos - l);
            ll d2 = val * abs(pos - r);
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + d1);  //moving the element to left
            if (r - 1 >= 0)
                dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + d2);  //moving the element to right
        }
    }

    ll ans = 0;
    for (ll i = 0; i <= n; ++i) {
        for (ll j = 0; j <= n; ++j) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << "\n";
}

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

    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin >> t;

    // while (t--)
    solve();

    return 0;
}


Measured memory_bytes: 35280
#include <bits/stdc++.h>
#define SIZE 3005
#define MOD 998244353
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll dp[SIZE][SIZE];
int main()
{
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	for(int i=A;i<=C;i++)
	{
		for(int j=B;j<=D;j++)
		{
			if(i==A&&j==B) dp[i][j]=1; 
			else if(i==A) dp[i][j]=dp[i][j-1]*(ll) A%MOD;
			else if(j==B) dp[i][j]=dp[i-1][j]*(ll) B%MOD;
			else
			{
				dp[i][j]+=dp[i-1][j]*(ll) j;
				dp[i][j]+=dp[i][j-1]*(ll) i;
				dp[i][j]%=MOD;
				dp[i][j]-=dp[i-1][j-1]*(ll) (i-1)*(ll) (j-1)%MOD;
				if(dp[i][j]<0) dp[i][j]+=MOD;
			}
		}
	}
	printf("%lld\n",dp[C][D]);
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
constexpr int inf = 1LL<<60;

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

  vi a(m), b(m), c(m);
  rep(i, 0, m){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
  }

  vi d(n, inf);
  d[0] = 0;

  rep(i, 0, n) rep(j, 0, m){
    if(d[a[j]] == inf) continue;
    if(d[b[j]] > d[a[j]] - c[j]){
      d[b[j]] = d[a[j]] - c[j];
    }
  }

  int ans = -d[n-1];
  vector<bool> vis(n, false);

  rep(i, 0, n) rep(j, 0, m){
    if(d[a[j]] == inf) continue;
    if(d[b[j]] > d[a[j]] - c[j]){
      d[b[j]] = d[a[j]] - c[j];
      vis[b[j]] = true;
    }
    if(vis[a[j]]) vis[b[j]] = true;
  }

  if(vis[n-1]) cout << "inf" << endl;
  else cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int m=scanner.nextInt();
		System.out.println((int)Math.pow(2, m)*(1900*m+(n-m)*100));
	}
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21204
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;


int main(){
	int N;
	scanf("%d",&N);

	int table[N][N];

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			if(i != k){
				table[i][k] = BIG_NUM;
			}else{
				table[i][k] = 0;
			}
		}
	}

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

	ll ans = 0;

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			ans += min(table[i][k],table[k][i]);
		}
	}

	printf("%lld\n",ans);

}

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

using namespace std;

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

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

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

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

int main() {
  vector<int>x(8);
  int cnt=0;
  for(int i=1;i<=6;i++){
    cin>>x[i];
    if(x[i]==0){
      cout<<i<<endl;
                break;
    }
  }
}

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

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

    int ans = 0;
    for (int cut = 1; cut < n; cut++) {
        set<char> cmn;
        for (int i = 0; i < cut; i++) {
            for (int j = cut; j < n; j++) {
                if (s[i] == s[j]) cmn.insert(s[i]);
            }
        }
        ans = max(ans, (int)cmn.size());
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n; cin >> n;
    int S[n];
    for(int i=0;i<n;++i) cin >> S[i];
    int q; cin >> q;
    int T[q];
    for(int j=0;j<q;++j) cin >> T[j];
    int C=0;
    for(int k=0;k < q; ++k)
    {
        if(binary_search(S,S+n,T[k])) C++;
    }
    cout << C << endl;
    return 0;
}


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

#define fori( tt,aa)      for(long long i= tt; i<aa; i++)
#define forj( yy,bb)      for(long long j=yy; j<bb; j++)
#define fork( uu,cc)      for(long long k=uu; k<cc; k++)
#define sz(v)    v.size()
#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define EPS 1e-7
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE; fast();

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string String;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
}

ld pow (ll a, ll b);
ll numOfDigits(ll n);
ll BN (ll arr[], ll j, ll val);
int main()
{

    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\Points on Line.txt", "r", stdin);
    int n; cin>>n;
    map<int, int> mp;
    fori(0, n){
        int a; cin>>a;
        mp[a] = (i+1);
    }
    fori(1, n+1)
    cout<<mp[i]<<" ";
    return 0;
}
ld pow (ll a, ll b){
    ld pow = 1;
    fori(0,b)
        pow *=a;
    return pow;
}
/*
ll BN (ll arr[], ll j, ll val){
int low = j;
int up = n-1;
ll ans = -1;
while(low<=up){
    ll mid = ((ll)low+ up)/2;
    if(abs(arr[mid]-val)<=d){
        ans = mid;
        low = mid+1;
    }else up = mid-1;
}
return ans;
}*/

ll numOfDigits(ll n){
    if(!n) return 1;
    return (ll)(log10(n)+1);
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf1 INT_MAX
#define inf2 LLONG_MAX
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sbit __builtin_popcount
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define rit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define fill(a,b) memset(a,b,sizeof(a))
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define infile ifstream fin; fin.open("input.txt")
#define outfile ofstream fout; fout.open("output.txt")
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<ll,int>
#define pll pair<ll,ll>
#define p_queue priority_queue< plii,vector< plii >,greater< plii > > 
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%lld",&x)
#define sst(x) scanf("%s",x)
#define pl(x) printf("%lld\n",x)
#define pi(x) printf("%d\n",x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mex 100005

inline ll binex(ll a,ll b)
{
    ll ans=1,temp=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b=b>>1;
    }
    return ans;
}

inline int solve(int n,ll w,ll wt[],ll val[])
{
    ll dp[mex][n];
    rep(i,0,n) dp[0][i]=0;
    rep(i,1,mex) dp[i][0]=inf1; dp[val[0]][0]=wt[0];
    rep(i,1,mex){
        rep(j,1,n){
            if(val[j]<=i) dp[i][j]=min(dp[i][j-1],wt[j]+dp[i-val[j]][j-1]);
            else dp[i][j]=dp[i][j-1];
        }
    }
    
    /*rep(i,0,15){
        rep(j,0,n) cerr<<dp[i][j]<<" "; cerr<<endl;
    }*/
    
    repr(i,mex-1,0){
        if(w>=dp[i][n-1]) return i;
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; ll w; cin>>n>>w;
    ll val[n],wt[n];
    rep(i,0,n) cin>>wt[i]>>val[i];
    cout<<solve(n,w,wt,val)<<endl;
}

Measured memory_bytes: 78336
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String ring = sc.nextLine();
        String p = sc.nextLine();
        ring += ring;
        if(ring.contains(p)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 26076
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)

l = -1     #スコアが絶対この値より大きくなる数値から始める。
r = 10**13 #スコアが絶対この値より小さくなる数値から始める。
while(l+1<r):
  m = (l+r)//2
  t = 0
  for i in range(N):
    t += max(A[i]-m//F[i],0)
  #print(l,m,r,t)
  if t <= K:
    r = m
  else:
    l = m
print(r)


Measured memory_bytes: 121036
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	scanf("%lld",&n);
	ll sum=0;
	sum=n*(n+1)/2;
	ll n1=n/3;
	sum-=3*(n1+1)*n1/2;
	n1=n/5;
	sum-=5*(n1+1)*n1/2;
	n1=n/15;
	sum+=15*(n1+1)*n1/2;
	printf("%lld",sum);
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll a, b; cin >> a >> b;
    (a+b) % 2 ? cout << "IMPOSSIBLE" : cout << (a+b)/2;
}


Measured memory_bytes: 256
def count(S):
    p = 0
    res = 0
    for s in S:
        if s == '0':
            p += 1
        else:
            res += p
    return res

S = input().strip()
a = '0'
b = 1
bc = '1'
x = '2'
T = ''
stack = []
for s in S:
    if s == 'A':
        if stack:
            T += x
        stack = []
        T += a
    elif s == 'B':
        stack.append(b)
    elif s == 'C':
        if stack and stack[-1] == b:
            stack.pop()
            if stack:
                T += x
            T += bc
        else:
            stack.append(x)
ans = 0
for g in T.split(x):
    ans += count(g)
print(ans)

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



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

    int r;
    cin >> r;
    cout << 3*r*r << endl;



}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {

	sc.Scan()
	return sc.Text()
}

func rev(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func main() {
	sc.Split(bufio.ScanWords)

	s := nextString()

	n := len(s)

	var s2 string
	var s3 string

	s2 = s[0 : (n-1)/2]
	s3 = s[(n+3)/2-1 : n]

	//fmt.Println(rev(s))
	//fmt.Println(rev(s2))
	//fmt.Println(rev(s3))

	if s == rev(s) && s2 == rev(s2) && s3 == rev(s3) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int INF=0x3f3f3f3f;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
struct edge{
	int to,nxt,cap,flow;
}e[30005];
int a[105],last[105],cur[105],dis[105],S,T,n,cnt=1;
ll min(ll x,ll y) {return x<y?x:y;}
void insert(int u,int v,int w)
{
	e[++cnt]=(edge){v,last[u],w,0};
	last[u]=cnt;
}
int bfs()
{
	queue<int> q;
	for(int i=1;i<=n+2;i++) dis[i]=INF;
	dis[S]=0;q.push(S);
	while(q.size())
	{
		int x=q.front();q.pop();
		for(int i=last[x];i;i=e[i].nxt)
		if(e[i].cap>e[i].flow&&dis[e[i].to]==INF)
		{
			dis[e[i].to]=dis[x]+1;
			q.push(e[i].to);
		}
	}
	return dis[T]!=INF;
}
ll dfs(int x,ll low)
{
	if(x==T||low==0) return low;
	ll ret=0,st;
	for(int i=cur[x];i;i=e[i].nxt)
	{
		cur[x]=i;
		if(dis[e[i].to]==dis[x]+1&&(st=dfs(e[i].to,min(low,e[i].cap-e[i].flow)))>0)
		{
			ret+=st,low-=st;
			e[i].flow+=st,e[i^1].flow-=st;
			if(!low) break;
		}
	}
	return ret;
}
ll dinic()
{
	ll ret=0;
	while(bfs())
	{
		for(int i=1;i<=n+2;i++) cur[i]=last[i];
		ret+=dfs(S,INF);
	}
	return ret;
}
ll ans;
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	S=n+1;T=n+2; 
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0) ans+=a[i],insert(i,T,a[i]),insert(T,i,0);
		else insert(S,i,-a[i]),insert(i,S,0);
	}
	for(int i=1;i<n;i++)
		for(int j=2;j<=n/i;j++)
		{
			insert(i,i*j,a[i*j]);
			insert(i*j,i,0);
		}
	ans-=dinic();
	printf("%lld\n",ans);
	return 0;
}

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

int main(void){
  int a, l;
  int i, j, k;
  int king, kingpoint, flag;
  int rank[10], past[30];
  char max[10], min[10];

  while(1){
    scanf("%d %d", &a, &l);
    if(a + l == 0){ break; }
    past[0] = a;
    for(i = 1;; ++i){
      // テ、ツクツ?ヲツ。ツ?」ツ?氾」ツ?ィテ」ツ?ォテ・ツ按?・ツ可イ
      for(j = 0; j < l; ++j){
	rank[j] = a%10;
	a /= 10;
      }

      // テヲツ。ツ?ヲツ閉ーテ・ツ按?ァツケツーテ」ツつ甘ィツソツ氾」ツ??
      for(j = 0; j < l; ++j){
	king = 0;
	// テヲツ慊?・ツ、ツァテ・ツ?、テ」ツつ津ヲツアツづ」ツつ?」ツつ?
	for(k = 0; k < l; ++k){
	  if(king < rank[k]){
	    king = rank[k];
	    kingpoint = k;
	  }
	}

	// テヲツ慊?・ツ、ツァテ・ツ?、テ」ツつ津ゥツ?ゥテ・ツ按?」ツ?ェテヲツ。ツ?」ツ?ォテ、ツサツ」テ・ツ?・
	max[j] = min[l - j - 1] = king + '0';
	rank[kingpoint] = 0;
      }
      // テァツオツづァツォツッテヲツ鳴?・ツュツ療」ツつ津、ツサツ」テ・ツ?・
      max[l] = min[l] = '\0';
      
      // テヲツ閉ーテ・ツ?、テ」ツ?ォテ・ツ、ツ嘉ヲツ渉?
      a = atoi(max) - atoi(min);

      flag = 0;
      for(j = 0; j < i; j++){
	if(past[j] == a){
	  // テ・ツ?コテ・ツ環?
	  printf("%d %d %d\n", j, a, i - j);
	  flag = 1;
	  break;
	}
      }
      past[i] = a;
      if(flag == 1){ break; }
    }
  }

  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//なんこれ？

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;

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


	int N = getint();
	int X[200000], X2[200000];
	rep(i, N) X[i] = getint();
	memcpy(X2, X, sizeof(X));

	//int L = 0;
	//int R = 1e9 + 1;
	//while (L < R) {
	//	int H = (L + R) / 2;
	//	int k = 0;
	//	rep(i, N) k += X[i] <= H;
	//	if (k < N / 2) L = H + 1;
	//	else R = H;
	//}
	//int L2 = L;
	//int R2 = 1e9 + 1;
	//while (L2 < R2) {
	//	int H = (L2 + R2) / 2;
	//	int k = 0;
	//	rep(i, N) k += X[i] <= H;
	//	if (k < N / 2 + 1) L2 = H + 1;
	//	else R2 = H;
	//}

	nth_element(X, X + N / 2, X + N);
	nth_element(X, X + N / 2 - 1, X + N / 2);
	int L = X[N / 2 - 1];
	int L2 = X[N / 2];
	int K = L;
	int keta1 = 0, keta2 = 0;
	char C1[10], C2[10];
	while (L) {
		*(C1 + keta1) = '0' + L % 10;
		L /= 10;
		keta1++;
	}
	while (L2) {
		*(C2 + keta2) = '0' + L2 % 10;
		L2 /= 10;
		keta2++;
	}

	rep(i, N) {
		if (X2[i] > K) {
			for (int i = keta1 - 1; i >= 0; i--)* di++ = (*(C1 + i));
			*di++ = '\n';
		}
		else {
			for (int i = keta2 - 1; i >= 0; i--)* di++ = (*(C2 + i));
			*di++ = '\n';
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	if(n<4)
	{
		cout<<"No\n";
		return 0;
	}
	if(s.substr(0,4)=="YAKI")
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

ll mod(ll x) {
    x %= MOD;
    if (x < 0) { x += MOD; }
    return x;
}

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

    string L;
    cin >> L;

    ll X = 0, Y = 1;
    for (char c : L) {
        if (c == '1') {
            X = mod(mod(3 * X) + Y);
            Y = mod(2 * Y);
        } else {
            X = mod(3 * X);
        }
    }
    cout << mod(X + Y) << endl;

    return 0;
}

Measured memory_bytes: 512
import math
K=int(input())
ans=0
for i in range(1,K+1):
    ans += i

for i in range(1,K):
    for j in range(i+1,K+1):
        ans += math.gcd(i,j)*6
        
for i in range(1,K-1):
    for j in range(i+1,K):
        for k in range(j+1,K+1):
            ans += math.gcd(i,math.gcd(j,k))*6
print(ans)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#include <array>
#include <bitset>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int a, b;
	CI a >> b;

	CO 6 - a - b EN;

	return 0;

}

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

using namespace std;
using ll=long long;

#define rep(i, a, n) for (int i = (a); i < (n); ++i)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;cin>>s;
  string ans;

  rep(i,0,s.size()){
    if(s[i] == '0') ans += '0';
    else if(s[i] == '1') ans += '1';
    else{
      if(!ans.empty()) ans.pop_back();//空文字でなければ
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
    char X, Y;
    cin >> X >> Y;
    if (X == Y) cout << "=" << endl;
    else if (X < Y) cout << "<" << endl;
    else if (X > Y) cout << ">" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
typedef pair<int,int> P;

int N;
int main(){
    cin >> N;
    vector<int> v(N);
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    if(N==2){
        cout << v[1]-v[0] << endl;
        cout << v[1] << " " << v[0] << endl;
        return 0;
    }
    if(v[0]>=0){
        int sum = 0;
        for(int i=0;i<N;i++){
            if(i==0) sum -= v[i];
            else sum += v[i];
        }
        cout << sum << endl;
        int now = v[1];
        for(int i=1;i<N;i++){
            if(i==1){
                cout << v[0] << " " << v[1] << endl;
                now = v[0]-v[1];
            }else if(i!=N-1){
                cout << now << " " << v[i] << endl;
                now = now-v[i];
            }else{
                cout << v[i] << " " << now << endl;
                now = v[i]-now;
            }
        }
        assert(sum==now);
    }else if(v[N-1]<=0){
        int sum = 0;
        for(int i=0;i<N;i++){
            if(i==N-1) sum += v[i];
            else sum -= v[i];
        }
        cout << sum << endl;
        int now = 0;
        for(int i=N-2;i>=0;i--){
            if(i==N-2){
                cout << v[N-1] << " " << v[N-2] << endl;
                now = v[N-1]-v[N-2];
            }else{
                cout << now << " " << v[i] << endl;
                now = now-v[i];
            }
        }
        assert(sum==now);
    }else{
        int sum = 0,id = -1;
        for(int i=0;i<N;i++){
            if(v[i]<0) sum -= v[i];
            else{
                sum += v[i];
                if(id==-1) id = i;
            }
        }
        cout << sum << endl;
        if(id==N-1){
            int now = v[N-1];
            for(int i=0;i<N-1;i++){
                cout << now << " " << v[i] << endl;
                now = now-v[i];
            }
            assert(sum==now);
        }else{
            int now = v[0];
            for(int i=id;i<N-1;i++){
                cout << now << " " << v[i] << endl;
                now = now-v[i];
            }
            cout << v[N-1] << " " << now << endl;
            now = v[N-1]-now;
            for(int i=1;i<id;i++){
                cout << now << " " << v[i] << endl;
                now = now-v[i];
            }
            assert(sum==now);
        }
    }
}

Measured memory_bytes: 2304
#include<stdio.h>
	int main()
{
	int b[100]={0}, c[100]={0}, a[100][100]={0}, m, n, i, j;
	scanf("%d %d", &n, &m);
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			scanf("%d", &a[i][j]);
		}
	}
	
	for(i = 0; i < m; i++){
		scanf("%d", &b[i]);
	}
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			c[i] += a[i][j] * b[j];
		}
	}	
	
	for(i = 0; i < n; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string S;
    cin >> S;
    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[200010], F[200010];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A, A + N);
    sort(F, F + N, greater<int>());
    int ok = INF2;
    int ng = -1;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        int cnt = 0;
        rep(i, N) {
            int cost = F[i] * A[i];
            if(cost < mid) continue;
            int lack = cost - mid;
            cnt += (lack + F[i] - 1) / F[i];
            if(cnt > K) break;
            
        }
        //cerr << mid << " " << cnt << endl;
        if(cnt <= K) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 6772
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for r in range(m):
    b.append(int(input()))
 
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

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

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

    vector<int> a(m, 0);
    int tmp, type;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        for (int j = 0; j < tmp; j++) {
            cin >> type;
            a.at(type-1)++;
        }
    }

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

    cout << cnt << endl;

    return 0;
}


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

int main() {
	int a, b, c, d, p; cin >> a >> b >> c >> d >> p;
	cout << min(p*a, b + max(p - c, 0)*d) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstdio>

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

int main(){

    bool exist = true;
    //bool match = true;
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    //cout << s << endl;

    string a("maerd");
    string b("remaerd");
    string c("esare");
    string d("resare");
    //cout << a << endl;
    
    for(int i = 0;i < s.length();){
        //cout << i << endl;
        if(i == s.length()){
            break;
        }
        if(s.substr(i,5) == a){
            i+=5;
        }else if(s.substr(i,7) == b){
            i+=7;
        }else if(s.substr(i,5) == c){
            i+=5;
        }else if(s.substr(i,6) == d){
            i+=6;
        }else{
            exist = false;
            break;
        }
    }

    if(exist){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 512