akhauriyash/Code-Regression huggingface dataset:
fn main(){
    let inp: Vec<usize> = read_vec();
    let mut graph = vec![Vec::new(); inp[0]];
    for _ in 0..inp[0]-1 {
        let edge: Vec<usize> = read_vec();
        graph[edge[0]-1].push(edge[1]-1);
        graph[edge[1]-1].push(edge[0]-1);
    };

    let mut weights = vec![0; inp[0]];
    for _ in 0..inp[1] {
        let inp: Vec<usize> = read_vec();
        weights[inp[0]-1] += inp[1];
    }

    let mut seen = vec![false; inp[0]];


    let mut tree = Tree {
        n: inp[0],
        tree: graph,
        w: weights,
        seen :seen,
    };

    tree.main();
}

struct Tree {
    n: usize,
    tree: Vec<Vec<usize>>,
    w: Vec<usize>,
    seen: Vec<bool>,
}

impl Tree {
    fn main(&mut self){
        let tree = self.tree.clone();
        self.seen[0] = true;
        for &e in &tree[0] {
            self.seen[e] = true;
            self.w[e] += self.w[0];
            self.dfs(&e, &tree);
        }
        for (i, weight) in self.w.iter().enumerate() {
            if i < self.n-1 {
                print!("{} ", weight);
            } else {
                print!("{}", weight);
            }
        }
    }

