akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	//0140 start
	//0200 end
	//0430 restart
	//0442 sample match WA
	//0509 WA * 2
	//0920 WA * 2
	//0921 AC
	
	class C{
		int count, rest;
		ArrayList<Integer> list;
		public C(int count, int rest) {
			this.count = count;
			this.rest = rest;
			this.list = new ArrayList<Integer>();
		}
		
		private void sort(){
			Collections.sort(this.list);
		}
		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-- > 0){
			ArrayList<Integer> input = new ArrayList<Integer>();
			int inputnum = sc.nextInt();
			while(inputnum != 0){
				input.add(inputnum);
				inputnum = sc.nextInt();
			}
			
			ArrayList<C> rooms = new ArrayList<C>();
			int first = input.get(0);
			int nowroom = 0;
			rooms.add(new C(0, first));
			for(int i = 1; i < input.size(); i++){
				int nownum = input.get(i);
				if(nownum < 0){
					//nownumのcount を探す
					int find = rooms.get(nowroom).count + nownum;
					for(int j = nowroom - 1; j >= 0; j--){
						if(rooms.get(j).count == find){
							//つなげる
							rooms.get(nowroom).rest--;
							rooms.get(nowroom).list.add(j + 1);
							
							//反対側
							rooms.get(j).rest--;
							rooms.get(j).list.add(nowroom + 1);
							break;
						}
					}
					
					//次のnowroomを探す
					for(int j = nowroom; j >= 0; j--){
						if(rooms.get(j).rest > 0){
							nowroom = j;
							break;
						}
					}
				}
				else{
					int nextcount = rooms.get(nowroom).count + 1;
					rooms.add(new C(nextcount, nownum));
					int nextroomid = rooms.size() - 1;
					
					//つなげる
					rooms.get(nowroom).rest--;
					rooms.get(nowroom).list.add(nextroomid + 1);
					
					//反対側
					rooms.get(nextroomid).rest--;
					rooms.get(nextroomid).list.add(nowroom + 1);
					
					for(int j = nextroomid; j >= 0; j--){
						if(rooms.get(j).rest > 0){
							nowroom = j;
							break;
						}
					}
				}
			}
			
			for(int i = 0; i < rooms.size(); i++){
				rooms.get(i).sort();
			}
			
			//print
			for(int i = 0; i < rooms.size(); i++){
				System.out.print((i + 1));
				for(int j = 0; j < rooms.get(i).list.size(); j++){
					System.out.print(" " + rooms.get(i).list.get(j));
				}
				System.out.println();
			}
		}
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  int ans = 1;
  for(int i=2; i * i <= x; i++) {
    for(int j = 2; pow(i, j) <= x; j++) {
      ans = max(ans, pow(i, j));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let x: i32 = read();

    let mut ways = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if i*500+j*100+k*50 == x {
                    ways += 1;
                }
            }
        }
    }
    println!("{}", ways);
}


Measured memory_bytes: 4352
/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/

#include <bits/stdc++.h>

#define pb push_back
#define MP make_pair
#define ALL(r) (r).begin(),(r).end()

typedef long long int ll;

#define FOR(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define FORN(i,m,n) for(ll i=(ll)(m-1) ; i >= (ll) (n) ; --i )

#define RUN_FAST ios::sync_with_stdio(false);

using namespace std;



void solve()
{
    ll a,b,c,d,m,n,p,q,r,x,y,z,aa,bb,cc,dd; //variable
    ll i,j,k,l; //pointer
    ll cnt=0,cnt1=0,cnt2=0,cnt3=0,sum=0,mx=LLONG_MIN,mn=LLONG_MAX; //counter
    ll flag=0,flag2=0; //flag
    vector <ll> vec1,vec2,vec3;
    string s1,s2,s3;

    //PULOK SAHA
    //BMO

    cin >>n >> s1;

    if(n%2)
        cout << "No\n";
    else
    {
        x=n/2;

        FOR(i,0,x)
        {
            s2.pb(s1[i]);
        }

        FOR(i,x,n)
        {
            s3.pb(s1[i]);
        }

        if(s3==s2)
        cout << "Yes\n";
        else
        cout << "No\n";
    }

}

int main()
{
    RUN_FAST
    //PULOK SAHA
    //BMO

    ll t=1;//test case

    //cin >> t;
    while(t--)
    {
        solve();
    }

    return 0;
}






