akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

template <typename T>
T MODpow(T x, T n, T MOD = 1000000007) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

signed main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    Mint<> cnt[61] = {};
    REP(i,n){
        REP(j,61){
            if(a[i] & 1LL << j) cnt[j] += 1;
        }
    }
    Mint<> ans = 0;
    Mint<> two = 2;
    REP(i,61){
        ans += cnt[i] * ((Mint<>)n - cnt[i]) * two.pow(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
// 3_abc131_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

ll gcd(ll x, ll y){
    if(x < y) swap(x, y);

    while(y > 0){
        ll r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll lcm(ll x, ll y){
    ll z = x * y / gcd(x, y);
    return z;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll n_c, n_d, n_cd;// c, d, cdで割り切れるものの数
    n_c = b / c - a / c;
    if(a % c == 0) n_c++;

    n_d = b / d - a / d;
    if(a % d == 0) n_d++;

    ll e = lcm(c, d);
    n_cd = b / e - a / e;
    if(a % e == 0) n_cd++;

    cout << b - a + 1 - (n_c + n_d - n_cd) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        System.out.println(ans);
    }
}

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

int A[50];
int n;

bool solve(int i, int m) {
    if(m == 0) return true;
    if(i >= n) return false;
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    int q;
    int m;
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> m;
        if(solve(0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

s=input()
s=s.replace("BC","D")
acnt=0
dcnt=0
ans=0
for i in s[::-1]:
    if i=="D":
        ans+=acnt*dcnt
        acnt=0
        dcnt+=1
    elif i=="A":
        acnt+=1
    else:
        ans += acnt * dcnt
        acnt=0
        dcnt=0
ans+=acnt*dcnt
print(ans)

Measured memory_bytes: 3500
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();

int gcd(int a,int b);
int main() {

	int n, ans = 0, tmp = 0;
	cin >> n;
	vi a(1000000), lef(1000000),ri(1000000);
	rep(i, n)
		cin >> a[i];

	tmp = a[0];
	lef[0]=tmp;
	REP(i,1,n)
		tmp = lef[i] = gcd(tmp, a[i]);


	tmp=a[n-1];
	ri[n-1]=a[n-1];
	rrep(i,n) {
		tmp = ri[i] = gcd(tmp, a[i]);
	}

	ans=max(lef[n-2],ri[1]);
	//cout<<ans<<endl;
	REP(i,1,n-1)
		ans=max(gcd(lef[i-1],ri[i+1]),ans);
/*
	cout<<"left"<<endl;
	rep(i,n)
		cout<<lef[i]<<endl;
	puts("");
	rep(i,n)
		cout<<ri[i]<<endl;
*/
	cout <<ans << endl;
}




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

Measured memory_bytes: 12032
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        int[] as = new int[n];
        PriorityQueue<P> q = new PriorityQueue<>();

        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
            q.add(new P(i, as[i]));
        }

        long[][] dp = new long[n + 1][n + 1];
        Arrays.fill(dp[0], -1);
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            P cur = q.remove();
//            debug(cur.c, cur.idx);
            for (int j = 0; j <= i; j++) {
                if (j > 0 && dp[i - 1][j - 1] >= 0) {
//                    debug("l", i, j, dp[i - 1][j - 1], Math.abs(cur.idx - j + 1) * cur.c);
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1L * Math.abs(cur.idx - j + 1) * cur.c);
                }
                if (dp[i - 1][j] >= 0) {
//                    debug("r", i, j, dp[i - 1][j], Math.abs(cur.idx - (n - 1 - (i - j - 1))) * cur.c);
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j] + 1L * Math.abs(cur.idx - (n - 1 - (i - j - 1))) * cur.c);
                }
            }
//            debug(dp[i]);
        }

        long ans = 0;
        for (int i = 0; i <= n; i++) {
            ans = Math.max(ans, dp[n][i]);
        }

        out.println(ans);


        out.flush();
    }

    class P implements Comparable<P> {
        int idx, c;
        P(int idx, int c) {
            this.idx = idx;
            this.c = c;
        }

        @Override
        public int compareTo(P o) {
            return o.c - c;
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

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

public class HelloWorld
{
    static bool res = false;
    static public void Main()
    {
        var NL = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NL[0];
        var L = NL[1];
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var ans = false;

        var last = -1;
        for (int i = 0; i < N -1; i++)
        {
            if(A[i] + A[i+1] >= L)
            {
                last = i+1;
                ans = true;
                break;
            }
        }

        var pippi = new List<long>();
        for (int i = 0; i < last -1; i++)
        {
            pippi.Add(i + 1);
        }

        for (int i = (int)N - 2; i >= last; i--)
        {
            pippi.Add(i + 1);
        }
        pippi.Add(last);

        if (ans)
        {
            Console.WriteLine("Possible");
            for (int i = 0; i < pippi.Count(); i++)
            {
                Console.WriteLine(pippi[i]);
            }
        }
        else
        {
            Console.WriteLine("Impossible");
        }
        
    }
}


Measured memory_bytes: 41216
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int H, W, R[2000][2000], maximum = 0;
  bool S[2000][2000];
  string s;

  cin >> H >> W;
  REP(i, H)
  {
    cin >> s;
    REP(j, W)
    {
      S[i][j] = s[j] == '.';
    }
  }

  int cnt;
  REP(i, H)
  {
    REP(j, W)
    {
      if (S[i][j])
      {
        cnt = 1;
        FOR(k, j + 1, W)
        {
          if (S[i][k])
            cnt++;
          else
            break;
        }
        REP(k, cnt)
        {
          R[i][j + k] = cnt;
        }
        j += cnt - 1;
      }
      else
      {
        R[i][j] = 0;
      }
    }
  }
  REP(i, W)
  {
    REP(j, H)
    {
      if (S[j][i])
      {
        cnt = 1;
        FOR(k, j + 1, H)
        {
          if (S[k][i])
            cnt++;
          else
            break;
        }
        REP(k, cnt)
        {
          R[j + k][i] += cnt - 1;
        }
        j += cnt - 1;
      }
    }
  }

  REP(i, H)
  {
    REP(j, W)
    {
      maximum = max(maximum, R[i][j]);
    }
  }

  cout << maximum << '\n';
  return 0;
}

Measured memory_bytes: 19840
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
score = 0

for i in range(N):
  if i > 0:
    if A[i-1]+1 == A[i]:
  	  score = score + (B[A[i]-1] + C[A[i]-2])
    else:
      score += B[A[i]-1]
      #print("plus : {}".format(B[A[i]-1]))
  else:
    score += B[A[i]-1]
    #print("plus : {}".format(B[A[i]-1]))
  #print(score)
  
print(score)



Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    // 0 dummy, 1 A, 2 G, 3 C, 4 T
    ll dp[N+1][5][5][5] = {0};

    ll mod = 1e9+7;
    dp[0][0][0][0] = 1;
    for (int n = 0; n < N; n++) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                for (int k = 0; k < 5; k++) {
                    for (int l = 1; l < 5; l++) {
                        // dp[n][i][j][k] から dp[n+1][j][k][l] を考える

                        // AG*C
                        if (i==1 && j==2 && l==3) continue;
                        // A*GC
                        if (i==1 && k==2 && l==3) continue;
                        // *AGC
                        if (j==1 && k==2 && l==3) continue;
                        // *GAC
                        if (j==2 && k==1 && l==3) continue;
                        // *ACG
                        if (j==1 && k==3 && l==2) continue;

                        dp[n+1][j][k][l] = (dp[n+1][j][k][l]+dp[n][i][j][k]) % mod;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 1; i < 5; i++)
    {
        for (int j = 1; j < 5; j++)
        {
            for (int k = 1; k < 5; k++)
            {
                ans = (ans+dp[N][i][j][k]) % mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl


void func() {
  LL N;
  cin >> N;
  N--;
  vector<LL> C(N);
  vector<LL> S(N);
  vector<LL> F(N);

  REP(i, N) {
    cin >> C[i];
    cin >> S[i];
    cin >> F[i];
  }

#if 0
  PRINTLN(C);
  PRINTLN(S);
  PRINTLN(F);
#endif

  for (LL start = 0; start < N+1; start++) {
    LL now = 0;
    for (LL i = start; i < N; i++) {
      now = max(now, S[i]);
      
      LL wait = (now - S[i]) % F[i];
      LL wait_ = 0;

      // slow
      // for (; now % F[i] != 0; now++) {}
      
      // mid
      if (now % F[i] != 0) {
        now += F[i] - (now % F[i]);
      }

      // fast
      now += F[i] - ((now - 1) % F[i] + 1);

      now += C[i];
    }
    cout << now << endl;
  }
}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    for (auto a : v) os << a << ", ";
    os << "]";
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto a : mp) os << "{" << a.first << ":" << a.second << "}, ";
    os << "]";
    return os;
}

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    ll A, B;
    cin >> A >> B;
    map<ll, int> ap, bp;
    ap = prime_factor(A);
    bp = prime_factor(B);

    ll ans = 0;
    for (auto p : ap) {
        if (bp.find(p.first) != bp.end()) ans++;
    }

    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 3660
from collections import deque
a = deque(list(input()))
b = deque(list(input()))
c = deque(list(input()))

card = a.popleft()

while True:
  if card == "a":
    if not a:
      print("A")
      exit()
    else:
      card = a.popleft()
  elif card == "b":
    if not b:
      print("B")
      exit()
    else:
      card = b.popleft()
  else:
    if not c:
      print("C")
      exit()
    else:
      card = c.popleft()
#print(a,b,c)


Measured memory_bytes: 3316
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]

    neg = pos = 0
    for x in X:
        if x > 0:
            pos += x
        else:
            neg += x

    M = pos - neg
    base = -neg

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][base] = 1

    for i in range(N):
        for s in range(M + 1):
            dp[i + 1][s] = dp[i][s]
            if 0 <= s - X[i] <= M:
                dp[i + 1][s] += dp[i][s - X[i]]

    print(dp[N][base] - 1)
    return


if __name__ == '__main__':
    main()


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

int main() {
  char a;
  cin >> a;
  
  string A ="abcdefghijklnmopqrstuvwxyz";
  
  for(int i = 0;i<26;i++) {
    if(a == A.at(i)) {
      a = A.at(i+1);
      break;
    }
  }
  cout << a <<endl;
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> a(10001, 0);
    for (int x = 1; x<100; x++) {
        for (int y = 1; y<100; y++) {
            for (int z = 1; z<100; z++) {
                int b = x*x+y*y+z*z+x*y+y*z+z*x;
                if (b < 10001) a[b]++;
            }
        }
    }
    for (int i=1; i<=n; i++) 
        cout << a[i] << '\n';
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A, B; cin >> A >> B;
	cout << (A*B%2 ? "Yes" : "No") << endl;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(b))

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

int target;
string nums;
int n;

int sum;
vector<int> part;
bool reject;

void rec(int i, vector<int> d, int sums, int tmp) {
	//if (i != 0 && tmp == 0) return;
	
	if (i == n) {
		sums += tmp;
		d.push_back(tmp);
		/*
		cout << sums << " ";
		for_(k,0,(int)d.size()) {
			if (k < (int)d.size() - 1) cout << d[k] << " ";
			else cout << d[k] << endl;
		}
		*/
		if (target >= sums) {
			if (sums > sum) {
				reject = false;
				sum = sums;
				part = d;
			} else if (sums == sum) {
				bool flag = true;
				int psize = (int)part.size();
				int dsize = (int)d.size();
				if (psize == dsize) {
					vector<int> sp = part, sd = part;
					sort(allof(sp)); sort(allof(sd));
					for_(k,0,psize) if (sp[k] != sd[k]) flag = false;
				}
				if (flag) reject = true;
			}
		}
		return;
	}
	
	int rtmp = tmp;
	
	int add = (int)(nums[i] - '0');
	tmp = 10 * tmp + add;
	rec(i + 1, d, sums, tmp);
	
	if (i != 0) {
		tmp = rtmp;
		sums += tmp;
		d.push_back(tmp);
		tmp = add;
		rec(i + 1, d, sums, tmp);
	}
}

void solve() {
	//cout << target << " " << nums << endl;
	n = (int)nums.size();
	sum = -1;
	part.clear();
	reject = false;
	
	rec(0,vector<int>(), 0, 0);
	
	if (sum == -1) cout << "error" << endl;
	else if (reject) cout << "rejected" << endl;
	else {
		cout << sum << " ";
		int psize = (int)part.size();
		for_(i,0,psize) {
			if (i < psize - 1) cout << part[i] << " ";
			else cout << part[i] << endl;
		}
	}
}

int main() {
	while (cin >> target >> nums, target) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1224
N, x = map(int, input().split())
a = [int(x) for x in input().split()]

a.sort()
ans = 0

for i in range(N):
	if x >= a[i]:
		ans += 1
		x -= a[i]
	else:
		break

if x > 0 and ans != 0 and ans == N:
	ans -= 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    int n;
    cin>>n;
    int a[n+1];
    int sum=0;
    for (int i = 1; i <=n ; ++i) {
        cin>>a[i];
        if(i%2==1 && i<n)
            sum+=a[i];
        else if(i<n)
            sum-=a[i];
    }
    int z=(sum+a[n]);


    vector<int>ans;
    ans.push_back(z);
    for (int i = 1; i < n; ++i) {
        ans.push_back(2*a[i]-ans.back());
    }

    for(auto i:ans)
        cout<<i<<" ";

}

Measured memory_bytes: 3060
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;
map<int, int> m1, m2;
int a[13];
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	a[2] = -1;
	a[4] = a[6] = a[9] = a[11] = 1;

	int x, y; cin >> x >> y;
	cout << (a[x] == a[y] ? "Yes\n" : "No\n");
	
	return 0;   
}  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int r = scanner.nextInt();
        int g = scanner.nextInt();
        int b = scanner.nextInt();

        int number = r * 100 + g * 10 + b;

        System.out.println(number % 4 == 0 ? "YES" : "NO");
    }
}


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

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define FR(i, l, r) for(int i = (l); i <= (r); i++)
#define gcd __gcd 
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);

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

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
template <typename T> inline void out(T x) { cout << x; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	int s;
	cin >> s;
	if(s % 4 == 0 || s % 7 == 0)
		return cout << "Yes", 0;
	if(s < 4)
		return cout << "No", 0;
	while(true)
	{
		s -= 4;
		if(s % 7 == 0)
			return cout << "Yes", 0;
		if(s < 4)
			return cout << "No", 0;
	}
}

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

