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

int main() {
  string s;
  cin >> s;
  int a[4] = {};
  for (int i = 0; i < 4; i++) a[i] = s[i] - '0';
  if (a[0] + a[1] + a[2] + a[3] == 7) {
    cout << a[0] << '+' << a[1] << '+' << a[2] << '+' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] + a[1] + a[2] - a[3] == 7) {
    cout << a[0] << '+' << a[1] << '+' << a[2] << '-' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] + a[1] - a[2] + a[3] == 7) {
    cout << a[0] << '+' << a[1] << '-' << a[2] << '+' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] + a[1] - a[2] - a[3] == 7) {
    cout << a[0] << '+' << a[1] << '-' << a[2] << '-' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] - a[1] + a[2] + a[3] == 7) {
    cout << a[0] << '-' << a[1] << '+' << a[2] << '+' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] - a[1] + a[2] - a[3] == 7) {
    cout << a[0] << '-' << a[1] << '+' << a[2] << '-' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] - a[1] - a[2] + a[3] == 7) {
    cout << a[0] << '-' << a[1] << '-' << a[2] << '+' << a[3] << "=7" << endl;
    return 0;
  }
  if (a[0] - a[1] - a[2] - a[3] == 7) {
    cout << a[0] << '-' << a[1] << '-' << a[2] << '-' << a[3] << "=7" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    vector<int> a;
    int count = 0;
    rep(i, n)
    {
        int l;
        cin >> l;
        a.push_back(l);
    }
    sort(a.begin(), a.end(), greater<int>());
    rep(i,n){
        if(i%2==0){
            count += a[i];
        }
        else
        {
            count -= a[i];
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a = [-1]*(n+1)

ans = 0
for i in range(m):
  s,c=map(int,input().split())
  if a[s] == -1 or a[s] == c:
    a[s] = c
  else:
    print(-1)
    exit()
if n == 1:
  print(max(0, a[1]))
  exit()
if a[1] == 0:
  if n>1:
    print(-1)
    exit()
  else:
    print(ans)
else:
  ans = max(1, a[1])
  for i in range(2, n+1):
    ans = ans*10+max(0, a[i])
print(ans)


Measured memory_bytes: 3064
N,W=map(int,input().split())
li=[list(map(int,input().split())) for i in range(N)]
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if j < li[i-1][0]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-li[i-1][0]]+li[i-1][1])
print(dp[N][W])


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

using namespace std;
using ll = long long;

int main() {
    int K = 0;
    int N = 0;
    cin >> K;
    cin >> N;
    vector<int> A(N,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    int ans = abs(K + A.at(0) - A.at(N - 1));
    for(int i = 0; i < N-1; i++) {
        ans = max(ans,abs(A.at(i) - A.at(i+1)));
    }
    cout << K - ans << endl;

    return 0;
} 

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

int main() {
    int m, n;
    while (cin >> m >> n) {
        if (n < m) {
            int temp = m;
            m = n;
            n = temp;
        }
        while (m > 0) {
            int temp = m;
            m = n % m;
            n = temp;
        }
        cout << n << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>

int sen(int *,int);

int main ()
{
  int A[100],N,i,x;

  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
    scanf("%d",&A[i]);
    }
  x=sen(A,N);
  for(i=0;i<N;i++)
    {
      if(i>0)
	{
	  printf(" ");
	}
      printf("%d",A[i]);
    }
  printf("\n");
  printf("%d\n",x);

  return 0;
}

int sen(int A[],int N)
{
  int i,j,y,x=0,minj;

  for(i=0;i<N-1;i++)
    {
      minj=i;
      for(j=i;j<N;j++)
	{
	  if(A[j]<A[minj])
	    minj=j;
	}
      y=A[i];A[i]=A[minj];A[minj]=y;
      if(i!=minj)
	x++;
    }
      return x;
}
  



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n, k;
    cin >> n >> k;

    vector<vector<int>> a(k + 1, vector<int>(k + 1));
    int p[2] = {};
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;

        int t = c == 'W';
        if (x / k + y / k & 1) t ^= 1;
        a[x % k + 1][y % k + 1] += t == 0 ? 1 : -1;
        p[t]++;
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            a[i][j] += a[i][j - 1];
        }
    }
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            a[i][j] += a[i - 1][j];
        }
    }

    int r = -n;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
            int t = a[i][k] + a[k][j] - 2 * a[i][j];
            r = max(r, max(t, a[k][k] - t));
        }
    }

    cout << r + p[1] << endl;

    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    for (int i = 0; i < a; i++)
    {
        cin>>p[i];
    }
    for (int i = 0; i < b; i++)
    {
        cin>>q[i];
    }
    for (int i = 0; i < c; i++)
    {
        cin>>r[i];
    }
    

    sort(all(p));
    sort(all(q));
    sort(all(r));
    reverse(all(p));
    reverse(all(q));
    reverse(all(r));
    
    ll pcnt=0,qcnt=0,rcnt=0,ans=0;
    while (pcnt+qcnt+rcnt<x+y)
    {
        if(pcnt>=x)
        {
            if(q[qcnt] <= r[rcnt])
            {
                ans+=r[rcnt];
                rcnt++;
            }
            else
            {
                ans+=q[qcnt];
                qcnt++;
            }
        }
        else if (qcnt>=y)
        {
            if(p[pcnt] <= r[rcnt])
            {
                ans+=r[rcnt];
                rcnt++;
            }
            else
            {
                ans+=p[pcnt];
                pcnt++;
            }
        }
        else
        {
            if(p[pcnt] <= r[rcnt] && q[qcnt] <= r[rcnt])
            {
                ans+=r[rcnt];
                rcnt++;
            }
            else if(p[pcnt] <= q[qcnt] && r[rcnt] <= q[qcnt])
            {
                ans+=q[qcnt];
                qcnt++;
            }
            else
            {
                ans+=p[pcnt];
                pcnt++;
            }
        }
        
    }
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
LikeL = []
for i in range(N):
    temp = list(map(int, input().split()))
    temp.pop(0)
    LikeL.append(temp)

