akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define MAX 20000
typedef pair<int,int> pii;

map<pii,int> id;
map<int,pii> mp;
int color[MAX][2],tmp[MAX][2];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};

struct State{
  int v,p,col;
  State(int v,int p,int col) :
    v(v),p(p),col(col) {}
};

bool bfs(int v,int p){
  queue<State> Q;
  Q.push(State(v,p,0));
  Q.push(State(v+1,1-p,1));
  
  while(!Q.empty()){
    State s = Q.front(); Q.pop();
    pii np = mp[s.v];
    if(color[s.v/2][s.p] >= 0){
      if(color[s.v/2][s.p] != s.col){
        return false;
      }
      continue;
    }
    color[s.v/2][s.p] = s.col;
    for(int i = 0 ; i < 4 ; i++){
      int nx = np.first+dx[i],ny = np.second+dy[i];
      if(id.find(pii(nx,ny)) != id.end()){
        int x = id[pii(nx,ny)]%2;
        if(id[np]/2 == id[pii(nx,ny)]/2){
          Q.push(State(id[pii(nx,ny)],1-s.p,1-s.col));
        }else{
          Q.push(State(id[pii(nx,ny)],(x&1?1:0),s.col));
        }
      }
    }
  }
  return true;
}

void init(){
  mp.clear();
  id.clear();
  memset(color,-1,sizeof(color));
}

