akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    int a[114514];
    ll sum[114514];
    rep(i,n)cin>>a[i];
    sum[0]=a[0];
    REP(i,n)sum[i]=sum[i-1]+a[i];
    ll p=0,ans1=0;
    rep(i,n){
        ll k=sum[i]+p;
        if(i%2==0){
            if(k<0){
                ans1+=1-k;
                p+=1-k;
            }else if(k==0){
                p++;
                ans1+=1;
            }
        }else {
            if(k>0){
                ans1+=k+1;
                p-=k+1;
            }else if(k==0){
                p--;
                ans1+=1;
            }
        }
    }
    p=0;
    ll ans2=0;
    rep(i,n){
        ll k=sum[i]+p;
        if(i%2==0){
            if(k>0){
                ans2+=k+1;
                p-=k+1;
            }else if(k==0){
                p--;
                ans2+=1;
            }
        }else {
            if(k<0){
                ans2+=1-k;
                p+=1-k;
            }else if(k==0){
                p++;
                ans2+=1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}



Measured memory_bytes: 1408
N=int(input())
t=list()
t=[(0,(0,0))]
for i in range(N):
        T,a,b=map(int,input().split())
        t.append((T,(a,b)))

ans="Yes"
for i in range(N):
        n=abs(t[i][1][0]-t[i+1][1][0])+abs(t[i][1][1]-t[i+1][1][1])
        if(n%2!=(t[i+1][0]-t[i][0])%2 or n>(t[i+1][0]-t[i][0])):
                ans="No"

print(ans)

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

bool check(vector<int> q){
  for (int i = 1; i < (int)q.size(); i++)
  {
    if((q[i]-q[i-1])!=1) return false;
  }
  return true;  
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
//  vector<int> q(n);


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

  bool ans = false;
  ans = check(p);

  if (ans){
    cout << "YES" << endl;
    return 0;
  }


  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      int pi=p[i];
      int pj=p[j];
      p[i]=pj;
      p[j]=pi;
      ans=check(p);
      if (ans){
        cout << "YES" << endl;
       return 0;
      }
      p[i] = pi;
      p[j] = pj;
    }
  }
  cout << "NO" << endl;
}

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

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

using namespace std;
using namespace __gnu_pbds;
typedef tree<signed, null_type, less_equal<signed>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//find_by_order();
//order_of_key();
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	switch(n%10) {
		case 2: case 4: case 5: case 7: case 9:
			cout << "hon" << endl;
			break;
		case 0: case 1: case 6: case 8:
			cout << "pon" << endl;
			break;
		case 3:
			cout << "bon" << endl;
			break;
	}
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 3608
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.map!(to!int).array;
  auto b = new int[](n);

  auto j = 0;
  if (n % 2) {
    foreach_reverse (i; iota(0, n, 2)) {
      b[j] = a[i];
      j++;
    }
    foreach (i; iota(1, n, 2)) {
      b[j] = a[i];
      j++;
    }
  } else {
    foreach_reverse (i; iota(1, n, 2)) {
      b[j] = a[i];
      j++;
    }
    foreach (i; iota(0, n, 2)) {
      b[j] = a[i];
      j++;
    }
  }

  foreach (i, e; b) {
    write(e);
    if (i != b.length-1) write(" ");
  }
  writeln("");
}


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


int main() {
	
	int N;
	cin >> N;
	vector<int> a(N+1);
	for(int j=1; j<=N; j++) cin >> a.at(j);
	
	int j = 1;
	bool flag = 0;
	
	for(int i=1; i<=N; i++){
		if(a.at(j) == 2) {
			cout << i << endl;
			flag = 1;
			break;
		}
		else j = a.at(j);
		
	}
	if (!flag) cout << -1 << endl;
	
	
	return 0;
}

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

vector<int> v;
map<int,int> mp;
void sieve()
{
	for(int i=2;i*i<1000000;i++)
	{
		if(mp[i]==false)
		{
			for(int j=i*i;j<1000000;j+=i)
				mp[j]=true;
		}
	}
	for(int i=2;i<1000000;i++)
		if(mp[i]==false)
			v.push_back(i);
}
 
int main()
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
 	
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		sieve();
 		int n;cin>>n;
 		for(int i=0;i<v.size();i++)
 		{
 			if(v[i]>=n)
 			{
 				cout<<v[i]<<endl;
 				break;
 			}
 		}
 	}
	return 0;
}

