akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


typedef string::const_iterator State;
int number(State&);
int factor(State&);
int term(State&);
int expression(State&);

map<char, int> length;
map<char, map<int, int>> array_;
bool invalid;
bool right__;
char name;
int p;

// 数字の列をパースして、その数を返す。
int number(State &begin) {
	long long ret = 0;

	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	if(ret > 2147483647) {
		invalid = true;
		return 0;
	}
	return ret;
}

// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin) {
	if(invalid) return 0;

	if (*begin == '[') {
		begin++; // '('を飛ばす。
		int ret = expression(begin);
		begin++; // ')'を飛ばす。
		return ret;
	} else {
		return number(begin);
	}
	return 0;
}

// 四則演算の式をパースして、その評価結果を返す。
int expression(State &begin) {
	if(invalid) return 0;

	int ret = factor(begin);
	char t = -1;
	for (;;) {
		if (isalpha(*begin)) {
			t = *begin;
			begin++;
			ret = factor(begin);

			//cout << t << ' ' << ret << endl;
			if(length[t] <= ret){
				invalid = true;
				return 0;
			}
			//cout << right__ << endl;
			//cout << inited[t].count(ret) << endl;
			if(right__ and not array_[t].count(ret)){
				invalid = true;
				return 0;
			}
		} else {
			break;
		}
	}

	name = t;
	p = ret;
	return t == -1 ? p : array_[name][p];
}

//beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
	if (*begin == expected) {
		begin++;
	} else {
		cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
		cerr << "Rest string is '";
		while (*begin) {
			cerr << *begin++;
		}
		cerr << "'" << endl;
		//throw ParseError();
	}
}

bool containEqual(string& s){
	for(auto i : s){
		if(i == '=') return true;
	}
	return false;
}

int main(){
	while(true){
		string s;
		vector<string> vs;
		while(cin >> s, s != "."){
			vs.emplace_back(s);
		}
		if(vs.empty()) break;

		length.clear();
		array_.clear();
		invalid = false;
		rep(i,vs.size()){
			if(not containEqual(vs[i])){
				State tmp = vs[i].begin();
				tmp++;
				tmp++;
				length[vs[i][0]] = number(tmp);
			}else{
				State tmp = vs[i].begin();
				while(*tmp != '=') tmp++;
				tmp++;
				right__ = true;
				int res = expression(tmp);
				//show(res)

				tmp = vs[i].begin();
				right__ = false;
				expression(tmp);
				array_[name][p] = res;
				//show(*tmp)
			}
			if(invalid){
				cout << i + 1 << endl;
				break;
			}
		}
		if(not invalid) cout << 0 << endl;
	}
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  string N;cin>>N;
  if(N[0]=='9'||N[1]=='9')cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n>=k)
    {
    ll a=k*x;
    ll b=y*(n-k);
    ll c=a+b;
    cout<<c<<endl;
    }
    else
    {
        ll c=n*x;
        cout<<c<<endl;
    }

}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        sc.close();

        int ans = (X - A) % B;
        System.out.println(ans);
	}
}


Measured memory_bytes: 21076
r0,g0,b0,n=map(int,input().split())
ans=0
l=[r0,g0,b0]
l.sort(reverse=True)
r=l[0]
g=l[1]
b=l[2]
x=0
while x*r<=n:
    y=0
    if g==1:
        ans+=1+n-x*r
        x+=1
        continue
    if b==1:
        ans+=1+(n-x*r)//g
        x+=1
        continue
    while y*g<=n-x*r:
        if (n-x*r-y*g) % b == 0:
            ans+=1
        y+=1
    x+=1
print(ans)

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

