akhauriyash/Code-Regression huggingface dataset:
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
 
void solve()
{
  int n;
  cin >> n;
  int a[n+1],b[n+1],c[n+1];
  a[0]=b[0]=c[0]=0;
  fp(i,1,n)
    cin >> a[i] >> b[i] >> c[i];
  int dp[n+1][3];
  dp[0][0]=dp[0][1]=dp[0][2]=0;
  fp(i,1,n)
  {
      dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
      dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
  }
  cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << '\n';
  return ;
}

signed main()
{
   FAST;
	int T=1;
	// cin >> T;
	while(T--)
	{
		solve();
	}
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {
	ll sum = 0, N, M, K;
	cin >> N >> M >> K;

	vector<ll>A(N), B(M);

	rep(i, N) {
		cin >> A[i];
	}

	rep(i, M) {
		cin >> B[i];
	}

	vector<ll>tA, tB;

	tA.push_back(0);
	tB.push_back(0);

	rep(i, N) {
		tA.push_back(tA[i] + A[i]);
	}
	rep(i, M) {
		tB.push_back(tB[i] + B[i]);
	}


	ll ans =0,j = M;
	for (ll i = 0; i < N + 1; i++) {
		if (tA[i] > K) {
			break;
		}
		else {
			while (tB[j] > K - tA[i]) {
				j--;
			}
			ans = max(ans, i + j);
		}

	}


	cout << ans;

	return 0;
}

Measured memory_bytes: 11124
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int N, M, r, q;
vector<P> v[10001];
int arr[2000];

int main()
{
	while (scanf("%d %d", &N, &M), N){
		for (int i = 0; i < 10001; i++){
			v[i].clear();
		}
		scanf("%d", &r);
		for (int i = 0; i < r; i++){
			int t, n, m, s;
			scanf("%d %d %d %d", &t, &n, &m, &s);
			int val = s ? 1 : -1;
			v[m].push_back(P(t, val));
		}
		scanf("%d", &q);
		for (int i = 0; i < q; i++){
			int s, e, m;
			scanf("%d %d %d", &s, &e, &m);
			
			sort(v[m].begin(), v[m].end());
			memset(arr, 0, sizeof(arr));
			for (int j = 0; j < v[m].size(); j++){
				arr[v[m][j].first] += v[m][j].second;
			}
			for (int j = 0; j < 1999; j++){
				arr[j + 1] += arr[j];
			}
			int res = 0;
			for (int j = s; j < e; j++){
				res += !!arr[j];
			}
			printf("%d\n", res);
		}
	}
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    int field[H][W];
    int num=0;
    int N;
    for(int i=0; i<H; i++){
        if(i>=B) num=1;
        for(int j=0; j<W; j++){
            if(j>=A) N=!num;
            else N=num;
            field[i][j]=N;
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << field[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
from collections import deque
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
dxdy = [(-1,0), (0,-1), (0,1), (1,0)]
INF = 10**5
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            continue
        q = deque([(i, j)])
        dist = [[INF]*w for _ in range(h)]
        dist[i][j] = 0
        while q:
            y, x = q.popleft()
            for dx, dy in dxdy:
                if not (0<=x+dx<w and 0<=y+dy<h):
                    continue
                if s[y+dy][x+dx]=='#' or dist[y+dy][x+dx]<INF:
                    continue
                dist[y+dy][x+dx] = dist[y][x] + 1
                q.append((y+dy, x+dx))
        for row in dist:
            for ele in row:
                if ele==INF:
                    continue
                ans = max(ans, ele)
print(ans)

Measured memory_bytes: 9472
//fast i/o functions will not work for negative values


#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
//#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j 
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable 
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb(a) push_back((a))

lo fact(lo n)
{
    if(n > 1)
        return n * fact(n - 1);
    else
        return 1;
}


int main(){
	lo t,n,m,x,i,j,sum;
	cin>>x>>i;
	if(i>=x){
		cout<<"0";
		return 0;
	}
	else cout<<x-i;
	return 0;
}	


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			
			double pow =Math.pow((x1-x2), 2) + Math.pow((y1-y2), 2);
			BigDecimal ans = new BigDecimal(Math.sqrt(pow));
			System.out.println(ans.setScale(6, RoundingMode.HALF_EVEN));
		}
	}

}


Measured memory_bytes: 28228
h, w = map(int, input().split())
s = [list(input().strip()) for _ in range(h)]

dw = []
dh = []

for i in range(h):
    cw = []
    for j in range(w):
        if s[i][j] == '#':
            cw.append(0)
        elif j == 0 or s[i][j - 1] == '#':
            count = 0
            for k in range(j, w):
                if s[i][k] == '.':
                    count += 1
                    if k == w - 1:
                        cw.append(count)
                else:
                    cw.append(count)
                    break
        else:
            cw.append(cw[j - 1])
    dw.append(cw)

for j in range(w):
    ch = []
    for i in range(h):
        if s[i][j] == '#':
            ch.append(0)
        elif i == 0 or s[i - 1][j] == '#':
            count = 0
            for k in range(i, h):
                if s[k][j] == '.':
                    count += 1
                    if k == h - 1:
                        ch.append(count)
                else:
                    ch.append(count)
                    break
        else:
            ch.append(ch[i - 1])
    dh.append(ch)

max = 0
for i in range(h):
    for j in range(w):
        sum = dw[i][j] + dh[j][i]
        if max < sum:
            max = sum
print(max - 1)


Measured memory_bytes: 250504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005;
const ll INF=1LL<<60;

typedef pair<ll,ll> pii;
deque<pii> dq;

bool check(pii a,pii b,pii c){
    return (c.second-b.second)*(b.first-a.first)>=(b.second-a.second)*(c.first-b.first);
}

void add(ll a,ll b){
    pii p=make_pair(a,b);
    while(dq.size()>=2&&check(dq[dq.size()-2],dq[dq.size()-1],p)) dq.pop_back();
    dq.push_back(p);
}

ll query(ll x){
    while(dq.size()>1&&dq[0].first*x+dq[0].second>dq[1].first*x+dq[1].second) dq.pop_front();
    return dq[0].first*x+dq[0].second;
}

ll dp[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;ll C;cin>>N>>C;
    vector<ll> h(N);
    for(int i=0;i<N;i++) cin>>h[i];
    
    add(-2*h[0],dp[0]+h[0]*h[0]);
    
    for(int i=1;i<N;i++){
        ll x=query(h[i]);
        dp[i]=C+h[i]*h[i]+x;
        add(-2*h[i],dp[i]+h[i]*h[i]);
    }
    
    cout<<dp[N-1]<<endl;
}



Measured memory_bytes: 8424
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    int ans;
    if((N-K)%(K-1) != 0){
        ans = (N-K)/(K-1) + 1 + 1;
    }else{
        ans = (N-K)/(K-1) + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
        using System.Linq;
        using System.Collections.Generic;
        using static System.Math;

        public class Program
        {
            public static void Main(string[] args)
            {
            int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] input = new int[] { };
            int cost = 0;

            for(int i = 0; i < n[0]; i++)
            {
                input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (cost == 0 && input[1] <= n[1]) cost = input[0];
                else
                {
                    if(input[0] < cost && input[1] <= n[1]) cost = input[0];
                }
            }

            Console.WriteLine(cost == 0 ? "TLE" : cost.ToString());
            }
        }

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

int main() {
  ll n;
  cin>>n;
  ll nd=sqrt(n)+1;
  ll min_ans=n;
  for(int i=1; i<=nd; i++){
    if(n%i==0){
      ll ans=i+n/i-2;
      min_ans=min(min_ans,ans);
    }
  }
  cout<<min_ans<<endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

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


  int a, b; cin >> a >> b;
  string s; cin >> s;
  bool ok = true;
  for(int i=0;i<SZ(s);++i) {
    if(i == a) {
      if(s[i] != '-') {
        ok = false;
        break;
      }
    } else {
      if(!('0' <= s[i] && s[i] <= '9')) {
        ok = false;
        break;
      }
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  
}


Measured memory_bytes: 256
import math

a=int(input())

t=0
"""
for i in range(1,a+1):
  for j in range(i,a+1):
    for k in range(j,a+1):
      
      print(i,j,k)

      if i==j and j==k:
        t+=math.gcd(math.gcd(i,j),k)
      else:
        t+=(math.gcd(math.gcd(i,j),k)*3)

print(t)
"""

for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      t+=math.gcd(math.gcd(i,j),k)
print(t)

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    
    rep(i,n) {
    cout << s.at(i) << t.at(i);
    }
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
kouho = set([])
kouho2 = set([])
for i in c.most_common():
	if i[1] >= 2:
		kouho.add(i[0])
	if i[1] >= 4:
		kouho2.add(i[0])
kouholist = list(kouho)
kouholist2 = list(kouho2)
kouholist = kouholist + kouholist2
kouholist = sorted(kouholist)[::-1]
if len(kouholist) >= 2:
	print(kouholist[0]*kouholist[1])
else:
	print(0)

Measured memory_bytes: 21540
#include<stdio.h>
int main()
{
    int input, output;
    int data[3];
    int i;

    // 数字の入力
    scanf("%d", &input);
    
    data[2] = input / 100;
    data[1] = (input - (100 * data[2])) / 10;
    data[0] = input - (100 * data[2]) - (10 * data[1]);
    
    for(i = 0; i < 3; i++)
    {
        if( data[i] == 1)
        {
            data[i] = 9;
        }
        else if( data[i] == 9 )
        {
            data[i] = 1;
        }
    }
    
    output = (100 * data[2]) + (10 * data[1]) + data[0];
    
    // 出力
    printf("%d\n",output);
    return 0;
}

Measured memory_bytes: 128
import sys
texts=sys.stdin.read()
texts=texts.lower()
cnt=[0]*26

letters=list('abcdefghijklmnopqrstuvwxyz')
for x in texts:
    i=0
    for y in letters:
        if x==y:
            cnt[i]+=1
        i+=1
for i in range(26):
    print(letters[i]+" : "+str(cnt[i]))


Measured memory_bytes: 5564
#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; }

int main () {
  int n;
  ll k,q;
  ll result = 0;
  cin >> n >> k >> q;
  std::vector<int> a(q);
  std::vector<int> score(n,0);
  rep(i,q) {
    cin >> a[i];
    score[a[i]-1]++;
  }
  rep(i,n) {
    cout << (k - (q - score[i]) > 0 ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 1408
// Problem : H - Grid 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_h
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n,m;
	cin >> n >> m;
	string str[n];
	rep(i,0,n)
		cin >> str[i];
	int dp[n][m];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	rep(i,0,n)
		rep(j,0,m)
		{
			if(i > 0 and str[i-1][j] != '#')
			{
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= mod;
			}
			if(j > 0 and str[i][j-1] !='#')
			{
				dp[i][j] += dp[i][j-1];
				dp[i][j] %= mod;
			}
		}
	cout << dp[n-1][m-1] <<"\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 12492
#include <stdio.h>

int main(){
    int a;
    int b;
    int c;
    int d;
    int e;
    int k;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    scanf("%d",&e);
    scanf("%d",&k);
    int ans=0;
    if(e-a>k){
        ans=1;
    }
    if(ans==0){
        printf("Yay!");
    }else{
        printf(":(");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
int i1,i2,i3,p1,p2,p3,i,l,p;
int P[500];
i = 0;
while(1){
	scanf("%d%d%d",&i1,&i2,&i3);
	p1 = i1;
	p2 = i2;
	p3 = i3;
	if(p1+p2+p3 == -3)break;
	if(i1==-1){p1=-1;}
	if(i2==-1){p2=-1;}
	if(i3==-1){p3=-1;}
	p = p1 + p2;
	if(p1==-1 || p2==-1){P[i]=4;}
	else if(p>=80){P[i]=0;}
	else if(p>=65){P[i]=1;}
	else if((p>=30 && p3 >=50) || p >=50 ){P[i]=2;}
	else if(p>=30){P[i]=3;}
	else if(p<30){P[i]=4;}
	i++;
}
for(l=0;l<i;l++){
	switch(P[l]){
		case 0:printf("A\n");break;
		case 1:printf("B\n");break;
		case 2:printf("C\n");break;
		case 3:printf("D\n");break;
		case 4:printf("F\n");break;
	}
}
return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

int main(void){
int a,b,i,j;
while(1){
scanf("%d",&a);
scanf("%d",&b);
if(a==0 && b==0){
break;
       } 
else{
for ( i=0; i < a; i++ ){
    for ( j=0; j < b; j++ ){
        if(i==0||i==a-1||j==0||j==b-1)  printf("#");
        else printf(".");
    }
    printf("\n");
        }
}
 printf("\n");
}
return 0;
}

Measured memory_bytes: 572
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	String INPUT = "";
	
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		out.flush();
	}
	
	void solve(Scanner sc, PrintWriter out) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (a < b && b < c) System.out.println("Yes");
		else System.out.println("No");
	}
}



Measured memory_bytes: 26132
import math
def comb(n, k):
    if n < 0 or k < 0 or n < k: return 0
    return math.factorial(n) // math.factorial(n-k) // math.factorial(k)



n,k = map(int, input().split())
MOD = 10 ** 9 + 7

dp = [[0] * (n+1)] * (k+1)

dp[0][0] = 1
for i in range(1, k+1):
    for j in range(n+1):
        if j >= i: dp[i][j] = (dp[i-1][j] + dp[i][j-i])%MOD
        else: dp[i][j] = dp[i-1][j]

if n >= k: print(dp[k][n-k])
else: print(0)


Measured memory_bytes: 5668
#include<bits/stdc++.h>
typedef long long int ll;
#define INF 0x3f3f3f3f
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
using namespace std;
const int sz=1e5+10, mod =1e9+7;
vector<int> g[sz];
vector<pair<int,int>> ans;
bool visited[sz];
int out[sz];
map<pair<int,int>,int> mp;

int dfs(int u,int p){
    visited[u]=true;
    int c=out[u]&1;

    for(auto v:g[u]){
        if(visited[v] ) continue;
        c^=dfs(v,u);
    }

    if(p==-1) return c;

    if(c&1){
        mp[{p,u}]^=1;
        mp[{u,p}]^=1;
    }
    return c;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    memset(out,0,sizeof(out));
    memset(visited,false,sizeof(visited));

    int n,m,i,j,u,v;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
        mp[{u,v}]=true;
        mp[{v,u}]=false;
        out[u]++;
    }

    int zz=dfs(1,-1);

    if(zz&1)cout<<"-1";
    else{
        for(auto x:mp){
            if(x.yy) cout<<x.xx.xx<<" "<<x.xx.yy<<"\n";
        }
    }

}


Measured memory_bytes: 30848
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1E16;
ll ans,n,have,d,m[55],sum[55],sumW[55];
ll f[55*55*55];
int fa[55];
inline void chmin(ll&x,ll y)
{
	x=min(x,y);
}
struct pt
{
	ll v,w,id;
	bool operator<(const pt&A)const
	{
		return v*A.w>A.v*w;
	}
}a[55];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>have>>d>>m[1];
	++sum[1],sumW[1]+=m[1];
	for(int i=2;i<=n;++i)
	{
		cin>>m[i]>>fa[i];
		for(int j=i;j;j=fa[j])
			++sum[j],sumW[j]+=m[i];
	}
	int lim=0,l=min(d,n);
	for(int i=1;i<=n;++i)
	{
		a[i]=(pt){sum[i],sumW[i],i};
		lim+=sum[i]*l;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=lim;++i)
		f[i]=inf;
	for(int i=1;i<=n;++i)
	{
		ll v=a[i].v,w=a[i].w;
		for(int j=1;j<=l;++j)
			for(int k=lim;k>=v;--k)
				chmin(f[k],f[k-v]+w);
	}
	for(int j=0;j<=lim;++j)
	{
		if(f[j]>have)
			continue;
		ll left=have-f[j],now=j;
		for(int i=1;i<=n;++i)
		{
			ll g=left/a[i].w;
			if(a[i].id!=1)
				g=min(g,d-l);
			left-=g*a[i].w,now+=g*a[i].v;
		}
		ans=max(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4100
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
 
g=nx.Graph() #無向グラフ
g.add_edges_from(s) #リストsを参照して頂点（部屋）の追加
di=nx.predecessor(g,source=1)#1から全点までの最短路におけるその点の前の点を表示
 
print("Yes")
for x in range(2,n+1):
      print(di[x][0])

Measured memory_bytes: 222764
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n,n){
		int ans=0;
		for(int i=n/2+1;i>1;i--){
			for(int j=i-1,now=i;j>0&&now<n;j--){
				now+=j;
				if(now==n)ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

a,b = II()

print(min(str(a)*b, str(b)*a))

Measured memory_bytes: 38384
import collections

n, k = map(int, input().split())
A = list(map(int, input().split()))

set_A = set(A)
c = collections.Counter(A)
cnts = []
for a, t in c.items():
    cnts.append([t, a])
cnts.sort()
ans = 0
for cnt in cnts:
    if len(set_A) <= k:
        print(ans)
        break
    else:
        ans += cnt[0]
        set_A.remove(cnt[1])


Measured memory_bytes: 52392
from collections import deque
H, W = map(int, input().split())
grid = [list(input()) + [False] for _ in range(H)]
grid = grid + [[False for _ in range(W + 1)]]
d = ((1, 0), (-1, 0), (0, 1), (0, -1))


def bfs(q):
    res_q = deque()
    while len(q):
        x, y = q.popleft()
        for dx, dy in d:
            nx = x + dx
            ny = y + dy

            if grid[nx][ny] == '.':
                res_q.append((nx, ny))
                grid[nx][ny] = '#'
    return res_q


q = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            q.append((i, j))

res = 0
while len(q):
    res += 1
    q = bfs(q)

print(res - 1)


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

int main() {
  int n;
  cin >> n;
  
  string s = "Yes";
  
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  
  int max = h[0];
  int flag = 1;
  for (int i = 1; i < n; i++) {
    if (max < h[i]) {
      max = h[i];
      flag = 1;
    }
    else if (max == h[i]) {
      max = h[i];
    }
    else if ((max - h[i] == 1) && (flag == 1)) {
      max -= 1;
      flag = 0;
    }
    else {
      s = "No";
      break;
    }
  }
  
  cout << s << endl;
  return 0;  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, p[200010];

int main() {
    cin >> n;
    rep(i, n) cin >> p[i];

    int cur = p[0];
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (p[i] <= cur) {
            cur = p[i];
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    for(int i = 0; i < N; i++){
        cin >> V.at(i);
    }
    //入力終了
    vector<int> W(N + 100); //総和用配列
    int K;
    for(int i = 0; i < N + 100; i++){
        for(int j = 0; j < N; j++){
            K = K + pow((V.at(j) - i), 2);
        }
        W.at(i) = K;
        //cout << W.at(i) << endl;
        K = 0;
    }
    sort(W.begin(), W.end());
    cout << W.at(0) << endl;
}

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

using namespace std;

int main() {
  	int k;
  	long lun = 0, next;
  	queue<long> q;
  	for (long i = 1; i < 10; i++) {
      	q.push(i);
    }
  	cin >> k;
  	for (; k > 0; k--) {
      	lun = q.front();
      	next = lun * 10 + lun % 10;
      	if (lun % 10 > 0) {
      		q.push(next - 1);
        }
      	q.push(next);
      	if (lun % 10 < 9) {
      		q.push(next + 1);
        }
      	q.pop();
    }
  	cout << lun << endl;
  
	return 0;
}


Measured memory_bytes: 1792
#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=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,M,wa[100005];
bool ac[100005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>M;
	while(M--){
		int a;string s;
		cin>>a>>s;
		if(s=="WA"&&!ac[a])wa[a]++;
		if(s=="AC")ac[a]=true;
	}
	int accnt=0,wacnt=0;
	REP(i,N+1){
		if(ac[i]){
			accnt++;wacnt+=wa[i];
		}
	}
	cout<<accnt<<" "<<wacnt<<endl;
}


Measured memory_bytes: 4468
a,b,n=list(map(int,input().split()))
if b==1:
    print(0)
elif n>=b:
    k=n%b
    if k==b-1:
        print(int(a*(n)/b)-a*int(n/b))
    else:
        print(int(a*(n-k-1)/b)-a*int(n/b-1))
else:
    print(int(a*n/b))

Measured memory_bytes: 9192
#include<cstdio>
#include<algorithm>

int x[200000];

int main(void) {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; i++)
        scanf("%d",&x[i]);

    std::sort(x, x+m);

    for(int i=m-1; i>0; i--)
        x[i] -= x[i-1];

    std::sort(x+1, x+m);

    int res = 0;
    for(int i=1; i<m-(n-1); i++)
        res += x[i];

    printf("%d\n", res);
}


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

using namespace std;

int N, t[200009], u[200009], z[200009], val[200009], rt[200009];

int getType (pair < int, int > x)
{
    if (x.first == 0) return +1;
    if (x.second == 0) return -1;
    return 0;
}

bool cmp (pair < int, int > p0, pair < int, int > p1)
{
    int t0 = getType (p0), t1 = getType (p1);
    if (t0 != t1) return (t0 < t1);
    if (t0 == t1 && t0 != 0) return (p0.first + p0.second < p1.first + p1.second);
    return 1LL * p0.second * p1.first < 1LL * p1.second * p0.first;
}

struct str
{
    int z, u, nod;
    str ():
        z (0),u(0),nod(0){}
    str (int _z, int _u, int _nod):
        z (_z),
        u (_u),
        nod (_nod) {}
}pile[200009];

bool operator < (str a, str b)
{
    return cmp ({b.z, b.u}, {a.z, a.u});
}

int getRoot (int x)
{
    if (x == rt[x]) return x;
    return rt[x] = getRoot (rt[x]);
}
priority_queue < str > PQ;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), rt[1] = 1;
for (int i=2; i<=N; i++)
    scanf ("%d", &t[i]), rt[i] = i;
for (int i=1; i<=N; i++)
    scanf ("%d", &val[i]);
for (int i=1; i<=N; i++)
{
    pile[i] = str ((val[i] == 0), (val[i] == 1), i);
    if (i > 1) PQ.push (pile[i]);
}
long long ans = 0;
while (!PQ.empty ())
{
    str curr = PQ.top ();
    PQ.pop ();
    int nod = getRoot (curr.nod);
    if (pile[nod].z != curr.z || pile[nod].u != curr.u || pile[nod].nod != nod)
        continue;
    int peste = getRoot (t[nod]);
    //printf ("link %d %d\n", nod, peste);
    str sus = pile[peste];
    ans += 1LL * sus.u * curr.z;
    sus.u += curr.u, sus.z += curr.z;
    rt[nod] = peste, pile[peste] = sus;
    if (peste != 1)
        PQ.push (sus);
}
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 11124
from collections import deque

def solve(k):
    que = deque()
    que.append((1, 1))
    dp = {1: 1}
    while que:
        x, c = que.pop()
        y = (x + 1) % k
        if (not y in dp) or (dp[y] > c + 1):
            dp[y] = c + 1
            que.appendleft((y, c+1))
        z = (10 * x) % k
        if (not z in dp) or (dp[z] > c):
            dp[z] = c
            que.append((z, c))
    return dp[0]

k = int(input())
print(solve(k))

Measured memory_bytes: 18404
import sys
from collections import deque
S = deque(input())
Q = int(input())

reverse = False
for _ in range(Q):
    q = sys.stdin.readline()
    if q[0] == "1":
        reverse = not reverse
    else:
        _, f, c = q.split()
        if f == "1":
            if reverse:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if reverse:
                S.appendleft(c)
            else:
                S.append(c)
if reverse:
    S.reverse()
ans = "".join(S)
print(ans)

Measured memory_bytes: 14128
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("");
	let N = input.includes("N");
  	let S = input.includes("S");
  	let E = input.includes("E");
  	let W = input.includes("W");
	
  	let NS = N&&S || !N&&!S;
  	let EW = E&&W || !E&&!W;
	  
	if(NS&&EW){
      console.log("Yes");
    }else{
      console.log("No");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29648
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

long long int modpow(long long int b, long long int p){
    long long int num = 1, power = b;
    for(int i=0; i<=30; i++){
        if((p>>i) & 1){
            num *= power;
            num %= MOD;
        }

        power *= power;
        power %= MOD;
    }
    return num;
}

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

    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];

    vector<vector<long long int>> pows(401, vector<long long int>(401));// pows[p][b] = b^p
    for(int p=0; p<=400; p++){
        for(int b=0; b<=400; b++){
            pows[p][b] = modpow(b,p);
        }
    }
    for(int p=0; p<=400; p++){
        for(int b=0; b+1<=400; b++){
            pows[p][b+1] += pows[p][b];
            pows[p][b+1] %= MOD;
        }
    }

    vector<vector<long long int>> dp(n+1, vector<long long int>(c+1));
    dp[0][0] = 1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=c; j++){
            for(int k=0; j+k<=c; k++){
                dp[i+1][j+k] += dp[i][j] * (((pows[k][b[i]] - pows[k][a[i]-1]) % MOD + MOD) % MOD);
                dp[i+1][j+k] %= MOD;
            }
        }
    }
    cout << dp[n][c] << endl;
    return 0;
}

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

long long int LCM(long long int C, long long int D);
int main(void)
{
    long long int A,B,C,D,E,Cok,Dok,CandD,ret;
    scanf("%lld%lld%lld%lld", &A,&B,&C,&D);
    
    Cok=((B-B%C)-(A-1-(A-1)%C+C))/C+1;
    Dok=((B-B%D)-(A-1-(A-1)%D+D))/D+1;
    E=LCM(C,D);
    CandD=((B-B%E)-(A-1-(A-1)%E+E))/E+1;

    ret=B-A+1-Cok-Dok+CandD;
    printf("%lld", ret);
    return 0;
}

long long int LCM(long long int C, long long int D)
{
    long long int r,x,tmp;
    x=C*D;
    if(C<D)
    {
        tmp=C;
        C=D;
        D=tmp;
    }
    r=C%D;
    while(r!=0)
    {
        C=D;
        D=r;
        r=C%D;
    }
    return x/D;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+10;
typedef long long LL;
LL x,y,z,k,t;
LL a[N],b[N],c[N];
 
int main()
{
	cin>>x>>y>>z>>k;
	for (int i=1;i<=x;i++) scanf("%lld",&a[i]);
	LL cnt=0;
	for (int i=1;i<=y;i++)
	{
		scanf("%lld",&t);
		for (int j=1;j<=x;j++) b[++cnt]=a[j]+t;
	}
	sort(b+1,b+cnt+1);
	reverse(b+1,b+cnt+1);
	LL cnt2=0;
	for (int i=1;i<=z;i++)
	{
		scanf("%lld",&t);
		for (int j=1;j<=min(k,cnt);j++) c[++cnt2]=b[j]+t;
	}
	sort(c+1,c+cnt2+1);
	reverse(c+1,c+cnt2+1);
	for (int i=1;i<=k;i++) printf("%lld\n",c[i]);
	return 0;
}

Measured memory_bytes: 35072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ara[100002],visit[100002];

ll dp(ll pos)
{
    ll p,r;
    if(visit[pos]!=-1)return visit[pos];
    p=r=999999999;
    if(pos+1<n)
    {
        p=abs(ara[pos]-ara[pos+1])+dp(pos+1);
        if(pos+2<n)r=abs(ara[pos]-ara[pos+2])+dp(pos+2);
    }
    else r=p=0;
    return visit[pos]=min(p,r);
}

int main()
{
    ll i;
    scanf("%lld",&n);
    for(i=0; i<n; i++)scanf("%lld",&ara[i]);
    memset(visit,-1,sizeof(visit));
    printf("%lld\n",dp(0));
    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	string s;
	cin >> s;
	
	string sr=s;
	reverse(sr.begin(),sr.end());
	if(s!=sr){
		cout << "No" << endl;
		return 0;
	}
	
	string s1=s.substr(0 , s.size()/2);
	string s1r=s1;
	reverse(s1r.begin(),s1r.end());
	if(s1!=s1r){
		cout << "No" << endl;
		return 0;
	}
	
	string s2=s.substr((s.size()+1)/2 , s.size()-1);
	string s2r=s2;
	reverse(s2r.begin(),s2r.end());
	if(s2!=s2r){
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder strb = new StringBuilder();
        while (true) {
            String[] data = br.readLine().split(" ");
            int h = Integer.parseInt(data[0]);
            int w = Integer.parseInt(data[1]);
            if (h == 0 && w == 0) {
                break;
            }
            boolean hFlg = true;
            boolean wFlg = true;
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    if (wFlg) {
                        strb.append("#");
                    } else {
                        strb.append(".");
                    }
                    wFlg = !wFlg;
                }
                strb.append("\n");
                hFlg = !hFlg;
                wFlg = hFlg ? true : false;
            }
            strb.append("\n");
        }
        System.out.print(strb);
    }
}

Measured memory_bytes: 25484
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[110], d(110);

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            G[u-1].push_back(v-1);
        }
    }

    for (int i = 0; i < n; i++) d[i] = -1;

    queue<int> que;
    que.push(0);
    d[0] = 0;
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (int v: G[u]) {
            if (d[v] == -1) {
                que.push(v);
                d[v] = d[u] + 1;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << endl;
    }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=abs(a[i]-a[i-1])+dp[i-1];
        dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],dp[i]);
    }
    cout<<dp[n-1]<<endl;
    
}

