akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
map< int , int > mp;
int main()
{
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		mp[x]++;
	} 
	int cnt = 0;
	for(auto it : mp){
		if(it.second == 2)
			cnt++;
	}
	if(cnt != n/2)
	{
		cout << 0 << endl;
		return 0;
	}
	if(n % 2 && mp[0] == 2){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for(int i = 0 ; i < n/2 ; i++){
		ans = (ans * 2)%mod;
	}
	cout << ans << endl;
	return 0;
}



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


int main()
{
	int n;
	cin>>n;
	
	int len=0;
		
	int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		
		if(a==b)
			len++;
		else
			len=0;
		
		if(len>2)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
//--- pD ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	// 0 1 2 3 4
	//     2 3 4

	private void run_case() {
		int n = reader.ni();
		long k = reader.nl();
		int[] arr = new int[n+1];
		for (int i=1; i<=n; i++) arr[i] = reader.ni();

		int cur = 1;
		int step = 0;
		Map<Integer, Integer> map = new HashMap<>();
		Map<Integer, Integer> map_step = new HashMap<>();

		while (!map.containsKey(cur)) {
			// out.println("step = " + step);
			map.put(cur, step);
			map_step.put(step, cur);
			cur = arr[cur];
			step ++;
			if (step == k) {
				out.println(cur);
				return;
			}
		}

		// System.out.println("step = " + step + ", cur = " + cur);
		int start = map.get(cur);
		long len = step - start;

		k -= start;
		k %= len;

		int key = (int)k;
		// out.println("len = " + len + ", k = " + k);
		int res = map_step.get(start + key);
		System.out.println(res);

		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 72636
(function(input) {
  'use strict';
  input.split("\n").some(function(line) {
    const stringOfN = line.toString()
    const ArrayOfN = stringOfN.split("")
    let res = ArrayOfN.map(function(char){
      if (char === '1' ) return '9'
      if (char === '9' ) return '1'
    }).toString()
    res = res.replace(/,/gi, "")
    console.log(res);
  })
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
  ll n,b,x,y,i;
  cin >> n;
  ll a[n];
  b=0;
  for(i=1;i<=n;i++){
    cin >> a[i];
    b+=a[i];
  }
  b=b/n;
  x=0;
  y=0;
  for(i=1;i<=n;i++){
    x+=(a[i]-b)*(a[i]-b);
    y+=(a[i]-b-1)*(a[i]-b-1);
  }
  cout << min(x,y);
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;

template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N, K = 0;
    cin >> N;
    for(int i = 1; i * (i - 1) <= 2 * N; i++){
        if(i * (i - 1) / 2 == N) K = i;
    }
    if(K == 0){
        PRINT("No");
        return 0;
    }
    vector<vector<int>> v(K);
    int n = 1;
    REP(i, K - 1){
        FOR(j, i + 1, K){
            v[i].push_back(n);
            v[j].push_back(n);
            n++;
        }
    }
    PRINT("Yes");
    PRINT(K);
    REP(i, K){
        cout << v[i].size() << " ";
        REP(j, v[i].size()){
            cout << v[i][j];
            if(j == v[i].size() - 1) cout << endl;
            else cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b;
	cin >> a >> b;
	int x = ((a + b) % 2 == 0) ? (a + b) / 2 : (a + b) / 2 + 1;
	cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;


int main()
{
	ll S, M;
	cin >> S >> M;
	if (2 * S > M)
	{
		cout << M / 2 << endl;
	}
	else
	{
		cout << S + (M - 2 * S) / 4 << endl;
	}
	
	return 0;
}


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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
 	string s; cin >> s;
 	int a = 0, b = 0;
 	_for(i,0,3) if(s[i] == 'A') a++; else b++;
 	if(a && b) yes; else no;
}

Measured memory_bytes: 3620
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <tuple>
#define REP(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
using namespace std;

bool compare(const tuple<int,int,int> &a, const tuple<int,int,int> &b){
	if(get<0>(a) == get<0>(b)){
			if(get<1>(a) == get<1>(b)){
				return get<2>(a) < get<2>(b);
			}
			return get<1>(a) < get<1>(b);
		}
		return get<0>(a) > get<0>(b);
}
			
int main(){
	int t,p,r;
	while(cin>>t>>p>>r,t){
		vector<tuple<int,int,int> > inf_team(t,tuple<int,int,int>(0,0,0));//problem,time,number
		REP(i,t)get<2>(inf_team[i]) = i;
		vector<vector<int> > penalty(t,vector<int>(p,0));
		REP(i,r){
			int t_id,p_id,time;
			string mes;
			cin >> t_id >> p_id >> time >> mes;
			t_id--;p_id--;
			if(mes=="WRONG"){
				penalty[t_id][p_id]++;
			}else{
				get<1>(inf_team[t_id]) += time + 1200*penalty[t_id][p_id];
				get<0>(inf_team[t_id])++;
			}
		}
		sort(inf_team.begin(),inf_team.end(),compare);
		REP(i,t){
			cout << get<2>(inf_team[i]) + 1 << " " << get<0>(inf_team[i]) << " " << get<1>(inf_team[i]) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <bits/stdc++.h>
#define mod 100000000000000000
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    for(int i=0; i<a.size(); i++){
        if(a[i]!='0'){swap(a[i],a[0]); break;}
    }
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int main()
{
    Fastio();
    double x; cin>>x;
    cout<<ceil(x/2.0)<<'\n';

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

from heapq import *

n,m = [int(i) for i in readline().split()]
ab = [[int(i) for i in readline().split()] for _ in range(n)]

ab.sort(reverse = True)
#ab.sort()

#print(ab)
q = []
ans = 0
for i in range(m-1,-1,-1):
    while ab and ab[-1][0] + i <= m:
        (a,b) = ab.pop()
        heappush(q,-b)
    
    if q: ans -= heappop(q)
#    print(ans)



print(ans)






Measured memory_bytes: 22908
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        int[] counts = new int[length];
        ArrayDeque<Integer> stack = new ArrayDeque<>();
        for (int i = 0; i < length; i++) {
            if (arr[i] == 'R') {
                stack.push(i);
            } else {
                while (stack.size() > 0) {
                    counts[i - (i + stack.pop()) % 2]++;
                }
            }
        }
        for (int i = length - 1; i >= 0; i--) {
            if (arr[i] == 'L') {
                stack.push(i);
            } else {
                while(stack.size() > 0) {
                    counts[i + (i + stack.pop()) % 2]++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(counts[i]);
        }
        System.out.println(sb);
        
    }
}

Measured memory_bytes: 43256
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	string N;
	cin >> N;
	int msb, ans, tmp = 0;

	if (N.length() > 1) {

		msb = (int)N[0] - (int)'0';
		
		ans = (msb - 1) + 9 * (N.length() - 1);
		for (int i = 0; i < N.length(); i++) {
			tmp += (int)N[i] - (int)'0';
		}

		ans > tmp ? cout << ans : cout << tmp;
		cout << endl;

		return 0;
	}
	
	cout << N << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	int m = 2 * n;
	vector<int>a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int sum = 0;
	int p;
	for (int i = 0; i < n; i++) {
		p = 2 * i;
		sum += a[p];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void dfs(vector<vector<int>> &tree, int now, vector<int> &c, vector<int> &nd, int &index, int &ans){
  for(auto i : tree.at(now)){
    if(nd.at(i) != -1) continue;
    nd.at(i) = c.at(index++);
    ans += nd.at(i);
    dfs(tree, i, c, nd, index, ans);
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> tree(n, vector<int>());
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  vector<int> c(n);
  rep(snip_i, n) cin >> c.at(snip_i);
  sort(c.rbegin(), c.rend());
  vector<int> nd(n, -1);
  nd.at(0) = c.at(0);
  int ans = 0, index = 1;
  dfs(tree, 0, c, nd, index, ans);
  cout << ans << endl;
  rep(i, n){
    if(i != 0) cout << " ";
    cout << nd.at(i);
  }
  cout << endl;
  return 0;
}

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

4 4
3 4 5 6
3 4 5 6

  1 2 3 4
1 1 0 0 0
2 0 2 0 0
3 0 0 4 0
4 0 0 0 8
一致したら1手前の総和+1みたいなかんじ

4
1 2 3 4
1 2 2 2

  1 2 3 4
1 1 0 0 0
2 0 2 0 0
3 0 2 0 0
4 0 2 0 0 7+1=8通り？
一致してなかったら増えるの0通り、で

4
1 1 3 4
1 2 1 2

N*M*2でいけるかな
  1 2 3 4
1 1 0 1 0
2 1 0 2 0
3 0 0 0 0
4 0 0 0 0 5+1=6通り
3-2で一致していたら2-1の総和に+1する、という発想

total出すのが時間かかるのか
常に総和としてデータをおさえておきたい
  1 2 3 4
1 1 0 1 0
2 1 0 2 0
3 0 0 0 0
4 0 0 0 0

別配列作るのか
SUM
  1 2 3 4
1 1 1 2 2
2 2 2 5 5
3 2 2 5 5
4 2 2 5 5 5+1=6

4
1 1 3 4
1 2 1 2

まず外うめ？
  1 2 3 4
1 1 1 2 2
2 2 
3 2 
4 2 

  1 2 3 4
1 1 1 2 2
2 2 2 4 
3 2 
4 2 

二次元累積和が理解できてないのかな
  1 2 3 4
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 1 1 1

  1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3
4 4

外うめだけ必要？
*/

int main(){
  ll N,M,MOD=1e9+7; cin>>N>>M;
  vector<ll> S(N+1,0), T(M+1,0);
  vector<vector<ll>> DP(N+1,vector<ll>(M+1,0)), sum(N+1,vector<ll>(M+1,0));
  for(ll i=1; i<=N; i++) cin>>S[i];
  for(ll i=1; i<=M; i++) cin>>T[i];
  for(ll i=1; i<=N; i++) for(ll j=1; j<=M; j++){
    if(S[i]==T[j]) (DP[i][j]=sum[i-1][j-1]+1)%=MOD;
    (sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+DP[i][j])%=MOD;
  }
  cout<<(sum[N][M]+1+MOD)%MOD<<endl;
}

Measured memory_bytes: 62976
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int L = sc.nextInt();
        int ans = 0;
        int bite = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++){
            ans += L+i;
            if(Math.abs(bite) > Math.abs(L+i)){
                bite = L+i;
            }
        }
        System.out.println(ans-bite);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25316
import java.io.*;
import java.util.*;

    public class Main extends PrintWriter {
        Main() { super(System.out, true); }
        Scanner sc = new Scanner(System.in);
        public static void main(String[] $) {
            Main o = new Main(); o.main(); o.flush();
        }

        void main(){
            int A = Integer.parseInt(sc.next());
            int B = Integer.parseInt(sc.next());

            if(A != 1 && B != 1){
                print('1');
        }
            if(A != 2 && B != 2){
                print('2');
            }
            if(A != 3 && B != 3){
                print('3');
            }
    }
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

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

  ll h, w;

  cin >> h >> w;

  char c[h][w];

  REP(i, h) {
    REP(j, w) { cin >> c[i][j]; }
  }

  REP(i, h) {
    REP(j, 2) {
      REP(k, w) { cout << c[i][k]; }
      cout << "\n";
    }
  }
}

Measured memory_bytes: 256
// sky kaafi neeche aa gaya hai, sab choo rahe hain
// let's raise the bar now :P
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes";
    }
    else cout << "No";
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int k;
    string s;
    cin >> s >> k;

    int slen = s.length();
    vector<string> vs;
    rep(i, slen){
        int num = 1;
        for(int j=i; j<min(i+k, slen); j++){
            vs.push_back(s.substr(i, num++));
        }
    }

    sort(vs.begin(), vs.end());
    
    auto dupl = unique(vs.begin(), vs.end());
    vs.erase(dupl, vs.end());

    cout << vs[k-1] << endl;

    return 0;
}


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

int main(){
  long long  a,b,c,d;
  cin>>a>>b>>c>>d;
  long long ans;
  ans=max(max(max(a*c,a*d),b*c),b*d);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int n; ll k;
    cin >> n >> k;
    vi a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(all(a));
    sort(rall(f));

    auto check = [&](ll x) {
                     ll cnt = 0;
                     rep(i, n) {
                         cnt += max(0LL, a[i] -  x/f[i]);
                     }
                     return cnt <= k;
                 };
    ll l = -1, r = 1e12 + 1;
    while (r - l > 1) {
        ll m = (l + r) >> 1;
        if (check(m)) r = m;
        else l = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

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

	int N,A[100000];
	double K;

	cin>>N>>K;
	REP(i,N) cin>>A[i];
	
	if(N==K)  print(1);
	else print(ceil((N-1)/(K-1.0)));
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int s, w;
	cin >> s >> w;
	if (w >= s)puts("unsafe");
	else puts("safe");
	return 0;
}

Measured memory_bytes: 3100
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

int n;
ll const MOD = 1e9+7;
int main(){
    cin >> n;
    vector<int> c(n);
    vector<int> d;
    map<int,vector<int>> mp;
    REP(i,n){
        cin >> c[i];
        c[i]--;
        if(i){
            if(c[i-1]!=c[i])d.push_back(c[i]);
        }else{
            d.push_back(c[i]);
        }
        //d[c[i]]++;
    }
    n=d.size();
    vector<int> nextc(n,n);
    REP(i,n){
        auto itr = mp.find(d[i]);
        if(itr!=mp.end()){
            nextc[mp[d[i]].back()]=i;
            mp[d[i]].push_back(i);
            //nextc[i]=
        }else{
            mp[d[i]].push_back(i);
        }
    }
    vector<ll> dp(n+1,0);
    dp[0]=1;
    vector<ll> add(n+1,0);
    REP(i,n){
        dp[i+1]+=(add[i+1]+dp[i])%MOD;
        dp[i+1]%=MOD;
        if(nextc[i]!=n){
            add[nextc[i]+1]+=dp[i+1];
            add[nextc[i]+1]%=MOD;
        }
    }
    put(dp[n]);
    return 0;
}



Measured memory_bytes: 27636
import sys

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

x = ni()
t = x%11
if(t == 0): ans = -1
else: ans = 0
print(ans + x//11*2 + t//7+1)


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<pair<int,int> > xl;
    int x,l;
    for(i = 0;i < n;i++){
        cin >> x >> l;
        xl.push_back(make_pair(x,l));
    }
    sort(xl.begin(),xl.end());
    long long ans = 0;
    x = INT_MIN;
    for(i = 0;i < n;i++){
        if(x <= xl[i].first-xl[i].second){
            ans++;
            x = xl[i].first+xl[i].second;
        }
        else if(x > xl[i].first+xl[i].second){
            x = xl[i].first+xl[i].second;
        }
    }
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	int n,k,sum=0;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	for(int i=0;i<k;i++)
		sum+=arr[i];
	cout<<sum;
	return 0;
}



Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 3005;
ll dp[nax][nax];

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    // dp[0][n-1]
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = a[L];
            }
            else {
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
            }
        }
    }
    printf("%lld\n", dp[0][n-1]);
}

Measured memory_bytes: 70016
n, k = map(int, input().split())
a = list(map(int, input().split()))
count1, count2 = 0, 0

for i in range(n-1):
    for j in range(i+1, n):
        if a[i] > a[j]:
            count1 += 1

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            count2 += 1
            
print((count1*k+count2*(k*(k-1)//2))%(10**9+7))
        


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

counts = {}
max_count = 0
for _ in range(n):
    s = input()
    if s not in counts:
        counts[s] = 1
    else:
        counts[s] += 1
    if counts[s] > max_count:
        max_count = counts[s]

outputs = []
for key, value in counts.items():
    if value == max_count:
        outputs.append(key)
outputs.sort()
for output in outputs:
    print(output)

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

#define NDEBUG
#ifdef DEBUG
#include "cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*200001 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, vi& a) {
    ll ans = 0;

    int fl = 0;
    for (int s=0,e=0; e<N; ) {
        while ((fl & a[e]) == 0) {
            // printf("o [%d %d] %x %x\n", s, e, fl, a[e]);
            fl |= a[e];
            ++e;
            ans += (e - s);
            if (e == N) break;
        }
        while ((fl & a[e]) != 0) {
            // printf("x [%d %d] %x %x %x\n", s, e, fl, a[e], a[s]);
            fl -= a[s];
            ++s;
            if (s == e) break;
        }
    }

    return ans;
}

int main() {
    int N = loadint();
    vi a(N);
    loadvec(a, N);
    cout << solve(N, a) << endl;
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  string s;
  cin>>s;
  int ans=0;
  
 if(s[0]=='o') ans++;
  if(s[1]=='o') ans++;
  if(s[2]=='o') ans++;
  

  cout<<700+ans*100;

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
import numpy as np

S = input()
N = [0] * len(S)
for i in range(len(S)):
    N[i] = int(S[i])
arr = np.zeros((2,2))

for i in range(0, len(S), 2):
    if N[i] == 0:
        arr[0,0] += 1
    else:
        arr[0,1] += 1

for i in range(1, len(S), 2):
    if N[i] == 0:
        arr[1,0] += 1
    else:
        arr[1,1] += 1

ans = int(min(arr[0,0]+arr[1,1], arr[0,1]+arr[1,0]))

print(ans)

Measured memory_bytes: 13460
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
abc = [LIST() for _ in range(N-1)]

graph = defaultdict(list)
for a, b, c in abc:
	graph[a-1].append((b-1, c))
	graph[b-1].append((a-1, c))

Q, K = MAP()
xy = [LIST() for _ in range(Q)]

dist = [-1]*N
dist[K-1] = 0

def dfs(node):
	for to, cost in graph[node]:
		if dist[to] != -1:
			continue
		dist[to] = dist[node] + cost
		dfs(to)

dfs(K-1)
#print(dist)

for x, y in xy:
	print(dist[x-1] + dist[y-1])




Measured memory_bytes: 186364
#include <bits/stdc++.h>
using namespace std;
#define LL long int

int main(){
    LL n;
    cin >> n;
    LL before;
    cin >> before;

    bool f = true;

    for(int i = 0; i < n - 1; ++i){
        int m;
        cin >> m;
        if(m > before){
            before = m;
        }
        if(before - m > 1){
            f = false;
        }
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
fun main() {
    var (x, y) = readLine()!!.split(" ").map { it.toInt() }
    
    if (y == 0) {
            println(x)
        }
    else {
        var arr = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
        var ind = arr.indexOf(x)
        var i = 0
        var j = 0

        while(true) {
            var a = x + (i--)
            var b = x + (j++)
            if (a !in arr) {
                println(a)
                break
            }
            if (b !in arr) {
                println(b)
                break
            }
        }
    }
}

Measured memory_bytes: 40012
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    string S;
    cin >> S;

    int ans = inf;
    REP(i, S.size()-2) {
        int c = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + S[i+2] - '0';
        ans = min(ans, abs(c - 753));
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
	public static void main(String[] args) {
         
      try (Scanner scan = new Scanner(System.in)) {
        String input = scan.next();
        Pattern p = Pattern.compile("[ATGC]+");
	Matcher m = p.matcher(input);
	int maxlength = 0;
	while (m.find()) {
		if (m.group().length() > maxlength) {
			maxlength = m.group().length();
		}
	}
      System.out.println(maxlength);  
    }
    }
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll res = accumulate(all(A), 0LL);
  ll left = res;
  ll right = 0;
  ll ans = pow(10, 18);
  for(int i = 0; i < N; ++i) {
    left -= A[i];
    right += A[i];
    ll tmp = abs(left - right);
    if(ans > tmp) ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 100001;
const int maxk = 17;
#define is_anc(a, b) (in[a] < in[b] and out[a] >= out[b])
struct info{
	int v, c, w;
};
struct query{
	int id, c, w, y;
};
int n, sz[maxn], id[maxn], g[maxn], top[maxn], up[maxn], pref[maxn], depth[maxn], m;
long long ans[maxn];
vector < info > edge[maxn];
vector < query > ask[maxn];
int get_lca(int a, int b){
	while(g[a] != g[b])
		if(depth[top[g[a]]] < depth[top[g[b]]])b = up[top[g[b]]];
		else a = up[top[g[a]]];
	return depth[a] < depth[b] ? a : b;
}
void dfs1(int now, int last = 1){
	static int now_d = 0;
	up[now] = last;
	depth[now] = now_d++;
	sz[now] = 1;
	if(last != now){
		for(int i = 0;i < edge[now].size();++i)
			if(edge[now][i].v == last){
				edge[now].erase(edge[now].begin() + i);
				break;
			}
	}
	for(int i = 0;i < edge[now].size();++i){
		dfs1(edge[now][i].v, now), sz[now] += sz[edge[now][i].v];
		if(sz[edge[now][i].v] > sz[edge[now][0].v])swap(edge[now][i], edge[now][0]);
	}
	--now_d;
}
void dfs3(int now){
	static int x = 1;
	static int now_g = 0;
	id[now] = x++;
	g[now] = now_g;
	if(!top[now_g])top[now_g] = now;
	if(!edge[now].empty()){
		dfs3(edge[now][0].v);
		for(int i = 1;i < edge[now].size();++i)
			++now_g, dfs3(edge[now][i].v);
	}
}
void dfs2(int now, int last = 1){
	static int total_w = 0;
	static int q_of[maxn] = {};
	static int w_of[maxn] = {};
	for(auto &i : ask[now]){
		ans[i.id] += (total_w - w_of[i.c] + q_of[i.c] * i.y) * i.w;
	}
	for(auto &i : edge[now]){
		if(i.v != last){
			++q_of[i.c];
			w_of[i.c] += i.w;
			total_w += i.w;
			dfs2(i.v, now);
			--q_of[i.c];
			w_of[i.c] -= i.w;
			total_w -= i.w;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs1(1);
	dfs3(1);
	for(int i = 0, x, y, u, v, lca;i < m;++i){
        cin >> x >> y >> u >> v;
		lca = get_lca(u, v);
		ask[u].push_back({i, x, 1, y});
		ask[v].push_back({i, x, 1, y});
		ask[lca].push_back({i, x, -2, y});
	}
	dfs2(1);
	for(int i = 0;i < m;++i)cout << ans[i] << '\n';
}


Measured memory_bytes: 24692
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    int n, m;
    cin>>n>>m;
    cout<<(1900*m+100*(n-m)) * pow(2, m)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c, d, num, x, y;
	scanf("%d%d%d%d", &a, &b, &c, &d);
		if (a<=c) 
			x=c;
		else 
			x=a;
		if (b>=d)
			y=d;
		else 
			y=b;
		if (y>x)
			printf("%d\n", y-x);
		else
			printf("0");
			
	return 0;
}


Measured memory_bytes: 128
n = int(input())
# n = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
t = []
xy = []
for i in range(n):
    a, b, c = map(int, input().split())
    t.append(a)
    xy.append([b, c])

point = xy[0][0]+xy[0][1]
if n == 1:
    if point == t[0]:
        print("Yes")
    elif point < t[0] and (t[0]-point) % 2 == 0:
        print("Yes")
    else:
        print("No")
else:

    if point > t[0] or (point < t[0] and (t[0]-point) % 2 == 1):
        print("No")
        exit()

    for i in range(1, n):
        point += abs(xy[i][0]-xy[i-1][0]) + abs(xy[i][1]-xy[i-1][1])
        if point > t[i] or (point < t[i] and (t[i]-point) % 2 == 1):
            print("No")
            exit()
    print("Yes")


Measured memory_bytes: 20340
mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
for i in range(k):
    lr[i][1] += 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] += dp[i - 1]
    if i == 1:
        dp[1] = 0
    for l, r in lr:
        if i - l >= 0:
            dp[i] += dp[i - l]
        if i - r >= 0:
            dp[i] -= dp[i - r]
    dp[i] %= mod
print(dp[n - 1])

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

using namespace std;

typedef long long ll;

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> dp(n, 1e9);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 1; i + j < n && j <= k; ++j)
            dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
    }
    cout << dp[n - 1] << endl;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    vector<pair<int, int>> vs[15];
    cin >> N;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        while(a--){
            int x, y;
            cin >> x >> y;
            vs[i].emplace_back(x-1, y);
        }
    }
    int ans = 0;
    for(int b=0; b<(1<<N); b++){
        bitset<15> h;
        for(int i=0; i<N; i++) h[i] = nth_bit(b, i);
        bool ok = true;
        for(int i=0; i<N; i++) if(h[i]) for(auto& p : vs[i]) if(h[p.first] != p.second) ok = false;
        if(ok) ans = max(ans, int(h.count())); 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// D - Semi Common Multiple
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){
	int T=-1,N,M; scanf("%d%d",&N,&M);
	ll L=1;
	while(N--){
		int a,t; scanf("%d",&a);
		for(t=0; !(a&1); t++) a>>=1;
		if(T>0 && t!=T || (L=lcm(L, a)) > M){ puts("0"); return 0; }
		T = t;
	}
	printf("%lld\n",((M>>(T-1))/L+2-1)/2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;


using namespace std;

int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int a=0,b=0,c=0;
	string s; 
	cin>>s; 
	int len=s.length();
	repp(i,0,len-1,1){
		if(s[i]=='a')a++;
		else if(s[i]=='b')b++;
		else c++;
	}
	int maxx=max(max(a,b),c);
	int minn=min(min(a,b),c);
	if(maxx-minn<=1)cout<<"YES"<<endl; 
	else cout<<"NO"<<endl; 
	return 0;
}

    

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int cnt(ll num) {
  int digits = 0;
  while (num > 0) {
    num /= 10;
    digits++;
  }
  return digits;
}
int main() {
  ll N;
  cin >> N;
  int ans = cnt(N);
  for (ll A = 1; A * A <= N; ++A) {
    if (N % A != 0) continue;
    ll B = N / A;
    int tmp = max(cnt(A), cnt(B));
    ans = min(ans, tmp);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
ll x,y;
cin>>x>>y;
if(y%2==0){
if(x*2<=y && y<=x*4) cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

}
else
cout<<"No"<<endl;
}

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

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

    string s;
    int p;
    vector<tuple<string,int,int>> r;
    for(int i=0; i<n; i++){
        cin>>s>>p;
        r.emplace_back(s,100-p,i);
    }

    sort(r.begin(),r.end());

    for(int i=0; i<n; i++){
        cout<<get<2>(r[i])+1<<endl;
    }
}

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

#define llint long long int

int main(void){
  int n;
  llint head[5] = {};
  std::cin >> n;
  std::string s[n];
  for(int i=0; i<n; i++){
    std::cin >> s[i];
    switch(s[i][0]){
    case 'M':
      head[0]++;
      break;
    case 'A':
      head[1]++;
      break;
    case 'R':
      head[2]++;
      break;
    case 'C':
      head[3]++;
      break;
    case 'H':
      head[4]++;
      break;
    }
  }

  llint total = 0;
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      for(int k=j+1; k<5; k++){
        total += head[i] * head[j] * head[k];
      }
    }
  }
  std::cout << total << std::endl;
  return 0;
}







Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#define MAX 1000001
using namespace std;


bool isprime[MAX];

void calcprime() {
  for(int i = 0; i < MAX; i++) isprime[i] = true;

  isprime[0] = false;
  isprime[1] = false;
  for(int i = 2; i < MAX; i++) {
    if(isprime[i]) {
      for(int j = i*2; j < MAX; j += i) isprime[j] = false;
    }
  }
}

int key(int p) {
  int ans = 0;
  bool first = true;
  for(int i = p; i >= 0; i--) {
    if(p == 1) break;
    if(isprime[i] && p % i == 0) {
      if(first) {
	ans = i;
	first = false;
      } else {
	ans -= i;
      }
      p /= i;
    }
  }
  return ans;
}

void solve(int a, int b) {
  if(key(a) > key(b)) cout << "a" << endl;
  else                cout << "b" << endl;
}

main() {
  int a, b;
  calcprime();
  while(1) {
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    solve(a, b);
  }
}

Measured memory_bytes: 1832