akhauriyash/Code-Regression huggingface dataset:
def main():
    h,w=map(int,input().split())
    s=[]
    for i in range(h):
        ss=input()
        s.extend(ss)
    mat = [[float("INF")] * (h*w) for i in range(h*w)]
    for i,a in enumerate(s):
        if a == '.':
            mat[i][i] = 0
            makemat(i,mat,h,w,s)
    # mtemp = mat
    # for i , a in enumerate(mat):
    #     print(a)
    for i,a in enumerate(s):
        if a == '.':

            caldist(mat,w*h)
            break
    ans = 0
    # print(mat)
    # for i, a in enumerate(mat):
    #     print(a)
    #     ans = max(ans, max(a))
    print(calans(mat))
def calans(m):
    temp = 0
    for i,w in enumerate(m):
        for j, s in enumerate(w):
            if s != float("INF"):
                temp = max(temp,s)
    return temp
# 隣接行列m作成
def makemat(i,m,h,w,s):

    if (i % w) + 1 != w:
        if s[i+1] == '.':
            j = i+1
            m[i][j] = 1
            m[j][i] = 1
        # else:
        #     j = i+1
        #     m[i][j] = float('INF')
        #     m[j][i] = float('INF')
    if (i % w)  != 0:
        if s[i-1] == '.':
            j = i-1
            m[i][j] = 1
            m[j][i] = 1
        # else:
        #     j = i-1
        #     m[i][j] = float('INF')
        #     m[j][i] = float('INF')
    if i > w:
        if s[i-w] == '.':
            j=i-w
            m[i][j] = 1
            m[j][i] = 1
        # else:
        #     j = i-w
        #     m[i][j] = float('INF')
        #     m[j][i] = float('INF')
    if i < h*w - w:
        if s[i+w] == '.':
            j=i+w
            m[i][j] = 1
            m[j][i] = 1
        # else:
        #     j = i+w
        #     m[i][j] = float('INF')
        #     m[j][i] = float('INF')

def caldist(m,l):
    for i in range(l):
        for j in range(l):
            for k in range(l):
                m[j][k] = min(m[j][k],m[j][i]+m[i][k])


if __name__=='__main__':
    main()


Measured memory_bytes: 133352
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let nums = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<u64>>();
    let (a, b, c, x, y) = (nums[0], nums[1], nums[2], nums[3], nums[4]);

    if (a + b) < 2 * c {
        println!("{}", a * x + b * y);
    } else {
        if x > y {
            if a < 2 * c {
                println!("{}", c * 2 * y + (x - y) * a);
            } else {
                println!("{}", c * 2 * y + (x - y) * 2 * c);
            }
        } else {
            if b < 2 * c {
                println!("{}", c * 2 * x + (y - x) * b);
            } else {
                println!("{}", c * 2 * x + (y - x) * 2 * c);
            }
        }
    }
}


Measured memory_bytes: 4352
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(a,b) = input.nextLine().split(" ").map(_.toInt)

      output.println(if (a * b % 2 != 0) "Yes" else "No")
    }

  }

}


Measured memory_bytes: 25648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * [[iwi]]
 */
public class Main {

	static final String UNIQ = "iwi";
	static final char[][] PAIRS = new char[][]{
			{'w', 'w'},
			{'i', 'i'},
			{'(', ')'},
			{')', '('},
			{'{', '}'},
			{'}', '{'},
			{'[', ']'},
			{']', '['},
	};

	static Map<Character, List<int[]>> sym;

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

		Map<Character, List<Integer>> pos = new HashMap<>();
		sym = new HashMap<>();

		line = br.readLine();

		for (int i = 0; i < line.length(); i++) {
			pos.putIfAbsent(line.charAt(i), new ArrayList<>());
			pos.get(line.charAt(i)).add(i);
		}

		for (char[] key : PAIRS) {
			if (pos.containsKey(key[0]) && pos.containsKey(key[1])) {
				for (int i : pos.get(key[0])) {
					for (int j : pos.get(key[1])) {
						if (key[0] == 'w') {
							if (i <= j) {
								sym.putIfAbsent(key[0], new ArrayList<>());
								sym.get(key[0]).add(new int[]{i, j});
							}
						} else if (key[0] == 'i') {
							if (i < j - 1) {
								sym.putIfAbsent(key[0], new ArrayList<>());
								sym.get(key[0]).add(new int[]{i, j});
							}
						} else {
							if (i < j - 3) {
								sym.putIfAbsent(key[0], new ArrayList<>());
								sym.get(key[0]).add(new int[]{i, j});
							}
						}
					}
				}
			}
		}