string s;
int m;
signed main(){
	while(true){
		cin>>s;
		if(s=="-")break;
		cin>>m;
		rep(i,m){
			int h;
			cin>>h;
			s=s.substr(h,s.size()-h)+s.substr(0,h);
		}
		cout<<s<<endl;
	}
	return 0;
}


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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  vll a(5);
  ll k;
  rep(i, 5) {
    cin >> a[i];
  }
  cin >> k;

  if (a[4] - a[0] > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD (1e9+7)
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
vector<int> tre[100010];

int T[100010];//1-indexed
int A[100010];//1-indexed
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int N,u,v;cin>>N>>u>>v;
  for(int i = 0; N-1 > i; i++){
    //uからvの直線距離を求める
    int a,b;cin>>a>>b;
    tre[a].push_back(b);
    tre[b].push_back(a);
  }
  queue<P> t;
  t.push({u,1});
  while(!t.empty()){
    P k = t.front();
    t.pop();
    if(T[k.first]){
      continue;
    }
    T[k.first] = k.second;
    k.second++;
    for(int i = 0; tre[k.first].size() > i; i++){
      t.push({tre[k.first][i],k.second});
    }
  }


  queue<P> a;
  a.push({v,1});
  while(!a.empty()){
    P k = a.front();
    a.pop();
    if(A[k.first]){
      continue;
    }
    A[k.first] = k.second;
    k.second++;
    for(int i = 0; tre[k.first].size() > i; i++){
      a.push({tre[k.first][i],k.second});
    }
  }
  int ans = 0;
  int nya = 0;
  for(int i = 1; N >= i; i++){
    if(T[i] < A[i]){
      if(A[i]%2 == T[i]%2){
        ans = max(ans,A[i]-2);
      }else{
        ans = max(ans,A[i]-1);
      }
      ans = max(ans,T[i]);
      
    }
    //cout << i << ":" << T[i] << " " << A[i] << endl; 
  }
  //距離が偶数の場合
  if((T[v]%2)){
    ans++;
  }
  cout << ans-1 << endl;
}


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

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define MOD 1000000007
#define INF 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y) 
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,r;
	cin>>n>>r;

	ll x;
	if(n<10){
		x = r+ 100*(10-n);
		cout<<x;
	}
	else{
		cout<<r;
	}

	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto w = readln.chomp;
  int[char] cnt;
  foreach (e; w) {
    cnt[e]++;
  }
  auto f = false;
  foreach (k; cnt.keys) {
    if (cnt[k] % 2) {
      f = true;
    }
  }
  if (f) writeln("No");
  else writeln("Yes");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int a, b, c;

	std::cin >> a >> b >> c;

	int ans = 0;

	while (1) {
		if (a > c) {
			std::swap(a, c);
		}
		if (a > b) {
			std::swap(a, b);
		}
		if (b > c) {
			std::swap(b, c);
		}
		if (a == b && b == c) {
			break;
		}
		if (a < b && a < c) {
			a += 2;
		}else if (a == b && a < c) {
			a++;
			b++;
		}
		ans++;

	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

string s, t;
int dp[3333][3333]; // dp[si][tj]: s[i], t[j]まで見たときのLCSの大きさの最大値
int pre[3333][3333]; // どこから遷移して来たかを記録。左から: 3, 上から: 2, 左上から: 1

// DPでLCSの大きさを求める
void lcs() {
  int n = s.size(), m = t.size();
  s = "+" + s;
  t = "*" + t;

  fill(dp[0], dp[1111], 0LL);
  fill(pre[0], pre[1111], 0LL);

  for (int si = 1; si <= n; si++) {
    for (int ti = 1; ti <= m; ti++) {
      if (s[si] == t[ti]) {
        dp[si][ti] = dp[si-1][ti-1] + 1;
        pre[si][ti] = 1;
      } else if (dp[si-1][ti] > dp[si][ti-1]) {
        dp[si][ti] = dp[si-1][ti];
        pre[si][ti] = 2;
      } else {
        dp[si][ti] = dp[si][ti-1];
        pre[si][ti] = 3;
      }
    }
  }
}

// LCSの文字列自体を求める
string solve() {
  string ans = "";

  int si = s.size() - 1;
  int ti = t.size() - 1;
  while (si >= 1 && ti >= 1) {
    if (pre[si][ti] == 1) { // 左上に遷移
      ans += s[si];
      si--, ti--;
    } else if (pre[si][ti] == 2) { // 上に遷移
      si--;
    } else { // 左に遷移
      ti--;
    }
  }

  reverse(ans.begin(), ans.end());
  return ans;
}



//ミョ(-ω- ?)
int main() {
    cin >> s >> t;
    lcs();
    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 81756
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val A = input.nextLong()
    val B = input.nextLong()
    
    println(A * (B / gcd(A, B)))
  }
}

