akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

const int B = 600;
const string s = "RYGB";


int h, w, d;

char ans[510][510];

int main(){

  h = in();
  w = in();
  d = in();

  REP( i , h ){
    REP( j , w ){
      int x = i + j + B;
      int y = i - j + B;
      x /= d;
      y /= d;
      bool f = x % 2 == 0;
      bool g = y % 2 == 0;
      if( f && g ){
        ans[i][j] = s[0];
      } else if( f && !g ){
        ans[i][j] = s[1];
      } else if( !f && g ){
        ans[i][j] = s[2];
      } else {
        ans[i][j] = s[3];
      }
    }
  }

  /*
  REP( i , h ){
    REP( j , w ){
      REP( k , h ){
        REP( l , w ){
          int x = abs( i - k ) + abs( j - l );
          if( x == d ){
            assert( ans[i][j] != ans[k][l] );
          }
        }
      }
    }
  }
  */

  REP( i , h ){
    REP( j , w ){
      printf( "%c", ans[i][j] );
    }
    printf( "\n" );
  }
  
  return 0;
}


Measured memory_bytes: 768
// abc160_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;

    ll ans = 0;
    ll a = N / 500;
    ans += a * 1000;

    N %= 500;
    ll b = N / 5;
    ans += b * 5;

    print(ans);



    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{Read, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut S = String::new();
    stdin.read_to_string(&mut S).unwrap();
    let S = S.trim().parse::<i32>().unwrap();

    let h = S / 60i32.pow(2);
    let m = S % 60i32.pow(2) / 60;
    let s = S % 60i32.pow(2) % 60;

    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5028
N = int(input())
t = list(input())
Ans = ['n' for _ in t]
 
def judge(prevSW, SW, ox):
    if SW == 'S':
        if ox == 'o':
            return prevSW
        else:
            if prevSW == 'S':
                return 'W'
            else: return 'S'
    elif SW == 'W':
        if ox == 'x':
            return prevSW
        else:
            if prevSW == 'S':
                return 'W'
            else: return 'S'
 
def decideorder(startSW):
    Ans[1] = startSW
    for i in range(2,N):
        Ans[i] = judge(Ans[i-2], Ans[i-1], t[i-1])

def check():
    if judge(Ans[-2], Ans[-1], t[-1]) is Ans[0] and judge(Ans[-1], Ans[0], t[0]) is Ans[1]:
        return True
    else:
        return False

Ans[0] = 'S'
decideorder('S')
if check():
    print("".join(Ans))
else:
    decideorder('W')
    if check():
        print("".join(Ans))
    else:
        Ans[0] = 'W'
        decideorder('S')
        if check():
            print("".join(Ans))
        else:
            decideorder('W')
            if check():
                print("".join(Ans))
            else:
                print(-1)

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

int main(){
int n,p;
int c[50];
for(;;){
cin >> n >> p;
if(!n && !p)break;
for(int i=0;i<n;i++)c[i] = 0;

int pos = -1;
for(;;){
pos = (pos+1)%n;
if(p){
c[pos]++;
p--;
}else{
p = c[pos];
c[pos] = 0;
}
if(!p){
int cnt = 0;
for(int i=0;i<n;i++)
if(c[i])cnt++;
if(cnt==1)break;
}
}
cout << pos << endl;
}
}

Measured memory_bytes: 0
#include<stdio.h>
#define W 0
#define G 1
#define B 2
#define N 100
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_cisit(int u){
  int v;
  color[u]=G;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==W){
      dfs_cisit(v);
    }
  }
  color[u]=B;
  f[u]=++tt;
}
void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=W;
  }
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==W)dfs_cisit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
  scanf("%d%d",&u,&k);
  u--;
  for(j=0;j<k;j++){
    scanf("%d",&v);
    v--;
    M[u][v]=1;
  }
}
dfs();
return 0;
}



