akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  ll ans = 0;
  rep(i, n) rep3(j, i + 1, n) ans += a[i] * a[j];
  cout << ans << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int maxn=305;
long long dp[maxn][maxn][maxn];// 已经有i天了，连接了j个点的双联通 k个点还没有双联通 的方案数。
int main()
{
    memset(dp,0,sizeof(dp));
    dp[1][1][0]=1;
    int n,m;
    scanf("%d%d",&n,&m);
    m++;
    if(m<n){
        puts("0");
        return 0;
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=0;k+j<=n;k++)
            {
                if(dp[i][j][k]==0) continue;
                dp[i+1][j+k][0]=(dp[i+1][j+k][0]+dp[i][j][k]*j)%mod;
                dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*k)%mod;
                dp[i+1][j][k+1]=(dp[i+1][j][k+1]+dp[i][j][k])%mod;
            }
        }
    }
    long long ans=dp[m][n][0];
    for(int i=2;i<n;i++)
        ans=(ans*i)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 221952
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;



int main(void){
	int n,c;
	cin >> n >> c;

	int d[c+1][c+1], val[c+1][3];
	rep(i,c){
		rep(j,c){
			cin >> d[i+1][j+1];
		}
		rep(j,3)val[i+1][j] = 0;
	}

	rep(i,n){
		rep(j,n){
			int work,label=(i+j+2)%3;
			cin >> work;
			rep(k,c)val[k+1][label] += d[work][k+1];
		}
	}

	int color[3][3] = {{1,2,3},{1,2,3},{1,2,3}};

	for(int i=4;i<=c;i++){
		rep(j,3){
			int tmp=i;
			rep(k,3){
				if(val[color[j][k]][j] > val[tmp][j]){
					int work = color[j][k];
					color[j][k] = tmp;
					tmp = work;
				}
			}
		}
	}

	ll ans=MAX;
	rep(i,3){
		rep(j,3){
			rep(k,3){
				if(color[0][i] != color[1][j] && color[0][i] != color[2][k] && color[1][j] != color[2][k]){
					if(ans > val[color[0][i]][0]+val[color[1][j]][1]+val[color[2][k]][2])
							ans = val[color[0][i]][0]+val[color[1][j]][1]+val[color[2][k]][2];
				}
			}
		}
	}

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


Measured memory_bytes: 256
//KING NIKAN
#include<bits/stdc++.h>
using namespace std;
int a[200010] ;
int b[200010] ;
int main()
{	
	ios::sync_with_stdio(false) ;
	cin.tie(0) ;
	cout.tie(0) ;
	int n , m ;
	cin >> n >> m ;
	int x , y ;
	for(int i=1 ;i<=m ;i++)
	{
		cin >> x >> y;
		if(x==1)
		{
			a[y]++ ;
		}
		if(y==n)
		{
			b[x]++ ;
		}
	}
	for(int i=1 ;i<=m ;i++)
	{
		if(a[i]>0 && b[i]>0)
		{
			cout << "POSSIBLE" ;
			return 0 ;
		}
	}
	cout << "IMPOSSIBLE" ;
	return 0 ;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M; 

  bool hantei[N];
  int countWA[N];

  int pena=0;
  int seikai=0;
  
  for(int i=1;i<=N;i++){
    hantei[i]=false;
    countWA[i]=0;
  }
  while(M--){
    int p;
    string S;
    cin>>p>>S;
    if(hantei[p]==true)continue;
    if(S=="AC"){
      hantei[p]=true;
      seikai++;
      pena+=countWA[p];
    }else if(S=="WA"){
      countWA[p]++;
    }
  }
  cout<< seikai <<" "<<pena<<endl;
}

Measured memory_bytes: 768
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int h, w, n; readV(h, w, n);
  int[] a, b; readC(n, a, b);
  a[] -= 1; b[] -= 1;

  auto key(int a, int b)
  {
    return (a.to!long<<32)|b;
  }

  bool[long] p, q;
  foreach (i; 0..n) p[key(a[i], b[i])] = true;

  auto ans = new int[](10);

  foreach (i; 0..n)
    foreach (r; a[i]-2..a[i]+1)
      foreach (c; b[i]-2..b[i]+1) {
        if (r < 0 || r > h-3 || c < 0 || c > w-3 || key(r, c) in q) continue;
        q[key(r, c)] = true;

        auto ci = 0;
        foreach (cr; r..r+3)
          foreach (cc; c..c+3)
            if (key(cr, cc) in p) ++ci;
        ++ans[ci];
      }

  auto ans0 = (h-2).to!long*(w-2)-ans.sum;
  writeln(ans0);
  foreach (i; 1..10) writeln(ans[i]);
}


