akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int a[105];
LL dp[2][100005];
LL sum[2][100005];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
    }
    int pv = 0, cur = 1;
    sum[pv][0] = dp[pv][0] = 1;
    for(int j=1;j<=k;j++) sum[pv][j] = sum[pv][j-1] + dp[pv][j]; 
    for(int i=1;i<=n;i++){
        memset(dp[cur], 0, sizeof(dp[cur]));
        for(int j=0;j<=k;j++){
            int l = max(0, j-a[i]), r = j;
            dp[cur][j] = sum[pv][r];
            if(l != 0) dp[cur][j] = (dp[cur][j] - sum[pv][l-1] + mod)%mod;
        }
        sum[cur][0] = dp[cur][0];
        for(int j=1;j<=k;j++) sum[cur][j] = (sum[cur][j-1] + dp[cur][j])%mod;
        if(i != n) swap(pv, cur);
    }
    printf("%lld\n", dp[cur][k]);
}


Measured memory_bytes: 3328
from collections import defaultdict
# import sys
# input = sys.stdin.readline

n, m = map(int, input().split())
ac = 0
wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない
already = set()
sum_wa = 0
for line in range(m):
    p, s = input().split() # forでその都度入力を受け取る
    p = int(p)
    if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。
        continue
    if s == 'AC':
        ac += 1
        already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。
        # sum_wa += wa[p]
    else:
        wa[p] += 1 #{1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。

# print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので×
# print(ac, sum_wa)
print(ac, sum(wa[i] for i in already))


