akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const int MAXN = 1005;
const int MAXV = MAXN * MAXN; // The number of vectices is N*(N-1)/2
vector< vector<int> > to; // edges

int id[MAXN][MAXN];
int getId(int i, int j) {
  if (i > j) { swap(i, j); }
  return id[i][j];
}

int dp[MAXV]; // Represents the distance from leaf or state (initizlied by -1, intermediate is -2).
int dfs(int v) {
  if (dp[v] >= 0) { return dp[v]; }
  if (dp[v] == -2) { return -1; } // v is in intermediate state. Loop exists.

  dp[v] = -2;
  int d = 0;
  for (auto e : to[v]) {
    int res = dfs(e);
    if (res == -1) { return -1; }
    d = max(d, res);
  }

  return dp[v] = d + 1;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vector< vector<int> > A(N, vector<int>(N-1));
  rep(i, N) {
    rep(j, N-1) {
      cin >> A[i][j];
      --A[i][j];
    }
  }

  int V = 0;
  rep(i, N) {
    rep(j, N) {
      if (i < j) {
        id[i][j] = V++;
      }
    }
  }

  to.resize(V);

  rep(i, N) {
    for (int j = 0; j <= N - 3; ++j) { // j is from 0 to N-3 (N-2)
      int v = getId(i, A[i][j]);
      int n = getId(i, A[i][j+1]);
      to[v].push_back(n);
    }
  }

  int ans = 0;
  memset(dp, -1, sizeof(dp));
  rep(i, V) {
    int res = dfs(i); // dfs calculate the maximum distance from i.
    if (res == -1) {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 39424
void main()
{
    long n = rdElem;
    Dish[] d = n.rdCol!Dish;

    d.sort!"a.a + a.b > b.a + b.b";
    long total;
    foreach (i, x; d)
    {
        if (i & 1) total -= x.b;
        else total += x.a;
    }

    total.writeln;
}

struct Dish
{
    long a, b;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

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

Measured memory_bytes: 4860
#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(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll A, B, K;
	cin >> A >> B >> K;
	
	ll d = min(A, K);
	A -= d;
	K -= d;
	d = min(B, K);
	B -= d;
	cout << A << " " << B << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<string>
#include<stdio.h>
using namespace std;

int main() {
	string str;
	while (true) {
		cin >> str;

		if (str == "0") {
			break;
		}

		int sum = 0;
		
		for (int i = 0, l = str.size(); i < l; i++) {
			sum += str[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;
}




Measured memory_bytes: 3196
h,w=gets.split.map(&:to_i)
strs=(1..h).map{gets.chomp}

class NilClass
  def [](i); end
end

(0...h).each do |i|
  (0...w).each do |j|
    next unless strs[i][j]=='#'
    flg=false
    dxs=[0, 0, 1,-1]
    dys=[1,-1, 0, 0]
    dxs.each_with_index do |dx, k|
      x=i+dx
      y=j+dys[k]
      next if x<0 || y<0
      if strs[x][y]=='#'
        flg=true
      end
    end
    unless flg
      puts 'No'
      exit
    end
  end
end
puts 'Yes'

Measured memory_bytes: 1788
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(string):
    n, m, *a = map(int, string.split())
    l = reduce(lcm, a)
    while a[0] % 2 == 0:
        c = a[0] % 2
        for _a in a[1:]:
            if _a % 2 != c:
                return "0"
        if not c:
            a = [_a // 2 for _a in a]
    c = a[0] % 2
    for _a in a[1:]:
        if _a % 2 != c:
            return "0"
    return str(max((m - l // 2) // l + 1, 0))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

int main() {
	int c[3][3];
	rep(i,3) rep(j,3) cin >> c[i][j];
	int total = 0;
	rep(i,3) rep(j,3) total += c[i][j];
	bool ans = true;
	if (3*(c[0][0]+c[1][1]+c[2][2])!=total) ans = false;
	if (3*(c[0][1]+c[1][2]+c[2][0])!=total) ans = false;
	if (3*(c[0][2]+c[1][0]+c[2][1])!=total) ans = false;
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	cin>>N;
	vint W(N);
	
	int ans=INF;
	
	for (int i = 0; i < N; i++) {
		cin>>W[i];
	}
	
	for (int i = 0; i < N; i++) {
		int a=0,b=0;
		for (int j = 0; j < i; j++) {
			a+=W[j];
		}
		for (int j = i; j < N; j++) {
			b+=W[j];
		}
		ans=min(ans,abs(a-b));
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char a;cin>>a;
  if('a' <= a && a <= 'z')cout<<'a'<<endl;
  else cout<<'A'<<endl;
  return 0;
}


Measured memory_bytes: 3640
while True:
    x, y, z = map(int, input().split())
    if x == -1 and y == -1 and z == -1:
        break
    if x == -1 or y == -1:
        print ('F')
    elif x + y >= 80:
        print ('A')
    elif 65 <= x+y < 80:
        print ('B')
    elif 50 <= x+y < 65 or (30 <= x+y < 50 and z >= 50):
        print ('C')
    elif 30 <= x+y < 50:
        print ('D')
    elif x + y < 30:
        print ('F')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<pll,ll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,t1,t2;
vl c,g;
vpll a,b;
map<pll,int> sx,sy;

int main(){
	cin>>n>>t1>>t2;
	a=b=vpll(n);
	c=g=vl(n);
	t1--;t2--;
	for(int i=0;i<n;i++){
		ll x,y,X,Y;
		cin>>X>>Y;
		x=X+Y;
		y=X-Y;
		a[i]={x,y};
		b[i]={y,x};
	}
	ll d=max(abs(a[t1].first-a[t2].first),abs(a[t1].second-a[t2].second));
	pll p1=a[t1],p2=a[t2];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=0;i<n;i++){
		ll x=a[i].first,y=a[i].second;
		auto L=upper_bound(a.begin(),a.end(),make_pair(x-d,y-d)),R=upper_bound(a.begin(),a.end(),make_pair(x-d,y+d));
		c[i]+=R-L;
		L=lower_bound(a.begin(),a.end(),make_pair(x+d,y-d)),R=lower_bound(a.begin(),a.end(),make_pair(x+d,y+d));
		c[i]+=R-L;
		L=lower_bound(b.begin(),b.end(),make_pair(y-d,x-d)),R=lower_bound(b.begin(),b.end(),make_pair(y-d,x+d));
		c[i]+=R-L;
		L=upper_bound(b.begin(),b.end(),make_pair(y+d,x-d)),R=upper_bound(b.begin(),b.end(),make_pair(y+d,x+d));
		c[i]+=R-L;
		sx[{x,y}]=i;
		sy[{y,x}]=i;
	}
	queue<int> q;
	for(int i=0;i<n;i++){
		if(a[i]==p1) t1=i;
		if(a[i]==p2) t2=i;
	}
	q.push(t1);
	q.push(t2);
	g[t1]=g[t2]=1;
	while(!q.empty()){
		int i=q.front(),x=a[i].first,y=a[i].second;q.pop();
		vi tmp;
		auto L=sx.upper_bound(make_pair(x-d,y-d)),R=sx.upper_bound(make_pair(x-d,y+d));
		while(L!=R){
			tmp.push_back(L->second);
			L++;
		}
		L=sx.lower_bound(make_pair(x+d,y-d)),R=sx.lower_bound(make_pair(x+d,y+d));
		while(L!=R){
			tmp.push_back(L->second);
			L++;
		}
		L=sy.lower_bound(make_pair(y-d,x-d)),R=sy.lower_bound(make_pair(y-d,x+d));
		while(L!=R){
			tmp.push_back(L->second);
			L++;
		}
		L=sy.upper_bound(make_pair(y+d,x-d)),R=sy.upper_bound(make_pair(y+d,x+d));
		while(L!=R){
			tmp.push_back(L->second);
			L++;
		}
		for(auto j:tmp){
			g[j]=1;
			q.push(j);
			sx.erase(a[j]);
			sy.erase(make_pair(a[j].second,a[j].first));
		}
	}
	ll res=0;
	for(int i=0;i<n;i++) res+=c[i]*g[i];
	cout<<res/2<<endl;
}

Measured memory_bytes: 17792
#include<stdio.h>
main(){
  int a[100]={0},i,j,smp=0;
  while(1){
    if(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])==EOF)break;
    for(i=0;i<5;i++){
      for(j=i+1;j<5;j++){
	if(a[i] > a[j]){
	  smp=a[i];
	  a[i]=a[j];
	  a[j]=smp;
	}
      }
    }
    if(a[0]==a[1]&&a[1]==a[2] &&a[2]==a[3]||a[1]==a[2]&&a[2]==a[3]&&a[3]==a[4]){
      printf("four card\n");
    }
    else if(a[0]==a[1]&&a[2]==a[3]&&a[3]==a[4]||a[0]==a[1]&&a[1]==a[2]&&a[3]==a[4]){
      printf("full house\n");
    }
    else if(a[0]+1==a[1]&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4]||a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13){
      printf("straight\n");
    }
    else if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]||a[2]==a[3]&&a[3]==a[4]){
      printf("three card\n");
    }
    else if(a[0]==a[1]&&a[2]==a[3]||a[0]==a[1]&&a[3]==a[4]||a[1]==a[2]&&a[3]==a[4]){
      printf("two pair\n");
    }
    else if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]||a[3]==a[4]){
      printf("one pair\n");
    }
    else{
      printf("null\n");
    }
  }
  return 0;
}
    
    

Measured memory_bytes: 580
using System;
using System.Linq;

public class Tree{
  public int value;
  public Tree parent;
  public Tree left;
  public Tree right;
}

class A8{
  public static void Main(){
    Tree root = new Tree();
    int n = int.Parse(Console.ReadLine());
    for(int i = 0;i < n;i++){
      var command = Console.ReadLine().Split(' ');
      if(command[0].Equals("insert")) Insert(root,int.Parse(command[1]));
      else Print(root);
    }
  }
  public static void Insert(Tree tree,int value){
    Tree x = tree;
    Tree y = null;
    while(x != null && x.value != 0){
      y = x;
      if(value < x.value) x = x.left;
      else x = x.right;
    }
    Tree tmp = new Tree();
    tmp.value = value;
    tmp.parent = y;

    if(y == null){
      tree.value = value;
    }else if(value < y.value){
      y.left = tmp;
    }else{
      y.right = tmp;
    }
  }
  public static void Print(Tree tree){
    Inorder(tree);
    Console.WriteLine();
    Preorder(tree);
    Console.WriteLine();
  }

  public static void Inorder(Tree tree){
    if(tree == null) return;
    Inorder(tree.left);
    Console.Write(" " + tree.value);
    Inorder(tree.right);
  }
  public static void Preorder(Tree tree){
    if(tree == null) return;
    Console.Write(" " + tree.value);
    Preorder(tree.left);
    Preorder(tree.right);
  }
}


Measured memory_bytes: 46608
#include<stdio.h>
#include<stdlib.h>
 
int partition(int *,int ,int);

int a[100000];

int main(){
  int n,i,q;

  scanf("%d",&n);
  if(n < 1 || 100000 < n)exit(0);

  //a = (int *)malloc(n*sizeof(int));

  for ( i = 0; i < n; i++) {
    scanf("%d",&a[i]);
    if(a[i] < 0 || 100000 < a[i])exit(0);
  }

  q = partition(&a[0],0,n - 1);

  printf("%d",a[0]);
  for(i = 1; i < n; i++) {
    if(i == q ){
      printf(" [%d]",a[i]);
      continue;
    }
    printf(" %d",a[i]);
  }
  printf("\n");
  return 0;
}

int partition(int *a,int p,int r){
  int x,i,j,v;

  x = a[r];
  i = p - 1;
  
  for(j = p; j < r; j++) {
    
    if(a[j] <= x){
      i = i + 1;
      
      v = a[i];
      a[i] = a[j];
      a[j] = v;
    }
  }
  v = a[i+1];
  a[i+1] = a[r];
  a[r] = v;
  
  return i+1;
}



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

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  for(auto &dd: d)
    cin >> dd;

  for(int i = n;; i++){
    bool f = true;
    string s = to_string(i);
    for(int j = 0; j < s.length(); j++){
      for(k = 0; k < d.size(); k++){
        string t;
        t = s[j];
        if(d[k] == stoi(t)){
          f = false;
          k = d.size();
          j = s.length();
        }
      }
    }
    if(f){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            map[i] = sc.next().toCharArray();
        }
        int nt = 0, nx = 0, ny = 0;
        boolean bool = true;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j] == '.') continue;
                if(!check(map,i,j,h,w)){
                    bool = false;
                    break;
                }
            }
            if(!bool) break;
        }
        System.out.println(bool ? "Yes" : "No");
    }
    
    private static boolean check(char[][] map, int i, int j, int h, int w){
        int[] xl = {-1,0,0,1};
        int[] yl = {0,-1,1,0};
        for(int k = 0; k < 4; k++){
            if(i + yl[k] < 0 || i + yl[k] >= h || j + xl[k] < 0 || j + xl[k] >= w) continue;
            if(map[i + yl[k]][j + xl[k]] == '#') return true;
        }
        return false;
    }
}


