akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
"""
i-j-k間が等しくなる組み合わせを求めてから、
Rの数*G*B - それ
で求まる？
"""
n = int(readline())
s = readline().rstrip().decode('utf-8')

if n == 3:
    print(0)
    exit()
dic1 = dict()
for i in s:
    if i in dic1:
        dic1[i] += 1
    else:
        dic1[i] = 1

if len(dic1) != 3:
    print(0)
    exit()
res = 1
for i in dic1.values():
    res *= i
#例外を求める
i = 0
x,y,z = 0,0,0
count = 0
while True:
    if i >= n:
        break
    j = 1
    while True:
        x = i
        y = i+j
        z = i+2*j
        if z >= n:
            break
        else:
            if s[x] != s[y] and s[x] != s[z] and s[y] != s[z]:
                count += 1 
        j += 1
        
    i += 1

print(res - count)

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

using namespace std;

int main(void) {
    int t;
    while (cin>>t && t) {
        vector<int> s(t);
        for (int i = 0; i < t; i++) cin >> s[i];
        int n;
        cin >> n;
        vector<int> d(101, 24);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            a--;
            d[a] = min(d[a], b);
        }
        
        vector<vector<int> > dp(101, vector<int>(t, 101));
        dp[0][0] = 0;
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < t; j++) {
                if (s[j] <= d[i]) dp[i+1][(j+1)%t] = min(dp[i+1][(j+1)%t], dp[i][j]);
                dp[i+1][1] = min(dp[i+1][1], dp[i][j]+1);
            }
        }
        cout << *min_element(dp[100].begin(), dp[100].end()) << endl;
    }
}

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

