akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private static int[] dx = { 0, 1, 0, -1 };
    private static int[] dy = { 1, 0, -1, 0 };
    public static void Main()
    {
        int H = NextInt();
        int W = NextInt();
       // H = W = 50;
        char[,] map = new char[H, W];
        Node[,] node = new Node[H, W];
        int WhiteCount = 0;
        for (int i = 0; i < H; i++)
        {
            char[] line = NextString().ToCharArray();
            //line = Enumerable.Repeat('.',50).ToArray();
            for (int j = 0; j < W; j++)
            {
                if (line[j] == '.') WhiteCount++;
                map[i, j] = line[j];
                node[i, j] = new Node();
            }
        }
        Queue<int[]> pos = new Queue<int[]>();
        pos.Enqueue(new int[2] { 0, 0 });
        node[0, 0].count = 1;
        while (pos.Count() != 0)
        {
            var p = pos.Dequeue();
            if (node[p[0], p[1]].visit) continue;
            node[p[0], p[1]].visit = true;
            for (int i = 0; i < 4; i++)
            {
                int xx = p[1] + dx[i];
                int yy = p[0] + dy[i];
                if (yy < 0 || H <= yy || xx < 0 || W <= xx || node[yy, xx].visit || map[yy, xx] == '#') continue;
                node[yy, xx].count = node[p[0], p[1]].count + 1;
                pos.Enqueue(new int[2] { yy, xx });
            }
            if (p[0] == H - 1 && p[1] == W - 1) break;
        }
        if (node[H - 1, W - 1].visit) { Console.WriteLine(WhiteCount - node[H - 1, W - 1].count); }
        else Console.WriteLine(-1);
    }
}

