akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0, z=0, n=0;
      int sum = 0;
      int nokori;
      int r, g, b;
      int i,j,k;
      int count=0;
      int tempj, tempk;
      try {
         Scanner scanner = new Scanner(System.in);
         x = scanner.nextInt();
         y = scanner.nextInt();
         z = scanner.nextInt();
         n = scanner.nextInt();
         scanner.close();
      } catch (InputMismatchException e) {
         System.out.println("error");
      }
      if (y < z) {
         int temp = y;
         y = z;
         z = temp;
      }
      if (x<y) {
         int temp = x;
         x = y;
         y = temp;
      }
      r = n/x;
      g = n/y;
      b = n/z;
      for (i=0; i<r+1; i++) {
         sum = x*i;
         //nokori = n-sum;
         if (sum == n) {
            count++;
            continue;
         }
         tempj = sum;
         for (j=0; j<g+1; j++) {
            sum = sum + j*y;
            if (sum == n) {
               count++;
               break;
            }
            if (sum>n) {
               sum = tempj;
               continue;
            }
            nokori = n-sum;
            if (nokori%z == 0) {
               count++;
            }
            sum = tempj;
         }
         sum = 0;
      }
      System.out.println(count);
   }
}


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

using ll=int64_t;
//#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	#ifdef int
	scanf("%" SCNd64,&i);
	#else
	scanf("%d",&i);
	#endif
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	#ifdef int
	printf("%" PRId64,x);
	#else
	printf("%d",x);
	#endif
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

//const int inf=LLONG_MAX/3;
const int inf=114514;

const int Smax=45;
int sum[Smax][Smax];
int Get(int i1,int i2,int j1,int j2){
	i1--,i2--,j1--,j2--;
	int res=sum[i2][j2];
	if(i1>=0)res-=sum[i1][j2];
	if(j1>=0)res-=sum[i2][j1];
	if(i1>=0&&j1>=0)res+=sum[i1][j1];
	return res;
}
int dp[Smax][Smax][Smax][Smax];

signed main(){
	int h=read(),w=read();
	vector<string> ss;
	REP(i,h)
		ss.PB(readString());
	
	REP(i,h)REP(j,w){
		sum[i][j]=ss[i][j]=='#';
		if(i-1>=0)sum[i][j]+=sum[i-1][j];
		if(j-1>=0)sum[i][j]+=sum[i][j-1];
		if(i-1>=0&&j-1>=0)sum[i][j]-=sum[i-1][j-1];
	}
	
	int gi,gj;
	REP(i,h)REP(j,w)if(ss[i][j]=='P')
		gi=i,gj=j;
	
	for(int t=gi;t>=0;t--)FOR(b,gi+1,h+1)
	for(int l=gj;l>=0;l--)FOR(r,gj+1,w+1){
		dp[t][b][l][r]=inf;
		chmin(dp[t][b][l][r],Get(t,gi+1,l,gj+1));
		chmin(dp[t][b][l][r],Get(gi,b,l,gj+1));
		chmin(dp[t][b][l][r],Get(t,gi+1,gj,r));
		chmin(dp[t][b][l][r],Get(gi,b,gj,r));
		
		FOR(i,t+1,gi+1)FOR(j,l+1,gj+1)
			chmin(dp[t][b][l][r],dp[i][b][j][r]+Get(t,i,j,r)+Get(i,b,l,j));
		FOR(i,gi+1,b)FOR(j,gj+1,r)
			chmin(dp[t][b][l][r],dp[t][i][l][j]+Get(t,i,j,r)+Get(i,b,l,j));
		FOR(i,t+1,gi+1)FOR(j,gj+1,r)
			chmin(dp[t][b][l][r],dp[i][b][l][j]+Get(t,i,l,j)+Get(i,b,j,r));
		FOR(i,gi+1,b)FOR(j,l+1,gj+1)
			chmin(dp[t][b][l][r],dp[t][i][j][r]+Get(t,i,l,j)+Get(i,b,j,r));
	}
	
	cout<<dp[0][h][0][w]<<endl;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    while (getline(cin,s)) {
        if (s==".") {
            break;
        } else {
            int flag=0;
            std::deque<char> deq;
            for (int i=0;i<s.size();i++) {
                if (s.at(i)=='('||s.at(i)=='[') {
                    deq.emplace_back(s.at(i));
                } else if (s.at(i)==')') {
                    if (deq.empty()==true||deq.back()!='(') {
                        flag=1;
                        cout<<"no"<<endl;
                        break;
                    } else {
                        deq.pop_back();
                    }
                } else if (s.at(i)==']') {
                    if (deq.empty()==true||deq.back()!='[') {
                        flag=1;
                        cout<<"no"<<endl;
                        break;
                    } else {
                        deq.pop_back();
                    }
                }
            }
            if (flag==0&&deq.empty()==true) {
                cout<<"yes"<<endl;
            } else if (flag==0&&deq.empty()!=true) {
                cout<<"no"<<endl;
            }
        }
    }
}


