akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for(int i = k; i < (n); i++)

int main(){
    int n;
    cin >> n;
    vector<int> station(n, 0);
    vector<vector<int>> time;
    int c, s, f;
    rep(i, 0, n-1){
        cin >> c >> s >> f;
        vector<int> si = {c, s, f};
        time.push_back(si);
    }
    rep(i, 0, n-1){
        int t = time[i][0] + time[i][1];
        rep(j, i+1, n-1){
            if (t < time[j][1]) t = time[j][1];
            else if (t % time[j][2] != 0) t += time[j][2] - t % time[j][2];
            t += time[j][0];
        }
        station[i] = t;
    }
    for (auto s:station) cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N;
int Q;

int counter[200005];
bool check[200005];
vector<int> v[200005];

signed main(){
    cin>>N>>Q;
    for(int i=0;i<N-1;++i){
        int a,b;
        cin>>a>>b;
        v[a].PB(b);
        v[b].PB(a);
    }
    for(int i=0;i<Q;++i){
        int p,x;
        cin>>p>>x;
        counter[p]+=x;
    }
    queue<int> que;
    que.push(1);
    check[1]=true;
    while(!que.empty()){
        int parent=que.front();
        que.pop();
        for(auto child:v[parent]){
            if(check[child])continue;
            counter[child]+=counter[parent];
            check[child]=true;
            que.push(child);
        }
    }
    for(int i=1;i<=N;++i)cout<<counter[i]<<endl;
}


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

int main() {

long N,M;
cin>>N>>M;
vector<long> a(M);
for(int i=0;i<M;i++) cin>>a[i];
long sum =0;
for(int i=0;i<M;i++){
  sum+=a[i];
}
long ans=N-sum;
if(ans>=0) cout<<ans<<endl;
else cout<<-1<<endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint pow2(ll a, ll b){
  if(b == 0){
    return 1;
  }
  if(b % 2 == 0){
    mint x = pow2(a, b/2);
    return x * x;
  }
  else{
    mint x = pow2(a, b/2);
    return x * x * a;
  }
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<mint> d(K+1, 0), e(K+1, 0);
  rep2(i, 1, K+1){
    e.at(i) = pow2(K/i, N);
  }
  rep(i, K){
    d.at(K-i) = e.at(K-i);
    ll j = 2;
    while(j * (K - i) <= K){
      d.at(K-i) -= d.at(j*(K-i));
      j++;
    }
  }
  mint ans = 0;
  rep(i, K){
    ans += d.at(i+1) * (i+1);
  }
  cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    int y = 700;
    if(s[0] == 'o')
        y = y+100;
    if(s[1] == 'o')
        y = y+100;
    if(s[2] == 'o')
        y = y+100;
    cout << y << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import accumulate as ac
    from bisect import bisect_left as bl
    n, m, k = map(int, input().split())
    a = [0]+list(map(int, input().split()))
    b = [0]+list(map(int, input().split()))
    aa = list(ac(a))
    bb = list(ac(b))
    ans = 0
    for i in range(n+1):
        if aa[i] > k:
            break
        ans = max(ans, i+bl(bb, k-aa[i]+0.1)-1)
    print(ans)


main()


Measured memory_bytes: 47336
//
//AtCoder Beginner Contest 172
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    int ans=0;
    REP(i,s.size()){
        if (s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3916
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($s) = explode(" ", trim(fgets(STDIN)));

  $ans = 0;
  $now = 0;
  for ($i=0; $i<$n; $i++) {
    if($s[$i] == 'I'){
      $now++;
    }else{
      $now--;
    }
    $ans = max($ans, $now);
  }

  echo $ans;

Measured memory_bytes: 16108
n = int(input())
A = list(map(int, input().split()))
RAIN = [0] * n

for i in range(n):
    if i % 2 == 0:
        RAIN[0] += A[i]
    else:
        RAIN[0] -= A[i]

for i in range(n - 1):
    RAIN[i + 1] = 2 * A[i] - RAIN[i]

RAIN = [str(rain) for rain in RAIN]
answer = " ".join(RAIN)
print(answer)


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

using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

map<pair<int,int>, int> record(int N) {

  map<pair<int,int>, int > result;
  for(int i=1; i<=N; i++) {
    int x = i;
    int y = i%10;
    while(x>9) x /=10;
    result[PII(x, y)] ++;
  }
  return result;

}


int main() {
  int N;
  cin >> N;
  LL ans = 0;
  map<PII, int> res = record(N);
  for(int i=1; i<10; i++) {
    for(int j=1; j<10; j++) {
      ans += res[PII(i,j)] * res[PII(j, i)];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int cnt[100010];
 
int main(void) {
    int n, t, l, r;
    cin >> n >> t;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        cnt[l]++;
        cnt[r]--;
    }
 
    int ans = 0, sum = 0;
    for (int i = 0; i <= t; i++) {
        sum += cnt[i];
        ans = max(ans, sum);
    }
     
    cout << ans << endl;
 
    return 0;
}


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

int main(){
	int n, m;
	cin >> n;
	vector<int> t(n);
	for(int i=0; i<n; i++){
		cin >> t.at(i);
	}
	cin >> m;
	vector<int> p(m), x(m);
	for(int i=0; i<m; i++){
		cin >> p.at(i) >> x.at(i);
	}
	int total=0;
	for(int i=0; i<n; i++) total+=t.at(i);
	vector<int> ans(m);
	for(int i=0; i<m; i++){
		int sa=x.at(i)-t.at(p.at(i)-1);
		ans.at(i)=total+sa;
	}
	for(int i=0; i<m; i++){
		cout << ans.at(i) << endl;
	}
}


Measured memory_bytes: 3640
#include<cstdio>
#include<set>
using namespace std;

int n,m,x,y,z;
int g[100001];

void init(){
    for(int i=1;i<=n;i++){
        g[i]=i;
    }
}

int dfs(int x){
    if(x==g[x]){
        return x;
    }
    return g[x]=dfs(g[x]);
}

int main(){
    set<int> s;
    scanf("%d %d",&n,&m);
    init();
    for(int i=0;i<m;i++){
        scanf("%d %d %d",&x,&y,&z);
        x=dfs(x);
        y=dfs(y);
        if(x<y){
            g[y]=x;
        }
        else{
            g[x]=y;
        }
    }
    for(int i=1;i<=n;i++){
        dfs(i);
        s.insert(g[i]);
    }
    printf("%ld\n",s.size());
}

Measured memory_bytes: 5376
import java.util.Scanner;

class Dice3{
	private int[] number = new int[6]; //Diceの方向には何の数字かを示す
										//初期値の順番と一緒：上面①、その下②、その右③、その左④、その上⑤、その反面⑥（Indexと一個違い）

	//コンストラクタ
	public Dice3(int[] n) {
		for (int i=0; i< 6; i++)number[i] = n[i];
	}

	public int getDice(int no) {
		return number[no];
	}

	public void roll(String target) {
		int [] w = new int[6];  //仮のway
		int a = target.length();
		for (int i=0; i<a; i++) {
			for (int j=0; j< 6; j++) w[j] = number[j];  //コピーする
			String t = target.substring(i, i+1);
			switch(t) {
			case "N":
				number[4] = w[0];
				number[0] = w[1];
				number[1] = w[5];
				number[5] = w[4];
				break;
			case "E":
				number[2] = w[0];
				number[0] = w[3];
				number[3] = w[5];
				number[5] = w[2];
				break;
			case "S":
				number[4] = w[5];
				number[0] = w[4];
				number[1] = w[0];
				number[5] = w[1];
				break;
			case "W":
				number[2] = w[5];
				number[0] = w[2];
				number[3] = w[0];
				number[5] = w[3];
				break;
			}
		}
	}

	public void rollToAB(int A,int B) {
		if (number[0]!=A) {		//Aは①面ではない
			if (number[2] == A) roll("W"); //Aが③の時：W
			else if (number[3] == A) roll("E"); //Aが④の時：E
			else if (number[1] == A) roll("N"); //Aが②の時：N
			else if (number[4] == A) roll("S"); //Aが⑤の時：S
			else roll("NN"); //Aが⑥の時：NN
		}
		if (number[1]!=B){  //Aは①面にあって、Bは②にない
			if (number[2] == B) roll("WSE");  //Bが③の時：W→S→E
			else if (number[3] == B) roll("ESW");  //Bが④の時：E→S→W
			else if (number[4] == B) roll("SENWSE");  //Bが⑤の時：S→E→N→Bが③になる→W→S→E
			else number[2] = -1;  //Bが⑥の時：必ず異なる
		}
	}
}

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			//データ入力----------------------------------------------
			boolean[] check = new boolean[6];

			int [] n = new int[6];
			for (int i=0; i<6; i++) {
					n[i] = sc.nextInt();
					check[i] = false;  //初期化
			}
			Dice3 diceA = new Dice3(n);
			for (int i=0; i<6; i++) n[i] = sc.nextInt();
			Dice3 diceB = new Dice3(n);
			//面々の一致性をチェックする--------------------------------
			for (int i=0; i<6; i++) {
				for (int j=0; j<6; j++) {
					if (diceB.getDice(j) == diceA.getDice(i)) check[i] = true;  //jはiと一致する面があったらチェック
				}
			}
			boolean flag = true;
			for (int i=0; i<6; i++) {
				if (!check[i]) { //全部一致ではなければ異なるサイコロ
					flag = false;
					break;
				}
			}
			if (flag) {  //二つのサイコロが同じ数字の組み合わせの場合
				diceB.rollToAB(diceA.getDice(0), diceA.getDice(1));  //diceBの向きを調整する
				System.out.println(diceA.getDice(2)==diceB.getDice(2) ? "Yes" : "No");  //③右面を比較して同じかどうかを判断する
			} else System.out.println("No");
		}
	}
}


Measured memory_bytes: 26376
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

bool judge(int bit);

int n,m;
vector<int> k;
vector<vector<int>> s;
vector<int> p;
vector<vector<int>> stolb;

int main(){
    cin>>n>>m;
    k.resize(m);
    s.resize(m);
    p.resize(m);
    stolb.resize(n);
    REP(i,m){
        cin>>k[i];
        s[i].resize(k[i]);
        REP(j,k[i]){
            cin>>s[i][j];
            stolb[s[i][j]-1].push_back(i);
        }
    }
    REP(i,m){
        cin>>p[i];
    }

    int count=0;

    for(int bit=0; bit<(1<<n); bit++){
        if(judge(bit)){
            count++;
        }
    }
   
    cout<<count<<endl;
}

bool judge(int bit){
    vector<int> on(m);
    REP(i,n){
        if(bit&(1<<i)){
            REP(j,stolb[i].size()){
                if(on[stolb[i][j]]==0){
                    on[stolb[i][j]]=1;
                }else{
                    on[stolb[i][j]]=0;
                }
            }
        }
    }

    REP(i,m){
        if(on[i]!=p[i]){
            return false;
        }
    }

    return true;
}

Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]

dp = [0] * (N+1)
dp[1] = abs(H[1] - H[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]))

print(dp[N-1])


Measured memory_bytes: 52208
L=input()
a=int(L[0])
b=int(L[1])
c=int(L[2])
d=int(L[3])

import itertools

A=(1,-1)

def e(x):
	if x==1:
		return '+'
	else:
		return '-'

for v in itertools.product(A,repeat=3):
	s=a+b*v[0]+c*v[1]+d*v[2]
	if s==7:
		print(L[0]+e(v[0])+L[1]+e(v[1])+L[2]+e(v[2])+L[3]+'=7')
		exit()


Measured memory_bytes: 9180
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	String s=sc.next();
    if(s.indexOf("AC")!=-1){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}


Measured memory_bytes: 23252
//ALDS1_3B
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
 char name[100];
 int t;
 }P;

P Q[LEN];
int head,tail,n;

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

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

int min(int a,int b){return a<b?a:b;}

int main(){
 int elapse=0,c;
 int i,q;
 P u;
 scanf("%d %d",&n,&q);
 for(i=1;i<=n;i++){
  scanf("%s",Q[i].name);
  scanf("%d",&Q[i].t);
 }
 head=1;
 tail=n+1;

 while(head!=tail){
  u=dequeue();
  c=min(q,u.t);
  u.t-=c;
  elapse+=c;
  if(u.t>0) enqueue(u);
  else printf("%s %d\n",u.name,elapse);
 }

 return 0;
}

Measured memory_bytes: 11184
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N;
int a[100010],b[100010];
int main(){
    cin>>N;
    for(int i=0;i<N;i++)   {
        cin>>a[i];
        cin>>b[i];
    }
    LL ans=0;
    for(int i=N-1;i>=0;i--){
        if((a[i]+ans)%b[i]==0)continue;
        ans+=b[i]-(a[i]+ans)%b[i];
    }
    cout<<ans;
    
        
    return 0;
}


Measured memory_bytes: 1024
N, M, Q = map(int, input().split())
abcd = []
for i in range(Q): abcd.append(list(map(int, input().split())))
ans = 0
per_lst = []
def make_per(lst, n, m):
    n_lst = lst.copy()
    n_lst.append(0)
    if n == 1:
        for i in range(1, m+1):
            n_lst = n_lst.copy()
            n_lst[-1] = i
            if len(n_lst) > 1:
                if i >= n_lst[-2]:
                    per_lst.append(n_lst)
            else:
                per_lst.append(n_lst)
    else:
        for i in range(1, m+1):
            n_lst[-1] = i
            if len(n_lst) > 1:
                if i >= n_lst[-2]:
                    make_per(n_lst, n-1, m)
            else:
                make_per(n_lst, n-1, m)

make_per([], N, M)
# for i in per_lst:
#     print(i)
maxi = 0
for per in per_lst:
    score = 0
    for i in range(Q):
        a, b, c, d = abcd[i][0], abcd[i][1], abcd[i][2], abcd[i][3]
        a -= 1
        b -= 1
        if (per[b] - per[a]) == c: score += d
    if score > maxi: maxi = score
print(maxi)

Measured memory_bytes: 91900
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn group(s: i32) -> &'static str {
	let A = vec![1, 3, 5, 7, 8, 10, 12];
	let B = vec![4, 6, 9, 11];
	let C = vec![2,];

		if A.contains(&s) {
			"A"
		} else if B.contains(&s) {
			"B"
		} else if C.contains(&s) {
			"C"
		}else{
			"No"
		}
}