Measured memory_bytes: 22888
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll H,W,N;
    cin>>H>>W>>N;
    set<pair<ll,ll>> st;
    vector<ll> a(N),b(N);
    REP(i,N){
        cin>>a[i]>>b[i];
        st.insert(make_pair(a[i],b[i]));
    }

    vector<set<pair<ll,ll>>> ans(10);
    REP(i,N){
        REP2(x1,-1,2){
            REP2(y1,-1,2){
                ll x_center=a[i]+x1;
                ll y_center=b[i]+y1;
                if(x_center<2||x_center>H-1||y_center<2||y_center>W-1) continue;
                int cnt=0;
                REP2(x2,-1,2){
                    REP2(y2,-1,2){
                        if(st.count(make_pair(x_center+x2,y_center+y2))) cnt++;
                    }
                }
                if(cnt!=0&&!ans[cnt].count(make_pair(x_center,y_center))){
                    ans[cnt].insert(make_pair(x_center,y_center));
                }
            }
        }
    }
    ll tot=(H-2)*(W-2);
    ll minus=0;

    vector<ll> res(10,0);
    REP2(i,1,10){
        res[i]=ans[i].size();
        minus+=res[i];
    }
    res[0]=tot-minus;

    REP(i,10){
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 64256
#include <cstdlib>
#include <iostream>

int main(int argc, char *argv[]) {
  long x, k, d;
  std::cin >> x >> k >> d;

  long abs_x = std::abs(x);

  std::ldiv_t dv = std::ldiv(abs_x, d);
  if (dv.quot >= k) {
    std::cout << (dv.quot - k) * d + dv.rem << std::endl;
  } else if ((k - dv.quot) % 2 == 0) {
    std::cout << dv.rem << std::endl;
  } else {
    std::cout << d - dv.rem << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a,b;
  cin>>a>>b;
  float ans = (a+b-1)/b;
  cout<<ceil(ans)<<"\n";
  return 0;
}
  


Measured memory_bytes: 3796
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>

using namespace std;

const int H = 5, W = 4;

int countZero(const string &str) {
  int ret = 0;
  for(int i=0; i<H*W; i++) {
    ret += str[i] == '0';
  }
  
  return ret;
}

void rearrange(string &str) {
  int pos = 0;
  for(int i=0; i<H*W; i++) {
    if(str[i] == '0') continue;
    char ch = str[i];
    str[i] = '0';
    str[pos++] = ch;
  }
}

int main() {
  
  int Tc;
  cin >> Tc;
  
  while(Tc--) {
    
    string initial;
    for(int i=0; i<H; i++) {
      for(int j=0; j<W; j++) {
        char ch; cin >> ch;
        initial += ch;
      }
    }
    
    int ans = 0;
    
    set<string> used;
    queue<string> Q;
    Q.push(initial);
    while(!Q.empty()) {
      const string now = Q.front(); Q.pop();
      ans = max(ans, countZero(now));
      for(int pos=0; pos<H*W; pos++) {
        if(now[pos] == '0') continue;
        int x = pos%W, y = pos/W;
        for(int k=0; k<=1; k++) {
          for(int l=-1; l<=1; l++) {
            if(k == 0 && l == 0) continue;
            const int ny = y+k, nx = x+l;
            if(nx<0 || W<=nx || ny<0 || H<=ny) continue;
            const int npos = ny*W+nx;
            if(now[pos] != now[npos]) continue;
            string next;
            for(int i=0; i<H*W; i++) {
              if(i == pos || i == npos) continue;
              next += now[i];
            }
            next += "00";
            if(used.count(next)) continue;
            used.insert(next);
            Q.push(next);
          }
        }
      }
    }
    cout << 20-ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long int k,x,a,b;
    cin>>k>>x;
    a=x-k+1;
    b=x+k-1;
    for(int i=a; i<=b; i++)
        cout<<i<<" ";
    cout<<endl;

    return 0;
}


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

typedef long long ll;

using namespace std;

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

    int n;

    cin >> n;

    cout << (n * (n + 1)) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */

public class Main{

    /**
     * @param args the command line arguments
     */
   
    public static void main(String[] args) {
        // TODO code application logic 
        Scanner sc=new Scanner(System.in);
        int px[]=new int[90001];
        int py[]=new int[90001];
        int diff[]=new int[90001];
        int h=sc.nextInt();
        int w=sc.nextInt();
        int d=sc.nextInt();
        for (int i = 0; i < h; i++)  
    {  
        for (int j = 0; j < w; j++)  
        {  
           int A=sc.nextInt();
           px[A] = i;
           py[A] = j;  
        }  
    }  
    for (int i = d + 1; i <= h * w; i++)  
        diff[i] = diff[i - d] + Math.abs(px[i] - px[i - d]) + Math.abs(py[i] - py[i - d]);  
    int q=sc.nextInt();
    while (q-->0)  
    {  
        int l=sc.nextInt();
        int r=sc.nextInt();
        System.out.println(diff[r]-diff[l]);  
    }  

      
    }

    
}


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

typedef long long ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N), s(N+1);
	s[0] = a[0];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
		s[i+1] = s[i] + a[i];
	}

	ll mi=1e18;
	for (ll i = 1; i < N; i++) {
		ll x = s[i];
		ll y = s[N]-s[i];
		//cout << x <<" "<< y <<" "<< abs(x-y) << endl;
		mi = min(mi, abs(x-y));
	}

	cout << mi << endl;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC83(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC89();
}

void ABC89(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	size_t n, c;
	int *arr;
} list;

void add(list *l, int x) {
	if (l->n+1 > l->c) {
		l->c = l->c*2 + !l->c;
		l->arr = realloc(l->arr, l->c * sizeof *l->arr);
	}
	l->arr[l->n++] = x;
}

int seenx[100000], seeny[100000];
list lstx[100000], lsty[100000];
long long int cntx, cnty;

void dfs(int i, long long int* cnt, long long int* cntb, int* seen, int* seenb, list *lst, list *lstb) {
	seen[i] = 1;
	(*cnt)++;
	for (int j = 0; j < lst[i].n; j++) {
		int k = lst[i].arr[j];
		if (seenb[k]) continue;
		dfs(k, cntb, cnt, seenb, seen, lstb, lst);
	}
}

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

	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(&lstx[x-1], y-1);
		add(&lsty[y-1], x-1);
	}

	long long int cnt = -n;
	for (int i = 0; i < 100000; i++) {
		if (seenx[i] || lstx[i].n == 0) continue;
		cntx = cnty = 0;
		dfs(i, &cntx, &cnty, seenx, seeny, lstx, lsty);
		cnt += cntx * cnty;
	}

	for (int i = 0; i < n; i++) {
		free(lstx[i].arr);
		free(lsty[i].arr);
	}

	printf("%lld\n", cnt);
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define f first 
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
 
int main(){
  ll n,t,q;
  FIO;  
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << a[0]+a[1] << " ";
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = [0 for i in range(N)]
for i in range(1, N):
  D[i] = D[i-1] + abs(A[i-1] - A[i])
  for j in range(2, K + 1):
    if i - j < 0:
      break
    D[i] = min(D[i], D[i-j] + abs(A[i-j] - A[i]))
print(D[-1])

Measured memory_bytes: 90128
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x)
#define COUNT2(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll gcd(ll x, ll y) {
  if (x < y) swap(x, y);
  return y ? gcd(y, x%y) : x;
}

int main(void) {
  ll t, a, b, c, d;
  cin >> t;
  rep(i, t) {
	cin >> a >> b >> c >> d;
	if (a < b || b > d) {
	  cout << "No" << endl;
	  continue;
	}
	if (c >= b) {
	  cout << "Yes" << endl;
	  continue;
	}

	a %= b;
	d = gcd(b, d);

	tmp = c - a;
	if (tmp >= 0 && d != 0) ans = a + ((tmp / d) + 1)*d;
	else ans = a;
	//cout << ans << endl;
	ans %= b;
	if (ans > c) cout << "No" << endl;
	else cout << "Yes" << endl;

  }

  return 0;
}

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

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0){
    cout << x << endl;
  }
  else{
    vector<int> p(n);
    for (int i = 0;i < n;i++){
      cin >> p.at(i);
    }
    
    int la = x;
    int sa = x;
    
    while (true){
      int lc = 0;
      for (int i = 0;i < n;i++){
        if (la != p.at(i)){
          lc++;
        }
        else{
          la++;
          break;
        }
      }
      if (lc == n){
        break;
      }
    }
    
    while (true){
      int sc = 0;
      for (int i = 0;i < n;i++){
        if (sa != p.at(i)){
          sc++;
        }
        else{
          sa--;
          break;
        }
      }
      if (sc == n){
        break;
      }
    }
    
    if (la - x < x - sa){
      cout << la << endl;
    }
    else{
      cout << sa << endl;
    }
  }
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"math"
)

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func manhattan(a, b []int) float64 {
	d := 0
	for i := range a {
		d += abs(a[i] - b[i])
	}
	return float64(d)
}

