akhauriyash/Code-Regression huggingface dataset:
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(S, T):
    ans = 0
    for i in range(len(S)):
        #print("i:%s, S[i]:%s, T[i]:%s" % (i, S[i], T[i]))
        if S[i] == T[i]:
            ans += 1
    return ans


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    S = parsed_lines[1][0]
    return n, k, S


if not do_submit:
    a, b, c = input_parse("""
    3 1
    ABC
    """)
    print(sol(a, b, c))

    a, b, c = input_parse("""
    4 3
    CABA
    """)
    print(sol(a, b, c))

else:
    # n, k = list(map(int, input().split()))
    # S = input().split()
    S = input()
    T = input()
    print(sol(S, T))
    # S = input().strip()
    # print(sol(S))



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

void _139() {
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == t[i])
            count++;
    }
    cout << count << endl;
}

void _138() {
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

void _137() {
    int a, b;
    cin >> a >> b;

    int add = a + b;
    int mult = a * b;
    int sub = a - b;

    cout << max(add, max(mult, sub)) << endl;
}

void _136() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

void _135() {
    long long a, b;
    cin >> a >> b;

    if (abs(a - b) % 2 != 0)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << (a + b) / 2 << endl;
}

void _134() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

void _133() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)

const int mod = 1e9+7;

int h,w,a,b,ans;
int d[100010];
int fact[500010],inv_fact[500010];

int mod_fact(int n,int mod){
  if(n==0)return 1;
  return mod_fact(n-1,mod)*n%mod;
}

int mod_pow(int x,int k,int mod){
  if(k==0)return 1;
  if(k==1)return x;
  int ret = 1;
  while(k){
    if(k&1)ret=ret*x%mod;
    x=x*x%mod;
    k>>=1;
  }
  return ret;
}

int mod_comb(int n,int r,int mod){
  if(r>n-r)r=n-r;
  if(r==0)return 1;
  int a=1;
  FOR(i,0,r)a=a*((n-i)%mod)%mod;
  int b=mod_pow(mod_fact(r,mod),mod-2,mod);
  return (a%mod)*(b%mod)%mod;
}

signed main(){
  cin>>h>>w>>a>>b;

  fact[0]=fact[1]=1;

  for(int i=2;i<h+w;i++){
    fact[i]=(fact[i-1]*i)%mod;
  }
  for(int i = 0;i<h+w;i++){
    inv_fact[i]=mod_pow(fact[i],mod-2,mod);
  }



  for(int i=b;i<w;i++){
    int temp=((fact[i+h-a-1]*inv_fact[i]%mod)*inv_fact[h-a-1])%mod;
    temp = (temp*((((fact[a+w-i-2]*inv_fact[a-1])%mod)*inv_fact[w-i-1])%mod))%mod;

    ans=(ans+temp)%mod;
  //  cout<<ans<<endl;
  }
  cout<<ans<<endl;




  return 0;
}


Measured memory_bytes: 5888
#幅優先探索(BFS)
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()] # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

from collections import deque
di= [0]*n
def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                di[i] = v
                queue.append(i)
    return d

# 0からの各頂点の距離
d = bfs(0)
print("Yes")
for i in range(1,n):
    print(di[i]+1)
    



Measured memory_bytes: 34880
a,b,c,x,y=map(int,input().split())
cost=0
val=min(x,y)
x-=val
y-=val
if a+b>=2*c:
    cost+=val*2*c
else:
    cost+=val*a
    cost+=val*b
if x:
    cost+=x*min(a,2*c)
if y:
    cost+=y*min(b,2*c)
print(cost)



Measured memory_bytes: 3060
import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(1,50):
  b.append(2**i)
ct=0
check=[1]*n
for i in range(n-1,-1,-1):
  if a[i]==1:
    break
  if check[i]==1 and a[i] not in b:
    check[i]=0
    x=math.floor(math.log2(a[i]))
    x=b[x]-a[i]
    y=bisect.bisect_left(a,x)
    z=bisect.bisect_right(a,x)
    t=bisect.bisect_left(check[y:z],1)+y
    if t!=z:
      check[t]=0
      ct+=1

ctb=0
w=1
for i in range(n):
  if a[i] in b or a[i]==1:
    if a[i]==w:
      if check[i]==1:
        ctb+=1
    else:
      ct+=ctb//2
      w=a[i]
      if check[i]==1:
        ctb=1
      else:
        ctb=0
  else:
    ct+=ctb//2
    ctb=0
ct+=ctb//2

print(ct)

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