Measured memory_bytes: 3172
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  int a, b, c;
  cin >> a >> b >> c;
  int sum = a + b + c;
  if (sum >= 22) {
    cout << "bust\n";
  } else {
    cout << "win\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
def C3():
    N = int(input())
    def make_list(s):
        S = [s]
        if int(s) <= N:
            S.extend(make_list(s + "3"))
            S.extend(make_list(s + "5"))
            S.extend(make_list(s + "7"))
        return S

    datalist = make_list("0")

    ans = 0
    for i in datalist:
        s = 0
        f = 0
        t = 0
        for j in list(i):
            if j == "7":
                s = 1
            if j == "5":
                f = 1
            if j == "3":
                t = 1
        if s + f + t == 3 and int(i) <= N:
            ans += 1
    print(ans)
C3()


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

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    const long long mod = 1e9 + 7;
    int n; cin >> n;
    vector<vector<int>> bitCnt(2, vector<int> (60, 0));
    vector<long long> data(n);
    for(int i = 0; i < n; i++) cin >> data[i];

    long long ans = 0;
    for(auto num : data) {
        for(int i = 0; i < 60; i++) {
            ans += (bitCnt[!(num & (1LL << i))][i] * ((1LL << i) % mod)) % mod;
            ans %= mod;
            bitCnt[(bool)(num & 1LL << i)][i]++;
        }
    }

    cout << ans;
}

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

int main(int argc, char* argv[]){
        char tmp[1024+1]={0};
        char *buf=NULL;
        char* p=NULL;
        int N=0;
        int *A=NULL;
        int *C=NULL;

        buf = (char*)calloc(200000+1, 7);
        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }
        N = atoi(buf);

        A = (int*)calloc(N+1, sizeof(int));
        C = (int*)calloc(N+2, sizeof(int));
        for(int i=0; i<N+1; i++){ C[i]=0; }

        memset(buf, 0, N*7+1);
        while(fgets(tmp, sizeof(tmp)-1, stdin)!=NULL){
                strcat(buf, tmp);
                memset(tmp, 0 , sizeof(tmp));
        }

        p = strtok(buf, " ");
        A[0] = atoi(p);
        C[A[0]]++;
        for(int i=1; i<N; i++){
                p = strtok(NULL, " ");
                A[i] = atoi(p);
                C[A[i]]++;
        }
        long long total=0;
        for(int i=1; i<N+1; i++){
                long long a = (long long)C[i];
                total += a*(a-1)/2;
        }
        for(int i=0; i<N; i++){
                long long v = (long long)C[A[i]];
                long long d = 0;
                if(v>1) {
                        d = v*(v-1)/2 - (v-1)*(v-2)/2;
                }
                long long ans = total - d;
                printf("%lld\n", ans);
        }
        return 0;
}

Measured memory_bytes: 5376
#include <iostream>
using namespace std;
#define brk system("pause");

const int N = 1e5 + 1;
int dp[N], h[N];
main()
{
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> h[i];
	
	dp[2] = abs(h[2] - h[1]);
	for(int i = 3; i <= n; i++)
		dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	
	cout << dp[n] << endl;
}


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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

list_n = prime_factorize(n)
dic = {}
for i in list_n:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans = 0
for i in dic.values():
    count=0
    while True:
        count+=1
        if i>=count:
            i-=count
        else:
            ans+=count-1
            break
print(ans)


Measured memory_bytes: 62912
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(M):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0

while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')

Measured memory_bytes: 60228
import sys
from itertools import combinations
def input(): return sys.stdin.readline().strip()
carry = False

def f(n):
    """
    順番に貪欲するのではなく、「ある数 n 以上で n/S(n) を最小にする数 f(n) を求める」と言い換えれば
    このクエリを K 回繰り返せばよい。

    例えば n = 314159265 の場合に考えてみる。仮にf(n) = 314234567だったとしてこれが間違いであることを示しつつ
    最善手を模索してみる。
    実際これよりも小さい数で n/S(n) が小さいものが存在して、例えば 314199999である。なぜなら
    まず明らかにこれは 314234567より小さく、さらに各桁の和も後半がすべて9であることから S(n) は増加しているので
    n/S(n) は小さくなっている。

    これより、n が与えられたら f(n) は n の下の桁からどこかまで順に...999と埋めたものになる。
    """
    c = str(n)
    L = len(c)
    digit_sum = [0] * (L + 1)
    for i in range(1, L + 1): digit_sum[i] = digit_sum[i - 1] + int(c[i - 1])

    ret = n
    val = n / digit_sum[-1]
    for d in range(L - 1, -1, -1):
        N = int(c[:d] + '9' * (L - d))
        valN = N / (digit_sum[d] + 9 * (L - d))
        if val > valN:
            ret = N
            val = valN
    # 多分nの桁数を超えたところに最小値はない気がする
    return ret



def main():
    K = int(input())
    print(1)
    n = 1
    for _ in range(1, K):
        n = f(n + 1)
        print(n)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73840
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

