akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second

using namespace std;

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

int H,W,K;
string A[810];

int main() {
  cin>>H>>W>>K;
  int startX, startY;
  REP(i,0,H){
    cin>>A[i];
    REP(j,0,W){
      if(A[i][j]=='S'){
        startY = i;
        startX = j;
      }
    }
  }

  int d[810][810], td[810][810];
  REP(i,0,H)REP(j,0,W) d[i][j] = INF, td[i][j] = INF;
  queue< pair<int,int> > tq;
  queue< pair<int,int> > q;
  tq.push(make_pair(startY,startX));
  q.push(make_pair(startY,startX));
  d[startY][startX] = 0;
  td[startY][startX] = 0;

  while(!tq.empty()){
    pair<int,int> nowPos = tq.front();
    tq.pop();
    if(td[nowPos.F][nowPos.S] == K) continue;
    REP(k,0,4){
      int nextY = nowPos.F + dy[k], nextX = nowPos.S + dx[k];
      if(!CH(nextY,0,H) || !CH(nextX,0,W)) continue;
      if(A[nextY][nextX] == '#' || td[nextY][nextX] != INF) continue;
      td[nextY][nextX] = td[nowPos.F][nowPos.S] + 1;
      d[nextY][nextX] = 0;
      tq.push(make_pair(nextY,nextX));
      q.push(make_pair(nextY,nextX));
    }
  }

  int ans = INF;
  while(!q.empty()){
    pair<int,int> nowPos = q.front();
    q.pop();

    if(nowPos.F==0||nowPos.F==H-1||nowPos.S==0||nowPos.S==W-1){
      cout<<(d[nowPos.F][nowPos.S]+(K-1))/K + 1<<endl;
      return 0;
    }

    REP(k,0,4){
      int nextY = nowPos.F + dy[k], nextX = nowPos.S + dx[k];
      if(!CH(nextY,0,H) || !CH(nextX,0,W)) continue;
      if(d[nextY][nextX] != INF) continue;
      d[nextY][nextX] = d[nowPos.F][nowPos.S]+1;
      q.push(make_pair(nextY,nextX));
    }
  }

  return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
  int n,m,f,g,c=0; cin>>n>>m;
  int a[m]={0};
  rep(i,n){
    cin>>f;
    rep(i,f) cin>>g,a[--g]++;
  }
  for(int i=0; i<m; i++) if(a[i]==n) c++;
  cout<<c;
}

Measured memory_bytes: 3560
import java.util.*;
import java.lang.*;

public class Main {
	static long mod = 998244353;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		int[] toku = new int[n];
		for (int i = 0; i < n; i++) {
			toku[i] = v[i] - c[i];
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (toku[i] > 0) {
				sum += toku[i];
			}
		}
		System.out.println(sum);
	}
}

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

int a[5],ans = 1e9;

int getTime()
{
	int t = 0; 
  	for(int i = 0; i < 5; i++)
    {
      	t += a[i];
      	if(i != 4 && t % 10 != 0)
          	t += (10 - (t % 10));
    }
	return t;
}



int main()
{
  	for(int i = 0; i < 5; i++)
		cin >> a[i];
	do
    {
		ans = min(ans, getTime());
    }
  	while(next_permutation(a, a + 5));
 	cout << ans << endl;		
    return 0; 
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(m==n){
        cout<< "Yes"<< "\n";
    }else{cout<< "No"<< "\n";}
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int n,k;
    string s;
    cin>>n;
    cin>>s;
    cin>>k;
    char c=s[k-1];
    for(int i=0;i<n;++i){
        if(s[i]!=c)s[i]='*';
    }
    cout <<s<<endl;
    return 0;
}


Measured memory_bytes: 256
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 	
int mod=1e9+7;
int po(int x,int y,int m)  { if (y==0) return 1; int t=po(x,y/2,m)%m; t=(t*t)%m; if (y&1) return (t*x)%m;	return t%m; }

