akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
#define MK make_pair
#define PB push_back
using namespace std;

typedef long long LL;
typedef pair<int ,int> PII;
const int N=210,oo=1e9;

vector<int> g[N];

int n, m, d[N][N], maxd[N];
char s[N];
bool checklabel(int *lab){
	for (int u=1; u<=n; ++u)
		for (int v=1;v<=n;++v)
			if (d[u][v]==1 && abs(lab[u]-lab[v])!=1) return false;
	return true;
}
int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%d", &n);
	for (int i=1; i<=n; ++i){
		scanf("%s", s);
		for (int j=0; j<n; ++j){
			if ( i==j+1) d[i][j+1]=0;	else
			if ( s[j]=='1') d[i][j+1]=1;
				else d[i][j+1] = oo;
		}
	}
	for (int k=1; k<=n; ++k)
		for (int i=1; i<=n; ++i)
			for (int j=1; j<=n ; ++j)
				d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
	
	for (int i=1; i<=n; ++i){
		maxd[i]= 0;
		for (int j=1; j<=n; ++j){
			maxd[i]=max(maxd[i], d[i][j]);
			#ifdef che
			debug("d[%d][%d] = %d\n", i,j,d[i][j]);
			#endif
		}
	}
	int ans=0;
	for (int i=1;i<=n; ++i) 
		if (checklabel(d[i]))ans=max(ans, maxd[i]);
	if ( !ans) puts("-1");
		else	printf("%d\n", ans+1);
	return 0;
}

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


int main(){
    ll n,k,d;
    cin >> n >> k >> d;
    ll m=abs(n);
    ll memo=m/d;
    if(memo>=k){
        cout << m-(k*d) << endl;
    }
    else{
        if((k-memo)%2==0){
            cout << m-memo*d << endl;
        }
        else{
            cout << abs(m-(memo+1)*d) << endl;
        }
    }
}  


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define F first
#define S second
#define mset(x,v) memset(x, v, sizeof(x))
#define left(x) 2*x
#define right(x) (2*x) + 1
#define ALL(t) (t).begin(),(t).end() 
#define ret return 0
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rev(s) reverse(s.begin(),s.end())
#define WL(t) while(t --)
#define MOD 1000000007
int main()
{
      boost;
      ll a,b;
      cin>>a>>b;
      if((a*b)&1)
      cout<<"Odd"<<endl;
      else
      cout<<"Even"<<endl;
}


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

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long ans;
    ans=max(a*c,max(a*d,max(b*c,b*d)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>
#include <limits>
using namespace std;
int imax = std::numeric_limits<int>::max();
long long dp[101][100002],i,j,n,k,w,vi[101],wi[101];
int main()
{
    
   // cout<<"P:";
    cin>>n>>w;
    for(i=1;i<=n;i++)
        cin>>wi[i]>>vi[i];
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j-wi[i]>=0)
                dp[i][j]=max(dp[i][j],dp[i-1][j-wi[i]]+vi[i]);
            
        }
    }
    /*
    for(i=1;i<=n;i++)
        {
            for(j=1;j<=w;j++)
                cout<<dp[i][j]<<" ";
            cout<<"\n";
        }
     */
    cout<<dp[n][w];
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }


const ll MRINF = 5000000000000000;
int main() {

ll A, V;
cin >> A >> V;
ll B,W;
cin >> B >> W;
ll T;
 cin >> T;
 ll D=abs(A-B);
 ll D2=(V-W)*T;
 puts(D<=D2?"YES":"NO");
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int i = Integer.parseInt(str[1]);
    System.out.println(n-i+1);
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
//#define int long long
#define rep(i,n) for(int i;i<n;i++)
#define fi first
#define se second
#define INF 100000002
#define MAX 1000002
using namespace std;

int a[101];
int main(){
	int n, p1, p2, c, ans = 0, tmp;
	scanf("%d%d%d%d", &n, &p1, &p2, &c);
	for(int i = 0;i < n;i++)scanf("%d", &a[i]);
	sort(a, a+101, greater<int>());
	tmp = c;
	for(int i = 0;i < n;i++){
		tmp += a[i];
		ans = max(ans, tmp/(p1+p2*(i+1)));
	}
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 3236
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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 main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll H,W;
  cin >> H >> W;
  if(H == 1 || W == 1){
    cout << 1 << "\n";
    return 0;
  }
  cout << (H*W+1)/2 << "\n";
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,a,b;cin>>n>>a>>b;
	if (abs(a - b) % 2 == 0){
		cout << abs(a - b) / 2 << endl;
	}
	else{
		cout << min(a + (b - 1LL - a)/2LL,n - b + (- a + b + 1LL)/2LL) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
    int a[105];
    int b[105][2];
    int m;
    while(scanf("%d",&m)!=EOF)
    {
        for(int i=1;i<=m;i++)
        scanf("%d",&a[i]);
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)
        scanf("%d%d",&b[i][0],&b[i][1]);
        for(int i=1;i<=n;i++)
        {
        	int t=a[b[i][0]];
        	a[b[i][0]]=b[i][1];
        	int ant=0;
        	for(int j=1;j<=m;j++)
        	{
        		ant+=a[j];
			}
			printf("%d\n",ant);
			a[b[i][0]]=t;
		}

	}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define M 1000000007
typedef long long ll;
int main() { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t,a[1000000],n,i,c=1;
    string s;
    cin>>n;
    cin>>s;
    if(n%2){
        c=0;
    }
    else{
        for(i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2])
            c=0;
        }
    }
    if(c)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  vector<char> editor;
  char c;
  while(cin >> c){
    if(c == '0' or c == '1')editor.push_back(c);
    else if(editor.size())editor.pop_back();
  }
  for(auto x:editor)cout << x;
  cout << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

vll z_array(string &s){
  ll n = s.size();
  vll res(n,0);
  res[0] = n;

  ll i = 1, j = 0;
  while(i < n){
    while(i + j < n && s[j] == s[i + j]) j++;
    res[i] = j;

    if(j == 0){ i++; continue;}

    ll k = 1;
    while(k < j && k + res[k] < j){
      res[i + k] = res[k];
      k++;
    }

    i += k; j -= k;
  }

  return res;
}
//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  for(ll i=0;i<n;i++){
    vll z = z_array(s);
    for(ll j=0;j<z.size();j++){
      if(j >= z[j]) ans = max(ans,z[j]);
    }
    reverse(ALL(s));
    s.pop_back();
    reverse(ALL(s));
  }

  cout << ans <<endl;


    
  return 0;
}



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