Measured memory_bytes: 65020
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;


int main(){
  int res;

  vector<bool> bo(3,1);
  REP(i,3)bo[i]=1;
  REP(i,2){
    int a; cin>>a;
    bo[a-1]=0;
  }
  REP(i,3){
    if(bo[i]==1)res=i+1;
     
  }
    cout<<res<<endl;
  
}

Measured memory_bytes: 256
class Player:

    def __init__(self, name, s):
        self.name = name
        self.cards = list(s)

    @property
    def is_winner(self):
        return len(self.cards) == 0

    def _drop(self):
        dropped = self.cards.pop(0)
        return dropped

    def play(self):
        if len(self.cards) >= 1:
            dropped = self._drop()
            return dropped
        return None

    def __str__(self):
        return self.name

A=Player("A", input())
B=Player("B", input())
C=Player("C", input())

def get_player(ch):
    if ch == 'a':
        return A
    elif ch == 'b':
        return B
    elif ch == 'c':
        return C
    else:
        raise ValueError('unknown char {}'.format(ch))


player = get_player(A.play())
if A.is_winner:
    print('A')
else:
    while player is not None:
        if player.is_winner:
            print(str(player))
            break
        next_ch = player.play()
        player = get_player(next_ch)



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

const int INF = 1e+9 * 2;

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int N;
	while(cin >> N && N){
		string s;
		bool check[1001] = {0}, ok = true;;
		int a[1001] = {0}, cnt = 0;
		for(int i = 1; i <= N; ++i){
			cin >> s;
			if(s == "x"){
				a[i] = INF;
				check[i] = true;
				cnt++;
				if(i > 1 && check[i - 1])
					ok = false;
			}
			else{
				a[i] = stoi(s);
			}
		}
		if(!ok){
			cout << "none" << endl;
			continue;
		}
		for(int i = 1; i <= N; ++i){
			if(!check[i]){
				if(i % 2){
					if(i > 1){
						if(!check[i - 1] && a[i - 1] <= a[i]){
							ok = false;
							break;
						}
					}
					if(i < N){
						if(!check[i + 1] && a[i] >= a[i + 1]){
							ok = false;
							break;
						}
					}
				}
				else{
					if(!check[i - 1] && a[i - 1] >= a[i]){
						ok = false;
						break;
						
					}
					if(i < N){
						if(!check[i + 1] && a[i] <= a[i + 1]){
							ok = false;
							break;
						}
					}
				}
			}
		}
		if(!ok || cnt == N){
			cout << "none" << endl;
			continue;
		}
		else if(ok && cnt == 0){
			cout << "ambiguous" << endl;
			continue;
		}
		int omin = INF, emin = -INF;
		for(int i = 1; i <= N; ++i){
			if(check[i]){
				if(i % 2){
					if(i > 1 && !check[i - 1]){
						omin = min(omin, a[i - 1] - 1);
					}
					if(i < N && !check[i + 1]){
						omin = min(omin, a[i + 1] - 1);
					}
				}
				else{
					if(i < N && !check[i + 1]){
						emin = max(emin, a[i + 1] + 1);
					}
					if(!check[i - 1])
						emin = max(emin, a[i - 1] + 1);
				}
			}
		}
		if(emin == omin){
			cout << emin << endl;
		}
		else if(emin < omin || omin == INF || emin == -INF){
			cout << "ambiguous" << endl;
		}
		else{
			cout << "none" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
object Main extends App {
  var li = scala.collection.mutable.Set[String]()
  val s = scala.io.StdIn.readLine()
  val n = scala.io.StdIn.readLine().toInt
  for (i <- 0 to s.length) {
    for (l <- i to math.min(i+5, s.length)) {
      li += s.slice(i,l)
    }
  }
  println(li.toList.sorted.drop(1)(n-1))
}

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

using namespace std;
using ll = long long;

const int INF = 1000000000;

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

    int x, n;
    cin >> x >> n;

    int pt;
    set<int> p;

    for(int i = 0; i < n; ++i) {
        cin >> pt;
        p.emplace(pt);
    }

    for(int i = 0; true; ++i) {
        if(p.find(x - i) == p.end()) {
            printf("%d\n", x - i);
            return 0;
        } else if(p.find(x + i) == p.end()) {
            printf("%d\n", x + i);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3744
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 2**((self.n-1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = [None]*(2*self.N-1)
        
        # construction
        for i in range(self.N):
            self.v[i + self.N - 1] = lst[i] if i < self.n else self.e
        for i in range(self.N - 2, -1, -1):
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
        
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] += x
        while i > 0:
            i -= 1
            i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        assert l < r
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e
        R = self.e
        while left < right:
            if left % 2 == 0: # left is even
                L = self.op(L, self.v[left])
                left += 1
            if right % 2 == 0: # right is even
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1
            left >>= 1
            right >>= 1
        return self.op(L, R)

n, q = map(int, input().split())
A = [0]*n
st = SegmentTree(A, lambda x, y: x+y, 0)
for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        st.update(x-1, y)
    else:
        print(st.query(x-1, y))


Measured memory_bytes: 11520
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int m1 = sc.nextInt();
    int d1 = sc.nextInt();
    int m2 = sc.nextInt();
    int d2 = sc.nextInt();

    if (m1 != m2) {
      System.out.println(1);
    } else {
      System.out.println(0);
    }


  }

}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if ((a <= c && c <= b) || (a >= c && c >= b)) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define NIL -1

struct Node {
    int parent;
    int left,right;
};

struct Node T[MAX];
int n, D[MAX];



void print(int u){
    int i,c;
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("depth = %d, ",D[u]);
    
    
    if(T[u].parent == NIL) printf("root, ");
    else if(T[u].left == NIL) printf("leaf, ");
    else   printf("internal node, ");
    
    printf("[");
    for(i=0, c=T[u].left; c!=NIL; i++, c=T[c].right){
        if(i) printf(", ");
        printf("%d",c);
    }
    printf("]\n");
}
// 再帰的に深さを求める
void rec(int u, int p){
    D[u]=p;
    if(T[u].right !=NIL) rec(T[u].right, p); // 右の兄弟に同じ深さを設定
    if(T[u].left!=NIL) rec(T[u].left, p+1); // 最も左の子に自分の深さ+1を設定
}

int main(){
    int i,v,l,c,d,r;
    scanf("%d",&n);
   
       for(i=0; i<n; i++)
           T[i].parent = T[i].left=T[i].right=NIL;
    
    for( i=0; i<n; i++){
        scanf("%d%d",&v,&d);
    
    for(int j=0; j<d; j++){
        scanf("%d",&c);
        if(j==0) T[v].left=c;
        else T[l].right=c;
        l=c;
        T[c].parent = v;
    }
    }
    for(i=0;i<n;i++){
        
        if(T[i].parent == NIL) r=i;
    }
    rec(r,0);
   
    
   for(int i=0; i<n; i++) print(i);
    return 0;
}


Measured memory_bytes: 6388
a, b, c, d = map(int, input().split())
e = [a, b]; f = [c, d]; g = -10**18
if a < 0 and 0 < b: e.append(0)
if c < 0 and 0 < d: f.append(0)
for i in range(len(e)):
    for j in range(len(f)):
        g = max(g, e[i]*f[j])
print(g)

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}


void solve(){ 
    ll n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    vector<ll> a,b;
    for(ll i=0;i<n;i++){
        if(s[i]=='o'){
            a.pb(i);
            i += c;
        }
    }
    for(ll i=n-1;i>=0;i--){
        if(s[i]=='o'){
            b.pb(i);
            i -= c;
        }
    }
    vector<ll> ANS;
    for(ll i=0;i<k;i++){
        if(a[i] == b[k-i-1]){
            ANS.pb(a[i]+1);
        }
    }

    for(auto it : ANS)
        cout << it << endl;

}

int main(){
   
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 6664
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def main():
    L = input()
    N = len(L)
    # a + b が小さいのが確定
    dp_1 = [0] * N
    # a + b が大きいのか小さいのかわからない
    dp_2 = [0] * N

    dp_1[0] = 1
    dp_2[0] = 2

    for i in range(1, N):
        if L[i] == "1":
            # (1, 0), (0, 1)の組み合わせで，a+bのi桁目が1
            dp_2[i] = dp_2[i - 1] * 2

            dp_1[i] = dp_2[i - 1] + dp_1[i - 1] * 3

            dp_2[i] %= MOD
            dp_1[i] %= MOD
        else:
            # (1, 0), (0, 1)の組み合わせで，a+bのi桁目が1
            dp_2[i] = dp_2[i - 1]

            dp_1[i] = dp_1[i - 1] * 3

            dp_2[i] %= MOD
            dp_1[i] %= MOD

    ans = dp_1[-1] + dp_2[-1]
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11152
import java.util.Scanner;

class Main{
  public static void main(String []a){
    Scanner sc=new Scanner(System.in);
    char ch=sc.next().charAt(0);
    
    if(ch>90){
      System.out.println("a");
    }
    else{
      System.out.println("A");
    }
  }
}

Measured memory_bytes: 35532
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::*;

fn main() {
    input! {
        n: usize,
        s_list: [String; n],
        m: usize,
        t_list: [String; m]
    }

    let mut map: HashMap<String, i64> = HashMap::new();
    for s in s_list {
        let c = map.get(&s).unwrap_or(&0) + 1;
        map.insert(s, c);
    }
    for t in t_list {
        let c = map.get(&t).unwrap_or(&0) - 1;
        map.insert(t, c);
    }
    let ans = std::cmp::max(*map.values().max().unwrap(), 0_i64);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
using namespace std;
using ll = long long;
const int INF = 1e8;
int N;
vector<int>c;
int main() {
	int N;
	int a;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	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) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Bingo
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int MOD = 100000;
		for(;;){
			int N = sc.nextInt(), M = sc.nextInt(), S = sc.nextInt();
			if((N|M|S)==0)break;
			N*=N;
			int[][] dp = new int[N+1][S+1];
			dp[0][0] = 1;
			for(int m=1;m<=M;m++)for(int k=N;k>0;k--)for(int s=m;s<=S;s++){
				dp[k][s]+=dp[k-1][s-m];
				if(MOD<=dp[k][s])dp[k][s]-=MOD;
			}
			System.out.println(dp[N][S]);
		}
	}

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

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    string S;
    cin >> S;
    cout << (char)(S[0] + 1) << endl;
}


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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
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;
}

int main() {
    int N, M;
    COMinit();
    cin >> N >> M;
    auto vec = prime_factorize(M);
    long long res = 1;
    for (auto pa : vec) {
        int num = pa.second;
        long long tmp = COM(num+N-1, N-1);
        res = (res * tmp) % MOD;
    }
    cout << res << endl;
}          

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int gcd(int p, int q){
    if(q==0) return p;
    return gcd(q,p%q);
}

void compress(vector<P> &v){
    int g = 0;
    for(auto &p : v){
        g = gcd(abs(p.first), g);
        g = gcd(abs(p.second), g);
    }
    for(auto &p : v){
        p.first /= g;
        p.second /= g;
    }
}

void rotate90(vector<P> &v){
    for(auto &p : v){
        int x = p.first, y = p.second;
        p.first = y;
        p.second = -x;
    }
}

void rev(vector<P> &v){
    reverse(v.begin(), v.end());
    for(auto &p : v){
        p.first *= -1;
        p.second *= -1;
    }
}

int solve(){
    int n;
    cin >> n;
    if(n == 0) return 1;
    vector<vector<P> > lines(n+1);
    for(int i=0;i<n+1;i++){
        int m, px, py;
        cin >> m;
        for(int j=0;j<m;j++){
            int x, y;
            cin >> x >> y;
            if(j>0) lines[i].push_back(P(x-px,y-py));
            px = x;
            py = y;
        }
        compress(lines[i]);
    }
    for(int i=1;i<=n;i++){
        bool same = false;
        if(lines[0].size() != lines[i].size()) continue;
        for(int j=0;j<2;j++){
            for(int k=0;k<4;k++){
                same |= lines[0] == lines[i];
                rotate90(lines[i]);
            }
            rev(lines[i]);
        }
        if(same) cout << i << endl;
    }
    cout << "+++++" << endl;
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
typedef long long ll;
const ll mod=1e9+7;
const int N=1e5+5;
ll p[N];int n,m;
int main() {
    scanf("%d%d",&n,&m);
    if(n>m) std::swap(n,m);
    if(n+1<m) return !printf("0");
    p[0]=1;
    for(int i=1;i<=m;i++) p[i]=p[i-1]*i%mod;
    printf("%lld\n",n==m?p[n]*p[m]*2%mod:p[n]*p[m]%mod);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>

bool cmp(long long i, long long j){
	return i > j;
}

long long C[55][55];

int main(){
	
	//freopen("file", "r", stdin);
	
	int N, A, B; scanf("%d %d %d", &N, &A, &B);
	
	long long V[55];
	for(int i = 0; i < N; ++i){
		scanf("%lld", &V[i]);
	}
	
	std::sort(V, V + N, cmp);
	
	int st = 0, dr = 0;
	
	for(int i = A - 1; i >= 0; --i){
		if(V[i] != V[A - 1])
			break;
		
		st++;
	}
	
	for(int i = A; i < N; ++i){
		if(V[i] != V[A - 1])
			break;
		
		dr++;
	}
	
	
	for(int i = 0; i <= N; ++i){
		C[i][0] = 1;
		
		for(int j = 1; j <= i; ++j){
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
	
	long double mean = 0;
	for(int i = 0; i < A; ++i)
		mean += V[i];
	
	mean /= A;
	
	printf("%.10Lf\n", mean);
	
	//printf("%d %d\n", st, dr);
	
	long long ans = 0;
	
	if(st == A){
		for(int i = st; i <= B && i <= st + dr; ++i){
			ans += C[st +dr][i];
		}
	}else{
		ans += C[st + dr][st];
	}
	
	printf("%lld", ans);

return 0;	
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
int x1,y1,x2,y2,x3,y3,x4,y4;
int main(){
	in4(x1,y1,x2,y2);
	x3=x2-(y2-y1);
	y3=y2+(x2-x1);
	x4=x3-(x2-x1);
	y4=y1+(x2-x1);
	printf("%d %d %d %d",x3,y3,x4,y4);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


/*
  [x^k](x^A+x^(A+B)+x^B+1)^N
  = [x^k](x^A+1)^N(x^B+1)^N
  = sum(i+j=k) { [x^i](x^A + 1)^N * [x^j](x^B + 1)^N }
  = sum(i+j=k) { N_C_(i/A) * N_C_(j/B) }
  = sum(An+Bm=k) { N_C_n * N_C_m }

*/

class comb{
  vector<ll> f,fr;
  ll MOD_;
  public:
  //a^(p-1) = 1 (mod p)(p->Prime numbers)
  //a^(p-2) = a^(-1)
  ll calc(ll a,ll b,ll p){//a^(b) mod p   
    if(b==0)return 1;
    ll y = calc(a,b/2,p);y=(y*y)%p;
    if(b & 1) y = (y * a) % p;
    return y;
  }
  void init(ll n,ll mod){//input max_n
    MOD_ = mod;
    f.resize(n+1);
    fr.resize(n+1);
    f[0]=fr[0]=1;
    for(ll i=1;i<n+1;i++){
      f[i] = (f[i-1] * i) % mod;
    }
    fr[n] = calc(f[n],mod-2,mod);
    for(ll i=n-1;i>=0;i--){
      fr[i] = fr[i+1] * (i+1) % mod;
    }
  }
  ll nCr(ll n,ll r){
    if(n<0||r<0||n<r)return 0;
    return f[n] * fr[r] % MOD_ * fr[n-r] % MOD_;
  }//nHr = n+r-1Cr
};

int main(){

  ll N,A,B,K;
  cin >> N >> A >> B >> K;
  ll mod = 998244353;
  ll ans = 0;
  comb co;
  co.init(314159,mod);
  FOR(i,0,N+1){
    ll An = A*i;
    ll Bm = K - An;
    if(Bm % B != 0)continue;
    ll m = Bm/B;
    (ans += co.nCr(N,i) * co.nCr(N,m) % mod ) %= mod;
  }
  cout << ans << endl;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    string s;
    int k;

    cin >> n >> s >> k;
    char c = s[k - 1];
    rep(i, n) if (s[i] != c) s[i] = '*';

    cout << s << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  D - Dice in Line
//
//  Created by Hashizo on 2020/02/09.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {

	ll n,k;
	cin >> n >> k;

	
	vector<ll> point(n);
	
	ll index = 0;
	ll save = 0;
	ll sum = 0;

	REP(i, n) {
		cin >> point[i];
	
		sum += point[i];
	
		if (i == (k-1) ) {
			save = sum;
		}
		
		if (i > (k-1)) {
			sum -= point[i-k];
			if(save < sum) {
				index = i-k+1;
				save = sum;
			}
		}
	}

/*
	REP(i, n-k+1){
//		ll sum = 0;
		REP(j,k) {
			sum += point[i+j];
		}
		
		if(save < sum) {
			index = i;
			save = sum;
		}
	}
*/
	double ans = 0.0;

	REP(j,k) {
		ans += (double)(point[index+j]) / 2 + 0.5 ;
	}
	
	char s[20];
	sprintf(s,"%.6f" ,ans);
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
mod=10**9+7
fact = [1]*(max(n,m)+1)
r = 1
for i in range(1, max(n,m)+1):
    fact[i] = r * i % mod
    r = r * i % mod
    
if abs(n-m)>1: print(0)
elif abs(n-m)==1: print(fact[n]*fact[m]%mod)
else: print(fact[n]*2*fact[n]%mod)

Measured memory_bytes: 39280
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

void dump(vi& A) {
  string sp = "";
  for (auto& x:A) {
    cout << sp << x;
    sp = " ";
  }
  cout << endl;
}

void insertionSort(vi& A, int N) {
  for (int i = 1; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    dump(A);
  }
}

int main(int argc, char **argv)
{
  vi A;
  int n;
  cin >> n;
  A = vi(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  dump(A);
  insertionSort(A, n);
  return 0;
}

Measured memory_bytes: 3136
N,Q = map(int, input().split())
L = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
cnt = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x

flag = [1]*N
q = [0]
while q:
    temp = q.pop()
    flag[temp] = 0
    for i in L[temp]:
        if flag[i]:
            q.append(i)
            cnt[i] += cnt[temp]
            
print(*cnt)

Measured memory_bytes: 55856
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define itn int
#define int ll
using namespace std;

int N;
int X[1010];
int P[1010];
vi C[1010];
int dp[1010][5010];

pi solve(int n) {
//    cerr<<"solve("<<n<<")"<<endl;
    int children=C[n].size();
    pi cp[1010];
    REP(i,1,children) {
        cp[i]=solve(C[n][i-1]);
//        cerr << "solve("<<C[n][i-1]<<")="<<"("<<cp[i].fi<<","<<cp[i].se<<")"<<endl;
    }
    //ここからdp
    //dp[i][W]:i番目までのペアを使ってW以下に合計を抑える場合の相方の合計の最小値
//    REP(i,0,children) fill(dp[i], dp[i]+X[n]+1, 0);
    fill(dp[0], dp[0]+X[n]+5, 0);
    REP(i,1,children) {
        REP(w,0,X[n]) {
//            if (cp[i].fi <= w && cp[i].se <= w) { //どちらでも入れられる
//                dp[i][w] = min(dp[i-1][w-cp[i].fi] + cp[i].se, dp[i-1][w-cp[i].se] + cp[i].fi);
//            } else if (cp[i].fi <= w) {
//                dp[i][w] = dp[i-1][w-cp[i].fi] + cp[i].se;
//            } else if (cp[i].se <= w) {
//                dp[i][w] = dp[i-1][w-cp[i].se] + cp[i].fi;
//            } else {
//                dp[i][w] = INF;
//            }
            dp[i][w] = INF;
            if (cp[i].fi <= w && dp[i-1][w-cp[i].fi] != INF) {
                dp[i][w] = min(dp[i][w], dp[i-1][w-cp[i].fi]+cp[i].se);
            }
            if (cp[i].se <= w && dp[i-1][w-cp[i].se] != INF) {
                dp[i][w] = min(dp[i][w], dp[i-1][w-cp[i].se]+cp[i].fi);
            }
        }
    }
//    if (n==1) {
//        REP(i,1,children) {
//            REP(w,0,X[n]) {
//                cerr<<dp[i][w]<<"\t";
//            }
//            cerr<<endl;
//        }
//    }
    if (dp[children][X[n]] >= INF) {
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    } else {
        return mp(X[n],dp[children][X[n]]);
    }
}

signed main(void) {
    cin>>N;
    X[1]=1;
    REP(i,2,N) {
        cin>>P[i];
        C[P[i]].pb(i);
    }
    REP(i,1,N) cin>>X[i];
    solve(1);
    cout << "POSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 37376
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

bool f1(pint p1, pint p2){
	return p1.second >= p2.second;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;	cin>>n;
	int i,j;
	vector<pint> v1(100001),v2(100001);
	for(i=1;i<=n;i++){
		int temp;	cin>>temp;
		if(i%2==0){
			v1[temp].second=temp;	v1[temp].first++;
		}
		else{
			v2[temp].second=temp;	v2[temp].first++;
		}
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());

	if(v1[100000].second == v2[100000].second){
		cout<<min(n-v1[100000].first-v2[99999].first, n-v1[99999].first-v2[100000].first);
	}
	else{
		cout<<n-v1[100000].first-v2[100000].first;
	}

	return 0;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input())
n,*a = [int(i) for i in readline().split()]
s = read().split()

ans = ""
ok = 1

d = {"AB":0,"BC":1,"AC":2}
d2 = "ABC"

if sum(a) >= 3 or sum(a) <= 1:
    for i in s:
        v = d[i]
        w = (v+1)%3
        if a[w] < a[v]: v,w = w,v
        a[v] += 1
        a[w] -= 1
        ans += d2[v]
        if a[w] < 0: ok = 0
    
        #print(i,a,d2[v])
    if ok:
        print("Yes")
        print(*ans,sep="\n")
    else:
        print("No")


#d = {"AB":0,"BC":1,"AC":2}
#d2 = "ABC"

else: # (1,1,0) or (2,0,0)型
    for idx,c in enumerate(s):
        v = d[c]
        w = (v+1)%3
        
        if a[v]==1 and a[w]==1 and idx<n-1 and s[idx+1] != c:#先読み
            vv = d[s[idx+1]]
            ww = (vv+1)%3
            r = [0]*3
            r[v] += 1; r[w] += 1; r[vv] += 1; r[ww] += 1
            vv = r.index(2)
            ww = (vv+1)%3 if vv==v else (vv-1)%3
            a[vv] += 1
            a[ww] -= 1
            ans += d2[vv]
            if a[ww] < 0: ok = 0
        else: 
            if a[w] < a[v]: v,w = w,v
            a[v] += 1
            a[w] -= 1
            ans += d2[v]
            if a[w] < 0: ok = 0
        
        #print(a,c,ans[-1])
        
    if ok:
        print("Yes")
        print(*ans,sep="\n")
    else:
        print("No")








Measured memory_bytes: 17956
A, B, C, D = map(int, input().split())


def waru(a, b):
    if a % b == 0:
        return (a//b)
    else:
        return (a//b)+1


ao_win = waru(A, D)
taka_win = waru(C, B)
if ao_win >= taka_win:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long calc(long long c) {
    long long x = 0;
    for (long long i = 1; i < c; i++) {
        x += i;
    }
    return x;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> box(n + 1, 1);
    box[1] = -1;
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        if (box[x] < 0) {
            box[x]++;
            if (box[y] < 0) {
                box[y]--;
            } else {
                box[y]++;
                box[y] *= -1;
            }
        } else if(box[x] > 0) {
            box[x]--;
            if (box[y] < 0) {
                box[y]--;
            } else {
                box[y]++;
            }
        }
    }
    int c = 0;
    for (const int& b : box) {
        if (b < 0) {
            c++;
        }
    }
    cout << c << endl;
}


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


int main() {
  int N, Q;
  ll K;
  cin >> N >> K >> Q;
  vector<int> cnt(N);
  for (int i = 0; i < Q; ++i) {
    int ai;
    cin >> ai;
    ++cnt.at(ai - 1);
  }
  for (int i = 0; i < N; ++i) {
    if (K - (Q - cnt.at(i)) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

void dfs(int u, int p, vector<vector<int>> &graph, vector<int> &depth){
	depth[u] = depth[p]+1;

	for(int v: graph[u]){
		if(v==p) continue;
		dfs(v, u, graph, depth);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;
	vector<vector<int>> graph(n);
	for(int i=0; i<n-1; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<int> depth(n);
	dfs(0, -1, graph, depth);

	vector<int> ans(n);

	vector<int> ve, vo;

	for(int i=0; i<n; i++){
		if(depth[i]%2){
			ve.push_back(i);
		} else {
			vo.push_back(i);
		}
	}
	dbg(depth);

	if(ve.size()>vo.size()){
		swap(ve, vo);
	}

	vector<bool> used(n+1);
	if(ve.size()<=n/3){
		int m = 3;
		for(int v: ve){
			ans[v] = m;
			used[m] = true;
			m+=3;
		}

		int k=0;
		for(int i=1; i<=n; i++){
			if(!used[i]){
				ans[vo[k]] = i;
				k++;
			}
		}
	} else {
		for(int i=0; 3*i+1<=n; i++){
			ans[ve[i]] = 3*i+1;
			used[ve[i]] = true;
		}
		for(int i=0; 3*i+2<=n; i++){
			ans[vo[i]] = 3*i+2;
			used[vo[i]] = true;
		}
		int k = 1;
		for(int i=0; i<n; i++){
			if(!used[i]){
				ans[i] = 3*k;
				k++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 23124
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vll data(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    vll sum(N, 0);
    ll ans = 0, suma = 0;
    for (int i = 0; i < N; i++) {
        suma += data[i];
        suma %= mod;
        sum[i] = suma;
    }
    for (int i = 0; i < N - 1; i++) {
        ll b = sum[N - 1] - sum[i];
        if (b < 0) {
            b += mod;
        }
        ll a = data[i] * b % mod;
        ans += a;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6336
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

using Graph = vector<vector<ll>>;

void solve(ll N, ll M, std::vector<ll> A, std::vector<ll> B) {
  Graph G(N);

  rep(i, M) {
    ll a = A.at(i);
    ll b = B.at(i);
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  vector<ll> r(N, -1);
  vector<ll> dist(N, -1);
  queue<ll> q;

  dist.at(0) = 0;
  q.push(0);

  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    for (ll nv : G.at(v)) {
      if (dist[nv] != -1) continue;

      dist[nv] = dist[v] + 1;
      r[nv] = v;
      q.push(nv);
    }
  }

  for (int i = 1; i < N; i++) {
    if (r.at(i) == -1) {
      no();
      return;
    }
  }

  yes();
  for (int i = 1; i < N; i++) {
    cout << r.at(i) + 1 << endl;
  }

  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  std::vector<ll> A(M);
  std::vector<ll> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;  // 0-indexed
    B[i]--;  // 0-indexed
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 19948
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl
const int M = 1e5+1;
int s, n, i, j, si, pi;
long long dp[M];

int main ()
{
    cin >> n >> s;
    for(i = 1; i <= n; i++)
    {
        cin >> si >> pi;
        for(j = s; j >= si; j--)
        {
            dp[j] = max(dp[j], dp[j-si] + pi);
        }
    }
    cout << dp[s] << endl;
}


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

int main(){
  int N,M;
  cin >> N;
  string s[N];
  for (int i=0;i<N;i++){
    cin >> s[i];
  }
  cin >> M;
  string t[M];
  for (int i=0;i<M;i++){
    cin >> t[i];
  }
  int ans=0;
  for(string p:s){
    int f=0;
    for (string q:s){
      if (p==q){
        f++;
      }
    }
    for (string q:t){
      if (p==q){
        f--;
      }
    }
    ans=max(ans,f);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0';
  int d=s[3]-'0';
  // bit全探索始め
  for(int i=0;i<8;i++){
    int sum=0;
    sum=sum+a;
    if(i&(1<<0)){    
      sum=sum+b;
    }
    else{
      sum=sum-b;
    }
    if(i&(1<<1)){    
      sum=sum+c;
    }
    else{
      sum=sum-c;
    }
    if(i&(1<<2)){    
      sum=sum+d;
    }
    else{
      sum=sum-d;
    }
    if(sum==7){
      cout << a;
      if(i&(1<<0)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << b;
      if(i&(1<<1)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << c;
      if(i&(1<<2)){
        cout << '+';
      }
      else{
        cout << '-';
      }
      cout << d << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
n = gets.chop.to_i
line = []
cnt = 0
n.times do
    if cnt == 3
        puts 'Yes'
        return
    end
    line = gets.chop.split.map(&:to_i)
    if line[0] == line[1]
        cnt += 1
    else
        cnt = 0
    end
end

if cnt >= 3
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 14308