Measured memory_bytes: 23764
n, t = map(int, input().split())
ct = [list(map(int,input().split())) for _ in range(n)]
 
li = []
for i in range(n):
  if ct[i][1] <= t:
    li.append(ct[i][0])
  else:
    continue
 
if len(li) > 0:
  print(min(li))
else:
  print("TLE")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  ll n;
  cin>>n;
  ll a[n-1],b[n-1];
  rep(i,0,n-1) cin>>a[i]>>b[i];
  ll ans=(n+2)*(n+1)*n/6;
  rep(i,0,n-1){
    if(a[i]>b[i]) swap(a[i],b[i]);
    ans-=a[i]*(n+1-b[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int n,l;
  cin >>  n >> l;
  int a[n];
  rep(i,n) cin >> a[i];
  bool pos=false;
  int a_ind;
  vector<int> ans;
  rep(i,n-1){
    if(a[i]+a[i+1] >= l){
      pos=true;
      a_ind=i;
      break;
    }
  }
  if(!pos) cout << "Impossible" << endl;
  else{
    cout << "Possible"<< endl;
    rep(i,a_ind){
      cout << i+1 << endl;
    }
    for(int i=n-2;i>a_ind;i--){
      cout << i+1 << endl;
    }
    cout << a_ind+1 << endl;
  }

  
  return 0;

}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pll pair<ll, ll>
#pragma GCC optimize ("O3")
using namespace std;
vector <set <int>> tree (200001);
vector <int> add (200001, 0);
vector <bool> vis (200001, false);
void dfs (int ver) {
    vis[ver]=true;
    for (auto &i :  tree[ver]) {
        if (!vis[i]) {
            add[i]+=add[ver];
            dfs (i);
        }
    }
}
int main () {
    #ifdef LOCAL
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
        freopen ("error.txt", "w", stderr);
    #else
        ios::sync_with_stdio(false);
        cin.tie (NULL);
    #endif
    int n, q; cin>>n>>q;
    for (int i=1;i<n;++i) {
        int a, b; cin>>a>>b;
        tree[a].insert(b);
    }
    while (q--) {
        int p, x; cin>>p>>x;
        add[p]+=x;
    }
    dfs (1);
    for (int i=1;i<=n;++i) cout<<add[i]<<' ';
    return 0;
}


Measured memory_bytes: 27136
use std::io::*;

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

  let line = lines.next().unwrap().unwrap();
  let mut args = line.split_whitespace().map(|s| s.parse::<usize>().unwrap());
  let n = args.next().unwrap();
  let m = args.next().unwrap();
  let l = args.next().unwrap();

  let mut vec_a: Vec<Vec<usize>> = Vec::with_capacity(n);

  for line in lines.by_ref().take(n) {
    let line = line.unwrap();
    let v = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    vec_a.push(v);
  }

  let mut vec_b: Vec<Vec<usize>> = Vec::with_capacity(m);

  for line in lines.take(m) {
    let line = line.unwrap();
    let v = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    vec_b.push(v);
  }

  let stdout = stdout();
  let mut stdout = BufWriter::new(stdout.lock());

  for i in 0..n {
    for j in 0..l {
      let mut sum = 0;

      for k in 0..m { sum += vec_a[i][k] * vec_b[k][j]; }

      if j == l - 1 {
        writeln!(stdout, "{}", sum).unwrap();
      } else {
        write!(stdout, "{} ", sum).unwrap();
      }
    }
  }
}



Measured memory_bytes: 5052
import sys
input = sys.stdin.readline
n, l = map(int, input().split())
sum = 0
a = float('inf')
for i in range(1,n+1):
    sum += l + i - 1
    if a > abs(l + i - 1):
        a = abs(l + i - 1)

# print(sum)

# print(a)
# print(sum)
# print("***************")
if sum >= 0:
    print(sum - a)
else:
    print(sum + a)

Measured memory_bytes: 3060
X,Y = map(int,input().split())
result = False
for turtles in range (0,X+1):
    for cranes in range (0,X+1):
        if turtles + cranes == X and turtles*4 + cranes*2 == Y :
            result = True
if result == True:
    print ("Yes")
else:
    print ("No")


Measured memory_bytes: 9060
#include <stdio.h>
#include <math.h>

int main(){
	int a,b,c;
	double rad;
	double S, L, h;
	scanf("%d %d %d", &a, &b, &c);
	rad = c * 2*M_PI / 360.0;
	h = b * sin(rad);
	S = a * h / 2.0;
	L = a + b + sqrt(a*a+b*b-2*a*b*cos(rad));
	printf("%lf\n%lf\n%lf\n", S, L, h);
	return 0;
}

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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

int main()
{
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    
    bool same = true;

    rep(i, S.size())
    {
        if(i < A && '0' <= S[i] && S[i] <= '9') continue;
        if(A == i && S[i] == '-') continue;
        if(A  < i && '0' <= S[i] && S[i] <= '9') continue;

        same = false;
          
    }

    cout << (same ? "Yes" : "No") << endl;
    
    return 0;
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
 
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
 
#define rep(i,a) for(int i=0;i<a;i++)
#define repn(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;

 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans = n/(a+b);
	ll rm = n%(a+b);
	if (rm>=a) cout<<ans*a+a<<endl;
	else cout<<ans*a+rm<<endl;	
	return 0;
}


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

using namespace std;

int main()
{
    string S,T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {
        if(S[i]!=T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
   string S;
   cin >> S;

   bool flag = true;
   for (int i=0; i<3; i++){
      if (S.at(i) == S.at(i+1)){
         flag = false;
         break;
      }
   }
   if (flag)
      cout << "Good" << endl;
   else
      cout << "Bad" << endl;

}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main()
{
    bool b = true;
    int n;
    cin >> n;
    ll tmp;
    map<ll, int> a;
    rep(i, n)
    {
        cin >> tmp;
        a[tmp]++;
        if (a[tmp] == 2)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 14848
n = gets.to_i
d = gets.split(" ").map{|v| v.to_i}.sort.reverse
x = d[0]
y = 0
yd = 0
for i in 1...n
  v = d[i]
  ty = [v, x - v].min
  if yd < ty
    y = v
    yd = ty
  else
    break
  end
end
puts "#{x} #{y}"


Measured memory_bytes: 12660
using System;

namespace ITP1_9_C {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int a = 0, b = 0;
            string[] S = new string[N];
            for(int i = 0; i < N; i++) {
                S = Console.ReadLine().Split(' ');
                int abCompare = S[0].CompareTo(S[1]);
                if(abCompare < 0) {
                    b += 3;
                } else if(abCompare > 0) {
                    a += 3;
                } else {
                    a++;
                    b++;
                }
            }
            Console.WriteLine("{0} {1}", a, b);
        }
    }
}

Measured memory_bytes: 9968
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int W, H;
	int x, y, r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	W -= r, H -= r;
	if (r <= x && x <= W && r <= y && y <= H) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 584
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput());
        
        static void Main(string[] args)
        {
            var i = Scanner.Integer();
            Console.WriteLine(i + i * i + i* i * i);
        }

        private static IEnumerable<long> ScanLong(int count = 0)
        {
            var scan = new List<long>();
            for (int i = 0; i < count; i++)
            {
                scan.Add(Scanner.Long());
            }

            return scan;
        }
        
        private static void OutAllLine(IEnumerable<dynamic> items)
        {
            var sb = new StringBuilder();
            foreach (var result in items)
            {
                sb.Append(result + "\n");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb);
        }
    }
    
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len) {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char() 
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b; 
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}

