akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

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

    for (int i = A; i <= B && (i - A) < K; i++) cout << i << endl;
    for (int i = max(B - K + 1, A + K); i <= B; i++) cout << i << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())

a = []
b = []
for i in range(n):
    s = input()
    x = 0
    y = 0
    for c in s:
        if c == '(':
            y += 1
        else:
            if y >= 1:
                y -= 1
            else:
                x += 1
    if x < y: a.append([x, abs(x-y)])
    else: b.append([y, abs(x-y)])

def calc(a):
    ret = 0
    for x, y in sorted(a):
        if ret < x: return -1
        ret += y
    return ret
   
res1 = calc(a)
res2 = calc(b)
print("Yes" if res1 >= 0 and res1 == res2 else "No")

Measured memory_bytes: 194120
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        while(true) {
            String input = scanner.nextLine();
            
            if (input.equals("0 0")) {
                break;
            }
            
            String[] numbers = input.split(" ");
            List<String> list = Arrays.asList(numbers);
            Collections.sort(list, (c1, c2) -> Integer.parseInt(c1) - Integer.parseInt(c2));
            
            System.out.println(list.get(0) + " " + list.get(1)); 
        }
    }
}


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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> ans(n,-1);
  bool flag=false;
  for(ll i=0;i<m;i++) {
    ll s,c;
    cin >> s >> c;
    s--;
    if(ans[s]<0) {
      ans[s]=c;
    } 
    else if(ans[s]!=c){
      flag=true;
    }
  }
  if(flag) {
    cout << -1 << endl;
    return 0;
  }
  if(n!=1) {
    for(ll i=0;i<n;i++) {
      if(ans[i]>0) {
        cout << ans[i];
      }
      else if(ans[i]==0&&i==0) {
        cout << -1 << endl;
        return 0;
      }
      else {
        if(i==0) {
          cout << 1;
        }
        else {
          cout << 0;
        }
      }
    }
    cout << endl;
  }
  else {
    if(ans[0]<0) {
      cout << 0 << endl;
    }
    else {
      cout << ans[0] << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef pair<int,int> pii;
const int N = 2010;
char str[N][10010]; bitset<10010> can[N];
pii vis[2][N*N]; int now = 0; int cnt[2];
int len[N];
int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++) cin>>str[i],len[i] = strlen(str[i]);
  can[n+1][0] = 1;
  for(int i=n;i>=1;i--) can[i] =(can[i+1] << len[i]) | (can[i+1]);

  cnt[0]=cnt[1]=0;
  for(int i=1;i<=n;i++) if(can[i+1][k-len[i]])
  {
    cnt[0]++;
    vis[now][cnt[0]] = MP(i,0);
  }

  for(int i=1;i<=k;i++,now^=1)
  {
    cnt[now] = min(cnt[now] , 10000);
    char ch='z';
    for(int j=1;j<=cnt[now];j++)
    {
      int id = vis[now][j].first; int x=vis[now][j].second;
      if(str[id][x] < ch) ch = str[id][x];
    }printf("%c",ch);

    int minid = n+1; cnt[now^1] = 0;
    for(int j=1;j<=cnt[now];j++)
    {
      int id = vis[now][j].first; int x=vis[now][j].second;
      if(str[id][x] > ch) continue;
      if(x+1 == len[id]) minid = min( minid, id);
      else{cnt[now^1]++; vis[now^1][cnt[now^1]] = MP(id,x+1);}
    }
    
    for(int j=minid+1;j<=n;j++)
    {
      if((k-i-len[j])>= 0 && can[j+1][k-i-len[j]] )
      {
        cnt[now^1]++;
        vis[now^1][cnt[now^1]] = MP(j,0);
      }
    }
  }

  // cout<<(double)(clock())<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    bool d[101];
    for(int i = 0; i < 101; i++){
        d[i] = false;
    }
    for(int i = 0; i < n; i++){
        int m;
        cin >> m;
        d[m] = true;
    }
    int ans = 0;
    for(int i = 1; i < 101; i++){
        if(d[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>





const int N=1e5+10,M=1e9+7;
ll n,a,c[N],res;






void solve()
{
	cin>>n;
	for(int i=0;i<=n;i++)c[i]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		c[a]++;
	}
	res=1;
	for(int i=n-1;i>=0;i-=2)
	{
		if((i==0&&c[i]!=1)||(i>0&&c[i]!=2))
		{
			cout<<"0\n";
			return;
		}
		res=(res*c[i])%M;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n, x;
    scan(n, x);
    auto m = iota(n).map!(i => readln.chomp.to!int).array;
    writeln(n + (x - m.sum) / m.reduce!min);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int A[n][m];
    int b[m];
    int ans;

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

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

    for(int i=0;i<n;i++){
        ans = 0;
        for(int j=0;j<m;j++){
            ans += A[i][j] * b[j];
        }
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;
#define long long long

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n;
long f[N][2];
vector<int> g[N];

void Dfs(const int& k, const int& par)
{
    f[k][0] = f[k][1] = 1;
    for (int node : g[k]) if (node != par) {
        Dfs(node, k);
        (f[k][0] *= f[node][0] + f[node][1]) %= MOD;
        (f[k][1] *= f[node][0]) %= MOD;
    }
}

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 1, x, y; i < n; ++i) cin >> x >> y, g[x].push_back(y), g[y].push_back(x);
    Dfs(1, 0);
    cout << (f[1][0] + f[1][1]) % MOD;

    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n); i++)
#define sz(x) int(x.size())
using namespace std;

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

    d = 2*d+1;

    int ans = n/d;
    if(n%d!=0)ans++;

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


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll cal(vector<ll>& A, int sign)
{
  int n = A.size();
  ll ret = 0, diff = 0;
  for (int i = 0, s = sign; i < n; ++i, s *= -1) {
    if (A[i] + diff > 0 and s < 0) {
      ret += A[i] + diff + 1;
      diff -= A[i] + diff + 1;
    }
    else if (A[i] + diff < 0 and s > 0) {
      ret += abs(A[i] + diff) + 1;
      diff += abs(A[i] + diff) + 1;
    }
    else if (A[i] + diff == 0) {
      if (s < 0) {
        ++ret;
        --diff;
      }
      else {
        ++ret;
        ++diff;
      }
    }
  }

  return ret;
}

int main()
{
  int N; scanf("%d", &N);
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A[i]);
  }
  for (int i = 1; i < N; ++i) {
    A[i] += A[i - 1];
  }

  ll ans = min(cal(A, 1), cal(A, -1));
  printf("%lld\n", ans);
  return 0;
}


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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

string s, t;
int n, k;
int dp[302][302][302];

int go(int l, int r, int rem){
    if(rem < 0)
        return -inf;
    if(l >= r)
        return l == r;

    int &ans = dp[l][r][rem];
    if(~ans) return ans;

    ans = 0;
    if(s[l] == s[r])
        ans = max(ans, 2 + go(l + 1, r - 1, rem));
    ans = max(ans, 2 + go(l + 1, r - 1, rem - 1));
    ans = max({ans, go(l + 1, r, rem), go(l, r - 1, rem)});
    return ans;

}

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

    memset(dp, -1, sizeof(dp));
    cin >> s >> k;
    n = sz(s);
    cout << go(0,n-1,k);
}


