akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 1) {
            System.out.println(0);
            System.exit(0);
        }
        int prev = 0;
        int now = 0;

        int max = 0;
        List<Integer> maxList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if(i==0){
                prev = sc.nextInt();
                continue;
            }
            now = sc.nextInt();
            if(now <= prev) {
                max ++;
                if(i == n-1) {
                    maxList.add(max);
                }
            } else {
                maxList.add(max);
                max = 0;
            }
            prev = now;

        }
            System.out.println(Collections.max(maxList));
    }
}


Measured memory_bytes: 48560
#include <iostream>

int main()
{
	int H, W;
	while (true) {
		std::cin >> H >> W;
		if ( H == 0 && W == 0 ) break;
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (i==0 || i==H-1) std::cout << "#";
				else if (j==0 || j==W-1) std::cout << "#";
				else std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

	



Measured memory_bytes: 3104
#include<functional>
#include<algorithm>
#include<iterator>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
int c[11111];
char s[11111],t[11111];
int werken(int cs,int ct)
{
	int tmp=0;
	for(int i=0;i<n;++i)
	{
		++c[cs-ct+5555];
		tmp+=cs-ct+5555;
		if(s[i]!=s[i+1])++cs;
		if(t[i]!=t[i+1])++ct;
	}
	int cu=n,cd=0,res=2147483647;
	for(int i=0;i<11111;++i)
	{
		if((i&1)&&tmp<res)res=tmp;
		cu-=c[i];
		cd+=c[i];
		tmp-=cu;
		tmp+=cd;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	scanf("%s%s",s,t);
	if(s[0]==t[0])printf("%d",werken(0,0));
	else printf("%d",werken(0,1));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool isvalid(int i,int j,int n,int m)
{
    return i>=0&&j>=0&&i<n&&j<m;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int x1,y1;
    cin>>x1>>y1;
    int x2,y2;
    cin>>x2>>y2;
    x1--;
    y1--;
    x2--;
    y2--;
    vector<vector<char> > adj(n,vector<char>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            char c;
            cin>>c;
            adj[i][j]=c;
            
        }
    }
    vector<vector<int> > dp(n,vector<int>(m,1e9));
    deque<pair<int,pair<int,int> > > q;
    q.push_front({0,{x1,y1}});
    dp[x1][y1]=0;
    while(!q.empty())
    {
        int dist=q.front().first;
        int x=q.front().second.first;
        int y=q.front().second.second;
        q.pop_front();
        for(int i=-2;i<=2;i++)
        {
            for(int j=-2;j<=2;j++)
            {
                int newx=x+i;
                int newy=y+j;
                if(isvalid(newx,newy,n,m)&&adj[newx][newy]=='.')
                {
                    if(abs(i)+abs(j)==1)
                    {
                        if(dp[newx][newy]>dp[x][y])
                        {
                            dp[newx][newy]=dp[x][y];
                            q.push_front({dist,{newx,newy}});
                        }
                        
                    }
                    else
                    {
                        if(dp[newx][newy]>dp[x][y]+1)
                        {
                            dp[newx][newy]=dp[x][y]+1;
                            q.push_back({dist+1,{newx,newy}});
                        }
                    }
                    
                }
            }
        }
    }
    if(dp[x2][y2]==1e9)
    cout<<-1<<endl;
    else
    {
        cout<<dp[x2][y2]<<endl;
    }
    
    
}

Measured memory_bytes: 8664
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    for (auto &x : a)
        cin >> x;

    FOR (i, k, n) {
        if (a[i] > a[i-k])
            cout << "Yes" << "\n";
        else
            cout << "No" << "\n";
    }
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases


Measured memory_bytes: 3988
#include <stdio.h>
#include <stdint.h>

#define NMAX (int)1.0e7
int N;
uint64_t f[NMAX];

int main()
{
    int _ = scanf("%lu", &N);
    int i;
    for (i=1; i <= NMAX; i++) {
        int x = i;
        while (x <= NMAX) {
            f[x] = f[x] + 1;
            x = x + i;
        }
    }
    uint64_t s = 0;
    int k = 0;
    for (k = 1; k <= N; k++) {
        s = s + k * f[k];
    }
    printf("%lu\n", s);
    return 0;
}

Measured memory_bytes: 79828
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n;cin >> n;
  while(n--){
    int a,b;cin >> a >> b;
    if(d.left()==a) d.roll('E');
    if(d.right()==a) d.roll('W');
    while(d.top()!=a) d.roll('N');
    while(d.front()!=b) d.roll('R');
    cout << d.right() << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int X,Y,Z,X2,Y2;
	map<int,int> myMap;
	map<int,int>::iterator mit;
	for (X=1;X<=N;X++){
		X2=X*X;
		if (X2>N){
			break;
		}
		for (Y=1;Y<=N;Y++){
			Y2=X2+Y*Y+X*Y;
			if (Y2>N){
				break;
			}
			for (Z=1;Z<=N;Z++){
				int F=Y2+Z*Z+Y*Z+X*Z;
				if (F>N){
					break;
				}else{
					mit=myMap.find(F);
					if (mit==myMap.end()){
						myMap[F]=1;
					}else{
						(*mit).second++;
					}
				}
			}
		}
	}
	for (int i=1;i<=N;i++){
		mit=myMap.find(i);
		if (mit==myMap.end()){
			cout<<0<<endl;
		}else{
			cout<<(*mit).second<<endl;
		}
	}
	return 0;
}

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

int main() {
	double t1, t2;
	while (cin >> t1 >> t2) {
		if (t1 < 35.5&&t2 < 71.)puts("AAA");
		else if (t1 < 37.5&&t2 < 77.)puts("AA");
		else if (t1 < 40.&&t2 < 83.)puts("A");
		else if (t1 < 43.&&t2 < 89.)puts("B");
		else if (t1 < 50.&&t2 < 105.)puts("C");
		else if (t1 < 55.&&t2 < 116.)puts("D");
		else if (t1 < 70.&&t2 < 148.)puts("E");
		else puts("NA");
	}
}

Measured memory_bytes: 3172
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

rotate90 = transpose . reverse

main = do
  f <- replicateM 8 getLine
  print 90
  mapM_ putStrLn . rotate90 $ f
  print 180
  mapM_ putStrLn . rotate90 . rotate90 $ f
  print 270
  mapM_ putStrLn . rotate90 . rotate90 . rotate90 $ f

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
import heapq

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, k = map(int, input().split())
    ary = []
    heapq.heapify(ary)
    for a, b in readlines(n):
        heapq.heappush(ary, (a, b))

    while True:
        a, b = heapq.heappop(ary)
        k -= b
        if k <= 0:
            print(a)
            return

main()




Measured memory_bytes: 16688
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;

int main(){
	ll x, t;
  	scanf("%lld%lld", &x, &t);
  	if(x >= t) printf("%lld", x - t);
  	if(x < t) printf("0");
	return 0;
}


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

int main(){
  int i,j;ll cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n;i++){
    if(i%2==0)cnt+=a[i];
    else cnt-=a[i];
  }
  cout<<cnt;
  for(i=0;i<n-1;i++){
    cnt=(-1)*cnt+2*a[i];
    cout<<" "<<cnt;
  }
  cout<<endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/
int par[100005];
int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
int main(){
     
     int n,m;
     cin>>n>>m;
     for(int i=1;i<=n;i++)par[i]=i;
     for(int i=1;i<=m;i++){
          int x,y,z;
          cin>>x>>y>>z;
          unite(x,y);
     }
     ll res=0;
     for(int i=1;i<=n;i++){
          if(find(i)==i){
               res++;
          }
     }
     cout<<res;

}
 
 
 
 
 

























Measured memory_bytes: 4148
#include<bits/stdc++.h>
#define N_ 101000
using namespace std;
int Deg[N_],Q[N_],head,tail,n,m,D[N_],res,a,b;
vector<int> E[N_];
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;i++) cin>>a>>b,E[a].push_back(b),Deg[b]++;
	for (int i=1;i<=n;i++) if (!Deg[i]) Q[++tail]=i;
	while (head<tail)
	{
		int x=Q[++head];
		res=max(res,D[x]);
		for (auto &y : E[x])
		{
			Deg[y]--;
			D[y]=max(D[y], D[x] + 1);
			if (!Deg[y]) Q[++tail] = y;
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>

int main(void) {
	char s1[10],s2[10],s3[10];

	scanf("%s %s %s",s1,s2,s3);

	int a=s1[0];
	int b=s2[0];
	int c=s3[0];

	printf("%c%c%c\n",a-32,b-32,c-32);

	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==25)
	  cout<<"Christmas";
	if(n==24)
	  cout<<"Christmas Eve";
	if(n==23)
	  cout<<"Christmas Eve Eve";
	if(n==22)
	  cout<<"Christmas Eve Eve Eve";
	return 0;
}

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

int n;
int mas[101][101];
int dp[101][101];

int rec(int i,int j){
  if(i == n) return 0;
  if(j < 0 || mas[i][j] == -1) return -(2 << 26);
  if(dp[i][j]) return dp[i][j];
  int res = 0;
  if(i < n/2) res = max(rec(i+1,j)+mas[i][j],rec(i+1,j+1)+mas[i][j]);
  else if(i >= n/2) res = max(rec(i+1,j-1)+mas[i][j],rec(i+1,j)+mas[i][j]);
  return dp[i][j] = res;
}

int main(){
  memset(mas,-1,sizeof(mas));
  for(int i=0;;i++){
    stringstream ss;  string s; 
    getline(cin,s);
    n = i;
    if(s.size() == 0) break;
    ss << s;
    for(int j=0;;j++){
      char tr; int fig;
      ss >> fig;  mas[i][j] = fig;
      if(ss.peek() == -1) break;
      ss >> tr;
    }
  }
  cout << rec(0,0) << endl;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> dis(N - 1);
    for (int i = 0; i < N - 1; i++){
        for (int j = i + 1; j < N; j++){
            if (i + 1 <= X && j + 1 >= Y){
                dis.at(X - i - 1 + 1 + (j + 1) - Y - 1)++;
                continue;
            }
            if (i + 1 >= Y || j + 1 <= X){
                dis.at(j - i - 1)++;
                continue;
            }
            if (i + 1 >= X && j + 1 >= Y){
                int a = min(j - i, i + 1 - X + 1 + (j + 1) - Y);
                dis.at(a - 1)++;
                continue;
            }
            if (i + 1 >= X && j + 1 <= Y){
                int a = min(j - i, i + 1 - X + 1 + Y - (j + 1));
                dis.at(a - 1)++;
                continue;
            }
            if (i + 1 <= X && j + 1 <= Y){
                int a = min(j - i, X - i - 1 + 1 + Y - (j + 1));
                dis.at(a - 1)++;
                continue;
            }
        }
    }
    for (int i = 0; i < N - 1; i++){
        cout << dis.at(i) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream> 
#include <algorithm> 
using namespace std;
int main()
{
    long long int h,i,k,m=0;
    cin >> h;
	k=log2(h);
    for(i=0;i<=k;i++)
        m+=pow(2,i);
    cout << m;
    
    return 0;
}


Measured memory_bytes: 384
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-10 21:04:02
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = INF;
    for (long bit = 0; bit < (1<<n); bit++) {
        int sum = 0;
        int p[m] = {0};
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                sum += c[i];
                for (int j = 0; j < m; j++) {
                    p[j] += a[i][j];
                }
            }   
        }

        int ok = 1;
        for (int j = 0; j < m; j++) {
            if (p[j] < x) {
                ok = 0;
            }
        }

        if (ok && ans > sum) ans = sum;
    }

    if (ans == INF) cout << "-1" << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
	string S; cin >> S;
	vector<int>A(26);
	for (int i = 0; i < 4; i++) {
		A.at(S.at(i) - 65)++;
	}
	int ans = 0;
	for (int i = 0; i < 26; i++) {
		if (A.at(i) == 2) ans++;
	}
	if (ans == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    cout << (n % k > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 3480
from sys import stdin
k = int(stdin.readline().rstrip())
num = 7
flag = 0
for i in range(1, k + 1):
    if num % k == 0:
        flag = 1
        break
    num = (num * 10 + 7) % k
if flag == 1:
    print(i)
else:
    print(-1)

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

int main(){
    ll a,b,k;
    cin>>a>>b>>k;

    ll n=b-a+1;
    //vector<ll> num(n);
    //iota(num.begin(),num.end(),a);
    if(n<=k){
        for(int i=a;i<=b;i++) cout<<i<<"\n";
        return 0;
    }

    set<ll> ans;
    for(ll i=a;i<a+k;i++) ans.insert(i);
    for(ll i=b-k+1;i<=b;i++) ans.insert(i);

    for(auto itr=ans.begin();itr!=ans.end();itr++) cout<<*itr<<"\n";
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = Array.fill(n)(sc.nextLong)
  val counts = new Array[Long](60)
  val Mod = 1000000007L

  for (a <- as; no <- 0 until 60) {
    val x: Long = a
    val z: Long = counts(no)
    counts(no) += (if ((a & (1L << no)) != 0) 1 else 0)
  }
  println(counts.zipWithIndex.foldLeft(0L){case (z, (c, i)) => (z + (c * (n - c) % Mod) * ((1L << i) % Mod)) % Mod})
}

Measured memory_bytes: 105644
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int zzz;
	int a,b,c,d,e,f,g,h;
	char x='+',y='+',z='+';
	cin >> zzz;
	a = zzz/1000;
	zzz -= a * 1000;
	b = zzz/100;
	zzz -= b * 100;
	c = zzz/10;
	zzz -= c * 10;
	d = zzz;
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			for (int k = 0;k < 2;k++) {
				if (i) b *= -1;
				if (j) c *= -1;
				if (k) d *= -1;
				if (a+b+c+d == 7) {
					if(i) x='-';
					if(j) y='-';
					if(k) z='-';
					b = abs(b);
					c = abs(c);
					d = abs(d);
					goto ii45i4;
				} else {
					b = abs(b);
					c = abs(c);
					d = abs(d);
				}
			}
		}
	}
	ii45i4: cout<<a<<x<<b<<y<<c<<z<<d<<"=7"<<endl;
}

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

using namespace std;

int main() {
  int a,b,c,k,ans=0;
  
  cin>>a>>b>>c>>k;
  for(int i=k;i>0;i--){
    if(a>0){
        ans+=1;
        a--;
    }
    else if(b>0){
        b--;
    }
    else{
        ans-=1;
        c--;
    }
  }

  cout<<ans;
  
  return 0;

}

Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
bool exist[5001][5001];
int x[3000];
int y[3000];
int max(int a,int b){return a>b?a:b;}
bool check(int px,int py){
	return px>=0&&px<=5000&&py>=0&&py<=5000&&exist[px][py];
}
int main(){
	int n;
	int i,j;
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	memset(exist,false,sizeof(exist));
	for(i=0;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
		exist[x[i]][y[i]]=true;
	}
	int ans=0;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			int x1=x[i];int y1=y[i];
			int x2=x[j];int y2=y[j];
			int ydf=x2-x1;int xdf=y1-y2;
			int area=xdf*xdf+ydf*ydf;
			if(check(x1+xdf,y1+ydf)&&check(x2+xdf,y2+ydf))ans=max(ans,area);
			if(check(x1-xdf,y1-ydf)&&check(x2-xdf,y2-ydf))ans=max(ans,area);
		}
	}
	printf("%d\n",ans);
	}
}
			

