akhauriyash/Code-Regression huggingface dataset:
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    println(join(["2018",readline()[5:end]]))
end
main()

Measured memory_bytes: 117524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int H,W;
 
        String work[] = new String[2];
 
        while(true){
 
            try {
                work = br.readLine().split("[\\s]+");
                if(work[0].equals("0") && work[1].equals("0"))break;
 
                H = Integer.parseInt(work[0]);
                W = Integer.parseInt(work[1]);
 
                for(int row = 0; row < H; row++){
                    for(int col = 0; col < W; col++){
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
 
                System.out.printf("\n");
 
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] sideArrayTmp = br.readLine().split(" ");
        int[] sideArray = new int[n];
        for(int i = 0; i < n; i++){
            sideArray[i] = Integer.parseInt(sideArrayTmp[i]);
        }
        Arrays.sort(sideArray);
        int sum = 0;
        for(int i = 0; i < n-1; i++){
            sum += sideArray[i];
        }
        if(sum > sideArray[n-1]){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22612
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        a: usize,
    }
    let amari = n % 500;
    if amari <= a {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, k, s;
    cin >> n >> k >> s;
    rep(i, n){
        if(k > 0){
            cout << s;
            k--;
        }
        else{
            cout << ((s != 1000000000) ? 1000000000 : 1);
        }
        cout << (i == n-1 ? endl : " ");   
    }
}

Measured memory_bytes: 3644
use std::io;
use std::io::BufRead;

fn main() {
  let stdin = io::stdin();
  for line in stdin.lock().lines() {
    let line = line.unwrap();
    let mut iter = line.trim()
      .split_whitespace()
      .map(|x| x.parse::<usize>().unwrap());
    let (h, w) = (iter.next().unwrap(), iter.next().unwrap());

    if h == 0 && w == 0 { break; }

    let line1 = "#.".repeat(w / 2) + if w % 2 != 0 { "#" } else { "" };
    let line2 = ".#".repeat(w / 2) + if w % 2 != 0 { "." } else { "" };

    for _ in 0..h / 2 {
      println!("{}", line1);
      println!("{}", line2);
    }
    
    if h % 2 != 0 {
      println!("{}", line1);
    }

    println!("");
  }
}


Measured memory_bytes: 5036
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string s;
	cin >> s;
	if(s == "Sunny"){
		cout << "Cloudy";
	}
	if(s == "Cloudy"){
		cout << "Rainy";
	}
	if(s == "Rainy"){
		cout << "Sunny";
	}
	return 0;
}


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

int main(){
	string s;
	int k;
	cin>>k>>s;
	if(s.size()<=k) cout<<s;
	else{
		for(int i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"...";
	}
	return 0;
} 

Measured memory_bytes: 3100
#include <stdio.h>

const int Mod = 1000000007;
int N, a[22][22], bit[22];
long long dp[2097152];

long long recursion(int n, int k)
{
	if (dp[k] >= 0) return dp[k];
	else dp[k] = 0;
	
	int i, j;
	for (i = 0, j = k; j > 0; i++, j >>= 1) {
		if (j % 2 == 1 && a[n-1][i] == 1) dp[k] = (dp[k] + recursion(n - 1, k ^ bit[i])) % Mod;
	}
	return dp[k];
}

int main()
{
	int i, j;
	scanf("%d", &N);
	for (i = 0; i < N; i++) for (j = 0; j < N; j++) scanf("%d", &(a[i][j]));
	for (i = 1, bit[0] = 1; i <= N; i++) bit[i] = bit[i-1] << 1;
	for (i = 1, dp[0] = 1; i < bit[N]; i++) dp[i] = -1;
	printf("%lld\n", recursion(N, bit[N] - 1));
	fflush(stdout);
	return 0;
}

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

using namespace std;

class Dice {
    public:
        int value[6];
        Dice(){};
        Dice(int* num) {
            for (int i = 0; i < 6; i++) {
                Dice::value[i] = num[i];
            }
        }
        void rotate(char direction) {
            int tmp;
            switch(direction) {
                case 'N':
                    tmp = Dice::value[0];
                    Dice::value[0] = Dice::value[1];
                    Dice::value[1] = Dice::value[5];
                    Dice::value[5] = Dice::value[4];
                    Dice::value[4] = tmp;
                    break;

                case 'S':
                    for(int i = 0; i < 3; i++) Dice::rotate('N');
                    break;

                case 'W':
                    tmp = Dice::value[0];
                    Dice::value[0] = Dice::value[2];
                    Dice::value[2] = Dice::value[5];
                    Dice::value[5] = Dice::value[3];
                    Dice::value[3] = tmp;
                    break;

                case 'E':
                    for(int i = 0; i < 3; i++) Dice::rotate('W');
                    break;

                case 'R':
                    tmp = Dice::value[1];
                    Dice::value[1] = Dice::value[3];
                    Dice::value[3] = Dice::value[4];
                    Dice::value[4] = Dice::value[2];
                    Dice::value[2] = tmp;
                    break;

                default:
                ;
            }
        }
};

bool isSame(Dice dice1, Dice dice2) {
    int count = 4;
    if(dice2.value[3] == dice1.value[0]) dice2.rotate('E');
    if(dice2.value[2] == dice1.value[0]) dice2.rotate('W');
    while(dice2.value[0] != dice1.value[0] && count-->0) dice2.rotate('N');
    count=4;
    while(dice2.value[1] != dice1.value[1] && count-->0) dice2.rotate('R');
    for(int i = 0; i< 6; i++) {
        if(dice2.value[i] != dice1.value[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int num[6];
    string result = "Yes";
    int n;cin >> n;
    Dice dices[n];
    Dice dicesBase[n];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 6; j++) cin >> num[j];
        dices[i] = Dice(num);
        dicesBase[i] = Dice(num);
    }

    char direction[4] = {'N', 'S', 'W', 'E'};
    for(int j = 1; j < n; j++) {
        for(int i=0;i<4;i++) {
            dices[j] = dicesBase[j];
            dices[j].rotate(direction[i]);
            if(isSame(dices[0], dices[j])) result = "No";
        }
        dices[j] = dicesBase[j];
        dices[j].rotate('N');
        dices[j].rotate('N');
        if(isSame(dices[0], dices[j])) result = "No";
    }

    cout << result << endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum,a;
    while(1){
        cin >> sum;
        if(sum==0){break;}
        for(int i=0;i<9;i++){
            cin >> a;
            sum-=a;
        }
        cout << sum << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3232
#include<iostream>
using namespace std;
int N,t,a,b;
int main(){
    scanf("%d",&N);
    int la=0,lb=0,lt=0;
    bool f=1;
    for(int i=0;i<N;i++){
        scanf("%d %d %d",&t,&a,&b);
        if(abs(a-la)+abs(b-lb)<=t-lt){
            if((abs(a-la)+abs(b-lb))%2!=(t-lt)%2)
                f=0;
        }else
            f=0;
        if(!f){
            printf("No\n");
            return 0;
        }

    }
    printf("Yes\n");



}


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

int N;
const int MAX_N = 20;
char a[MAX_N*2];

vector<int> R,B;
lint dp[MAX_N][MAX_N];
lint f(int x,int y){
    if(x==R.size() && y==B.size())return 1;
    lint& ret = dp[x][y];
    if(~ret)return ret;
    ret = 0;
    if(x<R.size() && a[x+y+N] == a[R[x]]){
        ret += f(x+1,y);
    }
    if(y<B.size() && a[x+y+N] == a[B[y]]){
        ret += f(x,y+1);
    }
    return ret;
}

int main(){
    scanf("%d",&N);
    scanf("%s",a);

    lint ans = 0;
    for(int i=(1<<N)-1;i>=0;i--){
        R.clear();
        B.clear();
        for(int j=N-1;j>=0;j--){
            if(i>>j&1){
                R.push_back(j);
            }else{
                B.push_back(j);
            }
        }
        memset(dp,-1,sizeof(dp));
        ans += f(0,0);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <iostream> 
using namespace std;
 
int main(){
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for(int i = 0; i < N; i++){
        if(ans < K){
            ans *= 2;
        }else{
            ans += K;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
        m1=h1*60+m1;
        m2=h2*60+m2;
        int ans=m2-m1-k;
        cout<<ans;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

typedef long long lli;

int main() {
  lli f[21];
  int num[26];

  f[0] = f[1] = 1;
  for(lli i = 2; i < 21; ++i) f[i] = f[i-1]*i;

  {
    string S;
    cin >> S;
    fill(num,num+26,0);
    for(int i = 0; i < S.size(); ++i) ++num[S[i]-'a'];
  }

  lli ans = 0;

  {
    int odd = 0;
    int sum = 0;
    for(int i = 0; i < 26; ++i) {
      if(num[i]%2) {
	++odd;
	--num[i];
      }
      sum += num[i];
    }
    if(odd <= 1) {
      ans = f[sum/2];
      for(int i = 0; i < 26; ++i) ans /= f[num[i]/2];
    }
  }

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class book{
public:
	ll t,a,b,flag;
};
bool compare(pair<ll,ll> p1,pair<ll,ll> p2){
  if(p1.second==p2.second) return p1.first>p2.first;
	return p1.second>p2.second;
}
bool comp(char a, char b)
{
    return (a < b);
}
int mex(int *A,int n){
	int C[n];
	for(int i=0;i<n;i++) C[i]=A[i];
	sort(C,C+n);
	for(int i=0;i<=n;i++){
		if(!binary_search(C,C+n,i)) return i;
	}
}
bool check(int *A,int n){
	for(int i=0;i<n-1;i++){
		if(A[i]>A[i+1]) return false;
	}
	return true;
}
bool subsetSum(vector<ll> arr, int n, int s){
	int dp[2][s+1];

	for(int i=0;i<=s;i++){
		dp[0][i] = false;
	}
    dp[0][0] = true;

    int flag = 1;

	for(int i=1;i<=n;i++){
		for(int j =1;j<=s;j++){
			dp[flag][j] = dp[flag^1][j];
			if(j-arr[i-1]>=0){
				dp[flag][j] = dp[flag][j] || dp[flag^1][j-arr[i-1]];
			}
		}
        flag^=1;
	}

 	return dp[flag^1][s];
}
int main() {
	// your code goes here


	int T=1;
	//cin>>T;

	while(T--){
	     ll n;
       ll d;
			 cin>>n>>d;
			 ll a,b;
       double x;
       int ctr=0;
       for(int i=0;i<n;i++){
         cin>>a>>b;
         x=(double)sqrt(a*a+b*b);
         //cout<<x<<endl;
         if(x<=(double)d) ctr++;

       }
       cout<<ctr<<endl;

}
	return 0;
}


Measured memory_bytes: 3680
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),min=0,max=0,f=0;
    int[] a=new int[n],color=new int[8];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      if(a[i]<400&&color[0]==0){
        color[0]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=400&&a[i]<800&&color[1]==0){
        color[1]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=800&&a[i]<1200&&color[2]==0){
        color[2]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=1200&&a[i]<1600&&color[3]==0){
        color[3]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=1600&&a[i]<2000&&color[4]==0){
        color[4]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=2000&&a[i]<2400&&color[5]==0){
        color[5]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=2400&&a[i]<2800&&color[6]==0){
        color[6]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=2800&&a[i]<3200&&color[7]==0){
        color[7]++;
        min++;
        max++;
        f++;
      }else if(a[i]>=3200){
        if(i==0){
          min++;
          max++;
        }else{
          max++;
        }
      }
    }
    if(n>=2){
      if(a[0]>=3200&&f>0){
        min--;
      }
    }
    System.out.println(min+" "+max);
  }
}


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

int a[3][3];

int main()
{
	int sum=0,sum1=0;
	for(int i=0; i<3; i++) 
	{
		for(int j=0; j<3; j++) 
		{
			cin>>a[i][j]; 
			sum+=a[i][j];
			if(i==j) 
				sum1+=a[i][j];
		}
	}
	
	if(sum-sum1==2*sum1) 
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1 << 28) - 1
#define MOD 1000000007
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, d[1100][1100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    int a[1100], b[1100], c[1100];
    rep(i, 0, n) rep(j, 0, n) 
        d[i][j] = (i == j ? 0 : INF);
    rep(i, 0, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
    }
    rep(i, 0, m) {
        d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
        d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
    }
    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    int ans = 0;
    rep(i, 0, m) {
        bool flag = false;
        rep(j, 0, n) {
            if (d[j][a[i]] + c[i] == d[j][b[i]]) flag = true;
        }
        if (flag) ans++;
    }
    cout << m - ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include<iostream>

using namespace std;

void print(int h,int w)
{
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<'#';
        }
        cout<<'\n';
    }
}

int main()
{
    int H[1000],W[1000];

    for(int i=0;;i++){
        cin>>H[i]>>W[i];
        if(H[i]==0 && W[i]==0)    break;
    }

    for(int i=0;;i++){
        if(H[i]==0 && W[i]==0)    break;
        print(H[i],W[i]);
        cout<<'\n';
    }

}


Measured memory_bytes: 3004
MOD = 10**9+7

def sum(a,d,n):
    return n*(2*a+(n-1)*d)//2

def main():
    n,m = map(int,input().split())

    s = 0
    if n == 1:
        s = m+1
    else:
        s = sum(m+1,-n+1,1+m//(n-1))
        s *= 2
        s -= (m+1)

    print(s%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(a[i]>0){
            if(cnt%2==1)tmp++;
            cnt=0;
        }
        else cnt++;
    }
    if(cnt%2==1)tmp++;
    if(tmp%2==1){
        rep(i,n)a[i]=abs(a[i]);
        sort(a,a+n);
        rrep(i,1,n)ans+=a[i];
        ans-=a[0];
    }
    else{
        rep(i,n)a[i]=abs(a[i]),ans+=a[i];
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
template <class T>
ostream& operator<<(ostream& s, vector<T>& d) {
    REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
    return s;
}
using Int = long long;

struct DirectedGraph {
    struct Edge {
        Int to, cost;
    };
    vector<vector<Edge>> G;
    Int V;
    DirectedGraph(Int V_) : G(V_), V(V_) {}
    void add_edge(Int u, Int v, Int cost) { G[u].push_back({v, cost}); }
    vector<Int> dijkstra(Int s) {
        vector<Int> d(V, 1e18);
        d[s] = 0;
        using ii = pair<Int, Int>;
        priority_queue<ii, vector<ii>, greater<ii>> q;
        q.push({0, s});
        while (!q.empty()) {
            ii p = q.top();
            q.pop();
            Int v = p.second;
            if (d[v] < p.first) continue;
            for (auto& e : G[v]) {
                Int tmp = d[v] + e.cost;
                if (d[e.to] <= tmp) continue;
                d[e.to] = tmp;
                q.push({tmp, e.to});
            }
        }
        return d;
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    vector<Int> d(n);
    REP(i, n) cin >> d[i];
    DirectedGraph g(n);
    REP(i, n - 1) { g.add_edge(i + 1, i, 0); }
    REP(i, m) {
        Int a, b;
        cin >> a >> b;
        a--, b--;
        g.add_edge(a, b, d[b]);
    }
    auto dist = g.dijkstra(s);
    // cerr << dist << endl;
    cout << dist[t] << endl;
}



Measured memory_bytes: 14416
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a+b == c+d){
		cout << "Balanced" << endl;
	}else{
		if(a+b > c+d) cout << "Left" << endl;
		else cout << "Right" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import defaultdict


def main():
    n = int(input().strip())
    a_list = list(map(int, input().split()))

    p_set = defaultdict(set)
    n_set = defaultdict(set)

    for i, a in enumerate(a_list):
        p_set[a_list[i] - i].add(i)
        n_set[- a_list[i] - i].add(i)

    r = 0
    for p in p_set:
        pl = len(p_set[p])
        nl = len(n_set[p])
        r += pl * nl
    print(r)

if __name__ == '__main__':
    main()


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

using namespace std;

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

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

typedef pair<ll, ll> P;

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

//#define int long long

#define all(v) v.begin(), v.end()

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

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

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

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

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

  ll n, t;
  cin >> n >> t;

  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vll mi(n), ma(n);
  mi[0] = a[0];
  REP(i, n) {
    mi[i] = min(mi[i - 1], a[i]);
  }
  ma[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    ma[i] = max(mi[i + 1], a[i]);
  }

  vll dif(n);
  ll max_dif = 0;
  rep(i, n) {
    dif[i] = ma[i] - mi[i];
    chmax(max_dif, dif[i]);
  }
  ll ans = 0;

  for (int i = 0; i < n; i++) {
    if (max_dif == dif[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashMap;
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
macro_rules! maxs {
    ($x:expr, $($y:expr), *) => {{
        let mut ret = $x;
        $(
            ret = max(ret, $y);
        )*
        ret
    }};
}
fn main() {
    input!(N: usize);
    let mut ans: usize = 0;
    for A in 1..N {
        ans += (N - 1) / A;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2168
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
        cout << (n - 1) / 2 << endl;
    return 0;
}

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

int main(){
  char b;

  cin >>b;

  if(b == 'A'){
      cout <<'T'<<endl;
  };
  if(b == 'T'){
      cout <<'A'<<endl;
  };
  if(b == 'C'){
      cout <<'G'<<endl;
  };
  if(b == 'G'){
      cout <<'C'<<endl;
  };
  return 0;
  }

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

int main() {
    int W, H, x, y, r;
    string str;
    cin >> W >> H >> x >> y >> r;
    if((x-r < 0 || y-r < 0)||(x+r > W || y+r > H)){
        str = "No";
    } else {
        str = "Yes";
    }

    cout << str << endl;
}

Measured memory_bytes: 3204
#define	Rd(s) scanf("%d",&s)
#define	Rs(s) scanf("%s",&s)
#define	Rf(s) scanf("%f",&s)
#define RTNd(n,s,i) for(int i=0;(i<n)?scanf("%d",&s),true:false;i++)
#define RTNf(n,s,i) for(int i=0;(i<n)?scanf("%lf",&s),true:false;i++)
#define RTEs(s) while(fgets(s,sizeof(s),stdin)!=NULL)
#define RTEc(s) while((s=scanf("%c"))!=EOF)
#define Pd(s) printf("%d",s);

#define Pn printf("\n");
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#include<stdio.h>

int main() {
	int n,x,a=0;
	vector<int> b;

	Rd(n);
	RTNd(n*2, x, i) {
		b.push_back(x);
	}
	sort(b.begin(), b.end());
		for (int i = 0;i < 2*n;i += 2) {
			a += b[i];
		}
		Pd(a);
		Pn;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e3+5;
ll n,p,P,ans,fac[N],inv[N],a[N][N];
ll fsp(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
ll ksm(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%p;
		x=x*x%p,y>>=1;
	}
	return ans;
}
ll C(int n,int m){
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
int main(){
	scanf("%lld%lld",&n,&P),p=P-1,a[0][0]=1;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=i;j++)
			a[i][j]=(a[i-1][j-1]+j*a[i-1][j])%P;
	inv[0]=fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	for(int i=0;i<=n;i++){
		ll d=1,sum=0,tmp=fsp(2,n-i),res=fsp(2,ksm(2,n-i));
		for(int j=0;j<=i;j++){
			sum=(sum+a[i+1][j+1]*d)%P;
			d=d*tmp%P;
		}
		ans=(ans+(i&1?-1:1)*sum*res%P*C(n,i)%P+P)%P;
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if (A-B >= 0){
    cout << "delicious" << endl;
  }
    else if (X-(B-A)>= 0 ){
      cout << "safe" << endl;
    }
      else {
        cout << "dangerous" << endl;
      }
}
        
      
  
  

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>

using namespace std;

#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 INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

/* template end */

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

  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<pair<int, int>> diff(n);
  REP(i, n) {
    cin >> a[i] >> b[i];
    diff[i] = make_pair(a[i] + b[i], i);
  }

  ll takahashi = 0, aoki = 0;
  sort(diff.begin(), diff.end());
  int turn = 0;
  for (int i = n - 1; i >= 0; i--) {
    int t = turn++ % 2;
    (t == 0 ? takahashi : aoki) +=
        (t == 0 ? a[diff[i].second] : b[diff[i].second]);
  }

#if DEBUG
  cout << "** RESULT **" << endl; // debug
#endif
  cout << (takahashi - aoki) << endl;

  return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main()
{
	int N;
	cin >> N;
	vector<ll> Asum(N);
	REP(i, N) {
		ll A;
		cin >> A;
		if(i > 0) Asum[i] = Asum[i - 1] + A;
		else Asum[i] = A;
	}

	/*REP(i, N) cout << Asum[i] << ' ';
	cout << endl;*/

	ll ans = LLINF;
	for(int j = 1; j < N - 2; j++) {
		int l, r;

		l = 0;
		r = j - 1;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(2 * Asum[mid] < Asum[j]) l = mid;
			else r = mid;
		}
		int i[2] = {l, r};

		l = j + 1;
		r = N - 2;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(2 * (Asum[mid] - Asum[j]) < Asum[N - 1] - Asum[j]) l = mid;
			else r = mid;
		}
		int k[2] = {l, r};

		REP(n, 2) {
			REP(m, 2) {
				//cout << i[n] << ' ' << j << ' ' << k[m] << ' ';
				ll P = Asum[i[n]];
				ll Q = Asum[j] - Asum[i[n]];
				ll R = Asum[k[m]] - Asum[j];
				ll S = Asum[N - 1] - Asum[k[m]];
				//cout << "> " << P << ' ' << Q << ' ' << R << ' ' << S << endl;
				ll ma = max({P, Q, R, S});
				ll mi = min({P, Q, R, S});
				ans = min(ans, ma - mi);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();

        String[][] list = new String[h][];

        for (int i = 0; i < h; i++) {
            list[i] = sc.next().split("");
        }

        // 上下左右（分岐先）の座標を配列に入れておくと、forループで回して処理できるので便利
        int[] dx = {0, 1, 0, -1};
        int[] dy = {-1, 0, 1, 0};
        int ans = 0;
        top:
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                // 始点が壁
                if (list[i][j].equals("#")) {
                    continue;
                }
                for (int k = i; k < h; k++) {
                    for (int l = 0; l < w; l++) {
                        // 探索済み
                        if (k == i && j <= l) {
                            continue;
                        }
                        // 終点が壁
                        if (list[k][l].equals("#")) {
                            continue;
                        }
                        String original = list[k][l];
                        list[k][l] = "e";
                        int[][] searched = new int[h][w];
                        Deque<Point> stack = new ArrayDeque<>();
                        stack.addFirst(new Point(j, i));
                        int count = 0;
                        syori : while (!stack.isEmpty()) {
                            Point p = stack.removeFirst(); // 先頭の座標を取得後、削除
                            for (int m = 0; m < 4; m++) {
                                int x = p.x + dx[m];
                                int y = p.y + dy[m];
                                // 分岐先の座標が、2つのif文の条件を満たすなら先頭に追加
                                if (x >= 0 && x < w && y >= 0 && y < h) {
                                    if (list[y][x].equals(".") && searched[y][x] == 0) {
                                        count++;
                                        stack.add(new Point(x, y));
                                        searched[y][x] = searched[p.y][p.x] + 1; // 追加した座標を探索済みにする
                                    } else if (list[y][x].equals("e")) {
                                        count = searched[p.y][p.x] + 1;
                                        break syori;
                                    }
                                }
                            }
                        }
                        list[k][l] = original;
                        ans = Math.max(ans, count);
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 150372
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF (INT_MAX/2)
using namespace std;

struct Edge {
  int src, dst, weight;
  Edge(int src, int dst, int weight) :
    src(src), dst(dst), weight(weight) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool bellmanford(const Graph g, int s, vector<int> &dist) {
  int V = g.size();
  dist.assign(V, INF);
  dist[s] = 0;
  
  bool negative_cycle = false;
  REP(k, V) REP(i, V) if(dist[i] < INF) FOR(e,g[i]) {
    if (dist[e->dst] > dist[e->src] + e->weight) {
      dist[e->dst] = dist[e->src] + e->weight;
      if (k == V - 1) {
        dist[e->dst] = -INF;
        negative_cycle = true;
      }
    }
  }
  return !negative_cycle;
}

int main(){
  int r,V,E,s,t,e,i;
  cin >> V >> E >> r;
  Graph g(V);
  vector<int> dist;

  while(E--){
    cin >> s >> t >> e;
    g[s].push_back(Edge(s,t,e));
  }
  if(!bellmanford(g,r,dist)) cout << "NEGATIVE CYCLE" << endl;
  else{
    for(i=0;i<V;i++){
      if(dist[i] >= INF) cout << "INF" << endl;
      else cout << dist[i] << endl;
    }
  }
}

Measured memory_bytes: 1324
N = int(input())
a = list(map(int, input().split()))
import math

#残差最小化の解
x = sum(a)/N
x_large = math.ceil(x)
x_small = math.floor(x)

#大きい残差と小さい残差を計算
sum_large = 0
sum_small = 0
for i in a:
	sum_large += (x_large-i)**2
	sum_small += (x_small-i)**2
#最小残差
print(min(sum_large,sum_small))

Measured memory_bytes: 3064
(n,m,),*a=$<.map{|z|z.split.map &:to_i}
r=[-1]*-~n
c=r.dup
f=->x{r[x]>0?f[r[x]]:x}
a.map{|u,v|x,y=[f[u],f[v]].sort
m>0&&x!=y&&[r[x]+=r[y],r[y]=y=x]
x==y&&[c[u]-=1,c[v]-=1,m-=1]}
(1..n).map{|i|p c[i]-r[f[i]]}

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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   int x,a[100000];scanf("%d",&x);
   int on = 0;
   for(int i = 0;i < x;i++)scanf("%d",&a[i]);
   for(int i = 1;i <= x;i++){
      if(a[on] == 2){
         printf("%d");
         return 0;
      }
      else on = a[on]-1;
   }
   printf("-1");
   return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(void)
{
    int xs[2], ys[2], eqs[2];
    float x, y;
 
    while (~scanf("%d %d %d %d %d %d", xs, ys, eqs, xs + 1, ys + 1, eqs + 1)){
        x = 1.*(eqs[0] * ys[1] - eqs[1] * ys[0]) / (xs[0] * ys[1] - xs[1] * ys[0]);
        y = 1.*(eqs[1] * xs[0] - eqs[0] * xs[1]) / (xs[0] * ys[1] - xs[1] * ys[0]);
 
        printf("%.3f %.3f\n", x?:0, y);
    }
 
    return (0);
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int ans=0;
  for(Int i=0;i<n;i+=2)
    ans+=as[i]&1;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3660
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var ps = new int[n].Select(_ => Read()).Select(v => (x: v[0], y: v[1])).ToArray();
		if (ps.Select(p => Math.Abs(p.x + p.y) % 2).Distinct().Count() == 2) { Console.WriteLine(-1); return; }

		var ds = new int[41];
		var uy = new bool[n, 41]; // for y-direction

		var qs = ps.Select((p, i) =>
		{
			var (x, y) = p;
			(x, y) = (Math.Abs(x), Math.Abs(y));
			uy[i, 0] = x < y;
			return x < y ? (x: y, y: x) : (x, y);
		}).ToArray();

		// Repeat to halve `max(x + y)`
		ds[0] = qs.Max(p => p.x);

		for (int k = 0; k < 40; k++)
		{
			qs = qs.Select((p, i) =>
			{
				var (x, y) = p;
				x = Math.Abs(x - ds[k]);
				uy[i, k + 1] = (x < y) ^ uy[i, k];
				return x < y ? (y, x) : (x, y);
			}).ToArray();

			var max = qs.Max(p => p.x);
			if (max == 0) break;
			ds[k + 1] = (ds[k] + 1) / 2;
		}

		var m = ds.TakeWhile(d => d > 0).Count();
		Console.WriteLine(m);
		Console.WriteLine(string.Join(" ", ds[..m]));

		var rs = ps.Select((p, i) =>
		{
			var (x, y) = p;
			var c = new char[m];

			for (int k = 0; k < m; k++)
			{
				if (uy[i, k])
				{
					if (y < 0)
					{
						y += ds[k];
						c[k] = 'D';
					}
					else
					{
						y -= ds[k];
						c[k] = 'U';
					}
				}
				else
				{
					if (x < 0)
					{
						x += ds[k];
						c[k] = 'L';
					}
					else
					{
						x -= ds[k];
						c[k] = 'R';
					}
				}
			}
			return new string(c);
		});
		Console.WriteLine(string.Join("\n", rs));
	}
}


Measured memory_bytes: 29732
#include <iostream>

using namespace std;

int main() {
    int n;  cin >> n;
    int *d = new int[n];
    for (int i =0; i < n; i++)
        cin >> d[i];

    int ans = 0;

    for (int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            ans += d[i]*d[j];
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

#define INF 999999999

void updateAns(int a,int b,int ta,int tb,int *ans_a,int *ans_b){
	if(*ans_a + *ans_b > ta + tb){
		*ans_a = ta;
		*ans_b = tb;
	}
	else if(*ans_a + *ans_b == ta + tb){
		if(a * ta + b * tb < a * (*ans_a) + b * (*ans_b)){
			*ans_a = ta;
			*ans_b = tb;
		}
	}
}

int main(void){
	int i,j;
	int a,b,d;
	int ta,tb,ans_a,ans_b;

	while(scanf("%d%d%d",&a,&b,&d) && (a||b||d)){
		ans_a = INF;
		ans_b = INF;

		for(i=0;i<=100000;i++){
			if((a * i + d) % b == 0){
				ta = i;
				tb = (a * i + d) / b;
				updateAns(a,b,ta,tb,&ans_a,&ans_b);
			}
			if(a * i >= d && (a * i - d) % b == 0){
				ta = i;
				tb = (a * i - d) / b;
				updateAns(a,b,ta,tb,&ans_a,&ans_b);
			}
			if(a * i <= d && (d - a * i) % b == 0){
				ta = i;
				tb = (d - a * i) / b;
				updateAns(a,b,ta,tb,&ans_a,&ans_b);
			}
		}

		printf("%d %d\n",ans_a,ans_b);
	}

	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    set<char> st;
    for(int i=0;i<s.size();i++)
    {
       st.insert(s[i]);
    }
    if(st.size()==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//????°???¬?????°
long long koubaisu(long long a,long long b){
  long long x=a*b;
  /* ?????¶??° a > b ????¢?????????\??? */ 
  if(a<b){ 
    long long tmp=a; 
    a=b; 
    b=tmp; 
  }
  /* ?????????????????????????????? */ 
  long long r=a%b; 
  while(r!=0){ 
    a=b; 
    b=r; 
    r=a%b; 
  } 
  /* ????°???¬?????°????????? */ 
  return x/b; 
}
int main(){
  long long a[3],m[3];
  while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]+a[1]+a[2]+m[0]+m[1]+m[2])
    {
      long long x=a[0]%m[0],y=a[1]%m[1],z=a[2]%m[2];
      long long cnt=0;
      long long indx,indy,indz;
      if(x==1)indx=1;
      else
	for(int i=0;i<m[0]-1;i++){
	  if(x==1){
	    indx=i+1;
	    break;
	  }
	  x=(a[0]*x)%m[0];
	}
      if(y==1)indy=1;
      else
	for(int i=0;i<m[1]-1;i++){
	  if(y==1){
	    indy=i+1;
	    break;
	  }
	  y=(a[1]*y)%m[1];
	}
      if(z==1)indz=1;
      else      
	for(int i=0;i<m[2]-1;i++){
	  if(z==1){
	    indz=i+1;
	    break;
	  }
	  z=(a[2]*z)%m[2];
	}
      long long ind;
      ind=koubaisu(indx,indy);
      cnt=koubaisu(ind,indz);
      cout<<cnt<<endl;
    }
  return 0;
}

Measured memory_bytes: 2980
from collections import defaultdict
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

q = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    q[p] += x

seen = [False] * (N + 1)
ans = [0] * (N + 1)


def dfs(e, v, x):
    seen[v] = True
    ans[v] += x
    for next_v in e[v]:
        if seen[next_v]:
            continue
        else:
            dfs(e, next_v, x + q[next_v])


dfs(e, 1, q[1])
print(*ans[1:])


Measured memory_bytes: 263660
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int X=scanner.nextInt();
		int Y=scanner.nextInt();
		int i = 0;
		while(true) {
			if(i > X){
				System.out.println("No");
				break;
				}
			if(Y == 4*i+2*(X-i)) {
				System.out.println("Yes");
				break;
			}
			i++;
		}
		scanner.close();
	}
}

Measured memory_bytes: 35840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String S;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.S = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        if (S.substring(S.length()-1, S.length()).equals("s")) {
        	answer = S + "es";
        } else {
        	answer = S + "s";
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 38492
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  if(S == "ABC") cout  << "ARC" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>



using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	int solve = -1;
	int cnt = 0;

	for (int i = 1; i < n; i++) {
		if (h[i] <= h[i - 1]) {
			cnt++;
		}
		else {
			if (solve < cnt) {
				solve = cnt;
			}
			cnt = 0;
		}
	}

	if (solve < cnt) {
		solve = cnt;
	}

	cout << solve << endl;

}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    bool f;
    string a[50],b[50];
    int n,m,i,j,c,d;
    cin >> n >> m;
    for (i=0;i<n;i++)
        cin >> a[i];
    for (i=0;i<m;i++)
        cin >> b[i];
    for (i=0;i<n-m+1;i++){
        for (j=0;j<n-m+1;j++){
            f=true;
            for (c=0;c<m;c++){
                for (d=0;d<m;d++){
                    if (a[i+c][j+d]!=b[c][d])
                        f=false;
                }
            }
            if (f==true){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
using namespace std;

int N,M,K;
int A[20001]={};
int minD[20001][1001]={};
int maxD[20001][1001]={};
long long dp[20001];
const int INF=2000000000;
const long long INF2=1000000000000000000;

int calmaxD(int n2,int n3){
	int ans=INF;
	if(maxD[n2][n3]>-1)return maxD[n2][n3];
	if(n3==0){
		ans=0;
	}else{
		ans=max(calmaxD(n2,n3-1),A[n2+n3]);
	}
	maxD[n2][n3]=ans;
	return ans;
}
int calminD(int n2,int n3){
	int ans=INF;
	if(minD[n2][n3]>-1)return minD[n2][n3];
	if(n3==0){
		ans=INF;
	}else{
		ans=min(calminD(n2,n3-1),A[n2+n3]);
	}
	minD[n2][n3]=ans;
	return ans;
}
long long calc(int n1){
	long long ans=INF2;
	if(dp[n1]>-1)return dp[n1];
	for(int i=1;i<M+1&&i<n1+1;++i){
		ans=min(ans,calc(n1-i)+(long long)K+(long long)i*(long long)((calmaxD(n1-i,i)-calminD(n1-i,i))));
	}

	dp[n1]=ans;
	return ans;
}

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

	for(int i=1;i<N+1;i++)cin>>A[i];
	fill(minD[0],minD[20001],-1);
	fill(maxD[0],maxD[20001],-1);
	fill(dp,dp+20001,-1);
	dp[0]=0;
	cout << calc(N) << endl;
	return 0;
}

Measured memory_bytes: 161604