Measured memory_bytes: 47480
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int doughCost, topingCost;
		int doughCal, topingCal[];
		double sumCost, sumCal;

		n = sc.nextInt();
		doughCost = sc.nextInt();
		topingCost = sc.nextInt();
		doughCal = sc.nextInt();
		topingCal = new int[n];
		sumCost = doughCost;
		sumCal = doughCal;
		for (int i = 0; i < n; i++) {
			topingCal[i] = sc.nextInt();
		}
		quickSort(topingCal, 0, n - 1);

		for (int i = 0; i < n; i++) {
			if (sumCal / sumCost < (sumCal + topingCal[i]) / (sumCost + topingCost)) {
				sumCal += topingCal[i];
				sumCost += topingCost;
			} else {
				break;
			}
		}
		System.out.println((int)(sumCal / sumCost));
	}

	public static void quickSort(int a[], int low, int high) {
		if (high <= low) {
			return ;
		}

		int x = a[low];
		int i = low;
		int j = high;

		while (i <= j) {
			while (x < a[i]) {
				i++;
			}
			while (a[j] < x) {
				j--;
			}
			if (i <= j) {
				int swap = a[i];
				a[i] = a[j];
				a[j] = swap;
				i++;
				j--;
			}
		}
		quickSort(a, low, j);
		quickSort(a, i, high);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define all(a)  a.begin(), a.end()
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define sz(a) ((int)(a.size()))
#define pb(a) push_back(a)
#define ins(a) insert(a)
#define mkpr make_pair
#define fi first
#define se second
#define newln cout<<"\n"
#define bigPrime 1000000007
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
// continue // break // greater // string // length // while

int main()
{
    fip;
    int n,i,max=-1,max2=-1;
    cin>>n;
    int a[n];
    int b[n];
    reptUsual(n)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n,greater<int>());
    reptUsual(n)
    {
        if(b[i]==a[0])
        {
            cout<<a[1]<<"\n";
        }
        else
            cout<<a[0]<<"\n";
    }
    return 0;

}

Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,ans;
    cin>>a>>b>>c;
    for(int i=a;i<b+1;i++)
    {
        if(c%i==0){ans=ans+1;}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N,A,B,C;
vector<int> l;
int ans = INF;

void calc(int &s,vector<int> &now,bool &ok){
  vector<int> nowA,nowB,nowC;
  int sumA = 0,sumB = 0,sumC = 0;
  rep(i,N){
    if(now[i] == 1){
      nowA.push_back(l[i]);
      sumA += l[i];
    }
    if(now[i] == 2){
      nowB.push_back(l[i]);
      sumB += l[i];
    }
    if(now[i] == 3){
      nowC.push_back(l[i]);
      sumC += l[i];
    }
  }
  if(nowA.size() >= 1 && nowB.size() >= 1 && nowC.size() >= 1) s += (nowA.size() + nowB.size() + nowC.size() - 3) * 10 + abs(sumA - A) + abs(sumB - B) + abs(sumC - C);
  else ok = false;
}

void dfs(int depth,vector<int> &now){
   if(depth == N){
     int s = 0;
     bool ok = true;
     calc(s,now,ok);
     if(ok)ans = min(ans,s);
     return;
   }
   rep(i,4){
     now[depth] = i;
     dfs(depth + 1,now);
   }
}

int main(){
   cin >> N >> A >> B >> C;
   l.resize(N);
   rep(i,N) cin >> l[i];
   
   vector<int> now(N);
   dfs(0,now);
   cout << ans << endl;


}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
using namespace std;
long long a[55],b[55];
vector<long long>v[55];
long long dfs(long long k,long long a,long long b,long long u[]){
	u[k]=1;
	long long ans=1;
	for (long long i : v[k]){
		if ( (k==a && i==b) || (k==b && i==a) )  continue;
		if (u[i]==0)  ans+=dfs(i,a,b,u);
	}
	re ans;
}
signed main()
{
	long long n,m,ans=0;
	cin>>n>>m;
	for (long long i=0;i<m;i++){
		cin>>a[i]>>b[i];
		v[a[i]].pb(b[i]);
		v[b[i]].pb(a[i]);
	}
	for (long long i=0;i<m;i++){
		long long u[55]={};
		if (dfs(1,a[i],b[i],u)<n)  ans++;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 256
import math

m = int(input())
a = (m * (m + 1)) // 2
b = 0
c = 0
for i in range(m):
    for j in range(i + 1, m):
        b += math.gcd(i + 1, j + 1)
for i in range(m):
    for j in range(i + 1, m):
        l = math.gcd(i + 1, j + 1)
        for k in range(j + 1, m):
            c += math.gcd(l, k + 1)
print(a + b * 6 + c * 6)

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define AI(a,size,n) array<int,size> a;REP(i,n){assert(0<scanf("%d",&a[i]));}
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(n); VI(ps, n);
  int ans = n - 1;
  vector<int> is(n + 1, -1), inc(n + 1, 0);
  REP(i, n){
    is[ps[i]] = i;
  }
  REP(p, 1, n){
    if (is[p] < is[p + 1]){
      inc[p + 1] = 1;
    }
  }
  REP(p, 2, n + 1){
    if (0 < inc[p - 1] && 0 < inc[p]){
      inc[p] += inc[p - 1];
    }
    ans = min(ans, n - inc[p] - 1);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2688
/*Bismillahir rahmanir rahim*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll              long long int
#define vi              vector<int>
#define sc              scanf
#define pf              printf
#define spc             pf(" ")
#define line            pf("\n")
 
#define pb              push_back
#define ppb             pop_back
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
 
#define sc1(x)          sc("%d",&x)
#define sc2(x,y)        sc("%d %d", &x, &y)
#define sc3(x,y,z)      sc("%d %d %d", &x, &y, &z)
#define scl1(x)         sc("%lld",&x);
#define scl2(x,y)       sc("%lld %lld", &x, &y)
#define scf1(x)         sc("%lf",&x)
#define scf2(x,y)       sc("%lf %lf", &x, &y)
 
#define pf1(x)          pf("%d",x)
#define pf2(x,y)        pf("%d %d", x, y)
#define pf3(x,y,z)      pf("%d %d %d", x, y, z)
#define pfl1(x)         pf("%lld",x)
#define pfl2(x,y)       pf("%lld %lld",x,y)
 
#define PI              acos(-1.0) //3.1415926535897932


 
int main()
{
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
    ///Start_Here.....
    int n,x,cnt=0;
    vi v;
    map<int,int>mymap;
    sc1(n);
    while(n--)
    {
        sc1(x);
        mymap[x]++;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    int un=unique(v.begin(),v.end())-v.begin();
    for(int i=0;i<un;i++)
    {
        //pf("fv=%d fmymap=%d\n",v[i],mymap[v[j]]);
        if(v[i]<mymap[v[i]]) cnt+=mymap[v[i]]-v[i];
        else if(v[i]>mymap[v[i]]) cnt+=mymap[v[i]];
        
    }
    cout<<cnt<<endl;

    ///--End--
    #ifndef ONLINE_JUDGE
       fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
 }

 
/*Alhamdulillah*/

Measured memory_bytes: 8112
import sys
from itertools import accumulate
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, M = map(int, readline().split())
A = list(map(int, read().split()))
A = list(accumulate(A))
a = Counter([i % M for i in A])

zero = 0
if a.get(0):
    zero = a[0]

answer = zero + sum([i * (i - 1) // 2 for i in list(a.values()) if i >= 2])
print(answer)

Measured memory_bytes: 15584
using System;

class B4{
  public static void Main(){
    int n,q,l = 0,count = 0;
    n = int.Parse(Console.ReadLine());
    //string[] S = new string[n];
    string[] str = Console.ReadLine().Split(' ');
    int[] S = new int[n];
    for(int i = 0;i < n;i++){
      S[i] = int.Parse(str[i]);
    }

    /*for(int i = 0;i < n;i++){
      S[i] = str[i];
    }*/

    q = int.Parse(Console.ReadLine());
    //string[] T = new string[q];
    string[] str2 = Console.ReadLine().Split(' ');
    int[] T = new int[n];

    for(int i = 0;i < q;i++){
      T[i] = int.Parse(str2[i]);
    }

  /*  for(int i = 0;i < q;i++){
      T[i] = str2[i];
    }*/

    int[] memory = new int[n];
    for(int i = 0;i < q;i++){
      if(binarySearch(S,T[i]) != -1){
        memory[l] = binarySearch(S,T[i]);
        l++;
      }
    }

  /*  for(int i = 0;i < l;i++){
      Console.Write(memory[i] + " ");
    }
    Console.WriteLine("");
*/
    for(int i = 0;i < l;i++){
      for(int j = 0;j < l;j++){
        if(memory[i].Equals(memory[j])){
          count++;
          break;
        }
      /*bool flag = false;
      for(int j = 0;j < l;j++){
        if(memory[i].Equals(memory[j]) && flag == false){
           count++;
           flag = true;
        }*/
      }
    }
    Console.WriteLine(count);

  }

  static int binarySearch(int[] S,int key){
    int left = 0;
    int right = S.Length;
    while(left < right){
      int mid = (left + right) / 2;
      if(S[mid] == key) return mid;
      else if(key < S[mid]) right = mid;
      else left = mid + 1;
    }
    return -1;
  }
}


Measured memory_bytes: 22280
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define li long long int
#define ld long double
#define F first
#define S second
//const li M = 1000000007;
#define ld long double
li dx[]={-1,1,0,0};
li dy[]={0,0,-1,1};

int main()
{
	li N,K,i,j; cin>>N;
	vector<li> A(100005,0); li sum=0;
	for(i=0;i<N;i++)
	{
		cin>>j; A[j]++; sum+=j;
	}
	li q; cin>>q;
	while(q--)
	{
		cin>>i>>j;
		li fr=A[i];
		A[j]+=fr;
		A[i]-=fr;
		sum = sum + fr*(j-i);
		cout<<sum<<"\n";
	}
	
}



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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


ll dp[101][100010];
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,W;
    cin>>n>>W;
    ll wt[n+1],v[n+1];
    for(int i=1;i<=n;i++)
        cin>>wt[i]>>v[i];
    for(int i=0;i<=100000;i++)
    	dp[0][i] = 1e18;
    dp[0][0] = 0 ;
    for(int i=1;i<=n;i++)
    {
    	for(int val = 1 ;val<=100000;val++)
    	{
    	   if(v[i]<=val)
    	     dp[i][val] = min(dp[i-1][val],dp[i-1][val - v[i]] + wt[i]);
    	   else dp[i][val] = dp[i-1][val];
    	}
    	       	
    }
    ll ans = 0;
    for(int i=1;i<=100000;i++)
    {
    	if(dp[n][i]<=W)
    	   ans = i;   
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 79232
#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(){
  string s;
  cin >> s;
  int ans =0;
  rep(i,3) if(s[i]=='1') ans++;
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>
 
using namespace std;
 
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)

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


int main(int argc, const char * argv[]){
    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC" << endl;
        return 0;
    }else{
        cout << "ABC" << endl;
        return 0;
    }
}

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

int px[90010], py[90010];
int dp[90010];

int main() {
    int H,W,D;
    cin >> H >> W >> D;
    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            int a; cin >> a;
            px[a] = j;
            py[a] = i;
        }
    }

    for (int i=D+1; i<=H*W; i++) {
        dp[i] = dp[i-D] + abs(px[i] - px[i-D]) + abs(py[i] - py[i-D]);
    }

    int Q;
    cin >> Q;
    for (int i=0; i<Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << dp[r] - dp[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include <algorithm>
#include<iomanip>
#include<math.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
    double N;
    cin >> N;
    cout <<setprecision(10)<< 2 * N * 3.1415926535897 << endl;
    return 0;
}

Measured memory_bytes: 3760
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: chars,
    }
    let mut n: Vec<usize> = n
        .into_iter().map(|x| (x as u8 - b'0') as usize).collect();
    n.insert(0, 0);
    let m = n.len();
    const INF: usize = 1 << 50;
    let mut dp = vec![[INF; 2]; m + 1];
    dp[m][0] = 0;
    for i in (0..m).rev() {
        for j in 0..2 {
            let val = n[i] + j;
            dp[i][1] = min(dp[i][1], dp[i + 1][j] + (10 - val));
            dp[i][0] = min(dp[i][0], dp[i + 1][j] + val);
        }
    }
    puts!("{}\n", min(dp[0][0], dp[0][1]));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
  	int min = a[0], max = a[0];
  	long long int sum = 0;
    for(int j = 0; j < n - 1; j++){
        if(min > a[j + 1])
            min = a[j + 1];
    }
    for(int k = 0; k < n - 1; k++){
        if(max < a[k + 1])
            max = a[k + 1];
    }
    for(int l = 0; l < n; l++)
        sum += a[l];
    cout << min << " " << max << " " << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  vector <int> graph[N], regraph(N);

  for (int i = 0; i < N + M - 1; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    graph[A].push_back(B);
    regraph[B]++;
  }
  
  vector <int> order;
  queue <int> que;
  for (int i = 0; i < N; i++){
    if (regraph[i] == 0){
      order.push_back(i);
      que.push(i);
    }
  }
  
  vector <int> ans(N);
  while (!que.empty()){
    int Q = que.front(); que.pop();

    for (int i = 0; i < graph[Q].size(); i++){
      int next = graph[Q][i];
      regraph[next]--;
      if (regraph[next] == 0){
        que.push(next);
        order.push_back(next);
        ans[next] = Q + 1;
      }
    }
  }

  
  for (int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }
  

  return 0;
}


Measured memory_bytes: 7544
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,tt;
const int mxN=1<<18;
int val[mxN],w[mxN];
const int mxW=1e5+5;
int dp[(int)(1<<9)+5][mxW];

void dfs(int u) {
    if(u==1) {
        F0R(i,mxW) {
            if(i<w[u])
                continue;
            dp[u][i]=val[u];
        }
    }
    else {
        F0R(i,mxW) {
            dp[u][i]=dp[u/2][i];
            if(w[u]<=i)
                dp[u][i]=max(dp[u][i],dp[u/2][i-w[u]] + val[u]);
        }
    }
    if(2*u<=min((1<<9),n))
        dfs(2*u);
    if(2*u+1<=min((1<<9),n))
        dfs(2*u+1);
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    FOR(i,1,n+1)
        cin >> val[i] >> w[i];
    dfs(1);
    cin >> tt;
    while(tt--) {
        int v,W;
        cin >> v >> W;
        if(v<=(1<<9)) {
            cout << dp[v][W] << "\n";
            continue;
        }
        vector<int> trace;
        while(v>(1<<9)) {
            trace.push_back(v);
            v/=2;
        }
        REV(trace);
        int best=0;
        F0R(i,1<<sz(trace)) {
            int totVal=0,totW=0;
            int tmp=i;
            F0R(j,sz(trace)) {
                if(tmp%2) {
                    totVal+=val[trace[j]];
                    totW+=w[trace[j]];
                }
                tmp/=2;
            }
            if(totW>W)
                continue;
            best=max(best,dp[v][W-totW] + totVal);
        }
        cout << best << "\n";
    }

    return 0;
}


Measured memory_bytes: 205712
n = int(input())
S_flag = [0] * 13
H_flag = [0] * 13
C_flag = [0] * 13
D_flag = [0] * 13
for i in range(n):
    mark , number = input().split()
    if mark == "S":
        S_flag[int( number )-1] = 1
    elif mark == "H":
        H_flag[int( number )-1] = 1
    elif mark == "D":
        D_flag[int( number )-1] = 1
    elif mark == "C":
        C_flag[int( number )-1] = 1

for i in range(13):
    if S_flag[i] == 0:
        print("S " + str( i + 1 ))

for i in range(13):
    if H_flag[i] == 0:
        print("H " + str( i + 1 ))

for i in range(13):
    if C_flag[i] == 0:
        print("C " + str( i + 1 ))

for i in range(13):
    if D_flag[i] == 0:
        print("D " + str( i + 1 ))




Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}


void oneCase () {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> edges(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    vector<int> componentsColors(n, -1);
    vector<int> componentsSizes;
    int curComp = -1;
    for (int start = 0; start < n; ++start) {
        if (componentsColors[start] != -1) {
            continue;
        }
        ++curComp;
        int count = 0;
        stack<int> nodes;
        nodes.push(start);

        while (!nodes.empty()) {
            auto cur = nodes.top();
            ++count;
            nodes.pop();
            componentsColors[cur] = curComp;

            for (auto out : edges[cur]) {
                if (componentsColors[out] == -1) {
                    componentsColors[out] = curComp;
                    nodes.push(out);
                }
            }
        }
        componentsSizes.push_back(count);
    }


    vector<vector<int>> blocks(n);
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if (componentsColors[a] != componentsColors[b]) {
            continue;
        }
        blocks[a].push_back(b);
        blocks[b].push_back(a);
    }
    for (int i = 0; i < n; ++i) {
        auto comp = componentsColors[i];
        cout << componentsSizes[comp] - 1 - blocks[i].size() - edges[i].size() << " ";
    }
    cout << "\n";

}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 12152
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;

    int ans = 180 * (N - 2);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e5+9;
const int MAXN = 10100;
const ld pi = acos(-1);
const ll mod = 1e9+7;

//bool cmp ( int a,int b ) { return a>b; }
ll vl;
ll po ( ll a , ll b )
{
    if ( b==0 ) { return 1; }
    ll x = po ( a , b/2 );
    x *= x;
    if ( b%2 ) { x*=a; }
    return x;
}
int power(int p)
{
    if(p==0)return 1;
    if(p==1)return vl;
    if(p%2)return (vl*power(p-1))%mod;
    long long x=power(p/2);
    return (x*x)%mod;
}
int mod_inv(ll a,ll b)
{
    vl=b;
    return (a*power(mod-2))%mod;
}
ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { return gcd( b , a%b ); }
}

bool cmp ( int a ,int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 };

vector <int> v[MX];
bool vis[MX];
ll ans=0;
int n,m;
set<int> edge[MX];
void dfs( int x , int mask )
{
    if ( __builtin_popcount(mask)==n ) { ans++; return; }
    for ( int i=0 ; i<n ; i++ )
    {
        if ( !((1<<i)&mask) && edge[x].count(i+1) ) { dfs( i+1 , mask|(1<<i) ); }
    }

}

int main()
{

    cin>>n>>m;
    for ( int i=0 ; i<m ; i++ )
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back( b );
        v[b].push_back( a );
        edge[a].insert( b );
        edge[b].insert( a );
    }
    dfs( 1 , 1 );
    cout<<ans;

    return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int32_t main(){
	int n,t;cin>>n;
	int g;
	for(int i=1;i<=n;i++){
		cin>>t;
		if(i==1){
			g = t;
		}
		else {
			g = __gcd(g,t);
		}
	}
	cout<<g;
}


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


int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i=0; i<N; i++) {
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int tmp=d.at(0), cnt=1;
  for (int i=0; i<N; i++) {
    if (tmp>d.at(i)) {
      tmp = d.at(i);
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char s[10000];
int a=-1;
int main(){
	cin>>s;
	for(int i=0;i<strlen(s);i++)
		if(s[i]=='C'){
			a=i;
			break;
		}
	if(a<0){cout<<"No";	return 0;}
	for(int i=a+1;i<strlen(s);i++)
		if(s[i]=='F'){
			cout<<"Yes";
			return 0;
		}
	cout<<"No";
	return 0;
}	

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    string s;
    cin>>s;
    
    int len=s.size(), cnt=0;
    rep(i,len){
        if(s[i]=='g') cnt++;
        else cnt--;
    }
    if(len%2==1) cnt--;
    
    cout1(cnt/2);
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int x = Integer.parseInt(strlist[0]);
		int y = Integer.parseInt(strlist[1]);
		int[] A = {1, 3, 5, 7, 8,10, 12};
		int[] B = {4, 6, 9, 11};
		ArrayList<Integer> listA = toList(A);
		ArrayList<Integer> listB = toList(B);

		String answer = "No";
		if(x == 2 && y == 2){
			answer = "Yes";
		}else if(listB.contains(x) && listB.contains(y)){
			answer = "Yes";
		}else if(listA.contains(x) && listA.contains(y)){
			answer = "Yes";
		}
		System.out.println(answer);
	}

	public static ArrayList<Integer> toList(int[] list){
		ArrayList<Integer> returnList = new ArrayList<Integer>();
		for(int i=0; i<list.length; i++){
			returnList.add(list[i]);
		}
		return returnList;
	}

}


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

using namespace std;

int main ()
{int K,A,B;
 int iBuf;
  cin >> K;
  cin >> A >> B;
 for(int i = A; i <= B; i++)
 {
   iBuf = i % K;
   if(iBuf == 0)
   {
     cout << "OK" << endl;
     break;
   }
 }
 if(iBuf != 0)
 {
   cout << "NG" << endl;
 }
return 0;
}



Measured memory_bytes: 3596
use std::io::{BufRead, BufWriter, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    solve(&mut stdin.lock(), &mut BufWriter::new(stdout.lock()));
}

fn solve<R: BufRead, W: Write>(stdin: &mut R, stdout: &mut BufWriter<W>) {
    let n = stdin.gets().parse::<usize>().unwrap();
    let a = stdin.gets().split(' ').take(n)
        .map(|x| x.parse::<i64>().unwrap()).collect::<Vec<_>>();
    let total = a.iter().sum::<i64>();
    let mut min = total;
    let mut cum = 0;
    for i in 0..n {
        cum += a[i];
        let t = (cum * 2 - total).abs();
        min = std::cmp::min(min, t);
    }
    writeln!(stdout, "{}", min).unwrap();
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n;
    cin >> n;
    
    vector<int> a(n), b(n), c(n-1);
    
    rep(i, n) cin >> a[i], a[i]--;
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];
    
    int ans = 0;
    int temp = -2;
    
    for (int i = 0; i < n; i++){
        int ryori = a[i];
        int manzoku = b[ryori];
        ans += manzoku;
        
        if(temp + 1 == ryori) ans += c[temp];
        temp = ryori;
        
    }
    cout << ans << endl;
}

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

