akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(System.out);
        Scanner sc = new Scanner();
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int arr[] = {a, b, c, d};
        boolean mark[] = {false, false, false, false};
        int arr2[] = {1, 9, 7, 4};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                if (arr[i] == arr2[j]) {
                    mark[j] = true;
                }
            }
        }
        boolean ok = true;
        for (int i = 0; i < mark.length; i++) {
            if (!mark[i]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }

    static class Scanner {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        int spaces = 0;

        public String nextLine() throws IOException {
            if (spaces-- > 0) {
                return "";
            } else if (st.hasMoreTokens()) {
                return new StringBuilder(st.nextToken("\n")).toString();
            }
            return br.readLine();
        }

        public String next() throws IOException {
            spaces = 0;
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public boolean hasNext() throws IOException {
            while (!st.hasMoreTokens()) {
                String line = br.readLine();
                if (line == null) {
                    return false;
                }
                if (line.equals("")) {
                    spaces = Math.max(spaces, 0) + 1;
                }
                st = new StringTokenizer(line);
            }
            return true;
        }
    }
}


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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

int main() {
  string S;
  int Q;

  cin >> S >> Q;

  int one = 0;
  bool flag = false;
  vector<bool> b;
  vector<int> f;
  vector<string> c;
  rep (i, Q) {
    int q;
    cin >> q;

    if (q == 1) {
      one++;
      flag = !flag;
      continue;
    }
    int F;
    string C;
    cin >> F >> C;
    b.push_back(flag);
    f.push_back(F);
    c.push_back(C);
  }

  rep(i, b.size()) {
    if (f[i] == 1) {
      S = b[i] ? S + c[i] : c[i] + S;
    } else {
      S = b[i] ? c[i] + S : S + c[i];
    }
  }

  if (one % 2 == 1) reverse(S.begin(), S.end());
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 13236
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
c = [int(i) for i in input().split()]
c.sort()
c.reverse()
ans_list = [0 for _ in range(n)]
ans = 0
p_list = [0]
ans_list[0] = c.pop(0)
while len(p_list) > 0:
    p = p_list.pop(0)
    for g in graph[p]:
        if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g)
print(ans)
print(' '.join([str(i) for i in ans_list]))

Measured memory_bytes: 6004
#include <stdio.h>
int main (void){
	int k,p,n,a=0,b=0,c=0,d=0;
	scanf("%d",&n);
	for(a=1;a<=n;a++){
	scanf("%d %d",&k,&p);
		if(k%p==0){
			b=p;
			printf("%d\n",b);
		}
		else {
			c=k%p;
			printf("%d\n",c);
		}
	}
		
	return 0;
}



Measured memory_bytes: 2740
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;


int main(void){
	int n;
	cin >> n;
	int a[n + 1];
	rep(i, n) cin >> a[i + 1];
	int q;
	cin >> q;
	int m[q + 1];
	rep(i, q) cin >> m[i + 1];

	vector<bool> jud(q + 1,false);

	int wa = 0;
	for(int bit = 0; bit < (1 << n); bit++){
		wa = 0;
		for(int i = 0; i < n; i++){
			if(bit & (1<<i)){

				wa += a[i + 1];

			}
		}
		//cout << wa << endl;

		for(int j = 1; j <= q; j++){
			if(m[j] == wa) jud[j] = true;
		}
	}

	for(int a = 1; a <= q; a++ ){
		cout << (jud[a] ? "yes" : "no") << endl;
	}
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int ans = 0;

    if(d == 1)ans = 1;

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#define min(a,b) (((a)<(b))?((a)):((b)))
#define MAX 100000
int altura[MAX];
int custo(int n)
{
    int menorCustoAte[MAX];
    for(int i = 0; i < n; i++)
        menorCustoAte[i] = INT_MAX / 2;
    menorCustoAte[0] = 0;
    for(int i = 0; i < n; i++)
    {
        if(i < n - 1)
            menorCustoAte[i + 1] = min(menorCustoAte[i + 1],
                    menorCustoAte[i] + abs(altura[i] - altura[i + 1]));
        if(i < n - 2)
            menorCustoAte[i + 2] = min(menorCustoAte[i + 2],
                    menorCustoAte[i] + abs(altura[i] - altura[i + 2]));
    }
    return menorCustoAte[n - 1];
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &altura[i]);
    printf("%d\n", custo(n));
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>
#include <algorithm>

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

using namespace std;

inline int max(int a, int b) {
	if (b > a) swap(a, b);
	return a;
}

inline int min(int a, int b) {
	if (a > b) swap(a, b);
	return a;
}




int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	vector<int> d(n);
	rep(i, n) {
		cin >> d[i];
	}

	for (int l = 0; l <= k; l++) {
		for (int r = 0; r <= k - l; r++) {
			int b, sum = 0;
			if (l + r > n) continue;
			vector<int> tmp;
			rep(i, l) {
				tmp.emplace_back(d[i]);
			}
			rep(i, r) {
				tmp.emplace_back(d[n - i - 1]);
			}
			sort(tmp.begin(), tmp.end());
			for (b = 0; b < k - l - r; b++) {
				if (b >= tmp.size()) break;
				if (tmp[b] >= 0) break;
			}
			while (b < tmp.size()) {
				sum += tmp[b];
				b++;
			}
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
input()
xs = map(int, input().split())

n1, n2, n4 = 0, 0, 0

for x in xs:
    if x % 4 == 0:
        n4 += 1
    elif x % 2 == 0:
        n2 += 1
    else:
        n1 += 1

if n2 == 0:
    print("Yes" if n4 >= n1 - 1 else "No")
else:
    print("Yes" if n4 >= n1 else "No")








Measured memory_bytes: 11096
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M,A,B;
int S[1010][1010];

signed main(){
	cin>>N>>M>>A>>B;
	for(int i=0;i<N;i++){
		if(i<N-B){
			for(int j=0;j<A;j++){
				S[i][j]=1;
			}
		}
		else{
			for(int j=A;j<M;j++){
				S[i][j]=1;
			}
		}
	}
	REP(i,N){
		REP(j,M){
			cout<<S[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> sum(n + 1);
    for (int i = 1; i <= n; i++){
        cin >> sum[i];
    }

    for (int i = 1; i <= n; i++){
        sum[i] += sum[i - 1];
    }

    ll ans = 0LL;
    map<int, int> mp;
    for (int i = 0; i <= n; i++){
        ans += mp[sum[i] % m]++;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3968
import math
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(round(math.pow(P,(1/N)))+1)):
    tmp=math.pow(i,N)
    if P==1:
        ans=1
        break
    if N==1:
        ans=P
        break
    if P%tmp==0:
        ans=i
        break
print(ans)

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

int main(){
    ll n,m,s=0,u;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    priority_queue<ll> q;
    rep(i,n){
        q.push(a[i]);
    }
    rep(i,m){
        u=q.top()/2;
        q.pop();
        q.push(u);
    }
    while(!q.empty()){
        s+=q.top();
        q.pop();
    }
    cout << s;
}

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

const int INF = 1000000000;
int d, g, p[20], c[20];

int main(){
  cin >> d >> g;
  rep(i, d) cin >> p[i] >> c[i];
  //compbonus取得の有無をbit全探索
  int res = 1000000000; 
  for(int S = 0; S < (1 << d); S++){
    int score = 0, cnt = 0;
    //compを取得する問題について加算
    rep(i, d){
      if(S & (1 << i)){
        score += p[i] * (i + 1) * 100;
        score += c[i];
        cnt += p[i];
      }
    }
    
    //compを取得しない問題を取る場合は得点が大きいものから貪欲
    for(int i = d - 1; i >= 0; i--){
      if(g < score){
        break;
      }
      if(!(S & (1 << i))){
        //cerr << bitset<10>(S) << " ";
        int rest = g - score;
        int point = (i + 1) * 100;
        int solve = (rest + point - 1) / point;
        //cerr << "rest, point, solve : " << rest <<" "<< point <<" "<< solve<<" ";
        if(solve <= p[i]){
          cnt += solve;
        }else{
          cnt = INF;
        }
        break;
      }
    }
    //cerr << score << " "<< cnt << endl;
    res = min(cnt, res);
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

ll Solve(ll a, ll b) {
    if (a == b) return 2 * a - 2;

    if (b < a) swap(a, b);

    ll lb = a, ub = 2 * b, ab = a * b;
    while (1 < ub - lb) {
        ll mid = 0.5 * (lb + ub);
        ll max_p = (mid + 1) / 2 * (mid + 1 - (mid + 1) / 2);
        if (max_p < ab) lb = mid;
        else ub = mid;
    }

    return lb - 1;
}

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

    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        cout << Solve(a, b) << '\n';
    }

    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;



signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        vector<ll> adj[n+1];
        f(i,1,n)
        {
            ll x;
            cin>>x;
            adj[i].pb(x);
        }
        ll vis[n+1]={0};
        vis[1]=1;
        ll id=2;
        ll per;
        ll sub,r;
        ll x=adj[1][0];
        while(1)
        {
            if(vis[x])
            {
                sub=vis[x];
                r=x;
                per=id-vis[x];
                break;
            }
            vis[x]=id++;
            x=adj[x][0];
        }
        sub--;
        if(k<=sub)
        {
            ll x=1;
            while(k--)
            {
                x=adj[x][0];
            }
            cout<<x<<endl;
            return 0;
        }
        k-=sub;
        k%=per;
        x=r;
        while(k--)
        {
            x=adj[x][0];
        }
        cout<<x<<endl;
    }
    return 0;
}


















Measured memory_bytes: 16096
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt();
        int [] c = new int [n]; int [][] p = new int [n][m];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) p[i][j] = sc.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i <= ((1 << n) - 1); i++) {
            int [] arr = new int [m]; int cost = 0;
            for (int j = 0; j <= n - 1; j++) {
                if (((i & (1 << j)) >>> j) == 1) {
                    for (int k = 0; k < m; k++) {
                        arr[k] += p[j][k];
                    }
                    cost += c[j];
                }
            }
            boolean good = true;
            for (int j = 0; j < m; j++) {
                if (arr[j] < x) good = false;
            }
            if (good) ans = Math.min(ans, cost);
        }
        System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
    }


}

Measured memory_bytes: 37640
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    next().filterIndexed{ index, c ->  index % 2 == 0 }.let(::println)
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 32436
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] ipt = Console.ReadLine().Split(' ');
    bool result = true;
    for (int i = 0; i < N; i++) {
      int a = int.Parse(ipt[i]);
      if (a % 2 == 0) {
        if (a % 3 != 0 && a % 5 != 0) {
          result = false;
          break;
        }
      }
    }
    Console.WriteLine(result ? "APPROVED" : "DENIED");
  }
}