public class Node
{
    public bool visit = false;
    public int count = 0;
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13396
console.log((args=>{
  const [[N],b] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  const a = [];
  let n = N;
  while( n ) {
    for ( let i = n-1; i >= 0; i-- ) {
      if ( b[i] !== i+1 ) continue;
      a.push( b[i] );
      b.splice(i,1);
      break;
    }
    if ( n > b.length ) n--;
    else return '-1';
  }
  return a.reverse().join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 29436
def dfs(i, sum, count, rest):
    global ans
    if i == d:
        if sum < g:
            rest_max = max(rest)
            n = min(l[rest_max-1][0], -(-(g-sum)//(rest_max*100)))
            count += n
            sum += n * rest_max * 100
        if sum >= g:
            ans = min(ans, count)
    else :
        dfs(i+1, sum, count, rest) #二分岐のうち解かない選択
        dfs(i+1, sum + l[i][0]*(i+1)*100+l[i][1], count + l[i][0], rest - {i+1}) #解く選択

d, g = map(int, input().split())
l = [list((map(int, input().split()))) for _ in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d+1)))
print(ans)


Measured memory_bytes: 9140
import sys
sys.setrecursionlimit(10**4)

n, k = map(int, input().split())
stirling = [[-1 for _ in range(k+1)] for _ in range(n+1)]

MOD = 10**9 + 7

def rec(nn, kk):
    if nn < kk:
        return 0
    if kk == 1 or kk == nn:
        return 1
    if stirling[nn][kk] == -1:
        stirling[nn][kk] = (kk * rec(nn-1, kk) + rec(nn-1, kk-1)) % MOD
    return stirling[nn][kk]

print(rec(n, k))


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N, X, T;
    cin >> N >> X >> T;

    cout << ((N-1) / X + 1) * T << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3648
N = int(input())
S = input()
EE = S.count("E")
WE = S.count("W")
EW = 0
WW = 0
ans = N

for i in range(N):
  if S[i] == "W":
    ans = min(ans,EE+WW)
    WE -= 1
    WW += 1
  else:
    ans = min(ans,EE+WW-1)
    EE -= 1
    WE += 1
print(ans)

Measured memory_bytes: 69188
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919810893ll;
const int mod=1000000007ll;
const int hoge=1000000000ll;
const double pi=3.14159265358979324;
const int dd[]={0,-1,0,1,0};
using namespace std;
int n,m,h,w;
int p[26];
signed main(){
	int i,j,k;
	string s;
	cin>>s;
	int ans=1;
	for(auto x:s){
		for(i=0;i<26;i++)
			if(i!=x-'a')
				ans+=p[i];
		p[x-'a']++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(T) priority_queue<T>
#define heap(T) priority_queue<T,vector<T>,greater<T> > 
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define error(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	x=rev?-x:x;
	return 1;
}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,cnt[10];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		if(x%4==0) cnt[2]++;
		else if(x%2==0) cnt[1]++;
		else cnt[0]++;
	}
	if(cnt[0]==cnt[2]+1&&!cnt[1]){puts("Yes");return 0;}
	if(cnt[0]>cnt[2]){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;

int sosuu(int n);

int main(){
    int w=0;
    scanf("%d",&w);
    
    int n=0;
    scanf("%d",&n);
    
    int DL[w+1];
    for(int i=1; i<=w; i++){
        DL[i]=i;
    }
    
    for(int i=0; i<n; i++){
        int a,b;
        char c;
        scanf("%d%c%d",&a,&c,&b);
        int temp;
        temp=DL[a];
        DL[a]=DL[b];
        DL[b]=temp;
    }
    
    for(int i=1; i<=w; i++){
        printf("%d\n",DL[i]);

    }
    
}

Measured memory_bytes: 1188
# エラトステネスの篩
#############################################################
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
#############################################################


primes = set(get_sieve_of_eratosthenes(10**5))

cumsum = [0]
for i in range(1, 10**5 + 1):
    if i % 2 == 1 and i in primes and (i + 1) // 2 in primes:
        cumsum.append(cumsum[-1] + 1)
    else:
        cumsum.append(cumsum[-1])

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    ans = cumsum[r] - cumsum[l - 1]
    print(ans)


Measured memory_bytes: 12708
#include <stdio.h>
 
int main(){
    int n,s[1024]={0};
        int max,min,max1,min1;
        int sum,i;
 
scanf("%d\n",&n);
 
do {
        max=0;
        min=100000;
        sum=0;
        sum=0;
    max1=0;
    min1=0;
        for (i=0;i<n;i++){
                scanf("%d\n",&s[i]);
                if(s[i]>max){
            max=s[i];
                        max1=i;
                }
                if(s[i]<min){
                        min=s[i];
            min1=i;
                }
        }
        for(i=0;i<n;i++){
                if(i!=max1&&i!=min1){
                        sum+=s[i];
                }
        }
        printf("%d\n",sum/(n-2));
        scanf("%d\n",&n);
}while (n!=0);
return 0;
}

Measured memory_bytes: 1032
#include<iostream>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int ans=1,n,m;
char map[30][30];

void d(int x,int y){
  if(x==m||y==n||x<0||y<0)return;
  if(map[x][y]=='.')ans++;
  if(map[x][y]=='#')return;
  map[x][y]='#';
  d(x+1,y),d(x-1,y),d(x,y+1),d(x,y-1);
}

int main(){
  while(cin>>n>>m,n){
  int x,y;
  ans=1;
  r(i,m)r(j,n){
    cin>>map[i][j];
    if(map[i][j]=='@')x=i,y=j;
  }
  d(x,y);
  cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3000
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ
　　 　 /　　　 　 |　見ちゃだめだよ！
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<pair<int, int>> pairs(n);
  rep(i, n) {
    int t1, t2;
    cin >> t1 >> t2;
    pairs[i] = make_pair(t1, t2);
  }
  SORT(pairs);
  rep(i, n) {
    k -= pairs[i].second;
    if (k <= 0) {
      cout << pairs[i].first << endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main( void )
{
	int map[4];
	bool used[10];
	while(1) {
		bool eof = false;
		for(int i=0; i < 10; ++i) used[i] = false;
		for(int i=0; i < 4; ++i) {
			if(cin >> map[i]) {
				used[map[i]] = true;
			}
			else	{ eof = true; break; }
		}
		if(eof) break;
		int hit, br;
		hit = br = 0;
		for(int i=0; i < 4; ++i) {
			int inNum;
			cin >> inNum;
			if		(map[i] == inNum) ++hit;
			else if	(used[inNum]) ++br;
		}
		cout << hit << ' ' << br << endl;
	}
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<Int> a(n);
    map<Int, Int> mp;
    map<Int, Int> sum;
    rep(i, n) {
         cin >> a[i];
         mp[a[i]]++;
    }
    Int sum_all = 0;
    for (auto m : mp) {
        sum[m.first] = (m.second * (m.second-1))/2;
        sum_all += (m.second * (m.second-1))/2;
    }
    rep(i, n) {
        Int before = sum[a[i]];
        Int after = (mp[a[i]]-1) * (mp[a[i]] -2) /2 ;
        cout << sum_all - (before - after) << endl;
    }

}

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

long long integer(string s) {
	int rtn = 0, d = 1;
	for (int i = 0; i < s.length(); i++) {
		rtn += (s[s.length() - i - 1] - '0') * d;
		d *= 10;
	}
	return rtn;
}

int main() {
	string s;
	cin >> s;
	long long n = integer(s),sum;
	for(int i=0;i<s.length();i++){
		sum+=s[i]-'0';
	}
	if(n%sum==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import os
import sys
import math
import numpy as np


def func(n):
    return int(n * (n+1) / 2)

def main():
    a, b = list(map(int, input().split()))
    left = func(b-a-1)
    print(left - a)



if __name__ == '__main__':
    main()


Measured memory_bytes: 13640
#include <iostream>
#include <iostream>

using namespace std;

struct op
{
	char s; int v;
};

int t[100010];
int f[100010];
int p[100010];
op r[100010];
int n, q, v;
long long o = 0;
op x;

int query(int x)
{
	int i;
	for (i = 0;; i++)
	{
		f[i] = x;
		if (t[x] == x)
		{
			break;
		}
		x = t[x];
	}
	for (int j = i; j >= 0; j--)
	{
		t[f[j]] = x;
	}
	return x;
}

void mark(int x)
{
    p[x]=t[x];
	t[x] = x;
}

int main()
{
	ios::sync_with_stdio(false);
	t[0] = 0;
	while (1)
	{
		cin >> n >> q;
		if (n == 0)
		{
			break;
		}
		for (int i = 1; i<n; i++)
		{
			cin >> v;
			t[i] = v - 1;
		}
		int i;
		for (i = 0; i<q; i++)
		{
			cin >> x.s >> x.v;
			if (x.s == 'Q')
			{
				r[i] = x;
			}
			else
			{
				v = x.v - 1;
				if (t[v] == v) 
				{
					i-=1;
					q -= 1;
					continue;
				}
				mark(v);
				r[i] = x;
			}
		}
		for (int j = i-1; j >= 0; j--)
		{
			v = r[j].v - 1;
			if (r[j].s == 'M')
			{
				t[v] = p[v];
			}
			else
			{
				o += query(v);
				o += 1;
			}
		}
		cout << o << endl;
		o = 0;
	}
	return 0;
}


Measured memory_bytes: 4548
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
//constant
//------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;






#define SIZEOF(x) sizeof(x)/sizeof(x[0])




template <class T>
T max(T *a , LL n){
    T maxi = a[0];
    for(LL i = 0; i < n; ++i){
        if(a[i] > maxi)maxi = a[i];
    }
    return maxi;
}

template <class T>
T maxfrag(T *a , LL n){
    T maxi = a[0];
    T frag = 0;
    for(LL i = 0; i < n; ++i){
        if(a[i] > maxi){
            maxi = a[i];
            frag = i;
        }
    }
    return frag;
}


template <class T>
T min(T *a , LL n){
    T mini = a[0];
    for(LL i = 0; i < n; ++i){
        if(a[i] < mini)mini = a[i];
    }
    return mini;
}

template <class T>
T minfrag(T *a , LL n){
    T mini = a[0];
    T frag = 0;
    for(LL i = 0; i < n; ++i){
        if(a[i] < mini){
            mini = a[i];
            frag = i;
        }
    }
    return frag;
}


template <class T>
T sum(T *a , LL n){
    T s=0;
    for(LL i = 0; i < n; ++i){
       s+=a[i]; 
    }
    return s;
}

#define MAX(x) max(x,SIZEOF(x))
#define MIN(x) min(x,SIZEOF(x))
#define SUM(x) sum(x,SIZEOF(x))



int main(){

    LL a,b;
    cin >> a >> b;
    if((a+b)%2 == 1){
        cout << "IMPOSSIBLE";
    }else{
        cout << (a+b)/2;
    }

    
    return 0;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <iostream>
using namespace std;
const int INF = 2000000000;
int dp[101][10001];
int main() {
	int n, W;
	cin >> n >> W;
	int v[100], w[100];
	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];
	fill(dp[0], dp[n], -1);
	fill(dp[0], dp[1], 0);
	for(int i = 1; i <= n; i++)
		for (int j = 0; j <= W; j++) {
			if (j < w[i - 1]) dp[i][j] = dp[i - 1][j]; //cout << "fe " << dp[i - 1][j] << " "; }
			else dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i - 1][j]);
			//cout << "i " << i << " j " << j << "  " << dp[i][j] << endl;
		}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include <cmath>
#include <limits>
using namespace std;
long pow2(int x){
  return (x*x);
}
int main(){
  int N;
  cin>>N;
  int cnt=0;
  double rootN = sqrt(N);
  for(int i=1;i<=N;i++){
    cnt=0;
    if(i<6 || i==7){
      cout<<0<<endl;
      continue;
    }
    if(i==6){
      cout<<1<<endl;
      continue;
    }
    for(int x=1;x<rootN;x++){
      for(int y=1;y<=x;y++){
        for(int z=1;z<=y;z++){
          if(pow2(x+y)+pow2(y+z)+pow2(z+x)==2*i){
            if(x==y && y==z){
              cnt++;
            }else if(x==y && y>z){
              cnt+=3;
            }else if(x>y && y==z){
              cnt+=3;
            }else if(x>y && y>z){
              cnt+=6;
            }
          }
        }
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

int main(){
  ll n, d;
  cin >> n >> d;
  ll ans = 0;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    if(x * x + y * y <= d * d) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE
Int n;
vector<Int> A;
Int X;

Int add(map<Int,Int> &num, Int idx){
  num[idx] = num[idx]+1;
  while(idx > 1 && num[idx] >= X){
    if(X == 1) return 0;
    num[idx] = 0;
    num[idx - 1] = num[idx - 1] + 1;
    idx--;
  }
  if(num[1] >= X) return 0;
  return 1;
}

void shiftRight(map<Int,Int> &num, Int idx){
  while(1){
    auto it = num.upper_bound(idx);
    if(it == num.end()) break;
    num.erase(it);
  }
}

Int dfs(Int idx, map<Int,Int> &num, Int len){
  //prArr(num);
  if(idx == n) return 1;
  if(len < A[idx])return dfs(idx + 1, num, A[idx]);
  if(len == A[idx]){
    if(add(num, A[idx]) == 0) return 0;
    return dfs(idx + 1, num, A[idx]);
  }
  if(len > A[idx]){
    shiftRight(num, A[idx]);
    if(add(num, A[idx]) == 0) return 0;
    return dfs(idx + 1, num, A[idx]);
  }
  assert(0);
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  cin>>n;
  A.resize(n);
  cin>>A;
  /*
    X = 2;
    map<Int,Int> num;
    int res = dfs(0, num, 0);
    pr(res);
    return 0;
  */

  Int L = 0, R = 1e6;
  while(L + 1 < R){
    Int M = (L+R)/2;
    X = M;
    map<Int,Int> num;
    Int y = dfs(0, num, 0);
    if(y == 0) L = M;
    else R = M;
  }
  Int ans = R;
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1792
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    ans = 0
    while N:
        ans += 1
        N//=K
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 66540
/***********************************************************************************
*           Falling down is an accident, Staying down is a choice.                 *
***********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define _USE_MATH_DEFINES
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;
void solve();int main(){ios;solve();return 0;}
/***********************************************************************************/
void solve()
{
	int n;cin>>n;
	int a,b;cin>>a>>b;
	cout<<min(n*a,b)<<endl;		
}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

N, M, S, T = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y, a, b = map(int, input().split())
    edge[x].append((y, a, b))
    edge[y].append((x, a, b))


def dijkstra(start, currency):
    # currency=0 -> yen, 1 -> snuuk
    dist = [inf] * (N + 1)
    dist[start] = 0
    que = [(0, start)]
    while que:
        c, s = heapq.heappop(que)
        if dist[s] < c:
            continue
        for t, *cost in edge[s]:
            cost = cost[currency]
            if dist[t] > dist[s] + cost:
                dist[t] = dist[s] + cost
                heapq.heappush(que, (dist[t], t))
    return dist


s_to_i_yen = dijkstra(S, 0)
t_to_i_snu = dijkstra(T, 1)
need = [(x + y, i) for i, (x, y) in enumerate(zip(s_to_i_yen, t_to_i_snu))]
need.sort(reverse=True)

money = 10 ** 15
for y in range(N):
    while need[-1][1] <= y:
        need.pop()
    print(money-need[-1][0])

Measured memory_bytes: 67296
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,ans=0;
string s[2010];
pii num[2010][2010];

int main()
{
	cin>>n>>m;
	rep(i,n) cin>>s[i];
	rep(i,n)
	{
		int j=0,tmp;
		while(j<m)
		{
			if(s[i][j]=='#')
			{
				j++;
				continue;
			}
			tmp=j;
			while(s[i][j]=='.'&&j<m) j++;
			for(int k=tmp;k<j;k++) num[i][k].fi=j-tmp;
		}
	}
	rep(i,m)
	{
		int j=0,tmp;
		while(j<n)
		{
			if(s[j][i]=='#')
			{
				j++;
				continue;
			}
			tmp=j;
			while(s[j][i]=='.'&&j<n) j++;
			for(int k=tmp;k<j;k++) num[k][i].se=j-tmp;
		}
	}
	rep(i,n) rep(j,m) if(s[i][j]=='.') ans=max(ans,num[i][j].fi+num[i][j].se-1);
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 35712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int[] ans = new int[N];
            for (int i = 0; i < N; i++) {
                if (i % 2 == 0) {
                    ans[0] += A[i];
                } else {
                    ans[0] -= A[i];
                }
            }
            A[0] -= ans[0] / 2;
            A[N - 1] -= ans[0] / 2;
            for (int i = 1; i < N; i++) {
                ans[i] = A[i - 1] * 2;
                A[i] -= A[i - 1];
            }

            StringBuilder sb = new StringBuilder();
            for (int v : ans) {
                sb.append(v).append(' ');
            }
            out.println(sb.substring(0, sb.length() - 1));
        }

    }
}



Measured memory_bytes: 54548
#include <iostream>
using namespace std;
    
int main() {
  int n, b, f, r, v, A[4][3][10];
  for (int i = 0; i < 4 ; i++) {
    for (int j = 0; j < 3 ; j++) {
      for (int k = 0; k < 10 ; k++) { A[i][j][k]=0; }
    }
  }
    
    
  cin >> n;
  for (int i = 0; i < n ; i++){
    cin >> b >> f >> r >> v;
    A[b-1][f-1][r-1] += v;
  }
    
  for (int i = 0; i < 4 ; i++) {
    for (int j = 0; j < 3 ; j++) {
      for (int k = 0; k < 10 ; k++) { 
        cout << " " << A[i][j][k] ;
        if (k==9) { cout << endl;}
      }
    }
    if (i!=3) {cout << "####################" << endl ;}
  }
  return 0;
}


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

int main(void) {
  int X, Y;
  cin >> X >> Y;
  bool flag = false;
  for (int i = 0; i <= X; i++) {
    if (2 * i + 4 * (X - i) == Y) {
      flag = true;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main() {
 int A, B, C, D, L, i, R, cnt = 0;
 scanf( "%d", &L );
 scanf( "%d", &A );
 scanf( "%d", &B );
 scanf( "%d", &C );
 scanf( "%d", &D );
 for( ;; ) {
   A -= C;
   B -= D;
   cnt++;
   if( A <= 0 && B <= 0 ) break;
 }
 R = L - cnt;
 printf( "%d\n", R );
 return 0;
}

Measured memory_bytes: 1024
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let k: u32 = sc.read();
    let mut ans = Vec::<u64>::new();

    for i in 1..10 {
        dfs(&mut ans, i);
    }
    ans.sort();

    println!("{}", ans[k as usize - 1]);
}

fn dfs(ans: &mut Vec<u64>, n: u64) {
    if n > 3234566667 {
        return;
    }

    ans.push(n);
    let c = n % 10;

    if c > 0 {
        dfs(ans, n * 10 + c - 1);
    }
    dfs(ans, n * 10 + c);
    if c < 9 {
        dfs(ans, n * 10 + c + 1);
    }
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

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

    int n; cin >> n;
    vector<P> a(n);
    rep(i, n) {
        int x, y; cin >> x >> y;
        a[i] = P(x-y, x+y);
    }
    sort(all(a), [](P &a, P &b) { return a.se<b.se ;});
    rep(i, n) debug(a[i].fi, a[i].se);

    int cur = a[0].se;
    int ans = 1;
    FOR(i, 1, n) {
        P p = a[i];
        if (cur<=p.fi) {
            ans++;
            cur = p.se;
        }
        debug(i, cur, ans);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
def solve():
  N = int(input())
  SP = [[i for i in input().split()] for s in range(N)]
  name = []
  dictionary = {}
  for i in range(N):
    S, P = SP[i]
    if S not in dictionary:
      dictionary[S] = []
      name.append(S)
    dictionary[S].append([i + 1, int(P)])
  name.sort()
  for n in name:
    d = sorted(dictionary[n], key=lambda x: x[1], reverse=True)
    for _d in d:
      print(_d[0])

solve()


Measured memory_bytes: 3064
#include<stdio.h>
 
int main()
{
  int A[100];
  int N;
  int key;
  int i, j, k;
 
  //Read N and keys
  scanf("%d ", &N);
  for(i=0; i<N; i++)scanf("%d ",&A[i]);
 
  //Sort
  for(i=0; i<N; i++){
    key=A[i];
    j=i-1;
 
      //if A[j]>key, change A[j] to A[j+1]
    while(j>=0 && A[j]>=key){
      A[j+1]=A[j];
      j=j-1;
    }
    A[j+1]=key;
 
      //print
    for(k=0; k<N; k++){
      printf("%d", A[k]);
      if(k<N-1)printf(" ");
    }
    printf("\n");
  } 
  return 0;
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
typedef unsigned long long int ull;

using namespace std;

ull LCM(ull a,ull b){
  ull tmp,r,a1,a2,x;
  a1=a,a2=b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=(a1/b)*a2;
  return x;
}

int main(void){
  int N;
  cin >> N;
  ull T[N],ans;
  rep(i,N) cin >> T[i];
  ans=T[0];
  rep(i,N) ans=LCM(ans,T[i]);
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
rlst = [None] * (n + 1)
for _ in range(n):
  lst = list(map(int, input().split()))
  r = lst[0]
  lst = lst[2:]
  rlst[r] = lst

p = int(input())

for _ in range(p):
  s, d, v = map(int, input().split())
  visited = [False] * (n + 1)
  visited[s] = True
  que = deque()
  que.append((s, 0))
  while que:
    node, dist = que.popleft()
    if node == d:
      if dist < v:
        print(dist + 1)
      else:
        print("NA")
      break
    for to in rlst[node]:
      if not visited[to]:
        que.append((to, dist + 1))
        visited[to] = True
  else:
    print("NA")


Measured memory_bytes: 6004
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii; typedef pair<pii,int> ppi; typedef pair<int,pii> pip; typedef pair<pii,pii> ppp;
typedef vector<pii> vii; typedef queue<int> qi;
#define pb push_back
const int inf = 0x3f3f3f3f;
#define fi first
#define se second
int N,M,L,Q; vii adj[301]; pii dist[301][301]; bool inq[301]; qi q;
int main() {
    scanf("%d%d%d",&N,&M,&L);
    for (int i = 0,A,B,C;i < M;i++) scanf("%d%d%d",&A,&B,&C),adj[A].pb({B,C}),adj[B].pb({A,C});
    for (int i = 1;i <= N;i++) {
        for (int j = 1;j <= N;j++) dist[i][j] = {inf,inf};
        dist[i][i] = {0,-L}; q.push(i); inq[i] = 1;
        while (!q.empty()) {
            int cur = q.front(); q.pop(); inq[cur] = 0;
            for (pii nxt : adj[cur]) {
                if (-dist[i][cur].se >= nxt.se) {
                    pii tmp = {dist[i][cur].fi,dist[i][cur].se + nxt.se};
                    if (tmp < dist[i][nxt.fi]) {
                        dist[i][nxt.fi] = tmp;
                        if (!inq[nxt.fi]) q.push(nxt.fi),inq[nxt.fi] = 1;
                    }
                }
                else if (nxt.se <= L) {
                    pii tmp = {dist[i][cur].fi+1,nxt.se-L};
                    if (tmp < dist[i][nxt.fi]) {
                        dist[i][nxt.fi] = tmp;
                        if (!inq[nxt.fi]) q.push(nxt.fi),inq[nxt.fi] = 1;
                    }
                }
            }
        }
    }
    scanf("%d",&Q);
    for (int i = 0,s,t;i < Q;i++) {
        scanf("%d%d",&s,&t);
        if (dist[s][t].fi == inf) printf("-1\n");
        else printf("%d\n",dist[s][t].fi);
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int l = 0;

  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if (x < K-x){
      l += x;
    }
    else{
      l += K-x;
    }
  }
    cout << l*2 << endl;
}
      
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s;
    int l,c=0;
    l=s.size();
    for(int i=0,j=l-1;i<l/2;i++,j--)
    {
        if(s[i]!=s[j])
        {
            c++;
        }
    }
    cout<<c<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<cmath>
#include<cctype>
#include<cstdio>
#include <algorithm>
#include <string.h>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
#include<unordered_map>

#define ull unsigned long long
using namespace std;


int a[1005];
int main(){
	int n,k,i,ans=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=k;i++)
            ans+=a[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3788
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
ans=10**9
for p in range(l,r+1):
  d=0
  for i in range(n):
    d+=(p-x[i])**2
  ans=min(ans,d)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

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

  while (T--) {
    solve();
  }
}

void solve() {
  int s, w;
  cin >> s >> w;
  if (w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n) 
#define all(a) a.begin(), (a).end()
#define inf = 9876543210
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int ax, ay, bx, by; cin>>ax>>ay>>bx>>by;
    int cx, cy, dx, dy;
    cx = ax - (by-ay);
    cy = ay + (bx-ax);
    dx = cx - (ay-cy);
    dy = cy + (ax-cx);
    cout<<dx<<" "<<dy<<" "<<cx<<" "<<cy;
return 0;
}

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

queue<int> Q;

void solve(vector<int> P, vector<int> I)
{
  int n = P.size();
  if (n != I.size())
  {
    cout << "Size Error!" << endl;
  }
  // ベースケース
  if (n == 1)
  {
    Q.push(P.at(0));
    return;
  }
  // 再帰ステップ
  int pivot_value = P.at(0);
  int index;
  for (int i = 0; i < n; i++)
  {
    if (I.at(i) == pivot_value)
    {
      index = i;
      break;
    }
  }
  vector<int> LI, RI, LP, RP;
  bool flagL = false, flagR = false;
  for (int i = 0; i < index; i++)
  {
    LI.push_back(I.at(i));
    LP.push_back(P.at(i + 1));
    flagL = true;
  }
  for (int i = index + 1; i < n; i++)
  {
    RI.push_back(I.at(i));
    RP.push_back(P.at(i));
    flagR = true;
  }
  if (flagL)
  {
    solve(LP, LI);
  }
  if (flagR)
  {
    solve(RP, RI);
  }
  Q.push(pivot_value);
  return;
}

int main()
{
  int n;
  cin >> n;
  vector<int> P(n), I(n);
  for (int i = 0; i < n; i++)
  {
    cin >> P.at(i);
  }
  for (int i = 0; i < n; i++)
  {
    cin >> I.at(i);
  }

  solve(P, I);

  for (int i = 0; i < n; i++)
  {
    cout << Q.front();
    Q.pop();
    if (i == n - 1)
    {
      cout << endl;
    }
    else
    {
      cout << " ";
    }
  }
}


Measured memory_bytes: 3200
#include <algorithm>
#include <climits>
#include <iostream>
#include <random>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  int m, n;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }

  vector<int> r(n, -1);
  for (int i = 0; i < m; ++i) {
    if (r[s[i] - 1] == -1 || r[s[i] - 1] == c[i]) {
      r[s[i] - 1] = c[i];
    } else {
      cout << -1;
      return 0;
    }
  }
  if (n != 1 && r[0] == 0) {
    cout << -1;
    return 0;
  }

  if (r[0] == -1) {
    r[0] = n == 1 ? 0 : 1;
  }
  for (int i = 1; i < n; ++i) {
    if (r[i] == -1) {
      r[i] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << r[i];
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
using namespace std;
typedef long long LL;

LL n,tot = 0;
LL a[5005];
bitset<4000005> dp;

int main(){
	cin >> n;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		tot += a[i];
	}
	dp[0] = 1;
	for(LL i = 1;i <= n;i ++) dp |= (dp << a[i]);
	for(LL i = (tot + 1) >> 1;i <= tot;i ++){
		if(dp[i]){
			cout << i << endl;
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.nextLine());
		int num =0;
		
		for(int i=1; i<=a; i++) {
			num+=i;
		}
		
		System.out.println(num);
		
	}
}


Measured memory_bytes: 21844
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a,ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  map<int,int>mp;
  rep(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  bool ok=true;
  ll ans;
  if(n%2==1){
    for(auto p:mp){
      if(p.first==0 && p.second!=1)ok=false;
      if(p.first>0 && p.first%2==1)ok=false;
      if(p.first>0 && p.second!=2)ok=false;
    }
    ans=modpow(2,n/2);
  }
  else{
    for(auto p:mp){
      if(p.first%2!=1 || p.second!=2)ok=false;
    }
    ans=modpow(2,n/2);
  }
  if(ok)cout<<ans<<endl;
  else cout << 0 << endl;
          
}

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

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 ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> v(N,false);
  for(int i = 0; i < K ; i++) {
    int d;
    cin >> d;
    for(int j = 0; j < d; j++) {
      int A;
      cin >> A;
      v[A-1] = true;
    }
  }
  int ans = 0;
  for(int i = 0;i < N; i++){
    if(!v[i])ans++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main(){
	long long a, b, k;
	scanf("%lld %lld %lld", &a, &b, &k);
	if (a >= k){
		printf("%lld %lld\n", a - k, b);
		return 0;
	}
	else {
		k -= a;
		if (b >= k){
			printf("%lld %lld\n", 0, b - k);
		}
		else {
			puts("0 0");
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X=I()
    temp=0
    for i in range(10**7):
        temp+=i
        if temp>=X:
            print(i)
            break

main()


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

signed main(){
  string A,B;
  cin>>A>>B;
  int AL=A.size(),BL=B.size();
  string ans="LESS";
  if(AL>BL||(AL==BL)&&A>B)ans="GREATER";
  if(A==B)ans="EQUAL";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll ans = -1;
  ll now = 0;
  rep(i,N){
    ll d;
    ll c;
    cin >> d >> c;
    ans += c;
    now += d*c;
    if(i==0) --now;
    ans += now/9;
    now = now%9;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-201, 200))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])


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

int main() {
  int n;
  string str;
  cin >> n >> str;
  int n1 = 0, n2 = 0;
  for (int i = 0; i < n; i++) {
    if (str.at(i) == 'R') {
      n1++;
    } else {
      n2++;
    }
  }
  if (n1 > n2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384