akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return


template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int) 1e18
vector<int> v;
int x, n, aux;
bool flag = false;

void solve(){
	cin >> x >> n;
	for(int i = 0; i < n;i++){
  		cin >> aux;
  		v.pb(aux);
  		if(v[i] == x){
  			flag = true;
	  	}
	}
	if(n == 0	|| 	flag == false){
		cout << x << endl;
	  	return;
	}
	sort(v.begin(),v.end());
	int i = 1;
	while(true){
		if(!binary_search(v.begin(),v.end(),x-i)){
			cout << x - i << endl;
			return;
		}
		else if(!binary_search(v.begin(),v.end(),x+i)){
			cout << x + i << endl;
			return;
 		}
 		i++;
	}
}
int main(){_
    solve();
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

class B {
	int N;
public:
	void solve()
	{
		int left, right;
		int ans{ 0 };
		for (int i{ 0 }; i < N; i++)
		{
			cin >> left >> right;
			ans += (right - left + 1);
		}

		cout << ans << endl;
	}

	B() { cin >> N; }
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#coding: euc-jp
class Main
  def self.main
    min = 10
    cnt = 0
    5.times do
      a = read
      min = a % 10 if (a - 1) % 10 < (min - 1) % 10
      cnt += (a / 10) * 10 + (a % 10 == 0 ? 0 : 10)
    end
    cnt -= 10 - min
    puts cnt
  end

  def self.read
    gets.chomp.to_i
  end
end

Main.main


Measured memory_bytes: 1788
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	if A == B + C{
		fmt.Println("Yes")
	}else if B == A+C {
		fmt.Println("Yes")
	}else if C == A+B {
		fmt.Println("Yes")
	}else {
		fmt.Println("No")
	}



}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    map<char, int> cnt;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char a;
            cin >> a;
            cnt[a]++;
        }
    }
    int cnt_4 = (h/2)*(w/2);
    int cnt_2, cnt_1;
    if((h*w)%2 == 1) cnt_1 = 1;
    else cnt_1 = 0;
    cnt_2 = (h*w - cnt_4*4 - cnt_1)/2;
    vector<int> v;
    for(auto p : cnt){
        v.push_back(p.second);
    }
    for(auto p : v){
        while(p-4 >= 0 && cnt_4 > 0){
            p -= 4;
            cnt_4--;
        }
        while(p-2 >= 0 && cnt_2 > 0){
            p -= 2;
            cnt_2--;
        }
        while(p-1 >= 0 && cnt_1 > 0){
            p--;
            cnt_1--;
        }
    }
    if(cnt_1 == 0 && cnt_2 == 0 && cnt_4 == 0)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
	n=list(raw_input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print "NA"
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print count
			break
		l=sorted(n)[::-1]
		s=sorted(n)[n.count("0"):]
		n=list(str(int("".join(map(str,l)))-int("".join(map(str,s)))))
		for i in range(4-len(n)):
			n.insert(0,"0")
		count+=1

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int i,o,t,j,l,s,z;
  cin>>i>>o>>t>>j>>l>>s>>z;
  ll ans = 0;
  ans = o;
  // I J L
  ans += i - (i%2);
  ans += j - (j%2);
  ans += l - (l%2);
  int a = i%2, b = j%2, c = l%2;
  if(a+b+c==3){
    ans += 3;
  }else if(a+b+c==2){
    if(a==0){
      //
      if(i >= 2)ans++;
    }else if(b==0){
      //
      if(j>=2)ans++;
    }else{
      // c==0
      if(l>=2)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2000050;
//↑templete
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
//%MOD下での階乗
ll ex[SIZE]={1,0};
//%MOD下での階乗の逆数
ll inv[SIZE]={1,0};
ll func(ll a, ll b){
	ll ret=0;
	for(int i=1;i<=b+1;i++)
		(ret+=ex[a+i]*inv[a]%MOD*inv[i]%MOD)%=MOD;
	return ret;
}
signed main(){
	for(int i=1;i<SIZE;i++){
		ex[i]=ex[i-1]*i%MOD;
	}
	for(int i=1;i<SIZE;i++){
		inv[i]=mod_pow(i,MOD-2,MOD);
	}
	for(int i=1;i<SIZE;i++){
		inv[i]=inv[i-1]*inv[i]%MOD;
	}

	ll r1, c1, r2, c2;
	cin>>r1>>c1>>r2>>c2;

	cout<<((func(r2, c2)+MOD-func(r1-1, c2))%MOD+MOD-func(r2, c1-1)+func(r1-1, c1-1))%MOD<<endl;

	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int main() {
    string s;
    cin >> s;
    string ostr = "Heisei";
    string m = s.substr(5,2);
    int mm = stoi(m);
    if (mm > 4)
        cout << "TBD" << endl;
    else
        cout << ostr << endl;

    return 0;
}


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

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

  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }
  
  return 0;
}


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

typedef struct _c {
        int x,y,r;
}circle;

const double LIT=1e-6;

circle p1[2000],p2[2000];
int dp1[2000], dp2[2000];

int cmp(const void *a, const void *b) {
        return (((const circle*)a)->r)-(((const circle*)b)->r);
}

double dis(circle a, circle b) {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int c_isin(circle a, circle b) {
        return dis(a,b)+LIT<abs(a.r-b.r);
}

int p_isin(int x, int y, circle b) {
        circle a;
        a.x=x;a.y=y;a.r=0;
        return c_isin(a,b);
}

int touch(circle a, circle b) {
        double d = dis(a,b);
        return d-LIT<abs(a.r+b.r);
}

int max(int a,int b) {
        return (a>b)?a:b;
}

void lis(int dp[], circle t[], int n) {
        int i,j,k,l;
        memset(dp, 0, sizeof(dp));
        qsort(t+1,n,sizeof(circle), cmp);
        for(i=1;i<=n;i++) {
                dp[i] = 1;
                for(j=1;j<i;j++) {
                        if(c_isin(t[i],t[j])) {
                                dp[i]=max(dp[i], dp[j]+1);
                        }
                }
        }
}

int main(void) {
        int i,j,k,l,n1,n2,n;
        int sol=0;
        int x,y,r;
        int xs,ys,xt,yt;
        circle t;
        while(1) {
                sol=0;
                scanf("%d", &n);
                if(n==0) {
                        break;
                }
                scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
                n1=0;
                n2=0;
                for(i=1;i<=n;i++) {
                        k=0;l=0;
                        scanf("%d%d%d", &t.x, &t.y, &t.r);
                        k=p_isin(xs,ys, t);
                        l=p_isin(xt,yt,t);
                        if(k&&!l) {
                                p1[++n1]=t;
                        }
                        else if(!k&&l) {
                                p2[++n2]=t;
                        }
                }
                lis(dp1, p1,n1);
                lis(dp2,p2,n2);
                for(i=1;i<=n1;i++) {
                        for(j=1;j<=n2;j++) {
                                if(!touch(p1[i],p2[j])) {
                                        sol=max(sol, dp1[i]+dp2[j]);
                                }
                        }
                }
                for(i=1;i<=n1;i++) {
                        sol=max(sol, dp1[i]);
                }
                for(i=1;i<=n2;i++) {
                        sol=max(sol,dp2[i]);
                }
                printf("%d\n", sol);
        }
        return 0;
}

Measured memory_bytes: 1116
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Card[] c1 = new Card[n];
        Card[] c2 = new Card[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            c1[i] = new Card(); c2[i] = new Card();
            c1[i].suit = t[i].charAt(0);
            c1[i].value = t[i].charAt(1);
        }

        for(int i = 0; i < n; i++) c2[i] = c1[i];

        babble(c1, n);
        selection(c2, n);
        if(isSame(c1, c2, n))System.out.println("Stable");
        else System.out.println("Not stable");
    }

    public static void babble(Card[] a, int n){
        Card temp = new Card();
        for(int i = 0; i < n; i++){
            for(int j = n - 1; j >= i + 1; j--){
                if(a[j].value < a[j-1].value){
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                }
            }
        }
        print(a, n);
        System.out.println("Stable");
    }
 public static void selection(Card[] a, int n){
        Card temp = new Card();
        for(int i = 0; i < n; i++){
            int minj = i;
            for(int j = i; j < n; j++){
                if( a[j].value < a[minj].value) minj = j;
            }
            if(i != minj){
                temp = a[i]; a[i] = a[minj]; a[minj] = temp;
            }
        }
        print(a, n);
    }

    public static void print(Card[] a, int n){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            if(i != 0) sb.append(" ");
            sb.append(a[i].suit).append(a[i].value);
        }
        System.out.println(sb);
    }

    public static boolean isSame(Card[] a, Card[] b, int n){
        for(int i = 0; i < n; i++){
            if(a[i].suit != b[i].suit)return false;
        }
        return true;
    }

}