signed main(){
    int n;
    cin >> n;
    vector<double> a(n), x(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    x[0] = a[0];
    double ans = a[0] * 2.0;    
    rep(i, 1, n){
        x[i] = a[i];
        rep(j, 0, i){
            x[i] = max(x[i], x[j] + 2.0 * sqrt(a[i] * a[j]));
        }
        ans = max(ans, x[i] + a[i]);
    }
    printf("%.12f\n", ans);
}


Measured memory_bytes: 3248
h, w = [int(_) for _ in input().split()]
s = [[_ for _ in list(input())] for _ in range(h)]
l = [['.' for i in range(w + 2)] for j in range(h + 2)]
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
for i in range(1, h+1):
    for j in range(1, w+1):
        if l[i][j] == '#':
            if l[i-1][j] == '.' and l[i+1][j] == '.' and l[i][j-1] == '.' and l[i][j+1] == '.':
                ans = "No"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> v(10, true);
    for (int i = 0; i < k; ++i) {
        int x;
        cin >> x;
        v[x] = false;
    }

    for (int i = n; i <= 1e5; ++i) {
        string d = to_string(i);
        bool pos = true;
        for (int j = 0; j < (int) d.size(); ++j) {
            if (!v[d[j] - '0']){
                pos = false;
                break;
            }
        }
        if (pos){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
s = input()
n = len(s)
cnt = 0
pass_cnt = 0

for i in range(n-1):
  if pass_cnt != 0:
    pass_cnt -= 1
    continue
  else:
    if s[i]==s[i+1]:
      cnt += 1
      pass_cnt = 2
ans = n - cnt
print(ans)
    

Measured memory_bytes: 40560
#include <cstdio>

#include <cstdint>
#include <cassert>
struct Flags {
  Flags() : v(0ULL) {}
  Flags(int x) : v(1ULL << x) {}
  Flags(uint64_t x) : v(x) {}
  uint64_t v;
};

Flags operator | (Flags x, Flags y) {
  return Flags(x.v | y.v);
}

Flags andAll(const Flags xs[], int n) {
  assert( n != 0 );
  Flags res = xs[0];
  for(int i = 0; i < n; ++i) {
    res.v &= xs[i].v;
  }
  return res;
}

Flags clear(Flags& x) {
  x.v = 0ULL;
  return x;
}

void dump(Flags flags, int n) {
  for(int i = 0; i < n; ++i) {
    putchar((flags.v & (1ULL << i)) ? '1' : '0');
  }
  puts("");
}

// 0 0 : 0
// 0 1 : 0
// 1 0 : 1
// 1 1 : 0
bool operator <= (const Flags& x, const Flags& y) {
  return (x.v & ~(y.v)) == 0;
}

Flags orConversion(Flags flags, Flags cflags[64]) {
  Flags res;
  for(int i = 0; i < 64; ++i) {
    if( flags.v & (1ULL << i) ) {
      res.v |= cflags[i].v;
    }
  }
  return res;
}

Flags xs[64]; // xs[day]
int n;

bool load() {
  for(int i = 0; i < 64; ++i) clear(xs[i]);
  scanf("%d", &n);
  if( n == 0 ) return false;
  for(int i = 0; i < n; ++i) {
    int m;
    scanf("%d", &m);
    for(int j = 0; j < m; ++j) {
      int t; scanf("%d", &t);
      xs[t] = xs[t] | Flags(i);
    }
  }
  return true;
}

void solve() {
  Flags ys[64]; // ys[human]
  // step 1 ; oneself
  for(int i = 0; i < n; ++i) ys[i] = Flags(i);
  // step 2
  for(int day = 1; day <= 30; ++day) {
    for(int i = 0; i < 64; ++i) {
      Flags zs[64];
      //]if( not ( Flags(i) <= xs[day] ) ) continue;
      for(int j = 0; j < 64; ++j) {
        if( Flags(j) <= xs[day] ) {
          zs[j] = xs[day];
        }
        else {
          zs[j] = Flags((uint64_t)0);
        }
      }
      ys[i] = ys[i] | orConversion(ys[i], zs);
    }
    // dump(xs[day], 31);
    // //printf("%08lx #\n", xs[day]); 
    // for(int i = 0; i < n; ++i) {
    //   dump(ys[i], n);
    //   //printf("%08lx\n", ys[i].v);
    // }
    // puts("");
    // for(int i = 0; i < n; ++i) {
    if( andAll(ys, n).v != 0ULL ) {
      printf("%d\n", day);
      return;
    }
    // }
  }
  printf("%d\n", -1);
}

int main() {
  while( load() ) {
    solve();
  }
  
  return 0;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N - x; y++) {
      int z = N - x - y;
      if (Y == x * 10000 + y * 5000 + z * 1000) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int n;
int graph[8][8] = {};
vector<vector<int> > res((1 << 8), vector<int>(8, -1));

// bit: これまで訪れたnodeの組み合わせをbitで表したもの
// now: 今いるnode
int solve(int now, int bit)
{
	// cout << now << " " << bit << endl;
	if(res[bit][now] >= 0) return res[bit][now];
	if(bit == (1 << n) - 1) return res[bit][now] = 1;
	res[bit][now] = 0;
	for(int next = 0; next < n; next++){
		if(graph[now][next] == 0 || ((1 << next) & bit) > 0) continue;
		res[bit][now] += solve(next, ((1 << next) | bit));
	}
	return res[bit][now];
}

int main()
{
	int m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a][b] = graph[b][a] = 1;
	}
	cout << solve(0, 1) << endl;
}

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

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


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


def read_float():
    return float(buff_readline())


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


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


def read_str_n():
    return readline().strip().split()

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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(A, V, B, W, T):
    d = abs(A-B)
    vd = V-W
    if vd <= 0:
        return 'NO'

    from fractions import Fraction
    if Fraction(d, vd) <= T:
        return 'YES'

    return 'NO'



def main():
    A, V = read_int_n()
    B, W = read_int_n()
    T = read_int()
    print(slv(A, V, B, W, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 72800
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c = li()
abc = list([a,b,c])

abc.sort(reverse=True)

print(10*abc[0] + abc[1] + abc[2])

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int m = n % 10;
    if(m == 3) {
        cout << "bon\n";
    } else if(m == 0 || m == 1 || m == 6 || m == 8) {
        cout << "pon\n";
    } else {
        cout << "hon\n";
    }

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,n,s=0;;
    cin>>H>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        s=s+arr[i];
    }
    if(s>=H){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

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



int main(){
    ll n;
    cin >> n;
    ll sum=0;
    ll mini=10000000000;
    ll negs=0;
    rp(i,n){
        ll a;
        cin >> a;
        if(a<0) negs++;
        sum += abs(a);
        mini=min(mini,abs(a));
        
    }
    /*cout << sum << endl;
    cout << negs << endl;
    cout << mini << endl;*/
    if(negs%2==0)
    cout << sum << endl;
    else{
        cout << sum-mini*2 << endl;
    }
    return 0;
}

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

int bubbleSort(int *A,int N){
	int cnt;
	bool flag;
	
	flag=true;
	while(flag){
		flag=false;
		for(int j=N-1;j>=1;j--){
			if(A[j]<A[j-1]){
				cnt++;
				int tmp=A[j];
				A[j]=A[j-1];
				A[j-1]=tmp;
				flag=true;
			}
		}	
	
	}
	
	return cnt;
}
int main(){
	int n,a[1000],x;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	x=bubbleSort(a,n);
	for(int i=0;i<n;i++){
		if(i!=n-1)cout<<a[i]<<" ";
		else cout<<a[i]<<endl;
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long n,m;
  cin>>n>>m;
  if(n==1||m==1){
    cout<<1<<endl;
  }else{
    if(n*m%2==0){
    cout<<n*m/2<<endl;
  }else{
    cout<<n*m/2+1<<endl;
 	 }
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;

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



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 998244353;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }



int dp[10005];

int main() {

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

	int N;
	cin >> N;

	vector<int> A(N);


	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	dp[0] = 1;
	for (int i = 0; i < N; i++)
	{
		for (int j = 10000; j >= 0; j--)
		{
			if (dp[j] == 0)continue;
			if (j + A[i] <= 10000) {
				dp[j + A[i]] = 1;
			}
		}
	}

	int maxi = 0;
	for (int i = 0; i <= 10000; i++)
	{
		if (dp[i] == 1 && ((i % 10) != 0)) {
			maxi = max(maxi, i);
		}
	}

	cout << maxi << endl;

}


Measured memory_bytes: 256
h,w=map(int,input().split())
n=h*w
inf=10**6
field=[]
for i in range(h):
    field.append(input())
dist=[[inf]*n for i in range(n)]
for i in range(h):
    for j in range(w):
        if field[i][j]=="#":continue
        if j+1<w and field[i][j+1]!="#":
            dist[i*w+j][i*w+j+1]=1
            dist[i*w+j+1][i*w+j]=1
        if i+1<h and field[i+1][j]!="#":
            dist[i*w+j][(i+1)*w+j]=1
            dist[(i+1)*w+j][i*w+j]=1
for i in range(n):
    for j in range(n):
        for k in range(n):
            dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if dist[i][j]==inf:
            continue
        ans=max(ans,dist[i][j])
print(ans)

Measured memory_bytes: 43996
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:56:10 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

N = int(input())
#X, Y = map(int,input().split())
#ab = [list(map(int,input().split())) for i in range(N-1)]

fact = [1, 1] # 元テーブル
fact_inv = [1, 1] # 逆元テーブル
tmp_inv = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N+1):
    fact.append((fact[-1] * i) % mod)
    tmp_inv.append((-tmp_inv[mod % i] * (mod//i)) % mod)
    fact_inv.append((fact_inv[-1] * tmp_inv[-1]) % mod)
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
#逆元作成
def inv(a,mod):
    return pow(a,mod-2,mod)

graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(lambda x : int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a)

dp = [1] * (N + 0)
size = [0] * (N + 0)
def dfs(par, v):
    for u in graph[v]:
        if par == u:
            continue
        dfs(v, u)
        size[v] += size[u]
        dp[v] = dp[v] * dp[u] * fact_inv[size[u]] % mod
    dp[v] = dp[v] * fact[size[v]] % mod
    size[v] += 1

ans = [0] * (N + 0)
def reroot(par, val_par, size_par, v):
    ans[v] = val_par * dp[v] * cmb(N-1, size_par, mod) % mod
    for u in graph[v]:
        if par == u:
            continue
        val = ans[v] * inv(dp[u] * cmb(N-1, size[u],mod),mod) % mod
        reroot(v, val, N - size[u], u)

dfs(-1,1)
reroot(-1,1,0,1)
for i in range(N):
    print(ans[i])

Measured memory_bytes: 89224
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int64_t A, B, C;
  cin >> A >> B >> C;
  if(A % C == 0) {
    cout << B / C - A / C + 1 << endl;
  }
  else {
    cout << B / C - A / C << endl;
  }
}


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

int main () {
  string S;
  cin >> S;
  
  int val = 700;
  
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o') {
      val += 100; 
    }
  }
  cout << val << endl;
}



Measured memory_bytes: 256
using System;

class P2001
{
  public static void Main()
  {
    String[] line = Console.ReadLine().Split(' ');
    int n = Int32.Parse(line[0]);
    int m = Int32.Parse(line[1]);
    int a = Int32.Parse(line[2]);

    while(n!=0)
      {
	int[,] row = new int[m,3];
	int maxHight = 0;
	for(int i=0; i<m; i++)
	  {
	    line = Console.ReadLine().Split(' ');
	    row[i,0] =  Int32.Parse(line[0]);
	    row[i,1] =  Int32.Parse(line[1]);
	    row[i,2] =  Int32.Parse(line[2]);
	    maxHight = Math.Max(maxHight,row[i,0]);
	  }

	for(int i=maxHight; i>0; i--)
	  {
	    for(int j=0; j<m; j++)
	      {
		if(row[j,0]==i && row[j,1]==a)
		  {
		    a = row[j,2];
		    break;
		  }
		if(row[j,0]==i && row[j,2]==a)
		  {
		    a = row[j,1];
		    break;
		  }
	      }
	  }

	Console.WriteLine(a);

	line = Console.ReadLine().Split(' ');
	n = Int32.Parse(line[0]);
	m = Int32.Parse(line[1]);
	a = Int32.Parse(line[2]);
      }
  }
}

Measured memory_bytes: 5828
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int INF=0x3f3f3f3f;
int n;
int a[100001],dp[100001];
int main(){
    cin>>n;
    rep(i,n) cin>>a[i];
    reverse(a,a+n);
    memset(dp,0x3f,sizeof(dp));
    rep(i,n){
        *upper_bound(dp,dp+n,a[i])=a[i];
    }
    cout<<lower_bound(dp,dp+n,INF)-dp<<endl;
    return 0;
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc164/tasks/abc164_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<static_cast<ll>(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
//https://atcoder.jp/contests/agc023/tasks/agc023_a
//zero-sum rangesにちかい
int main(){
#if LOCAL&01
  //std::ifstream in("./test/sample-1.in");
  std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  string S; cin>>S;
  reverse(S.begin(),S.end());
  dump(18171%2019);
  dump(S,2019123%2019);

  //Aj*10^n,..,Ai+2*10^2,Ai+1*10,Ai
  ll sum=0;
  unordered_map<ll,ll> tbl;
  ll rate=1;
  tbl[sum]++;
  FOR(i,0,S.size()){
    ll digit=S.at(i)-'0';
    sum = sum+digit*rate;
    sum %= 2019;
    tbl[sum]++;
    rate = (rate * 10)%2019;
  }
  dump(tbl);
  ll ans=0;
  for(auto&p:tbl){
    if(p.second>=2){
      ans += p.second * (p.second-1)/2;
    }
  }
  cout<<ans<<endl;

  return 0;
}

int main_() {
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  string S; cin>>S;

  auto getval=[&](ll ii,ll jj){
    ll v=0;
    FOR(p,ii,jj+1){
      v*=10;
      v+=S.at(p)-'0';
    }
    return v;
  };

  ll ans=0;
  FOR(i,0,(ll)S.size()){
    if (i+2>=(ll)S.size())break;
    ll v=getval(i,i+2);
    FOR(j,i+3,(ll)S.size()){
      if(j-i>=4-1){
        v *= 10;
        v += S.at(j)-'0';
//        dump(i,j,v);
        if(v%2019==0) {
          ++ans;
          dump(v);
        }
      }else{
        break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3748
<?php
$n = (int)trim(fgets(STDIN));
$S = array_map('intval', explode(' ', trim(fgets(STDIN))));
$q = (int)trim(fgets(STDIN));
$T = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($S);
$cnt = 0;

// binary search
foreach ($T as $t) {
    $left = 0;
    $right = $n - 1;
    while ($left <= $right) {
        $mid = (int)(($left + $right) / 2);
        $diff = $t - $S[$mid];
        
        if ($diff == 0) {
            $cnt++;
            break;
        } elseif ($diff > 0) {
            $left = $mid + 1;
        } else {
            $right = $mid - 1;
        }
    }
}

print "{$cnt}\n";


Measured memory_bytes: 40892
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int f = 0, pre = a[0], ans = 1;
    Rep(i, 1, n)
    {
        if (pre == a[i])
        {
            pre = a[i];
            continue;
        }
        if (pre > a[i])
        {
            if (f == 0)
                f = 1;
            else if (f == 2)
            {
                ans++;
                f = 0;
            }
        }
        else
        {
            if (f == 0)
                f = 2;
            else if (f == 1)
            {
                ans++;
                f = 0;
            }
        }
        pre = a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/agc025/tasks/agc025_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}


const INF: i64 = 100000000;

fn main() {
    input! {
        n: usize,
        lr: [(i64, i64); n]
    };

    let mut lrid: Vec<(usize, i64, i64)> = lr.iter().enumerate().map(|(idx, w)| (idx, w.0, w.1)).collect();
    let mut left = lrid.clone();
    left.sort_by_key(|w| w.2);
    let mut right = lrid.clone();
    right.sort_by_key(|w| -w.1);
    let mut lrtbl: Vec<Vec<(usize, i64, i64)>> = vec![left, right];

    let mut best = 0;

    // l to r
    for w in 0..2 {
        let mut used = vec![false; n];
        let mut dsum = 0;
        let mut last = vec![-INF, INF];
        let mut idx = vec![0, 0];
        let mut which = w;

        loop {
            while idx[which] < n {
                let i = lrtbl[which][idx[which]].0;
                if used[i] {
                    idx[which] += 1;
                    continue;
                }
                break;
            }

            if idx[which] == n {
                break;
            }
            if which == 0 {
                if lrtbl[0][idx[0]].2 > last[1] {
                    break;
                }
                dsum -= lrtbl[0][idx[0]].2 * 2;
            }
            if which == 1 {
                if lrtbl[1][idx[1]].1 < last[0] {
                    break;
                }
                dsum += lrtbl[1][idx[1]].1 * 2;
            }
            best = max(best, dsum);
            used[lrtbl[which][idx[which]].0] = true;
            idx[which] += 1;
            which ^= 1;
        }
   }


    println!("{}", best);
}


Measured memory_bytes: 22780
x,k,d = map(int,input().split())
c = abs(x)//d
if c < k:
    if (k-c) % 2 == 0:
        print(abs(x)%d)
    else:
        print(min(abs(abs(x)%d+d),abs(abs(x)%d-d)))
else:
    print(abs(x)-d*k)

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

main()
{
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    long long i,j,k,l,m,n,o,p;
  while(cin>>p>>m>>n){
if(abs(p-n)<abs(p-m))cout<<"B"<<endl;
else cout<<"A"<<endl;
  }
    return 0;

}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
int ans = 2000000;
 
int main() {
    int N, M, X;
    int A[12][12];
    cin >> N >> M >> X;
    
    vector<int> C (N, 0);
    
    rep(i, 0, N){
        cin >> C[i];
        rep(j, 0, M){
            cin >> A[i][j];
        }
    }
    
    
    
    rep(i, 0, 1<<N){
        int sum = 0;
        vector<int> d(M);
        rep(j, 0, N){
            if(1 & i >> j) {
                sum += C[j];
                rep(k, 0, M) {
                    d[k] += A[j][k];
                }
            }
        }
        bool isOK = true;
       rep(k, 0, M) {
           if(d[k] < X){
               isOK = false;
           };
        }
        if (isOK){
            ans = min(ans, sum);
        }
    }
    if (ans == 2000000) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<ll> a(3*n);
	for(auto &x : a){
		cin>>x;
	}
	vector<ll> f(3*n), b(3*n);
	{
		ll sum = 0;
		map<ll, int> mp;
		for(int i = 0; i < n; i++){
			sum += a[i];
			mp[a[i]]++;
		}
		f[n - 1] = sum;
		for(int i = n; i < 3*n; i++){
			sum += a[i];
			mp[a[i]]++;
			ll val = (*mp.begin()).first;
			mp[val]--; if(!mp[val])mp.erase(val);
			sum -= val;
			f[i] = max(sum, f[i - 1]);
		}
	}
	{
		ll sum = 0;
		map<ll, int> mp;
		for(int i = 2*n; i < 3*n; i++){
			sum += a[i];
			mp[a[i]]++;
		}
		b[2*n] = sum;
		for(int i = 2*n - 1; i >= 0; i--){
			sum += a[i];
			mp[a[i]]++;
			ll val = (*mp.rbegin()).first;
			mp[val]--; if(!mp[val])mp.erase(val);
			sum -= val;
			b[i] = min(sum, b[i + 1]);
		}
	}
	ll ans = -1e18;
	for(int i = n - 1; i < 2*n; i++){
		ans = max(ans, f[i] - b[i + 1]);
	}
	cout<<ans<<'\n';


	return 0;
}

Measured memory_bytes: 13568
x, y, a, b, c = map(int, input().split())
pa = list(map(int, input().split()))
pb = list(map(int, input().split()))
pc = list(map(int, input().split()))
pa.sort(reverse=True)
pb.sort(reverse=True)
pc.sort(reverse=True)
N = x+y
i = ia = ib = ic = 0
psum = 0
while i < N:
    xa = pa[ia] if ia < len(pa) and ia < x else -1
    xb = pb[ib] if ib < len(pb) and ib < y else -1
    xc = pc[ic] if ic < len(pc) else -1
    if xa >= xb and xa >= xc:
        ia += 1
        psum += xa
    elif xb >= xc:
        ib += 1
        psum += xb
    else:
        ic += 1
        psum += xc
    i += 1

print(psum)

Measured memory_bytes: 23216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;  //4つの重りの重さ
  cin >> A >> B >> C >> D;  //入力
  
  int L = A + B;  //左の重さ
  int R = C + D;  //右の重さ
  
  if (L > R){
  	cout << "Left" << endl;
  } else if (L == R){
  	cout << "Balanced" << endl;
  } else if (L < R){
  	cout << "Right" << endl;
  }
}

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

typedef long long ll;

ll N;
vector<ll> Parent;
vector<vector<ll>> Kids;
ll Root;
vector<ll> A;

void find_root() {
  vector<bool> Seen;
  Seen.resize(N);
  ll v;
  for (v = 0; !Seen[v]; v = Parent[v]) Seen[v] = true;
  Root = v;
}
ll dfs(ll v, ll mode) {
  unordered_set<ll> kids_as;
  for (ll w : Kids[v])
    if (w != Root) kids_as.insert(dfs(w, mode));
  vector<ll> a_candidates;
  for (ll x = 0; a_candidates.size() < 2; ++x)
    if (!kids_as.count(x)) a_candidates.push_back(x);
  return A[v] = v == Parent[Root] ? a_candidates[mode] : a_candidates[0];
}
bool check() {
  ll v = Parent[Root];
  unordered_set<ll> needed;
  for (ll x = 0; x < A[v]; ++x) needed.insert(x);
  for (ll w : Kids[v]) {
    if (A[v] == A[w]) return false;
    needed.erase(A[w]);
  }
  return needed.empty();
}
bool solve() {
  find_root();
  for (ll mode : {0, 1}) {
    A.resize(N, -1);
    dfs(Root, mode);
    if (check()) return true;
  }
  return false;
}
int main() {
  cin >> N;
  Parent.resize(N);
  Kids.resize(N);
  for (ll v = 0; v < N; ++v) {
    ll p;
    cin >> p;
    --p;
    Parent[v] = p;
    Kids[p].push_back(v);
  }
  cout << (solve() ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 42624
#include<stdio.h>
int priority_queue[11],size=0;

void push(int);
int pop(void);

int main(void){
  int hill,i;

    for(i=0;i<10;i++){
      scanf("%d",&hill);
      push(hill);
    }

  for(i=0;i<3;i++)
    printf("%d\n",pop());

  return 0;
}

void push(int x){
  int i=size++,p;

  while(i>0){
    p=(i-1)/2;

    if(priority_queue[p]>=x)break;
      
      priority_queue[i]=priority_queue[p];
    i=p;
  }
  priority_queue[i]=x;
}

int pop(void){
  int ret=priority_queue[0],i=0,a,b;
  
  int x=priority_queue[--size];
  
  while(2*i+1<size){
    a=2*i+1;
    b=2*i+2;
    
    if(b<size && priority_queue[b]>priority_queue[a])a=b;
    
    if(priority_queue[a]<=x)break;
    
    priority_queue[i]=priority_queue[a];
    i=a;
  }
  priority_queue[i]=x;

  return ret;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<pair<int, int>> red(N);
  vector<pair<int, int>> blue(N);
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    red[i] = make_pair(x, y);
  }
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    blue[i] = make_pair(x, y);
  }
  vector<bool> is_checked(N, false);
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());
  int cnt = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(red[j].first < blue[i].first && red[j].second < blue[i].second){
        int maxk = -1;
        int maxr = -1;
        for(int k = j; k < N; k++){
          if(red[k].second > maxr && red[k].second < blue[i].second && red[k].first < blue[i].first && !is_checked[k]){
            maxk = k;
            maxr = red[k].second;
          }
        }
        if(maxk != -1){
        is_checked[maxk] = true;
        cnt++;
        break;
        }else{
        break;
        }
      }else{
        //is_checked[j] = true;
      }
    }
  }
  cout << cnt;
}


Measured memory_bytes: 256
def naiive(xs)
  n = xs.size
  cx = 0
  while true
    m = xs.max
    break if m <= n - 1
    xs[xs.index m] -= n + 1
    n.times do |i|
      xs[i] += 1
    end
    cx += 1
  end
  cx
end

def solve(xs)
  ans = 0
  n = xs.size

  100000.times do

    n.times do |i|
      k = (xs[i] - (n - 1)) / n
      next if k <= 0
      ans += k
      xs[i] -= k * n
      n.times do |j|
        next if i == j
        xs[j] += k
      end
    end

  end
  ans += naiive(xs)
  ans
end

def gen(n)
  (0...n).to_a.map { rand 1000 }
end

n = gets.to_i
xs = gets.chomp.split.map(&:to_i)
# xs = gen(10)
# p xs
# p naiive(xs.clone)
p solve(xs)


Measured memory_bytes: 1788
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
  q=[p[i],p[i+1],p[i+2]]
  if max(q)!=p[i+1] and min(q)!=p[i+1]:
    cnt += 1
    
print(cnt)

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

void put_house(int arr[3][10]){
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 10; j++){
      cout << ' ' << arr[i][j];
    }
    cout << endl;
  }
}

int main(){
  int house[4][3][10],b,f,r,v,num;
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 10; k++)house[i][j][k] = 0;
    }
  }
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> b >> f >> r >> v;
    house[b - 1][f - 1][r - 1] += v;
  }
  for(int i = 0; i < 4; i++){
    if(i != 0){
      for(int j = 0; j < 20; j++)cout << '#';
      cout << endl;
    }
    put_house(house[i]);
  }
  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);
  //int ans = 0;
  //string ans = "Yes";

  int ken, city; cin >> ken >> city;
  vector<vector<tuple<int, int, int>>> eachken(ken);
  rep(i, city){
    int x, y; cin >> x >> y;
    eachken[x - 1].push_back(make_tuple(x, y, i));
  }

  rep(i, ken){
    sort(all(eachken[i]));
  }
  rep(i, ken){
    rep(j, eachken[i].size()){
      get<1>(eachken[i][j]) = j + 1;
    }
  }
  vector<pair<int, int>> information(city);
  rep(i, ken){
    rep(j, eachken[i].size()){
      information[get<2>(eachken[i][j])] = make_pair(get<0>(eachken[i][j]), get<1>(eachken[i][j]));
    }
  }
  rep(i, city){
    string s = "";
    int digits = 0;
    int num = information[i].first;
    while(information[i].first > 0){
      information[i].first /= 10;
      digits++;
    }
    rep(j, 6 - digits){
      s += "0";
    }
    s += to_string(num);
    digits = 0;
    num = information[i].second;
    while(information[i].second > 0){
      information[i].second /= 10;
      digits++;
    }
    rep(j, 6 - digits){
      s += "0";
    }
    s += to_string(num);
    cout << s << endl;
  }
  
  //cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7808
let rec arr_string str =
        let length = String.length str in
        match length with
        | 0 -> []
       | len ->
                let first = String.sub str 0 1 in
                let rest = String.sub str 1 (len - 1) in
                (String.get first 0) :: (arr_string rest)
                
let print_intline num = print_endline (string_of_int num)
                
let rec sum ls = match ls with
    | [] -> 0
    | (x::xs) -> x + (sum xs)            
                
let digits n =
    let rec loop n acc =
        if n = 0 then acc
        else loop (n/10) (n mod 10::acc) in
    match n with
    | 0 -> [0]
    | _ -> loop n []

let () =
    let line = read_line () in
    let input = int_of_string line in
    let ans = sum (digits input) in
    let resp = input mod ans in
    match resp with
        | 0 -> print_endline "Yes"
         | _ -> print_endline "No"

Measured memory_bytes: 384
//f(l) + … + f(r)を求めることを考えると、f(l)とf(r)は固定したくなって(f(l) = aとおく)、
//f(l) = f(r) (1区間に収まる), f(l) + 1 = f(r) (区間を跨ぐ), f(l) + 2 ≦ f(r) (区間を飛び越える)
//を考えるまでは定石っぽい感じがする。f(l) + 2 ≦ f(r)は尺取り、f(l) = f(r)は約数列挙、
//f(l) + 1 = f(r)はf(l)の大きさで場合分け。f(l)が大きい時は自明全探索。小さい時は、
//拡張ユーグリッドに見えるけど実はいらない。
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2) return (a * powmod(a, n - 1, mod)) % mod;
	return powmod((a * a) % mod, n / 2, mod);
}