import jdk.nashorn.internal.codegen.types.BitwiseType;

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

    BigInteger s = a.compareTo(b) < 0 ? a : b;
    BigInteger l = a.compareTo(b) < 0 ? b : a;

    List<BigInteger[]> yakusuList = new ArrayList<>();
    for (BigInteger i = new BigInteger("2"), len = IntUtil.sqrtFloor(s); i.compareTo(len) <= 0; i = i.add(BigInteger.ONE)) {
      if (s.remainder(i).compareTo(BigInteger.ZERO) == 0) {
        int count = 0;
        while(s.remainder(i).compareTo(BigInteger.ZERO) == 0) {
          s = s.divide(i);
          if (l.remainder(i).compareTo(BigInteger.ZERO) == 0) {
            l = l.divide(i);
            count++;
          }
        }
        if (count > 0) {
          yakusuList.add(new BigInteger[]{ i, IntUtil.toBig(count) });
        }
      }
    }
    if (s.compareTo(BigInteger.ONE) > 0) {
      if (l.remainder(s).compareTo(BigInteger.ZERO) == 0) {
        yakusuList.add(new BigInteger[]{ s, BigInteger.ONE });
      }
    }
    
    System.out.println(yakusuList.size() + 1);
  }
}

/**
 * 整数ユーティリティー
 */
class IntUtil {
  public static BigInteger toBig(long i) {
    return new BigInteger(Long.toString(i));
  }

  /**
   * 拡張ユークリッドの互除法
   * @param x 数値1
   * @param y 数値2
   * @return [xとyの最大公約数r, a, b] (ただしa, bは ax + by = r となる整数)
   */
  static BigInteger[] gcd(BigInteger x, BigInteger y) {
    BigInteger r0 = x;
    BigInteger r1 = y;
    BigInteger a0 = BigInteger.ONE;
    BigInteger a1 = BigInteger.ZERO;
    BigInteger b0 = BigInteger.ZERO;
    BigInteger b1 = BigInteger.ONE;
    while(r1.compareTo(BigInteger.ZERO) > 0) {
      BigInteger[] tmp = r0.divideAndRemainder(r1);
      BigInteger q = tmp[0];
      BigInteger r = tmp[1];
      BigInteger a = a0.subtract(q.multiply(a1));
      BigInteger b = b0.subtract(q.multiply(b1));
      r0 = r1;
      r1 = r;
      a0 = a1;
      a1 = a;
      b0 = b1;
      b1 = b;
    }
    return new BigInteger[]{r0, a0, b0};
  }

  /**
   * 最小公倍数を求める。
   * @param x 数値1
   * @param y 数値2
   * @return 最小公倍数
   */
  public static BigInteger lcm(BigInteger x, BigInteger y) {
    BigInteger gcd = x.gcd(y);
    return x.multiply(y).subtract(gcd);
  }

  public static BigInteger sqrtFloor(BigInteger n) {
    try {
      return new BigDecimal(Math.sqrt(n.longValueExact())).toBigInteger();
    } catch (ArithmeticException e) {
      BigDecimal nq = new BigDecimal(n);
      BigDecimal x = BigDecimal.ONE;
      BigDecimal d2 = BigDecimal.ONE.add(BigDecimal.ONE);
      BigInteger r = new BigInteger("1000000000");
      BigInteger r1 = r.add(BigInteger.ONE);
      while (!(r.multiply(r).compareTo(n) <= 0 && r1.multiply(r1).compareTo(n) > 0)) {
        for (int i = 0; i < 10; i++) {
          x = x.add(nq.divide(x, BigDecimal.ROUND_HALF_DOWN)).divide(d2);
        }
        r = x.toBigInteger();
        r1 = r.add(BigInteger.ONE);
      }
      return r;
    }
  }
}


Measured memory_bytes: 87064
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  for(ll i=0;i<N-2;i++) {
if(S[i]=='A') {
if(S[i+1]=='B'&&S[i+2]=='C') {
ans++;
}
}
  }
  
  
  cout<<ans<<endl;
}
  

Measured memory_bytes: 3628
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    okane = 1000

    for a, b in zip(A, A[1:]):
        if a <= b:
            q, r = divmod(okane, a)
            okane = q * b + r

    print(okane)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<iostream>