fn main() {
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();

	let x = group(s[0]);
	let y = group(s[1]);
	if x == y {
		println!("Yes");
	}else{
		println!("No");
	}
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}
/*



*/

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
        char array[100];
        int a,i,flag = 0;
        int count = 0;

        scanf("%d",&a);
        scanf("%s",array);
        for(i = 0; i < a / 2 ;i++){
                if(array[i] == array[a / 2 + i]){
                        flag = 1;
                }else{
                        flag = 0;
                        break;
                } 
        }
        if(a %  2 != 0){
                flag = 0;
        }

        if(flag == 1){
                printf("Yes");
        }else{
                printf("No");
        }
        return 0;
}




Measured memory_bytes: 128
function main(input) {
  const inputs = input.trim().split('\n')
  const [N, M] = inputs[0].split(' ')
  const H = [0, ...inputs[1].split(' ')].map(Number)
  const path = []
  inputs.slice(2).forEach(e => {
    // console.log('e', e)
    const [A, B] = e.split(' ')
    if (!path[A]) {
      path[A] = []
    }
    path[A].push(B)
    if (!path[B]) {
      path[B] = []
    }
    path[B].push(A)
  })
  // console.log(path)

  let good = 0
  for(let i = 1; i <= N; i++) {
    let isGood = true
    if (!path[i]) {
      good++
      continue
    }
    for(const e of path[i]) {
      // console.log(i, H[i], e, H[e])
      if (H[e] >= H[i]) {
        isGood = false
        // console.log('not good')
        break
      }
    }
    if (isGood) good++
  }
  console.log(good)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 97672
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()
#define DIV 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;
	
	cin >> n;
	
	string a,b;
	cin >> a >> b;
	
	int i = 0;
	ll ans = 1;
	bool tate = false;
	
	if(n > 1 && a[i] == a[i+1])
	{
		ans *= 6;
		i+=2;
		tate = false;
	}
	else
	{
		ans *= 3;
		i+=1;
		tate = true;
	}
	
	while(i < a.size())
	{
		if(i < a.size()-1 && a[i] == a[i+1])
		{
			if(tate)
			{
				ans = (ans*2)%DIV;
				i += 2;
				tate = false;
			}
			else
			{
				ans = (ans * 3) % DIV;
				i += 2;
				tate = false;
			}
		}
		else
		{
			if(tate)
			{
				ans = (ans*2) % DIV;
				i++;
				tate = true;
			}
			else
			{
				i++;
				tate = true;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
int main()
{
	int n;
	cin >> n;

	if(n >= 100 && n <= 111){
		cout << 111 <<endl;
	}else if(n>=112 && n<=222){
		cout << 222 <<endl;
	}else if(n>=223 && n<=333){
		cout << 333 <<endl;
	}else if(n>=334 && n<=444){
		cout << 444 <<endl;
	}else if(n>=445 && n<=555){
		cout << 555 <<endl;
	}else if(n>=556 && n<=666){
		cout << 666 <<endl;
	}else if(n>=667 && n<=777){
		cout << 777 <<endl;
	}else if(n>=778 && n<=888){
		cout << 888 <<endl;
	}else{
		cout << 999 <<endl;
	}
	return 0;
}


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

int N, Q;
string s;
const int MAX_N = 100100;
int res[MAX_N];
int l;
int r;


int main()
{
  cin >> N >> Q;
  cin >> s;

  for (int i = 0; i < N; i++) {
    if (i + 1 < N && s[i] == 'A' && s[i + 1] == 'C') {
      res[i + 1] = res[i] + 1;
    }
    else
    {
      res[i + 1] = res[i];
    }
  }

    for (int i = 0; i < Q; i++)
    {
      cin >> l >> r;
      l--;
      r--;
      cout << res[r] - res[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()

if u==s:
    a-=1
else:
    b-=1
print(a,b)

Measured memory_bytes: 6252
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


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

  map<string,int> mp;

  for(int i=0;i<n;i++){
    string s; cin >> s;
    mp[s]++;
  }

  int maxx = -1;

  for(auto p : mp){
    if(maxx<p.second){
      maxx = p.second;
    }
  }

  vector<string> vec;

  for(auto p : mp){
    if(p.second==maxx) vec.pb(p.first);
  }

  sort(all(vec));

  for(auto k  : vec) cout << k << "\n";


  

  return 0;
}

Measured memory_bytes: 25584
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#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 MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N,now=0;
    cin>>N;
    V<pair<int,int>> A(N);
    REP(i,N){
        int a,b;cin>>a>>b;
        A[i].F=b,A[i].S=a;
    }
    sort(All(A));
    REP(i,N){
        if(now+A[i].S>A[i].F){
            cout<<"No"<<endl;
            return 0;
        }
        else now+=A[i].S;
    }
    
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(N)]
ret=0
for i in range(N):
  ans=C
  for j in range(M):
    ans+=B[j]*A[i][j]
  if ans >0:
    ret+=1
print(ret)

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

int main() {
  #define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int H,N;
  cin>>H>>N;
  vector<int> a(N);
  rep(i,N){
    cin>>a[i];
    H=H-a[i];
  }
  if(H<=0)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = 998244353;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 ll INF = 1LL << 60;

ll 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;
    }
}

ll 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;
}

ll binarypow(ll a, ll n, ll MOD) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    n >>= 1;
  }
  return res;
}

int main() {
    COMinit();
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;
    rep(i, k+1) ans += m * COM(n-1, i) % MOD * binarypow(m-1, n-i-1, MOD) % MOD;
    cout << ans % MOD << endl;
}


Measured memory_bytes: 15584
int main(int argc ,const char *argv[])
{
    int d[10000],x=1,n=0;
    while(1){
        scanf("%d",&x);
        if(x==0){
            break;
        }else{if(1<=x&&x<=10000){
            d[n]=x;
            n++;
        }
    }}
    for(int i=0;i<n;i++){
        printf("Case %d: %d\n",i+1,d[i]);
    }
}


Measured memory_bytes: 2080
#include <iostream>
#include <ios>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>

using namespace std;
int Es[100][100] = {{0}};

int MST(int n){
    vector<bool> used(n, false);
    priority_queue< pair<int, int> > pq;
    pq.emplace(0, 0);
    int dist = 0;
    int node = 0;
    int total_dist = 0;
    while (! pq.empty()){
        tie(dist, node) = pq.top();
        pq.pop();
        if (used[node]) continue;
        used[node] = true;
        total_dist -= dist;
        for (int new_node = 0; new_node != n; ++new_node){
            if (used[new_node] || Es[node][new_node] == -1) continue;
            pq.emplace(-Es[node][new_node], new_node);
        }
    }
    return total_dist;
}

int main()
{
    ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    for (int i = 0; i != n; ++i){
        for (int j = 0; j != n; ++j){
            cin >> Es[i][j];
        }
    }
    cout << MST(n) << endl;
    return 0;
}

Measured memory_bytes: 3204
from bisect import bisect_left as bl
def main():
  n, m = map(int, input().split())
  plst = []
  xlst = set()
  ylst = set()
  for _ in range(n):
    x, y = map(int, input().split())
    plst.append((x, y))
    xlst.add(x)
    ylst.add(y)
  
  xlst = sorted(list(xlst))
  ylst = sorted(list(ylst))
  xdic = {}
  ydic = {}
  for i, x in enumerate(xlst):
    xdic[x] = i
  for i, y in enumerate(ylst):
    ydic[y] = i
  
  xlen = len(xlst)
  ylen = len(ylst)
  mp = [[0] * (xlen + 1) for _ in range(ylen + 1)]
  for x, y in plst:
    mp[ydic[y] + 1][xdic[x] + 1] += 1
  
  for y in range(1, ylen + 1):
    acc = 0
    for x in range(1, xlen + 1):
      acc += mp[y][x]
      mp[y][x] = acc + mp[y - 1][x]
  
  for _ in range(m):
    x1, y1, x2, y2 = map(int, input().split())
    x1i = bl(xlst, x1)
    y1i = bl(ylst, y1)
    x2i = bl(xlst, x2)
    y2i = bl(ylst, y2)
    if x2i < xlen and xlst[x2i] == x2:
      x2i += 1
    if y2i < ylen and ylst[y2i] == y2:
      y2i += 1
    print(mp[y2i][x2i] - mp[y2i][x1i] - mp[y1i][x2i] + mp[y1i][x1i])

main()


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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N);
    rep(i,N) cin >> x[i];
    vector<ll> d(N-1);

    for(int i=1;i<N;i++){
      d[i-1] = x[i]-x[i-1];
    }

    ll p = 1;
    for(ll i=1;i<=N-1;i++){
      p = (p*i) % ((ll)1e9+7);
    }

    vector<ll> xs(N-1);
    xs[0] = p;
    for(ll i=2;i<=N-1;i++){
      xs[i-1] = xs[i-2]+p* modinv(i,(ll)1e9+7);
      xs[i - 1] %= ((ll)1e9 + 7);
    }

    ll ans = 0;
    rep(i,N-1){
        ans += ((d[i] * xs[i]) % ((ll)1e9 + 7));
        ans %= ((ll)1e9 + 7);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b && c!=b)
		cout<<c;
	if(a==c and b!=a)
		cout<<b;
	if(b==c and a!=b)
		cout<<a;
	
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};

    static int h, w;
    static char[][] S;

    public static void main(String[] args) {
        input();
        solve();
    }

    static void solve() {
        int ans = 0;

        Queue<P> q = new ArrayDeque<>();
        q.add(new P(0, 0));
        int[][] cost = new int[h][w];
        for(int i = 0; i < h; i++) Arrays.fill(cost[i], -1);
        cost[0][0] = 1;
        while(!q.isEmpty()) {
            P c = q.remove();

            for(int i = 0; i < 4; i++) {
                int nx = c.x + x4[i];
                int ny = c.y + y4[i];
                if(nx < 0 || w-1 < nx || ny < 0 || h-1 < ny) continue;
                if(cost[ny][nx] != -1 || S[ny][nx] != '.') continue;

                cost[ny][nx] = cost[c.y][c.x] + 1;
                S[ny][nx] = '@';
                q.add(new P(nx, ny));
            }
        }

        if(cost[h-1][w-1] == -1) {
            print(-1);
            return;
        }

        int cnt = 0;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(S[i][j] == '#') cnt++;
            }
        }

        ans = w * h - cnt - cost[h-1][w-1];
        print(ans);
    }

    static void input() {
        Scanner in = new Scanner(System.in);
        h = in.nextInt();
        w = in.nextInt();
        S = new char[h][w];
        for(int i = 0; i < h; i++) {
            S[i] = in.next().toCharArray();
        }
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(char c) {
        System.out.println(c);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }

    static void print(float i) {
        System.out.println(i);
    }

    static void printArray2D(int[][] array, char del) {
        int r = array.length;
        int c = array[0].length;
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                System.out.format("%3d", array[i][j]);
                if(j != c-1) System.out.print(del);
                else System.out.print('\n');
            }
        }
    }
}

