akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

const int MV = 1003;
const int ME = 200005;

int n, m;
vector<int> v[MV];
int frm[ME], tar[ME];
int way1[MV][MV], way2[MV][MV], dir[MV][MV];

void input()
{
	read(n), read(m);
	for(int i=1; i<=m; i++)
	{
		read(frm[i]), read(tar[i]);
		dir[frm[i]][tar[i]]++;
		v[frm[i]].push_back(tar[i]);
	}
}

bool ban[MV];

void dfs(int x, int *s)
{
	for(auto y : v[x])
		if(!s[y] && !ban[y])
		{
			s[y]++;
			dfs(y, s);
		}
}

void work()
{
	for(int x=1; x<=n; x++)
	{
		ban[x] = 1;
		for(int i=0; i<v[x].size(); i++) ban[v[x][i]] = 1, dfs(v[x][i], way1[x]), ban[v[x][i]] = 0;
		for(int i=v[x].size()-1; i>=0; i--) ban[v[x][i]] = 1, dfs(v[x][i], way2[x]), ban[v[x][i]] = 0;
		ban[x] = 0;
	}
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			dir[i][j] += way1[i][j]+way2[i][j];
	for(int i=1; i<=m; i++)
	{
		int a = frm[i], b = tar[i];
		if(dir[a][b]==1 && !dir[b][a]) puts("same");
		else if(dir[a][b]>=2 && !dir[b][a]) puts("diff");
		else if(dir[a][b]==1 && dir[b][a]) puts("diff");
		else if(dir[a][b]>=2 && dir[b][a]) puts("same");
	}
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 16128
A = int(input())
B = int(input())
C = int(input())
X = int(input())

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: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      int ans = 0;
      for (int i = 0; i < n; i++) {
        int a = scanner.nextInt();
        ans += --a;
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}

Measured memory_bytes: 26032
#include<bits/stdc++.h>
using namespace std;
int sum(int number){
   int result=0;
   while(number>0){
      result+=number%10;
      number=number/10;
   }
   return result;
}
int main(void){
   int N;
   cin>>N;
   if(N%sum(N)==0) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}



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

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

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

	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				cout<<" "<<house[i][j][k];
			}
			cout<<endl;
		}
		if(i != 3) cout<<"####################"<<endl;
	}

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N-1);
    int i;
    for(i=0; i<N-1; i++){
        cin >> B.at(i);
    }

    A.at(0)=B.at(0);
    for(i=1; i<N-1; i++){
        A.at(i)=min(B.at(i-1),B.at(i));
    }
    A.at(N-1)=B.at(N-2);

    int ans=0;
    for(i=0; i<N; i++){
        ans+=A.at(i);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,a,i,p;
    scanf("%d",&n);
    int v[n+1],x[n+1];

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

    }

    for(i=0; i<n; i++)
    {
        x[i]=v[i];


    }
    sort(x,x+n);


    for(i=0; i<n; i++)
    {
        if(x[n-1]>v[i])
            p=x[n-1];
        else
            p=x[n-2];
        printf("%d\n",p);
    }
    return 0;

}


Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int H,W;
int c[11][11];
int A[201][201];
int dist[10]={};



int main(){
	
	cin >> H >> W;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin >> c[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				c[j][k] = min(c[j][k],c[j][i] + c[i][k]);
			}
		}
	}
	
	int answer=0;
	for(int i=0;i<H;i++){
		for(int j = 0;j<W;j++){
			if(A[i][j] == -1 || A[i][j] == 1){
				continue;
			}else{
				answer += c[A[i][j]][1];
			}
		}
	}
	
	cout << answer << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,max_num=-100000001,min_num=100000001,tmp;
	long sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		sum += tmp;
		max_num = max(max_num,tmp);
		min_num = min(min_num,tmp);
	}
	printf("%d %d %lld\n",min_num,max_num,sum);
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

const int MAX = 510000;
const int P = 1000000007; //shuoud be prime

long long fac[MAX], finv[MAX], inv[MAX];

void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % P;
        inv[i] = P - inv[P%i] * (P / i) % P;
        finv[i] = finv[i - 1] * inv[i] % P;
    }
}

long long COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % P) % P;
}

LL N;
vector<LL> A;
map<LL, int> M;
int al, ar;
LL a;

