akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int a, b, c; cin>>a>>b>>c;
    swap(a, b);
    swap(a, c);

    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
int main (){
  int a,b;
  cin>>a>>b;
  if(a==1){
    a=14;
  }
  if(b==1){
    b=14;
  }
  if(a>b){
    cout<<"Alice";
  }
  else if (b>a){
    cout<<"Bob";
  }
  else {
    cout<<"Draw";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int N = S.length();
    int p = 13;
    vector<ll> dp(p);

    int mul = 1;
    dp[0] = 1;
    for (int i = N-1; i >= 0; --i) {
        vector<ll> nextDP(p);
        char c = S[i];
        if (c == '?') {
            for (int j = 0; j < 10; ++j) {
                for (int k = 0; k < p; ++k) {
                    nextDP[(j * mul + k) % p] += dp[k];
                    nextDP[(j * mul + k) % p] %= MOD;
                }
                
            }
        }
        else {
            int j = (int)(c - '0');
            for (int k = 0; k < p; ++k) {
                    nextDP[(j * mul + k) % p] += dp[k];
                    nextDP[(j * mul + k) % p] %= MOD;
                }
        }
        mul *= 10;
        mul %= p;
        dp = nextDP;
    }
    cout << dp[5] << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 262144
class segtree1
{
public:
	int seg[SIZE * 2];
	void init()
	{
		fill(seg, seg + SIZE * 2, 1000000000);
	}
	void update(int a, int b)
	{
		a += SIZE;
		seg[a] = min(seg[a], b);
		for (;;)
		{
			a /= 2;
			if (a == 0)break;
			seg[a] = min(seg[a * 2], seg[a * 2 + 1]);
		}
	}
	int get(int beg, int end, int node, int lb, int ub)
	{
		if (ub < beg || end < lb)return 1000000000;
		if (beg <= lb&&ub <= end)return seg[node];
		return min(get(beg, end, node * 2, lb, (lb + ub) / 2), get(beg, end, node * 2 + 1, (lb + ub) / 2 + 1, ub));
	}
};
segtree1 tree1;
class segtree2
{
public:
	int seg[SIZE * 2];
	void init()
	{
		fill(seg, seg + SIZE * 2, 1000000000);
	}
	void update(int beg, int end, int node, int lb, int ub, int num)
	{
		if (ub < beg || end < lb)return;
		if (beg <= lb&&ub <= end)
		{
			seg[node] = min(seg[node], num);
			return;
		}
		update(beg, end, node * 2, lb, (lb + ub) / 2, num);
		update(beg, end, node * 2 + 1, (lb + ub) / 2 + 1, ub, num);
	}
	int get(int pl, int node, int lb, int ub)
	{
		if (lb == ub)return seg[node];
		if (pl <= (lb + ub) / 2)return min(seg[node], get(pl, node * 2, lb, (lb + ub) / 2));
		else return min(seg[node], get(pl, node * 2 + 1, (lb + ub) / 2 + 1, ub));
	}
};
segtree2 tree2;
int d[300000], r[300000];
typedef pair<int, int>pii;
int main()
{
	int num, query;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%d", &d[i]);
	for (int i = num - 1; i >= 0; i--)r[i] = r[i + 1] + d[i];
	scanf("%d", &query);
	vector<pii>v;
	for (int i = 0; i < query; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		v.push_back(make_pair(zb, za));
	}
	sort(v.begin(), v.end());
	tree1.init();
	tree2.init();
	tree1.update(0, r[0]);
	int mini = r[0];
	for (int i = 0; i < v.size(); i++)
	{
		int s = v[i].second, t = v[i].first;
		int a = tree1.get(0, s, 1, 0, SIZE - 1) - (r[s] - r[t + 1]) + (t - s + 1 - (r[s] - r[t + 1]));
		int b = tree2.get(s, 1, 0, SIZE - 1) + r[t + 1] - (num - 1 - t - r[t + 1]);
		int x = min(a, b);
		//printf("%d %d  %d\n", s, t, x);
		mini = min(mini, x);
		tree1.update(t + 1, x);
		tree2.update(s, t, 1, 0, SIZE - 1, x - r[t + 1] + (num - 1 - t - r[t + 1]));
	}
	printf("%d\n", mini);
}

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

ll f(ll a) {
  switch (a % 4) {
    case 0:
      return a;
    case 1:
      return 1;
    case 2:
      return a + 1;
    case 3:
      return 0;
  }
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (f(a - 1) ^ f(b)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,n;
	cin>>n;
	ll ar[n];
	for(i=0;i<n;i++){
		cin>>ar[i];
	}
	k=0;
	for(i=0;i<n;i++){
		if(ar[i]%2==1){
			k++;
		}
	}
	if(k%2==0){
		cout<<"YES";
	}
	else {
		cout<<"NO";
	}
	return 0;
}


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

int main() {
	int a;string b,c;
cin>>a>>b>>c;
for(int d=a;d>=1;d--){
bool k=true;
for(int e=0;e<d;e++){
if(b[a-d+e]!=c[e])k=false;
}
if(k){cout<<a*2-d<<endl;return 0;}
}
cout<<a*2<<endl;
}

Measured memory_bytes: 256
# https://emtubasa.hateblo.jp/entry/2019/02/14/000000_2

def main():
    from itertools import tee
    S = input()
    L = len(S)

    s1, s2 = tee(iter(S), 2)
    next(s2)

    k = L
    for i, (c1, c2) in enumerate(zip(s1, s2), start=1):
        if c1 != c2:
            t = max(i, L - i)
            if k > t:
                k = t
    print(k)


if __name__ == '__main__':
    main()

# 異なる文字の境界で
# 左端、右端からその境界までの距離のうち長い方を反転させることで、
# その境界をなくすことができる
# そのような長い方の距離の最小値であれば、どの境界であっても処理できる


Measured memory_bytes: 3188
n = int(input())
a = list(map(int,input().split()))

su = 0
for i in range((n+1)//2):

    if i<(n-1)//2:
        su += (a[i]+a[n-i-1])*(-1)**i
    else:
        su += a[i]*(-1)**i

lis = [su]
for i in range(n-1):
    nex = 2*a[i]-lis[-1]
    lis.append(nex)

print(*lis)


Measured memory_bytes: 69604
n, m = map(int, input().split())

graph = [[] for i in range(n)]

for i in range(m):
    a, b = map(int ,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

transported = [0]
count = 0

def dfs(loc):
    global count
    if graph[loc] != []:
        for i in graph[loc]:
            if i not in transported:
                transported.append(i)
                dfs(i)
                transported.remove(i)

        if len(transported) == n:
            count += 1



for i in graph[0]:
    transported = [0, i]
    dfs(i)

print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
const int INF = 2e6;

class Parser{
public:
  string S;
  int i, k;
  void init(string s, int x){
    S = s;
    k = x;
    i = 0;
  }

  char parse(){
    return expr2();
  }

  int expr(){
    int ret = 0;
    while(i < S.length() && S[i] != ')'){
      int n = number(), t;
      if(S[i] == '('){
        ++i;
        t = expr();
        ++i;
      }else{
        t = str();
      }
      if(ret >= INF || n >= INF || t >= INF || n >= INF/t)
        ret = INF;
      else ret = min(ret + n*t, INF);
    }
    return min(INF,ret);
  }

  char expr2(){
    //cout << "i, k = " << i << ", " << k << endl;
    if(i >= S.length()) return '0';
    int n = number(), j;
    if(S[i] == '('){
      ++i;
      j = i;
      int t = expr();
      ++i;
      if(k >= n*t){
        k -= n*t;
      }else{
        k %= t;
        i = j;
      }
      return expr2();
    }else{
      j = i;
      int t = str();
      if(t*n > k){
        return S[j + k%t];
      }else{
        k -= t*n;
        return expr2();
      }
    }
    return '0';
  }

  int number(){
    if(i >= S.length() || S[i] < '0' || S[i] > '9') return 1;
    int ret = 0;
    while(i < S.length() && S[i] >= '0' && S[i] <= '9'){
      ret *= 10;
      ret += S[i] - '0';
      ++i;
    }
    return ret;
  }
  
  int str(){
    int ret = 0;
    while(i < S.length() && S[i] >= 'A' && S[i] <= 'Z'){
      ++ret;
      ++i;
    }
    return ret;
  }
};

int main(){
  string s;
  int x;
  Parser P;
  while(cin >> s >> x, s != "0"){
    P.init(s,x);
    cout << P.parse() << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long cot[105];
ll ans=0;
int main()
{
    int n;
    memset(cot,0,sizeof(cot));
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int t=i;
        for(int j=2;j*j<=t;j++)
            while(t%j==0) cot[j]++,t/=j;
        if(t>1) cot[t]++;
    }
    for(int i=2;i<=100;i++)
        for(int j=2;j<=100;j++)
        {
            if(i==j) continue;
            if(cot[i]>=4&&cot[j]>=14) ans++;
            if(cot[i]>=2&&cot[j]>=24) ans++;
            for(int k=j+1;k<=100;k++)
            {
                if(k==j||i==k) continue;
                if(cot[i]>=2&&cot[j]>=4&&cot[k]>=4) ans++;
            }
        }
    for(int i=2;i<=100;i++)
        if(cot[i]>=74) ans++;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N;
	ll p=1;
	for(int i=1;;i++){
		p*=3;
		if(N<=p){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1192
N,K=map(int,input().split())
Ds=list(input().split())
Di=list(map(int,Ds))
nex=[1]*10
for i in reversed(Di):
    nex[i-1]=nex[i]+1

def check(n):
    ns = str(N)
    for nss in ns:
        if nss in Ds:
            return False
    return True

def next(i):
    global N
    ns='{0:0>5}'.format(N)
    t=nex[int(ns[i])]
    pp=int(ns[i])+t
    if pp >=10:
        t=t-10
        N+=t*(10**(4-i))
        next(i-1)
    else:
        N+=t*(10**(4-i))

while not check(N):
    next(4)
print(N)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
bool c(int a,int b){return a>b;}
int main()
{
int v[3],i,ans=0;
cin>>v[0]>>v[1]>>v[2];
sort(v,v+3,c);
if((v[0]==v[1])&&(v[1]==v[2])){cout<<"0";return 0;}
if(((v[0]-v[1])%2==1)&&((v[0]-v[2])%2==1))
{cout<<((v[0]-v[1]+v[0]-v[2])/2)<<endl;return 0;}
while(v[0]!=v[1]){v[1]++;v[2]++;ans++;}
if((v[1]-v[2])%2==0)
while(v[1]!=v[2]){v[2]+=2;ans++;}
else
{
while((v[1]-1)!=v[2]){v[2]+=2;ans++;}
v[0]++;v[1]++;ans++;v[2]+=2;ans++;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	_, M := nextInt(), nextInt()
	maxL, minR := 0, 100000
	for i := 0; i < M; i++ {
		l, r := nextInt(), nextInt()
		if maxL < l {
			maxL = l
		}
		if minR > r {
			minR = r
		}
	}

	if maxL > minR {
		fmt.Println(0)
	} else {
		fmt.Println(minR - maxL + 1)
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  ll n;
  cin>>n;
  ll s=0,c=0;
  for(ll i=1;i<=n;i++)
  {
    if( (i%3==0) || (i%5==0) || (i%15==0) )
    {
        c;
    }
    else
    {
        s=s+i;
    }
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cmath>
#include <iostream>
#include <vector>

int main(){
  long long int N;
  std::cin >> N;
  for(long long int i = std::floor(std::sqrt(N)); i >= 1; i--){
    if(N%i == 0){
      std::cout << i+(N/i)-2 << std::endl;
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		StringBuilder sb = new StringBuilder(in.next());
		int num = in.nextInt();

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

			String command = in.next();

			if(command.equals("print")){

				// ???????????????????????????????????§?????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();

				// ????????????????????????????????????
				System.out.println(sb.substring(first_num, second_num + 1));

			}else if(command.equals("reverse")){

				// ???????????????????????????????????§????????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();

				sb = reverse(first_num, second_num, sb);

				/*// ????????????????????????????????????????????????
				String reverse_word = sb.substring(first_num, second_num + 1);
				// ??????????????????????????????????????§?????????????????????
				StringBuilder reverse_sb = new StringBuilder(reverse_word);
				// ???????????????????????????
				reverse_word = reverse_sb.reverse().toString();
				// ???????????????????????????????????????????????´?????????????????????
				sb = sb.replace(first_num, second_num+1, reverse_word);*/

			}else if(command.equals("replace")){

				// ???????????????????????????????????§???????????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();
				// ??????????????????????????????
				String str = in.next();
				// ?????????????????????
				sb.replace(first_num, second_num + 1, str);

			}
		}
	}
	public static StringBuilder reverse(int first_num, int second_num, StringBuilder sb){

		// ????????????????????????????????????????????????
		String reverse_word = sb.substring(first_num, second_num + 1);
		// ??????????????????????????????????????§?????????????????????
		StringBuilder reverse_sb = new StringBuilder(reverse_word);
		// ???????????????????????????
		reverse_word = reverse_sb.reverse().toString();
		// ???????????????????????????????????????????????´?????????????????????
		sb = sb.replace(first_num, second_num+1, reverse_word);

		return sb;

	}
}

Measured memory_bytes: 29400
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::cout << (N <= 999 ? "ABC" : "ABD") << std::endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(N)])
drink = 0
cost = 0

for i in range(N):
    cost += shops[i][0]*shops[i][1]
    drink += shops[i][1]
    if drink >= M:
        cost -= (drink -M) * shops[i][0]
        break
        
print(cost)

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

int main()
{
    ll max = 1000000000000001;
    ll key = 26;
    ll n;
    cin >> n;

    ll temp = n - 1;
    stack<char> ans;
    while (temp >= 26)
    {
        ans.push(temp % 26 + 97);
        temp /= 26;
        temp--;
    }
    
    /*
    if(temp%26 == 0 && n!=1){
        ans.push(temp % 26 + 97);        
    }
    */
    
        ans.push(temp % 26 + 97);
    /*
    ll ans;
    ans = n%26 + 97;
    cout << (char)ans << endl;
    */
    while (!ans.empty())
    {
        cout << ans.top();
        ans.pop();
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3632
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)
	switch {
	case n == "A":
		fmt.Println("T")
	case n == "T":
		fmt.Println("A")
	case n == "G":
		fmt.Println("C")
	default:
		fmt.Println("G")
	}
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    int n, tmp[2];
    set<int> tt;

    cin >> n;
    while(n--) {
        cin >> tmp[0] >> tmp[1];
        tt.insert(tmp[0] * 60 + tmp[1]);
    }
    cin >> n;
    while(n--) {
        cin >> tmp[0] >> tmp[1];
        tt.insert(tmp[0] * 60 + tmp[1]);
    }

    for (auto it = tt.begin(); it != tt.end(); ++it)
        printf("%s%d:%02d", it != tt.begin() ? " " : "", *it/60, *it%60);

    PED;
    return 0;
}

Measured memory_bytes: 3248
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) (int)x.size()
#define see(x) cerr<<#x<<" "<<x<<endl
#define se(x) cerr<<" "<<x 
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for (long long i=l;i<=r;i++)
#define N 150
using namespace std;
queue<pair<int,int> > q;
int n,m,c;
int x,y,z,num;
int u[3000],v[3000],w[3000],next[3000],top[N];
int f[N][N];
int vis[N][N];
int main(){
	while (scanf("%d%d%d",&n,&m,&c)==3){
		if (n==0 && m==0 && c==0) return 0;
		clr(top,0);clr(next,0);num=0;
		rep(i,1,m) {
			scanf("%d%d%d",&x,&y,&z);
			++num;u[num]=x;v[num]=y;w[num]=z;next[num]=top[x];top[x]=num;
		}
		q.push(mp(1,0));
		rep(i,1,n) rep(j,0,n) f[i][j]=1e9;
		clr(vis,0);
		f[1][0]=0;vis[1][0]=1;
		while (!q.empty()){
			x=q.front().first;
			y=q.front().second;
		//	cout<<x<<" "<<y<<" "<<f[x][y]<<endl;
			q.pop();
			for (int j=top[x];j;j=next[j]){
			//	cout<<j<<endl;
				if (f[x][y]+w[j]<f[v[j]][y]){
					f[v[j]][y]=f[x][y]+w[j];
					if (!vis[v[j]][y]){
						vis[v[j]][y]=1;
						q.push(mp(v[j],y));
					}	
				}
				if (f[x][y]<f[v[j]][y+1]){
					f[v[j]][y+1]=f[x][y];
					if (!vis[v[j]][y+1]) {
						vis[v[j]][y+1]=1;
						q.push(mp(v[j],y+1));
					}
				}
			}
	//		cout<<"!"<<endl;
			vis[x][y]=0;
		}
//		cout<<"!"<<endl;
		for (int i=0;i<=n;i++){
			if (f[n][i]<=c) {
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
        int N;
        cin >> N;
        string key[N];
        for(int i=0;i<N;i++) cin >> key[i];
        string ID;
        int M;
        cin >> M;

        bool lock = true, find = false;
        for(int i=0;i<M;i++){
            cin >> ID;
            for(int j=0;j<N;j++){
                if(ID == key[j]){
                    if(lock){
                        cout << "Opened by " << key[j] << endl;
                        lock = false;
                        find = true;
                        break;
                    }else{
                        cout << "Closed by " << key[j] << endl;
                        lock = true; 
                        find = true;
                        break;
                    }
                }
            }
            if(!find) cout << "Unknown " << ID << endl;
            find = false;
        }
}


Measured memory_bytes: 3228
n=int(input())
a=list(map(int,input().split()))
b=[]
pre=-1
for x in a:
  if x!=pre:
    b.append(x)
  pre=x
n=len(b)
if n==1:
  print(1000)
  exit()
# はじめに売ることはないので初期値はFalse
up=False
money=1000
kabu=0
for i in range(n-1):
  # 上がり調子だったのに、次下がるという場合、売る。
  if b[i]>b[i+1]:
    if up:
      money+=kabu*b[i]
      kabu=0
    up=False
  elif b[i]<b[i+1]:
    # 下がり調子だったのに、次上がるという場合、買う。
    if not up:
      kabu+=money//b[i]
      money%=b[i]
    up=True
if b[n-2]<b[n-1]:
  money+=kabu*b[-1]
  kabu=0
print(money)

Measured memory_bytes: 9232
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    auto s = readln.chomp;
    
    int[] sinks;
    sinks ~= 0;
    foreach (i; 0 .. s.length - 1) {
        if (s[i] == 'R' && s[i+1] == 'L') { sinks ~= i.to!int; }
    }
    sinks ~= s.length.to!int;
    
    debug { sinks.writeln; }
    
    auto ans = new int[] (s.length);
    int j = 0;
    foreach (i; 0 .. s.length) {
        if (i > sinks[j+1]) { ++j; }
        
        int goToSink = s[i] == 'L' ? sinks[j] : sinks[j+1];
        int dist = i.to!int - goToSink;
        int finalField = dist % 2 == 0 ? goToSink : goToSink + 1;
        ans[finalField] += 1;
        
        debug { writeln(i, ' ', j, ' ', finalField); }
    }
    
    foreach (i; 0 .. s.length) {
        if (i > 0) { write(" "); }
        write(ans[i]);
    }
    
    writeln();
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>

using namespace std;
typedef long long ll;

const int MAXN = 1024;
int vis[MAXN], parent[MAXN];
vector<int> adj[MAXN];
int nxt[MAXN];

void go(vector<int> cycle) {
  map<int, int> in_cycle;
  for (int i = 0; i < cycle.size(); i++) {
    in_cycle[cycle[i]] = i;
    // cerr << "in cycle: " << cycle[i]+1 << endl;
  }
  int u = cycle[0];
  // cerr << "adding: " << u + 1 << endl; 
  queue<int> q;
  q.push(u);
  while (true) {
    int cur_pos = in_cycle[u];
    int best_pos = cur_pos;
    int node = -2; 
    // cerr << "searching for nxt after " << u + 1 << endl;
    // cerr << "cur pos: " << cur_pos << endl;
    for (int v: adj[u]) {
      if (in_cycle.count(v) == 0) continue;
      int pos = in_cycle[v];
      // cerr << "trying: " << v+1 << ", pos: " << pos << endl;
      if (pos > cur_pos) {
        if (best_pos >= cur_pos && pos > best_pos) {
          best_pos = pos;
          node = v;
        }
      } else {
        if (best_pos >= cur_pos || pos > best_pos) {
          best_pos = pos;
          node = v;
        }
      }
    }
    // cerr << "next one is: " << node+1 << endl;
    if (best_pos > cur_pos) {
      q.push(node);
      u = node;
      for (int j = cur_pos + 1; j < best_pos; j++) {
        int v = cycle[j];
        in_cycle.erase(v);
      }
    } else {
      while (!q.empty() && in_cycle[q.front()] < best_pos) q.pop();
      assert(q.front() == node);
      break;
    }
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    cout << q.front() + 1 << endl;
    q.pop();
  }
  exit(0);
}


void dfs(int u) {
  vis[u] = 1;
  bool here = false;
  int w;
  for (int v: adj[u]) {
    if (vis[v] == 1) {
      here = true;
      w = v;
      break;
    }
    parent[v] = u;
    dfs(v);
  }
  vector<int> cycle;
  if (here) {
    while (u != w) {
      cycle.push_back(u);
      u = parent[u];
    }
    cycle.push_back(w);
    reverse(cycle.begin(), cycle.end());
    go(cycle);
  }
  vis[u] = 2;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    adj[u].push_back(v);
  }
  fill(vis, vis + n, 0);
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  cout << -1 << endl;
  return 0;
}


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

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

  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  vector<int> hoge(3);
  rep(i, n) {
    if (p[i] <= a) {
      hoge[0]++;
    } else if (p[i] >= b+1) {
      hoge[2]++;
    } else {
      hoge[1]++;
    }
  }

  cout << min({hoge[0], hoge[1], hoge[2]}) << endl;
}


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

int main() {
  
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a <= c && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

int main(){
  string a;
  cin>>a;
  int count=0;
  for(int i=0;i<3;i++){
    if(a.at(i)=='o') count++;
  }
  int n=700+count*100;
  cout<<n<<endl;
}

Measured memory_bytes: 256
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

ans=0

# a,b,c are the same, mod k
# do a,b,c = 0 mod k
ans+=(n//k)**3

# do a,b,c = k/2 mod k
if k%2==0:
    ans+=((n+k//2)//k)**3

print(ans)


Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;


int main() {
	
	int sizeX, sizeY;

	int a[100][100];
	int b[100];

	cin >> sizeY >> sizeX;

	for (int i = 0; i < sizeY; i++) {
		for (int j = 0; j < sizeX; j++) {
			cin >> a[i][j];
		}
	}

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

	int sum = 0;

	for (int i = 0; i < sizeY; i++) {
		sum = 0;

		for (int j = 0; j < sizeX; j++) {
			sum += (a[i][j] * b[j]);
		}
		printf("%d\n", sum);
	}



	//system("pause");
	return 0;
}


Measured memory_bytes: 3232
a, b, c, d = map(int, (input().split()))


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


lcm = (c * d) // gcd(c, d)

from1toA = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
from1toB = b - (b // c + b // d - b // lcm)
fromAtoB = from1toB - from1toA

print(fromAtoB)


Measured memory_bytes: 3060
// 解説後
#include <algorithm>
#include <iostream>
#include <vector>

// 最大のXORサブセットを返す関数
// from https://www.geeksforgeeks.org/find-maximum-subset-xor-given-set/
uint64_t max_subarray_xor(uint64_t* p, size_t n) noexcept {
  const size_t BITS = 60;  // 値のビット数

  // 最上位ビットから順に要素を調べる
  size_t index = 0;  // 入れ替える最大要素の終端
  for (uint64_t mask = uint64_t(1) << (BITS - 1); mask > 0; mask >>= 1) {
    // iビット目が立っている要素の中で最大のものを探す
    size_t max_element = 0;
    size_t max_element_index = index;
    for (size_t j = index; j < n; ++j) {
      if ((p[j] & mask) != 0 && p[j] > max_element) {
        max_element = p[j];
        max_element_index = j;
      }
    }

    // iビット目が立っている要素がなければ、次のビットへ進む
    if (max_element == 0) continue;

    // 最大要素をindex番目と入れ替える
    std::swap(p[index], p[max_element_index]);
    max_element_index = index;

    // p[max_element_index]をiビット目が立っている要素にXORする
    // TODO:どのように辻褄を合わせているかを調べる
    for (size_t j = 0; j < n; ++j) {
      if (j != max_element_index && (p[j] & mask) != 0) {
        p[j] = p[j] ^ p[max_element_index];
      }
    }

    // 次の要素へ
    index++;
  }

  // 結果を計算する
  uint64_t result = 0;
  for (size_t i = 0; i < n; ++i) {
    result ^= p[i];
  }

  return result;
}

// 赤色側をXORした値をR、青色側をXORした値をBとする
// S = A_1 ^ A_2 ^ ... ^ A_N = R ^ B
// Sで1となるビットに対応する(R_i, B_i)は(1, 0)か(0, 1)である
// ⇒ R+Bは塗り分け方に左右されずにそのビットが必ず1になる
// Sで0となるビットに対応する(R_i, B_i)は(0, 0)か(1, 1)である
// ⇒ R&~S（=B&~S）が最大となるような塗り分け方を選択したい
int main() {
  size_t N = 0;
  std::cin >> N;

  std::vector<uint64_t> A(N);
  uint64_t S = 0;
  for (auto& a : A) {
    std::cin >> a;
    S ^= a;
  }

  // Sで0となるビットのみを残す
  for (auto& a : A) {
    a &= ~S;
  }

  // Sで0となるビットだけのXORで値が最大となるパターンを見つける
  const uint64_t subset = max_subarray_xor(A.data(), A.size());

  // Sで0となるビットだけのR（subset） + Sで0となるビットだけのB（subset） + Sで1となるビットだけのR+B（S）
  std::cout << (subset * 2 + S);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct item_t {
  ll w, v;
  item_t(ll w, ll v):w(w),v(v){}
  item_t():w(0),v(0){}
  void operator+=(const item_t &r) {
    w += r.w;
    v += r.v;
  }
  bool operator<(const item_t &r) const { return w < r.w; }
};

vector<item_t> rekkyo(vector<item_t> item) {
  vector<item_t> a(1, item_t(0,0));
  for (auto i : item) {
    vector<item_t> b = a, c;
    for (auto &e : b) {
      e += i;
    }
    std::merge(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(c));
    a = c;
  }
  return a;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<item_t> item(n+1); //1-indexed
  rep(i,n) cin >> item[i+1].v >> item[i+1].w;
  int q;
  cin >> q;
  while(q--) {
    int v, L;
    cin >> v >> L;
    vector<item_t> A;
    while(v > 0) {  
      A.emplace_back(item[v]);
      v /= 2;
    }
    int m = A.size();
    auto a = rekkyo({A.begin(), A.begin() + m/2});
    auto b = rekkyo({A.begin() + m/2, A.end()});
    ll maxv = 0;
    for (auto&& x : b) { //x.v <- x.w以下で達成できる価値の最大値
      chmax(maxv, x.v);
      x.v = maxv;
    }
    reverse(all(a));
    ll ans = 0;
    int r = 0;
    for (auto&& x : a) {
      while(r+1 < (int)b.size() && x.w + b[r+1].w <= L) {
        r++;
      }
      if (x.w + b[r].w > L) continue;  
      chmax(ans, x.v + b[r].v);
    }
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 7400
#include<stdio.h>
int main()
{
    int a[10000],b[100000],n,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    }scanf("%d",&m);
    for(int j=0;j<2*m;j++){
        scanf("%d",&b[j]);
    }
    for(int k=0;k<2*m;k=k+2){
            int sum=0,temp;
         temp=a[b[k]-1];
         a[b[k]-1]=b[k+1];
         for(int l=0;l<n;l++){
            sum=sum+a[l];
         }
         printf("%d\n",sum);
         a[b[k]-1]=temp;

    }


    return 0;

}


Measured memory_bytes: 1740
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

a.append(a[0]+k)

l = 0
for i in range(n):
    l = max(l, a[i+1] - a[i])

print(k-l)




Measured memory_bytes: 32300
#include <iostream>
#include <algorithm>

using namespace std;

int vis[15][15];

int bfs(int a[15][15], int n, int m, int s, int t)
{
  int c = 0;
  if(s+1 == n){
    vis[s][t] = 1;
    return 1;
  }

  if(vis[s][t] > 0){
    return vis[s][t];
  }

  if(a[s][t] == 2){
    if(s+2 >= n){
      vis[s][t] = 1;
      return 1;
    }
    if(a[s+2][t] != 1){
      c = bfs(a, n, m, s+2, t);
    }
  } else {

    if(t-1 >= 0){
      if(a[s+1][t-1] == 0){
	c += bfs(a, n, m, s+1, t-1);
      }
    }
    if(a[s+1][t] != 1){
      c += bfs(a, n, m, s+1, t);
    }
    
    if(t+1 < m){
      if(a[s+1][t+1] == 0){
      c += bfs(a, n, m, s+1, t+1);
      }
    }
  }
  vis[s][t] = c;

  return c;
}

int main()
{
  int n, m, c;
  int a[15][15];

  while(1){
    cin >> m >> n;
    if(n == 0 && m == 0){
      break;
    }

    fill(&vis[0][0], &vis[14][14], -1);

    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
	cin >> a[i][j];
      }
    }
    c = 0;
    for(int i = 0; i < m; i++){
      if(a[0][i] != 1){
	c += bfs(a, n, m, 0, i);
      }
    }

    cout << c << endl;
  }


  return 0;
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,H;
  cin>>N>>H;
  int A=0;
  vi B(N);
  int ans=0;
  rep(i,0,N){
    int a;
    cin>>a>>B[i];
    A=max(A,a);
    }
  sort(ALL(B));
  rep(i,0,N){
    int K=N-1-i;
    if(B[K]<=A)
      break;
    H-=B[K];
    ans++;
    if(H<=0)
      break;
    }
  if(H>0)
    ans+=(A+H-1)/A;
  cout<<ans<<endl;
  }


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

using namespace std;

const int MAXN=1e5+1;

int n,m,k,f[MAXN],g[MAXN]={0},cnt[MAXN]={0};
map<pair<int,int>,bool> r;

inline int find_root(int x) {
	return x==f[x] ? x:f[x]=find_root(f[x]);
}

inline bool merge(int x,int y) {
	x=find_root(x),y=find_root(y);
	if(x==y) return 0;
	f[x]=y,g[y]+=g[x];
	return 1;
}

int main() {
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1; i<=n; ++i) f[i]=i,g[i]=1;
	for(int i=1,a,b; i<=m; ++i) {
		scanf("%d %d",&a,&b);
		++cnt[a],++cnt[b];
		merge(a,b);
	}
	for(int i=1; i<=n; ++i) cnt[i]=g[find_root(i)]-cnt[i];
	for(int i=1,c,d; i<=k; ++i) {
		scanf("%d %d",&c,&d);
		if(f[c]==f[d]) --cnt[c],--cnt[d];
	}
	for(int i=1; i<=n; ++i) printf("%d ",cnt[i]-1);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2432
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int isTri[500010];
signed main() {
    for(int i=1; i*(i+1)/2<=500000; i++) {
        isTri[ i*(i+1)/2 ] = i;
    }

    int A, B; cin >> A >> B;

    for(int i=1; i<500000; i++) {
        int na = A + i, nb = B + i;
        if(isTri[na] and isTri[nb]) {
            fprintf(stderr, "na = %lld (%lld), nb = %lld (%lld)\n", na, isTri[na], nb, isTri[nb]);
            if(isTri[nb] - isTri[na] == 1) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

const int MaxN=5e5+5;

int N,K,M;
int P[MaxN],Pos[MaxN];
int Deg[MaxN],Q[MaxN];

set<int> S;
set<int>::iterator it;
vector<int> To[MaxN];
priority_queue<int,vector<int>,greater<int> > H;

void Add_Edge(int u,int v){
	To[u].push_back(v);
	Deg[v]++;
}

int main(){
	int i,u,v;
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++){
		scanf("%d",&P[i]);
		Pos[P[i]]=i;
	}
	for(i=2;i<=N;i++){
		S.insert(P[i-1]);
		if(i>K)
			S.erase(P[i-K]);
		if((it=S.upper_bound(P[i]))!=S.end())
			Add_Edge(i,Pos[*it]);
	}
	S.clear();
	for(i=N-1;i;i--){
		S.insert(P[i+1]);
		if(i+K<=N)
			S.erase(P[i+K]);
		if((it=S.upper_bound(P[i]))!=S.end())
			Add_Edge(i,Pos[*it]);
	}
	for(i=1;i<=N;i++)
		if(!Deg[i]){
			H.push(i);
			//printf("%d ",i);
		}
	//puts("");
	while(H.size()){
		u=H.top();
		Q[u]=++M;
		H.pop();
		for(i=0;i<To[u].size();i++)
			if(!--Deg[v=To[u][i]])
				H.push(v);
	}
	for(i=1;i<=N;i++)
		printf("%d\n",Q[i]); 
	return 0;
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b;
    if (a == 1 && b == 2){
        cout << 3 << endl;
    }
    if (a == 1 && b == 3){
        cout << 2 << endl;
    }
    if (a == 2 && b == 3){
        cout << 1 << endl;
    }
    if (a == 2 && b == 1){
        cout << 3 << endl;
    }
    if (a == 3 && b == 1){
        cout << 2 << endl;
    }
    if (a == 3 && b == 2){
        cout << 1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

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

const int MAXN = 2000 * 1000 + 1;


const int INF = 1e9;

vector<int> a;

bool check(vector<int>& a, ll x)
{
    for (int i = 0; i < a.size(); i++)
    {
        x = x / a[i] * a[i];
    }
    return (x == 2);
}

bitset<MAXN> can = 0;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    int k;
    cin >> n;
    a.resize(n);

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
//    vector<int> b;
//    set<int> myset;
    int all = sum;
    sum /= 2;


    can.set(0);
//    cerr << sum;
//    sort(a.begin(), a.end());
//    reverse(a.begin(), a.end());
    for (int k = 0; k < n; k++)
    {
        can |= can << a[k];
    }

    for (int i = sum; i >= 0; i--) {
        if (can.test(i)) {
            cout << all - i;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n;
  cin >> n;
  vector<vector<ll> > a(n,vector<ll>(n));
  vector<vector<ll> > d(n+1,vector<ll>(n+1, INF));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
      d[i][j] = a[i][j];
    }
  }

  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (k == i or k == j or i == j or d[i][k] == INF or d[k][j] == INF) continue;
        if (a[i][k] + d[k][j] == a[i][j]) d[i][j] = INF;
        else if (d[i][k] + d[k][j] < a[i][j]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }

  ll ans = 0;
  for (auto itr : d) {
    for (auto sub : itr) {
      if (sub != INF) ans += sub;
    }
  }

  cout << ans / 2 << endl;
}


Measured memory_bytes: 1664
N=int(input())
s=[]
for i in range(N):
    s.append(input())
M=int(input())
t=[]
for i in range(M):
    t.append(input())
result=0
for i in range(N):
    if s[i] in t:
        ans=s.count(s[i])-t.count(s[i])
    else:
        ans=s.count(s[i])
    if ans>result:
        result=ans
print(result)

Measured memory_bytes: 3064
N=int(input())
n=list(range(1,N+1,1))
n3=list(range(3,N+1,3))
n5=list(range(5,N+1,5))
n15=list(range(15,N+1,15))
print(sum(n)-sum(n3)-sum(n5)+sum(n15))

Measured memory_bytes: 72156
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, Q;
	string S;
	cin >> N >> S >> Q;


	REP(j, Q) {
		int a, ans = 0;
		int dcnt = 0, mcnt = 0, dmcnt = 0;
		int s = 0, t = 0;
		cin >> a;
		if (S[0] == 'D')dcnt++;
		if (S[0] == 'M')mcnt++;
		while (t < N) {

			/*int d = 0, m = 0;
			eFOR(i, s, t) {
				if (S[i] == 'D')d++;
				if (S[i] == 'M')m++;
			}


			if (j == 2) {
				cout << s << " " << t << " " << " " << dcnt << " " << mcnt << " " << dmcnt << endl;
				cout << d << " " << m << endl << endl;
			}*/
			if (S[t + 1] == 'C') ans += dmcnt;
			if (S[t + 1] == 'M') {
				if (t - s + 1 == a - 1) {
					if (S[s] == 'D') {
						mcnt++;
						dmcnt += dcnt - 1;
					}
					else {
						mcnt++;
						dmcnt += dcnt;
					}
				}
				else {
					mcnt++;
					dmcnt += dcnt;
				}
				t++;
			}
			else if (S[t + 1] == 'D') {
				t++;
				dcnt++;
			}
			else t++;

			if (t - s  == a - 1) {
				if (S[s] == 'D') {
					dmcnt -= mcnt;
					dcnt--;
					if (S[t] == 'M')dmcnt++;
				}
				if (S[s] == 'M') {
					mcnt--;
				}
				s++;
			}
		}
		
		
		cout << ans << endl;
	}



	return 0;
}



Measured memory_bytes: 1948
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e18
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
using namespace std;

int main() 
{
    fastio; 
    ll T=1;
    //cin>>T; 
    while(T--)
    { 	
        ll x;
        cin>>x;
        cout<<1-x<<endl;
	}
}
 

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

int main() {
  int k ,x;
  cin >> k >> x;
  if (500 * k >= x) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque

def main():
    N, M, *L = map(int, open(0).read().split())

    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(L[:2 * M])] * 2):
        E[a].append(b)
        E[b].append(a)

    colors = [0] * (N + 1)
    visited = [-1] * (N + 1)

    for v, d, c in reversed(tuple(zip(*[iter(L[2 * M + 1:])] * 3))):
        Q = deque([(d, v)])
        while Q:
            cnt, v = Q.popleft()
            if visited[v] >= cnt:
                continue
            if colors[v] == 0:
                colors[v] = c
            visited[v] = cnt
            if cnt > 0:
                Q.extend((cnt - 1, u) for u in E[v])

    for c in colors[1:]:
        print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50252
#include<iostream>                                        
#include<cstdio>                                          
#include<cctype>                                          
using namespace std;                                      
                                                          
int main(){                                               
  char ch;                                                
  int cnt[26] = {};                                       
                                                          
  while(scanf("%c",&ch) != EOF){                          
    ch = tolower(ch);                                     
    if(isalpha(ch)){                                      
      cnt[ch-'a']++;                                      
    }                                                     
  }                                                       
                                                          
  for(int i=0;i<26;i++){                                  
    printf("%c : %d\n",i+'a',cnt[i]);                     
  }                                                       
                                                          
  return 0;                                               
} 

Measured memory_bytes: 3200
n, m = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
d = {}  # key=match, val=num
d[2] = [1]
d[3] = [7]
d[4] = [4]
d[5] = [5, 3, 2]
d[6] = [9, 6]
d[7] = [8]
enable = [False] * 10
for a in l:
  enable[a] = True
# マッチをk(=2..7)本使う場合の一番大きい値を総当たり
def f(nokori, current):
  if nokori == 0:
    return current
  if nokori < 0:
    return -1
  temps = []
  for key, nums in list(d.items())[::-1]:
    for num in nums:
      if enable[num]:
        if nokori-key != 0 and current % 10 != 0 and current % 10 < num:
          # 98 ok, 89 重複するので最後の桁以外は skip
          continue
        temps.append(f(nokori-key, current*10+num))
        break
  return max(temps)

# 余裕があるうちは一番マッチの本数が少ないモノをヤケクソで詰めまくる
def hoge():
  for key, nums in list(d.items()):
      for num in nums:
        if enable[num]:
          return (num, key)
num, key = hoge()
cs = []
while n > 50:
  n -= key
  cs.append(str(num))

# ヤケクソで詰めたやつと総当たりで調べたマックスを並び替えて辞書順で大きくする
num_ans = str(f(n, 0))
print(''.join(sorted(list(num_ans) + cs)[::-1]))


Measured memory_bytes: 3444