    fn dfs(&mut self, e: &usize, tree: &Vec<Vec<usize>>){
        for &f in tree[*e].iter(){
            if self.seen[f] { continue };
            self.seen[f] = true;
            self.w[f] += self.w[*e];
            self.dfs(&f, tree);
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 41468
import sys
N = int(input())
A = [[0] * (N-1)]+[list(map(int,input().split())) for _ in range(N)]

idx = [0] * (N+1)
cnt = 0
day = 0
flag_max = [False] * (N+1)
looplist = list(range(1,N+1))
while cnt != N:
    
    error = True
    flag =[False] * (N+1)
    nxtlst = []
    
    while looplist:
        
        i = looplist.pop()
        if (flag[i]) or flag_max[i]:continue
        tmp = A[i][idx[i]]
        if (flag[tmp]) or flag_max[tmp]:continue
    
        if A[tmp][idx[tmp]] == i:
            nxtlst.append(i)
            nxtlst.append(tmp)
            idx[tmp] = idx[tmp] + 1
            idx[i] = idx[i] + 1
            if idx[tmp] == N-1:
                flag_max[tmp] = True
                cnt += 1
            if idx[i] == N-1:
                flag_max[i] = True
                cnt += 1
            flag[i] = True
            flag[tmp] = True
            error = False
    looplist = nxtlst
    if error:
        print(-1)
        sys.exit()
    
    day += 1
            

    if day > 10000:
        print(N*(N-1)//2)
        sys.exit()
    
    
print(day)
    
    


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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 1E5 + 10;

int n;
ll L;
int a[N], b[N];

int n2;
int s[N * 2 + 2];

void update(int i){
	for (; i <= n2; i = (i | i - 1) + 1)
		++s[i];
}

int query(int i){
	int ret = 0;
	for (; i > 0; i &= i - 1)
		ret += s[i];
	return ret;
}

ll check(int m){
	b[0] = 0;
	for (int i = 1; i <= n; ++i)
		b[i] = a[i] >= m ? 1 : -1;

	partial_sum(b, b + n + 1, b);
	n2 = n * 2 + 1;
	fill_n(s + 1, n2, 0);
	ll ret = 0;
	for (int i = 0; i <= n; ++i){
		b[i] += n + 1;
		ret += query(b[i]);
		update(b[i]);
	}
	return ret;
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);

	ll L = (n * (n + 1ll) / 2 + 1) / 2;
	int low = 1, high = 2e9;
	while (low < high){
		int mid = low + (high - low >> 1);
		if (check(mid) >= L)
			low = mid + 1;
		else
			high = mid;
	}
	printf("%d\n", low - 1);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
int main()
{
     int w, a, b;

     std::cin >> w;
     std::cin >> a;
     std::cin >> b;

     if(abs(a - b) > w){
          std::cout << abs(a - b) - w << std::endl;
     }
     else{
          std::cout << 0 << std::endl;
     }
     return 0;
}


Measured memory_bytes: 256
flag = 1
s = input()
d = {}
for i in s:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

for key in d:
    if d[key] %2 != 0:
      flag = 0     
if flag == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9052
#include<iostream>
#include<iomanip>
#include<math.h>

//関数の宣言
void xSwap(double& x1, double& x2);
void ySwap(double& y1, double& y2);

int main()
{
	double x1;
	double x2;
	double y1;
	double y2;

	std::cin >> x1 >> y1 >> x2 >> y2;

	xSwap(x1, x2);
	ySwap(y1, y2);

	double base;
	double height;

	base = x1 - x2;
	height = y1 - y2;

	double hypotenuse;
	double ans;

	hypotenuse = base*base + height*height;
	ans = sqrt(hypotenuse);

	std::cout << std::fixed << std::setprecision(20) << ans << std::endl;

	return 0;
}

//関数の定義
void xSwap(double& x1, double& x2){
	if (x1 < x2){
		double tmp;

		tmp = x1;
		x1 = x2;
		x2 = tmp;
	}
}

void ySwap(double& y1, double& y2){
	if (y1 < y2){
		double tmp;

		tmp = y1;
		y1 = y2;
		y2 = tmp;
	}
}


Measured memory_bytes: 3276
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;
 
public class Main {
	public static void main(String[] args) {
		Scanner ob=new Scanner(System.in);
	int n=ob.nextInt();
	int k=0;
	for(int i=0;i<n;i++)
	{
	int a=ob.nextInt();
	int b=ob.nextInt();
	if(a==b){k++;}
	else{k=0;}
	if(k==3){System.out.println("Yes");System.exit(0);}
	}
		System.out.println("No");
	}
}

Measured memory_bytes: 27284
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int L;
string s;

int main() {
    cin >> L >> s;
    int ans = 0;
    rep(i,L) {
        if (s[i] != '.') continue;
        int x = 0;
        for (int j = i+1; j < L; j++) {
            if (s[j] == 'W') continue;
            if (s[j] == 'B') x++;
            break;
        }
        for (int j = i-1; j >= 0; j--) {
            if (s[j] == 'W') continue;
            if (s[j] == 'B') x++;
            break;
        }
        if (x == 2) continue;
        int y1 = 0;
        for (int j = i+1; j < L; j++) {
            if (s[j] == 'W') {
                y1 *= -1;
                break;
            }
            if (s[j] == 'B') y1--;
            if (s[j] == '.') {
                y1 = 0;
                break;
            }
        }
        int y2 = 0;
        for (int j = i-1; j >= 0; j--) {
            if (s[j] == 'W') {
                y2 *= -1;
                break;
            }
            if (s[j] == 'B') y2--;
            if (s[j] == '.') {
                y2 = 0;
                break;
            }
        }
        ans = max(ans, max(y1,y2));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3212
import heapq
n,m = map(int,input().split())
dp = [0]*(n+1)
L = []
days = []
cost = []
for i in range(n):
    a,b = map(int,input().split())
    if a > m:
        continue
    L.append([a,b])

L.sort(reverse = True)

ans = 0
li = []
for i in range(1,m+1):
    while L and L[-1][0] <= i:
        (a,b) = L.pop()
        heapq.heappush(li,b*(-1))

    if li:
        h = heapq.heappop(li)
        ans +=(-1)*h

print(ans)

Measured memory_bytes: 21128
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >>n;
  vector<int> vec(n);
  for (int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  int j=1;
  int i=0;
  while (i<n) {
    j=vec.at(j-1);
    i++;
    if (j==2) break;
  }
  if (j==2) cout << i <<endl;
  else cout << -1 <<endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		StringBuilder value = new StringBuilder();
		for (int i = 0; i < n.length(); i++) {
			switch (n.charAt(i)) {
				case '1' :
				value.append('9');
				break;
				case '9' :
				value.append('1');
				break;
				default :
				value.append(n.charAt(i));
			}
		}
		System.out.println(value);
	}
	
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
const int INF = 0x3f3f3f3f;
const int maxn=52+7;
char str[2][maxn];
const int mod=1000000007;
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    scanf("%s",str[0]);
    scanf("%s",str[1]);
    //puts(str[0]);  puts(str[1]);
   ll ans=1;
   int flag=-1;
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			 if(str[0][0]==str[1][0]) { ans*=3;flag=1;}
			 else { ans*=6;flag=0;i++;}
		}
		else if(flag==1) //前一个是/ 
		{
			if(str[0][i]==str[1][i]) 
			{
				ans*=2;
				flag=1; 
			}	
			else
			{
				ans*=2;
				flag=0;
				i++;
			}
		}
		else if(flag==0)//前一个是- 
		{
			if(str[0][i]==str[1][i]) { ans=ans; flag=1; }
			else 
			{
				ans*=3;
				i++;
				flag=0;
            }
		}
		
		ans%=mod;
	}
	cout<<ans;
	return 0;
} 

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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second

inline int in(){int x, y; y = scanf("%d", &x); return x; }

const int N = 200002, E = 200002;

vector <int> g[N];
vector <pair<int, int>> ces;
int up[N], h[N], from[E], to[E];
bool mark[N], iscv[N];

int cecvme(int v, int pare = -1) // With multiple edge
{
	up[v] = h[v];
	mark[v] = true;
	int children = 0;
	for(int e : g[v])
		if(e != pare)
		{
			int u = to[e] ^ from[e] ^ v;
			if(mark[u])
				up[v] = min(up[v], h[u]);
			else
			{
				h[u] = h[v] + 1;
				up[v] = min(up[v], cecvme(u, e));
				if(up[u] >= h[v] && pare != -1)
					iscv[v] = true;
				children++;
			}
		}
	if(pare != -1 && up[v] == h[v])
		ces.push_back({from[pare] ^ to[pare] ^ v, v}); // pare
	if(pare == -1 && children > 1)
		iscv[v] = true;
	return up[v];
}
 
int cecv(int v, int par) // Without multiple edge
{
	up[v] = h[v];
	mark[v] = true;
	int children = 0;
	for(int u : g[v])
	{
		if(mark[u] && u != par)
			up[v] = min(up[v], h[u]);
		if(!mark[u])
		{
			h[u] = h[v] + 1;
			up[v] = min(up[v], cecv(u, v));
			if(up[u] >= h[v] && h[v] > 0)
				iscv[v] = true;
			children++;
		}
	}
	if(h[v] > 0 && up[v] == h[v])
		ces.push_back({par, v});
	if(h[v] == 0 && children > 1)
		iscv[v] = true;
	return up[v];
}

int main()
{
	int n = in(), m = in();
	for(int i = 0; i < m; i++)
	{
		int u = in(), v = in();
		g[u].push_back(i);
		g[v].push_back(i);
		from[i] = u;
		to[i] = v;
	}
	h[0] = 0;
	cecvme(0, -1);
	for(int i = 0; i < n; i++)
		if(iscv[i])
			cout << i << endl;
}



Measured memory_bytes: 9956
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if Al <= len:
                Al = len
                At = tim
        elif l[2] == 1:
            if Bl <= len:
                Bl = len
                Bt = tim
    last = l

if Al != -1:
    print("{0:.10f}".format(round(Al,10)), end = " ")
    print("{0:.10f}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.10f}".format(round(Bl,10)), end = " ")
    print("{0:.10f}".format(Bt/60))
else:
    print("-1 -1")

Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a,b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int a[201][3],d[3][101],b[201];

int main() {
  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    for(int j=0,x; j<3; j++) {
      cin >> x;
      a[i][j]=x;
      d[j][x]++;
    }
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<3; j++) {
      if(d[j][a[i][j]]==1) b[i]+=a[i][j];
    }
  }
  for(int i=0; i<n; i++) cout << b[i] << endl;
  return 0;
}


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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x, y = input_to_int_map()