class Card{
    char suit, value;
    /*Card(char suit, char value){                                                     
        this.suit = suit;                                                              
        this.value = value;                                                            
        }*/
}

Measured memory_bytes: 24204
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<pair<ll, ll>> d(n);
    rep(i, n)
    {
        ll d1, d2;
        cin >> d1 >> d2;
        d[i] = pair<ll, ll>{d1, d2};
    }
    bool result = false;
    ll count = 0;
    rep(i, n)
    {
        if (get<0>(d[i]) == get<1>(d[i]))
        {
            count++;
            if (count == 3)
            {
                result = true;
                break;
            }
        }
        else
        {
            count = 0;
        }
    }
    if (result)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3044
#include<stdio.h>
using namespace std;

int main() {
	int n = 0;
	scanf("%d", &n);
	long long* a = new long long[n];
	long long b = 0;
	long long c = 0;
	for (int i = 0;i < n;i++) {
		  scanf("%lld", &a[i]);
	}
	for (int i = 0;i < n;i++) {
		for (int i = 0;i < n - 1;i++) {
			if (a[i] < a[i + 1]) {
				b = a[i];
				a[i] = a[i + 1];
				a[i + 1] = b;
			}
		}
	}
	for (int i = 0;i < n;i++) {
		c += a[i];
	}
	printf("%lld %lld %lld\n",a[n - 1], a[0], c);
	delete[]a;
	return 0;
}