Measured memory_bytes: 25704
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

long long calc(long long n)
{
	if(n < 10)
		return n;

	return n%10 + calc(n/10);
}

long long f(long long n)
{
	string str = to_string(n);
	vector<long long> v;
	v.push_back(n);

	for(auto it=str.rbegin(); it!=str.rend(); it++){
		*it = '9';
		v.push_back(stoll(str));
	}

	vector<double> vv(v.size());
	for(int i=0; i<vv.size(); i++)
		vv[i] = 1.0 * v[i] / calc(v[i]);
	
	int index = min_element(vv.begin(), vv.end()) - vv.begin();

	return v[index];
}

int main(void)
{
	int K;
	cin >> K;

	long long n = 1;
	for(int i=0; i<K; i++){
		cout << n << endl;

		n = f(n+1);
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int j, x, y, z;
    j = 0;
    scanf("%d%d%d", &x, &y, &z);
    for (int i = x; i <= y; i++){
        if (z % i == 0) {
            j += 1;
        }
    }
    printf("%d\n", j);
    return 0;
}


Measured memory_bytes: 2132
#include <stdio.h>
#include <stdlib.h>
 
int puzzle[4][4];
int tmp[4][4];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
void empty(int *,int *);
int dfs(int,int,int,int,const int);
int cal();
void swap(int *,int *);
 
int main() {
  int i,j,n,x,y,l;

  for(i=0; i<4; i++) {
    if(i<4)break;
  }
  
  for(i=0; i<4; i++) {
    for(j=0; j<4; j++) scanf("%d",&puzzle[i][j]);
  }
 
  empty(&x,&y);
  for(l=0; l<100; l++) {
    for(i=0; i<4; i++) {
      for(j=0; j<4; j++) tmp[i][j] = puzzle[i][j];
    }
 
    n = dfs(x,y,-1,0,l);
    if(n!=-1) {
      printf("%d\n",n);
      break;
    }
 
    for(i=0 ; i<4; i++) {
      for(j=0 ; j<4; j++) puzzle[i][j] = tmp[i][j];
    }
    n = -1;
    if(l==99) printf("%d\n",n);
  } 
  return 0;
}


void empty(int *x,int *y) {
  int i,j;
  for(i=0; i<4; i++) {
    for(j=0; j<4; j++) {
      if(!puzzle[i][j]) {
	*x = j;
	*y = i;
	return;
                
      }
    }
  }
}
 
 
void swap(int *n,int *m) {
  int tmp;
  tmp = *n;
  *n = *m;
  *m = tmp;
}
 
 
int cal() {
  int i,n,sum=0;
  for(i=0; i<16; i++) {
    n = puzzle[i/4][i%4];
    if(n) {
      n--;
      sum += abs(i/4 - n/4) + abs(i%4 - n%4);
    }
  }
    
  return sum;
    
}

int dfs(int x,int y,int p,int dep,const int lim) {
  int i,h,nx,ny,res;
 
  h = cal();
  if(h==0) return dep;
  if(dep+h>lim) return -1;
 
  for(i=0; i<4; i++) {
    nx = x+dx[i];
    ny = y+dy[i];
 
    if(~p && i==(p+2)%4) continue;
    if(!(0<=nx && nx<4 && 0<=ny && ny<4)) continue;
 
    swap(&puzzle[y][x],&puzzle[ny][nx]);
    res = dfs(nx,ny,i,dep+1,lim);
    if(~res) return res;
 
    swap(&puzzle[y][x],&puzzle[ny][nx]);
  }
 
  return -1;
}



Measured memory_bytes: 2112
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,q;
vector<int> G[100001];

struct data{
	int c,id;
	data(){}
	data(int cc,int idd){
		c=cc;
		id=idd;
	}
	bool operator<(const data& dat)const{
		return id<dat.id;
	}
};

int color[100001];
int lid[100001];
data que[11][100001];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
		G[t].push_back(f);
	}
	 
	scanf("%d",&q);
	for(int i=0;i<=10;i++){
		for(int j=0;j<n;j++){
			que[i][j].id=-1;
		}
	}
	for(int i=0;i<q;i++){
		int v,d,c;
		scanf("%d%d%d",&v,&d,&c);
		v--;
		if(que[d][v].id<i){
			que[d][v].c=c;
			que[d][v].id=i;
		}
	}
	for(int i=10;i>=0;i--){
		for(int j=0;j<n;j++){
			if(i>0){
				if(que[i][j].id!=-1 && que[i-1][j].id<que[i][j].id)que[i-1][j].c=que[i][j].c;
				que[i-1][j].id=max(que[i-1][j].id,que[i][j].id);
			}
		}
		for(int j=0;j<n;j++){
			if(que[i][j].id!=-1){
				data d=que[i][j];
				color[j]=d.c;
				//printf("d=%d v=%d col=%d id=%d nv=",i,j,d.c,d.id);
				if(i==0){
					//printf("\n");
					continue;
				}
				for(int k=0;k<G[j].size();k++){
					int nv=G[j][k];
					//printf("%d",nv);
					if(que[i-1][nv].id<=d.id){
						//printf("+");
						que[i-1][nv].id=d.id;
						que[i-1][nv].c=d.c;
					}
					//printf(" ");
				}
				//printf("\n");
			}
		}
		/*
		for(int i=0;i<n;i++){
			printf("%d ",color[i]);
		}
		printf("\n");
		*/
	}
	//printf("\n");
	for(int i=0;i<n;i++){
		printf("%d\n",color[i]);
	}
	return 0;
}


