akhauriyash/Code-Regression huggingface dataset:
N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

parent = [None]*N
depth = [0]*N
d = 0
queue = [0]
while queue:
    d += 1
    queue_new = []
    for q in queue:
        for e in E[q]:
            if e==parent[q]: continue
            parent[e] = q
            depth[e] = d
            queue_new.append(e)
    queue = queue_new

ancestor = [[None]*N for _ in range(N)]
for a in range(N):
    for b in range(a, N):
        _a = a
        _b = b
        while _a!=_b:
            if depth[_a] < depth[_b]: _b = parent[_b]
            else: _a = parent[_a]
        ancestor[a][b] = ancestor[b][a] = _a

M = int(input())
P = []
for _ in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    w = ancestor[u][v]
    path = set()
    while u!=w:
        _u = parent[u]
        #path.add((u, _u))
        path.add(u*N+_u)
        u = _u
    while v!=w:
        _v = parent[v]
        #path.add((v, _v))
        path.add(v*N+_v)
        v = _v
    P.append(path)


ans = 0
n1 = N-1
for k in range(2**M):
    path = set()
    n = 0
    for i, p in enumerate(P):
        if (k>>i)&1:
            path |= p
            n += 1

    if n==0: continue
    sign = +1 if n&1 else -1
    ans += sign * pow(2, n1-len(path))
    
print(pow(2, N-1) - ans)

Measured memory_bytes: 44688
#include <stdio.h>


int main(void){
	int A;
	int B;
	int C;
	scanf("%d",&A);
	scanf("%d",&B);
	
	if(A<B){
		C=B;
	}else if(B<A){
		C=A;
	}
	

	if(A==B){
		printf("%d",A*2);
	}else{
		printf("%d",C*2-1);
		
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int c[16];
int a[16][16];
int b[16];

int main(){
	int n, m, x; scanf("%d%d%d", &n, &m, &x);
	REP(i, n){
		scanf("%d", c+i);
		REP(j, m) scanf("%d", a[i]+j);
	}
	int ans = INT_MAX;
	REP(h, 1<<n){
		fill(b, b+16, 0);
		int e = 0;
		REP(i, n){
			if(h&(1<<i)) continue;
			REP(j, m) b[j] += a[i][j];
			e += c[i];
		}
		bool ok = true;
		REP(j, m) if(b[j] < x) ok = false;
		if(ok) SML(ans, e);
	}
	if(ans == INT_MAX) ans = -1;
	printf("%d\n", ans);
}


Measured memory_bytes: 3828
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	int n, T, ans = 1001;
	cin >> n >> T;

	vector<int> c(n), t(n);
	rep(i, 0, n) {
		cin >> c[i] >> t[i];
		if (t[i] <= T) ans = min(ans, c[i]);
	}

	if (ans == 1001) {
		cout << "TLE" << endl;
		return 0;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

const int N = 100010;

int a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p;
    a[i] = (p == i);
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] > 0 || (i == 2 && a[i] + a[i - 1] > 0)) {
      ans++;
      a[i] = a[i - 1] = 0;
    }
  }
  cout << ans << endl;
}


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

int a[105], d[105], pos[105];
int n, ans;
int ne[5050][10];
int dp[105][5050];
vector<int> conds[5050];
vector<int> cond;

int main(){
	cin >> n;
	for(int i = 0;i < n;i++)cin >> d[i];
	for(int i = 0;i < n;i++)cin >> a[i];
	
	for(int i = 0;i < 7;i++)cond.push_back(i);
	int p = 0;
	do{
		conds[p++] = cond;
	}while(next_permutation(cond.begin(), cond.end()));
	
	for(int i = 0;i < p;i++){
		vector<int> tmp1, tmp2;
		for(int j = 0;j < 8;j++){
			tmp1 = conds[i];
			for(int k = 0;k < 7;k++){
				if(tmp1[k] >= j)tmp1[k]++;
			}
			tmp2.clear();
			for(int k = 1;k <= 7;k++){
				tmp2.push_back(tmp1[k]);
				if(tmp2[k - 1] > tmp1[0])tmp2[k - 1]--;
			}
			ne[i][j] = lower_bound(conds, conds + p, tmp2) - conds;
		}
	}
	
	for(int  i = 0;i < n;i++){
		for(int j = 0;j < p;j++){
			for(int k = 0;k < 7;k++)pos[conds[j][k]] = k;
			int res = dp[i][j];
			for(int k = 0;k < 7;k++)
				if(i - 7 + k >= 0 && 7 - k <= d[i])res += a[i];
			for(int k = 0;k < 8;k++){
				dp[i + 1][ne[j][k]] = max(dp[i + 1][ne[j][k]], res);
				ans = max(ans, dp[i + 1][ne[j][k]]);
				if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i])res -= a[i];
				if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i - 7 + pos[k]])res += a[i - 7 + pos[k]];
			}
		}
	}	
	cout << ans << endl;
}