int mod = 1000000007;
int s;
int p10[10];

int digit(int x) {
	int ret = 0;
	while (x > 0) {
		x /= 10;
		ret++;
	}
	return ret;
}

int calc0(int s) {
	int i;
	vector<int> yaku;
	
	for (i = 1; i * i <= s; i++) {
		if (s % i == 0) {
			yaku.push_back(i);
			if (i != s / i) yaku.push_back(s / i);
		}
	}
	
	int ret = 0;
	for (i = 0; i < yaku.size(); i++) {
		int a = yaku[i];
		if (a >= 8 || p10[a - 1] * 9 >= s / a) {
			ret += powmod(10, a - 1, mod) * 9 % mod + mod - s / a + 1;
			ret %= mod;
		}
	}
	return ret;
}

int calc2(int s) {
	int l, r;
	int sumD = 0;
	int ret = 0;
	
	r = 1;
	for (l = 1; l < 1000000; l++) {
		for (; sumD < s; r++) {
			sumD += digit(r);
		}
		if (sumD == s && digit(l) + 2 <= digit(r - 1)) {
			ret++;
		}
		sumD -= digit(l);
	}
	return ret;
}

int calc1(int s) {
	int a, x, y;
	int ret = 0;
	
	for (a = 1; a <= 1000000; a++) {
		int lowT = ((s + 1) + a) / (a + 1);
		if (a <= 7) { lowT = max(lowT, ((s - 9 * p10[a]) + (a - 1)) / a); }
		int highT = (s - 1) / a;
		if (a <= 8) { highT = min(highT, (s + 9 * p10[a - 1]) / (a + 1)); }
		
		int cntT = max(highT - lowT + 1, 0LL);
		ret += cntT;
		ret %= mod;
	}
	
	for (x = 1; x <= 100; x++) {
		for (y = 1; y <= 100; y++) {
			if (s >= y && (s - y) % (x + y) == 0) {
				int a = (s - y) / (x + y);
				if (a > 1000000) { ret++; }
			}
		}
	}
	return ret;
}

signed main() {
	int i;
	
	p10[0] = 1;
	for (i = 1; i < 10; i++) p10[i] = 10 * p10[i - 1];
	
	cin >> s;
	cout << (calc0(s) + calc1(s) + calc2(s)) % mod << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a,b = [], []
for i in range(n):
    s,t = list(map(int, input().split()))
    a.append(s)
    b.append(t)

res = 0
for i in range(n-1, -1, -1):
    if not (a[i]+res)%b[i] == 0:
        res += b[i] - (a[i]+res)%b[i]
print(res)

Measured memory_bytes: 11016