    for i in range(0, x + 1):
        kame = i
        turu = x - i

        if ((kame * 4) + (turu * 2)) == y:
            return "Yes"

    return "No"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9204
#include "bits/stdc++.h"

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q;
	cin >> n; vi s(n);
	REP(i, n) cin >> s[i];

	cin >> q; vi t(q);
	REP(i, q) cin >> t[i];

	int c = 0;

	bool flag = false;
	REP(i, q) {
		REP(j, n) {

			if (c >= n) {
				flag = true;
				break;
			}

			if (t[i] == s[j]) {
				c++;
				break;
			}
		}

		if (flag) break;
	}

	cout << c << "\n";
	return 0;
}

Measured memory_bytes: 3264
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N) {
		cout<<(N<=999?"ABC":"ABD")<<endl;
	}
	
	return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f,a||b||c||d||e||f){
        a+=d;b+=e;c+=f;

        int t=min(min(a,b),c);
        int ma=0;
        for(int i=max(t-2,0ll);i<=t;i++){
            chmax(ma,i+(a-i)/3+(b-i)/3+(c-i)/3);
        }
        cout<<ma<<endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	int N,M;
	int i,j,k,l;
	long long int B = 0;
	multiset<int> S;
	cin >> N;
	cin >> l >> j >> k;
	B += k;
	S.insert(j);
	auto pos = S.begin();
	int cur = j;
	//同じ値なら左に行く
	int left = 0;
	int right = 0;
	long long int total = 0;
	for(i=1;i<N;++i)
	{
		cin >> l;
		if(l==1)
		{
			cin >> j >> k;
			B += k;
			S.insert(j);
			total += ABS(cur-j);
			if(cur <= j)
				right++;
			else
				left++;

			if(right > left + 1 && pos != S.end())
			{
				pos ++;
				total -= (right-left-1)*(*pos-cur);
				right --;
				left++;
				cur = *pos;
			}
			else if(right < left && pos != S.begin())
			{
				pos--;
				total += (left-right-1)*(cur-*pos);
				right++;
				left--;
				cur=*pos;
			}
		} 
		else
		{
			cout << *pos << " " << total+B << endl;
		}
	}

	return 0;
}




