int main(){
  int N,x,y;
  char ch;
  while(cin >> N,N){
    init();
    for(int i = 0 ; i < N ; i++){
      cin >> x >> y >> ch;
      int j = i*2;
      if(ch == 'x'){
        mp[j] = pii(x,y); mp[j+1] = pii(x+1,y);
        id[pii(x,y)] = j; id[pii(x+1,y)] = j+1;
      }else{
        mp[j] = pii(x,y); mp[j+1] = pii(x,y+1);
        id[pii(x,y)] = j; id[pii(x,y+1)] = j+1;
      }
    }
    bool can = true;
    for(int i = 0 ; i < 2*N ; i+=2){
      if(color[i/2][0] >= 0){ continue; }
      for(int j = 0 ; j < N ; j++){
        for(int k = 0 ; k < 2 ; k++){
          tmp[j][k] = color[j][k];
        }
      }
      if(!bfs(i,0)){ can = false; }
      if(!can){
        can = true;
        for(int j = 0 ; j < N ; j++){
          for(int k = 0 ; k < 2 ; k++){
            color[j][k] = tmp[j][k];
          }
        }
        if(!bfs(i,1)){
          can = false;
          break;
        }
      }
    }
    cout << (can ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

long long judge(long long n){
  long long res;
  if(n == 1){
    res = 300'000;
  }else if(n == 2){
    res = 200'000;
  }else if(n == 3){
    res = 100'000;
  }else{
    res = 0;
  }
  return res;
}
int main(){
  
  long long x,y;
  cin>>x>>y;
  
  long long ans = 0;
  ans = judge(x) + judge(y);
  if(x == 1 && y == 1){
    long long a = 400'000;
    ans += a;
  }
  cout<<ans<<endl;
  
  return 0; 
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B,C,D;

int main() {
  INCANT;
  cin >> A >> B >> C >> D;
  cout << max(0, min(B,D)-max(A, C)) << "\n";
  return 0;
}

Measured memory_bytes: 256
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	int n;cin>>n;cout<<(n-2)*180<<endl;
	
}

			


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

typedef long long ll;
#define mod 1000000007

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

void solve() {
    string s;
    cin>>s;
    int n = s.size();
    if(s[n-1] == 's'){
        s += "es";
    }
    else{
        s += "s";
    }
    cout<<s;
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  int a,b;
  cin >> a >> b;
  int tmp = 0;
  int i,j;
  for(i=0;i<h;i++){
    if(i<b)tmp = 0;
    else tmp  = 1;
    for(j=0;j<w;j++){
      if(j<a)cout<<tmp;
      else cout<<(tmp+1)%2;
    }
    cout << endl;
  }
}


Measured memory_bytes: 1280
import math
n=int(input())

l=[2 for i in range(max(2,n+1))]
l[1]=1

for i in range(2,int(math.sqrt(n))+1):#振るい
  for j in range(i,n//i+1):
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
print(sum([i*l[i] for i in range(n+1)]))


Measured memory_bytes: 371164
#include<stdio.h>

int main(){
	long long int angka, tc, max=-1000000, min=1000000, sum=0;
	scanf("%lld", &tc);
	for(int i=0; i<tc; i++){
		scanf("%lld", &angka);
		sum += angka;
		if(max<angka) max=angka;
		if(min>angka) min=angka;
	}
	printf("%lld %lld %lld\n", min, max, sum);
}


Measured memory_bytes: 2764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		   Scanner sc = new Scanner(System.in);
		    long H = sc.nextLong();
		    long Attack = 0;
		    long Monster = 1;
		    
		    while (H > 0) {
		      Attack += Monster;
		      H /= 2;
		      Monster *= 2;
		    }
		 
		    System.out.println(Attack);
		sc.close();
	}

}

Measured memory_bytes: 23636
using System;

namespace ABC089
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long m = 0;
            long a = 0;
            long r = 0;
            long c = 0;
            long h = 0;
            for (int i = 0; i < N; i++)
            {
                string S = Console.ReadLine();
                char s = S[0];
                if (s == 'M') m++;
                if (s == 'A') a++;
                if (s == 'R') r++;
                if (s == 'C') c++;
                if (s == 'H') h++;
            }


            int[] P = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
            int[] Q = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
            int[] R = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };

            long[] D = new long[] { m, a, r, c, h };
            long res = 0;
            for (int i = 0; i < 10; i++)
            {
                res += D[P[i]] * D[Q[i]] * D[R[i]];
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main(){

    int n;
    cin >> n;

    int nums[n];
    for (int i = 0; i < n; i++) cin >> nums[i];

    bool colours[8];
    for (int i = 0; i < 8; i++) colours[i] = false;

    int anyColour = 0;

    for (int i = 0; i < n; i++){
        
            if (nums[i] < 400){
                colours[0] = true;
            }
            else if (nums[i] < 800){
                colours[1] = true;
            }
            else if (nums[i] < 1200){
                colours[2] = true;
            }
            else if (nums[i] < 1600){
                colours[3] = true;
            }
            else if (nums[i] < 2000){
                colours[4] = true;
            }
            else if (nums[i] < 2400){
                colours[5] = true;
            }
            else if (nums[i] < 2800){
                colours[6] = true;
            }
            else if (nums[i] < 3200){
                colours[7] = true;
            }
            else {
                ++anyColour;
            }
        
    }

    int minColour = 0;

    for (int i = 0; i < 8; i++){
        if (colours[i]){
            ++minColour;
        }
    }
    if (minColour > 0){
        cout << minColour << " ";

    } else {
        cout << 1 << " ";
    }


    // else if ((minColour + anyColour) > 8){
    //     cout << 8 << endl;
    // } 

    cout << minColour + anyColour << endl;
    

    return 0;
}

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

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

  	if(num_str.at(0)==num_str.at(1)&&num_str.at(1)==num_str.at(2)){cout << "Yes" << endl;}
    else if(num_str.at(1)==num_str.at(2)&&num_str.at(2)==num_str.at(3)){cout << "Yes" << endl;}
    else {cout << "No" << endl;}
}

Measured memory_bytes: 256
import Data.List

main = do
  line1 <- getLine
  line2 <- getLine
  let
    [n,m] = map read $ words line1 :: [Int]
    ls = map read $ words line2 :: [Int]
    addFstDiff ls =
      case ls of
        []   -> getDiffs ls
        x:tl -> (x,x,200001) : getDiffs ls
    getDiffs ls = 
      case ls of
        []         -> []
        x : []     -> [(x,x,200001)]
        x : y : tl -> (x,y,y-x) : getDiffs (y:tl)
    takeThrs n ls = sortBy (\(x,_,_) -> \(y,_,_) -> compare x y)
                    $ take n
                    $ (sortBy (\(_,_,x) -> \(_,_,y) -> (flip compare) x y)) ls
    calcLength ls = case ls of
      []                     -> 0
      x : []                 -> 0
      (_,x,_) : (y,y2,y3) : tl -> y-x + (calcLength ((y,y2,y3):tl))
    in
      putStrLn $ show $ calcLength $ takeThrs (n+1) $ addFstDiff $ sort ls




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

void fun(ll n, ll s){

  ll a[n],sum=0;
  for(ll i=0;i<n;i++){cin>>a[i];sum+=a[i];}
  ll l,r;
  l=0,r=n-1;
   while(l<r){
    if(a[l]<a[r]&&sum-a[l]>=s){
       sum-=a[l++];

    }else if(sum-a[r]>=s){
       sum-=a[r--];
    }else break;

   }
  cout << r-l+1 ;
 cout << "\n" ;
}

int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
  ll n,s;
  cin>>n;
  ll a[n],sum=0;
  for(ll i=0;i<n;i++){
    cin >>a[i];
  }
  ll r=0;
  for(ll i=0;i<n;i++){
    ll j=i;
    ll sum=0;
    while(j<n && a[j])
        sum+=a[j++];
    r+=sum/2;
   i=j;

  }
  cout << r;
}


Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int P[100010], Y[100010];
vector<int> g[100010];
map<pii, string> mp;