Measured memory_bytes: 215552
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	string S;
	cin >> S;
	int ans = 0;
	rep(i, S.size() - 1)if (S[i] != S[i + 1])ans++;
	cout << ans;
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    const int max_N = 40;
    const int max_a = 10;
    const int max_c = 100;
    const int INF = 100 * max_c * max_N;

    public void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int Ma = cin.nextInt();
        int Mb = cin.nextInt();

        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];

        for(int i = 0;i<N;i++)
        {
            a[i] = cin.nextInt();
            b[i] = cin.nextInt();
            c[i] = cin.nextInt();
        }

        // dp[i][ca][cb] := 1からi番目までの薬品の組み合わせで,物質Aがcaグラム、物質Bがcbグラムとなる
        //                  溶液の最小のコスト

        int[,,] dp = new int[max_N + 1, (max_a + 1) * max_c + 1, max_a * (max_c + 1) + 1];
        for (int i = 0; i < max_N + 1; i++)
            for (int ca = 0; ca < (max_a + 1) * max_c + 1; ca++)
                for (int cb = 0; cb < max_a * (max_c + 1) + 1; cb++)
                    dp[i, ca, cb] = INF;

        dp[0, 0, 0] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int ca = 0; ca < max_a * max_c; ca++)
            {
                for (int cb = 0; cb < max_a * max_c; cb++)
                {
                    if (dp[i, ca, cb] == INF) continue;
                    dp[i + 1, ca, cb] = Math.Min(dp[i + 1, ca, cb], dp[i, ca, cb]);
                    dp[i + 1, ca + a[i], cb + b[i]] = Math.Min(dp[i + 1, ca + a[i], cb + b[i]]
                                                           , dp[i, ca, cb] + c[i]);
                }
            }
        }

        int ans = INF;
        for(int ca = 1;ca< max_a * max_c;ca++)
            for (int cb = 1; cb < max_a * max_c; cb++)
            {
                if (ca * Mb == cb * Ma) ans = Math.Min(ans, dp[N, ca, cb]);
            }

        if (ans == INF) ans = -1;
        Console.WriteLine(ans);
}


    class Scanner
    {
        string[] s;
        int i;

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

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

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

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 189152
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module _2017QualA =
    let private Yakiniku () =
        let s = ReadNext ()
        if s.StartsWith "YAKI" then "Yes" else "No"
        |> printfn "%s"

    let Entry = Yakiniku

_2017QualA.Entry ()

Measured memory_bytes: 14172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int sum;
  if((a==1&&b==2)||(a==2&&b==1)){
      sum=3;
  }
  else if((a==2&&b==3)||(a==3&&b==2)){

    sum=1;
  }
   else if((a==1&&b==3)||(a==3&&b==1)){
               sum=2;
          }
          cout<<sum<<endl;
          }






Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