Measured memory_bytes: 3748
from math import factorial
def ncr(n,r):
    return factorial(n) // factorial(r) // factorial(n - r)

N, M = map(int, input().split())

n = 0
m = 0

if N > 1:
    n = ncr(N,2)
if M > 1:
    m = ncr(M,2)

print(n + m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

double det(double a1,double a2,double a3,double a4){
	return a1*a4-a2*a3;
}

int main(){
	double a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double g,h,i;
		g = det(a,b,d,e);
		h = det(c,b,f,e);
		i = det(a,c,d,f);
		double j,k;
		j = h ==0 ?0:h/g;
		k = i ==0 ?0:i/g;
		j = round(j*pow(10,4))/pow(10,4);
		k = round(k*pow(10,4))/pow(10,4);
		printf("%.3f %.3f\n",j,k);
	}
	return 0;
}

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

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let A: Vec<i64> = sc.vec(N);
    let mut x = vec![0; N];
    for i in 0..N {
        if i % 2 == 0 {
            x[0] += A[i];
        } else {
            x[0] -= A[i];
        }
    }
    for i in 1..N {
        x[i] = A[i-1] - x[i-1]/2;
        x[i] *= 2;
    }
    for i in 0..N {
        println!("{}", x[i]);
    }
}


Measured memory_bytes: 7420
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int dp[520][520] = {};
int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a)  a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

int main(){
   string s;
   cin >> s;
   stack<char> st;
   int res = 0;
   for(int n = 0; n < s.sz; ++n){
      if(s[n] == 'S'){
         st.push('S');
      }
      else{
         if(st.sz == 0 || st.top() != 'S'){
            st.push('T');
         }
         else{
            st.pop();
         }
      }
   }
   cout << st.sz << endl;
   return 0;
}

Measured memory_bytes: 644
#include <stdio.h>
#include <vector>

using namespace std;

struct Node{
	Node(){
		brother = parent = -1;
		height = depth = num_of_children = 0;
	}
	int parent,brother,depth,num_of_children,height;
	vector<int> children;
};

void calcDepth(Node nodes[],int root_id){
	for(int i = 0;i < nodes[root_id].num_of_children;i++){
		nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
		calcDepth(nodes,nodes[root_id].children[i]);
	}
}

void calcHeight(Node nodes[],int height,int parent){
	nodes[parent].height = max(nodes[parent].height,height+1);
	if(nodes[parent].parent != -1) calcHeight(nodes,height+1,nodes[parent].parent);
}

int main(){
	int n,id,left_id,right_id,root_id;
	scanf("%d",&n);
	Node nodes[n];

	for(int i = 0; i < n; i++){
		scanf("%d %d %d",&id,&left_id,&right_id);
		if(left_id != -1){
			nodes[id].children.push_back(left_id);
			nodes[id].num_of_children++;
			nodes[left_id].parent = id;
		}
		if(right_id != -1){
			nodes[id].children.push_back(right_id);
			nodes[id].num_of_children++;
			nodes[right_id].parent = id;
		}
		if(left_id != -1 && right_id != -1){
			nodes[left_id].brother = right_id;
			nodes[right_id].brother = left_id;
		}
	}

	for(root_id = 0; root_id < n; root_id++){
		if(nodes[root_id].parent == -1) break;
	}

	if(n > 1){
		calcDepth(nodes,root_id);

		for(int i = 0; i < n; i++){
			if(nodes[i].num_of_children == 0) calcHeight(nodes,0,nodes[i].parent);
		}
	}

	for(int i = 0; i < n; i++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
				,i,nodes[i].parent,nodes[i].brother,nodes[i].num_of_children,nodes[i].depth,nodes[i].height);
		if(nodes[i].parent == -1){
			printf(" root\n");
		}else if(nodes[i].num_of_children == 0){
			printf(" leaf\n");
		}else{
			printf(" internal node\n");
		}

	}
}


Measured memory_bytes: 2744
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools
from collections import Counter

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
a[0] %= m
cumsum = list(itertools.accumulate(a, lambda x, y: (x + y) % m))
counter = list(Counter(cumsum).items())
cnt = 0
for i, v in counter:
    cnt += v * (v - 1) // 2
    if i == 0:
        cnt += v