Measured memory_bytes: 25480
#include<stdio.h>
int main()
{
 char str1[200],str2[100],str3[100];

 scanf("%s",str1);
 strcpy(str3,str1);
 strcat(str1,str3);
 scanf("%s",str2);

 if(strstr(str1,str2))printf("Yes\n");
 else printf("No\n");

 return 0;

}



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

int main() {
    ll L,R;
    cin >> L >> R;
    if(R-L >= 2019){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 2018;
    for(ll l=L;l<R;++l)for(ll r=l+1;r<=R;++r){
        ans = min(ans,(l*r)%2019);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll x; cin>>x;
    rep(i,0,1000){
        rep(j,-250,250){
            ll a=i*i*i*i*i-j*j*j*j*j;
            if(a==x) {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int x,a,b; cin >> x >> a >> b;
	if (abs(x-a) < abs(x-b))
		cout << "A";
	else
		cout << "B";
	return (0);
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n, k);
  int bias = 0;
  for(int i = 0 ;i < q; i++) {
    bias--;
    int x;
    cin >> x;
    x--;
    a[x]++;
  }
  for(int i = 0; i < n; i++) cout << (a[i] + bias <= 0 ? "No" : "Yes") << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    map<int, int> mp;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int val=i*i+j*j+k*k+i*j+j*k+k*i;
                mp[val]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<mp[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5368
//https://atcoder.jp/contests/abc161/tasks/abc161_c
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long n = in.nextLong(), k = in.nextLong();

        long remainder = n % k;
        out.println(Math.min(remainder,k - remainder));
        out.close();

    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main(void) {
	int n, t, i, j, a, b[3003], dp[3003][3003] = {}, vi, rt;
	vector<P> v;

	cin >> n >> t;
	for (i = 0; i < n; i++) {
		cin >> a >> b[i];
		v.push_back(P(a, i));
	}

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

	for (i = 1; i <= n; i++) {
		rt = v[i - 1].first;
		vi = v[i - 1].second;
		for (j = 0; j <= t; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j >= rt) dp[i][j] = max(dp[i][j], dp[i - 1][j - rt] + b[vi]);
		}
	}

	int ans = 0, rmax = 0;
	for (i = n; i > 0; i--) {
		ans = max(ans, dp[i][t]);
		ans = max(ans, dp[i][t - 1] + rmax);
		rmax = max(rmax, b[v[i - 1].second]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35584
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = np.zeros(n + 1, np.int64)
    ba = np.zeros(m + 1, np.int64)
    aa[1:] = a.cumsum()
    ba[1:] = b.cumsum()
    aa = aa[aa <= k]
    ba = ba[ba <= k]
    rs = np.searchsorted(ba, k - aa, side='right') - 1
    rs += np.arange(len(aa))
    r = rs.max()
    print(r)

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
// #define MOD 1000000007
#define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<ll> dx8 = {-1, -1, -1,  0, 0,  1, 1, 1};
vector<ll> dy8 = {-1,  0,  1, -1, 1, -1, 0, 1};

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



int main()
{
	ll N, L;
	cin >> N >> L;

	vector<ll> A(N);
	REP(i, N) cin >> A[i];
	vector<ll> ans;
	REP(i, N-1) {
		if (A[i] + A[i+1] >= L) {
			PRINT("Possible");
			ans.push_back(i+1);
			REPR(j, i) {
				ans.push_back(j+1);
			}
			FOR(j, i+1, N-1) {
				ans.push_back(j+1);
			}
			REPR(i, N-1) {
				PRINT(ans[i]);
			}
			return 0;
		}
	}
	PRINT("Impossible");
	return 0;
}


Measured memory_bytes: 2548
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    vector<int> b(n-1,0);
    rep(i,n-1){
        cin>>b[i];
    }
    ans+=b[0]+b.back();
    rep(i,n-2) ans+=min(b[i],b[i+1]);
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
//BackandForth.cpp (C)
#include <iostream>
#include <string>
using namespace std;

void Da(int x, int y);
void Db(int x, int y);

int main(){
  int sx,sy,tx,ty,X,Y;
  cin >> sx >> sy >> tx >> ty;
  X = tx - sx;
  Y = ty - sy;
  Da(X,Y);
  Db(X,Y);
  if(Y >= 0) printf("D"), Da(X+1,Y+1);
  else printf("U"), Da(X+1,Y+1);
  if(X >= 0) printf("L");
  else printf("R");

  if(Y >= 0) printf("U"), Db(X+1,Y+1);
  else printf("D"), Db(X+1,Y+1);
  if(X >= 0) printf("R");
  else printf("L");  

}

void Da(int X, int Y){
  if(X >= 0) for(int i = 0; i < X; i++) printf("R");
  else for(int i = 0; i > X; i--) printf("L");
  if(Y >= 0) for(int i = 0; i < Y; i++) printf("U");
  else for(int i = 0; i > Y; i--) printf("D");
}
void Db(int X, int Y){
  if(X >= 0) for(int i = 0; i < X; i++) printf("L");
  else for(int i = 0; i > X; i--) printf("R");
  if(Y >= 0) for(int i = 0; i < Y; i++) printf("D");
  else for(int i = 0; i > Y; i--) printf("U");
}


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

using namespace std;

#define int long long

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

#ifdef DBG
#define log(item) cout << #item << " " << item << endl
#define loga(array, val) cout << #array << #val << " " << array[val] << endl
#else
#define log(item)
#define loga(array, val)
#endif

typedef vector<int> VI;
typedef pair<int, int> PII;

//-------------------

int r, D, x;

signed main(){
    cin >> r >> D >> x;

    for(int i = 0; i < 10; i++){
        x = x * r - D;
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
h,w = map(int,input().split())
A = [input() for _ in range(h)]
s = []
for a in A:
    for c in a:
        s.append(c)
c = Counter(s)
if h==1 and w==1:
    print('Yes')
else:
    x,y,z = 0,0,0
    for v in c.values():
        if v%4==0:
            x += 1
        elif v%4==2:
            y += 1
        else:
            z += 1
    if h%2==0 and w%2==0:
        print('Yes' if (y==0 and z==0) else 'No')
    elif h%2==0 or w%2==0:
        if z!=0:
            print('No')
        else:
            if h%2==0 and y<=h//2:
                print('Yes')
            elif w%2==0 and y<=w//2:
                print('Yes')
            else:
                print('No')
    else:
        if z!=1:
            print('No')
        else:
            if y<=(h-1)//2 + (w-1)//2:
                print('Yes')
            else:
                print('No')

Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(18), maxn(1 << 17), Mod(1e9 + 7);
inline void Add(int &x, int y) { x = (x + y) % Mod; }
int bin[N], fac[maxn], inv[maxn], n, m, ans, f[N][maxn], cnt[maxn], A[N];
inline int C(int n, int m) { return n < m ? 0 : 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod; }
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int main()
{
	n = read(), m = read(), cnt[0] = bin[0] = fac[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) bin[i] = bin[i - 1] << 1;
	for (int i = 1; i <= bin[n]; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[bin[n]] = fastpow(fac[bin[n]], Mod - 2);
	for (int i = bin[n] - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	for (int i = 1; i <= bin[n]; i++) cnt[i] = (i & 1) ? Mod - cnt[i >> 1] : cnt[i >> 1];
	for (int i = 1; i <= m; i++) A[i] = read(); std::sort(A + 1, A + m + 1);
	f[m + 1][0] = 1;
	for (int i = m; i; i--) for (int S = 0; S < bin[n]; S++) if (f[i + 1][S])
	{
		Add(f[i][S], f[i + 1][S]); int t = (bin[n] - 1) ^ S;
		for (int j = 0; j < n; j++) if (!(S & bin[j]))
			Add(f[i][S | bin[j]], 1ll * C(t - A[i] + 1, bin[j] - 1) *
					f[i + 1][S] % Mod * fac[bin[j]] % Mod);
	}
	for (int i = 0; i < bin[n]; i++)
		Add(ans, 1ll * f[1][i] * fac[bin[n] - 1 - i] % Mod * cnt[i] % Mod);
	ans = 1ll * ans * bin[n] % Mod; printf("%d\n", ans);
	return 0;
}
//fdsffffdsfgsg

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define INF 1<<30
#define MAX_V 10010

// graph by adjacency list
struct Edge {
  int dst, weight;
  Edge(int dst, int weight) :
    dst(dst), weight(weight) { }
  bool operator < (const Edge &e) const {
    return weight > e.weight; // reverse
  }
};

struct Graph {
  int V;
  std::vector<Edge> E[MAX_V];

  Graph(int V) : V(V) { }

  void add_edge(int src, int dst, int weight) {
    E[src].push_back(Edge(dst, weight));
  }
};

struct Node {
  int v, dist;
  Node(int v, int dist) :
    v(v), dist(dist) { };
  bool operator < (const Node &n) const {
    return dist > n.dist; // reverse
  }
};

struct MinimumSpanningTree {
  Graph g;
  std::vector<Node> mst;
  int mincost;

  MinimumSpanningTree(const Graph &g) : g(g) { }

  int find_mincost() {
    mincost = 0;

    bool used[MAX_V];
    std::fill(used, used + g.V, false);

    std::priority_queue<Node> que;
    que.push(Node(0, 0));

    while (!que.empty()) {
      Node n = que.top(); que.pop();
      int v = n.v, cost = n.dist;
      if (used[v]) continue;
      mst.push_back(n);
      used[v] = true;
      mincost += cost;
      for (Edge e : g.E[v]) {
	if (!used[e.dst]) que.push(Node(e.dst, e.weight));
      }
    }
    return mincost;
  }
};
  
int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  Graph g(V);
  REP(i, E) {
    int src, dst, weight;
    cin >> src >> dst >> weight;
    g.add_edge(src, dst, weight);
    g.add_edge(dst, src, weight);
  }

  MinimumSpanningTree mst(g);
  cout << mst.find_mincost() << endl;
  return 0;
}

Measured memory_bytes: 6672
// 解き直し.
// https://img.atcoder.jp/soundhound2018-summer-qual/editorial.pdf
#include <bits/stdc++.h>
using namespace std;

int main(){
    
    // 1. 入力情報.
    double n, m, d;
    scanf("%lf %lf %lf", &n, &m, &d);
    
    // 2. 出力.
    if(d == 0) printf("%.10lf", (m - 1.0) * 1.0 / n);
    else       printf("%.10lf", (m - 1.0) * 2.0 * (n - d) / n / n);
    return 0;
    
}

Measured memory_bytes: 3808
a=[int(input())]
def f(n):
  if n%2==1:
    return 3*n+1
  else:
    return n//2
for i in range(1,1000000):
  tmp=f(a[i-1])
  if tmp in a:
    print(i+1)
    exit()
  else:
    a.append(tmp)

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

int main() {
    int N, M, X;
    std::cin >> N >> M >> X; 

    int C[N+1] = {0};
    int A;
    for (int i = 0; i < M; ++i) {
        std::cin >> A;
        C[A] = 1;
    }

    int cost1 = 0;
    for (int i = X; i <= N; ++i) {
        cost1 += C[i];
    }

    int cost2 = 0;
    for (int i = X; i >= 0; --i) {
        cost2 += C[i];
    }

    std::cout << std::min(cost1, cost2) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <set>

using namespace std;

const int N=300005;

int h,w,n;
int row[N],col[N];
set<pair<int,int>> v;
vector<int> hr,hc;

int main()
{
    scanf("%d %d %d",&h,&w,&n);
    for(int i=1,x,y;i<=n;i++)
    {
        scanf("%d %d",&x,&y);
        row[x]++,col[y]++;
        v.insert(make_pair(x,y));
    }
    int pr=0,pc=0,res;
    for(int i=1;i<=h;i++)
        if(row[i]>row[pr])
            pr=i,hr.clear(),hr.push_back(i);
        else if(row[i]==row[pr])
            hr.push_back(i);
    for(int i=1;i<=w;i++)
        if(col[i]>col[pc])
            pc=i,hc.clear(),hc.push_back(i);
        else if(col[i]==col[pc])
            hc.push_back(i);
    res=row[pr]+col[pc]-1;
    bool f=true;
    for(int i:hr)
    {
        for(int j:hc)
            if(!v.count(make_pair(i,j)))
            {
                res++;
                f=false;
                break;
            }
        if(!f)break;
    }
    printf("%d\n",res<0?0:res);
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int n;
vector<int> a(100005);
vector<int> dp(100005, -1);

int solve(int start)
{
	if (start == n - 1)
		return 0;
	if (dp[start] != -1)
		return dp[start];

	int op1 = abs(a[start] - a[start + 1]) + solve(start + 1);
	int op2 = (start + 2 >= n) ? INT_MAX : abs(a[start] - a[start + 2]) + solve(start + 2);

	return dp[start] = min(op1, op2);
}

int32_t main()
{
	FIO();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	cout << solve(0) << '\n';

	return 0;
}

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

static const int INF = 1e9+7;

int main(){
    while(1){
        int h,w;
        cin>>h>>w;
        if(h == 0 && w == 0) break;
        int cmp = h*h+w*w;        
        int memo,wmemo,hmemo;
        memo = wmemo = hmemo = INF;

        for(int H=1; H<=150; H++){
            for(int W=H+1; W<=150; W++){
                int tmp = H*H+W*W;
                if(tmp > cmp || ((tmp == cmp) && (H > h))){
                    if(tmp < memo || ((tmp == memo) && (H < hmemo) )){
                        memo = tmp;
                        hmemo = H;
                        wmemo = W;
                    }
                    break;
                }
            }
        }

        cout<<hmemo<<" "<<wmemo<<endl;
    }

    return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string ch;
	getline(cin,ch);
	int i;
	for(i=0;i<ch.size();i++){
		if('A'<=ch[i]&&ch[i]<='Z'){
			ch[i]=ch[i]+('a'-'A');
			cout<<ch[i];
		}
		else if('a'<=ch[i]&&ch[i]<='z'){
			ch[i]=ch[i]-('a'-'A');
			cout<<ch[i];
		}
		else{
			cout<<ch[i];
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3232
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
ll a[maxi];

void dfs(int x, int pred) {
  //ここに処理をかく
  a[x] += a[pred];

  for(int i:v[x]) {
    if(i != pred) dfs(i,x);
  }
}

int main () {
  int q;
  cin >> n >> q;
  for(int i=1; i<n; i++) {
    int x,y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  while(q--) {
    int x,y;
    cin >> x >> y;
    a[x]+=y;
  }

  dfs(1,0);

  for(int i=1; i<=n; i++) cout << a[i] << " ";
  printf("\n");
}


Measured memory_bytes: 44672
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	odd := 0
	four := 0
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		if tmp%2 != 0 {
			odd++
		}
		if tmp%4 == 0 {
			four++
		}
	}
	var res bool
	switch {
	case odd == four+1 && odd+four == n:
		res = true
	case odd > four:
		res = false
	case odd <= four:
		res = true
	}
	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def k(a):
    print('----------------')
    c = 0
    n = len(a)
    while max(a) >= n:
        a[a.index(max(a))] -= n + 1
        for i in range(n):
            a[i] += 1
        c += 1
        # print(a)
    return c


@mt
def slv(K):
    n = 50
    m = K % n
    l = K // 50

    a = [n + l] * n

    # print(n, m, l, a)
    for i in range(n):
        if i < m:
            a[i] += n - m
        else:
            a[i] -= m + 1

    print(n)
    print(' '.join(map(str, a)))
    # print(k(a))


def main():
    K = read_int()
    slv(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5712
/// a.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int s[1 << 20];
    int n,k;
    fi>>n>>k;
    int ans = 0;
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    s[n + 1] = 2e9 + 55;
    for (int i = 2;i <= n + 1;++i)
        if (s[i] - s[i - 1] >= k)
            ans += k;
        else
            ans += s[i] - s[i - 1];
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
	int top[10];
	char temp;
	while (cin>>temp) {
		top[0] = temp - '0';
		for (int i=1; i<10; i++) {
			cin>>temp;
			top[i] = temp - '0';
		}
		for (int i=10; i>0; i--) {
			for (int j=0; j+1<i; j++) {
				top[j] = (top[j] + top[j+1]) % 10;
			}
		}
		cout<<top[0]<<endl;
	}
}

Measured memory_bytes: 0
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


#O(nlogn)
def f(x):
    cnt = 0
    for i in a:
        idx = bl(a,x-i)
        cnt += n - idx
        if cnt >= m:
            return True
    return False

n,m = LI()
a = LI()
a.sort()
ng,ok = 2*max(a)+1,2
#O(log(max(a)))
while ng - ok > 1:
    mid = (ng+ok) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid

ans = 0
tmp = 0
b = [0] + list(accumulate(a))
#O(nlogn)
for i in a:
    idx = bl(a,ok-i)
    # i*(n-idx) := 左手で握手する人の幸福度(i)*左手で握手する回数(n-idx)
    # (b[-1] - b[idx]) := 右手で握手する人の幸福度の総和
    ans += i*(n - idx) + (b[-1] - b[idx])
    # tmp := 左手で握手する人を決めたときの右手で握手した人の数の総和 = ペアの総数
    tmp += n - idx

# ペアの数がm以上なら答えからペアの数がmになるよう最小のペアの幸福度(ok)を引く
ans = ans - (tmp - m)*ok
print(ans)


Measured memory_bytes: 60816
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

int N;
int Q,K;

struct edge{
  int to,cost;
  edge(int to,int cost){
    this->to=to;
    this->cost=cost;
  }
};
typedef pair<int,int> P;

vector<edge> G[100010];
int d[100010];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+N,INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v= p.second;
    if(d[v]<p.first)continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}
signed main(){
  cin>>N;
  rep(i,N-1){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].push_back(edge(b,c));
    G[b].push_back(edge(a,c));

  }
  cin>>Q>>K;
  K--;
  dijkstra(K);
  rep(i,Q){
    int x,y;
    cin>>x>>y;
    x--;y--;
    int ans=0;
    ans+=d[x];
  //  cout<<ans<<endl;
    ans+=d[y];
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a,b;
int p[5005];
ll dp[5005][5005];

int main(void){
    scanf("%d%lld%lld",&n,&a,&b);
    for(int i=0;i<n;i++) {
        scanf("%d", &p[i]);
        p[i]--;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            if(j>p[i]){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+b);
            }
            if(j==p[i]){
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
            }
            if(j<p[i]){
                dp[i+1][p[i]+1]=min(dp[i+1][p[i]+1],dp[i][j]);
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+a);
            }
        }
    }
    ll ans=INF;
    for(int i=0;i<=n;i++){
        ans=min(dp[n][i],ans);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n, d; cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    rep(i,n)rep(j,d) cin >> x[i][j];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int dist2 = 0;
            for(int k = 0; k < d; k++){
                dist2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for(int l = 1; l <= dist2; l++){
                if(l*l == dist2) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256