Measured memory_bytes: 9600
N = int(input())
l = []
for i in range(N):
  s = int(input())
  l.append(s)
l.sort()
M = sum(l)
if M % 10 == 0:
  for i in range(N):
    if l[i] % 10 != 0:
      M -= l[i]
      break
  if M % 10 == 0:
    print(0)
  else:
    print(M)
else:
  print(M)

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

int main() {
	long int n, sum=0;
	long int b[100001] = { 0 };

	scanf("%ld",&n);
	for (int i = 1; i <= n-1; i++) {
		scanf("%ld",&b[i]);
		if (i == 1)
			sum += b[i];
		else {
			if (b[i - 1] >= b[i])
				sum += b[i];
			else sum += b[i - 1];
		}
	}
	printf("%ld", sum+b[n-1]);
}

Measured memory_bytes: 896
#include <iostream>

#define rep(i, n) for (i = 1; i <= n; i++)

using namespace std;

using ll = long long;

int main() {
	int n;
	cin >> n;
	
	int i;
	ll res = 0;
	rep(i, n) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		res += i;
	}
	
	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll MOD = 1e9 + 7;

vector<vector<ll>> dp(1000 + 10, vector<ll>(1000 + 10));

int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(auto &s : S) cin >> s;
    dp[0][0] = 1;
    for(ll i = 0; i < H; i++){
        for(ll j = 0; j < W; j++){
            if(S[i][j] == '#'){
                dp[i][j] = 0;
                continue;
            }
            if(i > 0) (dp[i][j] += dp[i - 1][j]) %= MOD;
            if(j > 0) (dp[i][j] += dp[i][j - 1]) %= MOD;
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}


Measured memory_bytes: 9344
x,y=map(int,input().split())

if (x+y)%3!=0 or x*2<y or y*2<x :
    print(0)
    exit()

a=(2*x-y)//3
b=(2*y-x)//3

# ans = math.factorial(a+b)/math.factorial(a)
# ans=1
# for i in range(a+1,a+b+1):
#     ans*=i%(10**9+7)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = cmb(a+b,a,p)

print(ans)


Measured memory_bytes: 127704
#include <iostream>
using namespace std;
int main(){
    int n,i,j;
    string w[100],p="Yes";
    cin >>n;
    for(i=0;i<n;i++){
        cin >>w[i];
        if(p=="Yes"){
        if(i!=0&&w[i][0]!=w[i-1][w[i-1].size()-1]){
            p="No";
        }
        else{
            for(j=0;j<i;j++){
                if(w[i]==w[j])
                    p="No";
            }
        }
        }
        else
            continue;
    }
    cout <<p;
}


Measured memory_bytes: 256
#include<cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define  LL long long
const double g = -9.8;
const int maxn = 1e5+555;
 
int main()
{
	char s[maxn];
	scanf("%s",s);
	int ll=strlen(s);
	int ans=ll/2;
	int l,r;
	while(1){
		l=ll-ans;
		r=ans+1;
		int flag=1;
		int now=s[l-1];
		for(int i=l;i<r;i++){
			if(s[i]!=now){
				flag=0;
				break;
			}
		}
		if(!flag){
			break;
		}
		ans++;
	}
	printf("%d\n",ans);
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

#define MAX 10000007


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

    int n; cin >> n;
    vi v(n); FOR(i, n) cin >> v[i];

    map<ll, int> sum;

    ll ans = 0;
    FOR(i, n){
        if(i+1 >= v[i]){
            ans += sum[i+1LL-v[i]];
        }
        sum[i+1LL+v[i]]++;
    }
    cout << ans << '\n';

    return 0;
}


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

long long int return_xor_c(long long int a, long long int b){
    long long int xor_a_b = a^b;
    return xor_a_b;
}

void vector_remove(vector<long long int>& vec, long int index)
{
    vec.erase(vec.begin() + index);
}

int vector_finder(vector<long long int> vec,long long int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = distance( vec.begin(), itr );
  if (itr != vec.end()) {
      //cout << "fount " << endl;
    return index;
  }
  else {
      //cout << "not fount " << endl;
    return -1;
  }
}

int main(){
    vector<long long int> num_vec;
    long int N, index;
    long long int num, comp;
    long long int a, b, c, first_num;
    cin >> N;
    for(long int i=0; i<N; i++){
        cin >> num;
        num_vec.push_back(num);
    }
    first_num = num_vec[0];
    comp = first_num;
    for(long int i=1; i<N; i++){
        comp = comp^ num_vec[i];
    }
    if(comp == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
		a: [isize; n],
	}

	// x=ai-i とおく
	// bを自由に決め、abs(x-b)の総和を最小化する
	// bをxの中央値にすればよい

	let mut x = vec![0isize; n];
	for i in 0..n {
		x[i] = a[i] - i as isize -1;
	}
	x.sort();
	let b;
	if x.len() % 2 == 1 {
		b = x[x.len()/2];
	}
	else {
		b = (x[x.len()/2-1] + x[x.len()/2]) / 2;
	}

	let mut ans = 0isize;
	for i in 0..n {
		ans += (a[i]-(b+i as isize+1)).abs();
	}

	println!("{}", ans);
}


Measured memory_bytes: 7792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin >> n;
  vector<int>L(n+1); rep(i,n) cin >> L[i];
  L[n] = INF;
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i=0; i<=n-2; i++){
    for (int j=i+1; j<=n-1; j++){
      int Li_plus_Lj = L[i] + L[j];
      auto k_itr = lower_bound(L.begin(), L.end(), Li_plus_Lj);
      if (k_itr != L.end()){
        int k_index = k_itr - L.begin();
        ans += k_index-1-j;
      }
    }
  }
  cout << ans << endl;
}

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