int main() {
  string str;
  string strFive,strSix;
  bool chk = true;
  cin >> str;
  
  // 後ろから解読
  reverse(str.begin(), str.end());
  
  while(true){
    if(str.size() == 0){
      // 0文字は正常判定
      break;
    }else if(str.size() < 5){
      // 4文字以下はエラー
      chk = false;
      break; 
    }
    
    // 5文字チェック
    strFive = str.substr(0,5);
    if(strFive == "maerd" || strFive == "esare"){
      // OK
      str = str.erase(0,5);
      continue;
    }
    
    if(str.size() >= 6){
      // 6文字チェック
      strSix = str.substr(0,6);
      if(strSix == "resare"){
        // OK
        str = str.erase(0,6);
        continue;
      } 
    }
    
    if(str.size() >= 7){
      // 7文字チェック
      strSix = str.substr(0,7);
      if(strSix == "remaerd"){
        // OK
        str = str.erase(0,7);
        continue;
      }else{
        chk = false;
        break;  
      }
    }
  }
  
  if(chk == true){
    cout << "YES";
  }else{
    cout << "NO";
  }
}


Measured memory_bytes: 512
import copy
N=int(input())
a=[0]*(N+1)
cnta=copy.copy(a)
for i in range(1,N+1):
    a[i]=int(input())