int64_t	modpow(int64_t a, int64_t n, const int64_t mod)
{
	int64_t	result = 1;
	while (n) {
		if (n & 1) result = result * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return result;
}

int	main()
{
	const static int64_t	mod = 1000000007;
	int64_t	m, n;
	cin >> m >> n;
	cout << modpow(m, n, mod) << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,K, l;cin>>N>>K;
    vector<int> v;
    for(int i=0; i<N;i++) {
      cin>>l; v.push_back(l);
    }
    sort(v.begin(),v.end(), greater<int>());
    int ans =0;
    for(int i=0; i<K;i++) {
      ans += v[i];
    }

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


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

int main(){
    int n,h,w; cin >> n >> h >> w;
    int c = 0;
    for(int i = 0; i < n; i++){
        int a,b; cin >> a >> b;
        if(a >= h && b >= w) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

n, h = map(int, input().split())
a = []
b = []

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a.sort()
b.sort()

x = a[-1]

count = 0
while(h > 0):    
    if b[-1] > x:
        h -= b.pop()
        count += 1;
        if not b:
            b.append(-100)
    else:
        #h -= a[-1]
        #count += 1;
        count += (h // a[-1])
        h -= a[-1] * (h//a[-1])
        break
if h > 0:
    count += 1
print(count)


Measured memory_bytes: 11296
//g++ -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG template.cpp
#include<bits/stdc++.h>

using namespace std;

void printVector(vector<int> A){
    int n = A.size();
    for(int i = 1; i < n; i++){
        printf(" %d", A[i]);
    }
    printf("\n");
}

int left(int i){
    return 2 * i;
}
int right(int i){
    return 2 * i + 1;
}
int parent(int i){
    return i/2;
}

// 1はじまりの
void maxHeapify(vector<int> &A, int it){
    // printVector(A);
    // printf("%d", A.size());
    if(2 * it > A.size() - 1){
        return;
    }
    if(2 * it == A.size() - 1){
        // printf("test1\n");
        int l = left(it);
        int largest_id = it;
        if(A[largest_id] < A[l]){
            swap(A[largest_id], A[l]);
        }
        return;
    }
    int l = left(it);
    int r = right(it);
    int largest_id = it;

    if(A[largest_id] < A[l]){
        largest_id = l;
    }
    if(A[largest_id] < A[r]){
        largest_id = r;
    }

    if(largest_id != it){
        swap(A[largest_id], A[it]);
        // printf("largest: %d\n", largest_id);
        maxHeapify(A, largest_id);
    }
    return;
}

// 1はじまりのヒープ配列Aを受け取ってMaxHeapにしたものを返す
void buildMaxHeap(vector<int> &A){
    int n = A.size();
    for(int i = n/2; i > 0; i--){
        maxHeapify(A, i);
    }
    return;
}

int main(){
    int n;
    scanf("%d", &n);
    vector<int> A(n + 1);
    for(int i = 1; i <= n; i++){
        scanf("%d", &A[i]);
    }
    //printVector(A);

    buildMaxHeap(A);
    printVector(A);
    return 0;
}


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

using namespace std;

int main() {
    int n; cin >> n;
    if (n == 1) {
        cout << "Yes\n2\n1 1\n1 1" << endl;
        return 0;
    }
    for (int k = 1; k <= n && k <= 500; ++k) {
        vector<vector<int>> s(k);
        int now = 0;

        for (int i = 0; i < k; ++i) {
            for (int j = i + 1; j < k; ++j) {
                s[i].push_back(now);
                s[j].push_back(now);
                ++now;
            }
        }

        if (now == n) {
            cout << "Yes\n";
            cout << k << endl;
            for (auto x : s) {
                cout << x.size() << ' ';
                for (auto y : x)
                    cout << y + 1 << " ";
                cout << '\n';
            }
            return 0;
        }

    }

    cout << "No\n";
}


Measured memory_bytes: 2388
//
// Created on 2020/06/05.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    int q;
    cin>>q;

    vector<vector<int>>g(n,vector<int>());
    for (int i = 1; i < n; ++i) {
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll>root(n,0);
    for (int j = 0; j < q; ++j) {
        int p;
        ll x;
        cin>>p>>x;
        p--;
        root[p] += x;
    }
    queue<pair<int,int>>bfs;
    vector<bool>visit(n,false);
    bfs.push({0,0});
    while(!bfs.empty()){
        int v_n = bfs.front().first;
        int v_last = bfs.front().second;
        bfs.pop();
        visit[v_n] = true;
        root[v_n] += v_last;
        for (int i = 0; i < g[v_n].size() ; ++i) {
            if(visit[g[v_n][i]] == false ){
                bfs.push({g[v_n][i],root[v_n]});
            }
        }
    }

    for (int k = 0; k < n; ++k) {
        cout << root[k] << ( k + 1 < n ? ' ' : '\n' );
    }

    return 0;
}


Measured memory_bytes: 17140
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	string s;
	bool flag;
	int count = 0;

	cin >> s;

	if (s[0] == 'W') {
		flag = true;
	}
	else {
		flag = false;
	}

	FOR(i, 1, s.size()) {
		if (flag == true && s[i] == 'B') {
			flag = false;
			count++;
		}
		else if (flag == false && s[i] == 'W') {
			flag = true;
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

const int INF = 1001001001;

int main() {
	string s;
	cin >> s;
	int ans = INF;
	rep(i, s.size() - 2) {
		int temp = 0;
		temp += (s[i] - '0') * 100;
		temp += (s[i + 1] - '0') * 10;
		temp += s[i + 2] - '0';
		ans = min(ans, abs(temp - 753));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int m, n;
	cin >> m >> n;
	if(m > n){
		cout << n-(m-n) << endl;
	}else{
		cout << n+(n-m) << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
ll l,a,b,m;
ll ans;
ll t10[20];
struct mod_fac{
    private:
        vector<ll> f,i_f;
        int n;ll MOD;
    public:
        void init(int n,ll m){
            MOD=m;
            f.resize(n+1,0);
            i_f.resize(n+1,0);
            f[0]=1;
            rep(i,n){
                f[i+1]=f[i]*(i+1)%MOD;
            }
            i_f[n]=power(f[n],MOD-2);
            per(i,n){
                i_f[i]=(i_f[i+1]*(i+1))%MOD;
            }
        }
        ll power(ll a ,ll x){
            if (x==0) return 1;
            if (x==1) return a%MOD;
            if (x==2) return (a*a)%MOD;
            if (x%2==1) return (a*power(power(a,(x-1)/2),2))%MOD;
            return (power(power(a,x/2),2))%MOD;
        }
        ll fac(int x){
            return f[x];
        }
        ll invfac(int x){
            return i_f[x];
        }
        ll comb(int m,int k){
            if (m<0 or k<0) return 0;
            if (m<k) return 0;
            return (((f[m]*i_f[k])%MOD)*i_f[m-k])%MOD;
        }
};

typedef vector< vector< ll > > mat;
typedef vector< ll > vec;

mat mtmul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
	rep(i, (int)A.size()) {
		rep(k, (int)B.size()) {
			rep(j, (int)B[0].size()) {
			    C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % m) % m;
			}
		}
	}
	return C;
}
mat mtpow(mat A, ll n) {
	mat B(A.size(), vec(A.size()));
	rep(i, (int)A.size()) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n&(ll)1)B = mtmul(B, A);
		A = mtmul(A, A);
		n >>= 1;
	}
	return B;
}

void solve(){
    cin >> l >> a >> b >> m;
    t10[0]=1;
    rep(i,19) t10[i+1]=t10[i]*10ll;
    ll _min=0,_max=-1;
    mat A,B,v;
    rep(d,19){
        if (t10[d+1]-a-1<0) continue;
        _min=max((t10[d]-a+b-1)/b,0ll);
        _max=min((t10[d+1]-a-1)/b,l-1);
        if (_min>l-1) break;
        if (_max<0) continue;
        A = { {t10[d+1]%m,0ll,0ll},{1ll,1ll,0ll},{0ll,b,1ll} };
        v = { {ans,(a+(b*_min)%m)%m,1ll} };
        B = mtpow(A,_max-_min+1);
        v = mtmul(v,B);
        ans = v[0][0];
        //cout << ans << endl;
    }

    cout << ans << endl;
}


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

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];
        for(int n=0;n<N;n++) array[n]=sc.nextInt();
        
        int total = 1;
        int odd  =  1;
        for(int n=0;n<N;n++){
        	total *= 3;
        	if(array[n]%2==0) odd*=2;
        }
        
        System.out.println(total-odd);
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

int main() {
	int X, Y; cin >> X >> Y;
	cout << abs(X - Y) << endl;

	return 0;
}



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

int main(){
   Long h,n;
   cin >> h >> n;
   Long o = 0;
   for(Long i=0 ; i<n ; ++i) {
      Long x;
      cin >> x;
      o += x;
   }
   if(o>=h) cout << "Yes";
   else cout << "No";
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val k = scn.nextInt()
	val ps = IntArray(n){scn.nextInt()}
	var sum = 0
	for (i in 0 until k){
		sum += ps[i]
	}
	var max = Pair(0, sum)
	for (i in k until ps.size){
		sum -= ps[i-k]
		sum += ps[i]
		if (sum>max.second){
			max = Pair(i-k+1, sum)
		}
	}
	print((max.first until max.first+k).sumByDouble { (ps[it]+1.0)/2 })
}

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

int main(){
	int n,a1;
	cin>>n;
	vector <int> a(n), pre(n), suf(n);
	for(a1=0;a1<n;++a1){	
		cin>>a[a1];
		if(a1==0) pre[0]=a[0];
		else pre[a1]=__gcd(pre[a1-1],a[a1]);
	}
	for(a1=n-1;a1>=0;--a1){
		if(a1==n-1) suf[n-1]=a[n-1];
		else suf[a1]=__gcd(suf[a1+1],a[a1]);
	}
	int ans=max(pre[n-2],suf[1]);
	for(a1=1;a1<=n-2;++a1){
		ans=max(ans,__gcd(pre[a1-1],suf[a1+1]));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>h(n);
    rep(i,n)cin>>h[i];
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    k=min(n,k);
    rep(i,k)h[i]=0;
    ll sum=0;
    rep(i,n)sum+=h[i];
    cout<<sum<<endl;
    }


Measured memory_bytes: 4824
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

struct UnionFind{
    vector<int> rank,p;
    UnionFind(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i = 0; i < size; i++){
            p[i] = i;
            rank[i] = 0;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
        }else{
            p[rx] = ry;
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
    }
};


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

    UnionFind uf(n);

    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x,y);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.same(i,p[i])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	int checkTable[50001] ={};
	bool bEven;

	scanf( "%d", &n );

	bEven = ( n % 2 == 0 );

	for (int i=0; i < (n+1)/2; i++)
	{
		checkTable[i] = 2;
	}

	if (bEven == false)
	{
		checkTable[0]--;
	}

	for (int i=0, a; i < n; i++)
	{
		scanf( "%d", &a );

		checkTable[a / 2]--;
	}

	for (int i=0; i < ( n + 1 ) / 2; i++)
	{
		if (checkTable[i] != 0)
		{
			printf( "0" );
			return 0;
		}
	}

	int value = 1;

	for (int i=0; i < ( n / 2 ); i++)
	{
		value *= 2;

		if (value >= 1000000007)
		{
			value -= 1000000007;
		}
	}

	printf( "%d", value );

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int w[100];
int s[100];

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
    }

    int acc = 0;
    for (int i = 0; i < n; i++)
    {
        acc += w[i];
        s[i] = acc;
    }

    int m = 100 * 100;
    for (int i = 0; i < n - 1; i++)
    {
        int s1, s2;

        s1 = s[i];
        s2 = s[n - 1] - s[i];

        m = min(m, abs(s1 - s2));
    }

    cout << m << 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;
int mod = 1000000007;

int main(void){
    //N+1日目に試合をしているペアについて考える
    //N日目には試合が出来なかった -> 他の人と試合をしていたか、試合が終わるのを待たされていた
    //両方待たされていたということは無い because 両方待たずに試合をすればいい
    //よってN+1日目に試合をするペアのどちらかはN日目に試合をしている
    //N日目に試合をした人について探索すればいい
    int N; cin >> N;
    int game[N+1][N-1];
    for(int i = 1; i <= N; i++){
        rep(j, N-1) cin >> game[i][j];
    }
    vector<int> play; //N日目に試合をした人
    int idx[N+1] = {}; //選手iが次に試合をするのはgame[i][idx[i]];

    //1日目に試合をする人
    bool use[N+1] = {}; //その日は既に試合をしている
    for(int i = 1; i <= N; i++){
        int aite = game[i][idx[i]]; //対戦相手
        if(use[i] || use[aite]) continue; //一方が既に試合をしていたらスキップ
        else if(i == game[aite][idx[aite]]){
            play.push_back(i);
            play.push_back(aite);
            use[i] = true; use[aite] = true;
        }
    }
    rep(i, N+1) use[i] = false;

    //2日目以降
    int max_day = N*(N-1)/2;
    for(int i = 1; i < max_day+1; i++){
        //playの全要素を探索
        //まず,i日目に試合した人のidxを進める
        rep(j, play.size()){
            idx[play[j]]++;
        }

        //終了判定 play.empty()でいいのでは?
        bool fin = true;
        for(int j = 1; j <= N; j++){
            if(idx[j] != N-1){
                fin = false;
            }
        }
        if(fin){
            cout << i << endl;
            return 0;
        }

        //試合する人探索
        vector<int> temp;
        rep(j, play.size()){
            int me = play[j];
            if(idx[me] == N-1) continue;
            int aite = game[me][idx[me]];
            if(idx[aite] == N-1) continue;
            if(use[me] || use[aite]) continue;
            else if(me == game[aite][idx[aite]]){
                temp.push_back(me);
                temp.push_back(aite);
                use[me] = true; use[aite] = true;
            }
        }
        play = temp;

        //rep(j, play.size()) cout << play[j] << " "; cout << endl;

        //後始末
        rep(j, N+1) use[j] = false;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

//typedef __int64 lint;

const double EPS = 1e-10;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int INF = 1001001001;
//const lint INFLL = (__int64)1001001001001001001;

#define clear(a) memset((a), 0, sizeof(a))
#define mclear(a) memset((a), -1, sizeof(a))

#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main()
{
	int s = 0;
	int cost[] = {6000, 4000, 3000, 2000};
	for (int i = 0; i < 4; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		printf("%d\n", y * cost[x - 1]);
	}
	
	return (0);
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
 
main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) cout << "No\n";
	else if (4ull * a * b < -2ull * a * c + a * a - 2ull * b * c + b * b + c * c + 2ull * a * b) cout << "Yes\n";
	else cout << "No\n";
}


Measured memory_bytes: 256
import math
N = int(input())

t = 0
a = 0
for i in range(N):
    T, A = map(int, input().split())
    if i == 0:
        t += T
        a += A
        continue
    if (T >= t and A >= a):
        t = T
        a = A
        continue

    max_ta = max(t, a)
    g = math.gcd(t, a)
    tg, ag = t // g, a // g
    if (T, A) != (tg, ag):
        sum_t, sum_a = T * max_ta, A * max_ta
        # print(sum_t, sum_a)

        cout_sn = min((sum_t - t) // T, (sum_a - a) // A)
        # while True:
        sum_t -= T * cout_sn
        sum_a -= A * cout_sn
        # if sum_t < t or sum_a < a:
        #     sum_t += T
        #     sum_a += A
        #     break
        t = sum_t
        a = sum_a
        continue

print(t + a)


Measured memory_bytes: 73320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1000000000;
int main(){
    int n;
    cin>>n;
    ll ans=0;
    ll mi=INF;
    bool f=true;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        ans+=a;
        if(a==b){
            continue;
        }
        f=false;
        if(a>b){
            mi=min(mi,b);
        }
    }
    if(f){
        ans=0;
    }else{
        ans-=mi;
    }
    cout<<ans<<endl;
    getchar();
    getchar();
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 18;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int N, M;
	scanf("%d", &N);
	scanf("%d", &M);
	char S[100001];
	scanf("%s", S);


	if (M == 1) {
		int OK = 1;
		rep(i, N + 1) if (S[i] == '1') OK = 0;
		if (OK) {
			rep(i, N) {
				*di++ = '1';
				*di++ = ' ';
			}
		}
		else {
			*di++ = '-';
			*di++ = '1';
			*di++ = '\n';
		}
	}
	else {
		int kotae[100001];
		int k = 0;
		for (int i = N; i > 0;) {
			int atta = 0;
			for (int j = max(0, i - M); j < i; j++) {
				if (S[j] == '0') {
					kotae[k++] = i - j;
					i = j;
					atta = 1;
					break;
				}
			}
			if (atta == 0) {
				printf("-1\n");
				return 0;
			}
		}
		for (int i = k - 1; i >= 0; i--) {
			putint(kotae[i]);
		}
	}

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

	Would you please return 0;
}

Measured memory_bytes: 640
import time
import random
def calc(a) :
    sum = 0
    for i in range(len(a) - 1):
        sum += abs(a[i + 1] - a[i])
    return sum

def crossList(a,b):
    y = []
    if len(a) > len(b):
        for i in range(len(b)):
            y.append(a[i])
            y.append(b[i])
        y.append(a[i+1])
    elif len(a) < len(b): 
        for i in range(len(a)):
            y.append(b[i])
            y.append(a[i])
        y.append(b[i+1])
    else :
        for i in range(len(a)):
            y.append(b[i])
            y.append(a[i])
    return y

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()
b = []
c = []
if len(a) % 2 == 1:
    b = a[0:int((len(a) - 1)/2) ]
    c = a[int((len(a) - 1)/2) : len(a)]
else :
    b = a[0:int((len(a) )/2)  ]
    c = a[int((len(a) )/2) : len(a)]
c.reverse()
d = []
e = []
forward = True;
for i in range(len(b)):
    if forward:
        d.append(b[i])
    else :
        d.insert(0,b[i])
    forward = not forward
forward = True

for i in range(len(c)):
    if forward:
        e.append(c[i])
    else :
        e.insert(0,c[i])
    forward = not forward

h = d[:]
j = e[:]
if len(a) % 2 == 1:
    if (len(h) % 2 == 0) :
        h.append(j.pop(-1))
    else:
        h.insert(0,j.pop(0))

print(max(calc(crossList(d,e)),calc(crossList(d[::-1],e[::-1])),
          calc(crossList(d,e[::-1])),calc(crossList(d[::-1],e)),
          calc(crossList(h[::-1],j[::-1])),calc(crossList(h,j[::-1])),
          calc(crossList(h[::-1],j)),calc(crossList(h,j))))



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

long long int h[11];
string in;
long long int l[4][4] = { { 0, 0, 0, 1 }, { 0, 1, 1, 1 }, { 1, 1, 0, 1 }, { 1, 0, 0, 1 } };

pair< long long int, long long int > kansu( long long int n ) {

  long long int hitei = 0;
  long long int k[2];
  long long int b = 0;
  long long int e;

  while( true ) {

    if ( in[n] == '-' && in[n+1] != '>' ) {
      hitei ^= 1;
      n++;
    }else if ( in[n] == '*' ) {
      e = 0;
      n++;
    }else if ( in[n] == '+' ) {
      e = 1;
      n++;
    }else if ( in[n] == '-' ) {
      e = 2;
      n += 2;
    }else if ( in[n] == '=' ) {
      e = 3;
      n++;
    }else if ( in[n] == ')' ) {
      if ( hitei == 1 ) k[0] ^= 1;
      return make_pair( k[0], n );
    }else {
      if ( in[n] == '(' ) {
	pair< long long int, long long int > p = kansu( n + 1 );
	k[b] = p.first;
	n = p.second + 1;
      }else if ( in[n] == 'T' ) {
	k[b] = 1;
	n++;
      }else if ( in[n] == 'F' ) {
	k[b] = 0;
	n++;
      }else {
	k[b] = h[ in[n] - 'a' ];
	n++;
      }
      if ( hitei == 1 ) k[b] ^= 1;
      if ( b == 0 ) {
	b++;
	hitei = 0;
      }else {
	//	cout << k[0] << " " << e << " " << k[1] << " = " << l[e][ k[0] * 2 + k[1] ] << endl;
	return make_pair( l[e][ k[0] * 2 + k[1] ], n );
      }
    }

  }

}

int main() {

  while( true ) {

    cin >> in;
    if ( in == "#" ) break;

    bool b = true;

    for ( long long int i = 0; i < (1<<11); i++ ) {
      long long int k = i;
      for ( long long int j = 0; j < 11; j++ ) {
	h[j] = k % 2;
	k /= 2;
      }
      if ( kansu( 0 ).first == 0 ) {
	b = false;
	break;
      }
    }
    if ( b == true ) {
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1184
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <iterator>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

long long int ncount = 0;
long long int pcount = 0;
long long int n,x;
long long int pmemo[51] = {0};//countp
long long int lmemo[51] = {0};//length

void burger(int lv){
  // cout << lv << endl;
  if(pmemo[lv]!=0) return;
  burger(lv-1);
  pmemo[lv] = pmemo[lv-1]*2 + 1;
  lmemo[lv] = lmemo[lv-1]*2 + 3;
  return;
}

void countP(int lv) {
  if(ncount>=x) return;
  if (lmemo[lv] > x - ncount) {
    ncount ++;//B
    if(ncount>=x) return;
    countP(lv-1);
    if(ncount>=x) return;
    ncount ++;pcount ++;//P
    if(ncount>=x) return;
    countP(lv-1);
    ncount ++;//B
    if(ncount>=x) return;
  }else{
    pcount += pmemo[lv];//Lv
    ncount += lmemo[lv];
  }
}

int main(){
  ios::sync_with_stdio(false);
	cin.tie(0);
  pmemo[0] = 1;
  lmemo[0] = 1;
  cin >> n >> x;
  burger(n);
  countP(n);
  // cout << pmemo[n] << endl;
  // cout << lmemo[n] << endl;
  cout << pcount << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define bug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define bugv(x) do{cerr<#x<<': "';for(auto&e:x)cerr<<e<<" ";cerr<<"\n";}while(0)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)

using namespace std;
using ll=long long;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  string s; cin >> s;
  rep(i,0,3) if (s[i]<'0' or s[i]>'9' or s.size()!=4) END("NA\n");
  int a = (s[0]-'0')*10+s[1]-'0';
  int b = (s[2]-'0')*10+s[3]-'0';
  if(a>0 and a<=12 and b>0 and b<12) END("AMBIGUOUS");
  if( (a>0 and a<=12) or (b>0 and b<=12)) {
    if (a==0 or a>12) END("YYMM");
    if (b==0 or b>12) END("MMYY");
    END("AMBIGUOUS");
  } else END("NA\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;

int main(int argc,char const* argv[])
{
  int n,k;
  cin >> n >> k;
  if(n%k==0)
    {
      cout << 0 << endl;
    }
  else
    {
      cout << 1 << endl;
    }
  return 0;
}


Measured memory_bytes: 256
p = input()
flag=0
L = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r",\
     "s","t","u","v","w","x","y","z"]
for i in L:
    if p == i:
        flag +=1
if flag == 0:
    print("A")
else:
    print("a")

Measured memory_bytes: 9124
def examA():
    N = I()
    A = [0]*N; B = [0]*N
    for i in range(N):
        A[i], B[i] = LI()
    cum = 0
    for i in range(N)[::-1]:
        cum +=(-(cum+A[i]))%B[i]
        #print(cum)

    ans = cum
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 43868
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
//
struct edge{int to;int cost;};
struct dijkstra{
	//
	int v;
	vector<edge> G[100000];
	vector<int> D;
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > que;
	//
	dijkstra(int n){
		D.resize(n);
		fill(D.begin(),D.end(),1e9+7);
	}
	//
	void add_edge(int from,int to,int cost){
		G[from].push_back((edge){to,cost});
	}
	//
	vector<int> dist(int s){
		D[s]=0;
		que.push(make_pair(0,s));
		while(!que.empty()){
			pair<int,int> p=que.top();que.pop();
			int vv=p.second;
			if(D[vv]<p.first){
				continue;
			}else{
				for(int i=0;i<G[vv].size();i++){
					edge &e=G[vv][i];
					if(D[e.to]>D[vv]+e.cost){
						D[e.to]=D[vv]+e.cost;
						que.push(make_pair(D[e.to],e.to));
					}
				}
			}
		}
		return D;
	}
};
int main(){
	int V,E,r;
	cin>>V>>E>>r;
	dijkstra di(V);
	for(int i=0;i<E;i++){
		int s,t,d;
		cin>>s>>t>>d;
		di.add_edge(s,t,d);
	}
	vector<int> ans=di.dist(r);
	for(int i=0;i<V;i++){
		if(ans[i]==1e9+7){
			cout<<"INF"<<endl;
		}else{
			cout<<ans[i]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 12940
#include <iostream>
using namespace std;
int main()
{
long long a,b,x,y,s=0;
cin>>a>>b;
for(int i=0;i<a;i++){
cin>>x>>y;
if(x*x+y*y<=b*b) s++;
}
 cout<<s;
 return 0;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
using namespace std;
int n,maxn=0,ans;
char s[101],ch;
set<char> a,b,c;
int main(){
	scanf("%d",&n);
	scanf("%c",&ch);
	for(int i=1;i<=n;i++){
		scanf("%c",&s[i]);
		c.insert(s[i]);
	} 
	for(int i=1;i<=n;i++){
		a.clear();b.clear();
		for(int j=1;j<=i;j++){
			a.insert(s[j]);
		}
		for(int j=i+1;j<=n;j++){
			b.insert(s[j]);
		}
		ans=a.size()+b.size()-c.size();
		maxn=max(maxn,ans);
	}
	printf("%d",maxn);
	return 0;
} 

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $X, $N);
$p = fgets(STDIN);
$array = explode(" ", $p);


for ($i = -2; $i < 103; $i++) {
  $base[] = $i;
}


foreach ($base as $key => $val) {
  foreach ($array as $a) {
    if($val == $a){
      //削除実行

      unset($base[$key]);
    }
  }
}


$ans = 1000;
$sa = 1000;
foreach ($base as $key => $value) {
  if (abs($value - $X) < $sa) {
    $sa = abs($value - $X);
    $ans = $value;
  } elseif (abs($value - $X) === $sa) {
    if ($ans > $value) {
      $ans = $value;
    }
  }
}



print_r ($ans);
?>

Measured memory_bytes: 16080
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 998244353;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 2100;

string s;

int n;
int cc[MAXN][2];

ll dp[MAXN][MAXN];

void add(ll &a, ll b) {
	a = (a + b) % MOD;
}

ll cnk[MAXN][MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	for (int i = 0; i < MAXN; ++i)
		for (int j = 0; j < MAXN; ++j) {
			if (i == j || j == 0)
				cnk[i][j] = 1;
			else if (j > i)
				cnk[i][j] = 0;
			else
				cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % MOD;
		}
	cin >> s;
	n = s.size();
	for (int i = 0; i < n; ++i)
		cc[i + 1][0] = cc[i][0] + 2 - (s[i] - '0');
	for (int i = 0; i < n; ++i)
		cc[i + 1][1] = cc[i][1] + (s[i] - '0');
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= i; ++j) {
			if (i - j + 1 <= cc[i + 1][0])
				add(dp[i + 1][j], dp[i][j]);
			if (j + 1 <= cc[i + 1][1])
				add(dp[i + 1][j + 1], dp[i][j]);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (dp[n][i]) {
			add(ans, dp[n][i] * cnk[n][cc[n][1] - i]);
		}
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 67840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int w = sc.nextInt();
			int n = sc.nextInt();
			int[] values = new int[w];
			for (int i = 0; i < values.length; i++) {
				values[i] = i + 1;
			}
			for (int i = 0; i < n; i++) {
				String str = sc.next();
				String[] ab = str.split(",");
				int a = Integer.parseInt(ab[0]) - 1;
				int b = Integer.parseInt(ab[1]) - 1;
				int swap;
				swap = values[a];
				values[a] = values[b];
				values[b] = swap;
				swap = 0;
			}
			for (int i = 0; i < w; i++) {
				System.out.println(values[i]);
			}
		}
	}
}


Measured memory_bytes: 26172
#include<iostream>
#include<vector>

using namespace std;
//记录移动次数
long long cnt;
vector<int> G;

void insertionSort(int A[],int n,int g)
{
    int i,j,v;
    for(i=g;i<n;i++)
    {
        v=A[i];
        j=i-g;
        while(j>=0&&A[j]>v)
        {
            A[j+g]=A[j];
            j=j-g;
            cnt++;
        }
        A[j+g]=v;
    }
}
void shellSort(int A[],int n)
{
    cnt=0;
    int h;
    for(h=1;;)
    {
        if(h>n)
            break;
        G.push_back(h);
        h=3*h+1;
    }
    for(int i=G.size()-1;i>=0;i--)
    {
        insertionSort(A,n,G[i]);
    }
}
int main()
{
    int n,tmp,A[1000000];
    //vector<int> A;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        //scanf("%d",&A[i]);
        //cin>>tmp;
        //A.push_back(tmp);
        cin>>A[i];
    }
    cnt=0;
    shellSort(A,n);
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;i--)
    {
        cout<<G[i];
        if(i)
            cout<<" ";

    }
    cout<<endl<<cnt<<endl;
    for(int i=0;i<n;i++)
    {
        cout<<A[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 6976
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char dif = 'A' - 'a';
    cout << char(s1[0]+dif) << char(s2[0]+dif) << char(s3[0]+dif) << endl;



    return 0;
}



Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
string s;
int n;
// const int maxn 
bool check(int mid){
	map<string,int> mp;
	repa(i,mid,n){
		string b;
		repa(j,i-mid+1,i+1){
			b.pb(s[j]);
		}
		if(i-2*mid+1>=0){
			string c;
			repa(j,i-2*mid+1,i-mid+1){
				c.pb(s[j]);
			}
			// cout<<c<<"*\n";
			mp[c]++;
		}
		// cout<<b<<"\n";
		if(mp[b] >= 1){
			return true;
		}
	}
	return false;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	cin>>s;
	// cout<<s<<"\n";
	int l = 1;
	int r = n/2;
	int ans = 0;
	// cout<<check(2)<<"\n";
	while(l <= r){
		int mid = (l+r)/2;
		if(check(mid)){
			ans = mid;
			l = mid+1;
		}
		else{
			r = mid-1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9836
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    double a, b, h, m; cin >> a >> b >> h >> m;
    double h_theta = 30 * h + m / 2;
    double m_theta = 6 * m;

    double tmp = abs(h_theta - m_theta);
    double theta = min(tmp, 360 - tmp) * PI / 180;
    cout.precision(12);
    cout << fixed;
    cout << sqrt((a * sin(theta)) * (a * sin(theta)) + (b - a * cos(theta)) * (b - a * cos(theta))) << '\n';

    // cout << h_theta << ' ' << m_theta << '\n';

    return 0;
}


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

#define INF 1000000000
#define min(x, y) (((x) < (y)) ? (x) : (y))

int solv(int n, int k, int *h) {
  int i, j, d[100000], t;

  for (i = 0; i < 100000; i++) {
    d[i] = INF;
  }
  d[0] = 0;

  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j <= i + k && j < n; j++) {
      t = d[i] + abs(h[i] - h[j]);
      d[j] = min(d[j], t);
    }
  }

  return d[n - 1];
}

int main(int argc, char **argv) {
  int i, n, k, h[100000];

  while (scanf("%d %d", &n, &k) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%d", h + i);
    }

    printf("%d\n", solv(n, k, h));
  }

  return 0;
}


Measured memory_bytes: 896
//This template belongs to Juan Carlo Vieri
#include <bits/stdc++.h>
using namespace std;

typedef int_fast64_t ll;
typedef long double ld;
typedef int_fast64_t intt;
typedef int_fast64_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, cmp1, cmp2) for (tmp_m i = cmp1; i < cmp2; ++i)
#define repp(i, cmp1, cmp2) for (tmp_m i = cmp1; i >= cmp2; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const ld pi = acos(-1.0);
const intt mod = 998244353;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst < cmp2.dst;
    if (x != cmp2.x) return x < cmp2.x;
    return y < cmp2.y;
  }
  inline bool operator==(const pr& cmp2) const {
    return (cmp2.dst == dst) && (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst > cmp2.dst;
    if (x != cmp2.x) return x > cmp2.x;
    return y > cmp2.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x < x;
    return cmp2.y < y;
  }
  inline bool operator==(const point& cmp2) const {
    return (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x > x;
    return cmp2.y > y;
  }
};

class prHash {
 public:
  size_t operator()(const pr& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y)) ^
           (hash<intt>()(cmp1.dst));
  }
};

class pointHash {
 public:
  size_t operator()(const point& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y));
  }
};

inline bool spoint(const point& cmp1, const point& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

inline bool spr(const pr& cmp1, const pr& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.dst != cmp2.dst) return cmp1.dst < cmp2.dst;
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

ll modex(ll b , ll e , ll m) {
  ll r = 1;
  while (e > 0) {
    if ((e & 1) == 1) {
      r = (r * b) % m;
    }
    e >>= 1;
    b = (b * b) % m;
  }
  return (ll) r;
}

intt fak[200005], inv[200005];

void solve() {
  intt n, m, k;
  cin >> n >> m >> k;
  fak[0] = 1;
  inv[0] = 1;
  rep(i, 1, n + 3){
    fak[i] = fak[i - 1] * i % mod;
    inv[i] = modex(fak[i], mod - 2, mod) % mod;
  }
  intt ans = 0;
  rep(i, 0, k + 1){
    intt temp = m;
    temp = temp * modex(m - 1, n - i - 1, mod) % mod;
    temp = temp * fak[n - 1] % mod * inv[i] % mod * inv[n - 1 - i] % mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

int main() {
  init();
  solve();
  return 0;
}


Measured memory_bytes: 6740
l=[]
e=[]
m,n=map(int,input().split())
for i in range(m):
  ab=list(map(int,input().split()))
  l.append(ab)

for c in l:
    if c[1]<=n:
        e.append(c[0])

if not e:
   print("TLE")
else: 
    print(min(e))

Measured memory_bytes: 3060