print(cnt)


Measured memory_bytes: 19844
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int solve(vector<string> fi,int ind){
  if(fi.size()==1) return fi[0][ind]-'0';
  vector<int> sons;
  REP(i,fi.size()) if(fi[i].size()==ind+2) sons.push_back(i);
  sons.push_back(fi.size());
  bool mult=fi[0][ind]=='*';
  int ans;
  if(mult) ans=1;
  else ans=0;
  REP(i,sons.size()-1){
    int tmp=solve(vector<string>(fi.begin()+sons[i],fi.begin()+sons[i+1]),ind+1);;
    if(mult) ans*=tmp;
    else ans+=tmp;
  }
  return ans;


}
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<string> fi(n);
    REP(i,n) cin >> fi[i];
    cout << solve(fi,0) << endl;
  }
}

Measured memory_bytes: 3156
#include<iostream>

using namespace std;
int main() {
	int S, h, m, s;
	cin >> S;
	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S - h * 3600 - m * 60;
	
	cout << h <<':'<< m<< ':'<< s << endl;

	return 0;
}



Measured memory_bytes: 3100
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b] <- getIntList
    if a < b then print (solve a b) else print (solve b a)

solve :: Int -> Int -> Int
solve n m = read . concat . map show . take m $ repeat n


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int N, M, Q;
int d[514][514];
signed main() {
	scanf("%lld %lld %lld", &N, &M, &Q);
	rep(i, M) {
		int L, R;
		scanf("%lld %lld", &L, &R);
		d[L][R]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			d[i][j] += d[i][j - 1];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			d[i][j] += d[i - 1][j];
		}
	}
	rep(i, Q) {
		int p, q;
		scanf("%lld %lld", &p, &q);
		printf("%lld\n", d[q][q] + d[p - 1][p - 1] - d[q][p - 1] - d[p - 1][q]);
	}
}

Measured memory_bytes: 2944
import math

def is_prime(n):
  if n == 1:
    return False
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True

n=int(input())
ran = range(n,100004)
res = 0
for num in ran:
  if is_prime(num):
    res = num
    break
    