button=1

for i in range(100000):
    cnta[button]=cnta[button]+1
    if cnta[2]==1:
        print(sum(cnta)-1)
        break
    elif cnta[button]>=2:
        print("-1")
        break
    button=a[button]
    


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

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};

//--global--//



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

ll keta(ll a){
    ll cnt = 0;
    while(a > 0){
        cnt++;
        a/=10;
    }
    return cnt;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll n;
    cin >> n;
    ll a, b;
    rep2(i, 1, sqrt(n)+1){
        if(n % i == 0){
            a = i;
            b = n / i;
        }
    }

    ll ans = max(keta(a), keta(b));


    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
   int n, a, b;
   cin >> n >> a >> b;
   out(min(n*a,b));
}

Measured memory_bytes: 256
#include<stdio.h>

int min(int x,int y){
  if (x<=y){
    return x;
  }
    return y;
}

int main(){
  int N;
  scanf("%d",&N);
  int X[N];
  for(int i=0;i<N;i++){
    scanf("%d",&X[i]);
  }

  int ans=1001001001;
  for(int p=1;p<=100;p++){
    int now =0;
    for(int j=0;j<N;j++){
      now += (X[j]-p)*(X[j]-p);
    }
     ans = min(ans,now);
  }
  printf("%d",ans);

  return 0;
}


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