Measured memory_bytes: 2052
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 50128
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    auto H = new int[][](N);
    auto D = new int[](N);
    foreach (i, p; readln.split.map!(to!int).enumerate) {
        G[p-1] ~= i.to!int;
        H[i] ~= p-1;
        D[p-1] += 1;
    }
    auto A = new int[](N);
    fill(A, -1);

    
    int mex(int n) {
        auto X = G[n].map!(j => A[j]).filter!"a >= 0".array.sort().uniq().array;
        int m = X.length.to!int;
        foreach (i; 0..X.length.to!int) {
            if (i != X[i]) {
                m = i;
                break;
            }
        }
        return m;
    }

    bool check() {
        return N.iota.map!(i => mex(i) == A[i]).all;
    }
    
    void dfs(int n) {
        A[n] = mex(n);
        foreach (m; H[n]) {
            D[m] -= 1;
            if (D[m] == 0 && A[m] == -1) {
                dfs(m);
            }
        }
    }


    
    foreach (i; 0..N) {
        if (D[i] == 0 && A[i] == -1) {
            dfs(i);
        }
    }

    if (!A.canFind(-1)) {
        writeln(check ? "POSSIBLE" : "IMPOSSIBLE");
        return;
    }

    foreach (i; 0..N) {
        if (A[i] == -1) {
            int k = -1;
            foreach (j; H[i]) if (A[j] == -1) k = j;
            
            int m = mex(i);
            auto AA = new int[](N);
            auto DD = new int[](N);
            foreach (j; 0..N) AA[j] = A[j], DD[j] = D[j];
            A[i] = m;
            dfs(k);
            if (check) {
                writeln("POSSIBLE");
                return;
            }
            
            foreach (j; 0..N) A[j] = AA[j], D[j] = DD[j];
            auto X = G[i].map!(j => A[j]).filter!"a >= 0".array ~ m;
            X = X.sort().uniq().array;
            m = X.length.to!int;
            foreach (j; 0..X.length.to!int) {
                if (j != X[j]) {
                    m = j;
                    break;
                }
            }
            A[i] = m;
            dfs(k);
            if (check) {
                writeln("POSSIBLE");
                return;
            }
            break;
        }
    }

    writeln("IMPOSSIBLE");
}