Measured memory_bytes: 2840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static Integer ct;
	private static Integer len;

	public static void main(String[] args) throws IOException {
		proconScan proScan = new proconScan();
		proScan.scan();

		ct = 0;
		len = proScan.backLine().length();
		Character flag=' ';
		for(Character buf:proScan.backLine().toCharArray()){
			if(flag==' ') flag=buf;
			else if(flag!=buf){
				ct++;
				flag=buf;
			}
			
		}
		System.out.println(ct);
		proScan.proconEnd();
	}
}

class proconScan {
	private BufferedReader br;
	private String inLine;
	private String[] inString;
	private Integer idx;
	private String splitChar;

	public proconScan() {
		br = new BufferedReader(new InputStreamReader(System.in));
		idx = 0;
		splitChar = " ";
	}

	public proconScan(String split) {
		br = new BufferedReader(new InputStreamReader(System.in));
		idx = 0;
		splitChar = split;
	}

	public void proconEnd() throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		br.close();
	}

	public String scan() throws IOException {
		idx = 0;
		inLine = br.readLine();
		inString = inLine.split(splitChar, 0);
		return inLine;
	}

	public Integer scanInteger1() throws IOException {
		scan();
		return Integer.parseInt(inString[0]);
	}

	public String backLine() {
		return inLine;
	}

	public String nextString() {
		return inString[idx++];
	}

	public String[] getString() {
		return inString;
	}

	public Integer nextInteger() {
		Integer num;
		try {
			num = Integer.parseInt(inString[idx++]);
		} catch (NumberFormatException e) {
			num = null;// TODO: handle exception
		}
		return num;
	}

	public Integer[] getInteger() {
		Integer[] num = new Integer[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Integer.parseInt(inString[i]);
		}

		return num;
	}

	public Float nextFloat() {
		Float num;
		try {
			num = Float.parseFloat(inString[idx++]);
		} catch (NumberFormatException e) {
			num = null;// TODO: handle exception
		}
		return num;
	}

	public Float[] getFloat() {
		Float[] num = new Float[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Float.parseFloat(inString[i]);
		}

		return num;
	}

	public Integer getLen() {
		return inString.length;
	}

	public int[] getInt() {
		int[] num = new int[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Integer.parseInt(inString[i]);
		}

		return num;
	}

}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int dp[400][200001];
void solve() {
   int n, k; cin >> n >> k;
   rep(i,n)cin >> dp[0][i];
   int j=0;
   while(k--){
      rep(i,n){
         dp[j+1][max(i-dp[j][i], 0)]++;
         dp[j+1][min(i+dp[j][i]+1, n)]--;
      }
      rep(i,n){
         dp[j+1][i+1] += dp[j+1][i];
      }
      j++;
      if (dp[j][0]==n&&dp[j][n-1]==n)break;
   }
   rep(i,n)cout << dp[j][i] << " ";
}
int main() {
   cin.tie(nullptr); ios::sync_with_stdio(false);
   solve();
}