const int MAX = 100000;
int main() {
	int N, K, h[MAX];
	cin >> N >> K;
	for (int i = 0;i < N;++ i) cin >> h[i];
	sort(h, h+N);
	int dist = h[K - 1] - h[0];
	for (int i = K;i < N;++ i) dist = min(dist, h[i] - h[i - K + 1]);
	cout << dist;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

先にソートしよう
すると、選ぶ範囲は当然だけど連続したK本になる
後はその中でmax-minが最小になるようなのは、先頭から順に調べていけばスライド最小値O(N-K)、ということでO(NlogN-K)
*/

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

int r, c, k;
char ar[6][6];

int black()
{
	int res = 0;	
	for (int i = 0; i < r; ++i)
		for (int j = 0; j < c; ++j)
			res += (ar[i][j] == '#');
	return res;
}

bool check(int n)
{
	for (int i = 0; i < r; ++i)
	{
		if (n & (1 << i))
		{
			for (int j = 0; j < c; ++j)
				ar[i][j] = '.';
		}
	}

	for (int j = r; j < r+c; ++j)
	{
		if (n & (1 << j))
		{
			for (int i = 0; i < r; ++i)
				ar[i][j-r] = '.';
		}
	}

	return black() == k;
}

int main()
{
	char def[6][6]; //default

	cin >> r >> c >> k;
	for (int i = 0; i < r; ++i)
		cin >> def[i];

	int res = 0;
	for (int i = 0; i < (1 << r+c); ++i)
	{
		for (int i = 0; i < r; ++i)
			for (int j = 0; j < c; ++j)
				ar[i][j] = def[i][j];

		res += check(i);
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x;ll t,i=119,j=118;
int main()
{
	cin>>x;
	for(ll i=-120;i<=120;i++)
	  for(ll j=-120;j<=120;j++)
	  {
	  	if(i*i*i*i*i-j*j*j*j*j==x)
	  	{
	  		cout<<i<<" "<<j;
	  		return 0;
		  }
	  }
    return 0;
}

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

int main(){
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  vector<int> d(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  for (int i = 0; i < n; i++){
    if (i == 0){
      d[i] = a[i] + k - a[n-1];
    }else{
      d[i] = abs(a[i] - a[i - 1]);
    }
  }
  int sum = 0;
  int mx = 0;
  for (int i = 0; i < n; i++){
    sum = sum + d[i];
    mx = max(mx,d[i]);
  }
  int ans;
  ans = sum - mx;
  cout << ans << endl;
  return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

int main(){
    string s;
    cin >> s;
    i64 n = s.length(), ans = 0;
    rep(i, (1 << (n - 1))){
        i64 tmp = s[0] - '0', sum = 0;
        rep(j, n - 1){
            if(i & (1 << j)){
                sum += tmp;
                tmp = s[j + 1] - '0';
            }else{
                tmp = tmp * 10 + s[j + 1] - '0';
            }
        }
        sum += tmp;
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
t = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0]*3 for _ in range(n)]

dp[0] = [t[0][0], t[0][1], t[0][2]]

for i in range(1, n):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + t[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + t[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + t[i][2]

print(max(dp[-1]))


Measured memory_bytes: 40264
#include<bits/stdc++.h>
int N,M,A[1111],B[1111],V[1111],i,j;main(){scanf("%d%d",&N,&M);for(i=1;i<=N;i++){scanf("%d",&A[i]);}for(i=1;i<=M;i++){scanf("%d",&B[i]);}for(i=1;i<=M;i++){for(j=1;j<=N;j++){if(A[j]<=B[i]){V[j]++;break;}}}printf("%d\n",std::distance(V,std::max_element(V,V+N)));}

Measured memory_bytes: 3232
from collections import Counter
def main():
    N=int(input())
    A=list(map(int,input().split()))
    Q=int(input())
    count= Counter(A)
    ans=sum(A)
    for i in range(Q):
        b,c=map(int,input().split())
        if b in count.keys():
            if c in count.keys():
                count[c] = count[b]+count[c]
            else:
                count[c] = count[b]
            ch=count.pop(b)
            ans+=((c-b)*ch)
            print(ans)
        else:
            print(ans)
main()

Measured memory_bytes: 21340
// author - saiku_ni_naro
// TO THE TOP

#include<bits/stdc++.h>
using namespace std;
#define F_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define double long double
#define endl '\n'
#define For(i,a,n) for(int i=(a);i<=(n);i++)
#define RFor(i,a,n) for(int i=(n);i>=(a);i--)
#define SET(a,val) memset((a),(val),sizeof((a)))
#define X first
#define Y second
#define pb push_back
#define over(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define inp(x) cin>>x;
#define oup(x) cout<<x<<endl;

const int N = 2e5 + 10;
int a[N];
const int MOD = 1e9 + 7;

void solving_problem(){
    int n,k; cin>>n>>k;

    For(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    int product = 1;

    if(a[n] == 0 && (k%2 == 1)){
        cout<<0<<endl;
        return;
    }

    if(a[n] <= 0 && (k%2 == 1)){
        int ans = 1;
        RFor(i,n-k+1,n) ans = (ans*(MOD+a[i]))%MOD;
        cout<<ans<<endl;
        return;
    }

    int i = 1,j = n; 
    int ans = 1;

    if(k%2 == 1){
        ans = (ans*a[j])%MOD;
        j--,k--;
    }

    k>>=1;

    For(iy,1,k){
        int leftP = a[i]*a[i+1];
        int rightP = a[j]*a[j-1];

        if(leftP >= rightP){
            leftP %= MOD;
            ans = (ans*leftP)%MOD;
            i += 2;
        }else {
            rightP %= MOD;
            ans = (ans*rightP)%MOD;
            j -= 2;
        }
    }

    ans = (ans + MOD)%MOD;
    cout<<ans<<endl;
}

signed main(){
    F_IO;

    int testcases = 1; 
    // cin>>testcases;

    For(i,1,testcases){
        // cout<<"Cases #"<<i<<": ";
        solving_problem();
    }
}



Measured memory_bytes: 5136
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> accum(n+1, 0);
    for(int i=0;i<m;i++){
        int l, r;
        cin >> l >> r;
        l--, r--;
        accum[l]++, accum[r+1]--;
    }
    int cnt = 0;
    for(int i=0;i<n+1;i++){
        if(i > 0){
            accum[i] += accum[i-1];
        }
        if(accum[i] == m){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 888