LL f(LL k){
	LL ret = 0;
	if(k == 1){
		ret = N;
		return (ret%P);
	}
	if(k == N+1){
		return 1LL;
	}
	if(k == N){
		ret = N + 1 -2;
		if(ar - al == 1){
			ret += 1;
		}
		else if(ar - al > 1){
			ret += 2;
		}
		return (ret%P);
	}

	ret = COMB(N-1, k);

	if(k > 2){
		ret += COMB(N-1, k-2);
	}
	else{
		ret++;
	}
	ret %= P;

	if(ar - al == 1){
		ret += COMB(N-1, k-1);
		ret %= P;
	}
	else{
		LL s = COMB((N+1-ar) + al - 1, k-1);
		LL t = COMB(N-1, k-1) - s;
		t %= P;
		if(t < 0){
			t += P;
		}
		ret += (s + 2*t);
	}
	return (ret%P);
}

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


	COMBinit();

	cin >> N;
	for(int i=0; i<N+1; i++){
		LL u;
		cin >> u;
		A.push_back(u);
		if(M.count(u) == 0){
			M[u] = i;
		}
		else{
			al = M[u];
			ar = i;
			a = u;
		}
	}

	for(LL i = 1; i<=N+1; i++){
		LL w = f(i);
		printf("%lld\n", w);
	}
	return 0;
}


Measured memory_bytes: 22196
#include <bits/stdc++.h>
 
int main()
{
  int num_mozi=0;
 std::cin >> num_mozi;
 std::string a;
 std::cin >> a;
  if(a.length()>num_mozi)
  {
    a=a.substr(0,num_mozi);
    a+="...";
  }
  
  std::cout <<a;
  
  return 0;
}

Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C070
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long gcm=1;
            for (int i = 0; i < N; i++)
            {
                long T = long.Parse(Console.ReadLine());
                if (i == 0) gcm = T;
                else gcm = GetLeastCommonMultiple(gcm, T);
            }
            Console.WriteLine(gcm);
        }

        //最大公約数(Euclid互除法:O(log n)
        public static long GetGreatestCommonFactor(long x, long y)
        {
            while (x > 0 && y > 0)
            {
                if (x > y)
                {
                    x %= y;
                }
                else
                {
                    y %= x;
                }
            }
            return Math.Max(x, y);
        }

        //最小公倍数
        public static long GetLeastCommonMultiple(long x, long y)
        {
            long gcf = GetGreatestCommonFactor(x, y);
            long zz = y / gcf;
            return x * zz;
        }


    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void print_vector(const vector<int>& array)
{
    for (int i = 0; i < array.size(); i++){
        if (i >= 1){
            cout << " ";
        }

        cout << array[i];
    }
    cout << endl;
}

vector<int> insertion_sort(const vector<int>& array)
{
    // 配列のコピー
    vector<int> a = vector<int>(array.size());
    copy(array.begin(), array.end(), a.begin());

    // 配列を表示
    print_vector(a);

    int n = a.size();
    for (int i = 1; i < n; i++){
        int buf = a[i];

        int j;
        for (j = i - 1; j >= 0 && a[j] > buf; j--) a[j + 1] = a[j];
        a[j + 1] = buf;

        // 配列を表示
        print_vector(a);
    }

    return a;
}

int main()
{
    int n;
    vector<int> a;

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

    insertion_sort(a);

    return 0;
}



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

const int MAX_VACANCE= 100005;

int activite[MAX_VACANCE][3];
long long dp[MAX_VACANCE][3];

int nJour;

void init()
{
    scanf("%d", &nJour);
    for(int iJour = 0; iJour < nJour; iJour++)
    {
        scanf("%d %d %d", &activite[iJour][0], &activite[iJour][1], &activite[iJour][2]);
    }
}