Measured memory_bytes: 36464
class UnionFind():
    '''
    cited from https://note.nkmk.me/python-union-find/
    '''
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

N, M = map(int, input().split())

u = UnionFind(N)
for i in range(M):
    x, y, z = map(int, input().split())
    u.union(x-1,y-1)
    
print(u.group_count())



Measured memory_bytes: 13732
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 998244353
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<ll> dp(N, 0);
  vector<vector<int>> plus(N + 1), minus(N + 1);
  vector<ll> costs(M);
  FOR(i, M) {
    int L, R, C;
    cin >> L >> R >> C;
    L--;
    R--;
    costs[i] = C;
    plus[L].push_back(i);
    minus[R + 1].push_back(i);
  }
  set<pair<ll, int>> now;
  vector<ll> taiou(M + 1);
  for (int x : plus[0]) {
    now.insert(pair<ll, int>(costs[x], x));
    taiou[x] = costs[x];
  }
  FORIN(i, 1, N) {
    for (int x : minus[i]) {
      now.erase(pair<ll, int>(taiou[x], x));
    }
    if (now.empty()) {
      print(-1);
      return 0;
    }
    dp[i] = now.begin()->first;
    for (int x : plus[i]) {
      now.insert(pair<ll, int>(dp[i] + costs[x], x));
      taiou[x] = dp[i] + costs[x];
    }
  }
  print(dp[N - 1]);
  return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(3 * N);
  rep(i, 3 * N) { cin >> A[i]; }
  sort(A.begin(), A.end());

  int64_t answer = 0;
  for (int i = N; i < 3 * N; i += 2) {
    answer += (int64_t)A[i];
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int w[N][N], b[N][N], zw[N], zb[N], yw[N], yb[N];
int f[N][N], tr[N << 1], a[N << 1];

int lower(int x) {
  return x & (-x);
}

void upd(int x, int k) {
  for(; x < N * 2; x += lower(x)) tr[x] += k;
}

int get(int x) {
  int ans = 0;
  for(; x; x -= lower(x)) ans += tr[x];
  return ans;
}

char lx[10];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 1, x; i <= n * 2; ++i) {
    scanf("%s%d", lx + 1, &x);  
    if(lx[1] == 'B') a[i] = x + n, yb[x] = i;
    else a[i] = x, yw[x] = i;
  }
  for(int i = 2 * n; i >= 1; --i) {
    upd(a[i], 1);
    if(a[i] > n) {
      zb[a[i] - n] = get(a[i] - 1) - get(n);
      for(int j = 1; j <= n; ++j) {
        b[a[i] - n][j] = get(j);
      }
    } else {
      zw[a[i]] = get(a[i] - 1);
      for(int j = 1; j <= n; ++j) {
        w[a[i]][j] = get(j + n) - get(n);
      }
    }
  }