Measured memory_bytes: 41512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = ReadIntArray();
            var N = r[0];
            var M = r[1];
            List<int[]> positions = new List<int[]>();
            for (int i = 0; i < N; i++)
            {
                positions.Add(ReadIntArray());
            }
            List<int[]> checkPos = new List<int[]>();
            for (int i = 0; i < M; i++)
            {
                checkPos.Add(ReadIntArray());
            }

            int[] retList = new int[N];
            for (int i = 0; i < N; i++)
            {
                double distance = double.MaxValue;
                for (int j = 0; j < M; j++)
                {
                    var tmpDistance = Math.Abs(positions[i][0] - checkPos[j][0]) +
                                      Math.Abs(positions[i][1] - checkPos[j][1]);
                    if (tmpDistance < distance)
                    {
                        distance = Math.Min(distance, tmpDistance);
                        retList[i] = j + 1;
                    }
                }
            }

            foreach (var item in retList)
            {
                Console.WriteLine(item);
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

int main() {
    string s;
    cin >> s;
    string res = "yes";
    for (int i = 0; i < s.size() - 1; i++) {
        for (int j = i + 1; j < s.size(); j++) {
            if (s.at(i) == s.at(j)) res = "no";
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; while(t--)
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);


   ll n,l,i,j,k;
   string a[1000];
   cin>>n>>l;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   for(i=0;i<n;i++)
   {
       cout<<a[i];
   }
   cout<<endl;
   return 0;
}


Measured memory_bytes: 3688
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main(void)
{
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

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

  int n;
  cin>>n;

int aux1 = n/100;
int aux2 = n%100;
if(aux1>=1 && aux1<=12){
    //MMYY || Ambi
    if(aux2>=1 && aux2<=12){
        cout<<"AMBIGUOUS"<<endl;
    }else{
        cout<<"MMYY"<<endl;
    }
}else{
    //YYMM || NA
    if(aux2>=1 && aux2<=12){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
}

return 0;




}


Measured memory_bytes: 3624
#include<stdio.h>

int main( int argc, char* argv[] )
{
		int total_a, total_b;
		int cards;
		int i;
		int a, b;
		
		scanf( "%d", &cards );
		while( cards != 0 ){
				total_a = total_b = 0;
				for( i = 0; i<cards; i++ ){
						scanf( "%d %d", &a, &b );
						if( a > b ){
								total_a += a + b;
						}else if( a < b ){
								total_b += a + b;
						}else{
								total_a += a;
								total_b += b;
						}
				}
				printf( "%d %d\n", total_a, total_b );
				scanf( "%d", &cards );
		}

		return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll = long long;
using namespace std;
int main(){
    ll n,m;
    cin >> n >> m;
    if(m/2<=n){
        cout<<m/2<<endl;
        return 0;
    }
    cout<<n+(m-2*n)/4<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
if N%2:
    for i in range(1, M+1):
        print(i, N-i)
else:
    for i in range(1, M+1):
        if i <= (N//2)//2:
            print(i, N-i+1)
        else:
            print(i+1, N-i+1)


Measured memory_bytes: 75472
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
   int a,b;
   double A,B;
   double GCD,LCM;
   double z;
   
   while(cin>>A>>B){
      if(A<B){
         z = A;
         A = B;
         B = z;
      }
      a = static_cast<int>(A);
      b = static_cast<int>(B);
   
      while(1){
         if(a%b == 0){
            GCD = static_cast<double>(b);
            break;
         }
         z = a%b;
         a = b;
         b = z;
      }
      LCM = A*B/GCD;
      
      printf("%.0lf %.0lf\n",GCD,LCM);
   }
   return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>

int main(){
   int H, W;
   std::cin >> H >> W;
   std::vector<std::string> a(H);
   for(int i=0; i<H; ++i){
      std::string tmp;
      std::cin >> tmp;
      a[i] = tmp;
   }

   std::vector<bool> row(H);
   std::vector<bool> column(W);
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 if(a[i][j] == '#') {
	    row[i] = true;
	    column[j] = true;
	 }
      }
   }
      
   for(int i=0; i<H; ++i){
      if(row[i]){ 
	 for(int j=0; j<W; ++j){
	    if(column[j]){
	       std::cout << a[i][j];
	    }
	 }
	 std::cout << std::endl;
      }
   }

   return 0;
}


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

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

  for(int i = 0; i < N - 1;){
    if(A[i] < A[i+1]) {
      ++i;
      ++ans;
      while(i < N && A[i] <= A[i+1]) ++i;
      ++i;
    }

    if(A[i] > A[i+1]) {
      ++i;
      ++ans;
      while(i < N && A[i] >= A[i+1]) ++i;
      ++i;
    }

    if(A[i] == A[i+1]) ++i;
  }
  if(ans == 0) ++ans;
  cout << ans << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
const int N=2e5+5;
const int mod=1e9+7;

int main(){
    int x;
    scanf("%d",&x);
    printf("%.20f",x*4*asin(1));

return 0;
}


Measured memory_bytes: 3816
#include <fstream>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, A, B, C, ct0;
string alpha = "ABC";
int arr [3];
string mvs [100000];
char ans [100000];

// Helper Functions

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    F0R(i,3) {cin >> arr[i]; ct0 += !arr[i];}
    F0R(i,N) cin >> mvs[i];

    F0R(i,N) {
        int a = mvs[i][0]-'A', b = mvs[i][1]-'A';
        // cout << arr[0] << ' ' << arr[1] << ' '  << arr[2] << '\n';
        int miss = 3 - a - b;
        if (arr[miss] || i == N-1) {
            if (arr[a]) {arr[a]--; arr[b]++; ans[i] = alpha[b];}
            else if (arr[b]) {arr[a]++; arr[b]--; ans[i] = alpha[a];}
            else {cout << "No\n"; return 0;}
        } else {
            if (arr[b] && (!arr[a] || mvs[i+1][0]-'A' == a || mvs[i+1][1]-'A' == a)) {arr[b]--; arr[a]++; ans[i] = alpha[a];}
            else if (arr[a] && (!arr[b] || mvs[i+1][0]-'A' == b || mvs[i+1][1]-'A' == b)) {arr[a]--; arr[b]++; ans[i] = alpha[b];}
            else {cout << "No\n"; return 0;}
        }
    }
    cout << "Yes\n";
    F0R(i,N) cout << ans[i] << '\n';
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;


#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int a,b,c,x,y; cin >> a >> b >> c >> x >> y;
  int z = min(x,y); x -= z; y -= z;
  int ans = z * min(a + b, 2 * c);
  if(x > 0){
    ans += x * min(a, 2 * c);
  }else if(y > 0){
    ans += y * min(b, 2 * c);
  }
  cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 8002

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;

#define maxn 200005

int ask(i64 n)
{
    printf("? %lld\n",n) ;
    fflush(stdout) ;
    char s[5] ;
    scanf("%s",s) ;
    return (s[0]=='Y') ;
}

int findLength1()
{
    i64 st = 1 ;
    int len = 0 ;

    while( 1 )
    {
        int res = ask(st) ;
        if( res )
        {
            len++ ;
            st = st*10 ;
        }
        else break ;
    }
    return len ;
}

int findLength2()
{
    i64 st = 9 ;
    int len = 0 ;
    while( 1 )
    {
        int res = ask(st) ;
        len++ ;
        if( res == 0 )
        {
            st = st*10 + 9 ;
        }
        else break ;
    }
    return len ;
}

int main()
{
    int res = ask(555555555555LL) ;

    int len ;

    if(res) len = findLength2() ;
    else len = findLength1() ;

    i64 lo = 1 , hi ;

    for(int i=1 ; i<len ; i++) lo = lo*10 ;

    hi = 10*lo - 1 ;

//    printf("%d %lld %lld\n",len,lo,hi) ;

    while( lo < hi )
    {
        i64 mid = (lo+hi)/2 ;

        int res = ask(mid*10) ;

        if(res) hi = mid ;
        else lo = mid+1 ;
    }

    printf("! %lld\n",lo) ;

    return 0 ;
}


Measured memory_bytes: 596
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if(abs(a-c)<=d or abs(a-b)<=d and abs(b-c)<=d) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >> a >> b >>c;
  if ((100*a+10*b+c)%4==0){
      cout << "YES" << endl;
  }else{
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
N, K, S = map(int, input().split())
L = []
if (S < 10**9):
    for i in range(K):
        L.append(str(S))
    for i in range(N - K):
        L.append(str(S + 1))
elif (S == 10 ** 9):

    for i in range(K):
        L.append(str(S))
    for i in range(N - K):
        L.append(str(1))
print(' '.join(L))


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

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld",&n);

        if(n%2==1)printf("0\n");
        else
        {

            fr=5;

            while(1)
            {
                sc=fr*2;

                if(sc>n)break;

                ans=ans+(n/sc); fr=fr*5;

            }

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

        }






    return 0;
}





Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll ans=0,mark=1;
    for(ll i=0;i<n;i++)
    {
        if(a[i]==mark)
            mark++;
        else 
            ans++;
    }
    if(mark>1)
        cout<<ans;
    else
        cout<<"-1";
}

Measured memory_bytes: 1792
N = int(input())
nums = list(map(int, input().split()))

d4 = 0
d2 = 0
d0 = 0
for n in nums:
    if n % 4 == 0:
        d4 += 1
    elif n % 2== 0:
        d2 += 1
    else:
        d0 += 1

if d2 > 0 and d0 <= d4:
    print('Yes')
elif d2 == 0 and d0 <= d4+1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x = c-a,y = d-b;
    string ans = "";
    rep(i,x) ans += 'R';
    rep(i,y) ans += 'U';
    
    rep(i,x) ans += 'L';
    rep(i,y) ans += 'D';
    
    ans += 'D';
    rep(i,x+1) ans += 'R';
    rep(i,y+1) ans += 'U';
    ans += 'L';
    
    ans += 'U';
    rep(i,x+1) ans += 'L';
    rep(i,y+1) ans += 'D';
    ans += 'R';
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int w, h, n;
  scanf("%d %d %d", &w, &h, &n);
  int l = 0, r = w, t = h, b = 0;
  for (int i = 0; i < n; ++i)
  {
    int x, y, a;
    scanf("%d %d %d", &x, &y, &a);
    switch (a)
    {
      case 1:
        if (l < x) l = x;
        break;
      case 2:
        if (r > x) r = x;
        break;
      case 3:
        if (b < y) b = y;
        break;
      case 4:
        if (t > y) t = y;
        break;
    }
  }
  
  printf("%d\n", (l < r && b < t) ? (r - l) * (t - b) : 0);
  return 0;
}

Measured memory_bytes: 128
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N, X = i_map()
    A = i_list()

    ans = [A[0]]
    cnt = 0

    for i,k in enumerate(A[1:]):
        t = k + ans[i]
        if t <= X:
            ans.append(k)
        else:
            if k - (t-X) >= 0:
                cnt += t - X
                ans.append(k - (t-X))
            else:
                cnt += t - X
                ans[-1] += k - (t-X)
                ans.append(0)
    print(cnt)











if __name__=="__main__":
    main()


Measured memory_bytes: 85976
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

R, G, B, N = map(int, input().split())

ans = 0
for r in range(0, (N // R) + 1):
    for g in range(0, ((N - r * R) // G) + 1):
        if (N - r * R - g * G) % B == 0:
            ans += 1
print(ans)


Measured memory_bytes: 79912
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const int MAX_BANK = 100010;

int main() {
	ll dp[MAX_BANK];
	rep(i, MAX_BANK)dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < MAX_BANK; i++) {
		for (int out6 = 1; i + out6 <= MAX_BANK; out6 *= 6) {
			dp[i + out6] = min(dp[i + out6], dp[i] + 1);
		}
		for (int out9 = 1; i + out9 <= MAX_BANK; out9 *= 9) {
			dp[i + out9] = min(dp[i + out9], dp[i] + 1);
		}
	}
	int n;
	cin >> n;
	cout << dp[n] << endl;
	return 0;
}


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

int main() {
  int N, a, b;
  cin >> N >> a >> b;
  
  int answer = 0;
  
  for (int i = 1; i <= N; i ++){
    int i2 = i;
    int n = 0;
    while (i2 != 0){
     n+= i2%10;
     i2 /=10;
    }
    if ((n >= a) && (n <= b)) answer += i;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
l,r = map(int,input().split())
minimum = 2019
for i in range(l,r+1):
  if minimum == 0:
    break
  for j in range(i+1,r+1):
    if (i*j)%2019 == 0:
      minimum = 0
      break
    else:
      if (i*j)%2019 < minimum:
        minimum = (i*j)%2019
print(minimum)


Measured memory_bytes: 9176
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
const ll MAX_N = 3000;
/**/
int main() {
	// 入力
	ll S,W;cin>>S>>W;
	

	//出力
	if (S<=W) printf("unsafe\n");
	else printf("safe\n");
}


Measured memory_bytes: 3644
/* ex3_4
    suuxxu */

#include <stdio.h>

int main(void){
    int n, i, answer;
    
    // get inputs
    scanf("%d", &n);

    // calculate answer
    answer = 0; // answer is no
    for(i = 1; i < 10; i++){ // divide by 1 to 9
        if(n / i < 10 && n % i == 0){ // if divisible by i and Quotient is less than 10
            answer = 1; // answer is yes
        }
    }

    // output answer
    if(answer == 1){ // if answer is yes
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int main() {
	int sx, sy, tx, ty;
	int nowx, nowy;
	vector<string> v;
	cin >> sx >> sy >> tx >> ty;
	nowx = sx, nowy = sy;
	while (nowy != ty) {
		v.push_back("U");
		nowy += 1;
	}
	while (nowx != tx) {
		v.push_back("R");
		nowx += 1;
	}
	/*
	v.push_back(" t1 ");
	print(nowx);
	print(nowy);
	*/
	while (nowy != sy) {
		v.push_back("D");
		nowy -= 1;
	}
	while (nowx != sx) {
		v.push_back("L");
		nowx -= 1;
	}/*
	v.push_back(" s2 ");
	print(nowx);
	print(nowy);
	*/
	v.push_back("L");
	nowx -= 1;
	while (nowy != ty+1) {
		v.push_back("U");
		nowy += 1;
	}
	while (nowx != tx) {
		v.push_back("R");
		nowx += 1;
	}
	v.push_back("D");
	nowy -= 1;
	/*
	v.push_back(" t2 ");
	print(nowx);
	print(nowy);
	*/
	//if (nowx == tx&&nowy == ty)print("!!");
	v.push_back("R");
	nowx += 1;
	while (nowy != sy-1) {
		v.push_back("D");
		nowy -= 1;
	}
	while (nowx != sx) {
		v.push_back("L");
		nowx -= 1;
	}
	v.push_back("U");
	nowy += 1;
	/*
	print(nowx);
	print(nowy);
	*/
	//if (nowx == sx&&nowy == sy)print("!!");
	rep(i, 0, v.size())cout << v[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
C = []
for i in range(10):
    tmp = LIST()
    C.append(tmp)
A = []
for i in range(H):
    tmp = LIST()
    A.append(tmp)
    

def warshall_floyd(d, N):
    # d[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

C = warshall_floyd(C, 10)

ans = 0

for i in range(H):
    for j in range(W):
        if A[i][j] != -1 and A[i][j] != 1:
            ans += C[A[i][j]][1]
print(ans)


Measured memory_bytes: 5960
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    dg = 10**10
    lr = []
    for _ in [0]*n:
        lll,rrr = map(int,input().split())
        lr.append(lll*dg+rrr)
    lr.sort()

    #mirl[i],marl[i]:R0~Riのmin,max
    mirl = [10**10]*n
    marl = [0]*n
    for i,e in enumerate(lr):
        mirl[i] = min(mirl[i-1],e%dg)
        marl[i] = max(marl[i-1],e%dg)
    
    #mirr[i]:Ri~Rn-1のmin
    mirr = [0]*n
    mirr[-1] = lr[-1]%dg
    for i in range(n-2,-1,-1):
        mirr[i] = min(mirr[i+1],lr[i]%dg)

    L1 = lr[-1]//dg
    res = (lr[0]%dg - lr[0]//dg+1) + max(0,mirr[1]-L1+1)

    for k in range(n-2,0,-1):
        #print(res)
        L2 = lr[k]//dg
        R1 = mirr[k+1]
        R2 = lr[k]%dg

        restMaxR = marl[k-1]
        restMinR = mirl[k-1]

        #print(L1,L2,R1,R2,restMaxR,restMinR)

        tmp = max(0,R1-L1+1) + max(0,min(restMinR,R2)-L2+1)
        tmp = max(tmp,max(0,min(restMinR,R1)-L1+1) + max(0,R2-L2+1))

        res = max(res,tmp)

    
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56668
#include <iostream>
#include <math.h>
using namespace std;

int N;
int M;

int main() {
  cin >> N >> M;
  int A[M];
  int sum=0;
  for(int i=0;i<M;i++){
    cin >>A[i];
    sum+=A[i];
  }
  if(sum >N){
    cout << -1 << endl;
  }else{
    cout << N-sum << endl;
  }
}

Measured memory_bytes: 3176
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll A,B;
    cin >> A >> B;
    ll out = -1;
    if(A<10 && B<10) out = A*B;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    long long a[3*n]; rep(i,3*n) cin>>a[i];
    long long sumL[n+1]={},sumR[n+1]={};
    priority_queue<long long,vector<long long>,greater<long long>> pqL;
    rep(i,n){
        pqL.push(a[i]);
        sumL[0]+=a[i];
    }
    for(int i=1;i<n+1;i++){
        pqL.push(a[n-1+i]);
        long long sub=pqL.top(); pqL.pop();
        sumL[i]=sumL[i-1]+a[n-1+i]-sub;
    }
    priority_queue<long long,vector<long long>> pqR;
    reverse(a,a+3*n);
    rep(i,n){
        pqR.push(a[i]);
        sumR[0]+=a[i];
    }
    for(int i=1;i<n+1;i++){
        pqR.push(a[n-1+i]);
        long long sub=pqR.top(); pqR.pop();
        sumR[i]=sumR[i-1]+a[n-1+i]-sub;
    }
    reverse(sumR,sumR+n+1);
    long long ans=-LINF;
    rep(i,n+1){
        // cout<<sumL[i]<<" "<<sumR[i]<<endl;
        ans=max(ans,sumL[i]-sumR[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6516
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, A, B = map(int, readline().split())
  S = input()
  L = len(S)
  cnt_AB = 0
  cnt_B = 0
  for i in range(L):
    s = S[i]
    if s == 'a':
      if cnt_AB < A + B:
        print('Yes')
        cnt_AB += 1
      else:
        print('No')
    elif s == 'b':
      if cnt_AB<A+B and cnt_B<B:
        print('Yes')
        cnt_AB += 1
        cnt_B += 1
      else:
        print('No')
    else:
      print('No')
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 4144
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}


void solve()
{
	int n,m;
	cin >> n >> m;
	if(m < n)
		cout << "No" << ln;
	else
		cout << "Yes" << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	clock_t start,stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for(int tc = 1;tc < t + 1;tc++) solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string O, E;
    cin >> O;
    cin >> E;

    if (O.size() == E.size()) {
        for (int i = 0; i < E.size(); ++i) {
            cout << O[i] << E[i];
        }
        cout << endl;
    }
    else if (O.size() > E.size()) {
        for (int i = 0; i < E.size(); ++i) {
            cout << O[i] << E[i];
        }
        cout << O[O.size()-1] << endl;
    } else {
        for (int i = 0; i < O.size(); ++i) {
            cout << O[i] << E[i];
        }
        cout << E[E.size()-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()

for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
        ans += 1
print(ans)

Measured memory_bytes: 6476
while 1 :
	n, m = map(int,raw_input().split(" "))
	if (n, m) == (0,0):
		break
	Lon = [0 for i in range(1000 * n + 1)]
	Lat = [0 for i in range(1000 * m + 1)]
	Lon_sum = [0]
	Lat_sum = [0]
	for i in range(0,n):
		tmp_Lon_sum = [0]
		h = int(raw_input())
		for j in Lon_sum:
			Lon[j+h] += 1
			tmp_Lon_sum += [j+h] 
		Lon_sum = tmp_Lon_sum
	else :
		Lon_max = Lon_sum[-1]
	for i in range(0,m):
		tmp_Lat_sum = [0]
		w = int(raw_input())
		for j in Lat_sum:
			Lat[j+w] += 1
			tmp_Lat_sum += [j+w] 
		Lat_sum = tmp_Lat_sum
	else :
		Lat_max = Lat_sum[-1]
	max_width = min(Lon_max,Lat_max)
	print sum([Lon[i]*Lat[i] for i in range(1,max_width+1)])

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int INT_INF = 999999999;
const static llong INF = 1LL << 60;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

vector<int> dist;
vector<bool> visited;
vector<vector<int> > G;

void dfs(int v) {
    visited[v] = true;

    rep(i, (int)G[v].size()) {
        if (visited[G[v][i]]) continue;
        dist[G[v][i]] = dist[v] + 1;
        dfs(G[v][i]);
    }

    return;
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    G.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b), G[b].push_back(a);
    }

    dist.resize(n);
    visited.resize(n);
    rep(i, n) {
        dist[i] = 0;
        visited[i] = false;
    }
    dfs(0);

    int farthest_v, cmp = -1;
    rep(i, n) {
        if (dist[i] >= cmp) {
            farthest_v = i;
            cmp = dist[i];
        }
    }

    rep(i, n) {
        dist[i] = 0;
        visited[i] = false;
    }
    dfs(farthest_v);

    cmp = -1;
    int diameter;
    rep(i, n) {
        if (dist[i] >= cmp) {
            diameter = dist[i];
            cmp = dist[i];
        }
    }

    if (diameter % 3 == 1) cout << "Second";
    else cout << "First";
    cout << endl;

    return 0;
}

Measured memory_bytes: 21376
#include <iostream>
#include <math.h>

using namespace std;

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

    int mininmum = 99999;
    for(int i = 1; i < N; i++) {
        int a = 0;
        for(int j = 0; j <= i; j++) {
            a += W[j];
        }
        int b = 0;
        for(int j = i+1; j < N; j++) {
            b += W[j];
        }
        mininmum = min(mininmum, abs(a-b));
    }
    cout << mininmum << endl;
}

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

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

int main(){
	int N, D;
	cin >> N >> D;
	double X[15][15];
	rep(i,N){
		rep(j,D) cin >> X[i][j];
	}
	int ans=0;
	rep(i,N-1){
		for(int j=i+1; j<N; j++){
			double dist=0;
			rep(k,D){
				double d=X[i][k]-X[j][k];
				dist+=d*d;
			}
			if(sqrt(dist)==floor(sqrt(dist))) ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

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

Measured memory_bytes: 1152
n = int(input())
if n % 2 == 0:
    print(n*(n-1)//2 - n//2)
    for i in range(n-1):
        for j in range(i+1, n):
            if i+1 + j+1 != n+1:
                print(i+1, j+1)
else:
    print(n*(n-1)//2 - (n-1)//2)
    for i in range(n-1):
        for j in range(i+1, n):
            if i+1 + j+1 != n:
                print(i+1, j+1)


Measured memory_bytes: 3612
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

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



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(auto &I:a){cin>>I;}
    vector<ll> dp(n,-1);
    ll k=-1;
    for(int i=0;i<n;i++){k=gcd(k,a[i]); dp[i]=k;}
    ll ans=dp[n-2];
    k=a.back();
    for(ll i=n-2;i>0;i--){
        k=gcd(k,a[i+1]);
        ans=max(ans,gcd(k,dp[i-1]));
    }
    k=gcd(k,a[1]);
    ans=max(ans,k);
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    int n;
    cin>>n;
    
    vector<int> a(n);
    
    for(int i=0;i<n;i++) cin>>a[i];
    
    sort(a.begin(),a.end());
    
    cout<<a[0]<<" "<<a[n-1]<<" "<<accumulate(a.begin(),a.end(),0LL)<<endl;
    
    
    
}



Measured memory_bytes: 3152
n, a, b, k = map(int, input().split())

mod = 998244353
fact = [1] + [0] * n
inv_fact = [0] * (n+1)
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

for i in range(n+1):
    inv_fact[i] = pow(fact[i],mod-2,mod)
    
def cb(n, k, mod):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % mod

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            if x > n or y > n:
                pass
            else:
                ans += cb(n, x, mod) * cb(n, y, mod)
                ans %= mod
    
print(ans)


Measured memory_bytes: 46832
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#include <list>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define N 131072
#define SUM 377
#define MAG 33554431
#define RED 0
#define BLUE 1
#define ALP 26
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,n,k,l,m,r,x,y,K,tot,h;
string s,t,s1;
ll a[100500];
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);
    ll l = 0, r = n-1;
    while (l < r)
    {
        ll mid = (l+r)/2;
        ll sum = 0;
        for (i = 0; i <= mid; i++)
            sum += a[i];
        for (i = mid+1; i < n; i++)
        {
            if (2*sum >= a[i])
                sum += a[i];
            else
                break;
        }
        //cout << mid << " " << i << endl;
        if (i == n)
            r = mid;
        else
            l = mid+1;
    }
    cout << n-l << endl;
    return 0;
}


Measured memory_bytes: 1024