int main() {
  int N, x, a = 1000000000, b;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    b = 0;
    cin >> x;
    
    while (x % 2 == 0) {
      x /= 2;
      b++;
    }
    
    if (a > b)
      a = b;
  }
  
  cout << a;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N, A, B, C; cin >> N >> A >> B >> C;
   V<int> l(N);
   REP(i, N) {
      cin >> l[i];
   }

   int ans = INF;
   FOR(s1, 1, 1<<N) FOR(s2, 1, 1<<N) FOR(s3, 1, 1<<N) {
      if (s1 & s2 || s2 & s3 || s3 & s1) continue;
      int a = 0, b = 0, c = 0, n = 0;
      REP(i, N) if (s1 >> i & 1) {
         a += l[i]; n++;
      }
      REP(i, N) if (s2 >> i & 1) {
         b += l[i]; n++;
      }
      REP(i, N) if (s3 >> i & 1) {
         c += l[i]; n++;
      }
      chmin(ans, 10*(n-3) + abs(A-a) + abs(B-b) + abs(C-c));
   }
   cout << ans << endl;

   return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
  int n,k;
  cin >> n >> k;
  if(n%k!=0) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
from sys import stdin

def is_kaibun(S):
    for i in range(len(S) // 2):
        if S[i] != S[-i - 1]:
            print('No')
            return False
    return True


def main():
    S = (stdin.readline()).replace('\n', '')
    N = len(S)

    if len(S) % 2 == 0:
        print('No')
        return

    # 回分チェック
    if not is_kaibun(S): return

    # 中に回文が含まれるか？

    for c in [S[0:N // 2], S[N // 2 + 1:]]:
        if not is_kaibun(c): return

    # output
    print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

def find_negative_loop(n,w,es):
  dist=[float("inf")]*n
  #この始点はどこでもよい
  dist[1]=0
  
  for i in range(n):
    for j in range(w):
      e=es[j]
      if dist[e[1]]>dist[e[0]]+e[2]:
        dist[e[1]]=dist[e[0]]+e[2]
        if i==n-1:
          return True
  return False

def shortest_path(s,n,w,es):
  #s→iの最短距離
  #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト]
  dist=[float("inf")]*n
  #d[i]: s→iの最短距離
  dist[s]=0

  while True:
    update=False
    for p,q,r in es:
      # e: 辺iについて [from,to,cost]
      if dist[p]!=float("inf") and dist[q]>dist[p]+r:
        dist[q]=dist[p]+r
        update=True
    if not update:
      break
      
  return dist

graph=[[] for _ in range(N+1)]
elist=[]
for _ in range(M):
  a,b,c=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b,-c))
  
#remove unnecessary vertex and edge
visited=[None]*(N+1)
def check_reachable(u):
  visited[u]=True
  if u==N:
    reachable[u]=True
    return True
  elif reachable[u]!=None:
    return reachable[u]  

  cnt=0
  for v in graph[u]:
    if not visited[v]:
      ret=check_reachable(v)
      if ret:
        cnt+=1
        
  if cnt>0:
    reachable[u]=True
    return True
  else:
    reachable[u]=False
    return False

reachable=[None]*(N+1)
for i in range(1,N+1):
  if reachable[i]==None:
    visited=[False]*(N+1)
    check_reachable(i)
#print(reachable)
  
elist2=[]
for a,b,nc in elist:
  if reachable[a] and reachable[b]:
    elist2.append((a,b,nc))
  
M2=len(elist2)
res1=find_negative_loop(N+1,M2,elist2)

if res1:
  print("inf")
else:
  res2=shortest_path(1,N+1,M2,elist2)
  print(-res2[N])

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  
  int x = 0;
  int ans = 0;
  rep(i,N) {
    S.at(i) == 'I' ? x++ : x--;
    ans = max(ans,x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  // A B
  var numbers: number[] = lines[0].split(" ").map(x => {
    return Number(x);
  });
  var numA: number = Number(lines[0]);
  var numB: number = Number(lines[1]);
  var numC: number = Number(lines[2]);
  var numD: number = Number(lines[3]);
  var result: number = 0;
  if (numA < numB) {
    result = numA;
  } else {
    result = numB;
  }
  if (numC < numD) {
    result = result + numC;
  } else {
    result = result + numD;
  }

  console.log(result);
});


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

int main(){
  int N, K;
  cin >> N >> K;
  int A = 1;
  int X, Y;
  for(int i; i < N; i++){
    X = A * 2;
    Y = A + K;
    if(X >= Y){
      A = Y;
    }
    else if(Y >= X){
      A = X;
    }
  }
  
  cout << A << endl;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

struct hoge {
    vi bd;
    int depth;
    int x;
    int y;
    bool check(int x,int y) {
        return ((bd[y]&(1<<x))>>x);
    }
};
signed main() {
    while(true) {
        int w,h;
        cin>>w>>h;
        if(w==0 && h==0) break;
        int sx,sy,gx,gy;
        hoge init;
        REP(i,h) {
            int mask=0;
            REP(j,w) {
                int a;
                cin>>a;
                if(a==2) sy=i,sx=j;
                else if(a==3) gy=i,gx=j;
                else {
                    mask|=(a<<j);
                }
            }
            init.bd.push_back(mask);
        }
        init.x=sx;
        init.y=sy;
        init.depth=0;

        queue<hoge> q;
        q.push(init);
        int ans=-1;
        while(!q.empty()) {
            hoge s=q.front(); q.pop();
            if(s.x==gx && s.y==gy) {
                ans=s.depth;
                break;
            }
            if(s.depth>=10) {
                continue;
            }

            REP(i,4) {
                hoge ns=s;
                if(ns.check(ns.x+DX[i],ns.y+DY[i])) continue;
                bool invalid=false;
                while(!ns.check(ns.x,ns.y)) {
                    ns.x+=DX[i];
                    ns.y+=DY[i];
                    if(ns.x==gx && ns.y==gy) {
                        ans=ns.depth+1;
                        goto end;
                    }
                    if(ns.x<0 || ns.x>=w || ns.y<0 || ns.y>=h) {
                        invalid=true;
                        break;
                    }
                }
                if(invalid) continue;

                ns.bd[ns.y]^=(1<<ns.x);
                ns.x-=DX[i];
                ns.y-=DY[i];
                ns.depth++;
                q.push(ns);
            }
        }

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

Measured memory_bytes: 12924
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(m);
    LL ans = 0;
    VVI vvi(11);
    VI p;
    rep(i, m){
        cii(k);
        rep(j, k){
            cii(s);
            vvi[i].pb(s);
        }
    }
    rep(i, m){
        cii(pp);
        p.pb(pp);
    }
    rep(bit, (1<<n)){
        bool flag = true;
        rep(i, m){
        	int sum = 0;
            for(auto&& j : vvi[i]){
                if(bit & (1<<j-1)){
                  	dump(bit);
                  dump(j);
                    sum++;
                }
            }
          dump(p[i]);
          dump(sum);
            flag = flag && (p[i] == sum % 2);
        }
        if(flag) ans++;
    }

    co(ans);
    return 0;
}

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

alp = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
out = ''

for i in range(len(s)):
  a = alp.index(s[i])
  b = a+n
  if b > 25:
    b = b - 26
  out += alp[b]

print(out)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    for(int i=0;i<w+2;i++){
        cout << "#";
    }
    cout << endl;
    for(int i=0;i<h;i++){
        string x;
        cin >> x;
        cout <<"#" << x << "#" <<endl;
    }
    for(int i=0;i<w+2;i++){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<deque>
#include<vector>
#include<algorithm>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 110
using namespace std;

struct P
{
  int id; 
  bool ex;
  P(int id=-inf,bool ex=true):id(id),ex(ex){}
};

int CNT[MAX];
deque<P> desk[MAX];
deque<int> Person[MAX];
int m,c,n,ans,rem;

int getNext(int index)
{
  while(Person[index].empty())index = (index+1)%n;
  return index;
}

void take(int index)
{
  bool ok = false;
  rep(i,m)
    {
      rep(j,desk[i].size())
	{
	  //cout << "desk[" << i << "][" << j << "] = " << desk[i][j].id << " : " << desk[i][j].ex << endl;
	  if(!desk[i][j].ex)continue;
	  if(desk[i][j].id == index)
	    {
	      desk[i][j].ex = false,ans += (i+1);
	      CNT[i]--;
	      ok = true;
	      //cout << "take from desk:" << i << " +" << (i+1) << endl;
	      return;
	    }
	}
      while(!desk[i].empty() && !desk[i].front().ex)desk[i].pop_front();
    }
  //cout << "take from shelf +" << m+1 << endl;
  ans += (m+1);
}

bool check(int index)
{
  //cout << "CNT[0]+1 = " << CNT[0]+1 << " <= " << c << endl;
  if(CNT[0]+1 <= c)
    {
      //cout << "book : " << index << " is able to put desk : " << 0 << endl;
      ans++;
      CNT[0]++;
      desk[0].push_back(P(index,true));
      return true;
    }
  return false;
}

void put(int index)
{

  if(check(index))return;
  
  //put 
  int pre=-inf;
  bool ok = false;
  rep(i,m)
    if(CNT[i]+1 <= c)
      {
	//cout << "一時的にdesk" << i << "におく　＆　そこから再度取り出す" << endl;
	CNT[i]++;
	pre = i;
	ans += (i+1)*2;
	ok = true;
	break;
      }
  if(!ok)ans += (m+1)*2;

  //take from desk 1
  ans++;
  while(!desk[0].empty() && !desk[0].front().ex)desk[0].pop_front();
  P p = desk[0].front(); desk[0].pop_front();
  CNT[0]--;
  assert(CNT[0] >= 0);
  //cout << "0番の本 " << p.id << " をとる" << endl;

  //put
  ok = false;
  REP(i,1,m)
    if(CNT[i]+1 <= c)
      {
	//cout <<"0番からの本 " << p.id << "を机" << i << "におく" << endl;  
	CNT[i]++;
	ans += (i+1);
	p.ex = true;
	desk[i].push_back(p);
	ok = true;
	break;
      }
  if(!ok)ans += (m+1);
  if(pre != -inf)CNT[pre]--;
  
  ans++;
  CNT[0]++;
  desk[0].push_back(P(index,true));
  
}

int main()
{

  while(cin >> m >> c >> n,m|n|c)
    {
      rem = n;
      ans = 0;
      rep(i,m+1)desk[i].clear(),CNT[i] = 0;
      rep(i,n)Person[i].clear();
      rep(i,n)
	{
	  int k,b;
	  cin >> k;
	  rep(j,k)
	    {
	      cin >> b;
	      Person[i].push_back(b);
	    }
	}

      int index = 0;
      while(rem)
	{
	  //cout << endl;
	  //rep(i,m)cout << "desk[" << i << "] = "<< CNT[i] << " ";
	  //cout << endl;

	  index = getNext(index);
	  //cout << "index = " << index << endl;
	  int target = Person[index].front(); Person[index].pop_front();
	  //cout << "target = " << target << endl; 
	  if(Person[index].empty())rem--;

	  take(target);
	  //cout << "after take, ans = " << ans << endl;
	  put(target);
	  //cout << "after put, ans = "<< ans << endl;
	  index = (index+1)%n;
	}
      cout << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1380
fn solve(graph:Vec<Vec<usize>>){
    let size = graph.len();
    let mut reached:Vec<_> = vec![false;size];
    let mut topological = vec![];
    for i in 0..size{
        if reached[i]{
            continue;
        }
        let mut stack = vec![];
        stack.push(i);
        'dfs: while !stack.is_empty(){
            let from = *stack.last().unwrap();
            if !reached[from]{
                reached[from] = true;
                // preorder
            }
            for &to in &graph[from]{
                if !reached[to]{
                    stack.push(to);
                    continue 'dfs;
                }
                // Other operation.
            }
            // Postorder
            let from = stack.pop().unwrap();
            topological.push(from);
        }
    }
    topological.reverse();
    for t in topological{
        println!("{}",t);
    }
}

use std::io::{BufRead, BufReader};
fn main() {
    let mut read = BufReader::new(std::io::stdin())
        .lines()
        .filter_map(|e| e.ok());
    let (v, e) = {
        let line = read.next().unwrap();
        let line: Vec<&str> = line.split(' ').collect();
        let v: usize = line[0].parse().unwrap();
        let e: usize = line[1].parse().unwrap();
        (v, e)
    };
    let graph = {
        let mut graph: Vec<Vec<_>> = vec![vec![]; v]; // Adj list
        for _ in 0..e {
            let edge = read.next().unwrap();
            let mut edge = edge.split(' ');
            let start: usize = edge.next().unwrap().parse().unwrap();
            let end: usize = edge.next().unwrap().parse().unwrap();
            graph[start].push(end);
        }
        graph
    };
    solve(graph);
}




Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

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

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

int main()
{
    int n;
    cin >> n;
    char s[n];
    rep(i, n){
        cin >> s;
        if (s[0] == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    string k;
    cin >> k;
    int n = k.size();
    int ans = 1000;
    for(int i = 0; i < 26; i++){
        string s = k;
        char c = 'a' + i;
        int cnt = 0;
        while(true){
            bool end = true;
            for(int j = 0; j < n-cnt; j++){
                if(s[j] != c) end = false;
            }
            if(end) break;
            for(int j = 1; j < n; j++){
                if(s[j] == c){
                    s[j-1] = c;
                }
                if(s[j+1] == '\0'){
                    s[j] = '\0'; 
                }
            }
            cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)

int main(){
    int A[10000], B[10000], count = 0;
    while(1){
        int H, W;
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        A[count] = H;
        B[count] = W;
        count++;
    }

    rep(i, 0, count){
        rep(y, 0, A[i]){
            rep(x, 0, B[i]){
                if(y & 1){
                    if(x & 1) printf("#");
                    else printf(".");
                }else{
                    if(~x & 1) printf("#");
                    else printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2036
#!/usr/bin python3
# -*- coding: utf-8 -*-

from math import gcd        #for python3.8

def lcm(a,b):
    G = gcd(a, b) #最大公約数
    L = (a//G)*b #最小公倍数
    return L

def main():
    X = int(input())
    print(lcm(X,360)//X)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
N = int(input())
p_list = list(map(int, input().split()))


i_list = [False] * N

min_tmp = p_list[0]

for i in range(N):
    if p_list[i] > min_tmp:
        i_list[i] = False

    else:
        min_tmp = p_list[i]
        i_list[i] = True


ans = i_list.count(True)
print(ans)



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

int main() {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll max=0;
	if(k<a)
	{
	    max=k;
	    k=0;
	}
	else
	{
	    max=a;
	    k=k-a;
	}
	if(k>0)
	{
    	if(k<b)
    	{
    	    k=0;
    	}
    	else
    	{
    	    k=k-b;
    	}
	}
	if(k>0)
	{
	    max=max-k;
	}
	
	cout<<max;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    ll a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;

    if(a<b){
        ll av=a+(t*v);
        ll bw=b+(t*w);
        if((a<b&&av>=bw)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        return 0;

    }else{
        ll av=a+(-1*t*v);
        ll bw=b+(-1*t*w);
        if((a>b&&av<=bw)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }

    }


return 0;
}


Measured memory_bytes: 3624