int N, H, A[100000], B[100000];

int main(){
    cin >> N >> H;
    for(int i=0;i<N;i++)    cin >> A[i] >> B[i];

    int maxAi = 0;
    for(int i=0;i<N;i++){
        maxAi = max(maxAi, A[i]);
    }

    sort(B, B+N, greater<int>());

    int64_t ans = 0;
    for(int i=0;i<N;i++){
        if( maxAi < B[i] ){
            H -= B[i];
            ans++;
        }
        if( H <= 0 )   break;
    }

    if( 0 < H ){
        ans += H / maxAi;
        if( 0 < H % maxAi ) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iterator>
#define MAX 200001

using namespace std;

int main()
{
    int n;
    int m;
    int /*arr[MAX],*/ temp;
    vector<int> arr, brr;
    vector<int> vec;
    vector<int>::iterator itr ;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &temp);
        arr.push_back(temp);
    }

    scanf("%d", &m);
    for (int i = 0; i < m ; i++)
    {
        scanf("%d", &temp);
        brr.push_back(temp);
    }

    set_difference(arr.begin(), arr.begin() + n, brr.begin(), brr.begin() + m, back_inserter(vec));
    //vec.resize(itr - vec.begin());

    for (unsigned loop = 0; loop < vec.size(); loop++)
    {
        printf("%d\n", vec[loop]);
    }

    return 0;
}



Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL C[55][55];
void build(){
    REP(i,55){
        C[i][0]=1;
        REPP(j,1,i+1)C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
}
int main(){
    build();
    DRII(N,P);
    int d[2]={};
    REP(i,N){
        DRI(x);
        d[x&1]++;
    }
    LL an=0;
    REP(i,d[0]+1)REP(j,d[1]+1){
        if((j&1)==P){
            an+=C[d[0]][i]*C[d[1]][j];
        }
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
if S[0] != "A":
    print("WA")
    exit()
if S[2:-1].count("C") != 1:
    print("WA")
    exit()

dt = list(S)
dt.remove("A")
dt.remove("C")

if "".join(dt).islower():
    print("AC")
    exit()
else:
    print("WA")

Measured memory_bytes: 3060
//Bismillah hirrahmanir Rahim
    #include<bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define dbug printf("I am here\n");
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    using namespace std;
    int const mx=1e6;

    int main() {

    ll int a,b,c,d,tst;
    cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            return 0;
        }


    }

    if(a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

        return 0;
      }


Measured memory_bytes: 3620
N=int(input())
l=list(input())
r=0
g=0
b=0
for i in range(N):
    if l[i]=="R":
        r+=1
    if l[i]=="G":
        g+=1
    if l[i]=="B":
        b+=1
m=r*g*b
n=0
for i in range(N-1):
    for k in range(i+2,N+1,2):
        if k==N:
            break
        if l[i]==l[k]:
            n+=0
        else:
             if k==N-1:
                if l[int((k+i)/2)]!=l[k] and l[int((k+i)/2)]!=l[i]:
                      n+=1
                      break
                else:
                    break
             else:
                if l[int((k+i)/2)]!=l[k] and l[int((k+i)/2)]!=l[i]:
                      n+=1
m=m-n
print(m)

                





Measured memory_bytes: 68264
#include<iostream>
#include<cstdio>
#include<deque>
#include<string>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	int n,i,x;
	string s;
	deque<int> intlist;
	cin >> n;
	
	
	for(i=0;i<=n-1;i++){
		cin >> s;
		if (s=="insert"){
			cin >> x;
			intlist.push_front(x);
		}else if(s=="delete"){
			cin >> x;
			deque<int>::iterator it =intlist.begin();
			while (1){
				if (*it == x ){
					it=intlist.erase(it);
					break;
				}else if(it == intlist.end()){
					break;
				}
				it++;
			}
		}else if(s=="deleteFirst"){
			intlist.pop_front();
		}else if(s=="deleteLast"){
			intlist.pop_back();
		}
	}
	
	deque<int>::iterator it =intlist.begin();
	cout << *it;
	it++;
	while(1){
		if (it == intlist.end()){
			cout << "\n";
			break;
		}
		cout << " " << *it;
		it++;
	}
	
	return 0;
}

Measured memory_bytes: 5312
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A =nextInt();
		int B =nextInt();
		int C =nextInt();
		int K =nextInt();
		int ans =Math.min(A, K);
		K-=Math.min(A, K);
		K-=Math.min(B,K);
		ans-=Math.min(C, K);
		System.out.println(ans);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 25376
n = int(input())
lis = list(map(int, input().split()))

lis = sorted(lis, reverse = True)

a = 0
b = 0
for i in range(n):
    if i % 2 == 0:
        a += lis[i]
    else:
        b += lis[i]

print(a-b)

Measured memory_bytes: 9128
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
for d in range(1, D+1):
    s = list(map(int, input().split()))
    S += [s]
    maxs = float('-inf')
    maxi = -1
    cumsump = 0
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        cumsump += tmp
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        tmp2 = s[i] + cumsump - tmp
        if tmp2 > maxs:
            maxs = tmp2
            maxi = i
    ans += [maxi+1]
    last[maxi] = d
    prev_score += maxs


for dd in range(D):
    last = [0] * 26
    score = 0
    for d in range(1, D+1):
        if dd == (d-1):
            maxc = 0
            maxci = -1
            for i in range(26):
                cost = c[i] * (d - last[i])
                if maxc < cost:
                    maxc = cost
                    maxci = i+1
            prev_a = ans[dd]
            ans[dd] = maxci
        td = ans[d-1] - 1
        cumsump = 0
        for i in range(26):
            if td != i:
                tmp = -c[i] * (d - last[i])
                cumsump += tmp
        last[td] = d
        score += S[d-1][td]+cumsump
    if score <= prev_score:
        ans[dd] = prev_a
    else:
        prev_score = score
    
for a in ans:
    print(a)

Measured memory_bytes: 70596
import math

a, b, c = map(int, input().split())
c = math.radians(c)
s = a * b * math.sin(c) / 2
l = (a ** 2 + b ** 2 - 2 * a * b * math.cos(c)) ** (1/2) + a + b
h = s / a * 2

print(s)
print(l)
print(h)


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

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

    vector<int> data(n);
    for (auto& i : data)
    {
        cin >> i;
    }

    int numOdd = 0;
    int numMultiple4 = 0;
    for (const auto& i : data)
    {
        if (i%2)
            numOdd++;
        else if(i%4 == 0)
            numMultiple4++;
    }

    if (numOdd == 0 || numOdd+((n-numMultiple4-numOdd) ? 1 : 0) <= numMultiple4+1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    int res = 0;
    for (int i=0; i<N; i+=2) {
        if (a[i]%2 == 1) ++res;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge {
    LL from;
    LL to;
    LL cost;
};
edge es[EM];
LL d[EM];
LL N, M;

bool path(LL s){
    bool f = false;
    for(int i = 0;i < N;i++)    d[i] = -LINF;
    d[s] = 0;
    for(int j = 0;j < 2*N;j++){
        bool update = false;
        for(int i = 0;i < M;i++){
            edge e = es[i];
            if(d[e.from] != LINF && d[e.to] < d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
                if(j > N-1 && e.to == N-1)   f = true;
            }
        }
        if(!update) break;
    }
    return f;
}

int main(){
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int ai, bi, ci;
        cin >> ai >> bi >> ci;
        es[i] = edge{ai-1, bi-1, ci};
    }
    bool f = path(0LL);
    if(f)   cout << "inf" << endl;
    else    cout << d[N-1] << endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, n;
    cin >> a >> b >> n;
    if (b > n) cout << a * n / b << '\n';
    else cout << a * (n / b * b - 1) / b - (n / b * b - 1) / b * a << '\n';
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String S =sc.next();
        sc.close();

        int sum = 0;
        if(S.charAt(0) == 'A')
            sum++;
        int count = 0;
        for(int i = 2; i < S.length()-1; i++){
            if(S.charAt(i) == 'C'){
                count++;
            }
        }
        if(count == 1)
                sum++;
        int cnt = 0;
        for(int i = 1; i < S.length(); i++){
            if(S.charAt(i) - 'a' >= 0 && S.charAt(i) - 'a' <= 25){
                cnt++;
            }
        }
        if(cnt==S.length()-2)
                sum++;
        if(sum == 3)
            System.out.println("AC");
        else
            System.out.println("WA");
        
    }
}

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

using namespace std;

vector<int> t[111111];
int m = 1e9 + 7;
pair<int, int> f(int u, int v) {
	long r = 1, s = 1;
	for (int w : t[v]) {
		if (w == u) continue;
		auto p = f(v, w);
		(r *= p.second) %= m;
		(s *= p.first) %= m;
	}
	(r += s) %= m;
	return { r,s };
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		t[x].push_back(y);
		t[y].push_back(x);
	}
	cout << f(0, 1).first << endl;
	return 0;
}