const ll nmax = 1000000;

ll dp[nmax];
ll dp2[nmax];

int main() {
  fill(dp, dp + nmax, INF);
  fill(dp2, dp2 + nmax, INF);

  auto f = [](ll x) { return x * (x + 1) * (x + 2) / 6; };

  dp[0] = 0;
  dp2[0] = 0;

  rep(i, nmax) {
    ll n = 1;
    while (true) {
      ll fn = f(n);
      if (i - fn < 0) break;
      chmin(dp[i], dp[i - fn] + 1);
      if (fn % 2 == 1) chmin(dp2[i], dp2[i - fn] + 1);
      n++;
    } // while
  } // i

  while (true) {
    int N;
    cin >> N;
    if (N == 0) break;
    cout << dp[N] << " " << dp2[N] << endl;
  }
  return 0;
}



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

class Shop():
    def __init__(self, v, n):
        self.value = v
        self.zaiko = n

def solve():
    N, M = list(map(int, input().split()))
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        shops.append(Shop(a, b))
    
    shops.sort(key=lambda x: x.value)

    rest = M
    ans = 0
    for i in range(N):
        if shops[i].zaiko <= rest:
            ans += shops[i].value * shops[i].zaiko
            rest -= shops[i].zaiko
        else:
            ans += shops[i].value * rest
            break
    
    print(ans)


if __name__ == "__main__":
    solve()


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int N, L;
    cin >> N >> L;

    int left = L;
    int right = L + N - 1;
    
    int val_eat;
    if(right <= 0) val_eat = right;
    else if( left >= 0) val_eat = left;
    else val_eat = 0;

    cout << ((N * (N-1)/2) + (N * L) - val_eat) << endl;



    return 0;
}



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

int main(){
	int a, b, c;
	ll k;
	scanf("%d%d%d%lld", &a, &b, &c, &k);
	printf("%d\n", k & 1 ? b - a : a - b);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
struct Item{
    int a, b, c;
    Item(int _a, int _b, int _c) {
        a = _a;
        b = _b;
        c = _c;
    }
};
int n, base;
vector<Item> ret;
int solve(int& L) {
    int tmp = 0;
    while ((1<<tmp) <= L) {
        tmp++;
    }
    if (n == 0) {
        n = tmp;
        for (int i = 1; i+1 <= n; i++) {
            ret.emplace_back(i,i+1,0);
            ret.emplace_back(i,i+1, 1<<(i-1));
        }
    } else {
        ret.emplace_back(tmp, n, base);
    }
    L -= 1<<(tmp-1);
    base += 1<<(tmp-1);
}





int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int L; cin >> L;
    while (L) {
        solve(L);
    }
    cout << n << ' ' << ret.size() << endl;
    for (auto item : ret) {
        cout << item.a << ' ' << item.b << ' ' << item.c << endl;
    }










/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
 
int N;
long long nCk[200005];
long long n1Ck[200005];
long long mod = (long long)1e9+7;
long long res = 0;
 
// a^n mod を計算する
/*
long long modpow(long long a, long long n) {
  if (n == 0) return 1;
  res = modpow(a,n/2);
  res *= res % mod;
  if (n % 2 == 1) res *= a % mod;
  return res;
}
*/
long long modpow(long long x, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) { 
            res *= x;
            res %= mod;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return res;
}
 
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  long long res = 0;
  return modpow(a, mod - 2);
}
 
 
void calc(){
  nCk[0] = 1;
  n1Ck[0] = 1;
  for (int i=1; i<=N-1; i++){
    nCk[i] = (nCk[i-1]*((N-i+1)%mod)%mod)*modinv(i, mod);
    n1Ck[i] = (n1Ck[i-1]*((N-i)%mod)%mod)*modinv(i, mod);
    nCk[i] %= mod;
    n1Ck[i] %= mod;
  }
  nCk[N] = 1;
  return;
}
 