Measured memory_bytes: 15864
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long[] a=new long[s[0]+1];
		long[] p=new long[s[0]+1];
		long n=s[1],ans=0,e=0;
		a[0]=1;p[0]=1;
		for(int i=1;i<=s[0];i++){
			a[i]=a[i-1]*2+3;
			p[i]=p[i-1]*2+1;
		}
		int d=(int)s[0];
		while(e<n){
			while(n<e+a[d]+(s[0]-d)&&d!=0){d--;}
			if(d==0){
				e+=s[0];
				while(e<n){ans++;e++;}
			}
			else{
				ans+=p[d];
				e+=a[d]+s[0]-d;
			}
			if(e<n){
				e++;
				ans++;
			}
			s[0]=d;
		}
		Console.WriteLine(ans);
	}
}

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

using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

// 入力
int N;
Graph G;

// res は答え
vector<int> res;

// v を c に塗る。p は v の親
void dfs(int v, int p, int c) {
    res[v] = c;
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1-c);
        else dfs(e.first, v, c);
    }
}

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int u, v, w; cin >> u >> v >> w;
        --u, --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    res.assign(N, 0);
    dfs(0, -1, 1);
    for (auto v : res) cout << v << endl;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    string s;
    cin >> s;
    if(s == "SSS") cout << 0 << endl;
    else if(s == "RRR") cout << 3 << endl;
    else if(s == "SRR" || s == "RRS") cout << 2 << endl;
    else cout << 1 << endl;
    return 0; 
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;