/*  for(int i = 1; i <= n; ++i)
    for(int j = 1; j <= n; ++j) {
      printf("w[%d][%d] = %d\n", i, j, w[i][j]);
    }
  puts("");*/
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  for(int i = 0; i <= n; ++i)
    for(int j = 0; j <= n; ++j) {
      if(i == 0 && j == 0) continue;
      if(i) f[i][j] = min(f[i][j], f[i - 1][j] + yw[i] - (i + j) + zw[i] + w[i][j]);
      if(j) f[i][j] = min(f[i][j], f[i][j - 1] + yb[j] - (i + j) + zb[j] + b[j][i]);
    }
  printf("%d\n", f[n][n]);
  return 0;
}

Measured memory_bytes: 47616
#include<stdio.h>
void input(int *N, char *s, char *t)
{
    scanf("%d", N);
    scanf("%s", s);
    scanf("%s", t);
}
int str_slide_compare(char *str1, char *str2, int num)
{
    for (int i = 0; i < num; i++){
        if(str1[i] != str2[i]){
            return 0;
        }
    }
    return 1;
}
int main(void)
{
    char s[101];
    char t[101];
    int N;

    input(&N, s, t);

    int slide;
    for (slide = 0; slide <= 100; slide++){
        if (str_slide_compare(s + slide, t, N - slide)) {
            break;
        }
    }
    printf("%d\n",slide+N);
}


Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long[] a = new long[n];
		int MOD = 1000000007;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextLong();
		}
		
		// 計算
		long result = 0;
		long[] bit = new long[60];
		for(int i = 0; i < n; i++){
		    String s = Long.toString(a[i], 2);
		    for(int j = 0; j < s.length(); j++){
		        if(s.charAt(s.length()-1-j) == '1') bit[j]++;
		    }
		}
		for(int i = 0; i < bit.length; i++){
		    result += (((1L<<i)%MOD)*(((bit[i])*(n-bit[i]))%MOD))%MOD;
		    //result += (1L<<i)%MOD * bit[i]%MOD * (n-bit[i])%MOD;
		    result %= MOD;
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 136164
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
int main(){
	char a,b;
	cin>>a>>b;
	if(a<b)cout<<"<"<<endl;
	else if(a>b)cout<<">"<<endl;
	else cout<<"="<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[10001];
int a=999999,b;
int main()
{
    cin>>c;
    for(int i=0;i<=105;i++)
    {
        if(c[i]=='C')
        {
            a=i; break;
        }
    }
    for(int i=0;i<=105;i++)
     if(c[i]=='F')
      b=i;
    if(a<b)
     printf("Yes\n");
    else
     printf("No\n");
     return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main()
{   
    string S;
  int K;
 
  cin >> S;
  cin >> K;
 
  rep(i, K) {
    if(S[i] != '1') {
      cout << S[i];
      return 0;
    }
  }
  cout << '1';
    return 0;
}

Measured memory_bytes: 3624
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();
    let s_arr: Vec<char> = buf.trim().chars().collect();

    let len = s_arr.len();
    let mut ans: usize = 0;
    for i in 0..len/2 {
        if s_arr[i] != s_arr[len-1-i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

struct thing {
    pair<string, int> S;
    int index;
};
bool operator<(const thing &x, const thing &y) {
    return x.S < y.S;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<thing> A(N);
    REP(i, N) {
        cin >> A[i].S.first >> A[i].S.second;
        A[i].S.second *= -1;
        A[i].index = i + 1;
    }
    sort(ALL(A));
    REP(i, N) {
        cout << A[i].index << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    def dfs(i, s=[]):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                dfs(i, s + [a])
            a = alphabets[i-1]
            dfs(i+1, s + [a])
    
    dfs(2, s=['a'])
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)


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

#define FOR(type, i, a, b) for (type i = (a); i < (b); ++i)

ll l[51];
ll p[51];

ll solve(int N, ll X) {
  if (X == 0) return 0;
  else if (N == 0) return 1;
  else if (X == l[N]) return p[N];
  else if (X >= l[N]/2+1) return p[N-1]+1 + solve(N-1, X - (l[N]/2+1));
  else if (X > 1) return solve(N-1, X-1);
  else return 0;
}

int main(void) {
  l[0] = 1;
  FOR(int, i, 1, 51) l[i] = l[i-1]*2+3;
  p[0] = 1;
  FOR(int, i, 1, 51) p[i] = p[i-1]*2+1;


  int N; ll X; cin >> N >> X;
  cout << solve(N, X) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define INF INT_MAX
    ll dp[102][100002];
    vector<ll>vec;

    void subsetSum(ll v[],ll V,ll n){
    	bool mat[n+1][V+1];
    	
    	for(int i=0;i<=n;i++){
    		for(int j=0;j<=V;j++){
    			if(j==0)
    				mat[i][j] = true;
    			if(i==0 && j!=0)
    				mat[i][j] = false;
    		}
    	}

    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=V;j++){
    			if(v[i]<=j)
    				mat[i][j] = mat[i-1][j-v[i]] || mat[i-1][j];
    			else
    				mat[i-1][j];
    		}
    	}
    	
    	for(int j=0;j<=V;j++){
    		if(mat[n][j]==true)
    			vec.push_back(j);
    	}
    }
     
    ll knapsack1(ll v[], ll w[], ll V, ll n){
    	if(V==0)
    		return 0;
    	if(n==0)
    	    return INF;
    	
    	if(dp[n][V]!=-1)
    		return dp[n][V];
     
    	if(v[n]<=V)
    		return dp[n][V] = min(w[n] + knapsack1(v,w,V-v[n],n-1), knapsack1(v,w,V,n-1));
    	else
    		return dp[n][V] = knapsack1(v,w,V,n-1);
    }
     
    int main(){
    	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll n,W;
        cin>>n>>W;
        ll w[n+1],v[n+1];
        ll V=0;
        for(int i=1;i<=n;i++){
        	cin>>w[i]>>v[i];
        	V+=v[i];
        }
        memset(dp,-1,sizeof(dp));
        subsetSum(v,V,n);
        for(int i=(vec.size()-1);i>=0;--i){
        	ll temp = knapsack1(v,w,vec[i],n);
        	if(temp<=W){
        		cout<<vec[i]<<" ";
        		break;
        	}
        }
    }

Measured memory_bytes: 93260
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i=0,a=0;
	string s,e="keyence";
	cin>>s;
	for(int t=0;t<s.size();t++)
	{
		if(s[t]!=e[i])
		{ 
			break;
		}
		else
		{
			i++;
			a++;
		}
	}
	i=6;
	for(int t=s.size()-1;t>=0;t--)
	{
		if(s[t]!=e[i])
		{ 
			break;
		}
		else
		{
			i--;
			a++;
		}
	}
	//cout<<a<<" ";
	if(a>=7)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] in = new String[2];
		for (int i = 0; i < 2; i++) in[i] = sc.next();
		
		String[] weatherForecast = in[0].split("");
		String[] weather = in[1].split("");
		int count = 0;

		for (int i = 0; i < weatherForecast.length; i++) {
			if (weatherForecast[i].equals(weather[i]))
				count++;
		}
			
		System.out.println(count);
	}
}


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

int main(void){
    int len;
    cin >> len;
    string s;
    cin >> s;
    int x = 0;
    int ans = 0;
    for(int i = 0; i < len; i++){
        if(s[i] == 'I')
            x++;
        if(s[i] == 'D')
            x--;

        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s,t;
    vector<string> kouho;
    cin>>s>>t;

    int sl = s.length();
    int tl = t.length();

    rep(i,(sl-tl)+1){

        bool ok = true;
        rep(j,tl){
            if(s[i+j]!='?' && t[j]!=s[i+j])ok = false;
        }

        if(ok){
            string st = s;
            rep(k,sl){

                if(i<= k && k<tl+i)st[k]=t[k-i];
                else if(s[k]=='?')st[k]='a';

            }

            db(st);ln;
            kouho.eb(st);
        }
    }
    if(kouho.empty())cout<<"UNRESTORABLE"<<endl;
    else
    {
        sort(all(kouho));
        cout<<kouho[0]<<endl;
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll g=0,n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i],g=gcd(g,a[i]);
    cout<<g el;
}

main()
{
//    fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 4340
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    ll n;
    cin >> n;
    ll a = 0;
    ll b = 0;
    for(ll i = 0;i < n;++i){
        ll l;
        cin >> l;
        a += l;
        b += l * l;
        a %= BIG;
        b %= BIG;
    }
    ll ans = a * a - b;
    ans = (ans < 0) ? (BIG + ans) : ans;
    ans %= BIG;

    if(ans % 2 == 1){
        ans += BIG;
    }
    ans /= 2;
    cout << ans << endl;
}




Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int main() {
	int n;
	cin >> n;
	int ans = INF;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		int count = 0;
		while (a % 2 == 0) {
			a /= 2;
			count++;
		}
		ans = min(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#Educational DP c vacation
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n+1)]
for i in range(n):
    dp[i+1][0] = abc[i][0] + max(dp[i][1], dp[i][2])
    dp[i+1][1] = abc[i][1] + max(dp[i][0], dp[i][2])
    dp[i+1][2] = abc[i][2] + max(dp[i][0], dp[i][1])
print(max(dp[n][0], max(dp[n][1], dp[n][2])))

Measured memory_bytes: 50268
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll A,B;
    cin >>  A >> B;
    if(B % A == 0)cout << A + B << endl;
    else cout << B - A << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    char str[3];
    gets(str);
    if(str[0] == 'M'){
        printf("6\n");
    }
    else if(str[0] == 'T' && str[1] == 'U'){
        printf("5\n");
    }
    else if(str[0] == 'W'){
        printf("4\n");
    }
    else if(str[1] == 'H'){
        printf("3\n");
    }
    else if(str[0] == 'F'){
        printf("2\n");
    }
    else if(str[2] == 'T'){
        printf("1\n");
    }
    else if(str[2] == 'N'){
        printf("7\n");
    }
    return 0;

}


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


using namespace std;



int main()
{



int n;
string s;
cin >>n >> s;
if (n%2==1){ cout << "No"; return 0;}
for (int i=0; i<n/2; i++)
    if (s[i]!=s[i+n/2]){ cout << "No"; return 0;}

cout << "Yes";


}























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

int main(){
	int N[5],i;
	int order_time=0;
	int max_val=10,max_n=0;

	
	//入力
	for ( i = 0;i<5;i++){
		cin >> N[i];
	}
	
	//計算(10剰余最小（0以外）を求める)
	for ( i=0;i<5;i++){
		if ( (N[i]%10) != 0 && (N[i]%10 < max_val))
		{
			max_val = N[i]%10;
			max_n = i;
		}
	}

	
	for(i=0;i<5;i++){
		
		if(i==max_n || N[i]%10 == 0 )
		{
			order_time += N[i];
		}else{
			order_time += N[i]+(10-N[i]%10);
		}
	}
	
	
	//出力
	cout << order_time << endl;

	return 0;
}

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

int main(){
    long long n;cin>>n;
    vector<long long> positions(n + 2);
    positions[0] = 0;
    for (long long i=1;i<=n;i++){
        cin >> positions[i];
    }

    long long acc = 0;
    positions[n+1] = 0;
    for (long long i=0;i<=n;i++){
        acc += abs(positions[i+1] - positions[i]);
    }

    for (long long i=1;i<=n;i++){
        cout << acc - (abs(positions[i] - positions[i-1]) + abs(positions[i+1] - positions[i])) + abs(positions[i+1] - positions[i-1]) << endl;
    }
    return 0;
}

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

char s[15];

int get3(char a, char b, char c){
    int res = 0;
    char x[3]= {a, b, c};
    for(int i = 0; i<3; i++){
        res = res * 10 + x[i] - 48;
    }
    return res;
}

int main(){
    scanf("%s", s);
    int res = 10000;
    int num = 0;
    for(int i = 0; i< strlen(s)-2; i++){
        num = get3(s[i], s[i+1], s[i+2]);
        res = min(res, abs(num-753));
    }
    printf("%d\n", res);
    return 0;

}




Measured memory_bytes: 256
def main():
    a, b = map(int, input().split())
    if (a % 3 ==0) | (b % 3 ==0):
        ans = 0
    else:
        anss = []
        s1 = (b // 3 + 1) * a
        s2 = (b - (b // 3 + 1)) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3)) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3 - 1) * a
        s2 = (b - (b // 3) + 1) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3)) // 2 * a
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3 + 1)) // 2 * a
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        # b a
        t = a
        a = b
        b = t
        s1 = (b // 3 + 1) * a
        s2 = (b - (b // 3 + 1)) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3)) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3 - 1) * a
        s2 = (b - (b // 3) + 1) * (a // 2)
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3)) // 2 * a
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        s1 = (b // 3) * a
        s2 = (b - (b // 3 + 1)) // 2 * a
        s3 = a * b - s1 - s2
        anss.append(max(s1, s2, s3) - min(s1, s2, s3))

        ans = min(anss)

    print(ans)
    
main()

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 62;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N, M, A[100000], B[100000];

  cin >> N >> M;
  UnionFind uf(N);
  for(int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    --A[i], --B[i];
    uf.unite(A[i], B[i]);
  }

  bitset< 100001 > dp;
  dp[uf.size(0)] = true;
  for(int i = 2; i < N; i++) {
    if(uf.find(i) == uf.find(1)) continue;
    if(uf.find(i) == uf.find(0)) continue;
    if(uf.find(i) != i) continue;
    dp |= dp << uf.size(i);
  }

  int64 ret = -INF;
  for(int64 i = 1; i < N; i++) {
    if(dp[i]) {
      int64 j = N - i;
      ret = max(ret, i * (i - 1) / 2 + j * (j - 1) / 2);
    }
  }

  cout << ret - M << endl;
}

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

typedef long long LL;

const int N=1005;
const int M=25;
const int MOD=1000000007;

int n,m,a[M],jc[N],ny[N],f[M][N];

int C(int n,int m)
{
	return (LL)jc[n]*ny[m]%MOD*ny[n-m]%MOD;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d",&a[i]);
	jc[0]=jc[1]=ny[0]=ny[1]=1;
	for (int i=2;i<=n;i++) jc[i]=(LL)jc[i-1]*i%MOD,ny[i]=(LL)(MOD-MOD/i)*ny[MOD%i]%MOD;
	for (int i=2;i<=n;i++) ny[i]=(LL)ny[i-1]*ny[i]%MOD;
	f[0][0]=1;
	for (int i=0;i<m;i++)
		for (int j=0;j<=n;j++)
		{
			if (!f[i][j]) continue;
			for (int k=0;k<=a[i+1]&&j+k<=n;k++)
				(f[i+1][j+k]+=(LL)f[i][j]*C(j+k,j)%MOD*C(n-k,a[i+1]-k)%MOD)%=MOD;
		}
	printf("%d\n",f[m][n]);
	return 0;
}

Measured memory_bytes: 384