#include <algorithm>
using namespace std;
const int MAX = 1000;
int dir[4]={4, -4,1, -1 };//4个?找方向
map<string,int> dp;//存?最小?数
void BFS()
{
    //建立?列
    queue<string> que;
    //放入初始状?
    que.push("01234567");
    dp["01234567"]=0;

    while(que.size())
    {
        string tem2 = que.front();
        que.pop();

        int old =  tem2.find('0',0);
        for(int i=0;i<4;i++)
        {
            int x = old +dir[i];
            if(x>=0&&x<8&&!(old==3&&i==2)&&!(old==4&&i==3))
            {
                string tem=tem2;
                swap(tem[old],tem[x]);
                if(dp.find(tem)==dp.end())//如果存在tem?跳?，防止死循?
                {
                    dp[tem]=dp[tem2]+1;
                    //cout<<dp[tem]<<endl;
                    que.push(tem);
                }
            }
        }
    }
}
int main()
{
    BFS();
    string str;
    while(getline(cin,str))
    {
        str.erase(remove(str.begin(), str.end(), ' '), str.end());
        printf("%d\n",dp[str]);
        //cout<<str.find('0',0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3448
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
string test[213456], cnt[213456], ans[213456];
signed main() {
	int n, k, a = 0, b, ans = 0; cin >> n >> k; string s;
	for (int h = 0; h < n; h++) {
		cin >> s; test[h] = s;
	}
	for (int h = 0; h < 2 * n; h++) {
		cout << test[h / 2] << endl;
	}
	return 0;
}

Measured memory_bytes: 5248
//Warmdust Code
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn = 100+7;
const int mod = 10000+7;
Warmdust
//	TvT;
	int n;
	scanf("%d",&n);
	int a=n;
	if(n%2==1) n++;
	double s=n/2;
	printf("%.10f\n",s/a);
RETURN 


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

int d[705][705];
VI g[705];
int co[705];
int b = 0, w = 0;

bool dfs(int v, int c) {
  // cout << v << " " << c << endl;
  co[v] = c;
  if(c == 1) b++;
  else w++;
  for(auto i: g[v]) {
    if(co[i] == c) return false;
    if(co[i] == 0 && !dfs(i, -c)) return false;
  }
  return true;
}

bool dp[705][705];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    d[a][b] = d[b][a] = 1;
  }

  REP(i, n) FOR(j, i+1, n) {
    if(i!=j && d[i][j] == 0) {
      g[i].PB(j);
      g[j].PB(i);
      // cout << i << "," << j << endl;
    }
  }

  int cnt = 0;
  dp[0][0] = true;
  REP(i, n) {
    if(co[i] != 0) continue;
    b = 0, w = 0;
    if(!dfs(i, 1)) {
      cout << -1 << endl;
      return 0;
    }

    // cout << b << " " << w << endl;

    REP(j, cnt+1) {
      if(!dp[j][cnt-j]) continue;
      dp[j+b][cnt-j+w] = true;
      dp[j+w][cnt-j+b] = true;
    }

    cnt += b+w;
  }

  int ret = INF;
  REP(i, n+1) if(dp[i][n-i]) chmin(ret, i*(i-1)/2 + (n-i)*(n-i-1)/2);
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 6016
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] NK = ReadLineParseIntArray();
        int N = NK[0];
        int K = NK[1];
        WriteLine(N % K);
    }
      static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int N, X;
    cin >> N >> X;

    int D = 0;
    int ans = 1;
    for (int i = 0; i < N; ++i) {
        int L;
        cin >> L;
        D += L;
        if (D > X) continue;
        ++ans;
    }

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


Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      mut a: [usize; n]
   }
   a.sort();
   let ai = a[n - 1];
   a.remove(n - 1);

   a.sort_by_key(|&a| min(a, ai - a));
   let aj = a[n - 2];
   println!("{} {}", ai, aj);
}


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

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

for i in range(n):
    a =int(input())
    for j in range(a):
        x, y = [int(i) for i in input().split()]
        x -= 1
        info[i].append((x,y))

ans = 0

for bit in range(1 << n):
    flag = True
    for i in range(n):
        if bit >> i & 1:
            # 1番目が正直者
            for x,y in info[i]:
                if (bit >> x) & 1 != y:
                    flag = False

    if flag:
        ans = max(bin(bit).count('1'), ans)

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int dp[310][310], cost[310][310];
char v[310][310];