func euclid(a, b []int) float64 {
	d := 0
	for i := range a {
		x := abs(a[i] - b[i])
		d += x * x
	}
	return math.Sqrt(float64(d))
}

func dist3(a, b []int) float64 {
	d := 0
	for i := range a {
		x := abs(a[i] - b[i])
		d += x * x * x
	}
	return math.Pow(float64(d), 0.333333333333)
}

func chebyshev(a, b []int) float64 {
	d := abs(a[0] - b[0])
	for i := range a {
		d = max(d, abs(a[i]-b[i]))
	}
	return float64(d)
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range b {
		fmt.Scan(&b[i])
	}
	fmt.Printf("%f\n", manhattan(a, b))
	fmt.Printf("%f\n", euclid(a, b))
	fmt.Printf("%f\n", dist3(a, b))
	fmt.Printf("%f\n", chebyshev(a, b))
}



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

def main():
    d, g = map(int, input().split())
    prob_list = [tuple(map(int, input().split())) for _ in range(d)]
    ans = float('inf')

    for x in range(2 ** d):
        score = 0
        tmp_ans = 0
        bonus_list = []
        for i in range(d):
            if (x >> i) % 2 == 1:
                score += prob_list[i][0] * (i + 1) * 100 + prob_list[i][1]
                tmp_ans += prob_list[i][0]
                bonus_list.append(i)
        if score < g:
            for j in range(d-1, -1, -1):
                if j not in bonus_list:
                    if score + (prob_list[j][0] - 1) * (j + 1) * 100 >= g:
                        tmp_ans += -(-(g - score) // ((j + 1) * 100)) 
                        break
                    else:
                        tmp_ans = float('inf')
        ans = min(ans, tmp_ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct BIT
{
    vector<ll> bit;
    ll MAX_N;

    BIT(ll n) : bit(n), MAX_N(n)
    {
        for(int i = 0; i < MAX_N; i++)
        {
            bit[i] = 0;
        }
    }

    ll sum(ll i)
    {
        ll s = 0;
        while(i > 0)
        {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(ll i, ll x)
    {
        while(i <= MAX_N)
        {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= k;
    }
    vector<ll> s(n+1);
    for(int i = 1; i <= n; i++)
    {
        s[i] = s[i-1] + a[i-1];
    }

    vector<ll> tmp(n+1);
    for(int i = 1; i <= n; i++)
    {
        tmp[i] = s[i];
    }
    sort(tmp.begin(), tmp.end());

    vector<ll> c(n+1);
    for(int i = 0; i <= n; i++)
    {
        ll d = distance(tmp.begin(), lower_bound(tmp.begin(), tmp.end(), s[i]));
        c[i] = d;
    }

    BIT bit(n+10);
    ll ans = 0;
    for(int j = 0; j <= n; j++)
    {
        ans += bit.sum(c[j]+1);
        bit.add(c[j]+1, 1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 8064
import math
def main():
    N, X = map(int, input().split())
    D = [int(input()) for _ in range(N)]
    count = 0

    for i in range(len(D)):
        X -= D[i]
        count += 1
    D.sort()
    for i in range(len(D)):
        if X >= D[i]:
            n = math.floor(X/D[i])
            if n >= 1:
                X -= n*D[i]
                count += n
    print(count)
main()

Measured memory_bytes: 3064
n, x, m = map(int, input().split())

lst, num = set(), []
for i in range(n):
    lst.add(x), num.append(x)
    x = x ** 2 % m
    if x in lst:
        cnt, idx = i + 1, num.index(x)
        break

ans = sum(num)
if x in lst:
    div, mod = divmod(n - cnt, len(num) - idx)
    ans += sum(num[idx:]) * div
    ans += sum(num[idx:idx + mod])
print(ans)


Measured memory_bytes: 77388
a, b = gets.split.map(&:to_i)
if a == b * 2
  puts b * 3
  exit
end
ans = 0
x, y = [b, a - b].sort
while(true) do
  c = y % x
  ans += (y - c) * 3
  x, y = c, x
  if c == 0
    break
  end
end
puts ans


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<vector<pii>> shogen(n);
    REP(i,n){
        int32 a;
        cin >> a;
        REP(j,a){
            int32 x,y;
            cin >> x >> y;
            x--;
            // cout << x << " " << y << endl;
            shogen[i].pb(pii(x,y));
        }
    }
    // REP(i,n){
    //     for(pii p : shogen[i]){
    //         cout << p.first << " ";
    //     }
    //     cout << endl;
    // }
    int32 ans = 0;
    for(int32 mask = 0; mask < (1 << n); mask++){
        bool flg = true;
        REP(i,n){
            if((mask & (1 << i))){
                for(pii p : shogen[i]){
                    int32 x,y;
                    tie(x,y) = p;
                    if((mask >> x & 1) != y){
                        // cout << i << " " << x << endl;
                        flg = false;
                        break;
                    }
                    // if(mask & (1 << x)){
                    //     if(y == 0){
                    //         flg = false;
                    //         break;
                    //     }
                    // }else{
                    //     if(y == 1){
                    //         flg = false;
                    //         break;
                    //     }
                    // }
                }
            }
        }
        // cout << bitset<16>(mask) << " " << flg << endl;
        // if(flg)ans++;
        if(flg)
            ans = max<int64>(ans, bitset<20>(mask).count());
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			for (int i = 1; i > 0; i++){
				int x = scan.nextInt(); //????????§???????????\???

				if(x == 0){
					break;
				}
				System.out.println("Case " + i + ": " + x);
			}
	}
}

Measured memory_bytes: 41916
import heapq
N,M = map(int, input().split())
A = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    tmp = ((-tmp)//2)*(-1)
    heapq.heappush(A,tmp)
ans = sum(A)*(-1)
print(ans)

Measured memory_bytes: 72216
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod =1000000007;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> broken(n);
  vector<ll> dp(n+2,0);
  dp.at(n+1)=0;
  dp[n]=1;
  
  for (int i=0;i<m; i++) {
    int a;
    cin >> a;
    broken.at(a)=1;
  }
  for (int j=n-1; j > -1; --j){
    if (broken[j]==1) continue;
    dp[j]=dp[j+1]%mod+dp[j+2]%mod;
   }
  //for (int h=0;h < n;h++) cout <<broken[h] << " ";
  //printf("\n");
  //for (int i=0;i<n+2;i++) cout << dp[i] << " ";
  //printf("\n");
  cout << dp[0]%mod << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
using std::sqrt;
using std::sin;
using std::cos;
using std::asin;
using std::acos;
int m1, m2, ans1, ans2, xx1, xx2, yy1, yy2;
#define y1 Y1
double d1, d2, l1, l2, xita1, xita2, x1, y1, x2, y2;
char a[5];
int main() {
	//freopen("1.txt", "r", stdin);
	scanf("%s", a);
	if (a[0]=='B'&&a[1]=='C') m1 = 1;
	if (a[0]=='C'&&a[1]=='D') m1 = 2;
	if (a[0]=='D'&&a[1]=='B') m1 = 3;
	scanf("%lf%lf", &d1, &l1);
	scanf("%s", a);
	if (a[0]=='B'&&a[1]=='C') m2 = 1;
	if (a[0]=='C'&&a[1]=='D') m2 = 2;
	if (a[0]=='D'&&a[1]=='B') m2 = 3;
	scanf("%lf%lf", &d2, &l2);
	xita1 = d1/180*acos(-1);
	xita2 = d2/180*acos(-1);
	x1 = l1*cos(xita1); y1 = l1*sin(xita1);
	x2 = l2*cos(xita2); y2 = l2*sin(xita2);
	x1 -= y1/sqrt(3.0); y1 *= (2.0); y1 /= sqrt(3.0);
	x2 -= y2/sqrt(3.0); y2 *= (2.0); y2 /= sqrt(3.0);
	xx1 = int(x1 + 0.00001); yy1 = int(y1 + 0.00001);
	xx2 = int(x2 + 0.00001); yy2 = int(y2 + 0.00001);
	if ((xx1%2) && (yy1%2)) {
		if (x1 + y1 < xx1 + yy1 + 1.00001) ans1 = 1;
		else ans1 = 4;
	}
	else if ((xx1%2)&&(yy1%2==0)) {
		if (x1 + y1 < xx1 + yy1 + 1.00001) ans1 = 3;
		else ans1 = 2;
	}
	else if ((xx1%2==0)&&(yy1%2)) {
		if (x1 + y1 < xx1 + yy1 + 1.00001) ans1 = 2;
		else ans1 = 3;
	}
	else {
		if (x1 + y1 < xx1 + yy1 + 1.00001) ans1 = 4;
		else ans1 = 1;
	}

	if ((xx2%2) && (yy2%2)) {
		if (x2 + y2 < xx2 + yy2 + 1.00001) ans2 = 1;
		else ans2 = 4;
	}
	else if ((xx2%2)&&(yy2%2==0)) {
		if (x2 + y2 < xx2 + yy2 + 1.00001) ans2 = 3;
		else ans2 = 2;
	}
	else if ((xx2%2==0)&&(yy2%2)) {
		if (x2 + y2 < xx2 + yy2 + 1.00001) ans2 = 2;
		else ans2 = 3;
	}
	else {
		if (x2 + y2 < xx2 + yy2 + 1.00001) ans2 = 4;
		else ans2 = 1;
	}

	if (m1 == 2) {
		if (ans1 == 2) ans1 = 3;
		else if (ans1 == 3) ans1 = 4;
		else if (ans1 == 4) ans1 = 2;
	}
	else if (m1 == 3) {
		if (ans1 == 2) ans1 = 4;
		else if (ans1 == 3) ans1 = 2;
		else if (ans1 == 4) ans1 = 3;
	}

	if (m2 == 2) {
		if (ans2 == 2) ans2 = 3;
		else if (ans2 == 3) ans2 = 4;
		else if (ans2 == 4) ans2 = 2;
	}
	else if (m2 == 3) {
		if (ans2 == 2) ans2 = 4;
		else if (ans2 == 3) ans2 = 2;
		else if (ans2 == 4) ans2 = 3;
	}
	if (ans1 == ans2) printf("YES\n");
	else printf("NO\n");
	return 0;
}





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


int main(){

string s;
cin >> s;
string ans = "ABC";
if(s == "ABC"){
    ans = "ARC";
}

cout << ans << endl;


}

Measured memory_bytes: 3596
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(n):
  if arr1[i]>arr2[i]:
    cnt2+=arr1[i]-arr2[i]
  elif arr1[i]<arr2[i]:
    if (arr2[i]-arr1[i])%2==0:
      cnt1+=(arr2[i]-arr1[i])//2
    else:
      cnt1+=(arr2[i]-arr1[i])//2+1
      cnt2+=1
if cnt1>=cnt2:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 4600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b/2;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
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; }

const long long INF = 1LL<<60;

int main() {
    int x[5];
    rep(i, 5) cin >> x[i];

    rep(i, 5) {
        if(x[i]==0) {
            print(i+1);
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n;
    int x[9]={0};
    scanf("%d", &n);
    rep(i, 0, n){
        int a, b;
        scanf("%d", &a);
        b = a/400;
        if(b > 8){
            b = 8;
        }
        x[b]++;
    }
    int p=0;
    rep(i, 0, 8){
        //printf("%d ", x[i]);
        if(x[i] > 0){
            p++;
        }
    }
    if(p==0){
        p=1;
        x[8]--;
    }
    printf("%d %d", p, p+x[8]);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
int main()
{
    int N;
    scanf("%d",&N);
    
    if (N == 1)
    {
        printf("Hello World");
    }
    
    else
    {
        int A,B;
        scanf("%d %d",&A, &B);
        printf("%d", A+B);
    }
}

Measured memory_bytes: 128
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, m, p, i, sum;
    int[] x;

    for(;;){
      n = sc.nextInt(); m = sc.nextInt(); p = sc.nextInt();
      if(n == 0 && m == 0 && p == 0)break;

      x = new int[n]; sum = 0;
      for(i = 0;i < n;i++){
        x[i] = sc.nextInt(); sum += x[i];
      }
      if(x[m - 1] == 0)out.println("0");
      else out.println(sum * (100 - p) / x[m - 1]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 25036
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  int ans = 1;
  int ans_count = 0;
  
  for(int i = 1; i <= n; ++i){
    int count = 0;
    int tmp = i;
    while(tmp > 0){
      if(tmp % 2 == 0) count++;
      else break;
      tmp /= 2;
    }
    if(ans_count < count){
      ans = i;
      ans_count = count;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#include <map>
#include <set>
// vecのなかの全要素について座標圧縮を行い、元座標->圧縮後座標というmapを作る
// O(NlogN) 座圧後のサイズを返す
// org: もともとの各iに対する座標 値渡しなので破壊しません
// zip: 圧縮
// unzip: 復元
template <typename T>
int compress(vector<T> org, map<T, int> &zip, vector<T> &unzip) {
    sort(org.begin(), org.end()); 
    org.erase(unique(org.begin(), org.end()), org.end()); // vecの各要素を小さい順に重複を無くして並べたもの
    int i = 0;
    for (auto &oi : org) {
        zip[oi] = i;
        unzip.push_back(oi);
        i++;
    }
    return i;
}

// 和以外はseg木でよくねという発想の元、和のみを実装
#include <cassert>
template <typename T>
class BIT {
    const int n;
    vector<T> tree;

public:
    BIT(int _n) : n(_n), tree((size_t)_n, 0) {}

    // v[a] += w
    template <typename ID>
    void add(ID a, T w) {
        assert(0 <= a); assert(a < n);
        for (int i = (int)a; i < n; i |= (i + 1)) 
            tree[(size_t)i] += w;
    }

    // v[0] + v[1] + ... + v[a-1]
    template <typename ID>
    T sum(ID a) {
        assert(0 < a); assert(a <= n);
        T res = 0;
        for (int i = (int)a - 1; i >= 0; i = (i & (i + 1)) - 1)
            res += tree[(size_t)i];
        return res;
    }

    // v[0] + v[1] + ... + v[a] >= w なる最小のa
    int lower_bound(T w) {
        int x = 0, beki = 1;
        for (int _n=n; _n>0; _n>>=1) beki <<= 1;
        for (int k=beki; k>0; k>>=1) {
            if (x + k <= n && tree[(size_t)(x + k - 1)] < w) {
                w -= tree[(size_t)(x + k - 1)];
                x += k;
            }
            //cerr << k << ' ' << x << ' ' << tree[x] << '\n';
        }
        return x;
    }

    // set(被りなし)としての機能を見やすく
    // ただし同じものをたとえば二回pushする場合、値が+2となって一回のpopでは消えないというバグあり
    template <typename ID>
    void push(ID a) { add(a, 1); }

    template <typename ID>
    void pop(ID a) { add(a, -1); }
};

int main() {
    int n;
    long k;
    cin >> n >> k;
    long rui[n+1], a, s=0;
    rui[0] = 0;
    for (int i=1; i<=n; i++) {
        cin >> a;
        s += a - k;
        rui[i] = s;
    }
    map<long, int> zip;
    vector<long> unzip;
    n = compress(vector<long>(rui, rui+n+1), zip, unzip);
    BIT<int> bit(n);
    long sum = 0;
    for (auto r:rui) {
        int i = zip[r];
        sum += (long)bit.sum(i+1);
        bit.push(i);
    }
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 17392
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int n;
  cin>>n;
  vvi a(n,vi(3));
  rep(i,n) rep(j,3) cin>>a[i][j];
  vvi dp(n+1,vi(3));
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(j==k) continue;
        maxs(dp[i+1][j],dp[i][k]+a[i][j]);
      }
    }
  }
  int ans=dp[n][0];
  rrep(i,2){
    maxs(ans,dp[n][i]);
  }
  cout<<ans<<endl;
} 

Measured memory_bytes: 14084
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const int INF = 1e9 + 5;

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

	vector<vector<int>> arr(n, vector<int>(3));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> arr[i][j];
		}
	}

	vector<vector<int>> dp(n, vector<int>(3));
	for (int i = 0; i < 3; i++)
	{
		dp[0][i] = arr[0][i];
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (j == 0)
			{
				dp[i][j] = arr[i][j] + max(dp[i - 1][j + 1], dp[i - 
				1][j + 2]);
			}
			else if (j == 1)
			{
				dp[i][j] = arr[i][j] + max(dp[i - 1][j - 1], dp[i - 
				1][j + 1]);
			}
			else
			{
				dp[i][j]= arr[i][j] + max(dp[i - 1][j -1],dp[i -1][j - 
				2]);
			}
		}
	}

	cout << *max_element(dp[n- 1].begin(), dp[n -1].end());
}

Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		
		if(p[1] == 0)
		{
			Console.WriteLine(p[0]);
			return;
		}
		var a = Input().ToInt();
		int ind = 0;
		Array.Sort(a);
		int min = 999;
		int minInd = 999;
		for(int i = -100; i <= 101; i++)
		{
			if(ind < a.Length && i == a[ind])
			{
				ind++;
				continue;
			}
			if(Math.Abs(i-p[0]) <= min)
			{
				int min2 = Math.Min(Math.Abs(i-p[0]), min);
				
				if((min2 == min && minInd > i) || min2 < min)
				{
					minInd = i;
					min = min2;
				}
			}
		}
		Console.WriteLine(minInd);
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27172
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template
#pragma region factorization 1.0
map<ll, ll> factorization(ll x)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= x; ++i)
    {
        while (x % i == 0)
        {
            ++res[i];
            x /= i;
        }
    }
    if (x > 1)
    {
        ++res[x];
    }
    return res;
}
#pragma endregion factorization

int main()
{
    IN(ll, N);
    auto p = factorization(N);
    ll ans = 0;
    for (auto [x, y] : p)
    {
        for (ll i = 1; i <= y; ++i)
        {
            ++ans;
            y -= i;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main(){
  long long n,sum,min,max;
  long long a[10004];
  cin>>n;
  cin>>a[0];
  min=a[0];
  max=a[0];
  sum=a[0];
  for(int i=1;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    if(max<a[i])max=a[i];
    if(min>a[i])min=a[i];
  }
  cout<<min<<' '<<max<<' '<<sum<<'\n';
  return 0;
}



Measured memory_bytes: 3188
def solve():
  s = input()
  n = len(s)
  dp = [[float("Inf")]*2 for _ in range(n+1)]
  dp[0][0] = 0
  dp[0][1] = 1

  for i in range(0,n):
    number = int(s[i])
    for j in range(2):
      if j==0:
        dp[i+1][0] = min([dp[i][0]+number,dp[i][0]+(10-number)+1,dp[i+1][0]])
        if number != 9:
          dp[i+1][1] = min([dp[i][0]+number+1,dp[i][0]+(10-number),dp[i+1][1]])
      else:
        dp[i+1][0] = min(dp[i][1] +(10-number),dp[i+1][0])
        dp[i+1][1] = min(dp[i][1] + (10-number-1),dp[i+1][1])
        
  #print(dp)
  print(min(dp[n][0],dp[n][1]+1))
solve()

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

using namespace std;
using ll =long long;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(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 leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
//printfを使うときは上を削除
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	

//宣言だけしとく
int N,M,H,W,K,A,B;
string S;
//ここから書き始める

//dfs用にグラフを作る
struct Edge {
	int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c=-1, int p =-1){
	int k = 1;
	//どっから来たのかを表すp、デフォルトとして-1
	rep(i,g[v].size()){
		int u = g[v][i].to, ei = g[v][i].id;
		if( u == p ) continue;//親に伸びてるやつだったらコンティニューJ
		if( k == c) ++k;
		ans[ei] = k; k++ ;//親以外のものを一個ずつ入れてやる
		dfs(u,ans[ei],v);
	}
}
int main()
{
	cout << setprecision(10);
	int n ;
	cin >> n;
	//toは隣り合ってる頂点を記録したリスト
	g.resize(n);
	ans = vector<int> (n-1);
	rep(i,n-1){
		int a, b;
		cin >> a >> b;
		-- a; --b;
		// 0 index;
		g[a].push_back((Edge){b,i});
		g[b].push_back((Edge){a,i});

	}
	dfs(0);
	int mx = 0 ;
	rep(i,n) mx = max(mx,int(g[i].size()));
	cout << mx << endl;
	rep(i,n-1){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 8320
N = int(input())
A = [int(x) for x in input().split()]

def f():
    As = sorted(A)
    if N % 2:
        if As[0] != 0: return 0
        if any((i // 2 + 1)*2 != a for i,a in enumerate(As[1:])): return 0
    else:
        if any((i // 2)*2 + 1 != a for i,a in enumerate(As)): return 0
    return pow(2, N//2, 10**9 + 7)

print(f())

Measured memory_bytes: 13880
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

  	Int R; cin >> R;
    if (R < 1200) cout << "ABC" << endl;
    else if (R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<vector<ll> >  grid;
int r,c,k;
ll dp[3001][3001][4];
ll rec(int i,int j,int col)
{
    if(i>r||j>c) return 0;
    // if(i==r&&j==c)
    // {
    //     if(grid[i][j]!=0&&col<3) return dp[i][j][col]=max(grid[i][j],(ll)0);
    //     else return dp[i][j][col]=0;
    // }
    if(dp[i][j][col]!=-1) return dp[i][j][col];

    if(col==3) 
    {
        ll l1=0,l2=0;
       l1=rec(i+1,j,0);
       l2=rec(i,j+1,col);
        return dp[i][j][col]=max(l1,l2);
    }
    else
    {
        ll l1=0,l2=0,l3=0,l4=0,l5;
        if(grid[i][j]) 
        {
            l1= rec(i,j+1,col+1)+grid[i][j];
            l2=rec(i+1,j,0)+grid[i][j];
        }
        l3=rec(i,j+1,col);
        l4=rec(i+1,j,0);
    //    l5=max(l1,l2);
    //    l5=max({l5,l3,l4});
        l5=max({l1,l2,l3,l4});
       return dp[i][j][col]=l5;
    }
    

}
int main()
{
    cin>>r>>c>>k;
    grid.resize(r+1,vector<ll>(c+1,0));
    memset(dp,-1,sizeof dp);
    for(int i=0;i<k;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        grid[x][y]=z;

    }
    cout<<rec(1,1,0);
    
}

Measured memory_bytes: 356220
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n,k; cin >> n >> k;
    vector< int > v(n);

    for(int i=0;i<n;i++) cin >> v[i];

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

    int sum =0;
    for(int i=0;i<k;i++)
        sum+=v[i];
    cout << sum << endl;



    #ifdef TarekHasan
        main();
    #endif // TarekHasan

    return 0;
}


Measured memory_bytes: 3184
n,m = map(int,input().split())
if m % 2 == 0:
    for i in range(m // 2):
        print(*[i+1,m + 1 - i])
    for i in range(m // 2):
        print(*[ m + 2 + i, 2 * m + 1 - i])
else:
    for i in range((m - 1) // 2 ):
        print(*[i + 1, m -i])
    for i in range((m+1) // 2):
        print(*[m + 1 + i, 2 * m + 1 -i])

Measured memory_bytes: 9284
def prime_judge(n):
         for i in range(2,int(n**(1/2))+1):
                  if n % i == 0:
                           judge = False
                           break
         else:
                  judge = True
         return judge
x = 10**5
prime_similler = [0] * x
for i in range(3,x+1,2):
         if prime_judge(i) and prime_judge((i+1)//2):
                  prime_similler[i-1] = 1
ruiseki = [0]
for i in range(x):
         ruiseki.append(ruiseki[i] + prime_similler[i])
q = int(input())
for i in range(q):
         l,r = map(int,input().split())
         print(ruiseki[r] - ruiseki[l-1])







Measured memory_bytes: 7340
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, Q; cin >> N >> Q;
    vector<long long> A(N); for (auto& a : A) cin >> a;
    sort(begin(A), end(A));
    vector<long long> B(N), C(N);
    B[0] = A[0];
    for (int i = 1; i < N; i++) B[i] = B[i-1] + A[i];
    C[0] = A[0]; C[1] = A[1];
    for (int i = 2; i < N; i++) C[i] = C[i-2] + A[i];
    for (int i = 0; i < Q; i++) {
        int x; cin >> x;
        auto it = lower_bound(begin(A), end(A), x);
        if (it == end(A)) {
            cout << C[N-1] << '\n';
            continue;
        }
        if (it == begin(A)) {
            cout << B[N-1] - B[N / 2 - 1] << '\n';
            continue;
        }
        int ng = distance(begin(A), it)-1, ok = N-1;
        while (ok - ng > 1) {
            int mid = (ng + ok) / 2;
            int k = N - (N-mid) - (N-mid) + 1;
            if (k >= 0 && abs(A[mid] - x) >= abs(A[k] - x)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        int k = N - (N-ok) - (N-ok) + 1 - 2;
        cout << B[N-1] - B[ok-1] + (k >= 0 ? C[k] : 0) << '\n';
    }
    return 0;
}

Measured memory_bytes: 4096
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]

ans = []
for i in range(N - 1):
    cnt = 0
    for j in range(i, N - 1):
        if cnt < X[j][1]:
            st = X[j][1]
        elif cnt % X[j][2] == 0:
            st = cnt
        else:
            st = cnt + X[j][2] - (cnt % X[j][2])
        cnt = st + X[j][0]
    ans.append(cnt)
ans.append(0) 
print(*ans, sep='\n')

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    long long a, b;

    cin >> a >> b;

    string s;

    if(a <= 0 && 0 <= b)
    {
        s = "Zero";
    }
    else if(a >= 0 && b >= 0)
    {
        s = "Positive";
    }
    else
    {
        s = (b - a) % 2 == 0 ? "Negative" : "Positive";
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    ll K;
    cin >> K;

    for (int i = 0; i < K; i++) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }

    cout << '1' << endl;

    return 0;
}


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

using namespace std;

struct Node{
	int son[26], val[26];
}t[maxn];

int cnt = 0;

int n;
string s[maxn];
int a[26];
int id[maxn];

void add(string s, int I){
	for(int i = 0;i < s.length();i++) a[s[i] - 'a']++;
	int x = 0;
	for(int i = s.length() - 1;~i;i--){
		for(int j = 0;j < 26;j++) if(a[j]) t[x].val[j]++;
		if(!t[x].son[s[i] - 'a']) t[x].son[s[i] - 'a'] = ++cnt;
		x = t[x].son[s[i] - 'a'];
		if(i == 1) id[I] = x;
		a[s[i] - 'a']--;
	}
}

long long ans;

int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++) cin >> s[i], add(s[i], i);
	for(int i = 1;i <= n;i++){
		ans += t[id[i]].val[s[i][0] - 'a'] - 1;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 239400
#include <bits/stdc++.h>
#define ll long long
#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++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> switches(n);
  REP(i, n)
      cin >> switches.at(i);

  int cnt = 0;
  REP(i, n)
  {
    if (switches.at(cnt) == 2)
    {
      cout << i + 1 << "\n";
      return (0);
    } else {
      cnt = switches.at(cnt) - 1;
    }
  }

  cout << -1 << "\n";

  return (0);
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, k;
    ll s;
    cin >> n >> k >> s;
    int cnt = 0;
    rep(i, n) {
        if ( i != 0 ) cout << " ";
        ll out_num = ( s < 1e9 ) ? s + 1 : 1;
        if ( cnt >= k ) {
            cout << out_num;
        }
        else {
            cout << s;
        }
        ++cnt;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] v = {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};
		System.out.println(v[sc.nextInt()-1]);
		
		sc.close();
	}
}


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

ll gcd(ll a,ll b){
  if(a%b == 0)return b;
  return gcd(b,a%b);
}

int main(void){
  ll a,b;
  cin >> a >> b;
  
  ll work = gcd(a,b);
  //  cout << work << endl;
  
  ll ans = 1,tmp = work;
  for(ll i=2;i*i <= work;i++){
	if(work%i == 0){
	  while(work%i == 0)work/=i;
	  ans++;
	  if(i*i == work) i--;
	}
  }
  if(work != 1) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256