akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue> 
#include <cassert>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define INF 2000000000
#define MOD 998244353

using namespace std;

int h, w;
int n;
int arr[10000];
int ans[100][100];
int main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int index = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < arr[i]; j++) {
			int x = index / w;
			int y = index % w;
			if (x % 2 == 0)
				ans[x][y] = i + 1;
			else
				ans[x][w - 1 - y] = i + 1;
			index++;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)
			cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}	

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: int, A: "List[int]", B: "List[int]", C: "List[int]", Q: int, s: "List[int]", t: "List[int]"):
    import numpy as np    
    from scipy.sparse import coo_matrix    
    from scipy.sparse.csgraph import floyd_warshall
    mat = floyd_warshall(coo_matrix((C, (A, B)), shape=(N+1, N+1), dtype=np.int32).tocsr(), directed=False)
    mat = floyd_warshall(mat <= L, directed=False)
    for ss, tt in zip(s, t):
        yield -1 if np.isinf(mat[ss][tt]) else int(mat[ss][tt]) - 1


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    s = [int()] * (Q)  # type: "List[int]"
    t = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
    print(*solve(N, M, L, A, B, C, Q, s, t), sep="\n")

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 44744
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let _n: u64 = get_line().parse().unwrap();
    let s = get_line();
    let chrs: Vec<u32> = s.chars().map(|x| x.to_digit(10).unwrap()).collect();
    let mut answer = 0;

    for i in 0..1000 {
        let first = if i < 100 { 0 } else { i / 100 };
        let second = if i < 10 { 0 } else { i % 100 / 10 };
        let third = i % 10;

        let x = match chrs.iter().position(|&c| c == first) {
            Some(s) => s,
            None => continue
        };
        let y = match chrs[x + 1..].iter().position(|&c| c == second) {
            Some(s) => s,
            None => continue,
        };
        match chrs[x + 1..][y + 1..].iter().position(|&c| c == third) {
            Some(_s) => answer += 1,
            None => continue,
        }
    }

    println!("{}", answer);
}


Measured memory_bytes: 4476
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    string s;
    cin >> s;

    if (s == "SUN") {
        cout << 7 << endl;
    }
    else if (s == "MON") {
        cout << 6 << endl;
    }
    else if (s == "TUE") {
        cout << 5 << endl;
    }
    else if (s == "WED") {
        cout << 4 << endl;
    }
    else if (s == "THU") {
        cout << 3 << endl;
    }
    else if (s == "FRI") {
        cout << 2 << endl;
    }
    else if (s == "SAT") {
        cout << 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
lar, l = [], []
for i in range(n):
    a = int(input())
    if a == 0:
        lar.append(l)
        l = []
    else:
        l.append(a)
lar.append(l)
ans = 0
for l in lar:
    ans += sum(l) // 2
print(ans)

Measured memory_bytes: 82856
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
const int MAX = 1e7+10;
const int  MAX1 = 1e5+10;
const int INF = 1e9+10;
double eps = 1e-6;
int cnt[MAX];



int main(){
    IOS
    int n;
    cin >> n;
    for(int i = 1;i < 1e7+5;i++){
        for(int j = i;j < 1e7+5;j += i){
            ++cnt[j];
        }
    }
    ll sum = 0;
    for(int i = 1;i <= n;i++){
        sum += (ll) i*cnt[i];
    }
    cout << sum << endl;



}


/*


*/


Measured memory_bytes: 42688
n = int(input())
X = list(map(int,input().split()))


def get_score(i):
  res = 0
  for x in X:
    res += (x-i)**2
  return res
    
ans = float('inf')
for  i in range(1,101):
  ans = min(get_score(i),ans)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  long double W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << W / 2 * H;
  if (x * 2 == W && y * 2 == H) {
    cout << " 1" << endl;
  } else {
    cout << " 0" << endl;
  }
}