//PULOK SAHA

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
//AtCoder解説動画(https://www.youtube.com/watch?v=TdR816rqc3s&feature=youtu.be)からもらった
// (https://atcoder.jp/contests/abc157/submissions/10472433)
struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {} //このコロンってなんですか
	int find(int x){
		if (d[x] < 0) return x; //x:根
		return d[x] = find(d[x]);//x:子 -> xの親の根を返す
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);//根同士をくっつける。
		if ( x ==  y) return false ; 
		/*連結成分が一致してるんだったらfalse返す。
			minimum spanning tree (クラスカル法と言うのをやるときに、くっつけたかどうかを取れると嬉しい.
			chmin/chmaxみたいなノリかな
		 */
		if ( d[x] > d[y]) swap(x,y);//xの方が大きいようにする（ただしサイズは負デモっているので不等号が逆）
		d[x] += d[y] ; //xにyをくっつける.
		d[y] = x;
		return true; 
	}
	bool same(int x, int y) { return find(x) == find(y) ; }
	int size(int x) { return -d[find(x)];}
};
int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> x(m), y(m), z(m);
	// TODO 要素　n じゃなくて　m えむ　えむ 
	rep(i,m){
		cin >> x[i] >> y[i] >> z[i];
		--x[i], --y[i];
	}

	UnionFind uf(n);
	rep(i,m){
		uf.unite(x[i], y[i]);
	}

	map<int, bool> seen;
	int ans = 0;
	rep(i,n){
		if(seen[uf.find(i)]) continue;
		seen[uf.find(i)] = true;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<string, int> res;
int MOD = 998244353;
int solve(string s){
    if (s.size() == 1){
        if (s[0] == '1') return 2;
        return 1;
    }
    if (res.count(s)) return res[s];
    string a = "", b="";
    int ret = 0;
    for (int i=1; i < s.size(); i++){
        a += s[i];
    }
    string q = "";
    q += s[0];
    ret += solve(q) * solve(a);
    ret %= MOD;
    vector<string> suff(s.size());
    for (int i=s.size() - 1; i >= 0; i--){
        b += s[i];
        suff[i] = b;
    }
    for (int i=1; i < s.size(); i++){
        string p;
        for (int j=0; j < i; j++) p += '1';
        for (int M=0; (M+1)*i <= s.size(); M++){
            for (int k=M*i; k < (M+1)*i; k++){
                if (s[k] == '0') p[k%i] = '0';
            }
            if (M > 0){
                //cout << M << " " << s << endl;
                if ((M+1)*i == s.size()){
                    ret += solve(p);
                    ret %= MOD;
                    break;
                }
                ret += solve(p) * solve(suff[(M+1)*i]);
                ret %= MOD;
            }
        }
    }
    res[s] = ret;
    return ret;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    cout << solve(s);
    return 0;
}





Measured memory_bytes: 12196
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
using namespace std;
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
using P = pair<int,int>;

double MAX(double A,double B){
    return (A > B? A : B);
}

int main(){
    double N,t;
    cin >> N >> t;
    vector<double> X(N),H(N);
    rep(i,N) cin >> X[i] >> H[i];
    double ans = 0.0;
    rep(i,N) ans = MAX(ans,t*H[i]/X[i]);

    cout << setprecision(15) << ans <<endl;
    
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b == c+d){
  	cout << "Balanced" << endl;
  }
  else if (a+b > c+d){
  	cout << "Left" << endl;
  }
  else {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define first f
#define second s
#define pb push_back
#define mp make_pair
#define eb emplace_back // is faster than push_back
#define all(cont) cont.begin(), cont.end()
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define clr(x) x.clear()
#define gcd(x, y) __gcd(x, y) // atentie la cazul x = 0 y = 0
#define lsb(x) __builtin_ffs(x)
#define no_bits(x) __builtin_popcount(x)
#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<'>'<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<'>'<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

using namespace std;

//shortcuts data types
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
//DS
typedef set<int> seti;
typedef multiset<int> mseti;
typedef map<int, int> mpii;
//and <=> &&, or <=> ||)

int main() {
	//fast i/o
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//sol
	string s;
	cin >> s;
	bool ok = 1;
	for (int i = 1; i < 4; ++i)
		if (s[i] == s[i - 1])
			ok = 0;
	if (ok)
		cout << "Good";
	else
		cout << "Bad";

	system("pause");
	return 0;
}


Measured memory_bytes: 504
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    class Program
    {

        static void Main(string[] args)
        {
            while (true)
            {
                int N = int.Parse(Console.ReadLine());

                if(N == 0)
                {
                    break;
                }

                double x = 0;

                int ans = 0;

                for(int n = 1; n < N; n++)
                {
                    x = (double)(N - n * (n + 1) / 2) / (n + 1);
                    
                    int x_sub = (int)x;

                    if (x > 0 && x - (double)x_sub == 0)
                    {
                        ans++;
                    }
                }

                Console.WriteLine(ans);

            }
            
        }
    }
}


Measured memory_bytes: 15940
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    int w;
    unordered_set<int> us;
    for(int i= 0 ; i< n;i++ ) {
        cin>>w;
        us.insert(w);
    }
    int pos = x + 1;
    int neg = x - 1;
    bool turn = false;
    int findthis = x;
    while(1) {
        if(us.find(findthis) == us.end()) {
            cout<< findthis;
            break;
        }
        else{
            if( turn) {
                if(us.find(pos)== us.end()){
                    cout<< pos ;
                    break;
                }
                pos ++;turn = false;
            }
            else {
                if(us.find(neg) == us.end()){
                    cout << neg;
                    break;
                }
                neg --;turn = true;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3580
string_n = input()
string_n = '0' + string_n
len_n = len(string_n)
dp = [[0, 0] for _ in range(len_n + 1)]

for i in range(len_n):
    for j in range(2):
        if j == 0:
            dp[i + 1][j] = min(dp[i]) + int(string_n[i])
        else:
            dp[i + 1][j] = min(dp[i][0] + 1 + 10 - int(string_n[i]), dp[i][1] + 9 - int(string_n[i]))

print(min(dp[len_n]))

Measured memory_bytes: 138592
#include <iostream>
#include <vector>
#include <cassert>

static const int INF = 1 << 30;

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

int computeDP(int i, std::vector<int> &dp, std::vector<bool> &finished,
              const std::vector<std::vector<int>> &parentList) {
  assert(1 <= i and i < dp.size());
  if (finished[i])
    return dp[i];
  if (parentList[i].empty()) {
    dp[i] = 0;
    finished[i] = true;
    return dp[i];
  }
  for (int j : parentList[i]) {
    chmax(dp[i], computeDP(j, dp, finished, parentList) + 1);
  }
  finished[i] = true;
  return dp[i];
}

int main() {
  // Input
  int numNode;
  int numEdge;
  std::cin >> numNode >> numEdge;
  assert(2 <= numNode and numNode <= 1.0e+5);
  assert(1 <= numEdge and numEdge <= 1.0e+5);
  std::vector<std::vector<int>> childList(1 + numNode);
  std::vector<std::vector<int>> parentList(1 + numNode);
  for (int e = 1; e <= numEdge; ++e) {
    int fromNode;
    int toNode;
    std::cin >> fromNode >> toNode;
    assert(1 <= fromNode and fromNode <= numNode);
    assert(1 <= toNode and toNode <= numNode);
    childList[fromNode].push_back(toNode);
    parentList[toNode].push_back(fromNode);
  }

  // Initialization
  std::vector<int> dp(1 + numNode, -INF);
  std::vector<bool> finished(1 + numNode, false);

  // DP main
  for (int i = 1; i <= numNode; ++i)
    computeDP(i, dp, finished, parentList);

  // Output
  int result = -1;
  for (auto v : dp)
    chmax(result, v);
  std::cout << result << std::endl;

  return 0;
}


Measured memory_bytes: 19072
#include<iostream>
using namespace std;
int main(){
    int n,a;
    cin>>n;
    int R[n];
    for(int i=0;i<n;i++) cin>>R[i];
    int minv=R[0],maxv=-1000000000;
    for(int j=1;j<n;j++){
        a=R[j]-minv;
        if(R[j]<minv) minv=R[j];
        if(a>maxv) maxv=a;
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3884
#include <numeric>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; for (auto& e : a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; for (auto& e : a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; for (auto& r : a) { for (auto& e : r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; for (auto& e : a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)

using i64 = long long;

template<typename T>
using Pair = array<T, 2>;

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

    i64 n;
    while (cin >> n) {
        vector<int> s(1<<n);
        priority_queue<int> q;
        map<int, vector<int>> id_by_s;
        forn(i, 1<<n) {
            cin >> s[i];
        }

        sort(s.begin(), s.end(), greater<int>());
        forn(i, s.size()) {
            id_by_s[s[i]].push_back(i);
        }

        vector<int> c(s.size());
        c[0] = n;
        forr(i, 1, s.size()) {
            c[i] = n - (int)floorl(log2l(i)) - 1;
        }

        bool ok = true;
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> tb;
        id_by_s[s[0]].pop_back();
        tb.emplace(0, 0);

        for (auto it = id_by_s.rbegin(); it != id_by_s.rend(); ++it) {
            logv(it->second);
            vector<pair<int, int>> updates;
            for (auto i : it->second) {
                if (tb.empty()) {
                    ok = false;
                    break;
                }
                auto tc = tb.top();
                logss(s[tc.second], it->first);
                if (s[tc.second] <= it->first) {
                    ok = false;
                    break;
                }
                tb.pop();
                tc.first++;
                if (tc.first != n) {
                    tb.push(tc);
                    updates.emplace_back(tc.first, i);
                }
            }
            if (!ok) {
                break;
            }
            for (auto& upd : updates) {
                tb.push(upd);
            }
        }


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


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

using namespace  std;
const int N=1e5+5;

int n, k , h[N];
int brain[N];

int check(int i)
{
    if(i==n-1) return 0;
    if(i>n-1) return 1e9;

    if(brain[i]!=-1) return brain[i];
    int ans=1e9;
    for(int j=1 ; j<=k ; j++){
        ans=min(ans , abs(h[i]-h[i+j])+ check(i+j));
    }

    brain[i]=ans;
    return brain[i];
}

int main()
{
    scanf("%d %d" , &n , &k);

    for(int i=0 ; i<n ;i++)scanf("%d", &h[i]);

    memset(brain , -1 , sizeof brain);

    printf("%d\n" , check(0));




    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	REP(i, n) {
		if (i < k) ans += x;
		else ans += y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <stack>
using namespace std;
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    int a[n], b[m];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0; i<m; i++) {
        cin >> b[i];
    }
    int restTime = k;
    int cnt = 0, maxCnt = 0;
    stack<int> stA, stB;
    for (int i=0; i<n; i++) {
        if (a[i] <= restTime) {
            restTime -= a[i];
            stA.push(a[i]);
        } else {
            break;
        }
    }
    for (int j=0; j<m; j++) {
        if (b[j] <= restTime) {
            restTime -= b[j];
            stB.push(b[j]);
        } else {
            cnt = stA.size() + stB.size();
            maxCnt = max(maxCnt, cnt);
            if (stA.empty()) {
                break;
            } else {
                restTime += stA.top();
                stA.pop();
                j--;
            }           
        }
    }
    cnt = stA.size() + stB.size();
    maxCnt = max(maxCnt, cnt);
    cout << maxCnt << endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> field(h);
    rep(i, h) cin >> field[i];

    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;

    dist[0][0] = 0;
    que.push(make_pair(0, 0));

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

    while (!que.empty()) {
        pair<int, int> from = que.front();
        que.pop();

        rep(i, 4) {
            int ny = dy[i] + from.first;
            int nx = dx[i] + from.second;

            if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if (field[ny][nx] == '#') continue;
            if (dist[ny][nx] != -1) continue;

            dist[ny][nx] = dist[from.first][from.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }

    int cnt = 0;
    rep(i, h) rep(j, w) {
        if (field[i][j] == '#') cnt++;
    }

    int ans = h * w - cnt - dist[h - 1][w - 1] - 1;

    if (dist[h - 1][w - 1] == -1) cout << -1 << endl;
    else cout << ans << endl;
    
    return 0;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};



int main(){
	int N, A, B;
	cin >> N >> A >> B;
	int sum = 0;
	for(int a = 0; a <= 1; a++){
	for(int i = 0; i <= 9; i++){
		for(int j = 0; j <= 9; j++){
			for(int k = 0; k <= 9; k++){
				for(int l = 0; l <= 9; l++){
					if(a * 10000 + i * 1000 + j * 100 + k * 10 + l > N) continue;
					if(A <= a + i + j + k + l && a + i + j + k + l <= B) sum += a * 10000 + i * 1000 + j * 100 + k * 10 + l;
				}
			}
		}
	}}
	cout << sum << endl;
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1000000007ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int main() {
    int n;
    scanf("%d", &n);
    int a, b, c;
    // a...まだ値を書き換えていない場合の最大公約数 b...すでに値を書き換えた場合の最大公約数
    // c...最初の一つを書き換えた場合の最大公約数
    scanf("%d", &a);
    b = a;
    c = 0;
    rp(i, 0, n-1) {
        int m;
        scanf("%d", &m);
        //bの更新...この値mを書き換える場合はa,いままでに出た値を書き換えた場合はgcc(b, m)
        //aの更新...gcc(a, m)
        b = max({a, gcc(b, m)});
        a = gcc(m, a);
        c = gcc(m, c);
    }
    printf("%d", max({b, c}));
    return 0;
}

Measured memory_bytes: 256
def init():
  global top
  top = -1

def isEmpty():
  global top
  return top == -1

def isFull():
  global top, MAX
  return top >= MAX

def push(x):
  global top, s
  if isFull():
    return False
  s[top] = x
  top += 1


def pop():
  global top, s
  if isEmpty():
    return False
  top -= 1
  return s[top]


def calc(i_1, i_2, op):
  if op == '+':
    return i_1 + i_2
  elif op == '-':
    return i_1 - i_2
  else:
    return i_1 * i_2

data = list(map(str, input().split()))
top = 0
MAX = 100
s = [0 for i in range(MAX)]
for i in data:
  if i == '+' or i == '*' or i == '-':
    a = pop()
    b = pop()
    push(calc(int(b), int(a), i))
  else:
    push(i)
print(s[0])



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

int main(){
    double a, b, h, m;
    double zi, hun, kaku, result;
    double pi = 3.141592653589793238;
    cin >> a >> b >> h >> m;

    hun = m*6;
    zi = (h + m/60)*30;

    kaku = abs(hun - zi);

    cout << fixed << setprecision(100) << sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(kaku /180.0 *pi)) << endl;
}

Measured memory_bytes: 4212
N = gets.to_i
A = gets.split.map(&:to_i)

memo = Array.new(N+1){ 0 }
ans  = []

N.downto(1) do | i |
  hop = 1
  cnt = 0
  # ボールが入っている箱を数え, cntに加算.
  # e.g. i=3なら3, 6, 9...の箱を調べる.
  while hop * i <= N
    cnt += memo[hop * i - 1]
    hop += 1
  end
  #
  if cnt % 2 != A[i - 1]
    ans << i
    memo[i - 1] += 1
  end
end
puts ans.size
puts ans.join(' ') if ans.size != 0

Measured memory_bytes: 22084
#include<stdio.h>
const int N = 300;
const int M = 300;
int main()
{
	int n, m;
	while(scanf("%d %d",&n,&m))
	{
		if(n == 0 && m == n)
		{
			break;
		}
		for(int i = 0; i < m; i++)
		{	
		    printf("#");
	    }
	    printf("\n");
	    for(int i = 0; i < n-2; i++)
			{
				printf("#");
				for(int j = 0; j < m-2; j++)
				{
					printf(".");
				}
				printf("#");
				printf("\n");
			}
	    for(int i = 0;i < m; i++)
		{
			printf("#");
		}
		printf("\n");
		printf("\n");
	}
		return 0;
} 


Measured memory_bytes: 2612
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  while (a >= b && k > 0) {
    b *= 2;
    k--;
  }

  while (b >= c && k > 0) {
    c *= 2;
    k--;
  }

  if (a < b && b < c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int S[200000], n, R[200000]; bool used[200000];
int W[200000];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> S[i]; S[i] %= n; }
	for (int i = 0; i < n; i++) { R[i] = (i + S[i]) % n; }
	for (int i = 0; i < n; i++) {
		if (used[i] == true)continue;
		int c = i;
		vector<int>vec, vec2;
		while (true) {
			if (used[c] == true)break;
			W[c]++; if (W[c] >= 3)break;
			if (W[c] == 2)vec.push_back(c);
			if (W[c] == 1)vec2.push_back(c);
			c = R[c];
		}
		for (int j = 0; j < vec.size(); j++) {
			used[vec[j]] = true;
		}
		for (int j = 0; j < vec2.size(); j++)W[vec2[j]] = 0;
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) { if (used[i] == true)cnt++; }
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
int main(){
    long int a , b, n, c , d;
    scanf("%li %li %li", &a, &b, &n);
    c = a - n;
    if(c <= 0){
        int l = 0;
        d = b + c;
        if( d <= 0 ) d= 0;
        printf("%li %li",l , d);
    }
    else{
        printf("%li %li", c , b);
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,n,i,j,k,b[2001]={1};
main(){
  for(cin>>n;i++<n;){
    cin>>a;
    for(k=2001;k+1;--k)b[k]?b[k+a]=1:0;
  }
  for(cin>>n;j++<n;cout<<(b[i]?"yes\n":"no\n"))cin>>i;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;

int n, a[3001];

int main(){
	int f = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		f += a[i]-1;
	}
	cout << f << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
#define LL long long
#define db(x) cout<<#x<<"="<<x<<endl
LL a,b,c,d;
int main() {
	cin>>a>>b;
	c=1;
	while(c<b) {
		c=c-1+a;
		++d;
	}
	cout<<d;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string s;
  cin >> N >> s;
 
  int Rcount = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'R') {
      Rcount++;
    }
  }
  
    int Bcount = 0;
  for (int j = 0; j < s.size(); j++) {
    if (s.at(j) == 'B') {
      Bcount++;
    }
  }
  
  if (Rcount > Bcount){
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
signed main(){
    int in[3];
    cin>>in[0]>>in[1]>>in[2];
    sort(in,in+3);
    if(in[0]%2==1&&in[1]%2==1&&in[2]%2==1)cout<<in[0]*in[1]<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int H, W;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int cnt[1010][1010];
char A[1010][1010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;

    queue<pii> q;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
            cnt[i][j] = inf;
            if(A[i][j] == '#') cnt[i][j] = 0, q.push({i, j});
        }
    }
    int ans = 0;
    while(!q.empty()){
        pii p = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int rh = p.first + dx[i];
            int rw = p.second + dy[i];
            if(0 <= rh && rh < H && 0 <= rw && rw < W && cnt[rh][rw] > cnt[p.first][p.second] + 1){
                q.push({rh, rw});
                cnt[rh][rw] = cnt[p.first][p.second] + 1;
                chmax(ans, cnt[rh][rw]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13456
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    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):
    return " ".join(map(str,x))

n,x = m()
l = l()

co = 0

ans = 1

for i in range(n):
    co += l[i]
    if co <= x:
        ans += 1

print(ans)



Measured memory_bytes: 3444
import java.util.Scanner;


public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine())
		{
			String[] s = sc.nextLine().split("[\\s]+");

			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);

			int x = gcd(a,b);
			int y = lcm(a,b);
			System.out.println(x +" "+ y);
		}
		/*



			*/
	}
	
	 private static int gcd(int m, int n)
     {
         if ((m == 0) || (n == 0)) return 0;

         while (m != n)
         {
             if (m > n) m = m - n;
             else n = n - m;
         }
         return m;
     }

     private static int lcm(int m, int n)
     {
         if ((m == 0) || (n == 0)) return 0;
         return ((m / gcd(m, n) * n));
     }
}

Measured memory_bytes: 17208
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::vector<int> num_children(s.length(), 0);

    for (int direction = 0; direction < 2; direction++) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == 'R') {
                count++;
            } else {
                num_children[i - 1] += (count + 1) / 2;
                num_children[i] += count / 2;
                count = 0;
            }
        }

        std::reverse(num_children.begin(), num_children.end());
        std::reverse(s.begin(), s.end());

        for (int i = 0; i < s.length(); i++) {
            s[i] = (s[i] == 'R') ? 'L' : 'R';
        }
    }

    for (auto c : num_children) {
        std::cout << c << " ";
    }

    putchar('\n');
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int Res=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') f=(ch=='-'?-f:f),ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res*f;
}
int N;
int A[4005],B[2005],W[2005],Col[4005];
int F[2005][2005],NB[4005][2005],NW[4005][2005];
int main()
{
	N=read();
	for (int i=1;i<=2*N;i++){
		char S[5];scanf("%s",S);Col[i]=S[0]=='B'?1:0;A[i]=read();
		if (S[0]=='B') B[A[i]]=i;else W[A[i]]=i;
	}
	for (int i=1;i<=2*N;i++){
		for (int j=0;j<=N;j++){
			NB[i][j]=NB[i-1][j]+(A[i-1]>j&&Col[i-1]==1);
			NW[i][j]=NW[i-1][j]+(A[i-1]>j&&Col[i-1]==0);
		}
	}
	memset(F,63,sizeof F);
	F[0][0]=0;
	for (int i=0;i<=N;i++){
		for (int j=0;j<=N;j++){
			if (i) F[i][j]=min(F[i][j],F[i-1][j]+NB[B[i]][i-1]+NW[B[i]][j]);
			if (j) F[i][j]=min(F[i][j],F[i][j-1]+NB[W[j]][i]+NW[W[j]][j-1]);
		}
	}
	printf("%d\n",F[N][N]);
	return 0;
}

Measured memory_bytes: 78720
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
int n,f[N];
ll s[N],a,b;

int main() {
	cin>>n>>a>>b;
	if (a>b) swap(a,b);
	REP(i,1,n) cin>>s[i];
	REP(i,3,n) if (s[i]-s[i-2]<a) {
		return puts("0"),0;
	}
	f[0] = 1;
	int l=0, r=0;
	s[n+1] = 2e18;
	REP(i,1,n+1) {
		while (r<i-1&&s[i]-s[r+1]>=b) ++r;
		if (l<=r) f[i]=(f[r]-(l?f[l-1]:0))%P;
		f[i] = (f[i]+f[i-1])%P;
		if (i>1&&s[i]-s[i-1]<a) l=i-1;
	}
	int ans = (f[n+1]-f[n])%P;
	if (ans<0) ans+=P;
	printf("%d\n",ans);
}









Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include <iomanip>

using namespace std;

int main() {
	int64_t N, K;
	cin >> N >> K;
	vector<int64_t> p(N);
	for (int64_t i = 0; i < N; i++) {

		cin >> p[i];

	}
	int64_t max_index = 0,max=0;
	for (int64_t i = 0; i < K; i++) {
		max += p[i];
	}
	int64_t compare = max;
	for (int64_t i = 0; i < N - K ; i++) {
		if (max < compare - p[i] + p[i + K]) {
			max = compare - p[i] + p[i + K];
		}
		compare= compare - p[i] + p[i + K];
	}
	cout << fixed << setprecision(15) << double(max + K) / 2.0;
	
	return 0;

}

Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] whn = scanner.nextLine().split(" ", 3);
        int w = Integer.parseInt(whn[0]);
        int h = Integer.parseInt(whn[1]);
        int n = Integer.parseInt(whn[2]);

        boolean[][] black = new boolean[w][h];
        for (int i = 0; i < n; i++) {
            String[] xya = scanner.nextLine().split(" ", 3);
            int x = Integer.parseInt(xya[0]);
            int y = Integer.parseInt(xya[1]);
            int a = Integer.parseInt(xya[2]);
            switch (a) {
                case 1:
                    for (int j = 0; j < x; j++) {
                        for (int k = 0; k < h; k++) {
                            black[j][k] = true;
                        }
                    }
                    break;
                case 2:
                    for (int j = x; j < w; j++) {
                        for (int k = 0; k < h; k++) {
                            black[j][k] = true;
                        }
                    }
                    break;
                case 3:
                    for (int j = 0; j < w; j++) {
                        for (int k = 0; k < y; k++) {
                            black[j][k] = true;
                        }
                    }
                    break;
                case 4:
                    for (int j = 0; j < w; j++) {
                        for (int k = y; k < h; k++) {
                            black[j][k] = true;
                        }
                    }
                    break;
            }
        }

        int whiteNum = 0;
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                if (!black[i][j]) {
                    whiteNum++;
                }
            }
        }
        System.out.println(whiteNum);
    }
}


Measured memory_bytes: 23124
from math import sqrt, ceil, floor, log10

N = int(input())

min_f = floor(log10(N)) + 1
for A in range(1, ceil(sqrt(N)) + 1):
    if N % A != 0:
        continue
    else:
        B = N // A
        f = floor(max(log10(A), log10(B))) + 1
        if f < min_f:
            min_f = f

print(f)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int p,q,r,a,b,c;
  cin >> p >> q >> r;

  a = p+q;b = q+r,c=p+r;
  int arr[] = {a,b,c};
  sort(arr,arr+3);
  cout << arr[0];


  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int main() {
  int K; cin >> K;
  string ans = "";
  REP(i, K) {
    ans += "ACL";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int n;

    cin >> n;

    cout << n / 3 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    string n;
    cin >> n;
    cout << ((n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3]) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

struct pp {
    string name;
    int time;

    pp(string _name="", int _time=0) : name(_name), time(_time) {}
};

const int LEN = 101010;

pp q[LEN];
int head, tail;

void enqueue(pp x) {
    q[tail] = x;
    tail = (tail+1) % LEN;
}

pp dequeue() {
    pp x = q[head];
    head = (head+1) % LEN;
    return x;
}

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

    int n, lim;
    cin >> n >> lim;
    int time = 0;
    for(int i=0; i<n; ++i) {
        string s;
        int t;
        cin >> s >> t;
        q[i] = pp(s, t);
    } 

    head = 0; tail = n;
    while(head != tail) {
        pp process = dequeue();
        if(process.time <= lim) {
            time += process.time;
            cout << process.name << " " << time << endl;
        }
        else {
            time += lim;
            process.time -= lim;
            enqueue(process);
        }

    }
    
}



Measured memory_bytes: 7152
import sys
input = lambda: sys.stdin.readline().rstrip()

# UnionFind
class FenwickTree:
  def __init__(self,n):
    self.n=n
    self.bit=[0]*(n+1)
  def add(self,i,x):
    i+=1
    while i<=n:
      self.bit[i]+=x
      i+=i&-i
  def sumsub(self,r):
    ans=0
    while r:
      ans+=self.bit[r]
      r-=r&-r
    return ans
  def sum(self,l,r):
    ans=self.sumsub(r)
    if l!=0:ans-=self.sumsub(l)
    return ans

n,q=map(int,input().split())
a=list(map(int,input().split()))
ft=FenwickTree(n)
for i in range(n):ft.add(i,a[i])
for _ in range(q):
  t,a,b=map(int,input().split())
  if t==0:
    ft.add(a,b)
  else:
    print(ft.sum(a,b))

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

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    for(int j=0; j<10; ++j){
	cin >> temp;
	A.push_back(temp);
      }
    while(!A.empty()){
      temp = A.front();
      if(temp>=B.back()) B.push_back(temp);
      else if(temp>=C.back()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.erase(A.begin());
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
    A.clear(); B.clear(); C.clear();
  }
}
      

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100010

struct Node{
    int parent, left, right;
};
Node T[MAX];
int Depth[MAX];

void rec(int u, int p){//深さを求める関数
    Depth[u] = p;
    if(T[u].right != NIL) rec(T[u].right, p);//右の兄弟には同じ深さを
    if(T[u].left != NIL) rec(T[u].left, p + 1);//最も左(子)には自身の深さ+1を
}

void print(int u){
    printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, Depth[u]);
    if(T[u].parent == NIL) printf("root, [");
    else if(T[u].left == NIL) printf("leaf, [");
    else printf("internal node, [");
    for(int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right){
        if(i) cout << ", ";
        printf("%d", c);
    }
    cout << "]" << endl;
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    for(int i = 0; i < n; i++){
        int v, d, c, l;
        cin >> v >> d;
        for(int j = 0; j < d; j++){
            cin >> c;
            if(j == 0) T[v].left = c;//最も左は子
            else T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }

    int r;
    for(int 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: 7796
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int bal[26] = {};
		int ans = -1;
		string s;
		int ind1 = 0;
		for(int i = 0; i < n; i++){
			cin >> s;
			bal[s[0] - 'A']++;
			ind1 = 0;
			for(int j = 0; j < 26; j++){
				if(bal[ind1] < bal[j]){
					ind1 = j;
				}
			}
			int ind2 = (ind1 + 1) % 26;
			for(int j = 0; j < 26; j++){
				if(bal[ind2] < bal[j] && j != ind1){
					ind2 = j;
				}
			}
			if(bal[ind1] > bal[ind2] + (n - i - 1) && ans <= 0){
				ans = i + 1;
			}
		}
		if(ans > 0){
			string ss = "  ";
			ss[0] = 'A' + ind1;
			cout << ss << ans << endl;
		}else{
			cout << "TIE" << endl;
		}
	}
	return 0;
	
}



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

typedef long long ll;
const int N = 500233, mod = 998244353;
int n, m, fac[N], inv[N];
int main() {
  scanf("%d%d", &n, &m);
  if (n < m) swap(n, m);
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    fac[i] = (ll) fac[i - 1] * i % mod;
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  for (int i = 2; i <= n; i++) {
    inv[i] = (ll) inv[i] * inv[i - 1] % mod;
  }
  int pn = fac[n], pm = fac[m], ans = 0;
  for (int i = n - m; i; i--) pn = (ll) pn * (m + 1) % mod;
  for (int i = m; ~i; i--) {
    int coef = (ll) pn * pm % mod * inv[n - i] % mod * inv[m - i] % mod * inv[i] % mod * (i & 1 ? mod - 1 : 1) % mod;
    pn = (ll) pn * (m + 1) % mod;
    pm = (ll) pm * (n + 1) % mod;
    ans = (ans + coef) % mod;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4096