class P {
    int x, y;
    P(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class E {
    int from, to;
    long w;
    E(int from, int to, long w) {
        this.from = from;
        this.to = to;
        this.w = w;
    }
}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    const int a[] = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    };

    int n; read(n);
    print(a[n - 1]);

    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    int a, b, x; cin >> a >> b >> x;

    int nax = 1e9;

    for(int i = 0;  i < 100; i++) {
        for(int j = 0; j < 100; j++) {
            int wata = i * 1000 + j * 500;
            if(wata < x)continue;
            nax = min(i * a + j * b, nax);
        }
    }
    cout << nax << endl;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n;
    cin>>n;
    int digit = n%10;
    if(digit == 3){
        cout<<"bon";
    } else if(digit == 0 || digit == 1 || digit == 6 || digit == 8){
    cout<<"pon";
    }else
    {
        cout<<"hon";
    }
    
    return 0;
}

Measured memory_bytes: 3584
K = int(input())
A = list(map(int, input().split()))

lo = 2
hi = 10**18


def check1(people):
    for a in A:
        people = (people // a) * a
    if people > 2:
        return False
    else:
        return True


def check2(people):
    for a in A:
        people = (people // a) * a
    if people < 2:
        return False
    else:
        return True


for i in range(100):
    center = (lo + hi) // 2
    if check1(center):
        lo = center
    else:
        hi = center

Mz = center

lo = 2
hi = 10**18

for i in range(100):
    center = (lo + hi) // 2
    if center > Mz:
        hi = center
        continue
    if check2(center):
        hi = center
    else:
        lo = center

mz = hi
if Mz >= mz:
    print(mz, Mz)
else:
    print(-1)

Measured memory_bytes: 14252
import java.util.*;
import java.io.*;
import java.math.*;


public class Main {
 
	static final Scanner sc = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;
 
	static void solve() {
		int n = sc.nextInt();
		int sum = 0;
		int[] elements = new int[n];
		for(int i=0; i<n; i++) {
			elements[i] = sc.nextInt();
			sum += elements[i];
		}
		int res = sum / n;
		res = ((double)sum/n <= (res+0.5)) ? res : res + 1;
		int cost = 0;
		for(int i=0; i<n; i++) {
			cost += (elements[i] - res) * (elements[i] - res);
		}
		out.println(cost);
	}
 
	public static void main(String[] args) {
		solve();

		out.flush();
		out.close();
	}
}

Measured memory_bytes: 9812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

ll n;
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    cin >> n;
    cout << n * (n-1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll a,b;cin>>a>>b;
    ll ans=0;
    if(a>=b){
        ans+=a;
        a--;
    }else{
        ans+=b;
        b--;
    }

    if(a>=b){
        ans+=a;
    }else{
        ans+=b;
    }

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

Measured memory_bytes: 3600
import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_, foldM)
import Data.List (foldl', find)

import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V

import Control.Monad.State

main :: IO ()
main = do
  n <- readLn
  xss <- replicateM n (map read <$> words <$> getLine)
  solve n xss >>= printStat n

solve :: Int -> [[Int]] -> IO Stat
solve n xss = foldM f (Stat 1 (V.replicate n 0) (V.replicate n 0) (V.replicate n W)) [0 .. n-1]
  where gd = foldl' (\v (i:_:ls) -> v // [(i-1, map (subtract 1) ls)]) (V.replicate n []) xss
        f st@(Stat tm gt bt cd) i | cd ! i == B = return st
                                  | otherwise = return $ evalState (dfs [i]) (Stat (tm+1) (gt // [(i, tm)]) bt (cd // [(i,G)]))
        dfs :: [Int] -> State Stat Stat
        dfs [] = get
        dfs (u:st) = do
          (Stat tm gt bt cd) <- get
          case find (\v -> cd ! v == W) (gd ! u) of
           Just v -> do
             put $ Stat (tm+1) (gt // [(v, tm)]) bt (cd // [(v,G)])
             dfs (v:u:st)
           Nothing -> do
             put $ Stat (tm+1) gt (bt // [(u, tm)]) (cd // [(u,B)])
             dfs st

data Color = W | G | B deriving (Show, Eq, Ord)

data Stat = Stat Int (Vector Int) (Vector Int) (Vector Color) deriving (Show)

printStat :: Int -> Stat -> IO ()
printStat n (Stat _ gt bt _) = do
  forM_ [0 .. n-1] $ \i -> do
    putStrLn . unwords $ [show (i+1), show (gt ! i), show (bt ! i)]



Measured memory_bytes: 4988
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#define rep(n, i) for(int i = 0; i < n; i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

void solve(void){
    int n, m;
    scanf("%d %d\n", &n, &m);
    int coins[m], pays[n+1];
    rep(m, i) scanf("%d ", &coins[i]);
    rep(n+1, i) pays[i] = i;
    rep(m, i){
        for (int j = coins[i]; j < n+1; j++){
            pays[j] = MIN(pays[j], pays[j - coins[i]]+1);
        }
    }
  printf("%d\n", pays[n]);
}

int main(void){
  solve();
  return 0;
}

Measured memory_bytes: 2056
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>str>>stra>>straa;
    cout<<str[0]<<stra[1]<<straa[2]<<endl;
    return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const double eps = 1e-11;

inline int dcmp(double x){if(-eps<x && x<eps)return 0;return x>0?1:-1;}

struct points
{
	double x,y;
	points(double _x=0,double _y=0){x=_x,y=_y;}

	inline friend points operator + (points a,points b){return points(a.x+b.x,a.y+b.y);}
	inline friend points operator - (points a,points b){return points(a.x-b.x,a.y-b.y);}
	inline friend points operator * (points a,double b){return points(a.x*b,a.y*b);}
	inline friend points operator / (points a,double b){return points(a.x/b,a.y/b);}

	inline friend int operator == (points a,points b){return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;}

	void takein(){x=ty(),y=ty();}
	void print(char ends='\n'){printf("%.12lf %.12lf",x,y),putchar(ends);}
};

inline double dox(points a,points b){return a.x*b.x+a.y*b.y;}
inline double cox(points a,points b){return a.x*b.y-a.y*b.x;}
inline double length(points a){return sqrt(dox(a,a));}
inline double distan(points a,points b){return length(a-b);}

inline points pervec(points a){if(dcmp(length(a))<=0)return points(0,0);return a/length(a);}

inline int isponl(points p,points a,points b)
{
	return dcmp(cox(p-a,p-b))==0 && distan(a,p)<=distan(a,b) && distan(b,p)<=distan(a,b);
}

inline int iscrashed(points al,points ar,points bl,points br)
{
	double amix=min(al.x,ar.x),amxx=max(al.x,ar.x),amiy=min(al.y,ar.y),amxy=max(al.y,ar.y);
	double bmix=min(bl.x,br.x),bmxx=max(bl.x,br.x),bmiy=min(bl.y,br.y),bmxy=max(bl.y,br.y);
	
	if(amxx<bmix || bmxx<amix || amxy<bmiy || bmxy<amiy)return 0;
	if(isponl(al,bl,br) || isponl(ar,bl,br) || isponl(bl,al,ar) || isponl(br,al,ar))return 1;

	if(dcmp(cox(al-bl,br-bl))!=dcmp(cox(ar-bl,br-bl))
		&& dcmp(cox(bl-al,ar-al))!=dcmp(cox(br-al,ar-al)))return 1;
	return 0;
}

inline points crash(points al,points ar,points bl,points br)
{
	points a=ar-al,b=br-bl;
	double bas=cox(al-bl,b)/cox(b,a);
	return al+a*bas;
}

void finder()
{
	points al,ar,bl,br;
	al.takein(),ar.takein(),bl.takein(),br.takein();

	crash(al,ar,bl,br).print();
}

int main()
{
	int q=ty();
	while(q--)finder();
	
	return 0;
}



Measured memory_bytes: 3260
#include <stdio.h>

int main (){
    int a,b;
    int flag = 0;
    scanf("%d %d", &a, &b);
    char input[a+b+1];
    scanf("%s", input);
    int ctr = 0;

    for(int i=0;i<a+b+1;i++){
        if(input[i]== '-' && i == a ){
            flag = 1;
        } else if (input[i] >= '0' && input[i] <= '9'){
            ++ctr;
            }
        }

    if(flag == 1 && ctr == a+b){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, x;
  cin>>n>>x;
  int l[n];
  ARRIN(l, n);

  int s=0, t=0;
  REP(i, n){
    if(s+l[i]<=x)++t, s+=l[i];
    else break;
  }
  ECHO(t+1);

  return 0;
}


Measured memory_bytes: 256