Measured memory_bytes: 256
function Main(input) {
	input = input.trim().split(" ");
  var list1 = input[0].slice(0,1);
  var list2 = input[1].slice(0,1);
  var list3 = input[2].slice(0,1);
  console.log((list1 + list2 + list3).toUpperCase());
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N = int(input())

# 素数^a, 素数^b, 素数^c
# print((a+1)*(b+1)*(c+1) = 約数の数)

# p = [2]
# for i in range(3, 101):
#     if any(i % p_i == 0 for p_i in p):
#         continue
#     p.append(i)
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
     43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
# print(p)

l = [0]*101
for i in range(2, N+1):
    for p_i in p:
        while i % p_i == 0:
            i //= p_i
            l[p_i] += 1
# print(l[:N+1])

# (3, 5, 5), (15, 5), (3, 25), (75)


def e(m):
    return sum(l_i >= m-1 for l_i in l)

# WHYYYYYYYYYYYY.
print(e(75) + e(25) * (e(3) - 1) + e(15) * (e(5) - 1) +
      e(5) * (e(5) - 1) * (e(3) - 2) // 2)


Measured memory_bytes: 3064
//
//

#include <iostream>
#include <fstream>

using namespace std;

int main() {
  fstream f;
  int input1, input2, input3;
  cin >> input1;
  cin >> input2;
  cin >> input3;
  int sum = input1 + input2 + input3;
  if(sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    while(~scanf("%d",&a))
    {
        getchar();
        char s[105];
        scanf("%s",s);
        int sum[105];
        for(int i=0; i<a; i++)
            sum[i]=0;
        for(int i=0; i<a; i++)
        {
            sort(s,s+i+1);
            for(int j=0; j<i+1; j++)
            {
                int f=0;
                for(int z=i+1; s[z]; z++)
                {
                    if(s[j]==s[z])
                    {
                        f=1;
                        break;
                    }
                }
                if(f==1)
                {
                    if(s[j]!=s[j-1]||j==0)
                        sum[i]++;
                }
            }
        }
        int max=0;
        for(int i=0; i<a; i++)
        {
            if(sum[i]>max)
                max=sum[i];
        }
        printf("%d\n",max);
    }
    return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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



class DXorSum4 {
public:
    int dy[4]={-1,1,0,0};
    int dx[4]={0,0,1,-1};

	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<ll> A(N);
	    vector<ll> digit_zero(60, 0);
	    vector<ll> digit_one(60, 0);
	    REP(i, N) {
	        in >> A[i];
	    }
	    REP(i,N) {
            REP(j, 60) {
                if (A[i] >> j & 1) {
                    digit_one[j]++;
                } else {
                    digit_zero[j]++;
                }
            }
	    }
	    ll ans = 0;
	    REP(i, N) {
	        REP(j,  60) {
                if (A[i] >> j & 1) {
                    ans += ((1L << j) % ll(1e9+7)) * digit_zero[j];
                    digit_one[j]--;
                    ans %= ll(1e9+7);
                } else {
                    ans +=  ((1L << j) % ll(1e9+7)) * digit_one[j];
                    digit_zero[j]--;
                    ans %= ll(1e9+7);
                }
	        }
	    }
	    out << ans << endl;
	}
};


int main() {
    ios::sync_with_stdio(false);
	DXorSum4 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2560
def ispalindrome(str): return 1 if str == str[::-1] else 0

S = input()
le = len(S)
one = ispalindrome(S)
two = ispalindrome(S[:(le-1)//2])
three = ispalindrome(S[(le+3)//2-1:])
if one and two and three:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
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[] a = new int[ N ];
    int[] b = new int[ N ];
    for(int i = 0 ; i < N ;i ++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }

    int[] c = new int[ M ];
    int[] d = new int[ M ];
    for( int i = 0 ;i < M ; i ++ ){
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();
    }

    int[] checkPointMin = new int[ N ] ;
    for(int i = 0 ;i  < N ; i ++){
      int distanceMin = 200000000;
      for(int j = 0 ; j < M ; j ++){
        int distance = Math.abs( a[i] - c[j] ) + Math.abs( b[i] - d[j] );
        if( distance < distanceMin ){
          distanceMin = distance;
          checkPointMin[i] = j;
        }
      }
    }
    for(int i = 0 ; i < N ; i ++){
      System.out.println( checkPointMin[i] + 1  );
    }
  }
}


Measured memory_bytes: 23252
import math
k = int(input())
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(nums[k - 1])

Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>
int main(void){
  int A,B,C,X,Y;
  scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
  int min = X,max = Y;
  int judge = 0;
  if(X > Y){
    max = X;
    min = Y;
    judge += 10;
  }
  int min_v = A,max_v = B;
  if(A > B){
    max_v = A;
    min_v = B;
    judge += 1;
  }

  if(A + B < 2 * C){
    printf("%d", A * X + B * Y);
  }else if(min_v >= 2 * C){
    printf("%d",C * max * 2);
  }else{
    int ans = 0;
    ans += C * 2 * min;
    switch(judge){
      case 00:  if(2 * C > B){
                  ans += (max - min) * B;
                }else{
                  ans += (max - min) * 2 * C;
                }
                break;
      case 10:  ans += (max - min) * A; break;
      case 01:  ans += (max - min) * B; break;
      case 11:  if(2 * C > A){
                  ans += (max - min) * A;
                }else{
                  ans += (max - min) * 2 * C;
                }
                break;
    }
    printf("%d",ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>M) {
		VI A(M);
		REP(i, M) cin>>A[i];
		ll a=N-accumulate(ALL(A),0LL);
		ll ans=a<0?-1:max(0LL,a);
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3272
import math
a, b, x = map(int, input().split())
if (a ** 2 * b - x) > 0:
    t = (a ** 3) / (2 * (a ** 2 * b - x))
    if t >= (a / b):
        print(90 - (math.atan(t) / (math.pi)) * 180)
    else:
        print((math.atan(a * b * b / (2 * x)) / math.pi) * 180)
else:
    print(0)

Measured memory_bytes: 3060
c=[list(map(int,input().split())) for _ in range(3)]
yoko=[c[0][1]-c[0][0],c[0][2]-c[0][1]]
tate=[c[1][0]-c[0][0],c[2][0]-c[1][0]]
flag=1
for i in range(1,3):
 if not((c[i][1]-c[i][0]==yoko[0])and(c[i][2]-c[i][1]==yoko[1])):
  flag=0
 if not((c[1][i]-c[0][i]==tate[0])and(c[2][i]-c[1][i]==tate[1])):
  flag=0

if flag==1:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

template<typename T> class segtree {
private:
    int n,sz;
    vector<T> node;
public:
    segtree(int sz_) : sz(sz_){
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.assign(2*n,numeric_limits<T>::max());
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i],node[2*i+1]);
        }
    }
    void update(int k,T a)
    {
    	node[k+=n] = a;
    	while(k>>=1){
    		node[k] = min(node[2*k],node[2*k+1]);
    	}
    }
    T query(int a,int b)
    {
        T res1 = numeric_limits<T>::max();
        T res2 = numeric_limits<T>::max();
        a += n, b += n;
        while(a != b){
            if(a % 2) res1 = min(res1, node[a++]);
            if(b % 2) res2 = min(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print(){
        for(int i = 0; i < sz; i++){
            cout << query(i,i+1) << " ";
        }
        cout << endl;
    }
};

int main()
{
    int n, q;
    scanf("%d%d",&n,&q);
    segtree<int> sg(n);
    rep(i,q){
        int k,x,y;
        scanf("%d%d%d",&k,&x,&y);
        if(k){
            printf("%d\n",sg.query(x,y+1));
        }else{
            sg.update(x,y);
        }
    }
    return 0;
}



Measured memory_bytes: 3892
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N = intinput()

    # 出力
    print(2*N*pi)



Measured memory_bytes: 10728
#include <stdio.h>

int main(void)
{
	int a,b,c,n,x;
	n=0;
	scanf("%d %d %d",&a,&b,&c);
	for(x=a;x<=b;x+=1){
		if(c%x==0){
			n+=1;
		}}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 596
A, B, C, K = map(int, input().split())

ans = 0

if A >= K:
  ans = K
else:
  if A + B >= K:
    ans = A
  else:
    if A + B + C >= K:
      ans = A - (K - A - B)
    else:
      ans = A - C
      
print(ans)

Measured memory_bytes: 9180
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int d, n;
  	cin >> d >> n;
  	int e = pow(100,d); 
  	if(n==100) cout << e*(n+1) << endl;
  	else cout << e*n << endl;
    return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<list>
using namespace std;

vector<int> v(2000);
int n;
void solve(int m) {
	vector<int> dp(2010, 0);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 2000; j >= 0; j--) {
			if (dp[j] >= 1 && j + v[i] <= 2000) {
				dp[j + v[i]] = 1;
			}
		}
	}
	cout << (dp[m] ? "yes" : "no") << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	for (int i = 0; i < n; i++)cin >> v[i];

	int q;
	cin >> q;
	int m;
	for (int i = 0; i < q; i++) {
		cin >> m;
		solve(m);
	}

	return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,mod=1e9+7;
int n,ans,f[N][2];
char s[N];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    f[0][1]=1;
    for(int i=1;i<=n;i++)
    if(s[i]=='1')f[i][0]=(3ll*f[i-1][0]+f[i-1][1])%mod,f[i][1]=2ll*f[i-1][1]%mod;
    else f[i][0]=3ll*f[i-1][0]%mod,f[i][1]=f[i-1][1];
    ans=(f[n][0]+f[n][1])%mod;
    printf("%d",ans);
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}



signed main(){
  int n; cin>>n;
  VI p(n); rep(i,n) cin>>p[i];
  int ans = 1; int m = p[0];
  reps(i,n-1){
    if(p[i]<m){
      ans++; m=p[i];
    }
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
class SimpleEditor{
public:
  int cur;
  string s;
  SimpleEditor(string s):s(s),cur(0){}
  int RightWord(){
    int i=cur;
    while(s[i]==' '&&s[i]!='#')++i;
    if(s[i]=='#')return -1;
    for(i;i<s.length();++i){
      if(s[i]==' ')return i;
    }
    return s.length()-1;
  }
  int LeftWord(){
    int i=cur-1;
    while(s[i]==' '&&i>=0)--i;
    if(i==0)return -1;
    for(i;i>=0;--i){
      if(s[i]==' ')return i+1;
    }
    return 0;
  }
  void ForwardChar(){
    ++cur;
    if(cur>=s.length())cur=s.length()-1;
  }
  void BackwardChar(){
    --cur;
    if(cur<0)cur=0;
  }
  void ForwardWord(){
    cur = RightWord();
    if(cur==-1)cur=s.length()-1;
  }
  void BackwardWord(){
    cur = LeftWord();
    if(cur==-1)cur=0;
  }
  void Insert(string text){
    s.insert(s.begin()+cur,text.begin()+8,text.end()-1);
    cur += text.length()-9;
  }
  void DeleteChar(){
    if(*(s.begin()+cur)!='#'){
      s.erase(s.begin()+cur);
    }
  }
  void DeleteWord(){
    int i=RightWord();
    if(i>=0){
      //cout << " RIGHT : " << i << endl;
      for(int j=cur;j<i;++j)DeleteChar();
    }
  }
  string ToString()const{
    string ret;
    for(int i=0;i<s.length();++i){
      //if(i==cur)ret+='[';
      if(i==cur)ret+='^';
      ret+=s[i];
      //if(i==cur)ret+=']';
    }
    ret.erase(ret.end()-1);
    return ret;
  }
};
void GetLine(string &s){
  getline(cin,s);
  for(int i =0;i<s.length();++i){
    if(iscntrl(s[i])){s.erase(s.begin()+i);--i;}
  }
}
int main(){
  string dam;
  int T;
  cin >> T;
  GetLine(dam);
  for(int tc=1;tc<=T;++tc){
    string s;
    GetLine(s);
    s+='#';
    SimpleEditor se(s);
    //cout << "NUMBER OF TEST CASE : " << T << " INITIAL STRING : " << s << endl;
    int t;
    cin >> t;
    GetLine(dam);
    for(int i = 0; i < t; ++i){
      string inst;
      GetLine(inst);
      if(inst=="forward char")se.ForwardChar();
      if(inst=="forward word")se.ForwardWord();
      if(inst=="backward char")se.BackwardChar();
      if(inst=="backward word")se.BackwardWord();
      if(inst.find("insert")!=string::npos)se.Insert(inst);
      if(inst=="delete char")se.DeleteChar();
      if(inst=="delete word")se.DeleteWord();
      //cout<<i<<"/" <<t<<":"<<" INST:" <<inst<<" ED:"<<se.ToString() << endl;
    }
    cout << se.ToString() << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const long long int M=1e9+7;

int solve(vector<vector<char> >& grid,int h,int w) {

    vector<vector<int> > dp(h, vector<int> (w,0));

    dp[0][0] = 0;
    for(int i=1; i<w; i++) {
        if(grid[0][i] == '.')
            dp[0][i] = 1;
        else
            break;

    }

    for(int i=1; i<h; i++) {
        if(grid[i][0] == '.')
            dp[i][0] = 1;
        else
            break;

    }

    for(int i=1; i<h; i++) {
        for(int j=1; j<w; j++) {
            if(grid[i][j]=='#')
                dp[i][j]=0;
            else
                dp[i][j]=(dp[i][j-1]%M+dp[i-1][j]%M)%M;
        }
    }

    return dp[h-1][w-1];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
    }
    int h,w;
    cin>>h>>w;
    vector<vector<char> >grid(h,vector<char>(w,0));

    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            char c;
            cin>>c;
            grid[i][j]=c;
        }

    }

    cout<<solve(grid,h,w)<<endl;
    return 0;

}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define N 200005
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
using namespace std;





void solve()
{
	int n;
	cin>>n;
	
	string ans="";
	
	for(;n>0;n/=26)
	{
		n--;
		ans+=(char)('a'+n%26);
	}
	
	reverse(ans.begin(),ans.end());
	
	cout<<ans<<endl;
}
signed main()
{
    
	nuenxfiu
	//TT
	solve();
     return 0;
}

Measured memory_bytes: 3608
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        親が同じか判別する
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        yをxの根に繋ぐ
        """
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """
        xとyが同じ連結成分か判別する
        """
        return self.find(x) == self.find(y)

    def size(self, x):
        """
        xの連結成分の大きさを返す
        """
        return -self.parents[self.find(x)]

    def kruskal(self, edge):
        """
        :param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
        :return: 最小全域木のコストの和
        """
        edge.sort()
        cost_sum = 0
        for cost, node1, node2 in edge:
            if not self.same(node1, node2):
                cost_sum += cost
                self.union(node1, node2)
        return cost_sum


def resolve():
    n, q = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(q):
        t, u, v = map(int, input().split())
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.same(u, v)))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 11940
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)

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

	const int mod = 256;

	for(int n; cin >> n, n;) {
		vector<int> l(n);
		for(int i = 0; i < n; ++i)
			cin >> l[i];

		int as, aa, ac;
		double mn = INT_MAX;
		for(int s = 0; s <= 15; ++s) {
			for(int a = 0; a <= 15; ++a) {
				for(int c = 0; c <= 15; ++c) {
					int r = s;
					map<int, int> cnt;

					for(int i = 0; i < n; ++i) {
						r = (a * r + c) % mod;
						++cnt[(l[i] + r) % mod];
					}

					double h = 0.0;
					FOR(it, cnt) {
						const double tmp = (double)it->second / n;
						h -= tmp * log2(tmp);
					}

					if(mn > h) {
						as = s;
						aa = a;
						ac = c;
						mn = h;
					}
				}
			}
		}

		cout << as << " " << aa << " " << ac << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1244
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] list = sc.nextLine().split(" ",0);
		int A = Integer.parseInt(list[0]);
		int B = Integer.parseInt(list[1]);
		int T = Integer.parseInt(list[2]);

		System.out.println(B*(T/A));
		sc.close();
	}

}

Measured memory_bytes: 25044
a,b = map(int,input().split())
if a == 1 and b == 1:
  a = 14
  b = 14
elif b == 1:
  b = 14
elif a == 1:
  a = 14
  
if a>b:
  print("Alice")
elif b>a:
  print("Bob")
else:
  print("Draw")

Measured memory_bytes: 9016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	string s;
	cin>>s;
	string ans="";
	for (int i = 0; i < s.length(); ++i)
	{
		ans+='x';
	}
	cout<<ans;

	return 0;
}

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

// opeの単位元
int gen(char ope) {
    if (ope == '+') return 0;
    else return 1; // '*'
}

int operate(char ope, int x, int y) {
    if (ope == '+') return x + y;
    else return x * y;
}

// topの演算子を消す
void ope_sub(stack<char> &ope_sta, stack<int> &num_sta) {
    ope_sta.pop();
    if (ope_sta.empty()) return;
    int x = num_sta.top(); num_sta.pop();
    int y = num_sta.top(); num_sta.pop();
    num_sta.push(operate(ope_sta.top(), x, y));
}

// topに演算子を追加
void ope_add(char ope, stack<char> &ope_sta, stack<int> &num_sta) {
    ope_sta.push(ope);
    num_sta.push(gen(ope));
}


void operate(int x, stack<char> &ope_sta, stack<int> &num_sta) {
    char ope = ope_sta.top();
    int y = num_sta.top(); num_sta.pop();
    num_sta.push(operate(ope, y, x));
}

int main() {
    while (true) {
        int n; cin >> n;
        if (n == 0) break;
        if (n == 1) {
            int x; cin >> x;
            cout << x << endl;
            continue;
        }
        stack<char> ope_sta;
        stack<int> num_sta;
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            while (ope_sta.size() > s.size() - 1) {
                ope_sub(ope_sta, num_sta);
            }
            if (s[s.size() - 1] == '+' || s[s.size() - 1] == '*') {
                ope_add(s[s.size() - 1], ope_sta, num_sta);
            }
            else {
                int x = s[s.size() - 1] - '0';
                operate(x, ope_sta, num_sta);
            }
        }
        while (ope_sta.size()) {
            ope_sub(ope_sta, num_sta);
        }
        cout << num_sta.top() << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[n + 1];
		dp[0] = 1;
		HashMap<Integer, TreeSet<Integer>> map = new HashMap<>();
		for (int i = 1; i <= n; i++) {
		    int x = sc.nextInt();
		    int add = 0;
		    if (map.containsKey(x)) {
		        TreeSet<Integer> set = map.get(x);
		        int y = set.last();
		        if (i - y > 1) {
		            add = dp[y];
		        }
		        set.add(i);
		        map.put(x, set);
		    } else {
		        TreeSet<Integer> set = new TreeSet<>();
		        set.add(i);
		        map.put(x, set);
		    }
		    
		    dp[i] = (dp[i - 1] + add) % MOD;
		}
		System.out.println(dp[n]);
	}
}


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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = input_int()
    a_list = input_to_int_tuple()

    sorted_list = sorted(a_list, reverse=True)
    temp_cnt = n - 2
    ans = sorted_list[0]

    plus = False
    if temp_cnt % 2 == 0:
        temp_cnt //= 2
    else:
        temp_cnt //= 2
        plus = True

    if temp_cnt >= 1:
        ans += sum(sorted_list[1:temp_cnt + 1]) * 2

    if plus:
        ans += sorted_list[temp_cnt + 1]

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 31100
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string S,T,SS;
    cin >> S >> T;
    SS = S + S;
    if(SS.find(T) != string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define mp make_pair
#define fi first
#define se second
const int N = 1e3 + 5;
const int INF = INT_MAX;

int n, m, x, y, z, ans;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int val[N][N];
char cell[N][N];
iii a;
queue<iii> q;

bool inside(int i) {
    return (x + dx[i] >= 1 && x + dx[i] <= n &&
            y + dy[i] >= 1 && y + dy[i] <= m);
}

void BFS() {
    while(!q.empty()) {
        a = q.front();
        x = a.fi.fi, y = a.fi.se, z = a.se;
        q.pop();
        if(val[x][y] > -1) continue;
        val[x][y] = z;
        for(int i = 0; i < 4; i++) {
            if(!inside(i)) continue;
            q.push(mp(mp(x + dx[i], y + dy[i]), z + 1));
        }
    }
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> cell[i][j];
            if(cell[i][j] == '#') q.push(mp(mp(i, j), 0));
        }
    }
    BFS();
    ans = -INF;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            ans = max(ans, val[i][j]);
        }
    }
    cout << ans << "\n";
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    memset(val, -1, sizeof(val));
    solve();

}

Measured memory_bytes: 56416
N,M = map(int, input().split())
an_li = list(map(int, input().split()))
an_li.remove(an_li[0])
for i in range(N-1):
    flag = False
    r = []
    li = list(map(int, input().split()))
    li.remove(li[0])
    for t in an_li:
        if t in li:
            a = 1
        else:
            r.append(t)
            flag = True
    if flag:
        for w in r:
            an_li.remove(w)
print(len(an_li))

Measured memory_bytes: 9200
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#include <deque>
#include <ctime>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cassert>
#include <cstring>
#include <queue>
#include <random>

#define fi first
#define se second
#define ll long long
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define mp(x, y) make_pair((x), (y))

using namespace std;

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

    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        int c;
        cin >> c;
        vec[c - 1] = i;
    }
    for (auto e : vec) {
        cout << e + 1 << ' ';
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1280
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
dist=1000000
for i in range(110):
    i-=2
    if i in p:
        continue
    if abs(i-x) < dist:
        dist = abs(i-x)
        ans = i

print(ans)

Measured memory_bytes: 9172
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	int s[16] = {};
	vector<vector<pair<int, int>>> f(20);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < a; j++) {
			int q, w;
			cin >> q >> w;
			f[i].push_back(make_pair(q, w));
		}
	}
	int ans = 0;
	for (int i = 0; i < 33000;i++) {
		for (int j = 0; j < n; j++) {
			if (s[j] == 2) {
				s[j + 1] = s[j + 1] + 1;
				s[j] = 0;
			}
		}
		int k = 0;
		for (int j = 0; j < n; j++) {
			if (s[j] == 1) {
				k++;
			}
		}
		int c = 0;
		for (int j = 0; j < n; j++) {
			if (s[j] == 1) {
				for (auto y : f[j]) {
					int n, m;
					n = y.first-1;
					m = y.second;
					if (s[n] != m) {
						c = 1;
					}
				}
			}
			if (c == 1) {
				break;
			}
		}
		if (c == 0) {
			ans = max(ans, k);
		}
		if (k == n) {
			cout << ans;
			return 0;
		}
		s[0] = s[0] + 1;
	}
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    que = queue.Queue()
    process_end = []

    for n in range(N):
        name, time = sl()
        que.put([name, int(time)])

    end_time = 0
    while not que.empty():
        name, time = que.get()
        if time > Q:
            end_time += Q
            que.put([name, time - Q])
        else:
            end_time += time
            process_end.append([name, end_time])

    for p in process_end:
        print(*p)


if __name__ == '__main__':
    main()



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

using namespace std;

const int maxn = 55;

int T, n;
int E1[maxn][maxn], E2[maxn][maxn], E[maxn][maxn], deg[maxn];
int tag[maxn], _deg[maxn], _E1[maxn][maxn], _E2[maxn][maxn];

void dfs_tag(int u, int f) {
	tag[u] = 1;
	for (int v = 1; v <= n; v++) {
		if (E1[u][v] && E2[u][v] && v != f) {
			dfs_tag(v, u);
		}
	}
}

void dfs1(int u, int f) {
	for (int v = 1; v <= n; v++) {
		if (E1[u][v] && v != f) {
			if (!tag[u]) {
				++ E[u][v];
				++ deg[v];
			}
			dfs1(v, u);
		}
	}
}

void dfs2(int u, int f) {
	for (int v = 1; v <= n; v++) {
		if (E2[u][v] && v != f) {
			if (!tag[u]) {
				++ E[v][u];
				++ deg[u];
			}
			dfs2(v, u);
		}
	}
}

int main() {
	scanf("%d", &T);
	while (T --) {
		int ans = 0x3f3f3f3f;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				_E1[i][j] = _E2[i][j] = 0;
			}
			_deg[i] = 0;
		}
		for (int i = 1; i < n; i++) {
			int u, v; scanf("%d%d", &u, &v);
			_E1[u][v] = _E1[v][u] = 1;
			++ _deg[u], ++ _deg[v];
		}
		for (int i = 1; i < n; i++) {
			int u, v; scanf("%d%d", &u, &v);
			_E2[u][v] = _E2[v][u] = 1;
		}
		int dif = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (_E1[i][j] != _E2[i][j]) {
					dif = 1;
				}
			}
		}
		if (!dif) {
			puts("0");
			continue;
		}
		for (int s = 1; s <= n; s++) {
			if (_deg[s] != 1) continue;
			int f = 0;
			for (int i = 1; i <= n; i++) if (_E1[s][i]) f = i;
			for (int t = 1; t <= n; t++) {
				if (t == s) continue;
				for (int i = 1; i <= n; i++) {
					for (int j = 1; j <= n; j++) {
						E[i][j] = 0;
						E1[i][j] = _E1[i][j];
						E2[i][j] = _E2[i][j]; 
					}
					deg[i] = 0;
				}
				E1[s][f] = E1[f][s] = 0, E1[s][t] = E1[t][s] = 1;
				int cnt = 0;
				for (int i = 1; i <= n; i++) tag[i] = 0;
				dfs_tag(s, 0);
				for (int i = 1; i <= n; i++) if (tag[i]) ++ cnt;
				dfs1(s, 0), dfs2(s, 0);
				queue<int> Q;
				for (int i = 1; i <= n; i++) {
					if (!tag[i] && !deg[i]) Q.push(i);
				}
				while (!Q.empty()) {
					int u = Q.front(); Q.pop();
					for (int v = 1; v <= n; v++) {
						if (E[u][v]) {
							deg[v] -= E[u][v];
							if (!deg[v]) Q.push(v);
						}
					}
				}
				int ok = 1;
				for (int i = 1; i <= n; i++) if (!tag[i] && deg[i]) ok = 0;
				if (ok) ans = min(ans, n - cnt);
			}
		}
		if (ans < 0x3f3f3f3f) printf("%d\n", ans + 1);
		else puts("-1");
	}
	return 0;
}

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

int h, w;
char grid[200][200];

int main(){
  cin >> h >> w;
  rep(i, h){
    rep(j, w){ 
      cin >> grid[i][j];
    }
  }
  rep(i, h){
    bool flag = true;
    rep(j, w){
      if(grid[i][j] == '#'){
        flag = false;
        break;
      }
    }
    if(flag){
      for(int k = i; k < h; k++){
        rep(l, w){
          grid[k][l] = grid[k + 1][l];
          cerr << k <<" "<< l;
        }
      }
      i--; h--;
    }
  }
  rep(i, w){
    bool flag = true;
    rep(j, h){
      if(grid[j][i] == '#'){
        flag = false;
        break;
      }
    }
    if(flag){
      for(int k = i; k < w; k++){
        rep(l, h){
          grid[l][k] = grid[l][k + 1];
        }
      }
      i--; w--;
    }
  }
  rep(i, h){
    rep(j, w){
      cout << grid[i][j];
    }
    cout << 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 k=sc.nextInt();
    int min=1;
    for(int i=0;i<n;i++){
      min=Math.min(min*2,min+k);
    }

    System.out.println(min);

  }
}


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

int main()
{
    int n,l,r,ans = 0;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256