int main() {
	int a,b,c,d,s,e,ret;
	cin >> a >> b >> c >> d;
	if (a - c > 0) {
		s = a;
	}
	else {
		s = c;
	}

	if (b - d > 0) {
		e = d;
	}
	else {
		e = b;
	}
	ret = e - s;
	if (ret < 0)	ret = 0;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
r, c = map(int, raw_input().split())
matrix = []
sum_line = [0] * c
for i in range(r):
    line = map(int, raw_input().split())
    sum = 0
    for j in range(c):
        sum += line[j]
        sum_line[j] += line[j]
    line.append(sum)
    matrix.append(line)
    #print " ".join(map(str, line))

sum = 0
for i in range(r):
    print " ".join(map(str, matrix[i]))
    sum += matrix[i][c]
sum_line.append(sum)
print " ".join(map(str, sum_line))

Measured memory_bytes: 6452
import std.stdio;
import std.conv;
import std.string;

void main(){
    foreach(i; 0..readln.chomp.to!int){
        bool[string] set;
        string input = readln.chomp;
        foreach(j; 1..input.length){
            auto s1 = input[0..j];
            auto s2 = input[j..$];
            auto r1 = input[0..j].dup.reverse.idup;
            auto r2 = input[j..$].dup.reverse.idup;
            set[s1 ~ s2] = set[s1 ~ r2] = set[r1 ~ s2] = set[r1 ~ r2] = set[s2 ~ s1] = set[s2 ~ r1] = set[r2 ~ s1] = set[r2 ~ r1] = true;
        }
        set.length.writeln;
    }
}

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

using namespace std;

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

    if(x+0.0 > a*a*b/2.0) {
        theta = atan(2.0*(a*a*b-x)/(double)(a*a*a));
    }else{
        theta = atan((double)(a*b*b)/(2.0*x));
    }
    
    double ans = theta*180.0/(acos(-1));
    printf("%.8lf", ans);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
char s[100];
int main(){
	string a;
	int max=0;
    cin>>a;
	for(int i=0;i<a.length();i++){
	switch(a[i])
        {
            case '0':s[max]='0';max++;break;
            case '1':s[max]='1';max++;break;
            case 'B':if(max!=0)max--;break;
        }
		
	}
	for(int i=0;i<max;i++){
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

const int N = 1e6 + 10;

int n, a[N], cnt;
vector<int> g;

void insertionsort(int a[], int n, int g)
{
    for(int i = g; i < n; i++)
    {
        int j = i - g;
        int v = a[i];
        while(j >= 0 && a[j] > v)
        {
            a[j + g] = a[j];
            j -= g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellsort(int a[], int n)
{
    for(int h = 1;;)
    {
        if(h > n) break;
        g.push_back(h);
        h = 3 * h + 1;
    }

    for(int i = g.size() - 1; i >= 0; i--) insertionsort(a, n, g[i]);
}

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

    cin >> n;

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

    shellsort(a, n);

    cout << g.size() << endl;

    for(int i = g.size() - 1; i >= 0; i--)
    {
        cout << g[i];
        if(i) cout << ' ';
    }

    cout << endl << cnt << endl;

    for(int i = 0; i < n; i++) cout << a[i] << ' ';

    cout << endl;
    return 0;
}


Measured memory_bytes: 7076
#include <iostream>
#include <math.h>
#include <string>    // useful for reading and writing
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    double a_d, b_d;
    a_d = static_cast<double>(a);
    b_d = static_cast<double>(b);
	printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
    return 0;
}



Measured memory_bytes: 3224
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
//#pragma GCC optimize(2)

int main(){
    long long a[11111],t;
    while(cin>>t){
    for(int i=0;i<t;i++)cin>>a[i];
    if(t==1){
        cout<<0<<endl;
        continue;
    }
    sort(a,a+t);
    long long min1=LONG_LONG_MAX,qwe=0;
    //cout<<min1<<" "<<qwe<<endl;
    for(int i=1;i<=100;i++){
        qwe=0;
        for(int j=0;j<t;j++)qwe+=(i-a[j])*(i-a[j]);
        if(qwe>=0)
        min1=min1<qwe?min1:qwe;
    }
    cout<<min1<<endl;}
    return 0;
}

Measured memory_bytes: 888
n = gets.chomp.to_i
h_arr = gets.chomp.split(" ").map(&:to_i)

count = -1
tmp = 0
max = 0
h_arr.each do |h|
  if count == -1 then
    tmp = h
    count = 0
  elsif tmp >= h then
    tmp = h
    count += 1
  else
    max = count if count > max
    tmp = h
    count = 0
  end
end

max = count if count > max

puts max




Measured memory_bytes: 10244
h = input()

han = True

while han:
    if len(h) > 1:
        if h[0:2] == "hi":
            
            if len(h) == 2:
                break
            else:
                h = h[2:]
        else:
            han = False

    elif len(h) == 1:
        han = False
    else:
        han = True

if (han):
    print("Yes")
else:
    print("No")


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

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

    a[k-1]=tolower(a[k-1]);

    for(int i=0;i<n;i++)
    {
        cout<<a[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
	A = list(map(int, input().split()))
	s = 0
	for j in range(M):
		s += A[j] * B[j]

	if s + C > 0:
		ans += 1

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

typedef struct st{
    string s;
    ll n;
    ll idx;
    st(string _s,ll _n,ll _idx):s(_s),n(_n),idx(_idx){}
    bool operator<(const st &a) const{
        if(s == a.s)return n > a.n;
        return s < a.s;
    };
}ST;

ll nn;

int main(){
    cin >> nn;
    vector<ST> v;
    rep(i,nn){
        string s;
        ll num;
        cin >> s >> num;
        v.push_back(st(s,num,i+1));
    }
    sort(ALL(v));
    rep(i,nn){
        cout << v[i].idx << endl;
    }
}

Measured memory_bytes: 256
def test():
    s = int(input())
    a = [s]
    b = []
    while 1:
        if s % 2 == 0:
            s = int(s / 2)
            a.append(s)
        elif s % 2 == 1:
            s = 3*s + 1
            a.append(s)
        if len(a) != len(set(a)):
            for i in range(len(a)-1):
                for j in range(i+1,len(a)):
                    if a[i] == a[j]:
                        b.append(j)
            break
    print(max(b)+1)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
#![allow(unused_macros, unused_imports, dead_code, non_snake_case)]

use std::io;
use std::io::*;

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

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

macro_rules! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules! min {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: min ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: min ($ a , min ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules! chmin {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_min = min ! ($ ($ cmps ) ,+ ) ; if $ base > cmp_min {$ base = cmp_min ; true } else {false } } } ; }
macro_rules! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }


fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    loop {
        let n: usize = itr.next().unwrap().parse().unwrap();
        if n == 0 { break; };
        let mut b: Vec<u32> = Vec::new();
        for _ in 0..n {
            b.push(itr.next().unwrap().parse().unwrap());
        }
        b.sort();
        let mut ans = b[n-1] - b[0];
        for i in 0..n-1 {
            chmin!(ans, b[i+1] - b[i]);
        }
        println!("{}", ans);
    }
}



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

int main()
{
  int N, K;
  cin >> N >> K;
  
  map<int, int> sunuke;
  
  rep(i, K)
  {
    int tmp;
    cin >> tmp;
    
    rep(j, tmp)
    {
      int A;
      cin >> A;
      
      sunuke[A] = 1;
    }
  }
  
  cout << N - sunuke.size() << endl;
  
  return 0;
}


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

int main() {
  typedef long long int lli;
  int Q, H, S, D;
  scanf("%d %d %d %d",&Q,&H,&S,&D);
  lli N;
  scanf("%lld",&N);
  lli ans=(lli)((N/2)*min(min(8*Q,4*H),min(2*S,D))+(N%2)*min(min(4*Q,2*H),S));
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
list_n = []
for i in range(N):
  list_n.append(list(map(int,input().split())))

for i in range(N):
  s = set(list_n[i][1:])
  if i == 0:
    s_inter = s
  else:
    s_inter = s_inter & s

print(len(s_inter))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf = 1e9;
const int MAX = 1e5+5;
const ll MOD = 1e9+7;
#define REP(i, n) for (int i = 0; i < (n); ++i)

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, m; cin >> n >> m;
    vector<int> s(n, -1);
    int digit, num;
    bool error = false;
    int ans = 0;
    REP(i, m){
        cin >> digit >> num;
        if(s[digit-1] == -1) s[digit-1] = num;
        else if(s[digit-1] != num){
            error = true;
            break;
        }
    }
    if(s[0] == 0 && n >= 2) error = true;
    REP(i, n){
        if(i == 0 && s[i] == -1 && n >= 2) ans += pow(10, n-1);
        else if(s[i] != -1) ans += s[i] * pow(10, n-1-i);
        else continue;
    }
    if(!error) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	int n,i,ans=1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		int tmp1;
		cin>>tmp1;
		if(tmp1%2==0)
			ans*=2;
	}
	int tmp2=1;
	while(n--)
		tmp2*=3;
	cout<<tmp2-ans<<endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {

    let result = input.split(' ').map((x) => parseInt(x)).reduce((all, v) => all + v, 0);

    if (result >= 22) {
        console.log('bust')
    } else if (result <= 21) {
        console.log('win')
    }

}

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

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    char c;
    cin >> c;
    if(c >= 'a'){
        cout << "a\n";
    }
    else{
        cout << "A\n";
    }
}

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

for i in range(1,N):
    if A[i-1] == A[i]:
        continue
    elif A[i-1] < A[i]:
        A[i] -= 1
    else:
        chk = False
        
if chk:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63984
#include<bits/stdc++.h>
#define f() for(int i=0;i<n;i++)
using namespace std;
string c;
int main()
{
  cin>>c;
  if(c[0]=='9' or c[1]=='9')cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

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

int N,K,A[200000];

int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	int L,R;
	L=0;
	R=1000000000;
	while(L+1!=R){
		int M=(L+R)/2;
		long long c=0;
		for(int i=0;i<N;i++){
			c+=(A[i]-1)/M;
		}
		if(c<=K)R=M;
		else L=M;
	}
	cout<<R<<endl;
}


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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  
  vector<int> b(m);
  for(int i=0; i<m; i++){
    cin >> b.at(i);
  }
  
  int count=0;
  int sum=c;
  vector<int> a(m);
  
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin >> a.at(j);
    } 
    
    for(int j=0; j<m; j++){
      sum += a.at(j) * b.at(j);
    }
    
    if(sum > 0){
      count++;
    }
    
    sum=c;
  }
  
  	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <cstdio>

#define maxn 1010
typedef long long ll;
int a[maxn];
ll s[maxn * maxn];
int main()
{
	int n, k; scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	int t = 0;
	for (int i = 1; i <= n; ++i)
	{
		ll sum = 0;
		for (int j = i; j <= n; ++j)
			sum += a[j], s[++t] = sum;
	}
	ll ans = 0;
	for (int i = 40; ~i; --i)
	{
		int cnt = 0;
		for (int j = 1; j <= t; ++j)
			if (s[j] & (1ll << i)) ++cnt;
		if (cnt >= k)
		{
			int nt = 0;
			for (int j = 1; j <= t; ++j)
				if (s[j] & (1ll << i)) s[++nt] = s[j];
			t = nt;
			ans |= 1ll << i;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4224
//
//  main.cpp
//  B - Digits
//
//  Created by Hashizo on 2020/02/22.
//  Copyright © 2020 Hashizo. All rights reserved.
//

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

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


int main(int argc, const char * argv[]) {
	ll ans = 0;

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

	
	while(1) {
		ans++;
		n = n / k;
		if(n == 0) {
			break;
		}
	}
	
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;

using namespace std;

int n, m;
ld x, a[1010];

int main(){

	cin >> n >> m;
	for(int i=0; i<n; i++){ cin >> a[i]; x+=a[i];}
	sort(a, a+n);
	x /= (4*m);
	bool ok = 1;
	for(int i=1; i<=m; i++){
		if(a[n-i] < x) ok = 0;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class T> inline std::istream& operator >> (std::istream& is, std::vector<T>& v) { for (T& x : v) { is >> x; }return is; }
	template<class T> inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v) {
		for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); }
		return os;
	}
	template<class V, typename T>inline void fill(V& v, const T& val) { v = val; }
	template<class V, typename T>inline void fill(std::vector<V>& v, const T& val) { for (V& x : v) { fill(x, val); } }
	template<class V, typename H>inline void resize(std::vector<V>& v, const H h) { v.resize(h); }
	template<class V, typename H, typename... T>inline void resize(std::vector<V>& v, const H& h, const T& ... t) { v.resize(h); for (auto& x : v) { resize(x, t...); } }
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }

	void solve() {
		IOS;
		int n, m;
		cin >> n >> m;
		vector<int>h(n), a(m), b(m);
		cin >> h;
		vector<int> res(n, 0);
		REP(i, m) {
			cin >> a[i] >> b[i];
			a[i]--;
			b[i]--;
			int mi = min(h[a[i]], h[b[i]]);
			if (h[a[i]] == mi) {
				res[a[i]] = 1;
			}
			if (h[b[i]] == mi) {
				res[b[i]] = 1;
			}
		}
		int cnt = 0;
		REP(i, n) {
			if (res[i] == 0) {
				cnt++;
			}
		}
		put(cnt);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;
const int MAX_N = 200010;

vector<int> ans(MAX_N);

void dfs(const Graph &G, int v, int p) {

    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        ans[u] += ans[v];
        dfs(G, u, v);
    }
}

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

    Graph G(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(G, 0, -1);

    rep(i, n) {
        cout << ans[i] << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 26624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n;cin>>n;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    int xorval=0;
    for(int i=0;i<n;i++)
        xorval^=arr[i];

    if(!xorval)
        cout<<"Yes";
    else
        cout<<"No";
}

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

int main(){	
	long long N;
	long long W;
	long long H;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	
	long long ans[H][W];
	long long now = 1, cnt = 0;
	for (int i = 0 ; i <= H*W-1 ; i++) {
		if (cnt>=a[now-1]) {
			now++;
			cnt = 0;
		}
		if (i/W%2 == 0) {
			ans[i/W][i%W] = now;
			cnt++;
		} else {
			ans[i/W][W-1-i%W] = now;
			cnt++;
		}
	}

	for (int i = 0 ; i <= H-1 ; i++) {
		for (int j = 0 ; j <= W-1 ; j++) {
			cout << ans[i][j];
			if (j != W-1) cout << " ";
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;


vector<ll> d(ll n,ll from,  vector<vector<ll> > tree){
  vector<ll> res(n);
  queue<ll> que;
  que.push(from);
  ll dist = 0;
  while(!que.empty()){
    ll top = que.front();
    que.pop();
    dist++;
    // cout << top << endl;
    for(ll i = 0;i < tree[top].size(); i++){
      if(res[tree[top][i]] == 0){
        res[tree[top][i]] = res[top] + 1;
        que.push(tree[top][i]);
      }
    }
  }
  return res;
}

int solve() {
  ll n;
  cin >> n;
  vector<vector<ll> > tree(n);
  vector<ll> a(n - 1);
  vector<ll> b(n - 1);
  for(ll i = 0; i < n - 1; i++){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<ll> f(n),s(n);
  f = d(n, 0, tree);
  s = d(n, n - 1, tree);
  f[0] = 0;
  s[n - 1] = 0;
  ll sum = 0;
  for(ll i = 0;i < n; i++){
    if(f[i] > s[i]){
      sum++;
    }else{
      sum--;
    }
  }
  if(sum < 0){
    cout << "Fennec" << endl;
  }else{
    cout << "Snuke" << endl;
  }
  return 0;
}


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


Measured memory_bytes: 15772
// https://atcoder.jp/contests/abc165/tasks/abc165_f

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

//------------------------------------------------------------------------------
using Graph = vector<vector<int>>;
Graph G;

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

//------------------------------------------------------------------------------
const int N_MAX = 2*1e5;
const int A_I_MAX = 1e9;
const int INF = 1e9;

int N;
vector<int> a;
vector<int> dp;
vector<int> ans;


void dfs(int v, int p) {
  auto it = lower_bound(dp.begin(), dp.end(), a[v]);
  int a0 = *it;
  *it = a[v];
  ans[v] = distance(dp.begin(), lower_bound(dp.begin(), dp.end(), INF));
  for (int u : G[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  *it = a0;
}

int main() {
  cin >> N;
  G = Graph(N);
  a = vector<int>(N);
  REP(i, N) cin >> a[i];
  REP(i, N - 1) {
    int u, v;
    cin >> u >> v;
    add_edge(u - 1, v - 1);
  }

  dp = vector<int>(N, INF);
  ans = vector<int>(N);
  dfs(0, -1);
  REP(i, N) cout << ans[i] << endl;
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	string str;
	cin >> str;
	int len = str.size();

	stack<char> s;
	rep(i, len) {
		if (i == 0) {
			s.push(str[i]);
			continue;
		}
		if (s.size() != 0 && s.top() == 'S' && str[i] == 'T') {
			s.pop();
		}
		else s.push(str[i]);
	}

	cout << s.size() << endl;
}




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


	solve();
	system("PAUSE");
	return 0;
}

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

bool comp(vector<ll> x1, vector<ll> x2) {
  return x1[0] + x1[1] < x2[0] + x2[1];
}

int main() {
  ll n;
  cin >> n;
  
  vector<vector<ll>> x(n, vector<ll>(2));
  for (ll i = 0; i < n; i++) {
    cin >> x[i][0] >> x[i][1];
  }
  
  sort(x.begin(), x.end(), comp);

  ll cnt = 0;
  ll pre = -1e9;
  for (ll i = 0; i < n; i++) {
    if (pre <= x[i][0] - x[i][1]) {
      pre = x[i][0] + x[i][1];
      cnt++;
    }
  }
  
  cout << cnt << endl;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int MOD = 1000000007;
const int MX = 20;

inline void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int dir[MX][MX];
int dp[2][1 << (MX-1)];

int main() {
	int N, M, K; cin >> N >> M >> K;
	memset(dir, -1, sizeof(dir));
	rep(i, K) {
		int A, B, C; cin >> A >> B >> C;
		--A; --B;
		dir[A][B] = C;
	}

	int c = 0, f = 1;

	dp[c][0] = 1;

	rep(i, M) {
		rep(j, N-1) {
			rep(mask, (1 << N-1)) {
				dp[f][mask] = 0;
			}
			rep(mask, 1 << (N-1)) {
				if (dp[c][mask] == 0) {
					continue;
				}
				int u = (mask >> j) & 1;

				//same
				if (dir[i][j] != (u^1)) {
					add(dp[f][mask], dp[c][mask]);
				}

				//diff
				if (dir[i][j] != 0 && u == 0) {
					int hbit = mask >> (j+1);
					hbit -= hbit & (-hbit);
					int nmask = (hbit << (j+1)) | (mask & ((1 << j)-1)) | (1 << j);

					add(dp[f][nmask], dp[c][mask]);
				}
			}
			swap(c, f);
		}
	}

	int ans = 0;
	rep(mask, 1 << (N-1)) {
		add(ans, dp[c][mask]);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
 int a,b,c;
  cin >> a >> b;
  c = (a+b)%2;
  if(c == 0){
    cout << (a+b)/2 << endl;
  }
  else{
    cout << ((a+b)/2)+1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int rcnt=0,bcnt=0;
  for(int i=0;i<n;i++){
    char s;
    cin>>s;
    if(s=='R') rcnt++;
    else bcnt++;
  }
  cout<<(rcnt>bcnt?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    char S[N+1];
    cin >> S;
    
    int ans = 0;
    int x = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'I'){
            x++;
            ans = max(ans, x);
        }else{
            x--;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())

D = [input().split() for _ in range(N)]

count = 0

for i in range(N):
  if(D[i][0]==D[i][1]):
    count+=1
    if(count==3):
      print('Yes')
      sys.exit()
  else:
    count=0
print('No')

Measured memory_bytes: 9028
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(double, n, a);
    Sort(a);
    
    double ans = 0;
    For(i, n) ans += 1.0 / a[i];
    printf("%.15f\n", 1.0 / ans);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    
    int d[51];
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }
    
    int sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}


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

string solve(string s) {
    vector<vector<int>> vec(10);
    int locks = 0;
    for (char c: s) {
        if (c == 'u') {
            locks = 0;
        } else {
            vec[c - '0'].emplace_back(locks);
            locks |= 1 << (c - '0');
        }
    }
    for (int n = 0; n < 10; n++) {
        vector<int> dp(1 << 10);
        for (int s0: vec[n]) dp[s0] = true;
        for (int s = 0; s < (1 << 10); s++) if (dp[s]) {
            if (s >> n & 1) return "UNSAFE";
            for (int nxt = 0; nxt < 10; nxt++) if (s >> nxt & 1) {
                for (int has: vec[nxt]) {
                    if ((s & has) == 0) dp[s | has] = true;
                }
            }
        }
    }
    return "SAFE";
}

int main() {
    int n;
    while (cin >> n, n) {
        string s; cin >> s;
        cout << solve(s) << endl;
    }
    return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, d; cin >> n >> d;
    arr<int> X(n, vector<int>(d));

    rep(i, n) rep(j, d) cin >> X[i][j];

    vector<int> v;
    rep(i, 1000) v.push_back((i+1)*(i+1));

    int ans = 0;
    FOR(i, 0, n-1) FOR(j, i+1, n){
        int dist = 0;
        rep(k, d) dist += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);

        auto t = lower_bound(ALL(v), dist);
        if(*t == dist) ans++;
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3612
import itertools

def chkTrg(a,b,c):
    if (a + b > c and b + c > a and c + a > b) and (a != b and b != c and c != a):
        return True
    else:
        return False

N = int(input())
bars = [int(i) for i in input().split(" ")]

cnt = 0

for bar in itertools.combinations(bars, 3):
    if chkTrg(bar[0],bar[1],bar[2]):
        cnt += 1

print(cnt)

Measured memory_bytes: 9196
// AOJ - ALDS1
// ALDS1_2_B - Selection sort
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_B

package main

import "fmt"

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

func ssort(a []int) (sw int) {
	n := len(a)
	for i := 0; i < n; i++ { // i-1番目までソート済みとする
		minv := a[i] // i番目の値とそのインデックスを覚えておく
		mini := i
		for j := i + 1; j < n; j++ { // i+1番目以降で、minvより小さい値を探す
			if minv > a[j] { // a[j]の方がminvより小さい
				minv = a[j] // minv, miniを更新
				mini = j
			}
		}
		if i != mini {
			a[mini], a[i] = a[i], a[mini] // i番目の値とmini番目の値を交換する
			sw++
		}
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sw := ssort(a)
	for i := range a {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(a[i])
	}
	fmt.Println()
	fmt.Println(sw)
}



Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main()	{
  long long n;
  cin >> n;
  long long l_prev = 2;
  long long l_curr = 1;
  if (n == 0)	{
    cout << 2 << endl;
    return 0;
  }
  if (n == 1)	{
    cout << 1 << endl;
    return 0;
  }
  for (int i = 2; i <= n; i++)	{
    long long tmp = l_curr;
    l_curr = l_curr + l_prev;
    l_prev = tmp;
  }
  cout << l_curr << endl;
  return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  if(n < 1200)
    cout << "ABC" << endl;
  else if(n < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vector<string> s;
ll pos = 0;

ll cal(int n, int t) {
	ll res = 0;
	switch(t) {
		case 0:
		{
			while(pos < s.size()) {
				ll cnt = 0;
				REP(i, s[pos].size()) {
					if(s[pos][i] == '.') ++cnt;
					else break;
				}
				if(cnt == n) {
					if(s[pos][n] == '+') {
						++pos;
						res += cal(n + 1, 0);
					} else if(s[pos][n] == '*') {
						++pos;
						res += cal(n + 1, 1);
					} else {
						res += stoi(s[pos].substr(n, s[pos].size() - n));
						++pos;
					}
				} else {
					return res;
				}
			}
			break;
		}
		case 1:
		{
			++res;
			while(pos < s.size()) {
				ll cnt = 0;
				REP(i, s[pos].size()) {
					if(s[pos][i] == '.') ++cnt;
					else break;
				}
				if(cnt == n) {
					if(s[pos][n] == '+') {
						++pos;
						res *= cal(n + 1, 0);
					} else if(s[pos][n] == '*') {
						++pos;
						res *= cal(n + 1, 1);
					} else {
						res *= stoi(s[pos].substr(n, s[pos].size() - n));
						++pos;
					}
				} else {
					return res;
				}
			}
			break;
		}
		default:
			return 0;
	}
	return res;
}

int main(void) {
	while(true) {
		pos = 0;
		int n;
		cin>>n;
		if(n==0)break;
		s.resize(n);
		REP(i, n) cin>>s[i];
		if(n == 1) {
			cout<<s[0]<<endl;
			continue;
		}
		if(s[0] == "+") {
			++pos;
			cout<<cal(1, 0)<<endl;;
		}
		if(s[0] == "*") {
			++pos;
			cout<<cal(1, 1)<<endl;
		}

	}
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> edge[n];
  vector<pair<i64, i64>> p(n - 1);
  for (i64 i = 0; i < n - 1; i++)
  {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
    p[i] = {a, b};
  }
  map<pair<i64, i64>, i64> ans;
  queue<pair<i64, i64>> que;
  que.push({0, -1});
  while (que.size())
  {
    pair<i64, i64> p = que.front();
    que.pop();
    i64 cnt = 1;
    for (i64 i : edge[p.first])
      if (ans[{p.first, i}] == 0)
      {
        if (cnt == p.second)
          cnt++;
        ans[{p.first, i}] = cnt;
        ans[{i, p.first}] = cnt;
        cnt++;
        que.push({i, ans[{p.first, i}]});
      }
  }
  i64 m = 0;
  for (i64 i = 0; i < n - 1; i++)
    m = max(m, ans[p[i]]);
  cout << m << endl;
  for (i64 i = 0; i < n - 1; i++)
    cout << ans[p[i]] << endl;
  return 0;
}


Measured memory_bytes: 20608
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Program
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		bool a = true;
		int pa = 0;
		int pz = 0;

        for(var i = 0; i < s.Length; i++)
		{
			if (a && s[i] == 'A')
			{
				pa = i;
				a = false;
			}
			if (s[i] == 'Z')
			{
				pz = i;
			}
		}
		int ans = pz - pa + 1;

		Console.WriteLine(ans);
	}
}

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

typedef long long int ll;
const int maxn = 1e5 + 10;
void solved(){
	string s;cin>>s;
	if(s == "ABC")cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
}
int main(){
	solved();
	return 0;
} 

Measured memory_bytes: 3596
import sys
import itertools
import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    x, y, a, b, c = map(int, readline().split())
    p = sorted(map(int, readline().split()), reverse=True)
    q = sorted(map(int, readline().split()), reverse=True)
    r = sorted(map(int, readline().split()), reverse=True)

    z = sorted(p[:x] + q[:y] + r, reverse=True)
    ans = sum(z[:x+y])
    print(ans)

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

Measured memory_bytes: 45924
k = int(input())
a, b = map(int, input().split())

tmp = a

if a % k == 0 or b % k == 0:
  print("OK")
else:
  for i in range(a,b):
    if i % k == 0:
      if i <= b:
        print("OK")
        break
      else:
        print("NG")
        break
  else:
    print("NG")
  

Measured memory_bytes: 61820
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()


x = readInt()

print(8-1*(x-400)//200)

Measured memory_bytes: 9392
using System;
using System.Linq;

// https://atcoder.jp/contests/abc123/tasks/abc123_a
namespace AFiveAntennas
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            const int AntennaCount = 5;
            var positions = new int[AntennaCount];
            for (var i = 0; i < AntennaCount; i++)
            {
                positions[i] = int.Parse(Console.ReadLine());
            }
            var k = int.Parse(Console.ReadLine());

            // a < b < c < d < e なので、もっとも離れているのは a/e 間の距離
            var maxDistance = positions.Last() - positions.First();

            // 解答の出力
            var answer = maxDistance <= k ? "Yay!" : ":(";
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11220
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long c = long.Parse(input[1]);
    long answer = long.MaxValue;
    long answerMemo = 0;
    long[,] originalColors = new long[c,3];//それぞれの余りにおける色の数
    
    int[,] matrixDistance = new int[c,c];//行列
    for(int i = 0; i < c; i++)//それぞれの行
    {
    	int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    	for(int j = 0; j < c; j++) matrixDistance[i,j] = nums[j];//行の全ての成分
    }

    int[,] matrixColor = new int[n,n];//行列  
    for(int i = 0; i < n; i++)//それぞれの行
    {
    	int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    	for(int j = 0; j < n; j++) matrixColor[i,j] = nums[j]-1;//行の全ての成分
    }

    for(int a = 0; a < n; a++)
    {
      for(int b = 0; b < n; b++)
      {
        if((a+b)% 3 == 0)
          originalColors[matrixColor[a,b],0]++;
        if((a+b)% 3 == 1)
          originalColors[matrixColor[a,b],1]++;
        if((a+b)% 3 == 2)
          originalColors[matrixColor[a,b],2]++;
      }
    }

    for(int i = 0; i < c; i++)//全色試す
    {
      for(int j = 0; j < c; j++)
      {
        for(int k = 0; k < c; k++)
        {
          if(i == j || i == k || j == k) continue;//同じ色はダメ
          answerMemo = 0;
          for(int a = 0; a < c; a++)
          {
            answerMemo += matrixDistance[a,i] * originalColors[a,0];
            answerMemo += matrixDistance[a,j] * originalColors[a,1];
            answerMemo += matrixDistance[a,k] * originalColors[a,2];
          }

          answer = Math.Min(answer, answerMemo);
        }
      }
    }

    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 18128
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main(): 
    a,b,c,d,K = map(int,input().split())
    ans = 0
    if a == c:
        ans = (d - b - K)
    else:
        a += 1
        ans += 60 - b
        ans += (c - a) * 60 + d
        ans -= K
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include <stdio.h>

long long gcd(long long a,long long b){
   long long r,tmp;
   if(a>b){
     tmp=a;
     a=b;
     b=tmp;
   }
   if(a==0) return b;
   r=b%a;
   while(r!=0){
   b=a;
   a=r;
   r=b%a;
   }
   return a;
}


int main(void){
  long long n,a[100005],L[100005],R[100005],m[100005],max=0;
   scanf("%lld",&n);
   for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }
  L[0]=0;
  R[n]=0;
  for(int i=0;i<=n-1;i++){
    L[i+1] = gcd(L[i],a[i]);
  }
  for(int i=n;i>=1;i--){
    R[i-1] = gcd(R[i],a[i-1]);
  }
  for(int i=0;i<n;i++){
    m[i]=gcd(L[i],R[i+1]);
    if(max<m[i]) max=m[i];
  }
  printf("%lld",max);
  return 0;
}


Measured memory_bytes: 4068
x = int(input())
if x == 0:
    print("1 1")
    exit(0)

i = 1
while True:
    for a in range(-i, i + 1):
        b = i
        if a ** 5 - b ** 5 == x:
            print("{} {}".format(a, b))
            exit(0)
    
        b = -i
        if a ** 5 - b ** 5 == x:
            print("{} {}".format(a, b))
            exit(0)
    
    for b in range(-i, i + 1):
        a = i
        if a ** 5 - b ** 5 == x:
            print("{} {}".format(a, b))
            exit(0)
    
        a = -i
        if a ** 5 - b ** 5 == x:
            print("{} {}".format(a, b))
            exit(0)
    
    i += 1


Measured memory_bytes: 9128
import sys
import math
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    return


# B
def B():
    return


# C
def C():
    n = I()
    for i in range(int(n ** 0.5), 0, -1):
        if n % i == 0:
            print(i + n // i - 2)
            return
    return


# D
def D():
    a, b, x = LI()
    if (x <= a * a * b / 2):
        print(math.degrees(math.atan(a * b * b / x / 2)))
    else:
        print(math.degrees(math.atan(2 * (a * a * b - x) / a ** 3)))
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 38384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a<b){
			System.out.println("a < b");
		}else if(a>b){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 17164
#if 1

#include <bits/stdc++.h>
using namespace std;
double d[3005],p;
int n;

int main()
{
    d[0] = 1;
    scanf("%d", &n);
    for(int i = 0;i < n;i++)
    {
        scanf("%lf", &p);
        for(int j = i+1;j >= 1;j--)
        {
            d[j] += (d[j-1] - d[j]) * p;
        }
    }
    printf("%.10f",d[(n+1)/2]);
}

#endif // 1++


Measured memory_bytes: 256
import itertools
N=int(input())
lst=[input() for i in range(N)]
data={"M":0,"A":0,"R":0,"C":0,"H":0}
for S in lst:
    for c in data:
        if S[0]==c:
            data[c]+=1

ite=itertools.combinations("MARCH",3)
print(sum([data[a]*data[b]*data[c] for a,b,c in ite]))


Measured memory_bytes: 9772
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    if any(ai == 0 for ai in A):
        print(0)
        return
    ans = 1
    for ai in A:
        ans *= ai
        if 10 ** 18 < ans:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 21600
n = int(input())
a = list(map(int, input().split()))

b = [a[i]  for i in range(len(a)) if a[i]%2==0]

if all(b[i]%3==0 or b[i]%5==0 for i in range(len(b))):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064