akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>

using namespace std;

set<int> con;
vector<int> lcon;

int main(int argc, char* argv[])
{
	int c0, c1, c2, c3, c4;
	
	while(1) {

		cin >> c0;
		if( c0 == 0 )
			break;
		
		cin >> c1 >> c2 >> c3 >> c4;

		con.insert(c0);	lcon.push_back(c0);
		con.insert(c1);	lcon.push_back(c1);
		con.insert(c2);	lcon.push_back(c2);
		con.insert(c3);	lcon.push_back(c3);
		con.insert(c4);	lcon.push_back(c4);

		for( auto c : lcon ) {

			int o0 = c%3 + 1;
			int o1 = (c+1)%3 + 1;

			bool f0 = ( con.find(o0) != con.end() );
			bool f1 = ( con.find(o1) != con.end() );

			if( c0 == c1 && c1 == c2 && c2 == c3 && c3 == c4 ){
				cout << 3 << endl;				
			}
			
			else if( f0 && !f1 ) cout << 1 << endl;			
			else if( !f0 && f1 ) cout << 2 << endl;
			else if( f0 && f1 ) cout << 3 << endl;
		}

		con.clear();
		lcon.clear();
	}

    return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int NMAX=1010101010;

int main()
{
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll n=s.length();
    ll count=0;
    ll fc=0,lc=0;
    int i=0;
    while(s[0]==s[i++] && i<=n && s[0]==s[n-1])fc++;
    i=n-1;
    while(s[n-1]==s[i--] && i>=0 && s[0]==s[n-1])lc++;
    if(fc==n)
    {
        cout<<k*fc/2;
        return 0; 
    }

    for(int k=fc;k<n-lc;k++)
    {
        if(s[k]==s[k-1])
        {
            count++;
            k++;
        }
    }
    ll ans=(fc/2)+lc/2+(k-1)*((fc+lc)/2)+k*count;
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;   

int n,m,r;
int dist[200][200];
bool check[200];
vector <int>visit(8);
int ans = MOD;

void dfs(int cnt,int now,int sum){
  if(cnt == r){
    ans = min(ans,sum);
    return;
  }
  
  REP(i,r){
    if(!check[visit[i]]){
      check[visit[i]] = true;
      dfs(cnt+1,visit[i],sum+dist[now][visit[i]]);
      check[visit[i]] = false;
    }
  }
}

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

  cin >> n >> m >> r;
  

  REP(i,r){
    cin >> visit[i];
    visit[i]--;
  } 
  
  REP(i,n){
    REP(j,n){
      if(i == j) dist[i][j] = 0;
      else       dist[i][j] = MOD;
    }
  }
  
  REP(i,m){
    int a,b,d;
    cin >> a >> b >> d;
    a--;b--;
    dist[a][b] = d;
    dist[b][a] = d;
  }
  
  REP(k,n){
    REP(i,n){
      REP(j,n){
        if(dist[i][j] > dist[i][k] + dist[k][j]) dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  
  REP(i,r){
    check[visit[i]] = true;
    dfs(1,visit[i],0);
    check[visit[i]] = false;
  }
        
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
$n=<>;
for(1..$n-1){
    <>=~/ (.+) /;
    $tree{$`}->{$1}=$';
    $tree{$1}->{$`}=$';
}
($Q,$K)=glob<>;
@dep;$#dep=$N+1;
&dfs($K,-1,0);
for(1..$Q){<>=~$";print$dep[$`]+$dep[$'],$/}
sub dfs{
    my($v,$p,$d)=@_;
    $dep[$v]=$d;
    for my$c(keys %{$tree{$v}}){
        next if$c==$p;
        &dfs($c,$v,$d+$tree{$v}->{$c})
    }
}

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

int main() {
  string S;  
  cin >> S;
  
  if(S.at(2) == S.at(3)){
    if(S.at(4)==S.at(5)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }

}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, t;
  cin >> n >> t;
  vi32 a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vi32 ord(n);
  iota(all(ord), 0);
  sort(all(ord), [&](int i, int j) {
    if (a[i] != a[j]) return a[i] < a[j];
    return b[i] > b[j];
  });
cerr << ord << endl;
  vi32 dp(6001);
  rep(i, 6001) dp[i] = -1;
  dp[0] = 0;

  rep(i, n) {
    int as = a[ord[i]];
    int bs = b[ord[i]];
    rrep(j, t) {
      if (dp[j] == -1) continue;
      amax(dp[j + as], dp[j] + bs);
    }
  }

  int ans = 0;
  rep(i, 6001) amax(ans, dp[i]);
  cout << ans << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);++i)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")

#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")

int main(void){

  int x[5],i;
  rep(j,5){
  cin>>x[j];
  if(x[j]==0) i=j+1;
  }
  cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
	#define ll long long
	#define db double
	#define sht short
	#define MB template <class T>
	#define Fur(i,x,y) for(int i=x;i<=y;i++)
	#define fur(i,x,y) for(i=x;i<=y;i++)
	#define Fdr(i,x,y) for(int i=x;i>=y;i--)
	#define fdr(i,x,y) for(i=x;i>=y;i--)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define inf 0x3f3f3f3f
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdout)
	#define l2(n) (int(log2(n)))
	#define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define fcin ios::sync_with_stdio(false)
	MB T ABS(T x){return x>0?x:-x;}
	MB T MAX(T x,T y){return x>=y?x:y;}
	MB T MIN(T x,T y){return x<=y?x:y;}
	MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
	void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 100011
int main(){
	int a,b;
	cin>>a>>b;
	printf("%.10f",(db)a/b);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define int long long
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	vector<int>c(b);
	vector<int>f(a-1);
	for (int d = 0; d < b; d++) { int g; cin >> g; g--; c[d] = g; }
	for (int e = 0; e < b - 1; e++) {
		vector<int>h(2); h[0] = c[e]; h[1] = c[e + 1];
		sort(h.begin(), h.end());
		for (int i = 0; i < a - 1; i++) {
			if (i >= h[0] && i < h[1])f[i]++;
		}
	}
	int s = 0;
	for (int i = 0; i < a - 1; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		s += min(x*f[i],z+y*f[i]);
	}
	cout << s << endl;
}

Measured memory_bytes: 4404
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int f=0;
	if (a<0)
	{
		for (;;)
		{
			a=a+1;
			f=f+c;
			if (a==b)
			{
				cout<<f<<endl;
				return 0;
			}
			if (a==0)
			{
				f=f+d;
				break;
			}	
		}
	}
	if (a>=0)
	{
		for (;;)
		{
			if (a==b)
			{
				cout<<f<<endl;
				return 0;
			}
			a=a+1;
			f=f+e;
		}
		
	}
	return 0;	
}

Measured memory_bytes: 3080
# import n as integer
n = int(input())
# obtain list
l = list(map(int, input().split()))

# take avg. of where person is
avg = sum(l)/n
sum = 0

if abs(avg//1 - avg) < abs(avg//1+1 - avg):
	for i in range(0,n):
		sum+=(l[i]-avg//1)**2
else:
	for i in range(0,n):
		sum+=(l[i]-avg//1-1)**2

print(int(sum))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,max_wt;
ll w[101], v[101],dp[101][100001];
int main() {
    cin>>n>>max_wt;
    for(int i =0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=max_wt;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }else{
                if(w[i-1]>j){
                    dp[i][j] = dp[i-1][j];
                }else{
                    ll inc = v[i-1]+dp[i-1][j-w[i-1]];
                    ll exc = dp[i-1][j];

                    dp[i][j] = max(exc,inc);
                }
            }
        }
    }
    cout<<dp[n][max_wt]<<endl;
}


Measured memory_bytes: 79104
require "prime"

class Integer
  def divisors
    prime_division.inject([1]) do |ary, (p, e)|
      (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
    end.sort
  end
end

n = gets.to_i

ans = (n-1).divisors.size - 1

n.divisors.each do |d|
  next if d == 1
  t = n
  while t % d == 0 do
    t /= d
  end
  ans += 1 if t % d == 1
end

puts ans

Measured memory_bytes: 2556
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cerr<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 5e3 + 1, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int n, m, a[9][9];
vi v;
int main() {
#ifdef ONLINE_JUDGE
	   FAST;
#endif
	cin >> n >> m;
	lp (i,1,n)
		v.pb(i);
	while (m--) {
		int x, b;
		cin >> x >> b;
		a[x][b] = a[b][x] = 1;
	}
	int ans = 0;
	do {
		if (v[0] != 1)
			continue;
		bool is = true;
		lp(i,1,n-1)
		{
			if (!a[v[i]][v[i - 1]]) {
				is = false;
				break;
			}
		}
		ans += (is);
	} while (next_permutation(all(v)));
	f(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		sc.close();
		
		int d = a/b;
		int r = a%b;
		String f = String.format("%.5f",  1.0 * a / b);
		
		System.out.printf("%d %d %s", d, r, f);
		
	}

}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    int ans = 1;
    x -= (y + z + z);

    while (x - y - z >= 0) {
        x -= (y + z);
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
   
#define M 3333331
#define NIL (-1)
#define L 14
   
char H[M][L]; /* Hash Table */
   
int getChar(char ch){
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
}
   
/* convert a string into an integer value */
long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}
   
int h1(int key){ return key%M; }
int h2(int key){ return 1 + (key % (M - 1)); }
   
int find(char str[]){
    long long ii = getKey(str);
    int i;
    int hh1 = h1(ii);
    int hh2 = h2(ii);
    for (i = 0; i<M ; i++){
      if (H[(hh1 + i*hh2) % M][0] == '\0'){return 0;}
        else if (strcmp(H[(hh1 + i*hh2) % M], str) == 0){ return 1; }
    }
    return 0;
    /* your task */
   
}
   
int insert(char str[]){
    long long ii = getKey(str);
    int hh1 = h1(ii);
    int hh2 = h2(ii);
    int i;
    for (i = 0; i<M; i++){
        if (H[(hh1 + i*hh2) % M][0]== '\0'){
            strcpy(H[(hh1 + i*hh2)%M], str);
            return 0;
        }
    }
    return 0;
    /* your task */
   
}
   
int main(){
    int i, n, h;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';
   
    scanf("%d", &n);
   
    for (i = 0; i < n; i++){
        scanf("%s %s", com, str);
   
        if (com[0] == 'i'){
            insert(str);
        }
        else {
            if (find(str)){
                printf("yes\n");
            }
            else {
                printf("no\n");
            }
        }
    }
   
    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n,x,t;
    cin>>n>>x>>t;

    int ans=ceil((n/(x*1.0)))*t;

    cout<<ans;


    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (1 <= a && a <= 9 && 1 <= b && b <= 9)
    {
        cout << a * b << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define PI 3.14159265359
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() {
  string s;
  cin >> s;
  int n = s.length();
  int ans = 0;

  FOR(i,0,n/2-1){
    if(s[i]!=s[n-1-i]) ++ans;
  }

  cout << ans << endl;

}



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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B;
    cin >> A >> B;
    int counter = 0;
    for (int i = A; i <= B; i++) {
        int c = i;
        int first = c / 10 / 10 / 10 / 10;
        int second = c / 10 / 10 / 10 % 10;
        int fourth = c / 10 % 10;
        int fifth = c % 10;
        if (first == fifth && second == fourth) counter++;
    }
    cout << counter << endl;
    return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline ll combi2(const ll n) {
    return n * (n - 1) / 2;
}

int main() {
    int n;
    cin >> n;
    vpii p(n);
    REP(i, n) {
        cin >> p[i].first;
        p[i].second = i + 1;
    }
    sort(ALL(p));
    REP(i, n) {
        if(i == n - 1) cout << p[i].second << "\n";
        else cout << p[i].second << " ";
    }

    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vll vector<ll>
#define vec vector
#define pb push_back
#define pop pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define FASTio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//ll mod = 1000000007;
void solve() {
	ll n;
	cin >> n;
	vll v1(n);
	vll v2(n);
	FOR(i, 0, n) {
		ll x, y; cin >> x >> y;
		v1[i] = x + y;
		v2[i] = x - y;
	}
	sort(all(v1));
	sort(all(v2));
	ll ans = 0;
	ans = max(abs(v1[n - 1] - v1[0]) * 1LL, abs(v2[n - 1] - v2[0]) * 1LL);
	cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FASTio
	// START FROM HERE :)
	solve();
}

Measured memory_bytes: 6348
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int W;

	for(int t=1 ; scanf("%d", &W) , W ; t++ ){
		int n, v[1002]={0}, w[1002]={0};
		int dp[1002][1002] = {0};
		
		scanf("%d", &n);
		for(int i=0 ; i < n ; i++ ){
			scanf("%d,%d", &v[i] , &w[i] );
		}
		for(int i=0 ; i < n ; i++ ){
			for(int j=0 ; j <= W ; j++ ){
				if( j < w[i] ){
					dp[i+1][j] = dp[i][j];
				}else{
					dp[i+1][j] = max( dp[i][j] , dp[i][j-w[i]] + v[i] );
				}
			}
		}
		int total;
		for(int j=W ; j >= 0 ; j-- ){
			if( dp[n][W] == dp[n][j] ){
				total = j; 
			}
		}
		printf("Case %d:\n%d\n%d\n", t , dp[n][W] , total );
	}
}

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

using namespace std;

int main(){
  long n ,k;
  long a, b;
  cin >> n  >> k;
  map<long, long> ab;
  for(int i = 0; i < n; i++) {
    cin >> a >> b;
    auto itr = ab.find(a);
    if(itr != ab.end()) {
      itr->second = itr->second + b;
    } else {
      ab.insert(make_pair(a, b));
    }
  }
  for(auto const&[key, value] : ab) {
    if(k <= value) {
      cout << key << endl;
      break;
    } else {
      k -= value;
    }
  }
  return 0;
}


Measured memory_bytes: 7472
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
ab=t3(n-1)

d={i:[] for i in range(1,n+1)}
for a,b in ab:
    d[a].append(b)
    d[b].append(a)

l=list(d.items())
l.sort(key=lambda x:-len(x[1]))
m=len(l[0][1])

d2={line:0 for line in ab}
c={i:[] for i in range(1,n+1)}
for a1,list1 in l:
    color=1
    for b1 in list1:
        if a1>b1:
            a,b=b1,a1
        else:
            a,b=a1,b1
#         print(a,b)
        if d2[(a,b)]!=0:
            continue
        else:
            while color in c[a] or color in c[b]:
                color+=1 
            d2[(a,b)]=color
            c[a].append(color)
            c[b].append(color)
            color+=1
#     print(d2)
print(m)
for line in ab:
    print(d2[line])

Measured memory_bytes: 124756
#include <iostream>
#include <vector>
#include <set>
#include <utility>
using namespace std;

int main( void )
{
	int a, b;
	while ( cin >> a >> b && a > 0 && b > 0 )
	{
		vector < vector <int> > dp( b+1, vector <int>( a+1, 0 ) );
		dp[1][1] = 1;

		int n;
		cin >> n;

		set < pair<int,int> > C;

		for ( int i = 0; i < n; i++ )
		{
			int Xi, Yi;
			cin >> Xi >> Yi;

			C.insert( make_pair( Xi, Yi ) );
		}

		for ( int i = 1; i < b+1; i++ )
		{
			for ( int j = 1; j < a+1; j++ )
			{
				if ( i+1 < b+1 && C.find( make_pair( j, i+1 ) ) == C.end() )
				{
					dp[i+1][j] += dp[i][j];
				}
				if ( j+1 < a+1 && C.find( make_pair( j+1, i ) ) == C.end() )
				{
					dp[i][j+1] += dp[i][j];
				}
			}
		}

		cout << dp[b][a] << endl;

	}
	return 0;
}

Measured memory_bytes: 0
N, W = map(int, input().split())
dp_pv = [0]*(W+1)

for i in range(N):
    w, v = map(int, input().split())
    
    dp = [dp_pv[j] if w > j else max(dp_pv[j], dp_pv[j-w]+v) for j in range(W+1)]
    dp_pv = dp
    #print(dp)
    
print(dp[-1])
    

Measured memory_bytes: 120776
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> calc(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int num[3];
int main()
{
	set<int> s;
	rep(i, 3) {
		cin >> num[i];
		s.insert(num[i]);
	}
	if (s.size() == 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
vector<int>v;
bool isPresent(int n){
    for(int i=0;i<v.size();i++){
        if(v[i]==n) return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    int sum=0;
    while(t--){
        int n,t2;
        cin>>n>>t2;
        int c[n];
        int t[n];
        for(int i=0;i<n;i++){
            int c1,t1;
            cin>>c1>>t1;
            c[i]=c1;
            t[i]=t1;
        }
        int minh=t2;
        vector<int>v;
        for(int i=0;i<n;i++){
           if(minh>=t[i]) {v.pb(i);}
        }
        int min1=1e9;
        for(int i=0;i<v.size();i++){
            min1=min(min1,c[v[i]]);
        }
        if(v.empty())cout<<"TLE";
        else cout<<min1;
    }
}
    

Measured memory_bytes: 256
/*
    title: b_unplanned_queries.cpp
    author: Akhil
    date: 2020-09-23
    time: 07:59:13
*/

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;

int main()
{
    int n, m; cin >> n >> m; 
    vector<int> v(n); 
    for (size_t i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
        v[a - 1]++, v[b - 1]++; 
    }
    for (size_t i = 0; i < n; i++)
    {
        if (v[i] & 1) {cout << "NO" << endl; return 0;}
    }
    
    cout << "YES" << endl;
    return 0; 
}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> monhp(N);
    rep(i,N){
        cin >> monhp.at(i);
    }
    stable_sort(monhp.begin(),monhp.end(),greater<ll>());
    if(K!=0){
        int num = min(K,N);
        vector<ll> hissatu(num);
        copy(monhp.begin(),monhp.begin()+num,hissatu.begin());
        cout <<  accumulate(monhp.begin(),monhp.end(),0LL) - accumulate(hissatu.begin(),hissatu.end(),0LL) << endl;
    }else{
        cout <<  accumulate(monhp.begin(),monhp.end(),0LL) << endl;
    }
}




Measured memory_bytes: 6264
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)

int main(void){
    CIN_NO_SYNC;
    int n;
    stack<int> st;
    while(cin >> n){
        if(n == 0){
            cout << st.top() << endl;
            st.pop();
        } else {
            st.push(n);
        }
    }
    return 0;
}

Measured memory_bytes: 1200
import java.util.*;
import java.io.*;

public class Main {

  public static void main(String[] args) {

      Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int bill = 1000;
      int currAmount = 0;
      while (currAmount < N) {

          currAmount += bill;


      }
      System.out.println(currAmount-N);
  }

}


Measured memory_bytes: 35652
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n;
pair <int,int>a[53];
int main(){
	cin>>n;
	if (n==1){
		cout<<"1";return 0;
	}
	for (int i=1;i<=n;i++)
		cin>>a[i].first>>a[i].second;
	sort (a+1,a+n+1);
	int ans=1e9;
	for (int i=2;i<=n;i++)
		for (int j=1;j<i;j++){
			int q=a[i].first-a[j].first,p=a[i].second-a[j].second;
			int res=0;
			for (int k=1;k<=n;k++){
				int aa=a[k].first-q,bb=a[k].second-p;
				bool yes=0;
				for (int l=1;l<k;l++) if (a[l].first==aa && a[l].second==bb) yes=1;
				if (yes==0) res++;
			}
			ans=min(ans,res);
		}
	for (int i=1;i<=n;i++) a[i].first=-a[i].first;
	sort (a+1,a+n+1);
	for (int i=2;i<=n;i++)
		for (int j=1;j<i;j++){
			int q=a[i].first-a[j].first,p=a[i].second-a[j].second;
			int res=0;
			for (int k=1;k<=n;k++){
				int aa=a[k].first-q,bb=a[k].second-p;
				bool yes=0;
				for (int l=1;l<k;l++) if (a[l].first==aa && a[l].second==bb) yes=1;
				if (yes==0) res++;
			}
			ans=min(ans,res);
		}
	for (int i=1;i<=n;i++) a[i].second=-a[i].second;
	sort (a+1,a+n+1);
	for (int i=2;i<=n;i++)
		for (int j=1;j<i;j++){
			int q=a[i].first-a[j].first,p=a[i].second-a[j].second;
			int res=0;
			for (int k=1;k<=n;k++){
				int aa=a[k].first-q,bb=a[k].second-p;
				bool yes=0;
				for (int l=1;l<k;l++) if (a[l].first==aa && a[l].second==bb) yes=1;
				if (yes==0) res++;
			}
			ans=min(ans,res);
		}
	for (int i=1;i<=n;i++) a[i].first=-a[i].first;
	sort (a+1,a+n+1);
	for (int i=2;i<=n;i++)
		for (int j=1;j<i;j++){
			int q=a[i].first-a[j].first,p=a[i].second-a[j].second;
			int res=0;
			for (int k=1;k<=n;k++){
				int aa=a[k].first-q,bb=a[k].second-p;
				bool yes=0;
				for (int l=1;l<k;l++) if (a[l].first==aa && a[l].second==bb) yes=1;
				if (yes==0) res++;
			}
			ans=min(ans,res);
		}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int a, b, c, k, ans;

	scanf("%d%d%d%d", &a, &b, &c, &k);

	if (a >= k) {
		ans = k;
	}
	else if (a + b >= k) {
		ans = a;
	}
	else {
		ans = a - (k - a - b);
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 3828
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        String t;
        while((t=buf.readLine())!=null){
            String str[]=t.split(" ");
            int x=Integer.parseInt(str[0]);
            int y=Integer.parseInt(str[1]);
         
                System.out.println((int)Math.log10(x+y)+1);
            }
        }
    }

Measured memory_bytes: 24380
var  s:ansistring;
     i,j,k,l,f,n:longint;
     x:boolean;
begin
  readln(s);
  f:=1;  n:=1;
  while  s[f]=' '  do  inc(f);
  write(s[f]);
  for  i:=f+1  to  length(s) do
    begin
      if  s[i]=' '  then
        begin
          x:=true;
          continue;
        end;
      if  x  then
        begin
          write(s[i]);
          inc(n);
          if  n=3  then  break;
          x:=false;
        end;
    end;
  writeln;
end.


Measured memory_bytes: 128
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (x, y) = input_tuple();
    if y > x * 4 || y < x * 2 {
        println!("No");
    } else if y % 2 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
} 


Measured memory_bytes: 2128
#include <iostream>

using namespace std;

int main()
{   
 
   int a,cnt = 0;
   cin >> a;

   for(int i = 0;i<a;i++)
   {
       cnt += i+1;
   }
    cout << cnt << endl;
    return 0;


   /*
   int k,x,y,n,sum = 0;

   cin >> n >> k >> x >> y;
   for(int i = 0;i<k;i++)
   {
       sum += x;
   }

    for(int i = 0;n-k>i;i++)
    {
        sum+=y;
    }

    cout << sum << endl;

    return 0;
    */



}


Measured memory_bytes: 256
#include <stdio.h>

typedef long long LL;

LL gcd(LL x, LL y) {
    return y ? gcd(y, x % y) : x;
}

LL lcm(LL x, LL y) {
    return x/gcd(x, y)*y;
}

int main()
{
    LL x, y;

    while (scanf("%ld %ld", &x, &y) != EOF) {
        printf("%lld %lld\n", gcd(x, y), lcm(x, y));
    }

    return 0;
}

Measured memory_bytes: 1800
n = int(input())
a = [0] * n
for i in range(n): a[i] = int(input()) - 1
i = 0
c = 1
ok = False
s = set()
while a[i] != 1:
    c += 1
    if i in s:
        c = -1
        break;
    s.add(i)
    i = a[i]
print(c)


Measured memory_bytes: 13164
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(2e5) + 5;
const int mod = 1e9 + 7;
const int inv = 500000004;//1/2 mod 10^9 + 7
int p2[N];
vi g[N];
deque < pair < pii , int > > D[N];
pair < pii , int > add(pair < pii , int > a,pair < pii , int > b)
{
    pair < pii , int > ans;
    ans.fi.fi = 1ll * a.fi.fi * b.fi.fi % mod;
    ans.fi.se = (1ll * a.fi.fi * b.fi.se + 1ll * b.fi.fi * a.fi.se) % mod;
    ans.se = ((mod - ans.fi.fi) + (mod - ans.fi.se) + 1) % mod;
    return ans;
} //the long merge function....
int Merge(int & a,int & b)//merge in O(min(D[a].size(),D[b].size()))
{
    if (D[a].size() < D[b].size())
        swap(a,b);
    int sz = D[b].size();
    for (int i = 0;i < sz;++i)
        D[a][i] = add(D[a][i],D[b][i]);
    D[b].clear();
    return sz;
}
int cnt[N];
int dfs(int node,int dep)
{
    ++cnt[dep];
    int sz = 0;
    int d = node;
    int SZ = 0;
    for (auto it : g[node])
    {
        int nxt = dfs(it,dep + 1);
        smax(SZ,Merge(d,nxt));
    }
    for (int i = 0;i < SZ;++i)
        D[d][i].fi.fi += D[d][i].se,D[d][i].se = 0;//third dimension goes into the first one after we merged everything
    D[d].push_front(mp(mp(inv,inv),0));//add a new height and automatically increase the
    return d;
}
int main(void)
{
    int n;
    cin>>n;
    for (int i = 1;i <= n;++i)
    {
        int p;
        cin>>p;
        g[p].pb(i);
    }
    auto d = D[dfs(0,0)];
    int ans = 0;
    while (!d.empty())
        (ans += d.front().fi.se) %= mod,d.pop_front();
    for (int i = 1;i <= n + 1;++i)
        ans = (ans + ans) % mod;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 163712
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    cum = [[0]*(W+1) for _ in range(H+1)]
    for i in range(1,H+1):
        for j in range(1,W+1):
            cum[i][j]=cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+int(S[i-1][j-1])
    ans = 2000
    for p in product([0,1],repeat=H-1):
        line = [0]
        p = list(p)
        cnt = sum(p)
        for i in range(1,H):
            if p[i-1]==1:
                line.append(i)
        line.append(H)
        w_s = 0
        w_e = 1
        b = False
        while w_e <= W:
            for i in range(len(line)-1):
                h_s = line[i]
                h_e = line[i+1]
                white = cum[h_e][w_e]+cum[h_s][w_s]-cum[h_e][w_s]-cum[h_s][w_e]
                if white > K:
                    if w_e == w_s+1:
                        b = True
                        break
                    else:
                        w_s = w_e-1
                        cnt += 1
                        break
            if b==True:
                break
            w_e += 1
        else:
            ans = min(ans,cnt)
    return ans
print(solve())


Measured memory_bytes: 9408
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#define rep(i,n) for (int i=0; i<n;++i)
int N,K;
vector<int> kouho;
queue<int> que;

int bfs() {
  int k = que.front(); que.pop();
  while(k<N && k<10000) {
    for(auto p: kouho) que.push(k*10+p);
    k = que.front(); que.pop();
  }
  return k;
}
bool D[10];
int main() {
  cin >> N >> K;
  int d;
  rep(i, K) {
    cin >> d;
    D[d] = true;
  }
  
  rep(i, 10) {
    if (!D[i]) {
      kouho.push_back(i);
      if (i>0) que.push(i);
    }
  }
  cout << bfs() << endl;
}


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

int main() {
	long long n,k,ans,a,b;
	cin>>n>>k;
	if(k%2==0){
	    a=n/k;
	    b=(n+(k/2))/k;
	    ans=(a*a*a)+(b*b*b);
	}
	else{
	    a=n/k;
	    ans=a*a*a;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(int a, int b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin>>s;
	int ac_g=0,ac_p=0,win=0,lose=0;
	int n=s.size();
	rep(i,n){
		if(s[i]=='g'){
			if(ac_p<ac_g){
				ac_p++;
				win++;
			}else{
				ac_g++;
			}
		}else{
			if(ac_p<ac_g){
				ac_p++;
			}else{
				ac_g++;
				lose++;
			}
		}
		
	}
	cout<<win-lose<<endl;

}

Measured memory_bytes: 512
words = []
N = int(input())
flag = True

words.append(input())

for _ in range(N-1):
    w = input()
    if w not in words and words[-1][-1] == w[0]:
        words.append(w)
    else:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
main()
{
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int q;cin>>q;
    for(int i=0;i<q;i++)
    {
        int k;cin>>k;
        int K=*lower_bound(a.begin(),a.end(),k);
        cout<<(k==K)<<endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1010;
bool w[N];
double dis[N];
int a[N],b[N],c[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline double D(int x,int y) {
    return max(0.0,sqrt(1LL*(a[x]-a[y])*(a[x]-a[y])+1LL*(b[x]-b[y])*(b[x]-b[y]))-c[x]-c[y]);
}
int main() {
    int n;
    cin>>a[1]>>b[1]>>a[2]>>b[2]>>n,n+=2;
    for(int i=3;i<=n;i++) a[i]=gi(),b[i]=gi(),c[i]=gi();
    for(int i=2;i<=n;i++) dis[i]=1e100;
    dis[0]=1e100;
    while(1) {
	int x=0;
	for(int i=1;i<=n;i++)
	    if(!w[i]&&dis[i]<dis[x]) x=i;
	if(x==2) return printf("%.10f",dis[x]),0;
	w[x]=1;
	for(int i=1;i<=n;i++)
	    if(!w[i]) dis[i]=min(dis[i],dis[x]+D(x,i));
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{int a,b,c;
 scanf("%d %d",&a,&b);
 c=0;
  if(a>b) {c=c+a;
           a--;}
 else {c=c+b;
           b--;}
 if(a>b) {c=c+a;
           a--;}
 else {c=c+b;
           b--;}
 printf("%d",c);

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;

int n,ans=0;
int a[100005],b[100005],c[100005];

int p[100005][205];

signed main()
{
	cin>>n;
	n++;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	b[1]=1,c[n]=a[n];
	for (int i=2;i<=n;i++)  b[i]=(b[i-1]-a[i-1])*2;
	for (int i=n-1;i>=1;i--)  c[i]=c[i+1]+a[i];
	for (int i=1;i<=n;i++)  ans+=min(b[i],c[i]);
	for (int i=1;i<=n;i++)
	{
		if (a[i]>b[i])  return cout<<-1<<endl,0;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
int dfs(vector<int>adj[],int i,vector<int>&dp)
{
    if(adj[i].size()==0)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    int ans=0;
    for(int it=0;it<adj[i].size();it++)
    {
        ans=max(ans,1+dfs(adj,adj[i][it],dp));
    }
    return dp[i]=ans;
}
int main(){
int n,e,x,y,i;
cin>>n>>e;
map<int,int>m;
vector<int>dp(n+1,-1);
vector<int>adj[n+1];
int res=0;

for(i=0;i<e;i++)
{
    cin>>x>>y;
    adj[x].push_back(y);
    m[x]=1;
    
}
for(i=1;i<=n;i++)
{
    if(m.find(i)!=m.end()&&dp[i]==-1)
    {
        res=max(res,dfs(adj,i,dp));
    }
}cout<<res<<endl;
}


Measured memory_bytes: 13568
#include <stdio.h>


int main(void)
{
	//変数の宣言
	int n,k;
	int ans;
	
	//データの読み込み
	scanf("%d %d",&n,&k);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	ans=(n+k-3)/(k-1);
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int p,q,r;
    cin >> p >> q >> r;

    cout << min({p + q, p + r, q + r}) << endl;
}


Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

DEPMAX = 5

def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret

n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
mn = min([cs[x] for x in a])
for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a)
print(foo(n,0))


Measured memory_bytes: 69592
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define pb(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;



int main() {
	int n, q, t = 0;
	cin >> n >> q;
	queue < pair<string, int> > a, ans;
	REP(i, n) {
		string s;
		cin >> s;
		int b;
		cin >> b;
		a.push(make_pair(s, b));
	}
	while (!a.empty()) {
		int c = a.front().second;
		c-=q;
		if (c <= 0) {
			t += a.front().second;
			ans.push(make_pair(a.front().first, t));
			a.pop();
		}
		else {
			t += q;
			pair<string, int> d = make_pair(a.front().first, a.front().second - q);
			a.pop();
			a.push(d);
		}
	}
	REP(i, n) {
		cout << ans.front().first << " " << ans.front().second << endl;
		ans.pop();
	}

	return 0;
}

Measured memory_bytes: 6124
long B[3<<17],a,r,H,I;h[2<<17],i,j;main(n){for(scanf("%d",&n);i<n;)scanf("%d",h+i++);for(;~scanf("%d",&a);r=0){for(I=H=h[j++];H;H-=H&-H)r=fmax(r,B[H]);for(;I<3<<17;I+=I&-I)B[I]=fmax(B[I],a+r);}printf("%ld",B[2<<17]);}

Measured memory_bytes: 3840