int main()
{
    init();
    for(int iJour = 1;iJour <= nJour; iJour++)
    {
        dp[iJour][0] = max(dp[iJour-1][1],dp[iJour-1][2]) + activite[iJour-1][0];
        dp[iJour][1] = max(dp[iJour-1][0],dp[iJour-1][2]) + activite[iJour-1][1];
        dp[iJour][2] = max(dp[iJour-1][0],dp[iJour-1][1]) + activite[iJour-1][2];
    }
    printf("%lld", max(max(dp[nJour][0],dp[nJour][1]),dp[nJour][2]));
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
//typedef pair< ll , string > P;

 int main(){
   int n;
   cin>>n;
   cout<<((n%2==0)?(n/2):(n/2+1));
 }

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

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

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

  int n,k; cin >> n >> k;
  vector<int> a(n);
  int mx = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    mx = max(mx,a[i]);
  }

  int res = a[0];
  for(int i = 1; i < n; i++){
    res = gcd(res,a[i]);
  }
  if(k%res == 0 && k <= mx) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	
	char c[100][100];
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			c[i][j] = i >= 50 ? '.' : '#';
		}
	}

	for (int i = 0; i < a-1; i++) {
		int x = i%98 + 1;
		int y = i/98 * 4 + (i%2)*2 + 1;
		c[y][x] = '.';
	}
	for (int i = 0; i < b-1; i++) {
		int x = i%98 + 1;
		int y = i/98 * 4 + (i%2)*2 + 51;
		c[y][x] = '#';
	}

	printf("100 100\n");
	for (int i = 0; i < 100; i++) {
		for (int j = 0;  j < 100; j++) {
			printf("%c", c[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
int main() {
    long long n, a, b;
    std::cin >> n >> a >> b;
    if (n == 1 || a > b)
        std::cout << (a == b ? 1 : 0) << '\n';
    else
        std::cout << b * (n - 2) + a * (2 - n) + 1 << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int y=-1,flag=0;
  unsigned long long int x,s=100;
  scanf("%lu",&x);
  while(flag==0){
    if(s>=x){
      flag++;
    }
    y++;
    s+=s/100;
  }
  printf("%d\n",y);
  return 0;
}

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

int main(){
    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    long long neck = min({a, b, c, d, e});
    long long times = n / neck;
    if (n % neck != 0){
        times++;
    }

    cout << times + 4 << endl;
    return 0;
}

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

int main()
{
    long long s, c, sum;
    scanf("%lld %lld", &s, &c);
    if(c<=2*s)//c不够
        printf("%lld", c/2);
    else//s不够
    {
        sum=s;
        if(c<2)
        {
         sum=sum;
        }
        else
        {
            c=c-2*s;
            sum+=c/4;

        }
         printf("%lld", sum);
    }

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
int N,T,S;
int A[3010],B[3010];
int dp[3010][3010];
int main()
{
	scanf("%d %d %d",&N,&T,&S);
	for(int i=0;i<N;i++)scanf("%d %d",&A[i],&B[i]);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<=T;j++)
		{
			if(j-B[i]<S&&S<j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			else if(j-B[i]<0)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			else dp[i+1][j]=max(dp[i+1][j],max(dp[i][j],dp[i][j-B[i]]+A[i]));
			//printf("%d ",dp[i+1][j]);
		}
		//puts("");
	}
	int ans=0;
	for(int i=0;i<=T;i++)ans=max(ans,dp[N][i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 36336
n,m = [int(i) for i in input().split()]

hl = [int(i) for i in input().split()]

ml = [[] for _ in range(n)]

for _ in range(m):
  a, b = [int(i) for i in input().split()]
  ml[a-1].append(b-1)
  ml[b-1].append(a-1)
  
count = 0
for i in range(n):
  h = hl[i]
  max_h = 0
  for j in ml[i]:
    max_h = max(max_h, hl[j])
  if h > max_h:
    count += 1
    
print(count)

Measured memory_bytes: 92620
//ATCoder

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    string S;cin >> S;
    int Ans = 0, c = 0, n = S.size();
    rep(i,0,n){
        if(S[i]=='A'||S[i]=='T'||S[i]=='C'||S[i]=='G'){
            c++;
            Ans = max(c,Ans);
        }else{
            c=0;
        }
    }
    cout << Ans << endl;
    return 0;
}

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

inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<48||ch>57){if(ch=='-')f=-1;ch=getchar();}
	while(ch>=48&&ch<=57){k=(k<<1)+(k<<3)+(ch^48);ch=getchar();}
	return k*f;
}

inline void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+48);
}

inline void writeln(int x){
	write(x);puts("");
}

int n,m,ans;

signed main(){
	n=read();m=read();
	n-=2;m-=2;
	if(n>=0&&m>=0){
		ans=n*m;
	}else{
		if(n==-1){
			ans=m;
		}else{
			ans=n;
		}
	}
	if(n==-1&&m==-1)ans=1;
	writeln(ans);
	return 0;
}

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

using namespace std;

typedef struct ST_edge {
	int a;
	int b;
	int d;
	ST_edge() { a=0; b=0; d=0; }
	ST_edge(int a_, int b_, int d_) { a=a_; b=b_; d=d_; }
	bool operator>(const ST_edge& e) const { return d > e.d; }
} edge;

int main()
{
	while (true) {
		int n, m;
		cin >> n;
		if (n==0) break;
		cin >> m;
		priority_queue< edge, vector<edge>, greater<edge> > E;
		int a_, b_, d_;
		char dummy;
		for (int i=0; i<m; i++) {
			cin >> a_ >> dummy >> b_ >> dummy >> d_;
			E.push( edge(a_, b_, d_) );
		}
		
		vector<int> anc;
		anc.reserve(n);
		for (int i=0; i<n; i++) anc.push_back(i);
		
		int num_of_lantern = 0;
		while ( !E.empty() ) {
			edge e = E.top();
			while ( e.a != anc.at(e.a) ) e.a = anc.at(e.a);
			while ( e.b != anc.at(e.b) ) e.b = anc.at(e.b);
			if (e.a != e.b) {
				anc.at(e.b) = e.a;
				num_of_lantern += e.d/100 - 1;
			}
			E.pop();
		}
		// for (int i=0; i<n; i++) cout << anc.at(i) << " "; // test
		// cout << endl; // test
		cout << num_of_lantern << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3188
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if sum(A) < sum(B):
    print(-1)
    exit()
if all(a>=b for a,b in zip(A,B)):
    print(0)
    exit()

lack_v = lack_n = 0
gains = []
for a,b in zip(A,B):
    if a<b:
        lack_n += 1
        lack_v += b-a
    else:
        gains.append(a-b)

ans = lack_n
for g in sorted(gains, reverse=True):
    lack_v -= g
    ans += 1
    if lack_v <= 0:
        print(ans)
        exit()
print(-1)

Measured memory_bytes: 18708
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[5100];
long long dp[5100][5100];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<b)printf("0\n");
	else printf("10\n");
}


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


struct Edge {
  int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
  int k=1;
  rep(i, g[v].size()) {
    int u=g[v][i].to, ei=g[v][i].id;
    if (u==p) continue;
    if (k==c) k++;
    ans[ei]=k;
    k++;
    dfs(u, ans[ei], v);
  }
}

int main() {
  int n; cin>>n;
  g.resize(n);
  ans.resize(n);
  rep(i, n-1) {
    int a,b; cin>>a>>b;
    a--; b--;
    g[a].push_back((Edge){b, i});
    g[b].push_back((Edge){a, i});
  }
  dfs(0);
  int res=0;
  rep(i, n) {
    int tmp=g[i].size();
    res=max(res, tmp);
  }
  cout<<res<<endl;
  rep(i, n-1) cout<<ans[i]<<endl;
}

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

#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--)

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

int main(void) {
    int h, w;
    string s;
    cin >> h >> w;

    REP (i, h) {
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vector<string> a(n), b(m);
  re(i, n) std::cin >> a[i];
  re(i, m) std::cin >> b[i];
  bool flag = false;
  re(i, n){
    re(j, n){
      if(i+m-1>=n||j+m-1>=n) continue;
      bool tmp = true;
      re(l, m){
        re(r, m){
          if(a[i+l][j+r]!=b[l][r]) tmp = false;
        }
      }
      if(tmp) flag = true;
    }
  }
  std::cout << (flag?"Yes":"No") << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF = 1LL << 60;

int main() {
    ll N, x;
    cin >> N >> x;

    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(N + 10, -INF));
    dp[0][0] = 0;
    for(ll i = 1; i <= N; ++i) {
        for(ll sum_cnt = 0; sum_cnt < i; ++sum_cnt) {
            dp[i][sum_cnt] = dp[i - 1][sum_cnt];
            if(i >= 1) {
                chmin(dp[i][sum_cnt], dp[i - 1][sum_cnt - 1] + a[i - 1]);
            }
        }

        dp[i][i] = dp[i - 1][i - 1] + a[i - 1];
    }

    ll ans_i = 0;
    while(ans_i < N && dp[N][ans_i + 1] <= x) {
        ++ans_i;
    }
    if(dp[N][ans_i] < x && ans_i == N) {
        --ans_i;
    }
    cout << ans_i << endl;

    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	long long int a[3];
	while (1)
	{
		for (size_t i = 0; i < 3; i++)
		{
			cin >> a[i];
		}
		if (!a[0])break;
		sort(a, a + 3);
		a[2] = a[0] * a[0] + a[1] * a[1];
		int N;
		cin >> N;
		long long int x;
		for (size_t i = 0; i < N; i++)
		{
			cin >> x;
			x *= 2;
			if (x*x>a[2])
			{
				cout << "OK" << endl;
			} else
			{
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1176
h,w=map(int,input().split())
s=[input() for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]
for i in range(h):
  if s[i][0]=='.':
    l[i][0]=1
  if s[i][w-1]=='.':
    r[i][w-1]=1
for i in range(w):
  if s[0][i]=='.':
    u[0][i]=1
  if s[h-1][i]=='.':
    d[h-1][i]=1
for i in range(h):
  for j in range(w):
    if j>=1:
      if s[i][j]=='.':
        l[i][j]=l[i][j-1]+1
    if j<w-1:
      if s[i][w-j-2]=='.':
        r[i][w-j-2]=r[i][w-j-1]+1
    if i>=1:
      if s[i][j]=='.':
        u[i][j]=u[i-1][j]+1
    if i<h-1:
      if s[h-i-2][j]=='.':
        d[h-i-2][j]=d[h-i-1][j]+1
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)

Measured memory_bytes: 180740
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var b = new string[] { "a", "e", "i", "o", "u" };
        Console.WriteLine(b.Contains(s) ? "vowel" : "consonant");
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, b = 0;
    rep(i, n)
    {
        if (s[i] == 'R')
            r++;
        else
            b++;
    }
    if (r > b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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


void solve()
{
  int N, M;
  cin >> N >> M;
  vector<int> G[N];
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }
  vector<int> ans;
  rep(i,N){
    vector<bool> used(N);
    queue<int> Q;
    queue<vector<int>> P;
    used[i] = true;
    Q.push(i);
    vector<int> tmp={i};
    P.push({i});
    while(Q.size()){
      int u = Q.front();
      Q.pop();
      auto p = P.front();
      P.pop();

      for(auto v : G[u]){
	if(used[v]){
	  //cout << v <<  " " << p << endl;
	  if(v!=p[0])continue;
	  if(ans.size()==0 || p.size()<ans.size()){
	    ans=p;	    
	  }
	}
	else{
	  used[v]=true;
	  Q.push(v);
	  p.push_back(v);
	  P.push(p);
	  p.pop_back();
	}
      }
    }
  }
  if(ans.size()==0)cout << -1 << endl;
  else{
    cout << ans.size() << endl;
    for(auto v : ans){
      cout << (v+1) << endl;
    }
  }
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(11);
  solve();
  return 0; 
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int cnt = K;
    int ans = 0;
    if (cnt > 0 && cnt >= A) {
        ans += A;
        cnt -= A;
    } else {
        ans += cnt;
        cnt = 0;
    }

    if (cnt >= B) {
        cnt -= B;
    } else {
        cnt = 0;
    }

    ans -= cnt;

    cout << ans << endl;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vll A(N); cin >> A;
	ll xd = 0;
	for (int i = 0; i < N; i++) {
		xd ^= A[i];
	}
	for (int i = 0; i < N; i++) {
		A[i] ^= xd;
	}
	cout << A << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int s[n];
  int t[n];
  int sum = 0;
  for(int i = 0; i < n; ++i) {
    cin >> s[i];
    t[i] = s[i];
    sum += s[i];
  }
  sort(t, t+n);
  int cnt = 0;
  int tmp = 0;
  while(sum % 10 == 0 && cnt != n) {
    if(t[cnt] % 10 != 0) {
      sum -= t[cnt];
      break;
    } else {
      tmp++;
    }
    cnt++;
  }
  if(tmp == n) {
    cout << 0 << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}

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

#define mod 1000000007
#define modd 998244353
#define PI 3.1415926
#define ll long long
#define ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(),(v).end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define endl "\n"
#define forn(i,a,n) for(int i=a;i<int(n);++i)
#define forb(i,a,n) for(int i=int(n)-1;i>=a;--i)
#define cout(ans) cout<< ans << "\n"
#define couts(ans) cout<< ans <<" "
#define maxx *max_element
#define minn *min_element


void speed()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}


ll c[400005];
ll neg[400005];
void solve()
{
    char c;cin>>c;
    if(c>='A' && c<='Z')
        cout('A');
    else
        cout('a');
}


int main()
{   
    speed();
    int tc=1;
//    cin>>tc;
    while(tc--)
    {
        solve();
    }
}

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

int main() {
    //入力
    int N, Y;
    cin >> N >> Y;

    //処理
    for(int i = 0; i <= N; i++) {
        int z = N - i;
        for(int j = 0; j <= i; j++) {
            int y = i - j;
            int x = j;
            int total = x * 10000 + y * 5000 + z * 1000;
            if(total == Y) {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 3644
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        if (!isOk(s)) return No;

        string ss;
        int st, ed;

        st = 0;
        ed = (s.Length - 1) / 2;
        ss = s.Substring(st, ed-st);
        Debug.WriteLine(ss);
        
        if (!isOk(ss)) return No;
        
        st = (s.Length + 3) / 2 -1;
        ed = s.Length;
        ss = s.Substring(st, ed-st);
        Debug.WriteLine(ss);

        if (!isOk(ss)) return No;

        return Yes;
    }

    static bool isOk(string s) {
        for(int i=0; i<s.Length/2; i++) {
            if (s[i] != s[s.Length - i -1]) return false;
        }
        return true;
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
    }
    for (int cy = 0; cy <= 100; cy++) {
        for (int cx = 0; cx <= 100; cx++) {
            int needH = -1;
            rep(i, n) {
                if (h[i] > 0) {
                    int tmp = h[i] + abs(cy - y[i]) + abs(cx - x[i]);
                    if (needH == -1) needH = tmp;
                    else {
                        if (needH != tmp) {
                            needH = -2;
                            break;
                        }
                    }
                }
            }
            if (needH == -2) continue;
            rep(i, n) {
                if (h[i] == 0) {
                    int dist = abs(cy - y[i]) + abs(cx - x[i]);
                    if (needH > dist) {
                        needH = -2;
                        break;
                    }
                }
            }
            if (needH == -2) continue;
            printf("%d %d %d\n", cx, cy, needH);
            return 0;
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, M; cin >> N >> M;
  string S; cin >> S; reverse(S.begin(), S.end());

  vector<int> result;
  int pos = 0;
  while(pos!=N) {
    bool ok = false;
    for (int i=min(M, N-pos); i>=1; i--) {
      // cout << pos << "->" << i << endl;
      if (S[pos+i]=='0') {
        result.push_back(i);
        pos += i;
        ok = true;
      }
      if (ok) break;
    }
    if (!ok) { cout << -1 << endl; return 0; }
  }

  reverse(result.begin(), result.end());
  for(auto x: result) cout << x << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 1144
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int[][][] rooms = new int[4][3][10];

        int max = scanner.nextInt();
        int b,f,r,v;
        for(int i = 0; i < max; i++){
            b = scanner.nextInt();
            f = scanner.nextInt();
            r = scanner.nextInt();
            v = scanner.nextInt();

            rooms[b-1][f-1][r-1] += v;
            if(rooms[b-1][f-1][r-1] < 0){
                rooms[b-1][f-1][r-1] = 0;
            }
            if(rooms[b-1][f-1][r-1] > 9){
                rooms[b-1][f-1][r-1] = 8;
            }
        }

        int count = 0;
       for(int[][] bi : rooms){
            for(int[] fi : bi){
                for(int ri : fi){
                    System.out.print( " " + ri);
                }
                System.out.println();
            }
            if(count != rooms.length-1){
                count++;
                System.out.println("####################");
            }

       }
        scanner.close();
    }
}



Measured memory_bytes: 29480
import heapq

n, m = map(int,input().split())
a = [-1 * int(i) for i in input().split()]

ans = 0

heapq.heapify(a)

for i in range(m):
    hangaku = (heapq.heappop(a) * -1) // 2 * -1
    heapq.heappush(a, hangaku)    

print(-1*sum(a))

Measured memory_bytes: 14184
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val txyList = Array(n) {
        readLine()!!.split(" ").map(String::toInt).let { Triple<Int, Int, Int>(it[0], it[1], it[2]) }
    }

    var current = Triple(0, 0, 0)
    for (txy in txyList) {
        val (distT, distX, distY) = txy

        val (srcT, srcX, srcY) = current

        val time = distT - srcT
        val distance = Math.abs(distX - srcX) + Math.abs(distY - srcY)
        if (distance > time || time % distance != 0) {
            println("No")
            return
        }

        current = txy
    }
    println("Yes")

}




Measured memory_bytes: 64352
#include <cstdio>
#include <iostream>
#include <deque>
#define ll long long 
using namespace std;

int main() {
    ll n;
    ll num;

    deque<ll> b;
    scanf("%lld", &n);

    for (ll i=1; i<=n; i++) {
        scanf("%lld", &num);
        if (i%2 == n%2) {
            b.push_front(num);
        } else {
            b.push_back(num);
        }
    }

    for(deque<ll>::iterator it = b.begin(), e=b.end(); it != e; ++it) {
        printf("%lld ", *it);
    }

    printf("\n");
}


Measured memory_bytes: 3840
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < (i##_MACRO); i++)
#define RANGE(i, a, b) for(int i = (a); i < (b); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

typedef struct {
	int to_node;
	int color;
} edge;

typedef struct {
	vector<edge> next_nodes;
} node;

int color_num;

void color_tree(vector<node>& nodes, int node, int prev_color) {
	int c = 1;
	EACH(e, nodes[node].next_nodes) {
		c = c % color_num + 1;
		if(c == prev_color) {
			c = c % color_num + 1;
		}
		e.color = c;
		color_tree(nodes, e.to_node, e.color);
	}
}

int main() {
	int n;
	scanf("%d", &n);
	VI a(n - 1);
	VI b(n - 1);
	VI edge_num(n - 1, 0);
	vector<node> nodes(n);
	edge tmp;
	REP(i, n - 1) {
		scanf("%d %d", &a[i], &b[i]);
		edge_num[a[i] - 1]++;
		tmp.to_node = b[i] - 1;
		tmp.color = 0;
		nodes[a[i] - 1].next_nodes.push_back(tmp);
	}
	edge_num[0]--;
	color_num = *max_element(ALL(edge_num)) + 1;

	color_tree(nodes, 0, -1);

	VI edge_count(n - 1, 0);
	printf("%d\n", color_num);
	REP(i, n - 1) {
		printf("%d\n", nodes[a[i] - 1].next_nodes[edge_count[a[i] - 1]].color);
		edge_count[a[i] - 1]++;
	}
	return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,K;
vector<i64> A;

/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment {
  using Func = function<Monoid(Monoid, Monoid)>;

  vector<Monoid> node;
  Monoid ide;
  int n = 1;

  Func bin_f;
  Func update_f;

  Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
    : bin_f(f_), ide(ide_), update_f(u_f) {
      int sz = init.size();
      while (n < sz) n *= 2;
      node.assign(n * 2 - 1, ide);
      for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
      for (int i = n - 2; i >= 0; i--)
        node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

  void update(int i, Monoid x) {
    i += n - 1;
    node[i] = update_f(node[i], x);
    while (i) {
      i = (i - 1) / 2;
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }

  Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (a <= l && r <= b) return node[k];
    if (r <= a || b <= l) return ide;

    Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
    Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
    return bin_f(lm, rm);
  }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1
//
//

int main(){
  cin >> N >> K;
  A.resize(N);
  rep(i,0,N - 1){
    cin >> A[i];
    A[i] -= K;
    if(i > 0) A[i] += A[i - 1];
  }

  vector<i64> B = A;
  sort(all(B));

  Segment<i64> seg(vector<i64>(N,1),0,[](int a,int b){return a + b;},[](int a,int b){return a + b;});

  i64 before = 0;
  i64 ans = 0;
  rep(i,0,N - 1){
    int idx = lower_bound(all(B),before) - B.begin();
    ans += seg.get_inter(idx,N);
    before = A[i];
    seg.update(lower_bound(all(B),before) - B.begin(),-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 9088
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
l=[]
for i in range(0,n):
  a,b = map(int, input().split())
  l.append([a,b])
l.sort()
r=0
nn=0
for i in range(0,n):
  if nn+l[i][1]>=m:
    r=r+l[i][0]*(m-nn)
    break
  else:
    nn=nn+l[i][1]
    r=r+l[i][0]*l[i][1]

print(r)


Measured memory_bytes: 20048
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;
xy_t P[110];
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }
const double eps = 1e-11;
int main() {
 int N;
 double x[4], y[4];
 cin >> N;
 for (int t=0; t<N; ++t) {
  for (int i=0; i<4; ++i) {
   cin >> x[i] >> y[i];
  }
  xy_t a[2] = { xy_t(x[0],y[0])-xy_t(x[1],y[1]), xy_t(x[2],y[2])-xy_t(x[3],y[3]) };
  bool p = abs(cross_product(a[0],a[1])/2) < eps;
  cout << (p ? "YES" : "NO") << endl;
 }
}


Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


int main(void)
{
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0;i < m;i++) cin >> b[i];
    int calc = 0;

    int a;
    int cnt = 0;
    for (int i = 0;i < n;i++)
    {
        calc = c;
        for (int j = 0;j < m;j++)
        {
            cin >> a;
            calc += a * b[j];
        }
        if (calc > 0) cnt++;
        
    }

    cout << cnt << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a=in.nextInt(),b=in.nextInt(),c=in.nextInt(),d=in.nextInt();
        if(a+b==c+d){
            System.out.println("Balanced");
        }else if(a+b>c+d){
            System.out.println("Left");
        }else {
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 23764
def main():
    n,x,m = map(int,input().split())
    amari = [0 for i in range(m)]
    x = x%m
    amari[x] = 1
    loop = [x]
    while True:
        x = x**2 % m
        if amari[x]==0:
            loop.append(x)
            amari[x] = 1
        elif x==0:
            loop.append(0)
            if len(loop)>n:
                print(sum(loop))
            else:
                print(sum(loop[0:n]))
            return
        else:
            st = loop[0:loop.index(x)]
            loop = loop[loop.index(x):]
            break
    ans = 0
    if len(st)>=n:
        ans = sum(st[0:n])
        print(ans)
        return
    ans = sum(st)
    l = (n-len(st))//len(loop)
    ans += l*sum(loop)
    for i in range(n-len(st)-l*len(loop)):
        ans += loop[i]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 12308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n,a,b;
  cin >> n>>a>>b;
  ll x[n];
  ll ans=0;
  rep(i,n) cin >> x[i];
  rep1(i,n-1){
    if((x[i]-x[i-1])*a>b) ans+=b;
    else ans += (x[i]-x[i-1])*a;
  }
  cout << ans << endl;
  
  return 0;
    

}


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

int main(){
  while(1){
    string S;
    cin >> S;
    if(S=="#")break;
    int che=0;
    string R="yuiophjklnm";
    int a=0;
    for(int i=0;i<S.size();i++){
      bool ok=false;
      for(int j=0;j<R.size();j++){
        if(S[i]==R[j]){
          ok=true;
          break;
        }
      }
      if(a==0){
        if(ok){
          a=1;
        }else{
          a=-1;
        }
        continue;
      }
      if(ok){
        if(a==-1){
          che++;
          a=1;
        }
      }else{
        if(a==1){
          che++;
          a=-1;
        }
      }
    }
    cout << che << endl;
  }
}



Measured memory_bytes: 3136
package main

import "fmt"

var a []int

func dfs(i, sum, target int) bool {
	if i == len(a) {
		if sum == target {
			return true
		}
		return false
	}
	if sum > target {
		return false
	}
	if dfs(i+1, sum+a[i], target) {
		return true
	}
	if dfs(i+1, sum, target) {
		return true
	}
	return false
}

func main() {
	var n int
	fmt.Scan(&n)
	a = make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	var q int
	fmt.Scan(&q)
	m := make([]int, q)
	for i := range m {
		fmt.Scan(&m[i])
	}
	for i := range m {
		if dfs(0, 0, m[i]) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}



Measured memory_bytes: 1120
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Here your code !
    int h,w;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            string s;
            cin >> s;
            if(s == "snuke"){
                cout << (char)(j+'A') << i+1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#! env python
# -*- coding: utf-8 -*-

import os
import sys

from itertools import repeat


# ac_py.main
# Date: 2020/06/14
# Filename: main 
# Author: acto_mini

def main():
    H, W = map(int, input().split())

    S = list()

    for i in range(H):
        S.append(input())

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                # 上
                if i > 0 and S[i - 1][j] == "#":
                    continue
                # 左
                elif j > 0 and S[i][j - 1] == "#":
                    continue
                # 右
                elif j < (W - 1) and S[i][j + 1] == "#":
                    continue
                # 下
                elif i < (H - 1) and S[i + 1][j] == "#":
                    continue
                else:
                    print("No")
                    exit()

    print("Yes")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 40532
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;


int main()
{
	int n;
	cin >> n;
	long long sum = 0;
	long long ans = 0;
	vector<long> v(n);
	long long mod = pow(10, 9) + 7;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		sum += v[i];
	}
	//cout << sum << endl;
	for (int i = 0; i < n; i++)
	{
		//cout << ans << endl;
		sum = (sum - v[i] + mod) % mod;
		ans += (v[i] * sum) % mod;
	}
	cout << ans % mod;
}


Measured memory_bytes: 4752