print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

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

    int cost = 700;
    for (int i = 0; i < input.size(); ++i){
        if (input[i] == 'o') { 
            cost += 100;
        }
    }

    cout << cost << endl;
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    cin >> s;
    cout << (((s.front() != s.back()) ^ (s.length()%2)) ? "Second" : "First") << "\n";
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a==b){
        printf("a == b\n");
    }else{
        printf("a < b\n");
    }
    return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  if(N == 1 || N % 2 == 1){
    cout << "No";
    return 0;
  }
  int m = (int)(N/2);
  if(S.substr(0,m) == S.substr(m)){
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
typedef long long ll;
ll longinf=1ll<<60;


double n,m,d;

int main(){
    cin>>n>>m>>d;
    double x;
  double y,z;
  if(d==0){y=0;z=n;}
  else if(n-2*d>0){y=n-2*d;z=2*d;}
  else {y=0;z=n;}
    x=(2*y+z)*(m-1)/(n*n);
    printf("%f",x);

    return 0;
}

Measured memory_bytes: 256
n=int(input())
alist=list(map(int,input().split()))
q=int(input())

numdic={}
for i in range(10**5):
    numdic[i+1]=0

for a in alist:
    numdic[a] = numdic[a] + 1
    

outsum=sum(alist)

for i in range(q):
    tmpb,tmpc=map(int,input().split())
    tmp = numdic[tmpb]
    outsum += (tmpc-tmpb)*tmp

    print(outsum)
    
    numdic[tmpb]=0
    numdic[tmpc]=numdic[tmpc]+tmp


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  string w;
  vector<int> cnt(26);

  cin >> w;

  rep(i, w.length()){
    cnt[w[i]-'a']++;
  }

  bool ok = true;

  rep(i, 26){
    if(cnt[i] % 2 == 1){
      ok = false;
      break;
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
import sys
import io


def run(input: io.TextIOBase, output: io.TextIOBase):
    n = int(input.readline())
    r = 0
    for i in range(1, n + 1):
        r += i
    output.write(str(r) + '\n')


if __name__ == '__main__':
    run(sys.stdin, sys.stdout)


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

int main(){

  int h,w;
  while(1){
    cin>>h>>w;
    if(h==0 && w==0) break;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(i==0 || i==h-1 || j==0 || j==w-1) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3028
N = int(input())
A = list(map(int, input().split()))

# BT = [[0] * 20 for _ in range(N + 1)]
# for i, a in enumerate(A):
#     j = 0
#     while a > 0:
#         BT[i + 1][j] += (a & 1)
#         j += 1
#         a >>= 1
# print(BT)
# S = [[0] * 20 for _ in range(N + 1)]
# for j in range(20):
#     for i in range(N):
#         S[i + 1][j] = S[i][j] + BT[i][j]
# # print(S)

S = 0
X = 0
l = 0
cnt = 0
for r in range(N):
    S += A[r]
    X ^= A[r]
    if S == X:
        cnt += r - l + 1
    else:
        while l != r:
            S -= A[l]
            X ^= A[l]
            l += 1
            if S == X:
                cnt += r - l + 1
                break

print(cnt)


Measured memory_bytes: 77772
class ModWorld:
    def __init__(self, mod):
        self.mod = mod

    def prepare_factorial(self, N):
        self.f = [1]*(N+1) # f[n] := n!
        p = 1
        for i in range(1,N+1):
            p = (p*i) % self.mod
            self.f[i] = p
            
        self.finv = [None]*(N+1)
        for i, s in enumerate(self.f):
            self.finv[i] = self.modpow(s, -1)

    def modpow(self, x, k):
        x %= self.mod
        k %= self.mod-1 # a^(p-1) = 1
        retval = 1
        while k:
            if k&1: retval = retval*x % self.mod
            k>>=1
            x = x*x % self.mod

        return retval

    def modcomb(self, n, k):
        return self.f[n] * self.finv[n-k] * self.finv[k] % self.mod

mw = ModWorld(mod=10**9+7)
mw.prepare_factorial(N=10**5+10)

n = int(input())
A = list(map(int, input().split()))
P = [None]*(n+1)
for i, a in enumerate(A):
    if P[a] is not None: break
    P[a] = i
m = i-P[a]+1

for k in range(1, n+2):
    ans = mw.modcomb(n+1, k)
    if k-1<=n+1-m : ans -= mw.modcomb(n+1-m, k-1)
    print(ans%mw.mod)

Measured memory_bytes: 21736
# ALDS1_3_B
p_list = []
q_list = []
finished_list = []
time_list = []
time = 0

n, q = map(int, input().split())
for i in range(n):
    pi, qi = input().split()
    p_list.append(pi)
    q_list.append(int(qi))

##テスト用
# p_list = ["p1","p2","p3","p4","p5"]
# q_list = [150, 80, 200, 350, 20]

while len(p_list) > 0:
  processing_item = p_list.pop(0)
  processing_time = q_list.pop(0)
 
  if processing_time <= q:
    time += processing_time
    finished_list.append(processing_item)
    time_list.append(time)
  else:
    time += q
    processing_time -= q
    p_list.append(processing_item)
    q_list.append(processing_time)

for i in range(n):
#     print(finished_list, time_list)
  print(finished_list[i], time_list[i])



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

a,p = [1],[1]
for i in range(n):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
  
def f(n, x):
  if n == 0:
    if x <= 0: return 0
    else:return 1
  elif x <= 1 + a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n,x))

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

int main(){
    long long n;
    cin >> n;
    long long l[n];
    for(long long i = 0; i < n; i++) cin >> l[i];

    long long cnt = 0;
    for(long long i = 0; i < n; i++){
        for(long long j = i + 1; j < n; j++){
            for(long long k = j + 1; k < n; k++){
                if(l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and l[j] + l[k] > l[i] and l[i] + l[k] > l[j] and l[j] + l[i] > l[k]){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
int n;
vector<double> coins;
vector<vector<double>> dp;

double func(int idx, int heads) {
	if(idx<0||idx>=n||heads<0||heads>=2*n+1)
		return 0;
	if(idx==0) {
		if(heads==n+1)
			return coins[0];
		else if(heads==n-1)
			return 1-coins[0];
		else
			return 0;
	}
	if(dp[idx][heads]!=-1)
		return dp[idx][heads];

	dp[idx][heads] = coins[idx]*func(idx-1, heads-1) + (1 - coins[idx])*func(idx-1, heads+1);
	return dp[idx][heads];
}

int main() {
	cin>>n;
	coins.resize(n);
	dp.resize(n, vector<double>(2*n+1,-1));
	
	for(int i=0;i<n;i++) {
		cin>>coins[i];
	}

	double ans = 0;
	for(int i=1;i<=n;i++) {
		ans += func(n-1,i+n);
	}

	cout<<fixed << setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 142720
import heapq
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    Q = []
    for _ in range(N):
        a, b = map(int, input().split())
        heapq.heappush(Q, [a, b])
    
    ans = 0
    P = []
    for i in range(1, M+1):
        if len(Q)!=0:
            a, b = heapq.heappop(Q)
            while a==i:
                heapq.heappush(P, [b*(-1), a])
                if len(Q)==0:
                    break
                a, b = heapq.heappop(Q)
            heapq.heappush(Q, [a, b])
        if len(P)!=0:
            b, a = heapq.heappop(P)
            ans += b*(-1)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 86748
#include<stdio.h>
#include<math.h>
int main(void)
{
	double a,b,p,q,d;
	scanf("%lf %lf %lf %lf",&a,&b,&p,&q);
	d=sqrt(1.0*(p-a)*(p-a)+(q-b)*(q-b));
	printf("%f\n",d);
	return 0;
}

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

int main()
{
	int n,l,sum=0,x,min=1000000;
      cin >> n >> l;
  int a[n];
  for(int i=1;i<=n;i++){
  	if(abs(l+i-1)<min)
    {
    	min = abs(l+i-1);
      	x=l+i-1;
    }
  sum += l+i-1;
  
  }

      
cout << sum - x;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a,b;
    cin>>a>>b;
    if(a<b)
    {
    cout<<"<"<<endl;
	return 0;	
	}
    if(a>b)
    {
    cout<<">"<<endl;
	return 0;	
	}
    if(a==b)
    cout<<"=";
    return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"


template <typename T, typename K> struct P {
	T a; K b;
};

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
vector <P <ll, ll> >prime_factorize( ll N );
ll pow( ll a, ll n );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
int main( void ){
	// initialize();
	int r;
	cin >> r;
	cout << 3*r*r << endl;
}

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

/*
 * @fn eratosthenes
 * @brief O(NloglogN)~=(N)
 * @param N: その数まで
 * @return 0 or 1 の配列 (boolは都合が悪い)
 */
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}

/*
 * @fn prime_factorize
 * @brief O(√N): 素因数分解
 * @param N: 素因数分解する数
 * @return vec: (a: 素数, b: 個数)
 */
vector <P <ll, ll> >prime_factorize( ll N ){
	vector <P <ll, ll> > vec;
	int lim = sqrt( N ) + 1;
	rep( i, 2, N + 1 ){
		if (i >= lim){
			vec.push_back( P <ll, ll>{N, 1} );
			break;
		}
		if (N % i == 0){
			vec.push_back( P <ll, ll>{i, 0} );
			while(N % i == 0){
				N /= i;
				vec.back().b++;
			}
		}
	}
	return vec;
}
/*
 * @fn pow
 * @brief a^n
 * @param a: 基数
 * @param n: 指数
 */
ll pow( ll a, ll n ) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int l025 = nextInt();
        int l05 = nextInt();
        int l1 = nextInt();
        int l2 = nextInt();

        long n = nextInt();

        if (n == 1) {
            // 全部1Lの値段にする。
            int l025_1 = l025 * 4;
            int l05_1 = l05 * 2;

            // 一番安い奴つかう
            long[] parr1l = new long[] {l025_1, l05_1, l1};
            Arrays.sort(parr1l);

            out(parr1l[0]);

            return;

        } else if (n % 2 == 0) {
            // 全部2L値段にスル
            long l025_2 = l025 * 8L;
            long l05_2 = l05 * 4L;
            long l1_2 = l1 * 2L;

            // 一番安い奴つかう
            long[] parr = new long[] {l025_2, l05_2, l1_2, l2};
            Arrays.sort(parr);

            out(parr[0] * (n / 2));

            return;

        } else {
            // 全部2L値段にスル
            long l025_2 = l025 * 8L;
            long l05_2 = l05 * 4L;
            long l1_2 = l1 * 2L;

            // 一番安い奴つかう
            long[] parr = new long[] {l025_2, l05_2, l1_2, l2};
            Arrays.sort(parr);

            // 1L値段も
            long l025_1 = l025 * 4L;
            long l05_1 = l05 * 2L;

            // 一番安い奴つかう
            long[] parr1l = new long[] {l025_1, l05_1, l1};
            Arrays.sort(parr1l);


            out((parr[0] * (n / 2)) + parr1l[0]);

            return;
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

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

Measured memory_bytes: 21972
import datetime
date_str = "2019/04/30"
date_formatted = datetime.datetime.strptime(date_str, "%Y/%m/%d")
s = input()
s = datetime.datetime.strptime(s, "%Y/%m/%d")

if s <= date_formatted:
    print('Heisei')
else:
    print('TBD')

Measured memory_bytes: 10384
#include<stdio.h>  
#include <bits/stdc++.h>
#include<stdlib.h>

using namespace std;

bool ok(int n) {
    stringstream ss;
    ss << n;
    string s;
    ss >> s;
    for(int i = 1; i < s.length(); i++) {
        if(s[i] != s[i - 1]) {
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int o, t, res = 0, om = 0, tm = 0, som = 0, tom = 0, so, st;
    map<int, int> data;
    for(int i = n; i >= 0; i -= 2) {
        data[a[i]]++;
        if(data[a[i]] > om) {
            so = o;
            som = om;
            o = a[i];
            om = data[a[i]];
        }
        else if(data[a[i]] > som) {
            so = a[i];
            som = data[a[i]];
        }
    }
    data.clear();
    for(int i = 1; i < n; i += 2) {
        data[a[i]]++;
        if(data[a[i]] > tm) {
            st = t;
            tom = tm;
            tm = data[a[i]];
            t = a[i];
        } 
        else if(data[a[i]] > tom) {
            st = a[i];
            tom = data[a[i]];
        }
    }
  //  cout << o << ' ' << so << endl << t << ' ' << st << endl;
    if(tm == om and tm == n / 2) {
        if(t == o) {
            cout << n / 2;
        }
        else cout << 0;
    }
    else {
       // cout << tm << ' ' << om << endl;
        
        if(o == t) {
            cout << min(n / 2 - om + n / 2 - tom, n / 2 - som + n / 2 - tm);
        }else   {
            tm = n / 2 - tm;
            // cout << tm << endl;
            om = n / 2 - om;
            cout << tm + om;
         }
        
    }
}


Measured memory_bytes: 2944
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int str[4];
	memset(str,0,sizeof(str));
	while(n--)
	{
		char s[10];
		cin>>s;
		if(s[0]=='A') str[0]++;
		else if(s[0]=='W') str[1]++;
		else if(s[0]=='T') str[2]++;
		else if(s[0]=='R') str[3]++;
	}
	cout<<"AC x "<<str[0]<<endl;
	cout<<"WA x "<<str[1]<<endl;
	cout<<"TLE x "<<str[2]<<endl;
	cout<<"RE x "<<str[3]<<endl;
	
 } 

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

int main() {
  int n;
  int AC,WA,TLE,RE;
  int ACN=0,WAN=0,TLEN=0,REN=0;
  string S;
  cin >> n;
 
 for(int i = 0; i < n; i++){
     cin >> S;
     if(S == "AC"){
         ACN++;
    }else if(S == "WA"){
        WAN++;
    }else if(S == "TLE"){
        TLEN++;
    }else if(S == "RE"){
        REN++;
    }
  }
  cout << "AC x"<< " " << ACN << endl;
  cout << "WA x"<< " " << WAN << endl;
  cout << "TLE x"<< " " << TLEN << endl;
  cout << "RE x"<< " " << REN << endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N;
    string S;
    cin >> N >> S;
    ll M = 0;
    while(S.size() > 0) {
        vector<ll> A(S.size());
        A[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
            while (i+j < S.size() && S[j] == S[i+j]) ++j; // 右向きにjを伸ばしていく
            A[i] = j;
            if (j == 0) { ++i; continue;}
            int k = 1;
            while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k; // i~j間にkを走らせる
            i += k; j -= k;
        }
        for (int xi = 0; xi < A.size(); ++xi) {
            if(xi >= A[xi]){
                M = max(M,A[xi]);
            }
        }
        S.erase(0,1);
    }
    cout << M << endl;


}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = (c + b - 1) / b;
  int y = (a + d - 1) / d;
  if (x <= y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
struct node {
	int x,y,w;
};
node d[200100];
int n,m,H,W,fa[200100],is[200100];
long long Ans;
inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
inline bool cmp(const node a,const node b){return a.w>b.w;}
signed main(){
    int i,j,k;
    scanf("%lld%lld%lld",&m,&H,&W);
    n=H+W;
    for(i=1;i<=n;i++)fa[i]=i;
    for(i=1;i<=m;i++){
      scanf("%lld%lld%lld",&d[i].x,&d[i].y,&d[i].w);
      d[i].y+=H;
    }
    sort(d+1,d+m+1,cmp);
    for(i=1;i<=m;i++){
      int x=d[i].x,y=d[i].y;
      if(sf(x)!=sf(y)){
      	if(is[sf(x)]&&is[sf(y)])continue;
      	is[sf(y)]|=is[sf(x)];
      	fa[sf(x)]=sf(y);
      	Ans+=d[i].w;
      }else {
      	if(!is[sf(x)]){
      	  is[sf(x)]=1;
      	  Ans+=d[i].w;
      	}
      }
    }
    printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 5632
/*
	---------O7Oo7oO7O-------------
*/

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
#define all(v) v.begin(),v.end()


int Bin_expo(int n, int b)
{
	int res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * n) ;

		}
		n = (n * n) ;


		b /= 2;

	}
	return res;
}


int32_t main()
{
	IOS
#ifndef ONLINE_JUDGE
	freopen("inputf.txt", "r", stdin);
	freopen("output-ans.txt", "w", stdout);
#endif

	int d,t,s;
	cin>>d>>t>>s;
	if(s*t >= d)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}




Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
int p[110000];
int q[110000];
int r[110000];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	long long pas=0;
	for(int i=0;i<a;i++){
		scanf("%d%d",p+i,q+i);
		if(q[i]==1){
			r[i]=(p[i]+c)%b;
			pas+=(c+p[i])/b;
		}else{
			r[i]=(p[i]-(c%b)+b)%b;
			if(c-p[i]>=0)pas-=(c-p[i]+b-1)/b;
		}
	}
	pas=(pas%a+a)%a;
	std::sort(r,r+a);
	for(int i=0;i<a;i++){
		printf("%d\n",r[(pas+i)%a]);
	}
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n1,n2;
    cin>>n1>>n2;
    char a[n1][n2];
    int b[n1][n2],ans=0;
    char c;
    for(int i=0;i<n1;i++)
    {
        for(int j=0;j<n2;j++)
        {
           cin>>c;
           a[i][j] = c;
           b[i][j] = 0;
        }
    }
    if(a[0][0]=='#')
        b[0][0]=1;
    for(int i=1;i<n1;i++)
    {
        if(a[i][0]=='#')
        {
            if(a[i-1][0]=='#')
                b[i][0] = b[i-1][0];
            else
                b[i][0] = b[i-1][0]+1;
        }
        else
            b[i][0] = b[i-1][0];
    }
    for(int i=1;i<n2;i++)
    {
        if(a[0][i]=='#')
        {
            if(a[0][i-1]=='#')
                b[0][i] = b[0][i-1];
            else
                b[0][i]=b[0][i-1]+1;
        }
        else
            b[0][i] = b[0][i-1];
    }
    for(int i=1;i<n1;i++)
    {
        for(int j=1;j<n2;j++)
        {
            int t1=0,t2=0,last=0;
            if(a[i][j]=='.')
            {
                t1=b[i-1][j];
                t2=b[i][j-1];
                if(t1>t2)
                    last=t2;
                else
                    last=t1;
                b[i][j]=last;
                ans=last;
            }
            else
            {
                if(a[i-1][j]=='#')
                {
                    t1=b[i-1][j];
                }
                else
                    t1=b[i-1][j]+1;
                if(a[i][j-1]=='#')
                {
                    t2=b[i][j-1];
                }
                else
                    t2=b[i][j-1]+1;
                if(t1>t2)
                    last=t2;
                else
                    last=t1;
                b[i][j]=last;
                ans=last;
            }
        }
    }
    cout<<ans;

}


Measured memory_bytes: 256
#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)
 
S=gets.chomp

loseCount=S.split("").count{|s| s=="x"}
puts loseCount<=7 ? "YES" : "NO"

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
string s[114514];
int a[114514];
int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
    	cin>>s[i];
    	cin>>a[i];
    	sum+=a[i];
    }
    string x;
    cin>>x;
    for(int i=0;i<n;i++){
    	sum-=a[i];
    	if(s[i]==x){
    		cout<<sum<<endl;
    		return 0;
    	}
    }
} 	

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,T,H,L;
	cin>>n>>T>>H>>L;
	vvi in(n,vi(2));
	rep(i,n)cin>>in[i][0]>>in[i][1];
	int t=0,h=0;
	int i=0;
	while(1){
		if(in[i][0]==0&&in[i][1]==0){
			cout<<i+1<<endl;
			return 0;
		}
		if(in[i][0]){
			in[i][0]--;t++;
		}else{
			in[i][1]--;h++;
		}
		if(T+t>L){
			cout<<i+1<<endl;
			return 0;
		}
		if(h||t>=9){
			int o=h*10+t-9;
			T+=t;
			H+=h;
			t=h=0;
			if(T<o){
				cout<<i+1<<endl;
				return 0;
			}
			T-=o;
			in[i][0]+=o;
		}
		i++;if(i==n)i=0;
	}
}

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

int main() {
  int n, i, f=0;
  cin >> n;
  
  string s = to_string(n);
  
  for (i=0; i<s.size(); i++) {
    f += (int)(s[i]-'0');
  }
  
  if (n%f == 0) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
    
  return 0;
}

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


ans = 0
pre_i = None
for i in A:
    i -= 1
    ans += B[i]
    if pre_i == i - 1:
        ans += C[pre_i]
    pre_i = i

print(ans)


Measured memory_bytes: 3060
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import heapq
import bisect


def warshall_floyd(d):
    """
    d[i][l]がi→lへのコストを示す隣接行列
    結果としてd[i][l]はi→lへの最短コストになる。
    """
    info = copy.deepcopy(d)
    for i in range(len(info)):
        for l in range(len(info)):
            for k in range(len(info)):
                info[l][k] = min(info[l][k], info[l][i] + info[i][k])
    return info


MOD = float('inf')
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

result = warshall_floyd(A)
ans = 0
for i in range(N):
    for l in range(N):
        if result[i][l] != A[i][l]:
            print(-1)
            sys.exit()
        ans += A[i][l]
        if A[i][l] == 0:
            A[i][l] = INF

ans /= 2
for i in range(N - 1):
    for l in range(i + 1, N):
        for k in range(N):
            if A[i][l] == A[i][k] + A[k][l]:
                ans -= A[i][l]
                break
print(int(ans))


Measured memory_bytes: 84312
#include <stdio.h>
#include <string.h>
 
int main() {
  int height,length,i,j,t,max,depth,left,right,last_height,sum;
  char section[20001],reverse[20001];
  int L[10000] = {0},reverse_L[10000] = {0};
 
  scanf("%s", section);
  length = strlen(section);
  for(i = 0; i < length; i++) reverse[i] = section[length-i-1];
  reverse[i] = '\0';
   
  max = 0;height = 0;t = 0;
  for(i = 0; i < length; i++) {
    if(section[i] =='\\') height--;
    if(section[i] == '/') {
      height++;
      if(max == height) t++;
      if(max < height) {
    max = height;
    t = 0;
      }
    }
  }
  last_height = height;
 
   
  height = 0;depth = 0;i = 0;j = 0;
  while(height < max) {
    if(section[i] =='\\') {
      height--;
      depth++;
    }
    if(section[i] == '/') {
      height++;
      if(depth > 0) depth--;
      if(depth == 0 && L[j] > 0) j++;
    }
    L[j] += depth;
    i++;
  }
   
  while(t > 0) {
    if(section[i] =='\\') {
      height--;
      depth++;
    }
    if(section[i] == '/') {
      height++;
      if(depth > 0) depth--;
      if(depth == 0 && L[j] > 0) {
    j++;
    t--;
      }
    }
    L[j] += depth;
    i++;
  }
  left = j;
   
  height = last_height;depth = 0;i = 0;j = 0;
  while(height < max) {
    if(reverse[i] =='/') {
      height--;
      depth++;
    }
    if(reverse[i] == '\\') {
      height++;
      if(depth > 0) depth--;
      if(depth == 0 && reverse_L[j] > 0) j++;
    }
    reverse_L[j] += depth;
    i++;
  }
  right = j;
 
  for(i = 0; i < right; i++) L[left+i] = reverse_L[right-i-1];
  sum = 0;
  for(i = 0; i < left+right; i++) sum += L[i];
 
  printf("%d\n", sum);
  printf("%d", left+right);
  if(left+right != 0) printf(" ");
  for(i = 0; i < left+right-1; i++) printf("%d ", L[i]);
  if(left+right != 0) printf("%d", L[i]);
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
 
using namespace std;
using ll = long long;
 
ll gcd(ll a, ll b) {
    if (a<b) swap(a,b);
 
    while (b) {
        ll t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int wheel(ll n) {
    int cnt = 1;
    ll ws[] = {1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6};
    ll f = 2; int w = 0;

    while (f * f <= n) {
        if (n % f == 0) {
            cnt += 1;
            while (n % f == 0) n /= f;
        }
        f += ws[w];
        w = (w == 10) ? 3 : (w + 1);
    }
    if (n > 1) cnt += 1;

    return cnt;
}
 
int main() {
    ll a, b;
    cin >> a >> b;
 
    ll common = gcd(a,b);

    cout << wheel(common) << endl;
}

Measured memory_bytes: 256