Measured memory_bytes: 1024
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define pd(s) //cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << setw(10) << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

bool can_eternal(ll A, ll B, ll C, ll D){
    // 最初から在庫足りてない
    if(A<B){
        pd(1);
        return false;
    }

    // 補充より消費が速い
    if(B>D){
        pd(2);
        return false;
    }

    // 以降、A>=B, B<=D

    // AからBをギリギリまで引いた状態
    ll start = A % B;
    ll step = D-B;

    // 次の飲みで終わる
    if(start>C){
        return false;
    }

    if(step==0){
        if(start<=C){
            return true;
        }else{
            return false;
        }
    }

    // 危険ゾーンがない場合とは
    if(B-C<=1){
        pd("no danger zone");
        return true;
    }

    if(step==1){
        return false;
    }

    ll left = C+1;
    ll right = B; // 含まない

    // pn(start);
    // pn(left);
    // pn(right);
    // pn(step);
    // pn(B);
    // pn(C);

    // 幅が広いので踏む
    if(right - left >= step){
        return false;
    }

    step = gcd(step, B);

    // 幅が広くなくても踏むときは踏む
    // leftの直前まで移動
    ll diff = left - start;
    ll n = diff / step;
    n -= 3; // ちょっと引く・・・
    if(n>0){
        start += step * n;
    }

    // これ遅いのでここまで来てはダメ
    while(start < right){
        start += step;
        if(left <= start && start < right){
            return false;
        }
    }

    return true;
}

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

    // input
    ll T;
    cin >> T;

    FOR(i, 0, T){
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        pd("");

        bool can = can_eternal(A, B, C, D);
        if(can){
            p_yes();
        }else{
            p_no();
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define maxn 200005
#define ll long long
#define ld double
#define mod 998244353
using namespace std;
int a[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]), sum += a[i];
	int mns = maxn, pl = 0;
	for(int i = 0; i < n; i++)
	{
		int nans = abs(sum - a[i] * n);
		if(nans < mns) mns = nans, pl = i;
	}
	printf("%d\n", pl);
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

#define MOD 1000 * 1000 * 1000 + 7
#define INF 1000 * 1000 * 1000
#define EMPTY -10
#define mp(a, b) make_pair(a,b)

bool resuelveCaso() {
	int a,b,c,d,e;
	cin >> a >> b>> c >> d >> e;
	if (!cin) return false;

	vi comp;
	int mint = a;

	if ((mint + 10 - 1) % 10 < (b + 10 - 1) % 10) {
		comp.push_back(b);
	}
	else {
		comp.push_back(mint);
		mint = b;
	}

	if ((mint + 10 - 1) % 10 < (c + 10 - 1) % 10) {
		comp.push_back(c);
	}
	else {
		comp.push_back(mint);
		mint = c;
	}

	if ((mint + 10 - 1) % 10 % 10 < (d + 10 - 1) % 10) {
		comp.push_back(d);
	}
	else {
		comp.push_back(mint);
		mint = d;
	}

	if ((mint + 10 - 1) % 10 % 10 < (e + 10 - 1) % 10) {
		comp.push_back(e);
	}
	else {
		comp.push_back(mint);
		mint = e;
	}

	int tot = 0;
	for (int i = 0; i < comp.size(); ++i) {
		if (comp[i] % 10 == 0) tot += comp[i];
		else {
			tot += (comp[i] / 10 + 1) * 10;
		}
	}

	tot += mint;
	cout << tot << '\n';

	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};

ll mod=1e9+7;

int main(){
  int N;
  cin >> N;
  cout << (N+1)/2 << endl;
}
      
  
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int K, X;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> K >> X;
    cout << (500 * K >= X ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int main(){

	int w, m[40], n, a, b, c;

	cin >> w;
	for (int i = 1; i <= w; i++)
	{
		m[i - 1] = i;
	}
	
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		scanf("%d,%d", &a, &b);
		c = m[a - 1];
		m[a - 1] = m[b - 1];
		m[b - 1] = c;
	}

	for (int i = 0; i < w; i++)
	{
		cout << m[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(itr, v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

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

  if(N < K) {
    answer = min(N, abs(N - K));
  } else {
    int c = N / K;
    int mod = N % K;
    int v = N - K * (c+1);

    answer = min(mod, abs(v));
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int h, a, cnt=0;
    cin >> h >> a;
    while(true){
        h -= a;
        cnt++;
        if(h <= 0) break;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stack>

using namespace std;

int main() {

  string str;
  while(getline(cin,str) && !(str.length()==1 && str[0]=='.')) {
    //cout<<str<<endl;
    stack<char> checker;
    bool flag = true;

    for(int i=0; i<str.length() && flag==true; i++) {
      if(str[i] == '(' || str[i] == '[') {
	checker.push(str[i]);
      }
      else if(str[i] == ')') {
	if(checker.empty()) {
	  flag = false;
	}
	else if(checker.top() != '(') {
	  flag = false;
	}
	else {
	  checker.pop();
	}
      }
      else if(str[i] == ']') {
	if(checker.empty()) {
	  flag = false;
	}
	else if(checker.top() != '[') {
	  flag = false;
	}
	else {
	  checker.pop();
	}
      }
    }

    if(flag==true && checker.empty()) {
      cout<<"yes"<<endl;
    }
    else {
      cout<<"no"<<endl;
    }
  }

}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
 
bool dp[100100];
 
 
int main () {
    int K, A, B;
    cin >>K >> A >> B;

    repr(i,A,B+1){
        if(i%K  ==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3624
#include<map>
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int judge(li a,const map<li,li>& mp,li m,li v,li p){
  li s=0,cnt=0;
  for(auto itr=mp.rbegin();itr!=mp.rend();itr++){
    if(itr->first > a+m){
      s+=itr->second;
    }
    else break;
  }
  if(df)printf("upper count is %d\n",s);
  if(s>=p)return 0;
  s=0;p--; // p-1 問は無限でよい
  for(auto itr=mp.rbegin();itr!=mp.rend();itr++){
    if((itr->second) <= p){
      s+= itr->second * m; // m 人が推薦
      p-= itr->second;     // 枠は減る
    }
    else if(p>0){
      s+=p * m;  // p枠 はmax
      s+= (itr->second-p)*min(m,(a+m- (itr->first)));  // 残りは a+m と同じだけ
    }else{
      s+= (itr->second)*min(m,(a+m- (itr->first)));  // 全部 a+m と同じだけ
    }
  }
  if(s>=m*v)return 1;
  return 0;
}

int main(){
  if(df) printf("*debug mode*\n");
  li n,m,v,p; cin >>n >>m >>v >>p;
  map<li,li> mp;
  rep(i,n){
    int a; cin >>a;
    mp[a]++;
  }
  vector<li> able;
  for(auto x: mp){
    able.push_back(x.first);
    if(df)printf("(%d %d)",x.first,x.second);
  }
  li ng=-1,ok=able.size()-1;
  while(ok-ng>1){
    li mid=(ok+ng)/2;
    if(judge(able.at(mid),mp,m,v,p)){
      ok=mid;
      if(df)printf("%d:ok\n",able.at(mid));
    }
    else{
      ng=mid;
      if(df)printf("%d:ng\n",able.at(mid));
    }
  }
  li ans=0;
  repa(i,ok,able.size()){
    if(df)printf("%ld ",able.at(i));
    ans+=mp[able.at(i)];
  }
  printf("%ld",ans);
}

/// confirm df==0 ///


Measured memory_bytes: 7676
#include<stdio.h>
int main(void)
{
  int x,a,b;
  int c,d;
  
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  
  c=x-a;
  d=x-b;
  if(c<0)
    c*=(-1);
  if(d<0)
    d*=(-1);
  
  if(c<d)
    printf("A");
  else
    printf("B");
  return 0;
}

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

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

    long long r, D, x;

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

    return 0;
}

Measured memory_bytes: 256