int main ()
{
    //freopen  ("file.in", "r", stdin);

    int n, m;
    scanf ("%d %d\n", &n, &m);

    for (int i = 1; i <= n; ++i)
        fgets (v[i] + 1, 310, stdin);

    int rez = 0;
    for (int j = 1; j < m; ++j)
    {
        for (int a = 0; a <= n; ++a)
            for (int b = 0; b <= n; ++b)
                dp[a][b] = 2000000000,
                cost[a][b] = 0;

        for (int a = 0; a <= n; ++a)
        {
            for (int b = a + 1; b <= n; ++b)
            {
                cost[0][a] += (v[b][j] == v[b - a][j + 1]);
                if (a > 0) cost[a][0] += (v[b - a][j] == v[b][j + 1]);
            }
        }

        for (int a = 1; a <= n; ++a)
            for (int b = 1; b <= n; ++b)
                cost[a][b] = cost[a - 1][b - 1] - (v[n - a + 1][j] == v[n - b + 1][j + 1]);

        dp[0][0] = 0;
        for (int a = 0; a <= n; ++a)
            for (int b = 0; b <= n; ++b)
            {
                if (!a && !b) continue;

                if (a > 0) dp[a][b] = min (dp[a][b], dp[a - 1][b] + cost[a - 1][b]);
                if (b > 0) dp[a][b] = min (dp[a][b], dp[a][b - 1] + cost[a][b - 1]);
            }

        rez += dp[n][n];
    }

    printf ("%d\n", rez);

    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> v(H);
  for ( int i = 0; i < H; i++ ) {
    cin >> v[i];
  }

  vector<bool> row( H, false );
  vector<bool> col( W, false );

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      if ( v[i][j] == '#' ) {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for ( int i = 0; i < H; i++ ) {
    if ( row[i] ) {
      for ( int j = 0; j < W; j++ ) {
        if ( col[j] ) {
          cout << v[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{
	int i,j,k,a,b,c,n,s=0;
	scanf("%d\n%d\n%d\n%d",&a,&b,&c,&n);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if((i*500+j*100+k*50)==n)
					s++;
			}
		}
	}
	printf("%d",s);
	return 0;
}

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

int main(){
    int N; cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    multiset<int> st;
    st.insert(a[0]);
    int ans;
    for(int i=1;i<N;i++){
        auto it=st.lower_bound(a[i]);
        if(it!=st.begin()){
            it--;
            st.erase(it);
        }
        st.insert(a[i]);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 5376
private fun readInts() = readLine()!!.split(" ").map(String::toInt)

private val MOD = 1000000007
private val NOT_YET = -1

fun main(args: Array<String>) {
    val (N, M) = readInts()
    val a = (0 until M).map { readLine()!!.toInt() - 1 } // 0-indexed

    if (N == 1) {
        println(1)
        return
    }

    val ways = Array(N) { NOT_YET }
    a.forEach { hole -> ways[hole] = 0 }

    if (ways[0] == NOT_YET) ways[0] = 1
    if (ways[1] == NOT_YET) ways[1] = 1 + ways[0]
  
    (2 until N)
        .filter { position -> ways[position] == NOT_YET }
        .asSequence()
        .forEach { ways[it] = (ways[it - 1] + ways[it - 2]) % MOD }

    println(ways.last())
}


Measured memory_bytes: 41328
#include <bits/stdc++.h>
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

typedef long long i64; 

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

bool is_prime(int a) {
  int cnt = 0;
  for (int i = 1; i * i <= a; i++) if (a % i == 0) cnt++;
  if (cnt > 1) return false;
  return true;
}

int main(void) {
  int a; scanf("%d", &a);
  for (int i = a + ((a % 2 == 0 && a != 2) ? 1 : 0); ;i += 2) {
    if (is_prime(i)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int s , hour , min , sec;
  cin >> s;
  hour = s / 3600;
  s = s % 3600;
  min = s / 60;
  sec = s % 60;
  cout << hour << ":" << min << ":" << sec << endl;
  return 0;
}


Measured memory_bytes: 3132
l, r = map(int, input().split())

t = r - l

if t > 673:
    print("0")
else:
    ans = 2018
    for i in range(t):
        for j in range(t - i):
            p = ((l + i) * (l + i + j + 1)) % 2019
            if p < ans:
                ans = p
    print(ans)


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

int main(){
  int n; cin >> n;
  vector<int> b(n-1);
  for (int i=0; i<n-1; i++){
    cin >> b[i];
  }
  int ans = b[0]+b[n-2];
  int tmp = b[0];
  for (int i=1; i<n-1; i++){
    if(b[i] >= tmp){
      ans += tmp;
    }else{
      ans += b[i];
    }
    tmp = b[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
_input = input()
N, L = tuple([int(a) for a in _input.split(' ')])

def ans_func(I):
    return int(N*N/2 - N/2 + (N-1)*L + 1 - I)


if L >= 0:
    print(ans_func(1))
elif -L + 1 <= N:
    print(ans_func(-L + 1))
else:
    print(ans_func(N))


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

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define sz(s) (ll) s.size()
#define deb(i) cout << "Aqui " << (ld) i << "\n";



int main(){
		
	ll n, sum = 0ll, mn = (1e18);
	cin >> n;
	vll a(n), carga(n,0);
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(all(a), greater<ll>());
	
	int k = 2, i=1;
	sum += a[0];
	
	while(k<n){
		//cout << k << " " << i << " " << sum << "\n";
		if(carga[i]<2){
			carga[i]++;
			k++;
			sum += a[i];
		}
		if(carga[i]>=2){
			i++;
			continue;
		}
	}
	
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 6436
#include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;

int a[MAX];

int main(void){
 	int n,k;
	while(cin >> n >> k,n|k){
		int ans=-1000000000;
		int cmax=0;
		for(int i=0;i<k;i++){
			cin >> a[i];
			cmax+=a[i];
		}
		ans=max(ans,cmax);
		for(int i=k;i<n;i++){
			cin >> a[i];
			cmax+=a[i];
			cmax-=a[i-k];
			ans=max(ans,cmax);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int, int> pii;

const int N = 200005;
const ll OO = 1e18;

int n, m;
int a[N];
vector<pii> v[N];
ll val[1 << 20], lazy[1 << 20];

void push(int id) {
	val[id] += lazy[id];
	lazy[id * 2 + 1] += lazy[id];
	lazy[id * 2 + 2] += lazy[id];
	lazy[id] = 0;
}

void update(int ql, int qr, ll x, int id = 0, int l = 0, int r = n - 1) {
	push(id);
	if (ql > r || qr < l)
		return;
	if (ql <= l && r <= qr) {
		lazy[id] += x;
		push(id);
		return;
	}
	int mid = (l + r) / 2;
	update(ql, qr, x, id * 2 + 1, l, mid);
	update(ql, qr, x, id * 2 + 2, mid + 1, r);
	val[id] = max(val[id * 2 + 1], val[id * 2 + 2]);
}

ll query(int ql, int qr, int id = 0, int l = 0, int r = n - 1) {
	push(id);
	if (ql > r || qr < l)
		return -OO;
	if (ql <= l && r <= qr)
		return val[id];
	int mid = (l + r) / 2;
	return max(query(ql, qr, id * 2 + 1, l, mid), query(ql, qr, id * 2 + 2, mid + 1, r));
}

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		l--, r--;
		v[r].emplace_back(l, x);
	}
	for (int i = 0; i < n; i++) {
		update(i, i, max(0LL, query(0, i - 1)));
		for (auto p : v[i]) {
			update(p.first, i, p.second);
		}
	}
	cout << max(0LL, query(0, n - 1)) << endl;
	return 0;
}


Measured memory_bytes: 25600
n = int(input())
ans = 0

if n >= 105:
    for i in range(105, n+1, 2):
        count_yakusuu = 0
        for j in range(1, int(i**0.5)+1):
            if i % j == 0:
                count_yakusuu += 2
        if count_yakusuu == 8:
            ans += 1
print(ans)


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

#define pb push_back
typedef unsigned long long ll;
typedef vector<long long> vll;
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,b) for(ll i=a;i<b;i++)


void solve(){
    ll x,y,c,t;
    cin>>x>>y;
    t = (y - (2 * x))/2;
    c = ((4 * x) - y )/2;
    if((c+t == x) && ((4*t + 2*c)== y))   cout<<"Yes\n";
    else cout<<"No\n";
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3608
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//function myerr(t){return;}//デバッグOFF用
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var X = one[0];
  var Y = one[1];
  var Z = one[2];
  var K = one[3];
  var xlist = nextIntArray();
  xlist.sort(function(a,b){
  	return b - a;
  });
  var ylist = nextIntArray();
  ylist.sort(function(a,b){
  	return b - a;
  });
  var zlist = nextIntArray();
  zlist.sort(function(a,b){
  	return b - a;
  });
  var maelist = new Array(X * Y);
  var output = [];
  for(var i = 0; i < X; i++){
    for(var j = 0; j < Y; j++){
      if((i + 1) * (j + 1) > K){
        break;
      }else{
        for(var l = 0; l < Z; l++){
          if((i + 1) * (j + 1) * (l + 1) <= K){
            output.push(xlist[i] + ylist[j] + zlist[l]);
          }
        }
      }
    }
  }
  output.sort(function(a,b){
  	return b - a;
  });
  output.splice(K,output.length - K);
  myout(myconv(output,9));
}


Measured memory_bytes: 37940
import sys,bisect as bs,collections as cl
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
n = onem()

ans = 0
a = []

for i in range(n):
    a.append(l())

for k in range(n):
    for i in range(n):
        for j in range(n):
            if a[i][j] > a[i][k] + a[k][j]:
                print(-1)
                exit()
for i in range(n-1):
    for j in range(i,n):
        for k in range(n):
            if i == k or k == j:
                continue
            if a[i][j] == a[i][k] + a[k][j]:
                break
        else:
            ans += a[i][j]
    

print(ans)




Measured memory_bytes: 44252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <map>

//#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

/*
const int MAX = 1000000;
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;
        //そのまま計算すると負の値になるので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;
}

//UnionFind木
struct UnionFind{
   vector<long long int> par; //par[i] : iの親の番号
   vector<long long int> rnk; //root[i] : iの木のサイズ

   //コンストラクタ
   UnionFind(long long int n): par(n), rnk(n){
       //木の初期化
       for(long long int i = 0; i < n; i++){
           par[i] = i;
           rnk[i] = 1;
       }
   }

   //データxが属する木の根を再帰で取得
   long long int root(long long int x){
       if(par[x] == x){
           return x;
       }else{
           return par[x] = root(par[x]);
       }
   }

   //xとyが同じ木に属しているかを判定
   bool same(long long int x, long long int y){
       return root(x) == root(y);
   }

   //xとyの木を併合
   void unite(long long int x, long long int y){
       long long int rx = root(x); //xの根
       long long int ry = root(y); //yの根
       if(rx == ry) return; //根が同じならそのまま

       //併合するときにサイズを足し合わせる
       if(rnk[rx] < rnk[ry]){
           par[rx] = ry;
           rnk[ry] += rnk[rx];
       }else{
           par[ry] = rx;
           rnk[rx] += rnk[ry];
       }
   }

   //属している木のサイズを取得
   long long int size(long long int x){
       return rnk[root(x)];
   }
};
*/

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

    vector<long long int> v;

    long long int sum = 0;
    for(int i = 0; i < n; i++){
        long long int a, b;
        cin >> a >> b;
        sum -= b;
        v.push_back(a + b);
    }

    sort(v.begin(), v.end());

    for(int i = 0; i < n; i++){
        if(i%2 == 0) sum += v[n-1-i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 1400
import java.util.Scanner;

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

		for(int i=0; i<6; i++){
			defaultpip[i] = Integer.parseInt(std.next());
		}
		Dice dc1 = new Dice(defaultpip);

		int defaultpip2[] = new int[6];
		for(int i=0; i<6; i++){
			defaultpip2[i] = Integer.parseInt(std.next());
		}
		Dice dc2 = new Dice(defaultpip2);

		//??¬???????????¬???
		String query[] = {"S", "W", "N", "E"};

		boolean same = false;
		for(int i = 0; i<1000; i++){
			if(dc1.issame(dc2)){
				same = true; break;
			}else{
				dc1 = dc1.newnowpips(query[(int)(Math.random()*4)]);
			}
		}
		if(same){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

class Dice {
	int pips[];
	int nowpip;
	int spip;
	int epip;
	int wpip;
	int npip;
	int rpip;

	public Dice(int pip[]){
		this(pip, 0, 1, 2, 3, 4, 5);
	}

	public Dice(int pip[], int now, int s, int e, int w, int n, int r){
		pips = pip;
		nowpip = now;
		spip = s;
		epip = e;
		wpip = w;
		npip = n;
		rpip = r;
	}

	public Dice newnowpips(String query){
		if(query.equals("N")){
			return new Dice(pips,spip,rpip,epip,wpip,nowpip,npip);
		}else if(query.equals("E")){
			return new Dice(pips,wpip,spip,nowpip,rpip,npip,epip);
		}else if(query.equals("S")){
			return new Dice(pips,npip,nowpip,epip,wpip,rpip,spip);
		}else if(query.equals("W")){
			return new Dice(pips,epip,spip,rpip,nowpip,npip,wpip);
		}else {	//clockwise
			return new Dice(pips,nowpip,epip,npip,wpip,spip,rpip);
		}
	}

	public String showdice(){
		return pips[nowpip] +" "+ pips[spip] +" "+ pips[epip] +" "+ pips[wpip] +" "+ pips[npip] +" "+ pips[rpip];
	}

	public boolean issame(Dice d2){
		return showdice().equals(d2.showdice());
	}
}

Measured memory_bytes: 27748
int_a = 97
num_char = 26

c = input()
asc = ord(c)

if asc >= int_a:
    if asc < int_a + num_char - 1:
        print(chr(asc + 1))
    else:
        print("Please Input from a to y.")
else:
    print("Please Input from a to y.")

Measured memory_bytes: 2940
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	s := make([]string, n)
	dict := make(map[string]int)

	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%s", &s[i])
		dict[s[i]]++
		if max < dict[s[i]] {
			max = dict[s[i]]
		}
	}

	var maxWords []string
	for key, val := range dict {
		if val == max {
			maxWords = append(maxWords, key)
		}
	}
	sort.Strings(maxWords)
	for i := 0; i < len(maxWords); i++ {
		fmt.Println(maxWords[i])
	}
}


Measured memory_bytes: 37632
using System;
class Program{
  static void Main(string[] args){
	string[] input = Console.ReadLine().Split(' ');
	int N = int.Parse(input[0]);
	int M = int.Parse(input[1]);
    int correctNum = 0;
    int penaltyNum = 0;
    bool[] probB = new bool[N];
    int[] wai = new int[N];
    for (int i = 0; i < M; i++) {
      string[] input1 = Console.ReadLine().Split(' ');
      int probNum = int.Parse(input1[0]) - 1;
      if (!probB[probNum]) {
        if (input1[1] == "WA") {
          wai[probNum]++;
        } else {
          correctNum++;
          penaltyNum += wai[probNum];
          probB[probNum] = true;
        }
      }
    }
    Console.WriteLine(correctNum + " " + penaltyNum);
  }
}

Measured memory_bytes: 15456
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mod=1e9+7;
const int mx=2e5+77;
ll two[mx];

int main() {
	two[0]=1;
	for (int i=1; i<mx; i++)
		two[i]=(two[i-1]*2)%mod;
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<ll> A(N), B(N);
	for (int i=0; i<N; i++)
		cin>>A[i]>>B[i];
	int left=0, right=0, zero=0;
	map<ii,int> ct;
	for (int i=0; i<N; i++) {
		if(A[i]==0&&B[i]==0) {
			zero++;
		} else if(A[i]==0) left++;
		else if(B[i]==0) right++;
		else {
			if(A[i]<0 && B[i]<0) {
				A[i]=abs(A[i]), B[i]=abs(B[i]);
			} else if(A[i]>0 && B[i]>0) {
				;
			} else {
				A[i]=-abs(A[i]), B[i]=abs(B[i]);
			}
			ll G=gcd(abs(A[i]),abs(B[i]));
			ct[{A[i]/G,B[i]/G}]++;
		}
	}
	ll ret=1;
	ret=(ret*(1 + two[left]-1+two[right]-1))%mod;
//cout<<"#"<<ret<<endl;
	set<ii> done;
	for (auto it : ct) {
		ii key=it.first;
		if(done.count(key)) continue;
		ii opp={-key.second,key.first};
		if(!ct.count(opp)) opp={-opp.first, -opp.second};
//cout<<key.first<<"/"<<key.second<<"::"<<opp.first<<"/"<<opp.second<<endl;
//cout<<ct[key]<<" "<<ct[opp]<<"::"<<two[ct[key]]<<" "<<two[ct[opp]]<<"=>"<<1 + two[ct[key]]-1+two[ct[opp]]-1<<endl;
		ret=(ret*(1 + two[ct[key]]-1+two[ct[opp]]-1))%mod;
//cout<<"#"<<ret<<endl;
		done.insert(key);
		done.insert(opp);
	}
//cout<<ret<<endl;
	ret=(ret+zero+mod-1)%mod;
	cout<<ret<<"\n";
	return 0;
}


Measured memory_bytes: 57804
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
vector<int> ans;
struct Node {
  int idx;
  vector<int> nbr;
  bool vst = false;
  void dfs() {
    vst = true;
    if(idx != 0) ans.push_back(idx);
    for(int x : nbr) {
      if(!V[x].vst) {
        V[x].dfs();
        break;
      }
    }
  };
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  REP(i, N) {
    V.emplace_back();
    V[i].idx = i;
  }
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    V[u].nbr.push_back(v);
    V[v].nbr.push_back(u);
  }
  ans.push_back(0);
  V[0].dfs();
  reverse(ALL(ans));
  V[0].dfs();
  cout << ans.size() << "\n";
  REP(i, ans.size()) cout << (ans[i]+1) << (i!=ans.size()-1 ? " " : "");
  cout << "\n";
}

Measured memory_bytes: 8812
while 1:
    N = int(input())
    if N == 0:
        break
    st = []
    last = None
    for i in range(N):
        s = int(input())
        if last is None:
            last = [1, s]
            st.append(last)
            continue
        if last[1] == s:
            last[0] += 1
        else:
            if i % 2:
                P = st.pop()
                if st:
                    last = st[-1]
                    last[0] += P[0] + 1
                else:
                    last = [P[0]+1, s]
                    st.append(last)
            else:
                last = [1, s]
                st.append(last)
    ans = 0
    for s, c in st:
        if c == 0:
            ans += s
    print(ans)


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

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>

using namespace std;

main {
  int x;
  while(cin>>x) {
    vi r;
    x=x<<1;
    for(int i=0; x=x>>1; i++) {
      if (x&1) r.pb(1<<i);
     }
    if (!r.size()) {cout<<endl;continue;}
    cout<<r[0];
    loop(i,1,r.size()) cout<<' '<<r[i];
    cout<<endl;
  }
  bye;
}

Measured memory_bytes: 3104
#include <stdio.h>

int main (void){
  int a[100], n, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  for(i = n - 1; i > 0; i--){
    printf("%d ", a[i]);
  }

  printf("%d\n", a[0]);

  return 0;
}

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

#define fst first
#define snd second
#define mp make_pair
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define per(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()

template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {return (x>y ? (x=y,true):false);}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {return (x<y ? (x=y,true):false);}

template <typename T>
void read(T& x) {
    char ch;
    T p = 1; x = 0;
    do {ch = getchar();} while(ch <= ' ');
    if (ch == '-') p = -1, ch = getchar();
    while (ch>='0' && ch<='9') x = x*10 + ch-'0', ch = getchar();
    x *= p;
}

void read(string& x) {
    char ch;
    do {ch = getchar();} while (ch <= ' ');
    while (ch > ' ') x += ch, ch = getchar();
}

void read(char& x) {do {x = getchar();} while (x <= ' ');}
template<typename T, typename... R>
void read(T& x, R&... y) { read(x); read(y...); }

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

const int N = (int)1e6+3;
const int INF = (int)1e9+17;
const ll mod = (ll)1e9+7;
const ll LLINF = (ll)1e18+17;
const ld pi = (ld)acos(-1.0);


int n, m;
int a[N];


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

    read(n);
    rep(i, 0, n) read(a[i]);
    sort(a, a+n);
    int x = -INF;
    int idx = lower_bound(a, a+n, a[n-1]/2)-a-1;
    if (0 <= idx && idx < n && abs((ld)a[n-1]/2-x) > abs((ld)a[n-1]/2-a[idx])) {
        x = a[idx];
    }
    ++idx;
    if (0 <= idx && idx < n && abs((ld)a[n-1]/2-x) > abs((ld)a[n-1]/2-a[idx])) {
        x = a[idx];
    }
    printf("%d %d\n", a[n-1], x);

    return 0;
}


Measured memory_bytes: 640
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s, k := next(), nextInt()
	n := len(s)

	toa := make([]int, n)
	for i := 0; i < n; i++ {
		if s[i] > 'a' {
			toa[i] = int('z'-s[i]) + 1
		}
	}

	ans := make([]byte, n)
	for i := 0; i < n; i++ {
		ans[i] = s[i]
	}
	for i := 0; i < n && k > 0; i++ {
		if k >= toa[i] {
			ans[i] = 'a'
			k -= toa[i]
		}
	}

	if k > 0 {
		ans[n-1] += byte(k % 26)
	}

	puts(string(ans))
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void){
	int n;
	int i;
	int a,b;
	int sumA=0,sumB=0;
	while(scanf("%d",&n)!=0){
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			if(a>b){
				sumA+=a+b;
			}
			else if(a<b){
				sumB+=a+b;
			}
			else{
				sumA+=a;
				sumB+=a;
			}
		}
		printf("%d %d\n",sumA,sumB);
		sumA=0;
		sumB=0;
	}
	return 0;
}

Measured memory_bytes: 600
import sys
import math
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, N = map(int, input().split())
    if N>=B-1:
        ans = (A*(B-1))//B - A*((B-1)//B)
    else:
        ans = A*N//B - A*(N//B)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)


n = int(input())
uvw = [list(map(int, input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
color = [-1]*(n+1)
for u, v, w in uvw:
    graph[u].append((v, w))
    graph[v].append((u, w))

color[1] = 1
ne = [1]
while ne:
    t = ne.pop()
    for v, w in graph[t]:
        if color[v] == -1:
            ne.append(v)
            color[v] = color[t] if w % 2 == 0 else (color[t]+1) % 2

for i in range(1, n+1):
    print(color[i])


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

int main(){
  string s;
  cin >> s;
  if (s.at(2)==s.at(3)&& s.at(4)==s.at(5)){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256