const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
const int inf = 1e9;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

string s[SZ];
int d[SZ][SZ];

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

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int h, w, k;
    cin >> h >> w >> k;
    int x, y;
    for(int i = 0; i < h; i++){
        cin >> s[i];
        for(int j = 0; j < w; j++){
            if(s[i][j] == 'S') {x = i; y = j;}
            d[i][j] = inf;
        }
    }
    list<pair<int,int> > sp, sp2;
    sp.push_back({x, y});
    d[x][y] = 0;
    while(sp.begin() != sp.end()){
        x = sp.front().first;
        y = sp.front().second;
        if(x == 0 || y == 0 || x == h - 1 || y == w - 1){cout << 1 << endl; return 0;}
        if(d[x][y] == k) break;
        sp.pop_front();
        sp2.push_back({x, y});
        for(int z = 0; z < 4; z++){
            int xx = x + dx[z];
            int yy = y + dy[z];
            if(s[xx][yy] == '#') continue;
            if(d[xx][yy] > d[x][y] + 1){
                d[xx][yy] = d[x][y] + 1;
                sp.push_back({xx, yy});
            }
        }
    }
    while(sp.begin() != sp.end()){
        x = sp.front().first;
        y = sp.front().second;
        if(d[x][y] > k) break;
        if(x == 0 || y == 0 || x == h - 1 || y == w - 1){cout << 1 << endl; return 0;}
        sp.pop_front();
        sp2.push_back({x, y});
    }
    swap(sp, sp2);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            d[i][j] = inf;
        }
    }
    for(auto it = sp.begin(); it != sp.end(); it++){
        d[it->first][it->second] = 0;
    }
    while(sp.begin() != sp.end()){
        x = sp.front().first;
        y = sp.front().second;
        if(x == 0 || y == 0 || x == h - 1 || y == w - 1){
                cout << (d[x][y] + k - 1) / k + 1 << endl;
                return 0;
        }
        sp.pop_front();
        for(int z = 0; z < 4; z++){
            int xx = x + dx[z];
            int yy = y + dy[z];
            if(d[xx][yy] > d[x][y] + 1){
                d[xx][yy] = d[x][y] + 1;
                sp.push_back({xx, yy});
            }
        }
    }
    return 1;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0 , so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll a , b ;
    cin >> a >> b;
    if(a > 0 and b > 0 ){

        cout << "Positive\n";
        ro;
    }
    else if(a <= 0 and b >=0) {
        cout << "Zero\n";
        ro ;
    }
    else if(a < 0 and b < 0 ) {
        ll diff = abs(b -a );
        if(diff % 2 == 0 ){
            cout <<"Negative\n";
            ro;
        }
        else cout <<"Positive\n";
        ro;
    }
}