fun gcd (a : Long, b : Long): Long {
  return if(b == 0L) a else gcd(b, a % b)
}

Measured memory_bytes: 36456
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
N = len(S)
half = N // 2
for i in range(half):
    if S[i] != S[-(i+1)]:
        print('No')
        sys.exit()
SS = S[:half]
for i in range(half//2):
    if SS[i] != SS[-(i+1)]:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 9060
/*
 * Author       : YangDavid
 * Created Time : 2019年08月24日 星期六 22时30分48秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 2222, MOD = 1000000007;
inline int muln(int x, int y) { return 1LL * x * y % MOD; }
inline int mo(int x) { if(x >= MOD) return x - MOD; if(x < 0) return x + MOD; return x; }
int n, k, a[maxn], one;
int main() {
    scanf("%d%d", &n, &k);
    rep(i, n) {
        scanf("%d", &a[i]);
        for(int j = 1; j < i; ++j) 
            if(a[j] > a[i]) one++;
    }
    int ans = muln(one, k), g = 1LL * k * (k - 1) / 2 % MOD;
    rep(i, n) {
        int les = 0;
        rep(j, n) if(a[j] > a[i]) les++;
        ans = mo(ans + muln(les, g));
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}



signed main()
{
	IOS();
	int N,P;
	vector<int>ans;
	while(1){
		cin>>N>>P;
		if(N==0&&P==0)break;
		int turn = 0;
		int sum = P;
		int a[N] = {};
		while(1){
			if(sum){
				a[turn]++;
				sum--;
			}else{
				sum+=a[turn];
				a[turn]=0;
			}
			if(a[turn]==P){
				ans.push_back(turn);
				break;
			}
			turn = (turn+1)%N;
		}
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}



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

int main()
{
	// 入力 d以内で会話可能
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	int ac, ab, bc;
	int result = 0;
	
	ac = abs(a - c);
	ab = abs(a - b);
	bc = abs(b - c);

	if (ac <= d) {
		result = 1;
	}
	else if( ab<=d && bc <= d ) {
		result = 1;
	}
	if (result == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int ans;
string s;
int main()
{
    int i;
    cin >> s;
    for (i = 0; i < (s.size() + 1) / 2; i++) {
        if (s[i] == 'p') ans--;
    }
    for (; i < s.size(); i++) {
        if (s[i] == 'g') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
N = int(input())


def main():
    A1 = [int(i) for i in input().split()]
    A2 = [int(i) for i in input().split()]

    for i in range(N - 1):
        A1[i + 1] += A1[i]
        A2[i + 1] += A2[i]

    ans = -1

    for i in range(N):
        ans = max(ans, A1[i] + (A2[-1] if i == 0 else A2[-1] - A2[i - 1]))

    print(ans)

    return


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 105;

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
	if (!b) {
		x = 1, y = 0;
	} else {
		exgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
}

int inv(int a, int n) {
	int x, y;
	exgcd(a, n, x, y);
	return (x < 0) ? (x + n) : (x);
}

const int Mod = 1e9 + 7;

template <const int Mod = :: Mod>
class Z {
	public:
		int v;

		Z() : v(0) {	}
		Z(int x) : v(x){	}
		Z(ll x) : v(x % Mod) {	}

		friend Z operator + (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
		}
		friend Z operator - (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
		}
		friend Z operator * (const Z& a, const Z& b) {
			return Z(a.v * 1ll * b.v);
		}
		friend Z operator ~(const Z& a) {
			return inv(a.v, Mod);
		}
		friend Z operator - (const Z& a) {
			return Z(0) - a;
		}
		Z& operator += (Z b) {
			return *this = *this + b;
		}
		Z& operator -= (Z b) {
			return *this = *this - b;
		}
		Z& operator *= (Z b) {
			return *this = *this * b;
		}
		friend boolean operator == (const Z& a, const Z& b) {
			return a.v == b.v;
		} 
};

Z<> qpow(Z<> a, int p) {
	Z<> rt = Z<>(1), pa = a;
	for ( ; p; p >>= 1, pa = pa * pa) {
		if (p & 1) {
			rt = rt * pa;
		}
	}
	return rt;
}

typedef Z<> Zi;


int n, K;
Zi f[N * N], g[N * N];

int main() {
	scanf("%d%d", &n, &K);
	f[0] = 1;
	int sum = 0, nsum = 0;
	for (int i = n; i; i--) {
		nsum = sum + (sum + min(i, K)) / i;
		for (int j = 0; j <= sum; j++) {
			Zi v = f[j];
			if (!v.v)
				continue;
			for (int k = 0; k <= K; k++) {
				if (k > i || j + k < i) {
					g[j] += v;
				} else {
					g[j + (j + k) / i] += v;
				}
			}
		}
		for (int j = 0; j <= nsum; j++)
			f[j] = g[j], g[j] = 0;
		sum = nsum;
	}
	Zi ans = qpow(K + 1, n - 1) * n * ((K * (K + 1)) >> 1);
	for (int j = 1; j <= nsum; j++)
		ans -= j * f[j];
	printf("%d\n", ans.v);
	return 0;
}


Measured memory_bytes: 384
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		ArrayList<Integer> S = new ArrayList<Integer>();
		int[] dist = new int[totalVertex];
		for (int i = 0; i < dist.length; i++) {
			dist[i] = 999999999;
		}
		dist[s] = 0;
		
		while(S.size() != totalVertex) {
			int v = getUnsettledNearest(dist);
			LinkedList<Integer> neighbors = getNeighbors(v);
			for (int i = 0; i < neighbors.size(); i++) {
				int x = neighbors.get(i);
				dist[x] = Math.min(dist[v] + getWeight(v, x), dist[x]);
			}
			ifSettled[v] = true;
			S.add(v);
		}
		
		return dist;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


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

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  double s=x/a;
  double rad;
  if(s>=a*b/2){
    double h=(a*b-s)*2/a;
    rad=atan2(h,a);
  }else{
    double w=s*2/b;
    rad=atan2(b,w);
  }

  double PI=acos(-1);
  double deg=rad/(2*PI)*360;
  printf("%.10lf\n",deg);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
int N;
bool dfs(vii &A,vii &B,vector<bool> &F,int X,int Y,int Z){
    if(X==Y){
        return 1;
    }
    rep(i,0,A[X].size()){
        int P=A[X][i];
        if(F[P]){
            F[P]=0;
            if(dfs(A,B,F,P,Y,Z)){
                B[min(X,P)][max(X,P)]+=(1ll<<Z);
                return 1;
            }
        }
    }
    return 0;
}
signed main(){
    cin>>N;
    vii A(N);
    vector<pii> C(N);
    rep(i,1,N){
        int X,Y; cin>>X>>Y;
        A[X-1].pb(Y-1);
        A[Y-1].pb(X-1);
        C[i]=mp(min(X-1,Y-1),max(X-1,Y-1));
    }
    int M; cin>>M;
    vii B(N,vi(N));
    rep(i,0,M){
        vector<bool> F(N,1);
        int X,Y; cin>>X>>Y;
        F[X-1]=0;
        bool f=dfs(A,B,F,X-1,Y-1,i);
    }
    vii dp(N+1,vi((1ll<<M)));
    dp[1][0]=1;
    rep(i,1,N){
        int X=C[i].first,Y=C[i].second;
        rep(j,0,(1ll<<M)){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j|B[X][Y]]+=dp[i][j];
        }
    }
    cout<<dp[N][(1ll<<M)-1]<<endl;
}


Measured memory_bytes: 426496
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;

#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define in1(a,n) F(i,1,n)cin>>a[i]
#define ff first
#define ss second
#define F(i,a,b) for (ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,n) F(i,0,n-1)
#define clr clear
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define len(s) (s).length()

int main(int argc, char const *argv[])
{
	crap;
	int n, T;
	cin>>n>>T;
	int c[n], t[n];
	rep (i,n)
	{
		cin>>c[i]>>t[i];
	}
	int m=1002;
	rep(i,n)
	{
		if (t[i]<=T)
			m=min(m,c[i]);
	}

	if (m==1002)
		cout<<"TLE";
	else
		cout<<m;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _013_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            List<int>[] graph = new List<int>[n];
            for(int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for(int i = 0; i < m; i++)
            {
                int[] ab = ReadInts();
                int a = ab[0] - 1;
                int b = ab[1] - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            bool[] visites = new bool[n];
            List<int> startPaths = new List<int>();
            List<int> endPaths = new List<int>();
            int now = 0;
            while (true)
            {
                startPaths.Add(now);
                visites[now] = true;
                bool proceedTemp = false;
                for(int i = 0; i < graph[now].Count; i++)
                {
                    if (!visites[graph[now][i]])
                    {
                        proceedTemp = true;
                        now = graph[now][i];
                        break;
                    }
                }
                if (!proceedTemp)
                {
                    break;
                }
            }
            now = 0;
            while (true)
            {
                endPaths.Add(now);
                visites[now] = true;
                bool proceedTemp = false;
                for (int i = 0; i < graph[now].Count; i++)
                {
                    if (!visites[graph[now][i]])
                    {
                        proceedTemp = true;
                        now = graph[now][i];
                        break;
                    }
                }
                if (!proceedTemp)
                {
                    break;
                }
            }

            Console.WriteLine(startPaths.Count + endPaths.Count - 1);
            for(int i = startPaths.Count-1; i>=0; i--)
            {
                Console.Write((startPaths[i] + 1) + " ");
            }
            for(int i = 1; i < endPaths.Count; i++)
            {
                Console.Write((endPaths[i] + 1) + " ");
            }
            Console.WriteLine();
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 26628
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >>n;
    vector<string>s(n);
    int a,b,ab;
    a=b=ab=0;
    int ans=0;
    for (int i = 0; i < n; ++i) {
        cin>>s[i];
        int m=s[i].size();
        if(s[i].front()=='B' and s[i].back()=='A')ab++;
        else if(s[i].front()=='B')b++;
        else if(s[i].back()=='A')a++;
        for (int j = 0; j < m; ++j) {
            if(s[i].substr(j,2)=="AB")ans++;
        }
    }
    if(ab>0){
        ans+=ab-1;
        if(a>0){
            ans++;
            a--;
        }
        if(b>0){
            ans++;
            b--;
        }
    }
    ans+=min(a,b);
    cout <<ans<<"\n";
}


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

int main(){
  long long N, T;
  cin >> N >> T;

  vector<pair<double, pair<long long, long long>>> a_nz;
  vector<long long> a_z;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    if(a == 0){
      a_z.push_back(b);
    }else{
      a_nz.push_back(make_pair(-1.0 * a / (b + 1), make_pair(a, b)));
    }
  }
  sort(a_z.begin(), a_z.end());
  sort(a_nz.begin(), a_nz.end());

  vector<long long> a_z_sum;
  a_z_sum.push_back(0);
  for(int i = 0; i < a_z.size(); i++){
    a_z_sum.push_back(a_z_sum[i] + a_z[i] + 1);
  }

  // dp[i][j] := using mise[0: i), with time dp[i][j], j shop
  // dp[i + 1][j + 1] = a * (dp[i][j] + 1) + b
  vector<vector<long long>> dp(a_nz.size() + 1,
                               vector<long long>(31, T + 1));
  for(int i = 0; i <= a_nz.size(); i++){
    dp[i][0] = 0;
  }
  for(int i = 0; i < a_nz.size(); i++){
    long long a = a_nz[i].second.first, b = a_nz[i].second.second;
    for(int j = 0; j < 30; j++){
      dp[i + 1][j + 1] = min(dp[i][j + 1], min(dp[i][j] + 1 + a * (dp[i][j] + 1) + b, T + 1));
    }
  }

  /*
  for(int i = 0; i < 30; i++){
    cout << i << ' ' << dp[a_nz.size()][i] << endl;
  }
  */
  
  int ans = 0;
  for(int i = 0; i < 30; i++){
    int zero_cnt = 0;
    long long t_nz = dp[a_nz.size()][i];
    if(t_nz <= T){
      long long t_resid = T - t_nz;
      zero_cnt = (lower_bound(a_z_sum.begin(), a_z_sum.end(), t_resid + 1) - a_z_sum.begin() - 1);
      ans = max(ans, i + zero_cnt);
    }
    //cout << i << ' ' << zero_cnt << ' ' << endl;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 59756
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	vi a(3);
	rep(i,3)cin>>a[i];
	sort(all(a));
	cout<<a[2]-a[0]<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = Long.parseLong(sc.next());
		long V = Long.parseLong(sc.next());
		long B = Long.parseLong(sc.next());
		long W = Long.parseLong(sc.next());
		long T = Long.parseLong(sc.next());

		if(V-W == 0) {
			System.out.println("NO");
			return;
		}

		if(B>A && B<0) {
			System.out.println(Math.abs(B+A) <= (V-W)* T ? "YES":"NO");
		} else if(A>B && A<0) {
			System.out.println(Math.abs(B+A) <= (W-V)* T ? "YES":"NO");
		}else if(B>A) {
			System.out.println((B-A) <= (V-W)* T ? "YES":"NO");
		} else {
			System.out.println((A-B) <= (V-W)* T ? "YES":"NO");
		}
	}
}


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