string f(int x) {
  string res = to_string(x);
  while (res.size() < 6) res = "0" + res;
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    g[P[i]].emplace_back(Y[i]);
  }
  for (int i = 1; i <= N; i++) {
    if (g[i].empty()) continue;
    sort(g[i].begin(), g[i].end());
    int cnt = 1;
    for (int j : g[i]) {
      string s = f(i);
      s += f(cnt++);
      mp[pii(i, j)] = s;
    }
  }
  for (int i = 0; i < M; i++) {
    cout << mp[pii(P[i], Y[i])] << endl;
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  int A=0;
  int B=0;
  for(int i=N-1; i>=0; i -= 2) A += vec.at(i);
  for(int i=N-2; i>=0; i -= 2) B += vec.at(i);
  cout << A - B << endl;
}


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

int main(){
	stack<int> st;
	queue<int> que;
	int train;
	while(cin >> train){
		if(train)
			st.push(train);
		else{
			que.push(st.top());
			st.pop();
		}
	}
	while(!que.empty()){
		cout << que.front() << endl;
		que.pop();
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define pb push_back
#define pp pair<int, int>
#define fr(n) for(int i=0;i<n;i++)
#define fr1(n) for(int i=1;i<=n;i++)
typedef long long ll;
using namespace std;


ll power(int x, unsigned int y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

const int mod = 1000000007;
const int MAX = 1000001;
bool prime[MAX];

void sieve ()
{
    int i,j;
    prime[0] = prime[1] = true;

    for (i=4; i<MAX; i+=2)
        prime[i] = true;

    for (i=3; i*i<=MAX; i+=2)
        if (!prime[i])
            for (j=i*i; j<MAX; j+=2*i)
                prime[j] = true;
}

        int res=0;




int findUniquePair(int arr[], int n)
{
    int XOR = arr[0];
    for (int i = 1; i < n; i++)
        XOR = XOR ^ arr[i];

    int set_bit_no = XOR & ~(XOR-1);
    int x=0,y=0;

    for (int i = 0; i < n; i++)
    {
        if (arr[i] & set_bit_no)
            x = x ^ arr[i];
        else
            y = y ^ arr[i];
    }

    return abs(x-y);

}

const int N=5009;


ll n,m,k;
ll a[N],sum[N];






/*

ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

*/
int mostFrequent(int arr[], int n)
{

    sort(arr, arr + n);


    int max_count = 1, res = arr[0], curr_count = 1;
    for (int i = 1; i < n; i++) {
        if (arr[i] == arr[i - 1])
            curr_count++;
        else {
            if (curr_count > max_count) {
                max_count = curr_count;
                res = arr[i - 1];
            }
            curr_count = 1;
        }
    }

    if (curr_count > max_count)
    {
        max_count = curr_count;
        res = max_count ;
    }

    return res;
}
int dp[1000001];


int main()
{
int n,k;
cin >>n>>k;
int x[n];
    for(int i=0;i<n;i++)
        cin >> x[i];
    memset(dp,MAX,sizeof(dp));
    dp[0]=0;


    for(int i=0;i<n;i++)
    {

        for(int j=i+1;j<=i+k&&j<n;j++)
        {

            dp[j]=min(dp[j],dp[i]+abs(x[i]-x[j]));
        }

    }
cout<<dp[n-1];



    return 0;

}



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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 2e5+1;
const int M = 1e9+7;

ll n, sub[MAX], dp[MAX], f[MAX], res[MAX];
vector<int> tree[MAX];

ll mod_exp(ll a, ll b)
{
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    if(b&1)
        return ((a*mod_exp((a*a)%M, b/2))%M)%M;
    return mod_exp((a*a)%M, b/2)%M;
}
ll inv(ll a)
{
    return mod_exp(a, M-2);
}
ll mul(ll a, ll b)
{
    return (a%M*b%M)%M;
}
void DFS(int v, int pr)
{
    sub[v] = 1;
    for(int i : tree[v])
        if(i != pr)
        {
            DFS(i, v);
            sub[v] += sub[i];
        }
    dp[v] = f[sub[v]-1];
    for(int i : tree[v])
        if(i != pr)
            dp[v] = ((dp[v]*dp[i])%M*inv(f[sub[i]])%M)%M;
}
void solve(int v, int pr)
{
    res[v] = dp[v];

    for(int i : tree[v])
        if(i != pr)
        {
            //make i root instead of v
            ll temp1 = dp[v], temp2 = dp[i];
           // cout<<"V: "<<dp[v]<<"\n";

            dp[v] = (dp[v] * f[sub[i]])%M; //* (f[sub[v] - sub[i] -1] //* inv(dp[i]))%M)%M; //* inv(f[sub[v]-1]))%M;
            dp[v] = mul(dp[v], f[sub[v] - sub[i] - 1]);
            dp[v] = mul(dp[v], inv(dp[i]));
            dp[v] = mul(dp[v], inv(f[sub[v]-1]));
           // cout<<dp[v]<<"\n";
            dp[i] *= inv(f[sub[i]-1]);
            dp[i] %= M;
            sub[v] -= sub[i];
            sub[i] += sub[v];
            dp[i] *= f[sub[i]-1];
            dp[i] = ((dp[i]%M*dp[v])%M*inv(f[sub[v]]))%M;
            solve(i, v);
            //revert changes
            dp[v] = temp1, dp[i] = temp2;
            sub[i] -= sub[v];
            sub[v] += sub[i];
        }
}
int main()
{
    _upgrade;
    cin>>n;
    f[0] = 1;
    FOR(i, 1, n+1)
        f[i] = (f[i-1]*i)%M;

    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    solve(1, -1);
    FOR(i, 1, n+1)
        cout<<res[i]<<"\n";
}


Measured memory_bytes: 20212
#include<iostream>
using namespace std;
#define int long long

int opow(int x, int y) {
    int res = 1;
    for (int i = 0; i < y; i++) {
        res *= x;
    }
    return res;

}

signed main() {
    int X; cin >> X;
    pair<int, int> ans;
    for (int j = -1000; j < 1000; j++) {
        for (int k = -1000; k < 1000; k++) {
            if (opow(j, 5) - opow(k, 5) == X) {
                ans = { j,k };
                goto endloop;
            }
        }
    }
endloop:
    cout << ans.first << " " << ans.second << endl;
}

Measured memory_bytes: 3676
l = list(input() for _ in range(3))
str1 , str2 = l[0].split()
num1 , num2 = map(int,l[1].split())
if l[2] == str1:
  num1 -= 1
  print(num1 , num2)
else:
  num2 -= 1
  print(num1 , num2)

Measured memory_bytes: 3060
#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 abs(a*b)/gcd(a,b);}
std::vector<ll> enum_div(ll n){
	std::vector<ll> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

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

*/
ll n,m; ll ans=0;
int main(){
  cin >> n >> m;
  if (n == 1){
    cout << m << endl;
  } else {
    std::vector<ll> v(enum_div(m));sort(all(v));
    for (auto itr = v.begin(); itr != v.end(); itr++) {
      if(m%(*itr) == 0 && m/n >= *itr)ans = *itr;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 1LL<<60;
typedef long long ll;

int main() {
    // 方針
    // L -> R に切り替わるまでを一つの区切りと考える．
    // 一つの区切りに対して， R の個数と L の個数が R -> L に切り替わるところにそれぞれ下記の式のようになる．
    // R -> L の区切りを覚える idx と今 L 側にいてたことを覚える flag を使う

    // 入力
    string S; cin >> S;
    int N = S.size();
    vector<int> ans(N);

    // 変数の準備
    bool flag = true;   // L -> R に切り替わる時
    float cnt_r = 0;    // R の個数
    float cnt_l = 0;    // L の個数
    ll idx = 0;         // R -> L に切り替わる位置
    
    // 文字列 S をみていく
    for (int i = 0; i < N; ++i){
        ans[i] = 0;
        if (S[i] == 'R'){
            if (!flag){
                ans[idx-1] = ceil(cnt_r/2) + floor(cnt_l/2);     // R 側
                ans[idx] = floor(cnt_r/2) + ceil(cnt_l/2);       // L 側
                cnt_r = 1;
                cnt_l = 0;
                flag = true;
            }else{
                cnt_r += 1;
            }
        }else{
            if (flag){
                flag = false;
                idx = i;
            }
            cnt_l += 1;

        }
    }

    // 最後のところはfor ループの外で考えた．(中にも入れられるけど，)
    ans[idx-1] = ceil(cnt_r/2) + floor(cnt_l/2);     // R 側
    ans[idx] = floor(cnt_r/2) + ceil(cnt_l/2);       // L 側   

    // 答えの出力
    for (int i = 0; i < N; ++i){
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  int r, s, p;
  cin >> r >> s >> p;

  map<char, int> m;
  m['s'] = r;
  m['p'] = s;
  m['r'] = p;

  string t;
  cin >> t;

  long long sum = 0;
  long long ans[(int)t.size()] = {0};
  for (int i = 0; i < (int)t.size(); ++i) {
    if (i < k)  ans[i] = m[t[i]];
    else if (t[i] == t[i-k]) ans[i] = m[t[i]] - ans[i-k];
    else ans[i] = m[t[i]];
    sum += ans[i];
  }

  cout << sum << '\n';

}

Measured memory_bytes: 1232
import java.util.*;

public class Main {
	static int[][] c = new int[10][10];

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = sc.nextInt();
			}
		}
		int[] arr = new int[10];
		for (int i = 0; i < 10; i++) {
			if (i == 1) {
				continue;
			}
			int ceiling = c[i][1];
			for (int j = 0; j < 10; j++) {
				if (j == i || j == 1) {
					continue;
				}
				int ret = costCheck(j, c[i][j], ceiling);
				if (ret < ceiling) {
					ceiling = ret;
				}
			}
			arr[i] = ceiling;
		}
		int total = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int x = sc.nextInt();
				if (x != -1) {
					total += arr[x];
				}
			}
		}
		System.out.println(total);
	}
	
	public static int costCheck(int select, int cost, int ceiling) {
		int direct = c[select][1] + cost;
		for (int i = 0; i <= 9; i++) {
			if (i != 1 && i != select) {
				if (direct > c[select][i] + cost && cost + c[select][i] < ceiling) {
					int ret = costCheck(i, cost + c[select][i], ceiling);
					if (ret < direct) {
						direct = ret;
					}
				}
			}
		}
		if (direct < ceiling) {
			return direct;
		} else {
			return ceiling;
		}
	}
}


Measured memory_bytes: 46856
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

four = 0
two = 0
one = 0

n.times do |i|
  if a[i] % 4 == 0
    four += 1
  elsif a[i] % 2 ==0
    two += 1
  else
    one += 1
  end
end

if n.odd? && two == 0 && n / 2 == four
  puts 'Yes'
  exit
end

if four * 2 + two >= n
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 9476
use v5.18;
use warnings;
use List::Util;
use Data::Dumper;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my $n = read_line;
my @h = splited_read_line;

my $before = $h[0];
my $num = 0;
for (@h) {
  if ( $_ >= $before ) {
    $num++;
    $before = $_;
  }
}
say $num;
  




Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int taisyo = Integer.parseInt(line);
		int counter = 1;
		boolean zero = true;

		while (zero) {
			System.out.println("Case " + counter + ": " + taisyo);
			counter++;
			line = br.readLine();
			taisyo = Integer.parseInt(line);
			if (taisyo == 0) {
				zero = false;
			}
		}
	}
}

Measured memory_bytes: 32580
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    if(n==2){
        cout<<"1\n";
        return 0;
    }

    m = n-1;

    ll res = 1;//n
    ll curv;

    for(ll i=2;i*i<=n;i++){
        if(!(n%i)){
            k = n;
            while(!(k%i))k/=i;
            if(k%i==1)res++;
            if(i*i<n){
                k = n;
                curv = n/i;
                while(!(k%curv))k/=curv;
                if(k%curv==1)res++;
            }
        }
    }

    for(ll i=2;i*i<=m;i++){
        if(!(m%i)){
            if(i*i<m)res+=2;
            else res++;
        }
    }

    res++;

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

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

int main(void) {

  string s, t;
  cin >> s >> t;
  rep(i, s.size()) {
    if (s[i] != t[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";

  return 0;
}


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

int max_score = -1;
int calc_score(vector<int> A,vector<vector<int>> vec) {
  int score = 0;
  
  for (int i = 0; i < vec.size(); i++) {
    if(A.at(vec[i][1]-1)-A.at(vec[i][0]-1) == vec[i][2]) {
      score += vec[i][3];
    }
  }
  return score;
}

void make_A(vector<int> A,vector<vector<int>> vec,int i, int N, int M, int A_max) {
 
  for (int j = A_max; j <= M; j++) {
    A.at(i) = j;
    if (i == N - 1) {
      int score;
      score = calc_score(A, vec);
      if (score >= max_score) {
        max_score = score;
      }
    }
    else {
      make_A(A, vec, i+1, N, M, j);
    }
  }
}


int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> vec(Q, vector<int>(4));
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  
  
  vector<int> A(N);
  
  make_A(A, vec, 0, N, M, 1);
  
  
              
  
  cout << max_score;
}


Measured memory_bytes: 3636
fun main(argc:Array<String>){
    var S = readLine()!!.toInt()
    var XX = S/100
    var YY = S%100
    if(0 < XX && XX <= 12){
        if( 0 < YY && YY <= 12){
            println("AMBIGUOUS")
        }else{
            println("MMYY")
        }
    }else{
        if(0 < YY && YY <= 12){
            println("YYMM")
        }else{
            println("NA")
        }
    }
}

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

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){

  string s;

  cin >> s;
  for( int i = 0; 2*i < s.size(); ++i ){
    cout << s[2*i];
  }
  cout << endl;
  return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

const int MOD = 1e9+7;
int v[100005], fat[100005];

int inv(int a) {
	int b = MOD-2, r = 1;

	while(b) {
		if(b&1) r = ((ll)r*a)%MOD;
		b/=2;
		a = ((ll)a*a)%MOD;
	}

	return r;
}

int c(int n, int k) {
	if(n < k) return 0;
	int cur = ((ll)inv(fat[k])*inv(fat[n-k]))%MOD;
	return ((ll)cur*fat[n])%MOD;
}

int main(){
	int n,k;

	fat[0] = 1;
	for(int i = 1; i <= 100000; i++)
		fat[i] = ((ll)fat[i-1]*i)%MOD;

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

	for(int i = 1; i <= n; i++)
		scanf("%d", &v[i]);

	sort(v+1, v+n+1);
	int ans = 0;

	for(int i = 1; i <= n; i++) {
		int qttMin = c(n-i, k-1);
		int qttMax = c(i-1, k-1);

		// printf("%d: %d, %d\n", v[i], qttMin, qttMax);

		int aux = ((ll)qttMax*v[i])%MOD;
		int aux2 = ((ll)qttMin*v[i])%MOD;
		aux -= aux2;
		if(aux < 0) aux += MOD;
		ans += aux;
		if(ans >= MOD) ans -= MOD;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1024
/*
AOJ - ITP1_9_d
Date: 20181006
Author: Mikoron * ♡mikoiwate_351♡
 */

#define MAX 500

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

int main(void) {
        char w[11], t[MAX];
        short i, count = 0;

        scanf("%s", w);
        while(1) {
                scanf("%s", t);
                if(!(strncmp(t,"END_OF_TEXT",strlen(t)))) break;
                for(i = 0; i < (int)strlen(t); i++) t[i] = tolower(t[i]);
                if(!(strcmp(t,w))) {
                        count++;
                }
        }
        printf("%d\n", count);

        return 0;
}



Measured memory_bytes: 2044
package main

import (
    "fmt"
    "bufio"
    "os"
)

const (
    initialBufSize = 10000
    maxBufSize = 100000+1024
)

func main() {

    scanner := bufio.NewScanner(os.Stdin)
    buf := make([]byte, initialBufSize)
    scanner.Buffer(buf, maxBufSize)
    
    scanner.Scan()
	text := scanner.Text()


	var E0, E1, O0, O1 int
	for i, t := range text {
		if i%2 == 0 {
			if t == '0' {
				E0++
			} else {
				E1++
			}
		} else {
			if t == '0' {
				O0++
			} else {
				O1++
			}
		}
	}
	fmt.Println(min(E0+O1, E1+O0))

}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

Measured memory_bytes: 1024
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline int ri() {int x; scanf("%d", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int n, a[1000];
int main() {
  #ifdef _TEST_
  freopen("input.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
  #endif
  cin >> n >> n;
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n) if (a[i] & 1) swap(a[cnt ++], a[i]);
  if (cnt > 2) {
    cout << "Impossible" << endl; 
    return 0;
  }
  if (cnt == 2) swap(a[1], a[n - 1]);
  if (n == 1) {
    if (a[0] == 1) {
      cout << "1\n1\n\n1\n"; return 0;
    } else {
      cout << a[0] << endl << 2 << endl << a[0] - 1 << ' ' << 1 << endl; return 0;
    }
  }
  vector<int> b;
  b.pb(a[0] + 1);
  rep(i, 1, n - 1) b.pb(a[i]);
  if (a[n - 1] > 1) b.pb(a[n - 1] - 1);
  rep(i, n) cout << a[i] << ' '; cout << endl;
  cout << b.size() << endl;
  rep(i, b.size()) cout << b[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int s = 0;
    if(a > b){
        s += a;
        a--;
    }else{
        s += b;
        b--;
    }
    if(a > b){
        s += a;
        a--;
    }else{
        s += b;
        b--;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int s[100000][3];
int t[200002];//時間ごとに録画機が使われているかどうか
int cm[200002];//時間ごとに録画機がいくつ使われているか

int main()
{
	int n,c;
	int cmmax=0;
	cin>>n>>c;
	for(int i=0;i<n;i++)
	{
		cin>>s[i][0]>>s[i][1]>>s[i][2];
	}
	for(int i=0;i<200002;i++)
	{
		cm[i]=0;
	}

	for(int i=1;i<c+1;i++)
	{
		for(int j=0;j<200002;j++)
		{
			t[j]=0;
		}
		for(int j=0;j<n;j++)
		{
			if(s[j][2]==i)
			{
				t[s[j][0]*2-1]++;
				t[s[j][1]*2]--;
			}
		}
		for(int j=1;j<200002;j++)
		{
			t[j]+=t[j-1];
		}
		for(int j=0;j<200002;j++)
		{
			if(t[j]>0)
			{
				cm[j]++;
			}
		}
	}

	for(int i=0;i<200002;i++)
	{
		if(cm[i]>cmmax)
		{
			cmmax=cm[i];
		}
	}

	cout<<cmmax<<endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  
  int count = 0; 
  for(int i = 0; i < S.size(); i ++){
    if(S[i] == 'o'){
      count ++;
    }
  }
  
  cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll M;
    cin >> M;
    vector<ll> c(M), d(M);
    rep(i,M){
        cin >> d[i] >> c[i];
    }
    ll ans = 0;
    ll sum = 0;
    ll sum_b = 0;
    rep(i,M){
        ll tmp = d[i]*c[i];// + r;
        sum += c[i];
        sum_b += tmp;
        //r = tmp % 10;
    }
    /*while(sum_b >= 10){
        ll r = sum_b % 10;
        ll q = sum_b / 10;
        ans += q;
        sum_b = q + r;
    }*/
    cout << (sum_b-1)/9+sum-1 << endl;
}

Measured memory_bytes: 6372
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a < b){
        if (b < c) cout << "Yes" << endl;
        else cout << "No" << endl;
    } 
    else cout << "No" << endl;
    
    
    return 0;
}


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

int main() {
	ll N, K;
	cin >> N >> K;
	ll ans = 0;
	const ll mod = 1000000007;
	for (ll k = K; k <= N + 1; ++k) {
		(ans += k * (N - k + 1) + 1) %= mod;
	}
	cout << ans << endl;
}

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

    vector<int> s(n);
    rep(i,n) cin >> s[i]; 

    int q;
    cin >> q;

    vector<int> t(q);
    rep(i,q) cin >> t[i];

    int ans = 0;

    rep(i,q){
        int l = 0, r = n;
        while(l+1<r){
            int c = (l+r)/2;
            if(s[c]<=t[i]) l = c;
            else r = c;
        }
        if(s[l]==t[i]) ans++;
    }

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


Measured memory_bytes: 3296
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0589 : Production **/
int main()
{
	int N;
	map<string, int> p[5];
	cin>>N;
	rep(i, N) {
		string s; int a;
		cin>>s>>a;
		p[s.size()-1][s] += a;
	}
	
	rep(i, 5) {
		map<string, int>::iterator it = p[i].begin();
		for (; it != p[i].end(); it++) {
			cout << it->first << " " << it->second << endl;
		}
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar()); 
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,q,lg[100004],cnt[100004],par[17][100004],depth[100004];
vector<int>g[100004],cl[100004],len[100004],id[100004],A[100004],B[100004],C[100004];
ll ans[100004],sum[100004];
void dfs(int x,int pa,int d){
	depth[x]=d,par[0][x]=pa;
	for (int i=1;i<=lg[d];i++) par[i][x]=par[i-1][par[i-1][x]];
	for (int i=0;i<g[x].size();i++) if (g[x][i]!=pa) 
		dfs(g[x][i],x,d+1);
}
int lca(int u,int v){
	if (depth[u]>depth[v]) swap(u,v);
	while (depth[u]!=depth[v]) v=par[lg[depth[v]-depth[u]]][v];
	if (u==v) return u;
	for (int i=lg[depth[u]];i>=0;i--) if (par[i][u]!=par[i][v]) u=par[i][u],v=par[i][v];
	return par[0][u];
}
void dfs1(int x,int par,ll now){
	for (int i=0;i<id[x].size();i++)ans[id[x][i]]+=(now-sum[C[x][i]]+cnt[C[x][i]]*B[x][i])*A[x][i];
	for (int i=0;i<g[x].size();i++) if (g[x][i]!=par){
		cnt[cl[x][i]]++,sum[cl[x][i]]+=len[x][i];
		dfs1(g[x][i],x,now+len[x][i]);
		cnt[cl[x][i]]--,sum[cl[x][i]]-=len[x][i];
	}
}
int main(){
	read(n),read(q);
	for (int i=0;i<17;i++) lg[1<<i]=i;
	for (int i=3;i<=n;i++) lg[i]=max(lg[i],lg[i-1]);
	for (int i=1;i<n;i++){
		int a,b,c,d;read(a),read(b),read(c),read(d);
		g[a].push_back(b),g[b].push_back(a),cl[a].push_back(c),cl[b].push_back(c),len[a].push_back(d),len[b].push_back(d);
	}
	dfs(1,0,0);
	for (int i=1;i<=q;i++){
		int a,b,c,d;read(c),read(d),read(a),read(b);
		int LCA=lca(a,b); 
		id[a].push_back(i),A[a].push_back(1),B[a].push_back(d),C[a].push_back(c);
		id[b].push_back(i),A[b].push_back(1),B[b].push_back(d),C[b].push_back(c);
		id[LCA].push_back(i),A[LCA].push_back(-2),B[LCA].push_back(d),C[LCA].push_back(c);
	}
	dfs1(1,0,0);
	for (int i=1;i<=q;i++) write(ans[i]),puts("");
}

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

int main(){
   
  int n;
  cin >> n;
  int a[n];
  bool c[13]={};
  int count=0;
  
  
  
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++){
   a[i]/=400;
   c[a[i]]=1;
   if(a[i]>=8) count++;
  }
  int min=0,max=0;
  for(int i=0; i<8; i++){
    min+=c[i];
  }
  max=min+count;
  if(min==0) min++;
  cout << min << " " << max << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int f(vector<pair<int,int>>& v){
  int k=0;
  sort(v.begin(),v.end(),[](const pair<int,int> a,const pair<int,int> b){
                           if(a.first>b.first) return 1;
                           return 0;
                         });
  if(df)print(v);
  int n=v.size();
  rep(i,n){
    k+=v[i].first;
    if(k<0) return -1;
    k+=v[i].second-v[i].first;
  }
  return k;
}

int main(){
  int n; cin >>n;
  vector<pair<int,int>> pl,mi;
  rep(i,n){
    string s; cin >>s;
    int cnt=0,m=0;
    rep(j,s.size()){
      cnt+=((s[j]=='(')?1:-1);
      m=min(m,cnt);
    }
    if(cnt>=0) pl.push_back({m,cnt});
    else mi.push_back({m-cnt,-cnt});
  }
  if(df){
    print(pl);
    print(mi);
  }
  int up=f(pl), down=f(mi);
  if(df)print(up,down);
  if(up==down and up>=0) print("Yes");
  else print("No");
}


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

int main() {
  int N, a[50], max = 0, m_idx = 0;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a[i];
    if (max < abs(a[i])) {
      max = abs(a[i]);
      m_idx = i;
    }
  }

  cout << 2*(N-1) << endl;
  for (int i=0; i<N; i++) {
    if (i == m_idx) continue;
    cout << m_idx+1 << " " << i+1 << endl;
  }
  for (int i=1; i<N; i++) {
    if (0 < a[m_idx]) {
      cout << i << " " << i+1 << endl;
    } else {
      cout << N-i+1 << " " << N-i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n <= 999)
		printf("ABC");
	else
		printf("ABD");
	return 0;
}

Measured memory_bytes: 256
/*input
3 3
abc


*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=405;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ld f[maxn][maxn][maxn];
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            c1++;
        } else if (x == 2) {
            c2++;
        } else {
            c3++;
        }
    }
 
    for (int k = 0; k < maxn; k++) {
        for (int j = 0; j + k < maxn; j++) {
            for (int i = 0; i + j + k < maxn; i++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                if (i + j + k > maxn) {
                    continue;
                }
                ld wait = 1.0 * n / (i + j + k);
                ld pi = 1.0 * i / (i + j + k);
                ld pj = 1.0 * j / (i + j + k);
                ld pk = 1.0 * k / (i + j + k);
 
                if (i) {
                    f[i][j][k] += pi * f[i - 1][j][k];
                }
                if (j) {
                    f[i][j][k] += pj * f[i + 1][j - 1][k];
                }
                if (k) {
                    f[i][j][k] += pk * f[i][j + 1][k - 1];
                }
                f[i][j][k] += wait;
            }
        }
    }
 
    cout.precision(10);
    cout << fixed << f[c1][c2][c3] << "\n";
    return 0;
}
 


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

int main() {
    int a, b;
    cin >> a >> b;
    if(b < 0) { 
        if((b-a)&1) { /*b-aが奇数の時*/cout << "Positive" << endl;}
        else cout << "Negative" << endl;
        return 0;
    }
    if(a <= 0) { cout << "Zero" << endl; return 0;}
    cout << "Positive" << endl;
    return 0;
}

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

int main(void){
    int h, w;
    cin >> h >> w;

    //0行目
    for(int i = 0; i < w+1; i++){
        cout << '#';
    }
    cout << '#' << endl;

    //1からh行目
    for(int i = 0; i< h; i++){
        string s;
        cin >> s;
        cout << '#' << s << '#' << endl;
    }

    //ラスト
    for(int i = 0; i < w+1; i++){
        cout << '#';
    }
    cout << '#' << endl;

    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a=0,i;
	char s[32],t[32]="CODEFESTIVAL2016";
	scanf("%s",s);
	for(i=0;i<=15;i++){
		if(s[i]!=t[i]){a++;}
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nm = Console.ReadLine().Split(' ');
            string[] StringAi = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);
            int[] IntAi = new int[StringAi.Length];
            int sum = 0;

            for(int i = 0; i < StringAi.Length;i++)
            {
                sum += int.Parse(StringAi[i]);
            }
            if(n < sum)
            {
                Console.WriteLine("-1");
                return;
            }else{
                Console.WriteLine(n-sum);
            }
            
        }
    }
}


Measured memory_bytes: 28512