		int max = 0;

		for (int[] posw : sym.get('w')) {
			if (posw[0] == posw[1]) {
				for (int[] posi : sym.get('i')) {
					if (posi[0] < posw[0] && posw[1] < posi[1]) {
						max = Math.max(max, solve(posi[0], posi[1], "iwi"));
					}
				}
			}
		}

		System.out.println(max);

	}//end main

	static int solve(int s, int t, String handle) {

		//System.out.println(handle);

		if (handle.indexOf(UNIQ) != handle.lastIndexOf(UNIQ)) return 0;

		int ret = handle.length();

		for (char[] key : PAIRS) {
			if (sym.containsKey(key[0])) {
				for (int[] pos : sym.get(key[0])) {
					if (pos[0] < s && t < pos[1]) {
						ret = Math.max(ret, solve(pos[0], pos[1], key[0] + handle + key[1]));
					}
				}
			}
		}

		return ret;
	}
}

Measured memory_bytes: 24432
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
typedef long long ll;


using namespace std;


int main(){
    int K, X;
    cin >> K >> X;
    if(K*500 >= X){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;

    

    return 0;
}


Measured memory_bytes: 256
/**
 *   
 *   Date: 22 December 2019
 *   Time: 18:05:06
**/
#pragma GCC optimize("O3")
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1000000007;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,cnt=1,d;
	cin>>n;
	ll ar[n+2];
	for(ll i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(ar[i] == cnt)
		{
			cnt+=1;
		}
	}
	cnt-=1;
	d=n-cnt;
	if(d > n-1)
		d=-1;
	cout<<d<<endl;

return 0;
}

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

#define LL long long
const int N = 2005, mod = 1e9 + 7;
int n, m, a[N], b[N], dp[N][N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= m; i++) cin >> b[i];
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            (dp[i][j] += dp[i-1][j] + dp[i][j-1]) %= mod;
            (dp[i][j] += mod - dp[i-1][j-1]) %= mod;
            if(a[i] == b[j]) (dp[i][j] += dp[i-1][j-1] + 1) %= mod;  
        }
    }
    cout << (dp[n][m] + 1) % mod;
}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;