int main() {
  int A, B, N, X;
  cin >> A >> B;
  N = A * B;
  X = N % 2;
    if(X == 0)
      cout << "Even" << endl;
    else
      cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,M,res=1;
  set<int> yaku;
  cin >> N >> M;
  if(M / N == 1){
    cout << 1 << endl;
    return 0;
  }
  for(int i =1;i*i<=M;i++){
    if(M % i == 0){
      yaku.insert(i);
      yaku.insert(M/i);
    }
  }
  for(auto itr=yaku.begin();itr!=yaku.end();itr++){
    if(M /(*itr) >= N)
      res = max(res,*itr);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
/**
 * Yes, I have a number
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			if (line.equals("END OF INPUT")) break;

			line = line + " ";
			int head = 0;
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < line.length(); i++) {
				if (line.charAt(i) == ' ') {
					sb.append(i - head);
					head = i + 1;
				}
			}
			System.out.println(sb.toString());
		} //end while
	} //end main
}

Measured memory_bytes: 16872
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int N, M; 
    cin >> N >> M;
    vector<P> AB(N);
    priority_queue<int> que;
    for(int i = 0; i < N; i++){
        int a, b; 
        cin >> a >> b;
        AB[i] = {a, b};
    }
    sort(AB.begin(), AB.end());
    int idx = 0;
    int day = 1;
    int ans = 0;
    while(day != M + 1){
        int cnt = 0;
        for(int i = idx; i < N; i++){
            if(AB[i].first <= day){
                cnt++;
                que.push(AB[i].second);
            }
            else break;
        }
        idx += cnt;
        day++;
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4716
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		 
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        sc.close();
        
        int count = 0;
        
        for(int i = 0; i < str.length(); i++){
            String tempStr = String.valueOf(str.charAt(i));
            
            if(tempStr.equals("1")){
                count++;
            } 
        }
        
        System.out.println(count);
    }
}

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

typedef long long int ll;
typedef pair<ll, ll> P;

int N, K;

int main(){
    cin >> N >> K;

    vector< vector<int> > G(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i < j)  G[i].push_back(j);
        }
    }
    int cnt = 0;
    int M = N * (N-1) / 2;
    bool flg = false;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            if(cnt == K){
                flg = true;
                break;
            }
            if(1 < G[i].size()){
                G[i].erase(G[i].begin());
                cnt++;
                M--;
            }
        }
        if(flg) break;

    }

    if(!flg){
        cout << "-1" << endl;
    } else {
        cout << M << endl;
        for(int i=0;i<G.size();i++){
            for(int j=0;j<G[i].size();j++)    cout << i + 1 << " " << G[i][j] + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n, m;

	scanf("%d %d", &n, &m);

	if (n == m)
	{
		printf("Yes\n");
	}

	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define task "abc171"
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// Head:
// Source:
const int maxn = 1e5 + 7;
int n;
ll a[maxn], d[maxn], ans = 0;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
#endif
    cin>>n;
    rep(i, 1, n + 1){
        cin>>a[i];
        ans += a[i];
        d[a[i]] ++;
    }
    int Q;
    cin>>Q;
    rep(i, 1, Q + 1){
        ll x, y;
        cin>>x>>y;
        ans -= d[x] * x;
        ans += d[x] * y;
        d[y] += d[x]; d[x] = 0;
        cout<<ans<<"\n";
    }

}



Measured memory_bytes: 5180
# 写経AC
N,M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
Q = int(input())
VDC = [[int(i) for i in input().split()] for _ in range(Q)]

for i in range(Q):
    VDC[i][0] -= 1

color = [0] * N
# dp[v][d]: 頂点vから距離dは塗装済みか
visited = [[False] * 11 for _ in range(N)]

for v,d,c in reversed(VDC):
    if visited[v][d]: # 既に塗装済み
        continue
    if color[v] == 0:
        color[v] = c
    for dist in range(d + 1):
        # 距離d以下は塗装済み
        visited[v][dist] = True
    
    q = [v]
    for t in range(d - 1, -1, -1):
        qq = []
        for v in q:
            for w in edge[v]:
                if visited[w][t]:
                    continue
                for dist in range(t + 1):
                    visited[w][dist] = True
                if color[w] == 0:
                    color[w] = c
                qq.append(w)
        q = qq

print(*color, sep="\n")

Measured memory_bytes: 58444
N, M = map(int, input().split())
H = [int(n) for n in input().split()]

cur = [0]*N
chk = [0]*N
ans = 0

for i in range(M):
    a, b = [int(n)-1 for n in input().split()]
    if H[a] > H[b]:
        cur[a] += 1
    elif H[a] < H[b]:
        cur[b] += 1

    chk[a] += 1
    chk[b] += 1

for i in range(N):
    if cur[i] == chk[i]:
        ans += 1

print(ans)


Measured memory_bytes: 20140
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int i,g;
  i = a-b;
  if(c-i<=0){
    g = 0;
  }else{
    g = c - i;
  }
  cout << g << endl;



}


Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()
A, B, C, D = A-1, B-1, C-1, D-1
if C < D:
  if "##" in S[A:D+1]:
    print("No")
  else:
    print("Yes")
else:
  if "##" in S[A:C+1]:
    print("No")
  elif "..." in S[B-1:D+2]:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 3572
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll r;cin>>r;
  cout<<fixed<<setprecision(8)<<2*r*PI<<endl;
}
  
  
    

Measured memory_bytes: 3788
import sys
from collections import deque

def solve():
      input = sys.stdin.readline
      K = int(input())
      low, high = 0, 3234566668
      while high - low > 1:
            mid = (low + high) // 2
            midS = str(mid)
            lenS = len(midS)
            q = deque()
            for j in range(lenS):
                  for i in range(1, 10): q.append((i, i, j + 1))
            count = 0
            isRunrun = False
            while q:
                  ns, last, length = q.pop()
                  if length == lenS:
                        if ns <= mid: count += 1
                        if ns == mid: isRunrun = True
                  else:
                        if last == 0: 
                              q.append((ns*10 + 1, 1, length + 1))
                              q.append((ns*10 + 0, 0, length + 1))
                        elif last == 9: 
                              q.append((ns*10 + 8, 8, length + 1))
                              q.append((ns*10 + 9, 9, length + 1))
                        else:
                              q.append((ns*10 + last+1, last + 1, length + 1))
                              q.append((ns*10 + last-1, last - 1, length + 1))
                              q.append((ns*10 + last, last, length + 1))
            if count > K: high = mid
            elif count == K:
                  if isRunrun: low = mid
                  else: high = mid
            else: low = mid
            #print(mid, count)
      print(low)
            
      return 0

if __name__ == "__main__":
      solve()

Measured memory_bytes: 43244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}
int dp[9]={};
int main(){
    fast_io
    
    int n,m;
    cin>>n>>m;
    ll a[n], b[n];
    vector<pair<ll,ll>> p;
    rep(i,n) {
        cin>>a[i]>>b[i];
        p.push_back(make_pair(a[i], b[i]));
    }
    sort(p.begin(), p.end());
    ll cnt=0, ans=0;
    rep(i,n){
        if(m<=cnt+p[i].second){//m越えたら
            ans+=p[i].first*(m-cnt);
            cnt+=m-cnt;
        }
        else{
            ans+=p[i].first * p[i].second;
            cnt+=p[i].second;
        }
        if(cnt>=m) break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a+b>a-b){
    if(a+b>a*b)
    printf("%d\n",a+b);
    else
    printf("%d\n",a*b);
  }else{
    if(a-b>a*b)
    printf("%d\n",a-b);
    else
    printf("%d\n",a*b);
  }
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[200200];
int Ans[200200];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i + 1];
    }
    int num = 0;
    for (int i = N; i >= 1; --i) {
        int temp = 0;
        for (int j = 2 * i; j <= N; j += i) {
            temp += Ans[j];
        }
        if (temp % 2 == A[i]) {
            Ans[i] = 0;
        } else {
            num++;
            Ans[i] = 1;
        }
    }
    int k = 0;
    cout << num << endl;
    for (int i = 1; i <= N; ++i) {
        if (Ans[i]) {
            if (k != 0)cout << " ";
            cout << i;
            k++;
        }
    }
    return 0;
}


Measured memory_bytes: 3968
using System;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int[] n = new int[3];
            n[0] = int.Parse(s[0]);
            n[1] = int.Parse(s[1]);
            n[2] = int.Parse(s[2]);

            Array.Sort(n);
            Console.WriteLine(n[0] + " " + n[1] + " " + n[2]);
            

        }
    }
}

Measured memory_bytes: 9320
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int n,m;
int dist[100005];
bool vis[100005];
int f[100005];

void Dijkstra() {
	memset(dist,0x3f,sizeof(dist));
	dist[1]=0;
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > heap;
	heap.push(make_pair(0,1));
	while(!heap.empty()) {
		pair<int,int> t=heap.top();
		int u=t.second;
		int w=t.first;
		heap.pop();
		if(vis[u]) {
			continue;
		}
		vis[u]=1;
		for(int i=0;i<G[u].size();i++) {
			int v=G[u][i];
			if(dist[v]>dist[u]+1) {
				dist[v]=dist[u]+1;
				f[v]=u;
				heap.push(make_pair(dist[v],v));
			}
		}
	}
}

int main() {
	cin>>n>>m;
	for(int i=1;i<=m;i++) {
  		int u,v;
  		cin>>u>>v;
  		G[u].push_back(v);
  		G[v].push_back(u);
	}
	Dijkstra();
	for(int i=1;i<=n;i++) {
		if(dist[i]==0x3f3f3f3f) {
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++) {
		cout<<f[i]/*dist[i]*/<<endl;
	}
	return 0;
}

Measured memory_bytes: 11232
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    MAX_V = A[-1]
    target = MAX_V // 2 if MAX_V % 2 == 0 else (MAX_V + 1) // 2

    diff = f_inf
    res = A[0]
    for i in range(n - 1):
        if abs(target - A[i]) < diff:
            diff = abs(target - A[i])
            res = A[i]
    print(MAX_V, res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 20024