ans = 0
for Mi in range(M):
    all = True
    for i in range(N):
        if not(Mi+1 in LikeL[i]):
            all = False
            break
    if all:
        ans += 1
print(ans)


Measured memory_bytes: 9196
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['Yes', 'No']
############# CODE STARTS HERE #############


test_case=1
while test_case:
    test_case-=1

    n=ii()
    a=li()
    x=a[0]
    for i in a[1:]:
        x^=i
    #print(x)
    ans=[]
    for i in a:
        ans.append(i^x)
    print(*ans)

Measured memory_bytes: 109888
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;

    cout << (100 * (n - m) + 1900 * m) * pow(2, m) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>v;

    for(int i=0; i<3; i++){
        int x; cin>>x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    cout<<v[0];
    for(int i=1; i<3; i++)
        cout<<" "<<v[i];
    cout<<endl;

return 0;
}



Measured memory_bytes: 3160
#include <stdio.h>

int main(void){
  int tanka,kazu,sum=0,souko=0,line=0;
  int Ave;
  double a;
  while((scanf("%d,%d",&tanka,&kazu))!=EOF){
    sum+=tanka*kazu;
    souko+=kazu;
    line++;
  }
  a=(double)souko/(double)line;
  //printf("%f\n",a);
  if(a<0.5+(int)a){
    Ave=(int)a;
  }else{
    Ave=1+(int)a;
  }
  printf("%d\n",sum);
  printf("%d\n",Ave);
  return 0;
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    int sum;
    for(int i=0; i<n; i++){
        int j;
        cin >> j;
        sum += j;
        if(sum > x){
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << n+1 << endl;
    return 0;
}

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

using namespace std;
using ll =  long long;
using ull =  unsigned long long;
int main(){

    ull n;
    cin>>n;
    ull ans=0;
    if(n%2==0){
        n/=2;
        while(n){
            ans+=n/5;
            n/=5;
        }

            cout<<ans;
    }
    else{
        cout<<0;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b;
    
    scanf("%d",&a);
    scanf("%d",&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

const int MOD = 999999937; 
const int MAXN = 250005;
const int K = 6;

char s[MAXN];

int n, X[MAXN][K], IX[MAXN][K], C[K], pos[MAXN];

vector<int> a[MAXN], b[MAXN];

map<vector<int>, int> mp;

char rev(char x)
{
	if (x == '<') return '>';
	if (x == '>') return '<';
	if (x == '+') return '-';
	if (x == '-') return '+';	
}

int qpow(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (long long)ret * a % MOD;
		a = (long long)a * a % MOD;
		b >>= 1;	
	}
	return ret;
}

void T(int &c, char x, int k)
{
	if (x == '<') c = (long long)c * X[1][k] % MOD;
	if (x == '>') c = (long long)c * IX[1][k] % MOD;
	if (x == '+') c = (c + 1) % MOD;
	if (x == '-') c = (c - 1 + MOD) % MOD;
}

void init()
{
	for (int i = 0; i < K; i++)
		X[0][i] = 1;
	for (int i = 0; i < K; i++)
		X[1][i] = rand() % MOD; // ***************
	for (int i = 2; i < n; i++)
		for (int j = 0; j < K; j++)
			X[i][j] = (long long)X[i - 1][j] * X[1][j] % MOD;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < K; j++)
			IX[i][j] = qpow(X[i][j], MOD - 2);
	for (int i = n; i >= 1; i--)
		for (int j = 0; j < K; j++)
			T(C[j], s[i], j);
//	cout << "C: " << C[0] << endl;
	for (int i = 0; i <= n + 1; i++)
		a[i].resize(K, 0), b[i].resize(K, 0);
}

int main()
{
	srand(2333);
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	init();
	pos[n + 1] = 0;
	for (int i = n; i >= 1; i--)
	{
		for (int j = 0; j < K; j++)
			b[i][j] = b[i + 1][j];
		pos[i] = pos[i + 1];
		switch (rev(s[i])) 
		{
			case '<':
				pos[i]++;
				break;
			case '>':
				pos[i]--;
				break;
			case '+':
				if (pos[i] >= 0)
				{
					for (int j = 0; j < K; j++)
						b[i][j] = ((long long)b[i][j] + X[pos[i]][j]) % MOD;
				}
				else
				{
					for (int j = 0; j < K; j++)
						b[i][j] = ((long long)b[i][j] + IX[-pos[i]][j]) % MOD;
				}
				break;
			case '-':
				if (pos[i] >= 0)
				{
					for (int j = 0; j < K; j++)
						b[i][j] = ((long long)b[i][j] - X[pos[i]][j] + MOD) % MOD;
				}
				else
				{
					for (int j = 0; j < K; j++)
						b[i][j] = ((long long)b[i][j] - IX[-pos[i]][j] + MOD) % MOD;
				}
				break;	
		}
//		cout << "b[" << i << "]: " << b[i][0] << endl;
	}
	for (int i = n; i > 0; i--)
	{
		for (int j = 0; j < K; j++)
		{
			if (pos[i] >= 0)
				a[i][j] = ((long long)C[j] * X[pos[i]][j] % MOD + b[i][j]) % MOD;
			else
				a[i][j] = ((long long)C[j] * IX[-pos[i]][j] % MOD + b[i][j]) % MOD;
		}
//		cout << "b[" << i << "]: " << b[i][0] << endl;
		mp[a[i]]++;
	}
	long long res = 0;
	for (int i = n; i > 0; i--)
	{
		res += mp[b[i + 1]];
		mp[a[i]]--;
	}
	cout << res << endl;
	return 0;	
}


Measured memory_bytes: 95232
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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

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


int main(){
    string S, T, ans="No";
    cin >> S >> T;
    int len = S.length();
    for(int i = 0; i < len; ++i){
        string sub = S.substr(len-i, i);
        string tmp = S.substr(0, len-i);
        if(sub + tmp == T) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
  int n,k;
  int a[100];

  while(cin >> n >> k && (n||k)){
    for(int i=0;i<n;i++)cin >> a[i];

    int ck = 1;
    for(int i=0;i<k;i++)ck *= a[i];
    int m = ck;
    for(int i=k;i<n;i++){
      ck /= a[i-k];
      ck *= a[i];
      m = max(ck,m);
    }
   
    int ans = 0;
    for(int i=0;i+k<=n;i++){
      int x = 1, mi = 100, ma = 0;
      for(int j=0;j<n;j++){
	if(i<=j && j<i+k){
	  mi = min(mi,a[j]);
	  x *= a[j];
	}else ma = max(ma,a[j]);
      } 
      ans = max(ans,x/mi*ma-m);
    }
    cout << ans << endl;
  }
}

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



int main()
{
 int n;
 cin>>n;
 int a=0,b=0,c=0;
 for(int i=0;i<n;i++)
 {
     int tmp;
     cin>>tmp;
     if(tmp%4==0) a++;
     else if(tmp%2==0) b++;
     else c++;


 }
 if(n==2)
    {
        if(a==1||a==2)
        {cout<<"Yes"<<endl;return 0;}
        if(b==2)        {cout<<"Yes"<<endl;return 0;}
       cout<<"No"<<endl;return 0;

    }


 if(c==0)  cout<<"Yes"<<endl;
else{
    if(a<c-1) {cout<<"No"<<endl;}
    else {
        if(a>=c) cout<<"Yes"<<endl;
        else 
            {
                if(b==0) cout<<"Yes"<<endl;
                else cout<<"No"<<endl;
            }
    }

}

  return 0;
}

Measured memory_bytes: 256
n = int(input())
l = []
c = 0
for i,j in enumerate(map(int,input().split())):
  if i+1 == j:
    l.append(i)
for i in range(len(l)-1):
  if l[i] == -1:
    continue
  if l[i+1] == l[i] + 1:
    l[i+1] = -1
  c += 1
if l and l[-1] != -1:
  c += 1
print(c)

Measured memory_bytes: 55724
#include<stdio.h>
int main(void){
	char y[10];
	int i,kazu[10],yy,m,d;
	scanf("%s",&y);
	for(i=0;i<10;i++){
		if(i!=4&&i!=7){
			if(y[i]=='0'){
				kazu[i]=0;
			}else if(y[i]=='1'){
				kazu[i]=1;
			}else if(y[i]=='2'){
				kazu[i]=2;
			}else if(y[i]=='3'){
				kazu[i]=3;
			}else if(y[i]=='4'){
				kazu[i]=4;
			}else if(y[i]=='5'){
				kazu[i]=5;
			}else if(y[i]=='6'){
				kazu[i]=6;
			}else if(y[i]=='7'){
				kazu[i]=7;
			}else if(y[i]=='8'){
				kazu[i]=8;
			}else if(y[i]=='9'){
				kazu[i]=9;
			}
		}
	}
	yy=kazu[0]*1000+kazu[1]*100+kazu[2]*10+kazu[3];
	m=kazu[5]*10+kazu[6];
	d=kazu[8]*10+kazu[9];
	
	if(yy>2019){
		printf("TBD\n");
	}else if(yy==2019&&m>4){
		printf("TBD\n");
	}else if(yy==2019&&m==4&&d>30){
		printf("TBD\n");
	}else{
		printf("Heisei\n");
	}
	return 0;
}

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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			var a = cin.ArrayInt(n);
			int m = cin.NextInt();
			int sum = a.Sum();
            for (int i = 0; i < m; i++)
            {
				int p = cin.NextInt();
				int x = cin.NextInt();
				Console.WriteLine(sum - a[p - 1] + x);
            }

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11220
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,d,n,x[3]={1,100,10000};
	scanf("%d %d",&d,&n);
	if(n==100)	n++;
	printf("%d\n",n*x[d]);
	return 0;
}

Measured memory_bytes: 128
package main

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

func solve() {
	n, k := getInt(), getInt()
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		num := getInt()
		m[num]++
	}

	s := make([]int, 0, len(m))
	for _, v := range m {
		s = append(s, v)
	}

	sort.Ints(s)

	ans := 0
	for i := 0; i < len(s)-k; i++ {
		ans += s[i]
	}

	fmt.Fprintln(wr, ans)
}

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 11648
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string.h>
#include <vector>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <queue>
using namespace std;
typedef unsigned long long ui64;
typedef long long i64;
int t[2][100001];
int f[2][2];

void jig() {
	int n;
	cin >> n;
	int v[2][2];
	for (size_t i = 0; i < n; i++)
	{
		int p;
		cin >> p;
		int i2 = i % 2;
		t[i2][p]++;

		if (t[i2][p] > f[i2][0]) {
			f[i2][0] = t[i2][p];
			v[i2][0] = p;
		}else if(t[i2][p] > f[i2][1]){
			f[i2][1] = t[i2][p];
			v[i2][1] = p;
		}
	}

	if (v[0][0] != v[1][0]) {
		cout << (n - f[0][0] - f[1][0]) << "\n";
		return;
	}
	int val = max((f[0][0] + f[1][1]), max((f[0][1] + f[1][0]), f[0][1] + f[1][1]));
	cout << (n - val) << "\n";

}
 int main() {
	 jig();
	 return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;

int32_t main()
{
	FastIO; PRECISION;
	string s,t;
	cin>>s>>t;
	const int a = s.size(),b = t.size();
	if(b == (a+1))
	{
		if(t.compare(0,b-1,s)==0)
		{
			cout<<"Yes"<<endl;
		}
		else
			cout<<"No"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	ll x, y, z;
	cin >> x >> y >> z;

	x -= z;
	ll ans = 0;
	for (ll i = y + z; i <= x; i += y + z)
	{
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int ans[45] = {};

int fib(int n) {
	if (n <= 1) return 1;
	int a = ans[n];
	if (a) return a;
	a = fib(n-1) + fib(n-2);
	ans[n] = a;
	return a;
}

int main()
{
	int i = 0;
	cin >> i;
	cout << fib(i) << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, k;
	cin >> n >> k;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	ll ans = 0;
	vll cnt(2001, 0);
	cnt[a[0]]++;
	for (ll i = 1; i < n; i++) {
		for (ll j = a[i] + 1; j <= 2000; j++) ans += cnt[j];
		cnt[a[i]]++;
	}
	ans *= k;
	ans %= p;

	cnt.push_back(0);
	for (ll i = 1999; i > 0; i--) {
		cnt[i] += cnt[i + 1];
		cnt[i] %= p;
	}

	for (ll i = 0; i < n; i++) {
		ll subans = k * (k - 1) / 2 % p * cnt[a[i] + 1] % p;
		ans += subans;
		ans %= p;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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



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

 
  int n,m;
  cin>>n>>m;
  cout<<n*(n-1)/2  + m*(m-1)/2<<"\n";

}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
using namespace std;

typedef long long ll;

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

ll arr[100010];
ll gcdL[100010],gcdR[100010];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	gcdL[0]=arr[0];
	gcdR[n-1]=arr[n-1];
	for (int i = 1; i < n; ++i)
	{
		gcdL[i]=gcd(gcdL[i-1],arr[i]);
	}
	for (int i = n-2; i >=0; --i)
	{
		gcdR[i]=gcd(gcdR[i+1],arr[i]);
	}
	ll temp;
	ll maxi=max(gcdL[n-2],gcdR[1]);
	for (int i = 1; i < n-1; ++i)
	{
		temp=gcd(gcdL[i-1],gcdR[i+1]);
		if (temp>maxi) maxi=temp;
	}
	cout<<maxi<<endl;
}

Measured memory_bytes: 2560
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const int mod = 1000000007;
const int n_up = 1e5 + 5;
template <typename T> T add(T& a, T b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T mul(T& a, T b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T up_self(T& a, T b){a = up(a,b);}
template <typename T> T min_self(T& a, T b){a = min(a,b);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
vector<vector<int>> g(n_up);
bool visited[n_up];
int dis[n_up];
int in_degree[n_up];
void dfs(int a){
	assert(visited[a]==false);
	visited[a] = true;
	for(int i : g[a]){
		up_self(dis[i], dis[a]+1);
		in_degree[i]--;
		if(in_degree[i]==0)
			dfs(i);
	}
}
int main()
{
	int n,m; cin>>n>>m;
	for(int i= 0 ; i < m ; i++){
		int a,b; cin>>a>>b;
		g[a].push_back(b);
		in_degree[b]++;
	}
	for(int i = 1; i <= n; i++)
		if(!visited[i]&&in_degree[i]==0)
			dfs(i);
	int ans = 0;
	for(int i = 0; i < n; i++)
		up_self(ans, dis[i+1]);
	cout<<ans<<endl;
	
  	return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    char b;
    cin >> b;
    if(b == 'A') cout << "T" << endl;
    if(b == 'T') cout << "A" << endl;
    if(b == 'C') cout << "G" << endl;
    if(b == 'G') cout << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;vector<int> a(n), b(n);
    for(int i=0; i<n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if(n&1) {
        cout << b[n/2] - a[n/2] + 1 << endl;
    } else {
        int res = (b[(n-1)/2] + b[n/2]) - (a[(n-1)/2] + a[n/2]) + 1;
        cout << res << endl;
    }
}


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

static LL g[101][100002];

int main()
{
	for (LL i = 0; i < 100; ++i) {
		for (LL j = 0; j < 100002; ++j) {
			g[i][j] = 0;
		}
	}
	LL n, k;
	cin >> n >> k;

	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e;
	}

	//sort(a.begin(), a.end());

	g[0][0] = 1;

	for (LL i = 0; i <= n-1; ++i) {
		for (LL j = 0; j <= k; ++j) {
			g[i+1][j] += g[i][j];
			g[i+1][min(j+a[i]+1, k+1)] -= g[i][j];
			
		}
		LL acc = 0;
		for (LL j = 0; j <= k; ++j) {
			acc += g[i+1][j];
			acc %= mod;
			g[i+1][j] = (acc+mod)%mod;
		}
	}

	// for (LL i = 0; i <= n; ++i) {
	// 	for (LL j = 0; j <= k; ++j) {
	// 		cout << g[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }

	cout << g[n][k] << "\n";



}

Measured memory_bytes: 79104
import scala.io.StdIn

object Main extends App {

  case class Dice(su1: Int, su2: Int, su3: Int, su4: Int, su5: Int, su6: Int){
    private val nums = Map(1 -> su1, 2 -> su2, 3 -> su3, 4 -> su4, 5 -> su5, 6 -> su6)
    def currentTop(): Int = nums(1)
    
    def roll(d: Char): Dice = d match {
        case 'N' => Dice(su2, su6, su3, su4, su1, su5)
        case 'S' => Dice(su5, su1, su3, su4, su6, su2)
        case 'W' => Dice(su3, su2, su6, su1, su5, su4)
        case 'E' => Dice(su4, su2, su1, su6, su5, su3)
    }
    
    def rollToNum(top: Int): Dice = {
      
      var cnt = 0
      var temp = this.copy()
      while(temp.su1 != top && cnt < 4){
        temp = temp.roll('N')
        cnt += 1
      }

      cnt = 0
      while(temp.su1 != top && cnt < 4){
        temp = temp.roll('W')
        cnt += 1
      }
      if(temp.su1 == top) temp else this
    }
    
    
    def dicePattern(top: Int, front: Int): Int = (top, front) match {
        case (this.su4, this.su2) => this.su1
        case (this.su2, this.su3) => this.su1
        case (this.su3, this.su5) => this.su1
        case (this.su5, this.su4) => this.su1
        case (this.su1, this.su4) => this.su2
        case (this.su4, this.su6) => this.su2
        case (this.su6, this.su3) => this.su2
        case (this.su3, this.su1) => this.su2
        case (this.su6, this.su5) => this.su3
        case (this.su5, this.su1) => this.su3
        case (this.su1, this.su2) => this.su3
        case (this.su2, this.su6) => this.su3
        case (this.su1, this.su5) => this.su4
        case (this.su5, this.su6) => this.su4
        case (this.su6, this.su2) => this.su4
        case (this.su2, this.su1) => this.su4
        case (this.su1, this.su3) => this.su5
        case (this.su3, this.su6) => this.su5
        case (this.su6, this.su4) => this.su5
        case (this.su4, this.su1) => this.su5
        case (this.su2, this.su4) => this.su6
        case (this.su4, this.su5) => this.su6
        case (this.su5, this.su3) => this.su6
        case (this.su3, this.su2) => this.su6
    }
    
  }
  
  val nums = StdIn.readLine().split(' ').map(_.toInt)
  var dice1 = Dice(nums(0), nums(1), nums(2), nums(3), nums(4), nums(5))
  // for duplicate numbers
  val numsGrouped = nums.groupBy(n => n)
  dice1 = if(numsGrouped.keys.size == 2) {
    val k = numsGrouped.filter(p => p._2.size == 1).head._1
    dice1.rollToNum(k)
  } else {
    dice1
  }
  //println("dice1: " + dice1)
  val nums2 = StdIn.readLine().split(' ').map(_.toInt)
  var dice2 = Dice(nums2(0), nums2(1), nums2(2), nums2(3), nums2(4), nums2(5))
  
  // search top
  var count = 0
  dice2 = dice2.rollToNum(dice1.su1)
  //println("dice2: " + dice2)
  
  if(dice1.su1 == dice2.su1){
    // roll south
    dice1 = dice1.roll('S')
    dice2 = dice2.roll('S')

    count = 0
    // 2 is match / again search top, side 3 
    while(dice1.su1 != dice2.su1 &&
          dice1.su3 != dice2.su3 && count < 4){
      dice2 = dice2.roll('W')
      count += 1
    }
  }
  
  println(if(dice1 == dice2) "Yes" else "No")
  
}


Measured memory_bytes: 44216
#include<iostream>
using namespace std;
static const int PMAX = 100000;
int N, T[2 * PMAX + 20 + 1];
int main() {
	int a, b;
	for (int i = 0; i <= 2 * PMAX + 20; i++)T[i] = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		T[a + b]++;
	}
	for (int i = 0; i < 2 * PMAX + 20; i++) {
		T[i + 1] += T[i]/2;
		T[i] = T[i] % 2;
		if (T[i])cout << i << " " << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  for(int i=0;i<W+2;i++)
    cout<<"#";
  cout<<endl;
  for(int i=1;i<H+1;i++){
    string S;
    cin>>S;
    for(int j=0;j<W+2;j++){
      if(j==0||j==W+1)
        cout<<"#";
      else
        cout<<S.at(j-1);
      }
    cout<<endl;
    }
  for(int i=0;i<W+2;i++)
    cout<<"#";
  cout<<endl;
  }

Measured memory_bytes: 256
# EDP F-LCS
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

ans = ""


def main():
    S = input()
    T = input()
    LS = len(S)
    LT = len(T)
    dp = [[0 for j in range(LT+1)] for i in range(LS+1)]

    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i+1][j+1] = dp[i][j]+1
            else:
                if dp[i+1][j] >= dp[i][j+1]:
                    dp[i+1][j+1] = dp[i+1][j]
                else:
                    dp[i+1][j+1] = dp[i][j+1]

    def rec(i, j):
        if i == 0 or j == 0:
            return

        if S[i-1] == T[j-1]:
            global ans
            ans += S[i-1]
            rec(i-1, j-1)
        elif dp[i-1][j] > dp[i][j-1]:
            rec(i-1, j)
        else:
            rec(i, j-1)

    rec(LS, LT)
    print(ans[::-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 122332
#include<iostream>
#include<string>

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	string O;
	int K;
	cin >> O >> K;
	string S(O),G(O);
	int count_s = 0;
	int count_g = 1;
	bool  flag_s = false,flag_g = false;
	for (int i = 1; i < S.length(); i++) {
		if (S[i] == S[i - 1]) {
			count_s++;
			S[i] = '0';
			if (i == S.length()-1) {
				flag_s = true;
			}
		}
	}
	for (int i = 2;i < G.length();i++) {
		if (G[i] == G[i-1]) {
			count_g++;
			G[i] = '0';
			if (i == G.length() - 1) {
				flag_g = true;
			}
		}
	}

	if (S.length() == 1) {
		flag_g = true;
	}
	if (S[0] != S[S.length()-1]) {
		cout << count_s * K <<endl; //SSSS...
	}
	else {
		if (flag_s) {
			cout << count_s * K << endl; //SSSS...
		}
		else {
			if (flag_g) {
				cout << count_s * (K / 2 + K % 2) + count_g *( K / 2 )<< endl; //SGSGSGSG...
			}
			else {
				cout << count_s + count_g * (K - 1) << endl; //SGGG..
			}
		}
	}
}


Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = input()
if '7' in N:
    print("Yes")
else:
    print('No')


Measured memory_bytes: 68600
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    string S;
    cin >> S;
    int blue=0;
    int red=0;
    REP(i, S.length()){
        if(S[i]=='0'){
            red++;
        }else{
            blue++;
        }
    }
    cout << min(red, blue)*2 << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args){
		//宣言
		sc = new Scanner(System.in);
		int w=sc.nextInt();
		int n=sc.nextInt();
		int a[]=new int[n+1];
		int b[]=new int[n+1];
		String s[]=new String[n+1];
		int i=0;
		for(i=1;i<=n;i++){
			String str =sc.next();
			String[] ab =str.split(",");
			a[i]= Integer.parseInt(ab[0]);
			b[i]=Integer.parseInt(ab[1]);
		}
		int bar[]=new int[w+1];
		for(i=1;i<=w;i++) {
			bar[i]=i;
		}
		//演算
		for(i=1;i<=n;i++) {
			//swap
			int p =bar[(int)a[i]];
			bar[(int)a[i]]=bar[(int)b[i]];
			bar[(int)b[i]]=p;
			
		}
		//出力
		for(i=1;i<=w;i++) {
			System.out.println(bar[i]);
		}
	}
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<ll> A(N + 1);
  REP(i, N + 1) { cin >> A.at(i); }
  vector<ll> B(N);
  REP(i, N) { cin >> B.at(i); }

  ll ans = 0;
  REP(i, N) {
    ll cnt1, cnt2;
    cnt1 = min(A.at(i), B.at(i));
    ans += cnt1;
    A.at(i) -= cnt1;
    B.at(i) -= cnt1;

    cnt2 = min(A.at(i + 1), B.at(i));
    ans += cnt2;
    A.at(i + 1) -= cnt2;
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using ld = double;
using pii = pair<int, int>;

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

	int n;
	cin >> n;

	if (n <= 599) {
		cout << "8";
	} else if (n <= 799) {
		cout << "7";
	} else if (n <= 999) {
		cout << "6";
	} else if (n <= 1199) {
		cout << "5";
	} else if (n <= 1399) {
		cout << "4";
	} else if (n <= 1599) {
		cout << "3";
	} else if (n <= 1799) {
		cout << "2";
	} else if (n <= 1999) {
		cout << "1";
	}

	return 0;
}

Measured memory_bytes: 3648
import bisect

n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))

print(ans)

Measured memory_bytes: 23092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll v[110], w[110];
ll dp[110][10010];

int main(){
    ll n, W;
    cin >> n >> W;
    rep(i, n) cin >> v[i] >> w[i];

    rep(i, n){
        rep(j, W + 1){
            if (j - w[i] >= 0) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
            else dp[i + 1][j] = dp[i][j];
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


Measured memory_bytes: 10908
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	char a;
	in(a);
	char x = a + 1;
	out(x);
	return 0;
}

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

using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main()
{
	int n;
	cin >> n;
	vector<int> arr = {1,2,4,8,16,32,64};
	
	//for(int n = 1; n < 101; n++){
		//cout << n << ":" ;
		if(n >= 64){
			cout << "64" << endl;
			//return 0;
		}else{
	
//	rep(i,arr.size()){
			for(int i = 0; i < arr.size(); i++){
				//cout << i << endl;
				if(n < arr[i]){
					cout << arr[i-1] << endl;
					break;
					//return 0;
				}	
			}
		}

	//}
	
	return 0;
}


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

using namespace std;

int main() {
    char s[1000000];
    stack <char> st;
    int i, n;

    for (i=0, n=0; (s[i]=getchar()) != '\n';i++) {
        if (s[i] != 'x')    n++;
    }
    s[i] = '\0';

    //cout << n;
    
    int count;
    for (i=0, count=0; count<(n+1)/2; i++) {
        st.push(s[i]);
        if (s[i] != 'x') count++;
    }
    if (n%2)    st.pop();
    else        while(s[i] == 'x') i++;
    
    if (count == 0) {
        printf("0\n");
        return 0;
    }
    //cout << st.top() << st.size() <<  endl;

    int res = 0;
    while (s[i] != '\0') {
        if (st.empty()) {
            if (s[i] == 'x') {
                res++;
                i++;
            }
            else {
                res = -1;
                break;
            }
        }
        else if (s[i] == 'x') {
            if (st.top() == 'x') {
                st.pop();
                i++;
            }
            else {
                res++;
                i++;
            }
        }
        else {
            if (st.top() == 'x') {
                st.pop();
                res++;
            }
            else if (st.top() == s[i]) {
                st.pop();
                i++;
            }
            else {
                res = -1;
                break;
            }
        }
    }

    while (!st.empty()) {
        if (st.top() != 'x') {
            res = -1;
            break;
        }
        res++;
        st.pop();
    }

    printf("%d\n", res);

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  cin >>n;
  long long int a[n];
  map<long long int,int>mp;
  for(int i=0;i<n;i++){
    cin >>a[i];
    mp[a[i]]++;
  }
  int ans=0;
  for(auto p:mp){
    if(p.second<p.first)ans+=p.second;
    if(p.second>p.first)ans+=p.second-p.first;
  }
  cout << ans <<endl;
}

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

int main(){
	int N, M;
	cin >> N >> M;
	dsu d(N);
	for(int i = 0; i < M; i++){
		int a, b;
		cin >> a >> b;
		d.merge(a-1, b-1);
	}
	cout << d.groups().size() - 1 << endl;
	return 0;
}

Measured memory_bytes: 9004
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=b[a[0]-1]
for i in range(1,n):
  eat=a[i]
  ans+=b[a[i]-1]
  if a[i]-a[i-1]==1:
    ans+=c[a[i-1]-1]
print(ans)


Measured memory_bytes: 38384
N=int(input())
A=list(map(int,(input().split())))
Lis=[]
big=10**6
for i in range(len(A)):
	Lis.append(A[i]*big+i+1)
Lis.sort()
ans=""
for i in Lis:
	ans+=str((i%big))+" "
print(ans)

Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    rep(i, n) a[i + 1] += a[i];
    // rep(i, n + 1) cout << a[i] << " "; cout << endl;
    
    map<ll, int> mp;
    ll ans = 0;
    rep(i, n + 1) {
        ans += mp[a[i]];
        ++mp[a[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
const int N=3e5+5,MAX=3e7,MOD=1e9+7;

int n,a,b;
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
    	
 	scanf("%d %d %d",&n,&a,&b);

 	printf("%d\n",min(b,a*n));

}

Measured memory_bytes: 256
(let ((n (read))
      (a (read))
      (m (make-array 5000 :element-type 'integer
                          :adjustable t
                          :initial-element 0))
      (inp 0))
  (setf (aref m 2501) 1)
  (loop repeat n do
        (setf inp (- a (read)))
        (cond ((< inp 0) (loop for i from 1000 upto 4000 do
                               (setf (aref m i) (+ (aref m (- i inp)) (aref m i)))))
              ((> inp 0) (loop for i from 4000 downto 1000 do
                               (setf (aref m i) (+ (aref m (- i inp)) (aref m i)))))
              ((= inp 0) (loop for i upto 4999 do
                               (setf (aref m i) (* 2 (aref m i)))))))
  (format t "~A~%" (- (aref m 2501) 1)))



Measured memory_bytes: 16740