signed main() {

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	string s;
   	string t;
   	cin>>s;
   	cin>>t;
   	int n=s.size();
   	int m=t.size();
   	int ans=m;
   	int count=0;
   	for(int i=0;i<n-m+1;++i){
   		count=0;
   		for (int j=0;j<m;++j){
   			if (s[j+i]!=t[j])
   				++count;
   		}
   		ans=min(count,ans);
   	}
   	cout<<ans<<endl;
   	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second


int main() {
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
 int a,b,c;
 cin>>a>>b>>c;
 if(a+b+c>=22)
    cout<<"bust";
 else
    cout<<"win";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
struct edge {int /*from,*/to,cost;};

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    if(a+b-1>n||a*b<n){
        puts("-1");
        return 0;
    }
    int seq[314514];
	int slen = 0;
	int cur = 1;
	int lft = n-a;
	for(int i=1;i<=a;i++) {
		int tk = min(lft,b-1); lft -= tk;
		tk++;
		cur += tk;
		for(int j=cur-1;j>=cur-tk;j--) seq[slen++] = j;
	}
	for(int i=0;i<slen;i++) printf("%d ",seq[i]);

    puts("");

    return 0;
}


Measured memory_bytes: 4480
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MN 4010

int dp[2010][2010];
int t[MN]; int a[MN];
int wz[MN][2];
int n;
int c[MN];

void add(int x, int v) {for(int i = x; i <= n * 2; i += i & -i) c[i] += v;}
int query(int x) {int ans = 0; for(int i = x; i; i -= i & -i) ans += c[i]; return ans;}

int main()
{
	memset(dp, 0x3f, sizeof(dp));
	scanf("%d", &n);
	for(int i = 1; i <= n * 2; i++)
	{
		char c[2];
		scanf("%s%d", c, &a[i]);
		if(c[0] == 'B') t[i] = 0;
		else t[i] = 1; 
		wz[a[i]][t[i]] = i;
	}
	dp[0][0] = 0;
	for(int i = 0; i <= n; i++)
	{
		memset(c, 0, sizeof(c));
		for(int j = 1; j <= 2 * n; j++) add(j, 1);
		for(int j = 1; j <= i; j++) add(wz[j][0], -1);
		for(int j = 0; j <= n; j++)
		{
			if(i == n && j == n) continue;
			if(j) add(wz[j][1], -1);
			if(i + 1 <= n) dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + query(wz[i + 1][0]) - 1);
			if(j + 1 <= n) dp[i][j + 1] = std::min(dp[i][j + 1], dp[i][j] + query(wz[j + 1][1]) - 1);
		}
	}
	printf("%d\n", dp[n][n]);
	return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
using namespace std;

struct HIT
{
	char number[128];
	int yen;
};

char cmp(char str[], char hit[])
{
	for (int i = 0; i < 8; i++){
		if (str[i] != hit[i] && hit[i] != '*'){
			return 0;
		}
	}
	
	return 1;
}

int main()
{
	int n, m;
	HIT hit[128];
	char str[128];
	
	while (scanf("%d %d", &n, &m), n){
		for (int i = 0; i < n; i++){
			scanf("%s %d", hit[i].number, &hit[i].yen);
		}
		
		int sum = 0;
		for (int i = 0; i < m; i++){
			scanf("%s", str);
			for (int j = 0; j < n; j++){
				if (cmp(str, hit[j].number) == 1){
					sum += hit[j].yen;
					break;
				}
			}
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 1048
#include <stdio.h>
int main()
{
  int x,i,j,key,A[100],k,minj,count = 0;
  scanf("%d",&x);
  for(i = 0; i < x; i++)
    scanf("%d",&A[i]);
  
  for(i = 0; i < x; i++)
    {
      minj = i;
      for(j = i; j < x; j++)
	{
	  if(A[j] < A[minj])
	    {
	      minj = j;
	      
	    } 
	}
      key = A[i];
      A[i] = A[minj];
      A[minj] = key;
      if(A[i] != A[minj])
	count++;
    }
  
  for(k = 0; k < x; k++)
    {
      printf("%d",A[k]);
      if(k < x-1)
	printf(" ");
    }
  printf("\n%d\n",count);
    
  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int N,K;
vector<int>G[111111];
vector<int>P[1111111];
int ans[111111];
bool F[111111];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		ans[i]=-1;F[i]=false;
	}
	for(int i=0;i<N-1;i++){
		int A,B;
		scanf("%d%d",&A,&B);A--;B--;
		G[A].pb(B);
		G[B].pb(A);
	}
	scanf("%d",&K);
	for(int i=0;i<K;i++){
		int v,p;
		scanf("%d%d",&v,&p);v--;
		P[p].pb(v);ans[v]=p;F[v]=true;
	}
	for(int i=0;i<1111111;i++){
		for(int j=0;j<(int)P[i].size();j++){
			//P[i][j]
			int now=P[i][j];
			//printf("%d:",now);
			if(ans[now]==-1){
				ans[now]=i;
			}
			for(int k=0;k<(int)G[now].size();k++){
				//printf("%d ",G[now][k]);
				if(ans[G[now][k]]==-1){
					if(!F[G[now][k]]){
						P[i+1].pb(G[now][k]);F[G[now][k]]=true;
					}
				}
				else if(ans[G[now][k]]-i!=1&&ans[G[now][k]]-i!=-1){
					printf("No\n");
					return 0;
				}
			}
			//printf("\n");
		}
	}
	printf("Yes\n");
	for(int i=0;i<N;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


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

int main() {
	int h,w,i,j;
	cin >> h >> w;
	char c;
	for(i=0; i<w+2; i++){
		cout << '#';
	}
	cout << endl;
	for(i=0; i<h; i++){
		cout << '#';
		for(j=0; j<w; j++){
			cin >> c;
			cout << c;
		}
		cout << '#';
		cout << endl;
	}
	for(i=0; i<w+2; i++){
		cout << '#';
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.ToCharArray().OrderBy(x => x).ToList();

            if ((list[0] == list[1]) && (list[2] == list[3]) && (list[1] != list[2]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11348
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
    ll n, x;
    cin >> n >> x;
    ll d = 0;
    ll ans = 1;
    for(ll i = 0; i < n; ++i){
        ll l;
        cin >> l;
        d += l;
        if(d <= x){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
  char a[100];
  int cnt=0,len=0;
  scanf("%s", a);
  for(int i =0;a[i]!='\0';i++){
    len++;
  }
  for(int i =0;i<len/2;i++){
    if(a[i] != a[len-i-1]){
      cnt++;}  }
  printf("%d\n",cnt);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int N;
   cin >> N;
   int b[N];
   for(int i=0;i<N;i++){
      cin >> b[i];
   }
   vector<int> ans;
   bool ok = false;
   for(int i=0; i<N; i++){
      ok=false;
      for(int j=N-1-i; j>=0; j--){
         if(b[j]==j+1){
            ok=true;
            ans.push_back(j+1);
            for(int k=j; k+1 <= N-1-i; k++){
               b[k]=b[k+1];
            }
            break;
         }
      }
      if(ok == false){
         break;
      }
   }
   if(ok==false){
      cout << -1 << endl;
   }
   else{
      for(int i=N-1; i>=0; i--){
         cout << ans[i]<<endl;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#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> a(n);
    rep(i, n) cin >> a[i], a[i]-=(i+1);
    sort(a.begin(), a.end(), greater<int>());
    int b;
    b = a[n/2];
    ll ans = 0;
    rep(i, n) {
        ans += abs(a[i]-b);
    }
    cout << ans;
}


Measured memory_bytes: 1024
N=int(input())
h=list(map(int,input().split()))

dp=[0]*N
dp[1]=abs(h[0]-h[1])

for i in range(2,N):
    dp[i]=min((dp[i-2]+abs(h[i]-h[i-2])),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])


Measured memory_bytes: 13928
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

const int MAX = 510000;
const int MOD = 1000000007;

int main(){

    int r;
    cin >>r;

    cout <<3*r*r<<endl;
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    vector<bool> a(100001, false);
    fori(m) {
        int x;
        cin>>x;
        a[x]=true;
    }

    static int MOD=1000000007;

    vector<int> dp(100001);
    dp[0]=1;
    if(a[1])
        dp[1]=0;
    else
        dp[1]=1;

    for(int i=2; i<=n; i++) {
        if(a[i])
            dp[i]=0;
        else {
            dp[i]=(dp[i-1]+dp[i-2])%MOD;
        }
    }
    cout<<dp[n]<<endl;

}



Measured memory_bytes: 640
import fractions

n,k=map(int,input().split())
a=list(map(int,input().split()))

if n==1:
    ans=a[0]
elif n==2:
    ans=fractions.gcd(a[0],a[1])

else:
    ans=fractions.gcd(a[0],a[1])
    for i in range(2,n):
        ans=fractions.gcd(ans,a[i])

if k<=max(a) and k % ans ==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,k;
  cin >> n >> k;
  int A[n];
  rep(i,n) A[i]=0;
  int cnt = 0;

  rep(i,k){
    int d;
    cin >> d;
    rep(i,d){
      int j;
      cin>> j;
      j--;
      A[j]++;
    }
  }
  
  rep(i,n){
//    cout << A[i] << endl;
    if(A[i] == 0) cnt++;
  }
//  cout << "total" << endl;
  cout << cnt << endl;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	for(int i = min(a,b); i >= 1; i--) 
	if(a % i == 0 && b % i == 0) {
		k--;
		if(!k) {
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a,b;
string s;
int main(){
	ios_base::sync_with_stdio(0);
	cin>>a>>b;
	cin>>s;
	int ct=-1;
	for(int i=0;i<a+b+1;i++){
		if(s[i]=='-'){
			if(ct==-1) ct=i;
			else{
				cout<<"No";
				return 0;
			}
		}
		else if(s[i]>='0' && s[i]<='9') continue;
		else{
			cout<<"No";
			return 0;
		}
	}
	if(ct==a){
		cout<<"Yes";
	}
	else cout<<"No";
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n, m, k = inm()


def solve():
    for x in range(n + 1):
        for y in range(m + 1):
            a = m * x + n * y - 2 * x * y
            if a == k:
                return True
    return False


print("Yes" if solve() else "No")


Measured memory_bytes: 9124
H,W = map(int, input().split())
A = [list(input()) for _ in range(H)]

R = set()
C = set(list(range(W)))
for i in range(H):
    if not "#" in A[i]:
        R.add(i)
        continue
    tmp = set()
    for j in range(W):
        if A[i][j] == ".":
            tmp.add(j)
    C &= tmp

ans = []
for i in range(H):
    if i in R:
        continue
    tmp = []
    for j in range(W):
        if j in C:
            continue
        tmp.append(A[i][j])
    ans.append(tmp)

for a in ans:
    print(*a,sep="")

Measured memory_bytes: 4596
import java.util.Scanner;

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

        String s = sc.next();
        int cnt = 0;
        
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '+') {
                cnt++;
            } else {
                cnt--;
            }
        }
        
        System.out.println(cnt);
    }
}



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(int argc, char const *argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++) cin>>v[i].first>>v[i].second;
    long long ans=0;
    sort(v.begin(),v.end());
    priority_queue<int>pq;
    for(int day_left=1,cur_day=0;day_left<=m;day_left++) {
        while(v[cur_day].first==day_left) {
            pq.push(v[cur_day].second);
            cur_day++;
        }
        if(!pq.empty()) {
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<1LL*ans<<endl;
} 

Measured memory_bytes: 1660
N = int(input())
l = []
for i in range(N):
    x,y,h = map(int,input().split())
    l.append([x,y,h])

flag = False

for i in range(N):
    if l[i][2] != 0:
        l[0],l[i]=l[i],l[0]
        break

for cx in range(102):
    if flag:
        break
    for cy in range(102):
        if flag:
            break
        ll = []
        flag = True
        for i in range(N):
            x,y,h = l[i]
            if i == 0:
                H = h+abs(x-cx)+abs(y-cy)
            if h != 0:
                if H != h+abs(x-cx)+abs(y-cy):
                    flag = False
                    break
            else:
                if H > abs(x-cx)+abs(y-cy):
                    flag = False
                    break
                    
print('{} {} {}'.format(cx-1,cy-1,H))


    

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



int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    
    cin >> k >> a >> b;
    
    if (a / k == b / k && a % k > 0)
        cout << "NG";
    else
        cout << "OK";
    return 0;
}

Measured memory_bytes: 3652
import numpy as np
h, n = map(int, input().split())    
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

dp = np.zeros(h + 1, dtype="int")

for i in range(1, h+1):
    dpi_1 = dp[np.maximum(i - ab[:, 0], 0)]
    dpi = dpi_1 + ab[:, 1]
    dp[i] = np.min(dpi)
    
print(dp[-1])

Measured memory_bytes: 14528
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> s;
	string str = "";
	if (s == "Sunny") {
		str = "Cloudy";
	}
	else if (s == "Rainy") {
		str = "Sunny";
	}
	else if (s == "Cloudy") {
		str = "Rainy";
	}
	cout << str << endl;
}



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

using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {

  int h,w;
  char c;
  cin>>h>>w;

  rep(i, w+2) cout<<"#"; cout<<endl;

  rep(i, h) {
    cout<<"#";
    rep(j, w) {
      cin>>c;
      cout<<c;
    }
    cout<<"#"<<endl;
  }

  rep(i, w+2) cout<<"#"; cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const double PI= 3.141592653589793238;
using namespace std;
void solve()
{
	int  r;cin>>r;
	
	double ans=(double)2*PI*(r*1.0);
	printf("%.10f",ans);

}
int main()
{
	//int t;cin>>t;
	//while(t--)
	solve();
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e16;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll div1[10000000];
void findDivisors(ll n) 
{ 
    for(ll i=0;i<=10000000;i++)
      div1[i]=0;
    for (ll i = 1; i <= n; i++)
    { 
      for (ll j = 1; j * i <= n; j++) 
            div1[i * j]++; 
    } 
} 
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  ll ans=0;
  findDivisors(n); 
  for(ll i=1;i<=n;i++)
  {
    ans=ans+i*div1[i];
  }
  cout<<ans;
  return 0;
}


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

int main(){
  string s,t;
  cin >> s >> t;
  int cnt=0,n=s.size();
  for(int i=0;i<n;i++){
    if(s.at(i) != t.at(i)) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}


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

int main(){
  
  int n,d,a;
  cin >> n >> d >> a;

  pair<int,int> arr[n];
  
  for(int i =0;i<n;i++){
    cin >> arr[i].first >> arr[i].second;
  }

  sort(arr,arr+n);
  
  ll sum =0;
  ll ans =0;
  queue<pair<int,int>> q;

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

        int h = arr[i].second;
        int x = arr[i].first;
        
        while( !q.empty() && arr[i].first > q.front().first){
          sum-=q.front().second;
          q.pop();
        }
        h -= sum; 
        if( h > 0){
            int num = ( h + a -1)/a;
            int damage = num*a;
            ans += num;
            sum+=damage;
            q.push({x+2*d,damage});
        }     
  
  }
 cout << ans << endl;

}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int n;
bool vis[100005];
vector<int>v[100005];
int dp[100003];
int dfs(int x){
	if(dp[x])return dp[x];
	int ans=0;
	for(int i=0;i<v[x].size();i++)
		ans=max(ans,dfs(v[x][i]));
	dp[x]=ans+1;
	return ans+1;
}
int main(){
	int n,m;
	cin>>m>>n;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		vis[b]=0;
		v[a].push_back(b);
	}
	int ans=0;
	for(int i=0;i<m;i++)
		if(!vis[i])
			ans=max(ans,dfs(i));
	cout<<ans-1;
}


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

int main() {
    string s;

    int cnt[26] = {0};
    while (getline(cin, s)) {
        rep(i, s.size()) {
            if (s[i] >= 'a' && s[i] <= 'z')
                cnt[s[i] - 'a']++;
            else if (s[i] >= 'A' && s[i] <= 'Z')
                cnt[s[i] - 'A']++;
        }
    }

    rep(i, 26) printf("%c : %d\n", 'a' + i, cnt[i]);

    return 0;
}


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

namespace abc052_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(x[0] * x[1] > x[2] * x[3] ? x[0] * x[1] : x[2] * x[3]);
        }
    }
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }

int solve(int N,int K,string s) {
	vector<pair<int, char>>v;
	v.eb(0, '?');
	v.eb(1, s[0]);
	rep(i, 1, N) {
		if (v.back().second == s[i])v[v.size() - 1].first++;
		else {
			v.eb(1, s[i]);
		}
	}
	dump(v);
	rep(i, 1, v.size()) {
		v[i].first += v[i - 1].first;
	}
	int ans = 0;
	rep(i, 1, v.size()) {
		int x;
		if (v[i].second == '1') {
			x = v[i].first - v[max(i - (2 * K + 1), 0ll)].first;
		}
		else {
			x = v[i].first - v[max(i - (2 * (K - 1) + 1), 0ll)].first;
		}
		chmax(ans, x);
	}
	return ans;
}
signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	int K; cin >> K;
	string s; cin >> s;
	int ans = solve(N, K, s);
	reverse(all(s));
	chmax(ans, solve(N, K, s));
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 4132
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}



void __sol(){
    ll n,sum=0; cin >> n;
    ll f[100100];
    memset(f,0,sizeof(f));
    forr(i,n){
        ll x; cin >> x;
        f[x]++;
        sum+=x;
    }
    ll q;cin>> q;
    while(q--){
        ll b,c; cin >> b >> c;
        if(f[b]>0){
            sum -= b*f[b];
            sum -= c*f[c];
            f[c]+=f[b];
            f[b]=0;
            sum+=c*f[c];
        }
        cout << sum << "\n";
    }
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 4436
n, y = map(int, input().split())

ans = [-1, -1, -1]
find = False
for i in range(n + 1):
  if find:
    break
  for j in range(n + 1):
    if i + j > n:
      break
    k = n - (i + j)
    total = 10000 * i + 5000 * j + 1000 * k
    if total == y:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      find = True
      break

print('{0} {1} {2}'.format(ans[0], ans[1], ans[2]))

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
char b[10], ch[10]={'A', 'C', 'G', 'T'};
scanf("%c", b);
for(int i=0;i<4;i++){
    if(b[0]==ch[i]){
    printf("%c\n", ch[3-i]);
    }
}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(a>=k) ans=k;
    else{
        if(a+b>=k) ans=a;
        else ans=2*a+b-k;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//2個みて大きい添え字の方から優先的に食べていくO(N)

int main(void){
    int N;
    ll x;
    cin>>N>>x;
    ll a, b;
    cin>>a;
    ll ans = 0;
    FOR(i, 1, N){
        cin>>b;
        ll eat = a+b>x?a+b-x:0;
        ans += eat;
        a = b>eat?b-eat:0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
int n;
string s;
int main()
{
	cin>>n;cin>>s;
	for(int i=0;i<s.size();i++)
	{
		char t=s[i]-'A';
		int temp=t+n;
		if(temp>=26) temp-=26;
		cout<<char('A'+temp);
	}
	puts("");
	return 0;
}


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

int main(){
  int k;
  cin >> k;
  if(k % 2 == 0){
      cout << int(k/2)*int(k/2) << endl;
  }else{
      cout << int(k/2 + 1)*int(k/2) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge {
	ll to;     // 辺の行き先
	ll weight; // 辺の重み
	Edge(ll t, ll w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main() {

    // 頂点数と辺数
    ll n, m; cin >> n;
    m = n - 1;

    // グラフ入力受取 (ここでは重み付き無向グラフを想定)
    Graph G(n);
    for (ll i = 0; i < m; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }

    ll q, k; cin >> q >> k;
    k--;

    // BFS のためのデータ構造
    vector<ll> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<Edge> que;

    // 初期条件 (頂点 k を初期ノードとする)
    dist[k] = 0;
    que.push(Edge(k, 0)); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        Edge v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (Edge new_v : G[v.to]) {
            if (dist[new_v.to] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 new_v について距離情報を更新してキューに追加する
            dist[new_v.to] = dist[v.to] + new_v.weight;
            que.push(new_v);
        }
    }

    for (ll i = 0; i < q; i++) {
        ll x, y; cin >> x >> y;
        x--;
        y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 12724
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  vector<ll> A(N), sumA(N+1);
  for(int i=0;i<N;++i) cin>>A[i];
  sort(A.begin(), A.end());
  for(int i=1;i<=N;++i) {
    sumA[i] = A[i-1];
  }
  for(int i=1;i<=N;++i) {
    sumA[i] += sumA[i-1];
  }

  ll l=1, r=inf, m;
  ll index;
  ll sum;
  while(l<r) {
    m = (l+r)/2;
    sum = 0;
    for(int i=0;i<N;++i) {
      index = upper_bound(A.begin(), A.end(), m-A[i])-A.begin();
      sum += N-index;
    }
    if(sum>=M) l = m+1;
    else r = m;
  }
  sum = 0;
  for(int i=0;i<N;++i) {
    index = upper_bound(A.begin(), A.end(), l-A[i])-A.begin();
    sum += N-index;
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    index = upper_bound(A.begin(), A.end(), l-A[i])-A.begin();
    ans += A[i]*(N-index)+sumA[N]-sumA[index];
  }
  ans += l*(M-sum);
  cout<<ans<<endl;
}



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

word_set = set()
W = str(input())
word_set.add(W)
last_char = W[len(W)-1]
#print(last_char,W,last_char)

for i in range(N-1):
  W = str(input())
  #print(last_char,W,last_char)
  if W in word_set:
    print("No")
    break
  elif W[0]!=last_char:
    print("No")
    break
  
  last_char = W[len(W)-1]
  word_set.add(W)
else:
  print("Yes")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
    int N;
    void solve()
    {
        N = cin.nextint;
        WriteLine(N * N - cin.nextint);
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n, m, k;
    cin >> n >> m >> k;
    vs64 a(n), b(m);

    rep (i, n) cin >> a[i];
    rep (i, m) cin >> b[i];

    vs64 sa(n + 1), sb(m + 1);
    sa[0] = sb[0] = 0;
    rep (i, n) sa[i + 1] = sa[i] + a[i];
    rep (i, m) sb[i + 1] = sb[i] + b[i];

    int ans = 0;
    rep (i, n + 1)
    {
        s64 t = k - sa[i];
        if (t < 0) continue;
        int temp = i;
        temp += upper_bound(sb.begin(), sb.end(), t) - sb.begin() - 1;
        ans = max(ans, temp);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 9544
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

c = list(itertools.permutations([i for i in range(1, N+1)]))

for i in range(len(c)):
    if(list(c[i]) == P):
        a = i+1
    if(list(c[i]) == Q):
        b = i+1
print(abs(a-b))

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

typedef pair<int,int>P;

int main(){

  int N,M;

  while(1){
    
    cin >>N>>M;
    if(N==0 && M==0)break;
    
    P a[N];

    for(int i=0 ; i < N ; i++){
      cin >>a[i].second>>a[i].first;
    }

    sort(a,a+N,greater<P>());

    for(int i=0 ; i < N ; i++){
      int d=min(M,a[i].second);
      M-=d;
      a[i].second-=d;
    }

    int ans=0;

    for(int i=0 ; i < N ; i++){
      ans+=a[i].first*a[i].second;
    }

    cout <<ans<<endl;

  }
  
  return 0;
}

Measured memory_bytes: 1240
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a , a+3);
    cout << (a[1] - a[0] + a[2] - a[1]) << endl;

    return 0;
}




Measured memory_bytes: 256
N = int(input())
F = []
P = []
for _ in range(N):
    F.append([int(f) for f in input().split()])
for _ in range(N):
    P.append([int(p) for p in input().split()])
res = []
for bit in range(1, 1 << 10):
    open_times = []
    for i in range(10):
        if((bit >> i) & 1) == 1:
            open_times.append(i)

    profit = 0
    for i in range(N):
        num_open = 0
        for open_time in open_times:
            if F[i][open_time]:
                num_open += 1
        profit += P[i][num_open]
    res.append(profit)

print(max(res))

Measured memory_bytes: 3064
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef unsigned long long ll;

int main()
{
  ll n, tmp;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  ll width = 0, height = 0;
  for (ll j = n - 1; j > 0; j--) {
    if (a[j] == a[j - 1]) {
      width = a[j];
      tmp = j - 1;
      break;
    }
  }
  for (ll j = tmp - 1; j > 0; j--) {
    if (a[j] == a[j - 1]) {
      height = a[j];
      break;
    }
  }
  cout << width * height << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    if(N<3){System.out.println(0);}
    else{
      long L[] =new long[N];
      for(int i=0;i<N;i++){
        L[i] =sc.nextLong();}
      Arrays.sort(L);
      long ans =0;
      for(int j=0;j<N-2;j++){
        for(int k=j+1;k<N-1;k++){
          for(int l=k+1;l<N;l++){
            if(L[j]!=L[k]){
              if(L[k]!=L[l]){
                if(L[j]+L[k]>L[l]){
                  ans =ans +1;}
              }
            }
          }
        }
      }
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 36296
N = int(input())
S = [int(input()) for i in range(N)]
dp = {}
dp[0] = True

for s in S:
    keys = list(dp.keys())
    for k in keys:
        dp[k + s] = True

res = 0
for k in dp.keys():
    if k % 10 == 0:
        continue
    res = max(res, k)

print(res)


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

int main(){
    int n,k,h[100000],ans=2000000000;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h,h+n);
    for(int i=0;i<n-k+1;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include <functional>
using namespace std;
#define INF 1<<21
#define DIV 1000000007

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

int main() {
  int N;
  int L[210];
  int sum = 0;
  cin >> N;
  for (int i = 0; i < 2*N; i++) {
	cin >> L[i];
  }

  sort(L, L + 2 * N);

  for (int i = 0; i < 2 * N; i += 2) {
	sum += L[i];
  }

  cout << sum << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n+1, 0);
    rep(i, n) cin >> a[i];

    while (k--) {
        vector<int> b(n+1, 0);
        rep(i, n) {
            int l = max(i - a[i], 0);
            int r = min(i + a[i]+1, n);
            b[l]++;
            b[r]--;
        }
        rep(i, n) b[i+1] += b[i];

        a = b;

        bool fin = true;
        rep(i, n) if (b[i] != n) fin = false;
        if (fin) break;
    }

    rep(i, n) cout << a[i] << " ";
    cout << endl;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll N = S.size();
  ll ans = 10000;

  rep(i, N - 2){
    ll val = 100*(S[i] - '0') + 10*(S[i+1] - '0') + (S[i+2] - '0');
    ans = min(ans, abs(val - 753));
  }

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define nl cout<<"\n"
#define dbg(x) cout<<x<<" ";
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define UM unordered_map<char,int>
#define ULL unordered_map<ll,int>
void fun(){
    string s,t; cin>>s>>t;
    UM ms,mt;
    int S=1,T=1;
    fi(0,s.size()){
        if(ms[s[i]]!=mt[t[i]]){
            cout<<"No\n";
            return ;
        }
        if(ms[s[i]]==0){
            ms[s[i]]=S;
            S++;
        }
        if(mt[t[i]]==0){
            mt[t[i]]=T;
            T++;
        }
    }
    cout<<"Yes\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   fun();
}

Measured memory_bytes: 916
#include<iostream>
#include<vector>
#define DN 105
#define M 1000000007
#define pb push_back
#define x first
#define y second
using namespace std;
int a,b,c;
long long k;
int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin>>a>>b>>c>>k;
    if(k%2==0)
        cout<<a-b;
    else
        cout<<b-a;
}


Measured memory_bytes: 256