int sum_digits(int a) {
    auto s = to_string(a);
    int ans = 0;
    for (char c : s)
        ans += c - '0';
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n;
    cin >> n;
    int ans = 1000 * 1000 * 1000;
    for (int i = 1; i < n; i++)
        ans = min(ans, sum_digits(i) + sum_digits(n - i));
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<P> robots(n);
    rep(i,n) {
        int x, l;
        cin >> x >> l;
        robots.at(i).second = x-l;
        robots.at(i).first = x+l;
    }
    sort(robots.begin(), robots.end());
    int r = -2e9;
    int count = 0;
    rep(i,n) {
        if (r <= robots.at(i).second) {
            count++;
            r = max(r, robots.at(i).first);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4060
#include <stdio.h>

int main() {
    int x = 0;

    char N[3];
    scanf("%s", N);

    for (int i = 0; i < 3; i++) {
        if (N[i] =='7') {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

int c[10][10];

void warshall_floyd(){
	for(int k = 0; k < 10; k++){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
}

int main() {
	int H, W;
	cin >> H >> W;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			cin >> c[i][j];
		}
	}
	warshall_floyd();
	int A;
	int ans = 0;
	for(int i = 1; i <= H * W; i++){
		cin >> A;
		if(A != -1){
			ans += c[A][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
inputs = [list(map(int, input().split())) for _ in range(D)]

ans = 10 ** 7
for i in range(2 ** D):
    bit = format(i, 'b').zfill(D)
    count = 0
    score = 0
    # ボーナスの分を加算
    for index in range(len(bit)):
        if bit[index] == '1':
            score += 100 * (index + 1) * inputs[index][0] + inputs[index][1]
            count += inputs[index][0]
    if G <= score:
        ans = min(ans, count)
        continue
    
    for j in range(len(bit)-1, -1, -1):
        if bit[j] == '0':
            if G - score <= 100 * (j + 1) * (inputs[j][0] - 1):
                count += (G - score) // (100 * (j + 1)) + (1 if (G - score) % (100 * (j + 1)) != 0 else 0)
                ans = min(ans, count)
                break
            else:
                score += 100 * (j + 1) * (inputs[j][0] - 1)
                count += inputs[j][0] - 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 1000005;
const ll MOD = 1000000007;

int n;

ll ans;
ll fac[MAXN];
ll inv[MAXN];

ll power(ll a,ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			(res *= a) %= MOD;
		(a *= a) %= MOD;
		b >>= 1;
	}
	return res;
}

void init()
{
	fac[0] = 1;
	for (int i = 1;i <= n;i++)
		fac[i] = fac[i - 1] * i % MOD;
	inv[n] = power(fac[n],MOD - 2);
	for (int i = n;i >= 1;i--)
		inv[i - 1] = inv[i] * i % MOD;
}

ll C(int x,int y)
{
	return x < y ? 0 : fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}

int main()
{
	scanf("%d",&n);
	init();
	ll sum = 0;
	for (int i = (n + 1) / 2;i < n;i++)
	{
		ll val = (C(i - 1,n - i - 1) * fac[i] % MOD * fac[n - i - 1] - sum) % MOD;
		(ans += val * i) %= MOD;
		(sum += val) %= MOD;
	}
	printf("%lld\n",(ans + MOD) % MOD);
	return 0;
}

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

int main() {
    char a, b;
    cin >> a >> b;
    if (a=='H' && b=='H') cout << "H\n";
    else if (a=='H' && b=='D') cout << "D\n";
    if (a=='D' && b=='H') cout << "D\n";
    else if (a=='D' && b=='D') cout << "H\n";
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt=0
ans=1
if n%2==0:
	for i in range(n//2):
		if a[2*i]==a[2*i+1]==2*i+1:
			cnt+=1
			ans=(ans*2)%(10**9+7)
		else:
			break
	if cnt==n//2:
		print(ans)
	else:
		print(0)
else:
	if a[0]!=0:
		print(0)
		exit()
	for i in range(n//2):
		if a[2*i+1]==a[2*i+2]==2*i+2:
			cnt+=1
			ans=(ans*2)%(10**9+7)
		else:
			break
	if cnt==n//2:
		print(ans)
	else:
		print(0)
 
 
 

Measured memory_bytes: 14008
import java.util.Scanner;

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

		int result = -1;
		if (String.valueOf(a).length() == 1 && String.valueOf(b).length() == 1) {
			result = a * b;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}
int dp[10000000];
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,d,q=1;
    int c[1000000];
    cin>>a>>b;
    for(int i=0;i<b;i++){
	cin>>d;
	c[d]=1;
    }
    dp[0]=1,dp[1]=1;
    if(c[1]==1) dp[1]=0,q=0;
    for(int i=2;i<=a;i++){
	if(c[i]!=1){
	    dp[i]+=dp[i-1]%mod;
	    dp[i]+=dp[i-2]%mod;
	}
    }
    cout<<dp[a]%mod<<"\n";
    
}



Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int x;
    cin >> x;
    int ans = 1;
    for (int i = 2; i < x; i++)
    {
        for (int j = i*i; j <= x; j*=i)
        {
            ans = max(ans, j);
        }
    }
    cout << ans << endl;
}


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

int main(){
    int r, c;
    while(cin >> r >> c, r){
        vector<int> columns(c);
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                int a;
                cin >> a;
                columns[j] |= a<<i;
            }
        }
        int ans = 0;
        for(int S=0;S<1<<r;S++){
            int tmp = 0;
            for(int j=0;j<c;j++){
                int T = columns[j]^S;
                int cnt = 0;
                for(int i=0;i<r;i++){
                    if((T>>i)&1) cnt++;
                }
                tmp += max(cnt, r-cnt);
            }
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
N,K=map(int,input().split())
if N%K==0:
  print("0")
elif N<K and N<abs(N-K):
  print(N)
else:
  t=N//K
  if abs(N-t*K)<abs(N-(t+1)*K):
    print(abs(N-t*K))
  else:
    print(abs(N-(t+1)*K))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    string s, t;
    read(s,t);
    sort(all(s));
    sort(all(t), greater<>());

    if (s < t) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	static int N;
	static int W;
	static int[] w;
	static int[] v;
	static long[][] memo;
	static int UNCAL = -1;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter p = new PrintWriter(System.out);
		N = sc.nextInt();
		W = sc.nextInt();
		w = new int[N];
		v = new int[N];
		for(int  i = 0 ; i<N ; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		memo = new long[N][W+1];
		for(long[]a:memo)
			Arrays.fill(a,-1);
		System.out.println(dp(0,W));
		
		}
	public static long dp(int i , int remw) {
		if(i==N)
			return 0;
		if(memo[i][remw]!=UNCAL)
			return memo[i][remw];
		long leave = dp(i+1,remw);
		long take = -1;
		if(remw-w[i]>=0)
			take = dp(i+1,remw-w[i])+v[i];
		memo[i][remw] = Math.max(take, leave);
		return Math.max(take,leave);
		
	}
		
	}
	


Measured memory_bytes: 126292
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500 + 100;
int A[Maxn][Maxn];
int N, M;
char safe_getchar()
{
	char ch = getchar();
	while (ch != '#' && ch != '.') ch = getchar();
	return ch;
}
int main()
{
#ifdef hk_cnyali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
		{
			char c = safe_getchar();
			if (c == '#') A[i][j] = 1;
		}
	for (int i = 1; i <= N; ++i)
	{
		for (int j = 1; j <= M; ++j)
			if ((i == 1 || (j & 1) || A[i][j] == 1) && i != N)
				cout<<"#";
			else cout<<".";
		cout<<endl;
	}
	cout<<endl;
	for (int i = 1; i <= N; ++i)
	{
		for (int j = 1; j <= M; ++j)
			if ((i == N || !(j & 1) || A[i][j] == 1) && i != 1)
				cout<<"#";
			else cout<<".";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
int X,A,B;
int main(){
    cin >> X >> A >>B;
    X -= A;
    while(X >= B) X -= B;
    pr(X);
}

Measured memory_bytes: 256
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
			  br = new BufferedReader(new FileReader("input.txt"));
			  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
			  br = new BufferedReader(new InputStreamReader(System.in));
			  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			int n = readInt();
			int a = readInt();
			int b = readInt();
			road = init(n);
			while(a-- > 0) {
				int x = readInt()-1;
				int y = readInt()-1;
				merge(road, x, y);
			}
			rail = init(n);
			while(b-- > 0) {
				int x = readInt()-1;
				int y = readInt()-1;
				merge(rail, x, y);
			}
			int[] ret = new int[n];
			Map<Integer, ArrayList<Integer>> dp = new HashMap<>();
			for(int i = 0; i < n; i++) {
				int key = find(road, i);
				if(!dp.containsKey(key)) {
					dp.put(key, new ArrayList<>());
				}
				dp.get(key).add(i);
			}
			for(int out: dp.keySet()) {
				Map<Integer, ArrayList<Integer>> inner = new HashMap<>();
				for(int out2: dp.get(out)) {
					int key = find(rail, out2);
					if(!inner.containsKey(key)) {
						inner.put(key, new ArrayList<>());
					}
					inner.get(key).add(out2);
				}
				for(int out2: inner.keySet()) {
					for(int out3: inner.get(out2)) {
						ret[out3] = inner.get(out2).size();
					}
				}
			}
			for(int i = 0; i < n; i++) {
				pw.print(ret[i]);
				if(i == n-1) pw.println();
				else pw.print(" ");
			}
		}
		exitImmediately();
	}

	static int[] road;
	static int[] rail;

	public static int[] init(int x) {
		int[] ret = new int[x];
		for(int i = 0; i < x; i++) {
			ret[i] = i;
		}
		return ret;
	}

	public static int find(int[] p, int x) {
		return p[x] == x ? x : (p[x] = find(p, p[x]));
	}
	public static void merge(int[] p, int x, int y) {
		p[find(p, x)] = find(p, y);
	}

	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}

	private static String readLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String readToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}

Measured memory_bytes: 131064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n, k;
    string s;
    cin >> n >> s >> k;
    char t = s[k - 1];
    string ans;
    rep(i, s.size()) {
        if (s[i] == t) {
            ans += s[i];
        }
        else {
            ans += '*';
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
  char c;
  scanf("%c", &c);
  if (c >= 'A' && c <= 'Z')
  {
    printf("A");
  }
  else
  {
    printf("a");
  }
  return 0;
}

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

int main()
{

    int n;
    cin>>n;
    int arr[n];
    for(int i = 0 ;i<n;i++)
    {
        cin>>arr[i];
    }
    int ans = 0 ;
    for(int i = 0 ;i<n;i++)
    {
        int rem = n - (i+1);
        if(rem<ans)
        {
            break;
        }
        int cur = arr[i];
        int tmp = 0 ;
        for(int j = i+1 ;j<n;j++)
        { 
            if(arr[j]>cur)
            {
                break;
            }
            tmp++;
            cur = arr[j];
        }
        
        ans = max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

char str[20];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    long cnt=0;
    long i;
    for(i=0; i<6; i++) {
        if(str[i]=='1') cnt++;
    }
    printf("%ld\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(2)
#include <cstdio>
using namespace std;
int n,m;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
int main()
{
	n=read(),m=read();
	printf("%d\n",(m-1)*(n-1));
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


string s;

int main() {
	
	cin >> s;

	if (s == "Sunny")cout << "Cloudy" << endl;
	else if (s == "Cloudy")cout << "Rainy" << endl;
	else cout << "Sunny" << endl;

	return 0;
}

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

string s;

int main() {
	int n, q, b, c;
	int a[100005] = { 0 };
	long long int ans = 0;
	cin >> n;
	rep(i, n) {
		int ai;
		cin >> ai;
		a[ai]++;
		ans += ai;
	}
	cin >> q;
	rep(i, q) {
		cin >> b >> c;
		a[c] += a[b];
		ans += (c - b)*a[b];
		a[b] = 0;
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	int a, b, k;
	cin>>a>>b>>k;
	int curr = 0;
	vector < int > d;
	for (int i=1; i<a+b; i++) {
		if ((a%i==0) && (b%i==0)) {
			d.push_back(i);
		}
	}
	cout<<d[d.size()-k]<<endl;
}

Measured memory_bytes: 256
def reVal(num):
	if (num >= 0 and num <= 9):
		return chr(num + ord('0'))
	else:
		return chr(num - 10 + ord('A'))
def strev(str):
	par = len(str)
	for i in range(int(par / 2)):
		temp = str[i]
		str[i] = str[par - i - 1]
		str[par - i - 1] = temp
def fromDeci(res, base, inputNum):
	index = 0
	while (inputNum > 0):
		res+= reVal(inputNum % base)
		inputNum = int(inputNum / base)
	res = res[::-1]
	return res

n,k = list(map(int,input().split()))
res = ""; 
x = fromDeci(res, k, n)
print(len(x))

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

public class Main {

	static int n[]=new int[10];
	static boolean count[]=new boolean[10];
	static boolean f;

	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		Scanner sc=new Scanner(System.in);
		String str;
		int i;
		while(sc.hasNext()){
			str=sc.next();
			in(str);
			//						for(i=0;i<10;i++){
			//						System.out.print(" "+n[i]);
			//						}

			for(i=1;i<10;i++){
				n[i]++;
				f=false;
				if(n[i]>4){

				}
				else if(dfs()){
					count[i]=true;
				}
				n[i]--;
			}

			for(i=0;i<10;i++){
				if(count[i]) break;
			}
			if(i==10){
				System.out.println("0");
			}
			else{
				boolean p=true;;
				for(i=1;i<10;i++){
					if(count[i]){
						if(p){
							System.out.print(i);
							p=false;
						}
						else{
							System.out.print(" "+i);
						}
					}
				}
				System.out.println();
			}
			Arrays.fill(count, false);
			Arrays.fill(n, 0);
		}
	}
	static void in(String str){
		for(int i=0;i<13;i++){
			int x=str.charAt(i)-'0';
			n[x]++;
		}
	}

	static boolean dfs(){
		int i;
		if(sum()==2 && check()){

			f=true;
		}
		for(i=1;i+2<10;i++){
			if(n[i]>0 && n[i+1]>0 && n[i+2]>0){
				n[i]--;
				n[i+1]--;
				n[i+2]--;
				dfs();
				n[i]++;
				n[i+1]++;
				n[i+2]++;
			}
		}
		for(i=1;i<10;i++){
			if(n[i]>2){
				n[i]=n[i]-3;
				dfs();
				n[i]=n[i]+3;
			}
		}
		return f;
	}

	static int sum(){
		int i,sum=0;
		for(i=0;i<10;i++){
			sum+=n[i];
		}
		return sum;
	}
	static boolean check(){
		for(int i=1;i<10;i++){
			if(n[i]>0){
				if(n[i]==2){
					return true;
				}
			}
		}
		return false;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SIZE 10
using namespace std;
typedef long long ll;

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

	int N;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> N;

	answer=(N%2)?N/2:N/2-1;
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int Q = sc.nextInt();
        int[] Az = new int[Q];
        for (int i = 0; i < Q; i++) {
            Az[i] = sc.nextInt() - 1;
        }
        int[] rightNum = new int[N];
        for (int i = 0; i < Q; i++) {
            rightNum[Az[i]] ++;
        }

        for (int i = 0; i < N; i++) {
            rightNum[i] = Q - rightNum[i];
        }
        for (int i = 0; i < N; i++) {
            if (rightNum[i] >= K){
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }



    }
}


Measured memory_bytes: 60584
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    for(int i = 0;i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }

    vector<bool> vis(n,false);
    vector<int> dist(n);
    queue<int> que;
    que.push(0);
    vis[0] = true;
    while(que.size()){
        int v = que.front();
        que.pop();
        for(auto i : g[v]){
            if(!vis[i]){
                vis[i] = true;
                dist[i] = dist[v] + 1;
                que.push(i);
            }
        }
    }
    if(dist[n-1] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


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

int main()
{
  int K,A,B;cin>>K>>A>>B;
  int i=0;
  while (i*K<A)
  {
     i++;
  }
  if(A<=i*K && i*K <=B) cout<<"OK"<<endl;
  else cout<< "NG"<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e7;
bool notPrime[maxN + 1], primeSquare[maxN + 1];
int hehe[maxN + 1];
vector<int> primes;
vector<pair<lli, int>> primeFactors[maxN + 1];

vector<pair<lli, int>> getPrimeFactors(lli num)
{
  if (num <= maxN) return primeFactors[num];
  vector<pair<lli, int>> pf;
  for (lli i: primes)
  {
    if (i > num) break;
    if (num % i == 0)
    {
      int p = 0;
      while (num % i == 0) num /= i, p ++;
      pf.push_back({i, p});
    }
  }
  if (num != 1)
    pf.push_back({num, 1});
  return pf;
}

int main()
{
  notPrime[0] = notPrime[1] = true;
  for (int i = 2; i <= maxN; i ++)
  {
    if (!notPrime[i]) primes.push_back(i);
    for (int j = 0; i*primes[j] <= maxN; j ++)
    {
      notPrime[i*primes[j]] = true;
      hehe[i*primes[j]] += 1 + (i != primes[j]);
      if (i % primes[j] == 0) break;
    }
  }
  for (int p: primes)
    if ((lli)p*p <= maxN)
      primeSquare[p*p] = true;

  int n;
  while (scanf("%d", &n) != EOF)
  {
    lli ans = 0;
    for (int i = 1; i <= n; i++)
    {
      int divisors = 1, at = i;
      for (int j = 0; ; j++)
      {
        int p = primes[j];
        if (p * p * p > at) break;

        int cnt = 1;
        while (at % p == 0) at /= p, cnt++;
        divisors = divisors * cnt;
      }

      if (!notPrime[at]) divisors *= 2;
      else if (primeSquare[at]) divisors *= 3;
      else if (at != 1) divisors *= 4;

      ans += (lli)i * divisors;
      DEBUG printf("%d - %d\n", i, divisors);
    }
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 290916
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    long long N, K;
    cin >> N >> K;
    if (N > K) cout << min(N % K, abs(N % K - K)) << endl;
    else {
        cout << min(N, K - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int two=0;
  int one=0;
  bool ichi=false;
  rep(i,n){
    if(s[i]=='3' && (n-1|i)==n-1) {
    two++;
    }
    if(s[i]=='2' && (n-1|i)==n-1) {
    one++;
    }
    if(s[i]=='2') ichi=true;
  }

  if(!ichi){
    cout << (two%2==1? 2:0) << endl;
    return 0;
  }

  cout << (one%2==1? 1:0) << endl;

}

Measured memory_bytes: 1412
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int main(){
  long long dp[55][5000];
  const int G=2500;
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin>>x[i],x[i]-=a;
    
    memset(dp,0,sizeof(dp));
    dp[0][G]=1;
    for(int i=0;i<n;i++){
        for(int s=0;s+x[i]<5000;s++){
          if(dp[i][s]==0) continue;
          dp[i+1][s]+=dp[i][s];
          dp[i+1][s+x[i]]+=dp[i][s];
        }
    }
    
    cout<<dp[n][G]-1<<endl;
    return 0;
}


Measured memory_bytes: 2432
n = int(input())
ls: list = list(map(int, input().split()))

ls.sort(reverse=True)
ans = 0

for i in range(0, n - 2):
    longest = ls[i]
    for j in range(i + 1, n - 1):
        second = ls[j]
        if longest == second:
            continue
        for k in range(j + 1, n):
            shortest = ls[k]
            if second == shortest:
                continue
            elif longest < second + shortest:
                ans += 1
            else:
                break

print(ans)


Measured memory_bytes: 9196
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var W = Console.ReadLine();
            var count = 0;
            var line = "";
            while ((line = Console.ReadLine()) != "END_OF_TEXT")
            {
                var words = line.ToLower().Split();
                foreach (var item in words)
                {
                    if (item == W) ++count;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 5596
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  int A, B; cin >> A >> B;
  if (A < 10 && B < 10) cout << A*B << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
/* vim:set foldmethod=marker: */
#include <bits/stdc++.h>
using namespace std;

//{{{
#define all(x) (x).begin(),(x).end()
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i,a,b) for(int i=(int)(a); i>=b; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

#define dump(x) (cerr << #x << "=" << x << endl)
template<class T> ostream& osContainer(ostream& os,T c) { os<<'[';for(decltype(c.begin()) it=c.begin();it!=c.end();it++)os<<*it<<',';os<<']';return os; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { return osContainer(os,v); }
template<class T> ostream& operator<<(ostream& os,const set<T>& s) { return osContainer(os,s); }
template<class T> ostream& operator<<(ostream& os,const multiset<T>& s) { return osContainer(os,s); }
template<class T,class S> ostream& operator<<(ostream& os,const map<T,S>& m) { return osContainer(os,m); }
template<class T,class S> ostream& operator<<(ostream& os,const multimap<T,S>& m) { return osContainer(os,m); }
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){ os << '(' << p.first << ',' << p.second << ')'; return os; }

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
//}}}
//
void solve()
{
    string s;
    int k;
    getline(cin, s);
    cin >> k;
    int sz = s.size();

    for(int i=0; i<sz; i++){
        int d = ('z'- s[i] + 1) % 26;
        if ( k >= d ) {
            k-=d;
            s[i] = 'a';
        }
    }

    if ( k >= 0 ) {
        int d = k % 26;
        if (s[sz-1] + d > 'z') {
            s[sz-1] = 'a' + (s[sz-1] + d - 'z') - 1;
        } else {
            s[sz-1] += d;
        }
    }

    cout << s << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


struct graph{
    int V;
    vector<VP > v;
    graph(int V) : V(V), v(vector<VP >(V)){}
    void add_diedge(int v1, int v2, ll w){
        v[v1].pb({v2, w});
        v[v2].pb({v1, w});
    }
    void add_edge(int v1, int v2, ll w){
        v[v1].pb({v2, w});
    }
    VL dist = vector<ll>(V, -1);
    VI prever = vector<int>(V,-1);
    VL dijkstra(int start){
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(P(0,start));
        while(!que.empty()){
            P pa = que.top();
            que.pop();
            int u = pa.se;
            if(dist[u] >= 0 && dist[u] < pa.fi)continue;
            dist[u]=pa.fi;
            for(P e : v[u]){
                if(dist[e.fi] < 0 || dist[e.fi] > dist[u] + e.se){
                    dist[e.fi] = dist[u] + e.se;
                    prever[e.fi] = u;
                    que.push(P(dist[e.fi],e.fi));
                }
            }
        }
        return dist;
    }
    void dfs(ll now, ll prv, ll c){
        dist[now]=c;
        for(auto nxt : v[now])if(nxt.fi != prv){
            if(nxt.se % 2)dfs(nxt.fi, now, !c);
            else dfs(nxt.fi, now, c);
        }
    }
    void gprint(){
        rep(i,V){ps(i);ps(": ");for(P x : v[i]){ps(x.fi);ps(",");ps(x.se);ps(" ");}p("");}
    }
 
};



int main(){
    cin>>n;
    graph G(n);
    rep(i,n-1){
        cin>>a>>b>>c;
        a--;b--;
        G.add_diedge(a,b,c);
    }
    //G.gprint();
    G.dfs(0,-1,0);
    rep(i,n)p(G.dist[i]);
    return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	char s1,s2;
	scanf("%d %c %d %c %d",&a,&s1,&b,&s2,&c);
	if(a>2019||a==2019&&b>4) printf("TBD");
	else printf("Heisei");
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=0;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	int n,m;
	cin >>n;
	int t[105],p[105],x[105];
	for(i=0;i<n;i++){
		cin>>t[i];
	}
	cin>>m;
	for(i=0;i<m;i++){
		cin>>p[i]>>x[i];
	}
	for(i=0;i<m;i++){
	ans = 0;
		for(j=0;j<n;j++){
			if(j==p[i]-1){
				ans += x[i];
			}else{
				ans += t[j];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
A0021
 */

#include <stdio.h>
#define EPS (1e-10)
main()
{
  double x1,x2,y1,y2,x3,y3,x4,y4;
  int i,n;



  while(EOF!=scanf("%d",&n) && n)
    {
      for(i=0;i<n;i++)
	{
	  scanf(" %lf %lf %lf %lf %lf %lf %lf %lf",
		&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
  
	  if((x1 == x2) && (x3 == x4))
	    printf("YES\n");
	  else if((x1 == x2) || (x3 == x4))
	    printf("NO\n"); 
	  else if(((y1-y2)/(x1-x2)-(y3-y4)/(x3-x4))==0.0)
	    printf("YES\n");
	  else
	    printf("NO\n");
	}
    }
  return(0);
}

Measured memory_bytes: 620
main = do
  li <- getLine
  let n = read li
  li <- getLine
  putStrLn $
    if n `mod` 2 == 1 then
      "No"
    else if take (n `div` 2) li ==
            drop (n `div` 2) li then
      "Yes"
    else
      "No"
  


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (INT_MAX/2-1)
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int N;
  cin>>N;
  vector<int>V(N),C(N);
  for(int i=0;i<N;i++)cin>>V[i];
  for(int i=0;i<N;i++)cin>>C[i];
  int X=0;
  int Y=0;
  for(int i=0;i<N;i++){
    if(V[i]-C[i]>0){
      X+=V[i];
      Y+=C[i];
    }
  }
  cout<<X-Y<<endl;
  return 0;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            let mut next = || { iter.next().unwrap() };
            input_inner!{next, $($r)*}
        };
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! input_inner {
        ($next:expr) => {};
        ($next:expr, ) => {};

        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };

        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };

        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };

        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };

        ($next:expr, bytes) => {
            read_value!($next, String).into_bytes()
        };

        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };

        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }

fn main() {
    input! {
            n: u32,
        }

    let answer = (n as u64 * (n as u64 - 1u64)) / 2u64;

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

Measured memory_bytes: 4352
def f(n):
  n=int(n)
  if 1<=n<=399:
    return 1
  elif 400<=n<=799:
    return 2
  elif 800<=n<=1199:
    return 3
  elif 1200<=n<=1599:
    return 4
  elif 1600<=n<=1999:
    return 5
  elif 2000<=n<=2399:
    return 6
  elif 2400<=n<=2799:
    return 7
  elif 2800<=n<=3199:
    return 8
  else:
    return 9

n=int(input())
l=list(map(f,input().split()))
v=l.count(9)
t=len(set(l))

if not v:
  print(t,t)
else:
  if t-1:
    print(t-1,t+v-1)
  else:
    print(1,v)

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

#define N 100000
#define K_HAT 3
#define MOD 1000000007

int n; 
int a[N], cntSameHat[N+1];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        a[i]++;
    }
    for (int i = 0; i <= n; i++){
        cntSameHat[i] = 0;
    }
    cntSameHat[0] = 3;

    // 
    int ithCombiHat;
    long combi = 1;
    for (int i = 0; i < n; i++){
        cntSameHat[a[i]]++;
        ithCombiHat = cntSameHat[a[i]-1] - cntSameHat[a[i]] + 1;
        combi = combi * ithCombiHat % MOD;
    }

    cout << combi << endl;

    return 0;
}


Measured memory_bytes: 4412
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		if(s.length()%2!=0) {
			System.out.print("No");
			System.exit(0);
		}
		
		for(int i=0; i<s.length(); i+=2) {
			if(s.charAt(i)=='h' && s.charAt(i+1)=='i') {
				continue;
			}else {
				System.out.print("No");
				System.exit(0);
			}
		}
		
		System.out.print("Yes");
	}
	
}


Measured memory_bytes: 21844
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n, a, b = LI()
    print(min(a*n, b))

main()



Measured memory_bytes: 6324
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 700;

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

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256