Measured memory_bytes: 256
#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;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  string S;
  cin >> S;
  vector <int> cnt(2, 0);
  rep(i,S.length()){
     cnt[S[i] - '0'] ++;
  }
  int ans = 2 * min(cnt[0], cnt[1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3692
/*  ex9_1
    urah  */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// sの最大の長さ
#define MAX_LEN 11

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[MAX_LEN];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = MAX_LEN;
    stk->top = &(stk->data[MAX_LEN]);
}

//データの追加
void push(stack *stk, char elem){
    // エラー処理
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
void pop(stack *stk){
    // エラー処理
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }else{
        stk->top++;
        stk->count--;
    }
}

// データの出力
void print_stack(stack *stk){
    char *ptr;   

    ptr = &(stk->data[MAX_LEN]);

    // 逆方向から出力していく
    for(int i=0; i<stk->count; i++){
        printf("%c",*(--ptr));
    }

    printf("\n");
}


int main(void){
    stack stk;
    char string[MAX_LEN];

    // 入力受け取り
    scanf("%s", string);

    //スタックを初期化
    initialize_stack(&stk);   

    for (int i=0; i<strlen(string); i++){
        if (string[i] == 'B' && stk.count != 0){
            // データの取り出し
            pop(&stk);
        } else if (string[i] == '1' || string[i] == '0'){
            // データの追加
            push(&stk, string[i]);
        }
    }

    print_stack(&stk);

    return 0;
}

Measured memory_bytes: 1620
n = int(input())

def keta(x):
    ans = 0
    while x != 0:
        x //= 10
        ans += 1
    return ans


ans = float("inf")
for i in range(1, int(n**0.5)+2):
    if n % i == 0:
        j = n // i
        ans = min(ans, max(keta(i), keta(j)))
print(ans)

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
#define    bit(a)          __builtin_popcount(a)
#define    all(x)           x.begin(), x.end()
#define    minv(v)         *min_element(all(v))
#define    maxv(v)         *max_element(all(v))
#define    unq(v)           sort(all(v)),v.erase(unique(all(v)),v.end())
#define    w(x)             while(x--)
#define    rep(i,a,b)       for(i=a;i<=b;i++)
#define    ll               long long
#define    pb               push_back
#define    vii              vector<int>
#define    vll              vector<ll>
#define    vcc              vector<char>
#define    sii              set<int>
#define    sll              set<ll>
#define    scc              set<char>
#define    li               list<int>
#define    pii              pair<int,int>
#define    pll              pair<ll,ll>
#define    mii              map<int,int>
#define    mll              map<ll,ll>
#define    fill(arr,x)      memset(arr,x,sizeof(arr))
#define    gcd(a,b)         __gcd(a,b)
#define    lcm(a,b)        (a*(b/gcd(a,b)))
#define    srtc(a,b)        sort(a,a+b,greater<int>())
#define    pi               acos(-1.00)
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*
//find the position of 0 or 1 in binary representation
int zero(int n)
{
    int i=1,pos=0;
    while(n)
    {
        if(n%2==0)pos=i;
        n/=2;
        i++;
    }
    return pos;
}
*/
int t;
string s;
int main()
{
    _ios;
    int a,b,c,d,f;
    cin>>a>>b>>c>>d>>f;
    int ar[10];
    ar[a]=1;
    ar[b]=2;
    ar[c]=3;
    ar[d]=4;
    ar[f]=5;
    cout<<ar[0]<<endl;
    return 0;
}





Measured memory_bytes: 3516
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact(ll i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll modpow(ll a, ll n, ll mod) {
    ll hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*signed*/int main(void) {
    ld a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if (d > 0 && d * d > 4 * a * b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    string s;
    cin>>s;
    if(s == "ARC") cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
const int MAX = 1000100;
ll inv[MAX],fact[MAX],fi[MAX];
constexpr ll mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}
ll pw(ll a, ll x){
	ll ret = 1;
	while(x){
		while(!(x&1)){
			(a *= a) %= mod;
			x /= 2;
		}
		(ret *= a) %= mod;
		x--;
	}
	return ret;
}

ll a[200010];
map<ll,ll> mp;
int main(){
	int i,j,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		ll b = a[i];
		map<ll,ll> mp1;
		for(j=2;j*j<=b;j++){
			while(b%j==0){
				mp1[j]++;
				b /= j;
			}
		}
		if(b!=1){
			mp1[b]++;
		}
		for(auto x:mp1){
			mp[x.first] = max(mp[x.first],x.second);
		}
	}
	inverse();
	ll ans = 0;
	for(i=0;i<n;i++){
		(ans += inv[a[i]]) %= mod;
	}
	ll y = 1;
	for(auto x:mp){
		(ans *= pw(x.first,x.second)) %= mod;
		(y *= pw(x.first,x.second)) %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MAX = (ll)1e18;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (!a[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  rep(i, n) {
    if (a[i] <= MAX/ans)
      ans *= a[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3988
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
string s; 
int i=0;
int main()
{    
    getline(cin,s);
    while(i<s.length())
    {
        if(s[i]!='0'&&s[i]!='1')
        {
            if(i>0) 
                s.erase(i-1,2),i--;
            else s.erase(i,1);
        }
        else i++;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  bool flag=0;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n)flag=1;
    }
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt_g = 0, cnt_p = 0;
    int N = s.size();
    rep(i,0,N){
        if(s[i] == 'g') cnt_g++;
        if(s[i] == 'p') cnt_p++;
    }
    if(N % 2 == 0){
        print((cnt_g - cnt_p)/2);
    }else{
        print((cnt_g - cnt_p - 1)/2);
    }

}


Measured memory_bytes: 512