Measured memory_bytes: 11520
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int calc(string& S, char x) {
    int N = S.size();
    int add = 0;
    if (N % 2 != 1) add = 1;
    int l_max = 0;
    rep(i, N/2 + add) {
        if (S[i] == x) l_max = i + 1;
    }
    int r_max = 0;
    for (int i = N - 1; i >= N / 2 + add; i--) {
        if (S[i] == x) r_max = N - i;
    }
    return min(N - l_max, N - r_max);
}

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

    cout << max(calc(S, '1'), calc(S, '0')) << endl;
    return 0;
}

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

int L[ 110 ];

int main()
{
int i;
int N;
int X;
int iSum;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> X;

	for( i = 0; i < N; i++ ) cin >> L[ i ];

	iSum = 0;
	for( i = 0; i < N; i++ )
	{
		iSum += L[ i ];
		if( iSum > X )
		{
			cout << i + 1 << endl;

			return 0;
		}
	}

	cout << i + 1 << endl;

	return 0;
}



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

vector<long> getArms(bool& isEven, long dist_max) {
    vector<long> arms;

    // 偶数なら長さ1の腕を追加
    if(isEven) arms.push_back(1);

    int i = 0;
    long dist_remain = dist_max;
    while (dist_remain > 0) {
        long arm_length = pow(2, i);
        dist_remain -= arm_length;
        arms.push_back(arm_length);
        i++;
    }
    return arms;
}

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

    vector<long> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i) >> y.at(i);
    }

    // 腕の長さを 1,2,4,8, ... 2^iとすれば
    // 2^(i+1)-1までのすべての奇数点に到達できる
    // 偶数点の場合は長さ1の腕を1本追加する

    // 1点目の偶奇を調べる
    int odd_even = ( abs(x.at(0)) + abs(y.at(0)) ) % 2;
    bool isEven = false;
    if( odd_even % 2 == 0 ) isEven = true; 

    // 一番遠い座標をもとめる
    // ついでに偶奇が一致するかチェック
    long dist_max = 0;
    for (int i = 0; i < n; i++) {
        long dist = abs(x.at(i)) + abs(y.at(i));
        
        // 偶奇チェック
        if (dist % 2 != odd_even) {
            cout << "-1" << endl;
            return 0;
        }

        // 更新
        if (dist > dist_max) dist_max = dist;
    }

    // 腕を設定
    vector<long> arms = getArms(isEven, dist_max);

    // 腕の情報を出力
    cout << arms.size() << endl;
    for (int i = 0, len = arms.size(); i < len; i++) {
        cout << arms.at(i);
        if (i != len-1) cout << " ";
    }
    cout << endl;

    // 各点について
    for (int i = 0; i < n; i++) {
        int xm = x.at(i);
        int ym = y.at(i);

        // 腕のパターン
        vector<char> ptn;
        
        // 後ろの腕から考える
        for (int i = arms.size()-1; i >= 0; i--) {
            // 腕の長さ
            long arm_length = arms.at(i);

            if ( abs(xm) > abs(ym) ) {
                // LR
                if ( xm > 0 ) {
                    // R
                    xm -= arm_length;
                    ptn.push_back('R');
                } else {
                    // L
                    xm += arm_length;
                    ptn.push_back('L');
                }
            } else {
                // UD
                if (ym > 0) {
                    // U
                    ym -= arm_length;
                    ptn.push_back('U');
                } else {
                    // D
                    ym += arm_length;
                    ptn.push_back('D');
                }
            }
        }
        reverse(ptn.begin(), ptn.end());
        
        // パターンを出力
        for (int i = 0; i < ptn.size(); i++) {
            cout << ptn.at(i);
        }
        cout << endl;
    }
    

}

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