int main(){
  scanf("%d",&N);
  long long K;
  scanf("%lld", &K);
  //printf("N=%d, K=%lld\n", N, K);
  calc();
  K = std::min(K, (long long)N-1);
  long long ans = 0;
  for (int i=0; i<=K; i++){
    //printf("ans += %lld*%lld\n",nCk[i], n1Ck[i]);
    ans += (nCk[i]*n1Ck[i])%mod;
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3328
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

struct Node;
set<Node*> visited;
vector<int> v1, v2;
struct Node{
    vector<Node*> dests;
    int id;
    void add(Node* n){
        dests.push_back(n);
    }
    void add2(Node* n){
        add(n);
        n->add(this);
    }
    void solve(set<Node*>& visited, bool first = false){
        visited.insert(this);
        v1.push_back(id);
        for(Node* d : dests){
            if(visited.count(d)){ continue; }
            d -> solve(visited);
            if(!first){
                break;
            }else{
                first = false;
                v1.swap(v2);
            }
        }
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<Node> nodes(n);
    for(int i=0;i<n;i++){
        nodes[i].id = i + 1;
    }
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        nodes[a].add2(&nodes[b]);
    }
    // for(int i=0;i<n;i++){
    //     if(nodes[i].leaf()){
    //         nodes[i].dfs();
    //     }
    // }
    nodes[0].solve(visited, true);
    reverse(v1.begin(), v1.end());
    cout << v1.size() + v2.size() << '\n';
    for(int i : v1){
        cout << i << ' ';
    }
    for(int i : v2){
        cout << i << ' ';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 17912
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,c,x;
    int cnt,y[105];
    while(1){
        cin>>n>>a>>b>>c>>x;
        cnt=0;
        if(n==0 && a==0 && b==0 && c==0 && x==0){break;}
        for(int i=0;i<n;i++){
            cin>>y[i];
        }
        int i;
        for(i=0;i<10002;i++){
            if(x==y[cnt]){
                cnt++;
            }
            if(cnt==n){break;}
            x=(a*x+b)%c;
        }
        if(cnt==n && i < 10001){
            cout<<i<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 2980
//TEST_CODE
#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;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8101145141919364364;

int main(){
	int n; cin>>n;
	string r,s1,s2;
	string eins[]={".",".","#","#"};
	string zwei[]={".","#",".","#"};
	bool side=1;
	while(1){
		rep(i,4){
			string tmp1=(side?s1+eins[i]:eins[i]+s1);
			string tmp2=(side?s2+zwei[i]:zwei[i]+s2);
			cout<<tmp1<<"\n"<<tmp2<<"\n"; fflush(stdout);
			cin>>r;
			if(r=="end") return 0;
			if(r=="T"){
				s1=tmp1;
				s2=tmp2;
				if(s1.size()==n)
				{
					return 0;
				}
				break;
			}else if(i==3){
				side=0;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using i64 = long long;

template <class T>
std::vector<T> getDivisors(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<i64> a(n);
    i64 s = 0;
    for (auto &e : a) {
        std::cin >> e;
        s += e;
    }

    auto ds = getDivisors(s);

    auto ret = 0;
    for (auto d : ds) {
        i64 ss = 0;
        std::deque<i64> q;
        for (auto e : a) {
            auto r = e % d;
            q.push_back(r);
            ss += r;
        }

        if (ss % d) continue;

        std::sort(q.begin(), q.end(), std::greater<>());

        i64 p = 0, lim = ss / d;
        for (int i = 0; i < lim; i++) {
            p += d - q[i];
        }

        if (p <= k) ret = d;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
def ng():
  print "No"
  exit()

def ok():
  print "Yes"
  exit()

  
n = input()
t, x, y = 0, 0, 0
for i in range(n):
  nt, nx, ny = map(int, raw_input().split())
  dist = abs(nx - x) + abs(ny - y)
  dt = nt - t
  if dist > dt or (dist - dt) % 2 != 0:
    ng()
  t,x,y = nt, nx, ny

ok()
    

Measured memory_bytes: 5764
import sys
s, t = [ sys.stdin.readline().rstrip()
         for _ in range(2) ]
n = len(s)
yes = False
for i in range(n):
    if s[i] == t[0] and s[i:] + s[:i] == t:
        yes = True
        break
print("Yes" if yes else "No")

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

int main(){
	int n;
	stack<int> st;
	
	while(cin>>n){
		if(n!=0){
		st.push(n);
		}
		else{
		cout<<st.top()<<endl;
		st.pop();
		}
	}
		
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  str a; cin >> a;
  if(a[0] == a[1]&&a[1] == a[2]||a[1] == a[2]&&a[2] == a[3]) fin("Yes")
  else fin("No")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int maxAbsIndex = 0;
		int tmpMax = 0;
		for (int i = 0; i < n; i++) {
			tmpMax = Math.max(Math.abs(a[i]), tmpMax);
			if (Math.abs(a[i]) >= tmpMax) {
				maxAbsIndex = i;
			}

		}

		List<Answer> ans = new ArrayList<>();
		if (a[maxAbsIndex] < 0) {
			for (int i = 0; i < n; i++) {
				if (i != maxAbsIndex) {
					a[i] = a[i] + a[maxAbsIndex];
					ans.add(new Answer(maxAbsIndex, i));
				}
			}
			for (int i = n - 1; i >= 1; i--) {
				if (a[i] < a[i - 1]) {
					a[i - 1] = a[i - 1] + a[i];
					ans.add(new Answer(i, i - 1));
					i++;
				}
			}
		} else if (a[maxAbsIndex] > 0) {
			for (int i = 0; i < n; i++) {
				if (i != maxAbsIndex) {
					a[i] = a[i] + a[maxAbsIndex];
					ans.add(new Answer(maxAbsIndex, i));
				}
			}
			for (int i = 0; i < n - 1; i++) {
				if (a[i] > a[i + 1]) {
					a[i + 1] = a[i] + a[i + 1];
					ans.add(new Answer(i, i + 1));
					i--;
				}
			}
		}
		System.out.println(ans.size());
		for (Answer answer : ans) {
			System.out.print(answer.getFrom() + 1);
			System.out.print(" ");
			System.out.println(answer.getTo() + 1);
		}
	}
}

class Answer {
	private int from;
	private int to;
	public Answer(int from, int to) {
		this.from = from;
		this.to = to;
	}
	public int getFrom() {
		return from;
	}
	public int getTo() {
		return to;
	}
}

Measured memory_bytes: 21972
#include<stdio.h>

int main()
{
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d = a / b;
  r = a % b;
  f = 1.0 * a / b;
  printf("%d %d %.5lf\n",d,r,f);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int canuse[2025];

int main(){
  int L, R;
  cin >> L >> R;

  if(R-L >= 2500){
    int ret = 2500 * 2500;
    rep(i,2019){
      REP(j,i+1,2019){
        ret = min(ret, (i*j)%2019);
      }
    }
    cout << ret << endl;
  }else{
    int ret = 2500 * 2500;
    REP(l,L,R+1){
      REP(r,l+1,R+1){
        ret = min(ret, ((l%2019)*(r%2019))%2019);
      }
    }
    cout << ret << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	if (X < 0)X = -X;

	if (X / D >= K) {
		cout << X - K * D << endl;
	}
	else {
		K -= X / D;
		X %= D;
		if (K % 2) {
			cout << D - X << endl;
		}
		else {
			cout << X << endl;
		}
	}
}

Measured memory_bytes: 3628
N = int(input())
H = list(map(int,input().split()))
H[0] -= 1
for i in range(1,N):
  if H[i]-1 >= H[i-1]:
    H[i]-=1;
  elif H[i] < H[i-1]:
    print("No")
    break
else:
  print("Yes")
    

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

ll gcd(ll A, ll B){
    if(A<B) swap(A,B);
    while(B){
        ll w = A%B;
        A = B;
        B = w;
    }
    return A;
}

ll lcm(ll A, ll B){return A*B/gcd(A,B);}

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

    // solution comes here

    ll N, X;
    cin >> N >> X;
    vl x(N);
    rep(i, N) {
        cin >> x[i];
        x[i] = abs(x[i] - X);
    }
    
    for(ll i=1; i<N; i++) {
        x[i] = gcd(x[i], x[i-1]);
    }

    cout << x[N-1] << nl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main()
{
	int p=0,y=0,n,i;
	char a;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='Y')
			y=1;
                else{p=1;}
	}
	if(y==0)
		cout<<"Three";
	if(y==1)
		cout<<"Four";
	return 0;
}


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

using namespace std;
const int divisor = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vector<vector<long long int>> combination(N + 1, vector<long long int>(N + 1)); // 0 to N
    for (int i = 0; i < N + 1; ++i) {
        for (int j = 0; j < i + 1; ++j) {
            if (j == 0 || j == i) {
                combination.at(i).at(j) = 1;
            } else {
                combination.at(i).at(j) = (combination.at(i - 1).at(j - 1) + combination.at(i - 1).at(j)) % divisor;
            }
        }
    }

    for (int i = 1; i < K + 1; ++i) {
        cout << (combination.at(N - K + 1).at(i) * combination.at(K - 1).at(i - 1)) % divisor << "\n";
    }
    return 0;
}


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

int main(){
  int q;
  cin >> q;
  for(int m=0; m<q; m++){
    string wordx, wordy;
    cin >> wordx >> wordy;
    int L[1010][1010]={0};
    
    for(int j=0; j<wordy.size(); j++){
      for(int i=0; i<wordx.size(); i++){
	if(wordx[i]==wordy[j]){
	  L[i+1][j+1] = 1+L[i][j];
	}
	else{
	  L[i+1][j+1] = max(L[i+1][j], L[i][j+1]);
	}
      }
    }
    cout << L[wordx.size()][wordy.size()] << endl;
    
    
  }
}

Measured memory_bytes: 5200
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
	int N;
		cin >> N;
	int maxs=0,all=0;
	for(int i=0;i<N;i++){
		int a;
			cin >> a;
		maxs=max(maxs,a);
		all+=a;
	}
	all-=maxs;
	cout << (all>maxs?"Yes":"No") << endl;
	return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n , m;
bool bad[ N ];
LL dp[ N ][ 3 ];

LL solve( int idx , int k ) {
        if( idx == n ) return 1;
        if( dp[idx][k] != -1 ) return dp[idx][k];
        LL ret = 0;
        if( idx + 1 <= n && !bad[idx+1] ) ret += solve( idx + 1 , 1 );
        ret %= MOD;
        if( idx + 2 <= n && !bad[idx+2] ) ret += solve( idx + 2 , 2 );
        ret %= MOD;
        return dp[idx][k] = ret;
}
int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n >> m;
        for( int i = 1; i <= m; i++ ) {
                int x;
                cin >> x;
                bad[x] = true;
        }
        memset( dp , -1 , sizeof(dp) );
        cout << solve( 0 , 0 ) << endl;
        return 0;
}










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

int main(void){
    string n;
    cin >> n;
    bool ok = false;
    if(n[0]=='7') ok = true;
    if(n[1]=='7') ok = true;
    if(n[2]=='7') ok = true;

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,m;
    while(cin >> n >> m, n||m){
        string s;
        vector<int> p;
        vector<int>::iterator it;
        range(i,1,n+1){
            p.push_back(i);
        }
        range(i,1,m+1){
            cin >> s;
            if(p.size() == 1) continue;
            //テ」ツ?セテ」ツ?ィテ」ツつ?」ツ?淌」ツ??
            if(i % 3 == 0 && i % 5 == 0){
                if(s == "FizzBuzz"){
                    p.push_back(p.front());
                }
            }else if(i % 3 == 0){
                if(s == "Fizz"){
                    p.push_back(p.front());
                }
            }else if(i % 5 == 0){
                if(s == "Buzz"){
                    p.push_back(p.front());
                }
            }else{
                char num[10];
                for(int j = s.size(); j >= 0; j--){
                    num[j] = s[j];
                }
                if(i == atoi(num)){
                    p.push_back(p.front());
                }
            }
            p.erase(p.begin());
        }
        sort(p.begin(), p.end());
        for(it = p.begin(); it != p.end(); it++){
            if(it != p.begin()) cout << ' ';
            cout << *it;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7, dp[1<<21+5];
int main()
{
    int n, a;
    cin >> n;
    int arr[n][n];
    for(int i = 0; i < n; i++)for(int j = 0; j < n; j++)cin >> arr[i][j];
    dp[0]++;
    for(int i = 0; i < (1 << n)-1; i++){
        int a = __builtin_popcount(i);
        for(int j = 0; j < n; j++){
            if((i&(1<<j)) == 0 and arr[a][j] == 1 )dp[i|((1<<j))] = (dp[i|((1<<j))]+ dp[i])%mod;
        }
    }
    cout << dp[(1<<n)-1];
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 

void DEBUG_ARR(vt<T> a)
{
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}
int dp[1001][1<<12];
int n;
int solve(int pos,int mask,vt <pair<int,int>> &keys){
    if(dp[pos][mask]==-1){
        if(pos==keys.size()){
            if(mask==((1<<n)-1))return dp[pos][mask]=0;
            else return dp[pos][mask]=MAXN;
        } 
        dp[pos][mask]=min(solve(pos+1,mask,keys),solve(pos+1,mask|keys[pos].second,keys)+keys[pos].first);
    }
    return dp[pos][mask];
}
int main() 
{ 
  memset(dp,-1,sizeof dp);
  fastio;
  int m;
  cin>>n>>m;
  vt <pair<int,int>> keys;
  f(i,0,m){
      int a,b;
      cin>>a>>b;
      int c=0;
      f(i,0,b){
          int x;
          cin>>x;
          x--;
          x=(1<<x);
          c=(c|x);
      }
      keys.pb({a,c});
  }
  int ans=(solve(0,0,keys)<MAXN)?solve(0,0,keys):-1;
  cout<<ans<<"\n";
  return 0; 	
}


Measured memory_bytes: 16384
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
long long n,a[1010],b[1010],c[1010],k,x,y,z;
vector<long long> v,vv;
int main(){
	cin>>x>>y>>z>>k;
	for (long long i=0;i<x;i++) cin>>a[i];
	for (long long i=0;i<y;i++) cin>>b[i];
	for (long long i=0;i<z;i++) cin>>c[i];
	sort(a,a+x);sort(b,b+y);sort(c,c+z);
	for (long long i=0;i<x;i++)
		for (long long j=0;j<y;j++)
				v.push_back(a[i]+b[j]);
	sort(v.begin(),v.end(),greater<long long>());
	long long e=3000,f=v.size();
	for (long long i=0;i<min(e,f);i++)
		for (long long j=0;j<z;j++)
			vv.push_back(v[i]+c[j]);
	sort(vv.begin(),vv.end(),greater<long long>());
	long long d=vv.size();
	for (long long i=0;i<k;i++) cout<<vv[i]<<endl;
	return 0;
}

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

int n, m, q;
int a;
list<int> ls;
list<int>::iterator it;
bool f[200000];

int main()
{
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++){
		ls.insert(ls.end(), i);
	}
	it = ls.begin();
	for (int i = 0; i < m; i++){
		scanf("%d", &a);
		for (int j = 0; j < a; j++){
			//printf("%d\n", *it);
			if (a % 2 == 0){
				if (++it == ls.end()){
					it = ls.begin();
				}
			}
			else {
				if (it == ls.begin()){
					it = ls.end();
				}
				--it;
			}
		}
		//printf("%d\n", *it);
		f[*it] = true;
		it = ls.erase(it);
		if (it == ls.end()) it = ls.begin();
	}
	
	for (int i = 0; i < q; i++){
		scanf("%d", &a);
		printf("%d\n", !f[a]);
	}
}

Measured memory_bytes: 7632
var
	n,m,i,a,b:Longint;
	used:array[1..8]of Boolean;
	G:array[1..8,1..8]of Boolean;
function f(u,cnt:Longint):Longint;
var i,ret:Longint;
begin
	if cnt=n then begin
		f:=1;
		exit;
	end;
	ret:=0;
	for i:=1 to n do begin
		if G[u,i]and not used[i]then begin
			used[i]:=True;
			inc(ret,f(i,cnt+1));
			used[i]:=False;
		end;
	end;
	f:=ret;
end;
begin
	read(n,m);
	for i:=1 to m do begin
		read(a,b);
		if b<>1 then begin
			G[a,b]:=True;
		end;
		if a<>1 then begin
			G[b,a]:=True;
		end;
	end;
	used[1]:=True;
	writeln(f(1,1));
end.

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::vector<int> A(N);
  std::map<int, int> m;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    m[A[i]]++;
  }
  std::sort(A.begin(), A.end(), std::greater<int>());

  int pow2 = 1;
  while (pow2<=A[0]) pow2 *= 2;

  int counter = 0;
  for (int i = 0; i < N; ++i) {
    while(A[i]<(pow2/2)) pow2 /= 2;

    int v = A[i];
    int rem = pow2 - v;

    if (m.find(v) == m.end() || m.find(rem) == m.end()) continue;

    if (v != rem) {
      int hit = std::min(m[v], m[rem]);
      counter += hit;
      m[v] -= hit;
      m[rem] -= hit;
    } else {
      counter += m[v]/2;
      m[v] = m[v]%2;
    }
  }
  std::cout << counter<<std::endl;
}


Measured memory_bytes: 10368
import sys
abcd=str(input())
n=len(abcd)
ans=int(abcd[0])
sign=[]
for i in range(2**(n-1)):
    for j in range(n-1):
        if (i>>j)&1==True:
            ans+=int(abcd[j+1])
            sign.append("+")
        else:
            ans-=int(abcd[j+1])
            sign.append("-")
    if ans==7:
        print(abcd[0]+sign[0]+abcd[1]+sign[1]+abcd[2]+sign[2]+abcd[3]+"=7")
        sys.exit()
    else:
        ans=int(abcd[0])
        sign=[]

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll s;
    cin>>s;
    vector<ll> ans;
    for(ll i=3; i<=s; i++)
    {
        ans.pb(i);
    }
    ll n = ans.size();
    vector<ll> dp(s + 1, 0);
    dp[0] = 1;
    for(ll k=1; k<=s; k++)
    {
        for(ll i=0; i<n; i++)
        {
           if(k>=ans[i])
                dp[k] = (dp[k] + dp[k - ans[i]])%mod;
        }
    }
    cout<<dp[s]<<'\n';
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main()
{
    int n,W,i,j;
    ull max(ull,ull);
    cin>>n>>W;
    int w[n],v[n];
    for(i=0;i<n;i++)
        cin>>w[i]>>v[i];
    ull dp[n+1][W+1];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=W;j++)
        {
            if((i==0)||(j==0))
                dp[i][j]=0;
            else if(j<w[i-1])
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
        }
    }
    cout<<dp[n][W];
}
ull max(ull a,ull b)
{
    if(a>b)
        return(a);
    else
        return(b);
}

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <utility>
#define ll long long int
using namespace std;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


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

using namespace std;

int main() {

	int x, y;
	cin >> x >> y;

	for (int i = 0; i <= x; i++) {
		int j = x - i;
		if (i * 2 + j * 4 == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;

int n;
string s;

char inv(char c) {
  return (c == 'S') ? 'W' : 'S';
}

bool solve(string& t, char fir, char sec) {
  t[0] = fir; t[1] = sec;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'o') {
      if (t[i] == 'S') t[i + 1] = t[i - 1];
      else t[i + 1] = inv(t[i - 1]);
    } else {
      if (t[i] == 'S') t[i + 1] = inv(t[i - 1]);
      else t[i + 1] = t[i - 1];
    }
  }

  if (t[0] != t[n]) return false;

  if (s[0] == 'o') {
    if (t[0] == 'S') return t[n - 1] == t[1];
    else return t[n - 1] != t[1];
  } else {
    if (t[0] == 'S') return t[n - 1] != t[1];
    else return t[n - 1] == t[1];
  }
}

int main(void) {
  cin >> n >> s;

  string ans = "-1", cs = s + s[0];
  char c[2] = {'S', 'W'};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (solve(cs, c[i], c[j])) {
        ans = cs.substr(0, n);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100*10],ans;
int main()
{
  scanf("%d",&n);
  for(int i=0;i<n*2;i++)scanf("%d",&a[i]);
  sort(a,a+n*2);
  for(int i=0;i<n;i++)ans+=a[i*2];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define INF 1<<30

int k;
bool iroha[11];

int kodera(int n){
    int keta=1;
    int tmpn=n;
    while(tmpn>9){tmpn/=10; keta*=10;}

    int res=0;
    while(keta>0){
        if(iroha[n/keta]==false){
            return kodera(res + (n/keta+1)*keta);
        }
        res += (n/keta)*keta;
        n -= (n/keta)*keta;
        keta/=10;
    }
    return res;
}

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

    fill(iroha, iroha+11, true);

    rep(i,k){ int d; cin>>d; iroha[d]=false; }

    cout<< kodera(n) << endl;

    return 0;
}


Measured memory_bytes: 256