Measured memory_bytes: 13140
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,K = MI()
mod = 10**9+7

G = {}
for i in range(1,N+1):
    G[i] = []
for i in range(N-1):
    a,b = MI()
    G[a].append(b)
    G[b].append(a)

if max(len(G[i]) for i in range(1,N+1)) >= K:
    print(0)
    exit()


def nPr(n,r):  # permutation
    res = 1
    for i in range(r):
        res *= (n-i)
        res %= mod
    return res


from collections import deque

q = deque([(1,0)])  # 頂点、親
ans = K
while q:
    n,m = q.pop()
    if m == 0:
        ans *= nPr(K-1,len(G[n]))
        ans %= mod
        for d in G[n]:
            q.appendleft((d,n))
    else:
        ans *= nPr(K-2,len(G[n])-1)
        ans %= mod
        for d in G[n]:
            if d != m:
                q.appendleft((d,n))
print(ans)


Measured memory_bytes: 92132
#include <stdio.h>
#include <math.h>

int main()
{
	long long n,ans=0,i;
	long long k;
	scanf("%lld%lld",&n,&k);
	long long x[n],y[n];
	for(i=0;i<n;i++)
		scanf("%lld %lld",&x[i],&y[i]);
	for(i=0;i<n;i++){
		if(((x[i]*x[i])+(y[i]*y[i]))<=k*k)
			ans++;
	}
	printf("%lld\n",ans);
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(V),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(ALL(v));
	if (v[0] == 5 && v[1] == 5 &&v[2] == 7)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#今日の精進
#KI
n,q=map(int,input().split())
Node=[0 for i in range(n+1)]
visited=[ False for i in range(n+1)]
from collections import deque
ki_list={i: [] for i in range(1,n+1)}
for i in range( n-1):
    a,b=map(int,input().split())
    ki_list[a].append(b)
    ki_list[b].append(a)
visited[1]=True
d=deque()
e=deque()
d.append(1)
#点の保存リスト
for _ in range(q):
    node,score=map(int,input().split())
    Node[node]+=score

while d:
    for some in d:               
        for point in ki_list[some]:
            if visited[point]==False:
                visited[point]=True
                Node[point]+=Node[some]
                e.append(point)
            elif visited[point]==True:
              pass

    d=e
    e=deque()
print(*Node[1:])
  

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

int main(){
    int N,K; cin >> N >> K;
    long long a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    long long sum[N+1]={};
    for(int i=0;i<N;i++){
        sum[i+1]=sum[i]+a[i];
    }
    map<long long,long long> ma;
    long long ans=0;
    ma[0]++;
    for(int right=1;right<=N;right++){
        if(right>=K){
            ma[((sum[right-K]-(right-K))%K+K)%K]--;
        }
        ans+=ma[((sum[right]-right)%K+K)%K];
        ma[((sum[right]-right)%K+K)%K]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
n= int(input())

list=[]
for i in range(n):
  list.append(input())
  
import collections
c=collections.Counter(list)
t=0
for i in range(n-1):

  if list[i][len(list[i])-1]==list[i+1][0]:
    
    t += 1
  else:
    pass

if t == n-1 and len(c) == n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3436
let n, m, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let bs = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let a_ss = Array.init n @@ fun _ -> Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let f ans a_s = ans + if Array.fold_left (fun (s, i) a -> s + a * bs.(i), i + 1) (c, 0) a_s |> fst > 0 then 1 else 0
let _ = Array.fold_left f 0 a_ss |> Printf.printf "%d\n"

Measured memory_bytes: 4480
def num_div(n):
  p=[]
  for i in range(2,int(n**0.5)+1):
    while n%i==0:
      p.append(i)
      n//=i
  if n>1:
    p.append(n)
  return p

n=int(input())
x=[0]*(n+1)
for i in range(1,n+1):
  for j in num_div(i):
    x[j]+=1
ex2=len([i for i in x if i>1])
ex4=len([i for i in x if i>3])
ex14=len([i for i in x if i>13])
ex24=len([i for i in x if i>23])
ex74=len([i for i in x if i>73])
print(ex4*(ex4-1)//2*(ex2-2)+ex24*(ex2-1)+ex14*(ex4-1)+ex74)

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

int main(){
    vector<vector<char>> c(2, vector<char> (3));
    for(int i = 0;i < 2;i++){
        for(int j = 0;j < 3;j++)cin >> c.at(i).at(j);
    }
    if(c.at(0).at(0) == c.at(1).at(2) && c.at(0).at(1) == c.at(1).at(1) && c.at(0).at(2) == c.at(1).at(0)){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 3608
N, K = map(int, input().split())
p = [int(x) for x in input().split()]
s = sum(p[0 : K])
ans = sum(p[0 : K])
f = N-K+1
for i in range(1, f):
    s = s - p[i-1] + p[i + K - 1]
    if ans <= s:
        ans = s
print((ans + K) / 2)

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

int main() {
  
  int N, x;
  int cnt = 0;

  cin >> N >> x;

  vector<int> a(N);
  
  for (int i = 0; i < N; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  for (int i = 0; i < N; i++) {
    if (x >= a.at(i)) {
      if ((i == N - 1) && (x != a.at(i))) break;
      else {
        x -= a.at(i);
        cnt++;
      }
    }
    else break;
  }
  
  cout << cnt << endl;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=1; i<=m; ++i)
	{
		int a;
		scanf("%d",&a);
		sum += a;
	}
	if(sum>n) printf("-1");
	else printf("%d",n-sum);
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		TreeSet<String> ID = new TreeSet<String>();
		while(n-- != 0)
		{
			String str = stdIn.next();
			ID.add(str);
		}
		int m = stdIn.nextInt();
		boolean flag = false;
		while(m-- != 0)
		{
			String str = stdIn.next();
			if(ID.contains(str))
			{
				if(flag)
				{
					System.out.println("Closed by " + str);
				}
				else
				{
					System.out.println("Opened by " + str);
				}
				flag = !flag;
			}
			else
			{
				System.out.println("Unknown " + str);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
using namespace std;
const int MAXN = 1e5 + 10;
const ll MOD = 1e9 + 7;
ll N, M, Q;
char str[110];
vector<ll> vec;

int main()
{
	int i, j;
	ll K;
	scanf("%s %lld", str, &K);
	N = strlen(str);
	if (N == 1) {
		printf("%lld", K/2LL);
		return 0;
	}

	ll cnt;
	for (i = 0; i < N;) {
		cnt = 1LL;
		for (j = i + 1; j < N; ++j) {
			if (str[i] == str[j]) ++cnt;
			else break;
		}
		vec.push_back(cnt);
		i = j;
	}

	ll ans;
	ll sum = 0;
	if (N >= 2 && vec.size() == 1) {
		printf("%lld", vec[0] * K / 2LL);
		return 0;
	}
	for (i = 0; i < vec.size(); ++i) sum += (vec[i] / 2LL);
	if (str[0] == str[N - 1]) {
		ans = (vec.front() + vec.back()) / 2LL * (K - 1LL) + vec.front() / 2LL + vec.back() / 2LL;
		sum -= vec.front() / 2LL;
		sum -= vec.back() / 2LL;
		ans += (sum * K);
	}
	else {
		ans = (sum *K);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
int h[100005];
int main(void)
{
    int N;
    cin >> N;
    int B[105],A[105];
    int prev;
    int ans=0;
    memset(A,0,sizeof(A));
    for(int i=1;i<=N-1;i++)
    {
        cin >> B[i];
    }
    if(N==2)
    {
        cout << B[1]*2 << endl;
        return 0;
    }
    for(int i=1;i<=N-1;i++)
    {
        if(i==1)
        {
            A[i]=B[i];
            A[i+1]=B[i];
            prev=B[i];
        }
        else
        {
            if(prev<=B[i])
            {
                A[i+1]=B[i];
            }
            else
            {
                A[i]=B[i];
                A[i+1]=B[i];
            }
            prev=B[i];
        }
    }
    for(int i=1;i<=N;i++)
    {
        ans+=A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc014/tasks/agc014_b

//参考：
//http://ronly.hatenablog.com/entry/2017/10/14/201150

//ポイント1：
//木の根をrとするとクエリ(a,b)は(r,a)と(r,b)に分割できる
//ポイント2：
//クエリ(r,i)をa_i回行うとする
//すべてのiに対し、a_iが偶数であれば良い
//奇数回しかクエリに出ていない数の中で一番深いノードをxとすると
//xの上の辺には+1しかされていないため全てを偶数にすることはできない

//考え方：
//一本の鎖を考える

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL A[100000],B[100000];

string ans = "YES";

void solve(){
	vector<LL> counter(N+1,0);//点iの出現回数をcounter[i]とおく
	for(int i=0;i<M;i++){
		counter[A[i]]++;
		counter[B[i]]++;
	}
	for(int i=0;i<=N;i++){
		if(counter[i]%2==1){
			ans = "NO";
			return;
		}
	}
}

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

    solve();

	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(){
	int kiri, kanan, pembagi;
	int output = 0;	
	scanf("%d %d %d", &kiri, &kanan, &pembagi);
	
	for (int i=kiri; i<=kanan; i++){
		if(i%pembagi==0){
			output++;

		}
	}
	printf("%d", output);
	
	return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main(){
	int n, q;
	cin >> n >> q;
	UnionFind tree(n);
	int com;
	while (cin >> com) {
		if (com == 0) {
			int a, b;
			cin >> a >> b;
			tree.unite(a, b);
		}
		else {
			int a, b;
			cin >> a >> b;
			if (tree.same(a, b)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
}


Measured memory_bytes: 3172
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define pb push_back
using namespace std;
const int N=2e5+10,inf=1e9;
int n,c,p[N],q[N],id[N],x;vector<int> a[N];
struct edge{int u,v,c,f;};
struct Dinic{
    vector<edge> e;
    vector<int> G[N];queue<int> q;
    int cur[N],d[N],n,m,s,t,ma[N],cnt,p[N],_n;bool vis[N];
    inline void add(int u,int v,int c){
        //printf("%d %d %d\n",u,v,c);
        e.pb((edge){u,v,c,0});e.pb((edge){v,u,0,0});
        m=e.size();G[u].pb(m-2);G[v].pb(m-1);
    }
    bool bfs(){
        memset(d,0,sizeof(d));memset(vis,0,sizeof(vis));vis[s]=1;q.push(s);
        while(!q.empty()){
            int u=q.front();q.pop();
            for(int &x:G[u]){
                edge &E=e[x];
                if(E.c>E.f&&!vis[E.v]) d[E.v]=d[u]+1,vis[E.v]=1,q.push(E.v);
            }
        }
        return vis[t];
    }
    int dfs(int u,int a){
        if(u==t||!a) return a;
        int flow=0,f;
        for(int &i=cur[u];i<(int)G[u].size();++i){
            edge &E=e[G[u][i]];
            if(d[E.v]==d[u]+1&&(f=dfs(E.v,min(a,E.c-E.f)))){
                E.f+=f;e[G[u][i]^1].f-=f;
                flow+=f;a-=f;if(!a) break;
            }
        }
        return flow;
    }
    int max_flow(int s,int t){
        this->s=s;this->t=t;
        int flow=0;
        while(bfs()){memset(cur,0,sizeof(cur));flow+=dfs(s,inf);}
        return flow;
    }
    void DFS(int u){
        ++cnt;vis[u]=1;
        for(int &x:G[u]){
            edge &E=e[x];
            if(E.v!=t&&!vis[ma[E.v]]) p[ma[E.v]-_n]=u-_n,DFS(ma[E.v]);
        }
    }
    void solve(int n){
        memset(vis,0,sizeof(vis));_n=n;
        rep(i,2,n){
            for(int &x:G[i]){
                edge &E=e[x];
                if(E.v!=s&&E.f) ma[i]=E.v;
            }
        }
        DFS(n+n);
        if(cnt!=n) puts("-1");
        else rep(i,2,n) printf("%d %d\n",ma[i]-n,p[ma[i]-n]);
    }
}G;
int main(){
    //freopen("in","r",stdin);
    scanf("%d",&n);int S=1,T=2*n+1;G.n=T;
    rep(i,1,n-1) G.add(1,i+1,1);
    rep(i,1,n-1){
        scanf("%d",&c);
        rep(j,0,c-1) scanf("%d",&x),G.add(i+1,x+n,1);
    }
    rep(i,1,n-1) G.add(i+n,T,1);
    int t=G.max_flow(S,T);if(t!=n-1) return puts("-1"),0;
    G.solve(n);
    return 0;
}

Measured memory_bytes: 39928
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
#include  <sstream>
#include  <bitset>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

const ll M = 998244353;

int main()
{
	int n, k;
	cin >> n >> k;
	Vi L(k), R(k);
	rep(i, k) cin >> L[i] >> R[i];

	Vl A(n + 1, 0);
	Vl dp(n + 1, -1);
	dp[1] = 1;
	A[2] = -1;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < k; j++) {
			if (i + L[j] <= n)  A[i + L[j]] += dp[i] % M;
			if (i + R[j] + 1 <= n)   A[i + R[j] + 1] -= dp[i] % M;
		}
		/*for (int i = 1; i <= n; i++) {
			cout << A[i];
		}
		cout << endl;*/
		dp[i + 1] = (dp[i] + A[i + 1]);
	}
	cout << dp[n] % M << endl;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;

int main(){
   // freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int x, a, b;
    cin >> x >> a >> b;
    if(-a + b <= 0)
        cout << "delicious\n";
    else if(-a + b <= x)
        cout << "safe\n";
    else 
        cout << "dangerous\n";
    return 0;
}   

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

int main() {
    int X[3], K;
    ll ans = 0;
    cin >> X[0] >> X[1] >> X[2] >> K;
    vector<ll> A[3];
    priority_queue<tuple<ll, int, int, int>> que;
    set<tuple<int, int, int>> s;
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < X[i]; ++j) {
            ll tmp;
            cin >> tmp;
            A[i].push_back(tmp);
        }
        sort(A[i].begin(), A[i].end(), greater<ll>());
    }
    que.push(make_tuple(A[0][0] + A[1][0] + A[2][0], 0, 0, 0));
    s.insert(make_tuple(0, 0, 0));
    cout << get<0>(que.top()) << endl;
    for(int i = 1; i < K; ++i) {
        int a, b, c;
        auto t = que.top();
        que.pop();
        a = get<1>(t);
        b = get<2>(t);
        c = get<3>(t);
        if(a + 1 < X[0] && s.find(make_tuple(a + 1, b, c)) == s.end()) {
            s.insert(make_tuple(a + 1, b, c));
            que.push(make_tuple(A[0][a + 1] + A[1][b] + A[2][c], a + 1, b, c));
        }
        if(b + 1 < X[1] && s.find(make_tuple(a, b + 1, c)) == s.end()) {
            s.insert(make_tuple(a, b + 1, c));
            que.push(make_tuple(A[0][a] + A[1][b + 1] + A[2][c], a, b + 1, c));
        }
        if(c + 1 < X[2] && s.find(make_tuple(a, b, c + 1)) == s.end()) {
            s.insert(make_tuple(a, b, c + 1));
            que.push(make_tuple(A[0][a] + A[1][b] + A[2][c + 1], a, b, c + 1));
        }
        cout << get<0>(que.top()) << endl;
    }
    return 0;
}


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

using namespace __gnu_pbds;
using namespace std;


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

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}

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

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


int32_t main()
{
    fast;
    int x,y,z;cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y;
}

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

int main(){
	int x, y;
	cin >> x >> y;

	for(int i = 0; i <= x; i++){
    
    	int val = i*2 + (x-i)*4;

		if(val == y){
        	cout << "Yes";
            exit(0);
        }
    }
    cout << "No";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s, w; cin >> s >> w;
	std::vector<int> a(26, 0), b(26, 0);
	for(int i = 0; i < s.size(); i++) a[s[i] - 'a']++;
	for(int i = 0; i < w.size(); i++) b[w[i] - 'a']++;
	sort(begin(a), end(a)); sort(begin(b), end(b));
	
	for(int i = 0; i < 26; i++) {
		if(a[i] != b[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

struct unionFind{
    vector<ll> par;
    vector<ll> siz;

    void init(ll n){
        for(ll i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    ll root(ll x){
        //根を返す
        if(par[x]==x){
            return x;
        }
        else{
            return (par[x]=root(par[x]));
        }
    }
    bool sameParent(ll x,ll y){
        return(root(x)==root(y));
    }
    void unite(ll x, ll y){
        x=root(x);y=root(y);
        if(x==y)    return;
        //データ構造->小を大にくっつける
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y]=x;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    ll ans=0;
    for(int i=0;i<m;i++){
        unionFind uf;
        uf.init(m);
        for(int j=0;j<m;j++){
            if(i==j) continue;
            uf.unite(a[j],b[j]);
        }
        if(uf.size(0)!=n) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str, tmp;
  bool res, judge[256];

  cin >> str;
  tmp = str;
  sort(ALL(tmp));
  int last = str.size();
  res = true;
  REP(i, last)  judge[tmp[i]] = true;
  REP(i, last)  judge[str[i]] = !judge[str[i]];
  REP(i, last){
    if (!judge[str[i]]){
      res = false;
      break;
    }
  }
  cout << (res ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(1,N):
  A[i]+=A[i-1]
  #A[i]=(A[i]+A[i-1]-1)%K

for i in range(N):
  A[i]-=(i+1)
  A[i]%=K
A=[0]+A
D={}
ans=0
for j in range(1,N+1):
  D[A[j-1]]=D.get(A[j-1],0)+1
  if j-K>=0:
    D[A[j-K]]-=1
  ans+=D.get(A[j],0)
print(ans)
  

Measured memory_bytes: 37912
N, K = map(int, input().split())
A = list(map(int, input().split()))
pos = 0
res = [-1] * 3*10**5
d = 0
way = []
l = 0
c = 0

for i in range(N) :
    A[i] -= 1
    
for i in range(K+1):
    if(res[pos] != -1) :
        l = d - res[pos]
        c = d - l
        res[pos] = d
        break
    res[pos] = d
    way.append(pos)
    d += 1
    pos = A[pos]

ans = 0
if(K+1 <= len(way)) :
    ans = way[K]
else :
    K -= c
    K = K%l
    ans = way[K + c]
print(ans+1)

Measured memory_bytes: 32300
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
l1 = 0
l2 = 0
j = 0
for i in range(n - 1):
    j = i + 1
    if a[i] == a[i + 1]:
        l1 = a[i]
        j = i + 2
        break
for i in range(j, n - 1):
    if a[i] == a[i + 1]:
        l2 = a[i]
        break
print(l1 * l2)


Measured memory_bytes: 14672
#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(){
  string s ;
  cin >> s ;
  int a,b;
  a = s.size();
  a--;
  b = 0;
  int count = 0;
  rep( i, s.size()/2 ){
    if( s[b] == s[a] ){
      b++; a--;
      continue;
    }
    else if( s[b] != s[a] ){
      count ++;
      b++; a--;
      continue;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length();
    rep(i,n-1){
        cout<<s[i]<<t[i];
    }
    if(t.length()==n){
        cout<<s[n-1]<<t[n-1]<<endl;
    }
    else{
        cout<<s[n-1]<<endl;
    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=1,anss=0,a,b,c,d,e,f,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0,mizu,satou;
//double gendo,noudo,cmpnoudo;
string s;

vector<int> z;

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

       cin >> a >> b >> c >> d >> e >> f;
      // gendo=(double)(100*e)/(100+e);
      // Cout(gendo);
       for(int i=0;100*a*i<=f;i++){
           for(int j=0;100*a*i+100*b*j<=f;j++){
               for(int k=0;100*a*i+100*b*j+c*k<=f;k++){
                   for(int l=0;100*a*i+100*b*j+c*k+d*l<=f;l++){
               mizu=(i*a+j*b)*100;
               satou=c*k+d*l;
             //  cout << mizu << " " << satou << endl;
               
              // if(satou==0){
                //   noudo=0;
               //}
              // else{
              // noudo=(double)(100*satou)/(mizu+satou);
               //}
               //Cout(noudo);
               //Cout(satou);
               if(mizu!=0 &&  1.0*100*satou/mizu<=e && 1.0*satou/(satou+mizu)>=1.0*anss/ans){
                  // if(cmpnoudo<noudo){
                     //  cmpnoudo=noudo;
                      ans=satou+mizu;
                      anss=satou;
                     //cout << ans << " " << anss << endl;
                  // }
               }
           }
       }
           }
       }
       cout << ans << " " << anss << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  vec b(a);
  For(i,0,a)
    ci(b[i]);
  ll c=b[0];
  For(i,1,a)
    c=gcd(c,b[i]);
  co(c);
}

Measured memory_bytes: 1024
def factorize(n):
    ## 素因数分解
    # arr = factorize(20)
    # arr == [[2, 2], [5, 1]]
    
    result = []
    tmp = n
    for k in range(2, int(n ** 0.5) + 1):
        cnt = 0
        while tmp % k == 0:
            cnt += 1
            tmp //= k
        if cnt > 0:
            result.append([k, cnt])
    if tmp != 1:
        result.append([tmp, 1])
    return result


def hantei(n, m):
    if n * (n + 1) // 2 <= m:
        return False
    else:
        return True
def binary_search(l, r, m, hantei):
    ## hanteiはTrue or Falseを返すfunction
    while True:
        if r - l <= 1:
            break
        now = (r + l) // 2
    #     print(l, now, r)
        if hantei(now, m):
            r = now
        else:
            l = now
    return l


n = int(input())
f = factorize(n)

s = 0
for ff in f:
    s += int(binary_search(0, ff[1] + 1, ff[1], hantei))

print(s)

Measured memory_bytes: 9484