int comp(const void *a,const void *b){  return *(int*)a-*(int*)b ; }
int main(){
  int N,A[1000000],a;
  long long int S=0;
  scanf("%d",&N);
  
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
    A[i]-=i;
  }

  qsort(A,N,sizeof(int),comp);

  a=A[N/2];
  for(int i=0;i<N;i++)
    S+=abs(A[i]-a);

  printf("%lld\n",S);

  return 0;

}


Measured memory_bytes: 3196
s=input()
a=0
b=0
c=len(s)
s='0'+s
s=s[::-1]
d=0
for i in range(c+1):
  if 0<b:
    if 4<int(s[i])+1:
      if 5==int(s[i])+1 and int(s[i+1])<5:
        a+=5
        b=0
      else:
        a+=(9-int(s[i]))
    else:
      a+=(int(s[i])+1)
      b=0
  else:
    if 4<int(s[i]):
      if int(s[i])==5 and int(s[i+1])<5:
        a+=5
      else:
        b+=1
        a+=(10-int(s[i]))
    else:
      a+=int(s[i])
print(a)

Measured memory_bytes: 5516
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

        if (a * b % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21972
n = int(input())
s = input()
list_num = []
for i in range(0, n):
  if i == 0:
    temp = s[1:].count("E")
    list_num.append(temp)
  else:
    temp = list_num[-1]
    if s[i] == "E":
      temp -= 1
    if s[i-1] == "W":
      temp += 1
    list_num.append(temp)
print(min(list_num)) 

Measured memory_bytes: 15544
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))

