akhauriyash/Code-Regression huggingface dataset:
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1149&lang=jp
*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = pair<int,P>;

int debug_num=0;

void debug(){
    int as;
    cout <<"num:" <<debug_num<<" input>";
    cin >> as;
    debug_num++;
}

int main(){
    while(1){
    
    int n,h,w;
    cin >> n >> w >> h;
    if(h==0) break;

    vector<T> piece;
    P q(h,w); T t(1,q);
    piece.push_back(t);
    for(int num=1; num<=n; ++num){
        int p,s;
        cin >> p >> s;
        int cut_ind = 0;

        //debug();

        rep(i,piece.size()){
            if(piece[i].first==p) cut_ind = i;
            if(piece[i].first>p) piece[i].first--;
        }

        //debug();

        P hw= piece[cut_ind].second;
        s = s%(hw.first+hw.second);

        //debug();

        if(s>hw.second){
            s-=hw.second;
            T c1,c2;
            c1.first = num; c2.first = num+1;
            int min_l = min(s,hw.first-s);
            int max_l = hw.first-min_l;
            //cout << "yoko " << min_l <<":" << max_l << endl;

            c1.second.first = min_l; c2.second.first = max_l;
            c1.second.second = hw.second; c2.second.second = hw.second;
            piece[cut_ind]=c1;
            piece.push_back(c2);
        }
        else{
            T c1,c2;
            c1.first = num; c2.first = num+1;
            int min_l = min(s,hw.second-s);
            int max_l = hw.second-min_l;
            //cout << "tate " << min_l <<":" << max_l << endl;

            c1.second.second = min_l; c2.second.second = max_l;
            c1.second.first = hw.first; c2.second.first = hw.first;
            piece[cut_ind]=c1;
            piece.push_back(c2);
        }

    }

    //cout << "ans" << endl;
    sort(piece.begin(),piece.end());
    vector<int> res;
    for(auto pp:piece){
         //cout << pp.first << ":  "<<pp.second.first <<":"<<pp.second.second << endl;
        res.push_back(pp.second.first*pp.second.second);
    }
    sort(res.begin(),res.end());
    for(int i=0; i<res.size();++i){
        cout << res[i];
        if(i!=res.size()-1) cout << " ";
    }
    cout << endl;
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


int main(){
	int a,b;
	cin >> a >> b;
  	for(int i = 0; i < 1500; i++) {
    	if((int)(i*0.08) == a && (int)(i*0.1) == b) {
        	cout << i << endl;
          	return 0;
        }
    }
  	cout << -1 << endl;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

vector<int> to[1005];

vector<int> bfs(int v){
  queue<int> q;
  q.push(v);
  vector<int> visited(1005);
  vector<int> p(1005);
  p[v]=-1;
  vector<int> res;
  while(!q.empty()){
    int now = q.front();q.pop();
    visited[now]=1;
    for(int next:to[now]){
      if(next==v){
        res.push_back(now);
        while(now!=v){
          res.push_back(p[now]);
          now = p[now];
        }
        reverse(res.begin(),res.end());
        return res;
      }
      if(visited[next]==1)continue;
      q.push(next);
      p[next]=now;
    }
  }
  return res;
}

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--,b--;
    to[a].push_back(b);
    //to[b].push_back(a);
  }
  vector<int> ans;
  int size = INF;
  rep(i,n){
    auto t = bfs(i);
    if(t.size()!=0&&t.size()<size){
      ans = t;
      size=t.size();
    }
  }
  if(size==INF){
      cout << -1 << endl;
  }else{
    cout << size << endl;
    rep(i,size)cout << ans[i]+1 << endl;
  }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
int main()
{
  ll N,X;
  cin>>N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);
  A.at(0)=1;
  rep(i,N-1){
    cin>>C.at(i+1);
    A.at(C.at(i+1))+=1;
  }
  for(ll i=1;i<N;i++)cout<<A.at(i)<<endl;
  cout<<0<<endl;
}

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

int main()
{
    int a, b;
    int sum = 0;
    cin >> a >> b;
    for (int i = 0; i < 2; i++) {
        if (a > b) {
            sum += a--;
        }
        else {
            sum += b--;
        }
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int c;
vector<int> E[SIZE];
int d[SIZE],f[SIZE]; //init:0

void dfs(int v){
  c++;
  d[v]=c;
  for(int to : E[v]) if(d[to] == 0){
    dfs(to);
  }
  c++;
  f[v] = c;
}

int n;

int main(){
  cin >> n;
  rep(i,0,n){
    int v,k;
    cin >> v >> k;
    rep(i,0,k){
      int u;
      cin >> u;
      //E[u].push_back(v);
      E[v].push_back(u);
    }
  }

  rep(i,0,n){
    if(d[i+1] ==0) dfs(i+1);
  };

  rep(i,0,n){
    cout << i+1 << " " <<  d[i+1] << " " << f[i+1] << endl;
  }

  return 0;
}



Measured memory_bytes: 7860
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int R;

int main()
{
	in >> R;
	if (R < 1200) out << "ABC";
	else if (R < 2800) out << "ARC";
	else out << "AGC";
	out << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int s[100];
int main(){
    int n,k;
    cin>>n;
    int ans=0,l=1;
    for(int i=1;i<=n;i++){
        if(i%2==0){
           int t=i,p=0;
            while(t%2==0){
                t/=2;
                p++;
            }
            //cout<<p<<endl;
            if(p>=ans) l=i,ans=p;
        }
    }
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define min(a, b) ( (a) < (b) ? (a) : (b) )
#define max(a, b) ( (a) > (b) ? (a) : (b) )
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define Repeat_Forever for (;;)
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (n); (i) += (step))
#define FOREACH(it, v) for (auto (it) : (v))
#define ENDL cout << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector<ll> vll;

template <class T>
const bool is_impar(T x) {return (bool) (x & 1);}

int a, b, k;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> a >> b >> k;
    for (int i = 1; i <= k;) {
        if (is_impar(a))
            a--;
        a >>= 1;
        b += a;
        i++;
        if (i <= k) {
            if (is_impar(b))
            b--;
            b >>= 1;
            a += b;
            i++;
        }
    }
    cout << a << ' ' << b;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;

class Main {

  public static class Process {

    public String name;
    public int time;

    public Process(String name, int time) {
      this.name = name;
      this.time = time;
    }

  }

  public static void process(Queue<Process> q, int quantum) {

    int curr_time = 0;

    while (q.isEmpty() == false) {

      Process curr_ps = q.remove();

      int time_passed = Math.min(quantum, curr_ps.time);
      curr_time += time_passed;
      curr_ps.time -= time_passed;

      if (curr_ps.time == 0)
        System.out.println(curr_ps.name + " " + curr_time);
      else
        q.add(curr_ps);
    }

  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int quantum = s.nextInt();
    Queue<Process> processes = new LinkedList<Process>();
    for (int i = 0; i < n; i++) {
      processes.add(new Process(s.next(), s.nextInt()));
    }
    process(processes, quantum);
  }
}


Measured memory_bytes: 75216
#include <bits/stdc++.h>
using namespace std;
int n,v[3],h[3];

int main(){
	cin >> n;
	v[0] = 0;
	h[0] = -10000,h[1] = -10000;
	for(int i = 0 ; i < n ; i += 1){
		cin >> h[2];
		if(i){
			v[2] = min(v[1]+abs(h[2]-h[1]),v[0]+abs(h[2]-h[0]));
		}
		v[0] = v[1],v[1] = v[2];
		h[0] = h[1],h[1] = h[2];
	}
	cout << v[1] << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi seq(n);
		rep(i, n)
			scanf("%d", &seq[i]);
		
		int oh = 32;
		for(int i=0; oh; ++i){
			if(i%2 == 0)
				oh -= (oh - 1) % 5;
			else
				oh -= min(oh, seq[(i/2)%n]);
			printf("%d\n", oh);
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3];
    max(a*b, c*d).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr ll mod = 1e9+7;

int F(int a, int b) {
    return max(to_string(a).size(), to_string(b).size());
}

int main() {
    ll N;
    cin >> N;
    int res = 1e9;
    for(int i=1; i<=sqrt(N); ++i) {
        if(N % i == 0) {
            res = min(res, F(i, N/i));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int a[10];
vector<int> v;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    
    REP(i, n){
        v.push_back(i+1);
    }
    do{
        for(int i=0; i<n; ++i){
            if(i) cout << " ";
            cout << v[i];
        }
        cout << endl;
    }while(next_permutation(v.begin(), v.end()));
    
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  vec(c,string,2," ");
  rep(i,0,2)
      cin>>c.at(i);
  rep(i,0,2)
    rep(j,0,3)
      if(c.at(i).at(j)!=c.at(2-i-1).at(3-j-1)){
        ou("NO");
        return 0;
      }
  ou("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n;
	char s;
	cin >> n;
	REP(i, n) {
		cin >> s;
		if (s == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}
 

Measured memory_bytes: 256
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect
from decimal import Decimal

A, B = map(str,input().split())

ans = int(Decimal(A) * Decimal(B)) 

print(ans)

Measured memory_bytes: 73196
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll,ll> tllll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll x,y; cin >> x >> y;
  if(abs(x-y)<=1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
  int a=0;
  while(n!=0){
    a+=n%10;
    n=n/10;
  }
  return a;
}
int main(){
  int n;
  cin >> n;
  if(n%digit(n)==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3608
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def bomb(surface, x, y):
    surface[y][x] = 0

    start = (x-3) if (x-3) > 0 else 0
    end = (x+4) if (x+4) < 8 else 8
    for i in range(start, end):
        if surface[y][i]:
            bomb(surface, i, y)

    start = (y-3) if (y-3) > 0 else 0
    end = (y+4) if (y+4) < 8 else 8
    for i in range(start, end):
        if surface[i][x]:
            bomb(surface, x, i)

N = int(stdin.readline())
for n in range(1, N+1):
    stdin.readline()

    surface = []
    for _ in range(8):
        surface.append([int(c) for c in stdin.readline().rstrip()])
    x = int(stdin.readline())
    y = int(stdin.readline())

    bomb(surface, x-1, y-1)

    print('Data {}:'.format(n))
    for line in surface:
        print(''.join(str(d) for d in line))

Measured memory_bytes: 4308
#include "stdio.h"
#include <stdlib.h>

int main (){
  /*  int a, b, c;                                                                                            
  char x,y,z;                                                                                                 
  //  scanf("%c%c%c", &x, &y, &z);                                                                            
  scanf("%d",&a);                                                                                             
  int d=(int)3.8;                                                                                             
  */
  int N, a;
  scanf("%d %d",&N, &a);
  int d = (int)((double)N/(double)(2*a+1));
  if (N%(2*a+1)!=0){
    d++;
  }
  printf("%d\n",d);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
  int R,G,B,N,ans{},p;
  cin >> R >> G >> B >> N;
  for(int r = 0; r*R <= N; ++r) {
    for(int g = 0; p=r*R+g*G, p <= N; ++g) {
      if ((N-p)%B == 0) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin

q,h,s,d = [int(x) for x in stdin.readline().rstrip().split()]
n = int(stdin.readline().rstrip())

li = [q*4,h*2,s,d/2]

if min(li) == q*4:
    print(n*q*4)
elif min(li) == h*2:
    print(n*h*2)
elif min(li) == s:
    print(n*s)
else:
    if n%2 == 1:
        li.pop()
        li.sort()
        print(n//2*d+li[0])
    else:
        print(n//2*d)

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

bool unbalanced(const string& str)
{
    int counts[26] = {};
    for(char ch : str) counts[ch - 'a']++;
    for(int i = 0; i < 26; ++i)
        if(2*counts[i] > str.size()) return true;
    return false;
}

void solve(string s)
{
    if(s.size() == 2 && s[0] == s[1]) 
    {
        cout << 1 << " " << 2 << endl;
        return;
    }

    const int len = 3;
    for(int i = 0; i < s.size() - len + 1; ++i)
    {
        string temp = s.substr(i, len);
        if(unbalanced(temp)) 
        {
            cout << i + 1 << " " << i + 3 << endl;
            return;
        }
    }
    cout << -1 << ' ' << -1 << endl;
}

int main(int argc, char *argv[])
{
    string s;
    cin >> s;

    solve(s);
}


Measured memory_bytes: 512
//itp1_5-a
#include <iostream>
using namespace std;

int main(){
 int h,w;
 while(true){
  cin>>h>>w;
  if(h==0 && w==0){
   break;
  }
  for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
    cout<<'#';
   }
   cout<<endl;
  }
  cout<<endl;
 }
 return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

vector<ll>a, b;

struct UnionFind
{
	map<ll, ll> par;
	map<ll, int> sizes;

	UnionFind(int n){
		for (int i = 0; i < n; i++) {
			if (a[i] != b[i]) {
				sizes[a[i]] = 1;
				sizes[b[i]] = 1;

				par[a[i]] = a[i];
				par[b[i]] = b[i];
			}
		}
	}

	ll find(ll x) {
		if (x == par[x])return x;
		return par[x] = find(par[x]);
	}

	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);

		if (x == y) return;

		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}

	bool same(ll x, ll y) {
		return find(x) == find(y);
	}

	int size(ll x) {
		return sizes[find(x)];
	}
};


int main()
{
	int N; cin >> N;
	a.resize(N);
	b.resize(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];

	ll ax = a[0];
	for (int i = 1; i < N; i++)ax ^= a[i];
	ll bx = b[0];
	for (int i = 1; i < N; i++)bx ^= b[i];

	int mode = 0;

	bool same = false;
	int cnt = 0;
	UnionFind uf(N);
	for (int i = 0; i < N; i++) {
		if (a[i] != b[i]) {
			cnt++;

			uf.unite(a[i], b[i]);

			mode = 1;
		}

		if (b[i] == ax)same = true;
	}

	int cut = 0;
	map<ll, bool>link;
	for (int i = 0; i < N; i++) {
		if (a[i] != b[i]) {
			if (link[uf.find(a[i])] == false) {
				cut++;
				link[uf.find(a[i])] = true;
			}
		}
	}

	a.push_back(ax);
	b.push_back(bx);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for (int i = 0; i <= N; i++) {
		if (a[i] != b[i]) {
			mode = -1;
			break;
		}
	}

	if (mode == 1) {
		cout << cnt + cut - 1 + !same << endl;
	}
	else cout << mode << endl;

    return 0;
}



Measured memory_bytes: 18176
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#define max(a,b) ((a > b) ? a : b)
#define min(a,b) ((a < b) ? a : b)
#define abs(a) ((a < 0) ? -a : a)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

int main() {
	int n = ri();
	char s[n+1];
	scanf("%s", s);
	
	int resss = 0;
	for (int i = 1; i < n; i++) {
		int ress = 0;
		for (int k = 0; k < 26; k++) {
			bool res = false;
			for (int j = 0; j < i; j++) {
				if (s[j] == 'a'+k) res = true;
			}
			if (!res) continue;
			res = false;
			for (int j = i; j < n; j++) {
				if (s[j] == 'a'+k) res = true;
			}
			if (res) ress++;
		}
		resss = max(resss, ress);
	}
	
	printf("%d", resss);
	
	return 0;
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n, d;
    read(n, d);
    vt<int> a(n), b(n);
    int ans = 0;
    FOR(n) {
        read(a[i], b[i]);
        int val = a[i] * a[i] + b[i] * b[i];
        double t = sqrt(val);
        if (t <= d) {
            ans++;
        }
    }
    print(ans);
    
    
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



Measured memory_bytes: 6368
from itertools import permutations

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

def dist(A, B):
    x0, y0 = A
    x1, y1 = B
    res = pow((x0-x1)**2 + (y0-y1)**2, 1/2)
    return res

def sum_dist(arr):
    res = 0
    for A, B in zip(arr[:], arr[1:]):
        res += dist(A, B)
    return res

ans = 0
cnt = 0
for p in permutations(pos):
    ans += sum_dist(p)
    cnt += 1

ans /= cnt
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}



Measured memory_bytes: 256
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, p] <- getIntList
  as <- getIntList

  let checkAs [] res = res > 0
      checkAs (x:xs) res | x `mod` 2 == 1 = checkAs xs (res+1)
                         | otherwise      = checkAs xs res

      oddExists = checkAs as 0

      ans :: Int
      ans | oddExists = 1 `shiftL` (n-1)
          | p == 0    = 1 `shiftL` n
          | otherwise = 0

  print ans

Measured memory_bytes: 508
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
all_list = []
r_list = {}
for i in range(m):
	a, b = map(int, input().split())
	all_list.append(a)
	all_list.append(b)
	if a in r_list.keys():
		r_list[a].add(b)
	else:
		r_list[a] = {b}
	if b in r_list.keys():
		r_list[b].add(a)
	else:
		r_list[b] = {a}
all_list = list(set(all_list))
count = n - len(all_list)
for k in r_list.keys():
	targets = r_list[k]
	height1 = h_list[k - 1]
	flag = True
	for t in targets:
		height2 = h_list[t - 1]
		if height1 <= height2:
			flag = False
	if flag:
		count += 1
print(count) 

Measured memory_bytes: 136460
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
	int n,W,i,j;
	cin>>n>>W;
	int v[n],w[n],dp[n+1][W+1];
	for(i=0;i<n+1;i++)dp[i][0]=0;
	for(i=0;i<W+1;i++)dp[0][i]=0;	
	for(i=0;i<n;i++)cin>>v[i]>>w[i];
	for(i=1;i<=n;i++){
		for(j=1;j<=W;j++){
			if(j-w[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
			else dp[i][j]=dp[i-1][j];
		}
	}

	cout<<dp[n][W]<<endl;
}
/*reveres begin end
cout<<"\n";
  m.insert(std::make_pair('c', 30));
  .erase(v.begin() + 2)
*/



Measured memory_bytes: 7064
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var str = Console.ReadLine();
            var n = Int32.Parse(str);
            var a = new List<Int64>();
            while (n > 0)
            {
                a.Add(Int32.Parse(Console.ReadLine()));
                n--;
            }

            Int64 ret = 0;
            Int64 sum = 0;
            for (int i = 0; i < a.Count(); i++)
            {
                if (a[i] == 0)
                {
                    ret += sum / 2;
                    sum = 0;
                }
                else sum += a[i];
            }
            ret += sum / 2;

            Console.WriteLine(ret);
            Console.Out.Flush();        
        }


        static public Int64 ModPow(Int64 x, Int64 n, Int64 mod)
        {
            Int64 ret = 1;
            while (n > 0)
            {
                if ((n & 1) == 1) ret = ret * x % mod;
                x = x * x % mod;
                n >>= 1;
            }
            return ret;
        }

        static string ReadLine()
        {
            StringBuilder sb = new StringBuilder();
            while (true)
            {
                int ch = Console.Read();
                if (ch == -1) break;
                if (ch == '\r' || ch == '\n')
                {
                    if (ch == '\r') Console.Read();
                    return sb.ToString();
                }
                sb.Append((char)ch);
            }
            if (sb.Length > 0) return sb.ToString();
            return null;
        }
    }

}

Measured memory_bytes: 8664
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "functional"
#include "stack"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, L, R, H, W;



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

	cin >> N;
	while (N) {
		vector<long long int>v(N);
		for (auto &i : v)cin >> i;
		K = 0;
		M = accumulate(v.begin(), v.end(), 0LL);
		for (auto i : v) {
			if (i*N <= M)K++;
		}
		cout << K << endl;
		cin >> N;
	}
}


Measured memory_bytes: 3212
n,W=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(n)]
# dp[i][w] := 品物1〜i　を総和w以下で選ぶときの最大価値
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(n):
    for w in range(W+1):
        # 品物i の価値がw以下ならば dp[i][w]より大きく出来る可能性がある.
        if L[i][1] <=  w:
            dp[i+1][w] = max(dp[i][w - L[i][1]]+L[i][0], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(max(dp[n]))


Measured memory_bytes: 41884
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse = False)
cnt = 1


if 0 in A:
    print (0)
    exit()
else:
    for i in range(N):
        cnt *= A[i]
        if cnt > 10 ** 18:
            print (-1)
            exit ()
print (cnt)

Measured memory_bytes: 21648
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int input;
    cin >> input ;
    
    long long ans = 0, tall, before = 0;
    for(int i = 0; i < input; i++){
        cin >> tall ;
        ans += max((long long)0, before - tall);
        before = max(before, tall);
    }

    cout << ans << endl;

}


Measured memory_bytes: 3564
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long x=sc.nextLong(),y=sc.nextLong(),count=1;
		while(true) {
			x*=2;
			if(x>y)break;
			count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 24020
/**
 *    author:  FromDihPout
 *    created: 2020-09-17
**/

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

vector<vector<int>> adj;
vector<int> val;

void dfs(int u, int par, int x) {
    val[u] += x;
    for (int v : adj[u]) {
        if (v != par) {
            dfs(v, u, val[u]);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    adj.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    val.resize(n);
    for (int i = 0; i < q; i++) {
        int node, x;
        cin >> node >> x;
        val[node - 1] += x;
    }
    
    dfs(0, -1, 0);
    for (int i = 0; i < n; i++) {
        cout << val[i] << ' ';
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 24232
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
int card[10],n,k;
bool used[10];
vector<int> V;
set<int> S;
void solve(int x) {
	if(x==k) {
		int p=0,q=1;
		for(int i=0;i<V.size();i++) {
			p+=(V[i]%10)*q; q*=10;
			if(V[i]/10) p+=(V[i]/10)*q,q*=10;
		}
		S.insert(p);
		return;
	}
	for(int i=0;i<n;i++) {
		if(!used[i]) {
			used[i]=true;
			V.push_back(card[i]);
			solve(x+1);
			V.pop_back();
			used[i]=false;
		}
	}
}
int main() {
	while(scanf("%d",&n),n) {
		scanf("%d",&k);
		for(int i=0;i<n;i++) scanf("%d",&card[i]);
		S.clear();
		solve(0);
		printf("%d\n",S.size());
	}
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

// pは素数
// 事前処理 COMinit() の計算量はn
// https://drken1215.hatenablog.com/entry/2018/06/08/210000
const lint MAX = 2e6+9;  // nCkのn,kの最大値
const lint MOD = mod;
lint fac[MAX];  // i!
lint inv[MAX];  // i^(-1)
lint finv[MAX];  // (i!)^(-1)

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
lint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
////////////////////////////////

int app() {
  int k;
  cin>>k;

  string s;
  cin>>s;
  int sl=s.length();

  vector<lint> p26(k+1),p25(k+1);
  p26[0]=p25[0]=1;
  rep_range(i,1,k+1){
    p26[i]=p26[i-1]*26%mod;
    p25[i]=p25[i-1]*25%mod;
  }

  COMinit();

  lint ans=0;
  rep(i,k+1){
    lint c=p26[i]*p25[k-i]%mod;
    c=c*COM(sl-1+k-i,sl-1)%mod;
    ans+=c;
    ans%=mod;
  }

  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 66804
from sys import stdin
s,t = [x for x in stdin.readline().rstrip().split()]
a,b = map(int,stdin.readline().rstrip().split())
k = stdin.readline().rstrip()
if k == s:
    print(a-1,b)
elif k == t:
    print(a,b-1)
else:
    print(a,b)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n; cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  REP(i,n) {
    string s; cin >> s;
    if (s == "AC") ac++;
    else if (s == "WA") wa++;
    else if (s == "TLE") tle++;
    else if (s == "RE") re++;
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> n;
  u64 a[n];
  bool visit[n];
  for (u64 i = 0; i < n; ++i) {
    u64 ai;
    cin >> ai;
    a[i] = ai-1;
    visit[i] = false;
  }
  visit[0] = true;
  u64 cnt = 0;
  u64 last = 0;
  while (!visit[1]) {
    last = a[last];
    if (visit[last]) {
      cout << -1 << endl;
      return 0;
    }
    visit[last] = true;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
int n,sl,fh,ans,c[mxn],f[mxn],num[1<<20],a[20][20],b[20][20];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
bool check()
{
	for(int i=1;i<=n;++i)
		if(f[i])
		{
			for(int j=1;j<=c[i];++j)
				if(f[a[i][j]]!=b[i][j])
					return 0;
		}
	return 1;
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i)
	{
		c[i]=rd();
		for(int j=1;j<=c[i];++j) a[i][j]=rd(),b[i][j]=rd();
	}
	for(int i=0;i<1<<n;++i)
	{
		for(int j=0;j<n;++j) f[j+1]=(i>>j)&1;
		num[i]=num[i>>1]+(i&1);
		if(check()) ans=max(ans,num[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4480
n, m = (int(x) for x in input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a-1, b-1])

box = [1]*n

red = [0]*n

red[0] = 1

for x,y in ab:
    if 0 < red[x]:
        red[y] = 1
    box[x] -= 1
    box[y] += 1

    if box[x] == 0:
        red[x] = 0
print(sum(red))

Measured memory_bytes: 66904
class UnionFind:
    """
    parents: 各要素の親要素
             要素がrootの場合には　-(そのグループに属する要素数) を格納
    """
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        # xが属するグループのrootを取得
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # 高い方の木の根に低い方の木の根を結合
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return - self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

      
n, m, k = map(int, input().split())

union_find = UnionFind(n)
friends_counter = {i: 0 for i in range(n)}
blocks_counter = {i: 0 for i in range(n)}

for _ in range(m):
    a, b = map(int, input().split())
    union_find.union(a-1, b-1)
    friends_counter[a-1] += 1
    friends_counter[b-1] += 1

for _ in range(k):
    c, d = map(int, input().split())
    if union_find.same(c-1, d-1):
        blocks_counter[c-1] += 1
        blocks_counter[d-1] += 1

result = []
for i in range(n):
    result.append(str(union_find.size(i) - friends_counter[i] - blocks_counter[i] - 1))

print(" ".join(result))

Measured memory_bytes: 33760
using System;
using System.Linq;
using System.Collections.Generic;

public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		var sList = ReadLineAndToIntList().ToList();
		Console.ReadLine();
		var tList = ReadLineAndToIntList();
	
		int count = 0;
	
		foreach (var t in tList)
		{
			if(sList.BinarySearch(t) > -1) count++;
		}
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static IEnumerable<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c));
	}
}

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

#define endl '\n'
#define mod 1e7

using ll = long long;
using namespace std;

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

    string s;
    string t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();

    int dp[n + 1][m + 1];

    /**
     * if(s[i] == t[j]) dp[i][j] = dp[i-1][j-1] + 1; //Diagonally upwards
     * else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); // max b/w up and left elements
     * To find the sequence: backtrack
    */
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    char ans[dp[n][m] + 1];
    ans[dp[n][m]] = '\0';
    int i = n, j = m;
    int k = dp[n][m] - 1;
    while (i >= 0 && j >= 0)
    {
        if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
            ans[k--] = s[i-1];
            --i;
            --j;
        } else if (dp[i][j] == dp[i-1][j]) i--;
        else j--;
    }
    // cout << dp[n][m] << endl;
    cout << ans << endl;

    return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int a[n+2];
  a[0]=0;
  int sum=0;
  for(int i=0;i<n;i++) {
    cin>>a[i+1];
    sum+=abs(a[i+1]-a[i]);
  }
  a[n+1]=0;
  sum+=abs(a[n]);

  for(int i=1;i<n+1;i++){
    int tmp=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]);
    cout<<sum-abs(tmp)<<endl;
  }


}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[SIZE];
    for( int i = 1; i <= n; ++i ) cin >> a[i];

    int b[SIZE] = {};
    int res = 0;
    for( int i = n; i > 0; --i ) {
        int sum = 0;
        for( int j = i + i; j <= n; j += i ) {
            sum += b[j];

        }
        if( a[i] == 1 ) {
            if( sum % 2 == 0 ) { b[i] = 1;
            ++res; }

        } else {
            if( sum % 2 ) { b[i] = 1;
            ++res; }

        }
    }

    cout << res << endl;
    for( int i = 1; i <= n; ++i ) {
        if( b[i] == 1 ) cout << i << " ";

    }
    if( res ) cout << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

#define MAX_N 100'000

typedef long long ll;

using namespace std;

int A[MAX_N];
int B[MAX_N];

int main() {
  int N;
  cin >> N;
  ll a = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    a += (ll)A[i];
  }
  ll b = 0;
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
    b += (ll)B[i];
  }
  if (a < b) {
    printf("-1\n");
    return 0;
  }
  vector<int> V;
  vector<int> _V;
  for (int i = 0; i < N; ++i) {
    ll d = A[i] - B[i];
    if (d > 0) {
      V.push_back(d);
    } else if (d < 0) {
      _V.push_back(-d);
    }
  }
  int M = V.size();
  int _M = _V.size();
  if (_M == 0) {
    printf("0\n");
    return 0;
  }
  sort(V.begin(), V.end());
  sort(_V.begin(), _V.end());
  int i = M - 1;
  int _i = _M - 1;
  ll t = 0;
  int res = 0;
  while (_i >= 0) {
    if (t >= 0) {
      t -= _V[_i--];
      ++res;
    } else {
      t += V[i--];
      ++res;
    }
  }
  printf("%d\n", res + (t < 0));
}

Measured memory_bytes: 4356
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

vector<vector<pair<int,int>>> g;
vector<int> ans;

void dfs(int u, int p, int c){
    ans[u] = c;
    for(auto pp : g[u]){
        if(pp.ff==p) continue;
        if(pp.ss&1)
            dfs(pp.ff,u,c^1);
        else 
            dfs(pp.ff,u,c);
    }
}

int main(){
    Shazam;
    int n; cin>>n;
    g.resize(n+1);
    ans.resize(n+1);
    for(int i =1 ; i < n; i++){
        int a,b,w; cin>>a>>b>>w;
        g[a].push_back({b,w%2});
        g[b].push_back({a,w%2});
    }
    dfs(1,0,0);
    for(int i = 1; i <=n; i++)
        cout<<ans[i]<<endl;
    return 0;
}

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

int G(int m,int n){
  int a=max(m,n);
  int b=min(m,n);
  
  int r=a%b;
  
  if(r==0)
    return b;
  else
    return G(b,r);
}


int main(){
  int N,X;
  cin>>N>>X;
  
  vector<int>x(N+1);
  
  x.at(N)=X;
  
  for(int i=0;i<N;i++){
    cin>>x.at(i);
  }
  
  sort(x.begin(),x.end());
  
  vector<int>dx(N);
  
  for(int i=0;i<N;i++)
    dx.at(i)=x.at(i+1)-x.at(i);
  
  int g=dx.at(0);
  
  for(int i=0;i<N;i++)
    g=G(g,dx.at(i));
  
  cout<<g;
}

Measured memory_bytes: 1024
import math


def calc_minkowski_distance(x1, x2, p):
    """calc L_p norm(finite dimension)

    Args:
        x1: vector1
        x2: vector2
        p: p in L_p

    Returns:
        L_p distance between x1 and x2 (float)
    """
    if p == "inf":
        return max([math.fabs(x[0] - x[1]) for x in zip(x1, x2)])
    else:
        return math.pow(sum([math.pow(math.fabs(x[0] - x[1]), p) for x in zip(x1, x2)]), 1.0 / p)


target = [1, 2, 3, "inf"]
dimension = int(raw_input())
x1 = [float(x) for x in raw_input().split()]
x2 = [float(x) for x in raw_input().split()]
for p in target:
    print(calc_minkowski_distance(x1, x2, p))

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    minus_count = 0
    abs_min = float('inf')
    ans = 0

    for ai in a:
        if ai < 0:
            minus_count += 1

        abs_min = min(abs_min, abs(ai))
        ans += abs(ai)

    if minus_count % 2 == 1:
        ans -= abs_min * 2

    print(ans)


if __name__ == '__main__':
    main()


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

#define ll long long int

int main(){
	ios_base::sync_with_stdio(false);
  	
  	string s;
  	cin>>s;
  	cout<<((s[2]==s[3] && s[4]==s[5]) ? "Yes" : "No")<<"\n";
}

Measured memory_bytes: 256
d = int(input())
clst = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
last = [0 for _ in range(26)]

def score_minus(d, q):
    minus = 0
    for i, (c, ls) in enumerate(zip(clst, last)):
        if i == d:
            continue
        minus += c * (d - ls)
    return minus
    
ans = 0
for i in range(d):
    tmp = 0
    for q in range(26):
        tmp_score = s[i][q] - score_minus(i, q)
        if tmp_score > tmp:
            tmp = tmp_score
            max_q = q
    print(max_q + 1)
    last[max_q] = i

Measured memory_bytes: 9536
#include <iostream>
#include <iomanip>
using namespace std;
double dp[3005][3005];
int main()
{
    int n;
    double p[3005],rez=0.0;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> p[i];
    }
    dp[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<=i;j++)
        {
            if (j!=0) dp[i][j]=dp[i-1][j-1]*p[i];
            dp[i][j]+=dp[i-1][j]*(1-p[i]);
        }
    }
    for (int i=1;i<=n;i++)
    {
        if (i>n-i) rez+=dp[n][i];
    }
    cout << fixed << setprecision(12) << rez;
}

Measured memory_bytes: 68992