typedef vector<int> Ivec;
typedef pair<int, int> Pos;
const map<string, Pos> Dir = { //??????
	{ "N",{ 0,1 } },
	{ "S",{ 0,-1 } },
	{ "E",{ 1,0 } },
	{ "W",{ -1,0 } }
};
int main() {
	int n, m;
	
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		vector<Pos> jpos;
		for (int i = 0; n > i; i++) {
			int a, b;
			scanf("%d %d", &a, &b);
			jpos.push_back({ a,b });
		}

		Pos mpos = {10,10};
		scanf("%d", &m);
		for (int i = 0; m > i; i++) {
			char a[2];
			int b;
			scanf("%s %d", &a, &b);
			int &ch = (a[0] == 'E' || a[0] == 'W' ? mpos.first : mpos.second),
				gen = ch+(a[0] == 'E' || a[0] == 'W' ? Dir.at(a).first*b : Dir.at(a).second*b);
			int sign = Getsign(gen-ch);
			for (ch+=sign; sign*ch <= sign*gen; ch+=sign) {
				auto itr = find(jpos.begin(), jpos.end(), mpos);
				if (itr != jpos.end()) {
					jpos.erase(itr);
				}
			}
			ch-=sign;
		}
		if (jpos.size()) {
			printf("No\n");
		}
		else {
			printf("Yes\n");
		}
	}

	return 0;
}

Measured memory_bytes: 3140