akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
const int nax=2e5+5;
vector<vector<int>> v(nax);
vector<int> t;
int vis[nax]={0};
int rm[nax];
void dfs(int ci){
	vis[ci]=1;
	t.push_back(ci);
	int r=ci;
	for(auto x : v[ci]){
		if(vis[x]==1) continue;
		dfs(x);
		r=rm[x];
	}
	rm[ci]=r;
}
int main(){
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0);
	int arr[n]={0};
	int ind[n];
	for(int i=0;i<n;i++){
		ind[t[i]]=i;
	}
	while(q--){
		int a,b;
		cin>>a>>b;
		a--;
		int in1=ind[a];
		int in2=ind[rm[a]];
		arr[in1]+=b;
		if(in2<=n-2) arr[in2+1]-=b;
	}
	for(int i=1;i<n;i++){
		arr[i]+=arr[i-1];
	}
	for(int i=0;i<n;i++){
		cout<<arr[ind[i]]<<" ";
	}
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e3 + 5;

int main() {
    int N, A, B;
    cin >> A >> B;
    N = A + B;
    int ans[N] = {};
    if (A <= B)
    {
        /* If the number of unkind people is equal or greater than
         * the number of honest people solving the riddle is impossible */
        cout << "Impossible";
        fflush(stdout);     // Flush the output
    }
    else
    {
        // Define stack where we store the possible honest people
        stack<int> people_stack;
        char answer;    // char type answer (either "Y" or "N")

        REP(i, 0, N) {
            if (people_stack.empty())
                people_stack.push(i);
            else {
                cout << "? " << people_stack.top() << " " << i << endl;
                fflush(stdout);     // Flush the output
                cin >> answer;
                if (answer == 'Y') {
                    people_stack.push(i);
                } else {
                    people_stack.pop();
                }
            }
        }
        int s = people_stack.top();
        ans[s] = 1;
        REP(i,0,N)
        {
            cout << "? " << people_stack.top() << " " << i << endl;
            fflush(stdout);     // Flush the output
            cin >> answer;
            if (answer == 'Y')
                ans[i] = 1;
            else
                ans[i] = 0;
        }

        cout << "! ";
        REP(i,0,N) {
            cout << ans[i];
        }
    }
    return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int id;
    edge(int t, int w) : to(t),id(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<edge>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}


int main(){

    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    vector<int> g_a(n);
    vector<int> g_d(n);
    rep(i,n){
        if(i == 0) g_a.at(i) = a.at(0);
        else g_a.at(i) = __gcd(g_a.at(i-1),a.at(i));
    }
    rep(i,n){
        if(i == 0) g_d.at(i) = a.at(n-1);
        else g_d.at(i) = __gcd(g_d.at(i-1),a.at(n-1-i));
    }
    int now;
    int ans = 0;
    rep(i,n){
        if(i == 0) now = g_d.at(n-2);
        else if(i == n-1) now = g_a.at(n-2);
        else now =  __gcd(g_a.at(i-1),g_d.at(n-2-i));
        chmax(ans,now);
    }
    cout << ans << endl;
    
    return 0;
}

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

int main(){
  int H,W;
  while(cin>>H>>W){
    if(H==0 && W==0) break;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i%2==0){
        if(j%2==0) cout<<"#";
        else       cout<<".";
      }else{
        if(j%2==0) cout<<".";
        else       cout<<"#";
      }

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

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

typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int n, k;
  cin >> n >> k;

  vi p(n);
  rep(i, n) cin >> p.at(i);

  sort(p.begin(), p.end());

  int ans = 0;
  rep(i, k) ans += p.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


bool ok(vector<int> A){
  sort(A.begin(),A.end());
  auto tmp = A;
  A.erase(unique(A.begin(),A.end()),A.end());
  if(A.size() != tmp.size()) return 0;
  if(A.back() > 30000) return 0;

  int sum = 0;
  for(int a:A) sum += a;
  
  for(int a:A) if(__gcd(sum-a,a) == 1) return 0;
  int gcd = A[0];
  for(int a:A) gcd = __gcd(a,gcd);
  return gcd == 1;
}


signed main(){
  vector<int> A;
  int n;
  cin>>n;

  if(n == 3){
    cout<<2<<" "<<5<<" "<<63<<endl;
    assert(ok({2,5,63}));
    return 0;
  }

  {  
    int cnt = 0; 
    int sum = 0;  
    for(int i=2;;i+=2){
      if(i >= 30000 || (int)A.size() + 2 >= n) break;
      sum += i;
      A.push_back(i);
      if(sum % 3 == 0) cnt = A.size();
    }
    while((int)A.size() != cnt) A.pop_back();
  }

  
  {
    int sum = 0;
    for(int a:A) sum += a;
    int i;
    for(i=3;;i+=3){
      if(i%2==0) continue;
      if(i > 30000) break;
      if((int)A.size() == n) break;
      A.push_back(i);
      sum += i;
    }
    
    if(sum%2==1){
      A.pop_back();
      sum += 30000;
      A.push_back(30000);
    }

    if(A.size() < n) A.push_back(30000);

    sort(A.begin(),A.end());
    cout<<A<<endl;
    assert(ok(A));
  }
  return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
int main(){
	int ar[100];
	cin>>ar[1]>>ar[2]>>ar[3];
	sort(ar+1,ar+4);
	cout<<ar[1]+ar[2]<<endl;
	return 0;
}


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

int main() {
  string N;
  char check;
  cin >> N;
  check = N[1];

  if((N[0] == check && N[2] == check) || (N[2] == check && N[3] == check)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



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

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 100010

int p[SIZE];
int main() {
   int n;
   scanf("%d", &n);
   for (int i = 1 ; i <= n ; ++i) {
      scanf("%d", p + i);
   } 
   int ans = 0;
   for (int i = 1 ; i <= n ; ++i) {
      if (p[i] == i) {
         ++ans;
         swap(p[i], p[i + 1]);
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i, n - 2) {
	if (s.substr(i, 3) == "ABC") {
		ans++;
	  }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);

            var city = new int[n];
            for(var i = 0; i < m; i++){
                var r = Console.ReadLine().Split();
                city[int.Parse(r[0])-1] += 1;
                city[int.Parse(r[1])-1] += 1;
            }

            for(var i = 0; i < n; i++){
                Console.WriteLine(city[i]);
            }
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
As = list(map(int, input().split()))

ans = 0
while True:
    Bs = [A//N for A in As]
    if sum(Bs) == 0:
        print(ans)
        break
    sumB = sum(Bs)
    ans += sumB
    As = [A%N + sumB - B for A, B in zip(As, Bs)]


Measured memory_bytes: 2940
N = int(input())

cnt = 0
cnt_cnt = 0


for i in range(1,N+1):
  for j in range(1,i+1):
    if i%j == 0 and i%2 !=0:
      cnt += 1
  if cnt == 8:
    cnt_cnt += 1
  cnt = 0
  
print(cnt_cnt)
      
    


Measured memory_bytes: 2940
from itertools import *
A,B,C = map(int,input().split())
ans = 10**18
if A%2 == 0 or B%2 == 0 or C%2 == 0:
  ans = 0
else:
  for i,j in combinations([A,B,C],2):
    ans = min(ans,i*j)
print(ans)

Measured memory_bytes: 3060
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<LL> a(n);
		REP(i, n) cin >> a[i];
		sort(ALL(a));
		LL sum = 0;
		REP(i, n) {
			sum += a[i];
		}
		LL ans = sum;
		for(int i = 0; i < n - 1; i += 2) {
			sum -= (a[i] + a[i+1]);
			sum -= (a[i] + a[i+1]);
			chmax(ans, sum);
		}
		cout << ans << endl;
		
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   long long n,a,b;
   cin>>n>>a>>b;
   long long ans=0;
   if(a==b)ans=1;
   else if(a!=b && n==1)ans=0;
   else if(a>b)ans=0;
   else ans=a+b*(n-1)-(a*(n-1)+b)+1;
   cout<<ans<<endl;
}

   


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

int main() {
    int n,k;
    cin >> n >> k;
    int l,r;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x==1) l=i+1;
    }
    r=n-l+1;
    int ans=0;

    if(n==k){
        ans =1;
    }
    else if(l<=k || r<=k){
        n -= k;
        ans ++;
        ans += (n-1)/(k-1)+1;
    }
    else{
        n--;
        ans += n/(k-1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << ' ' << X << ' ' << Y << endl;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))




int solve(int a,int b,int c,int d){
    int ans=0;
    if(a<=c && b>=d){
        ans=max(ans,d-c);
    }
    else if(c>=a && c<=b){
        ans=max(ans,b-c);
    }
    return ans;


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(t--){
        cout<<max(solve(a,b,c,d),solve(c,d,a,b));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long n, m;

long long can(long long mid) {
    long long S = mid, cc = mid * 2;
    
    if(S <= n && cc <= m)
        return true;
    else {
        if(cc > m) return false;
        
        long long needS = S - n;
        
        if(cc <= (m - (needS * 2)))
            return true;
        else
            return false;
    }
}

int main() {
    cin >> n >> m;
    
    long long l = 0, r = 1e18, res;
    while(l <= r) {
        long long mid = (l + r) / 2;
        
        if(can(mid)) {
            res = mid;
            l = mid + 1;
        } else
            r = mid - 1;
    }
    
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

typedef int64_t ll;
using namespace std;

int main() {
    // freopen("output.txt", "w", stdout);

    int a, b;
    cin >> a >> b;
    for (int i=1; i<=3; i++) {
        if ((a*b*i)%2 != 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

int main(int argc, const char *argv[]) {
    int n;
    std::cin >> n;
    std::string taroCard, hanakoCard;
    int taroPoint = 0, hanakoPoint = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> taroCard >> hanakoCard;
        if (taroCard < hanakoCard) {
            hanakoPoint += 3;
        } else if (taroCard > hanakoCard) {
            taroPoint += 3;
        } else {
            taroPoint++;
            hanakoPoint++;
        }
    }
    std::cout << taroPoint << " " << hanakoPoint << std::endl;
    return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <cstdint>

int main()
{
  // 1 <= N =< 86
  int N;
  std::cin >> N;
  if (N == 1) {
    std::cout << 1 << std::endl;
    return 0;
  }
  uint64_t L0 = 2;
  uint64_t L1 = 1;
  uint64_t L = 0;
  for (int i = 2; i <= N; i++) {
    L = L0 + L1;
    L0 = L1;
    L1 = L;
  }
  std::cout << L << std::endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp::min;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n = buf.trim().parse::<i32>().ok().unwrap();
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v = Vec::new();
	for i in iter {
		v.push(i.parse::<i32>().ok().unwrap());
	}
	let mut minimam = 100;
	for i in 0..(n-1) {
		let mut s1 = 0;
		let mut s2 = 0;
		for j in 0..(i+1) {
			s1 += v[j as usize];
		}
		for j in (i+1)..n {
			s2 += v[j as usize];
		}
		minimam = min(minimam, (s1 - s2).abs());
	}
	println!("{}", minimam);
}

Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

const int M=10000;

int main(int argc,char* argv[])
{
    int n;
    cin>>n;
    cout<<((int)((n-1)/111)+1)*111<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int flag = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "Y") {
            flag += 1;
        }
    }
    if (flag == 0) {
        cout << "Three" << endl;
    }
    else {
        cout << "Four" <<endl;
    }
}

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

int main(){
  string s; cin >> s;
  int diff = 0;
  int point = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'p') {
      if (diff > 0) {
        diff--;
      } else {
        diff++;
        point--;
      }
    }
    else {
      if (diff > 0) {
        diff--;
        point++;
      } else {
        diff++;
      }
    }
  }
  cout << point << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;
char s[52][52];

int main(){
   int h,w;
   cin>>h>>w;
   for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
         cin>>s[i][j];
      }
   }
   for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
         int cnt=0;
         if(s[i][j]=='.'){
            for(int k=-1;k<=1;k++){
               for(int l=-1;l<=1;l++){
                  if(0<=i+k && i+k<h && 0<=j+l && j+l<w && s[i+k][j+l]=='#'){
                     cnt++;
                  }
               }
            }
            s[i][j]=char(cnt+'0');
         }
      }
   }
   for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
         cout<<s[i][j];
      }
      cout<<endl;
   }

   
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

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

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;
const int INF = 1 << 30;

int score[400000];

void solve()
{
  fill(score, score + 400000, INF);
  score[0] = 0;

  int d, g, p_input, c_input;
  cin >> d >> g;
  g /= 100;
  vector< vector<int> > point(d, vector<int>());

  for(int i = 0; i < d; ++i)
  {
    cin >> p_input >> c_input;
    c_input /= 100;
    for(int j = 0; j < p_input; ++j)
    {
      point[i].emplace_back( (i+1) * (j+1) );
    }
    point[i].back() += c_input;
  }

  // 1点問題
  for(int p = 1; p <= point[0].size(); ++p) score[point[0][p - 1]] = p;
  int over = point[0].back();

  // sc点問題
  for(int sc = 2; sc <= d; ++sc)
  {
    int sc_index = sc - 1;
    for(int s = min(g, over); s >= 0; --s)
    {
      if (score[s] != INF)
      for(int p = 1; p <= point[sc_index].size(); ++p)
      {
        score[s + point[sc_index][p - 1]] = min(score[s + point[sc_index][p - 1]], score[s] + p);
      }
    }
    over += point[sc_index].back();
    // cout << sc << " " << over << endl;
  }

  int ans = INF;
  for(int i = g; i <= over; ++i) ans = min(ans, score[i]);
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 5168
a, b = map(int, input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

target = Base_10_to_n(a, b)

ans = list(target)

print(len(target))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll s;cin>>s;
    cout<<"0 0 1 1000000000 ";
    ll x,y;
    ll t=s;
    ll dig=0;
    while(t>0){
        t/=10;
        dig++;
    }
    dig--;
    if(s<=1000000000){
        x=0;y=s;
    }
    else{
        x=s/1000000000;
        if(x%1000000000!=0)x++;
        y=1000000000*x-s;
    }
    
    cout<<x<<' '<<y<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int F[101][10], P[101][11];

int main(){
    LL N;
    cin >> N;
    for(int i = 1;i <= N;i++){
        for(int j = 0;j < 10;j++){
            cin >> F[i][j];
        }
    }
    for(int i = 1;i <= N;i++){
        for(int j = 0;j <= 10;j++){
            cin >> P[i][j];
        }
    }
    LL ans = -100000000000;
    for(int i = 1;i < 1<<10;i++){
        int bit[10];
        for(int j = 0;j < 10;j++){
            if(i >> j & 1)  bit[j] = 1;
            else    bit[j] = 0;
        }
        LL count = 0;
        for(int j = 1;j <= N;j++){
            LL ci = 0;
            for(int k = 0;k < 10;k++){
                if(bit[k] & F[j][k])   ci++;
            }
            count += P[j][ci];
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

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


def main():
    s = input()
    f = int(s[:2])
    l = int(s[2:])

    if 1 <= f <= 12 and 1 <= l <= 12:
        print('AMBIGUOUS')
    elif 1 <= l <= 12:
        print('YYMM')
    elif 1 <= f <= 12:
        print('MMYY')
    else:
        print('NA')


if __name__ == '__main__':
    main()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const ll inf = 1e9;
const ll MOD = 1e9 + 7;
const ll nax = 200000 + 10;

vi graph[nax];
ll visited[nax];
bool flag = false;
ll co[nax];

void dfs(ll v, ll c)
{
    visited[v] = 1;
    co[v] = c;
    for(auto x: graph[v])
    {
        if(visited[x] == 1 && co[x] == c)
            flag = true;
        if(visited[x] == 0)
            dfs(x, 1 - c);
    }
}
ll n, m;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(ll i = 1; i <= m; i++)
    {
        ll u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(1, 0);
    if(!flag)
    {
        ll b = 0;
        for(ll i = 1; i <= n; i++)
        {
            if(co[i] == 0) b++;
        }
        ll w = n - b;
        cout << b * w - m;
    }
    else
        cout << (n * (n - 1)) / 2 - m;
    return 0;
}


Measured memory_bytes: 11264
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    const int N = 100;

    int A, B;
    read(A, B);

    string mat[105];
    rep(i, N) {
        if (i < N / 2) mat[i] = string(N, '#');
        else mat[i] = string(N, '.');
    }

    for (int i = 1; i < N/2; ++++i) {
        for (int j = 0; A > 1 && j < N; ++++j) {
            mat[i][j] = '.';
            --A;
        }
    }

    for (int i = N/2 + 1; i < N; ++++i) {
        for (int j = 0; B > 1 && j < N; ++++j) {
            mat[i][j] = '#';
            --B;
        }
    }

    print(N, N);
    rep(i, N) print(mat[i]);

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int k, x; cin>>k>>x;

    cout << (500 * k >= x ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int A, B;	cin >> A >> B;
	if (A == B) {
		cout << "Draw" << endl;
		return 0;
	}
	if (A == 1) {
		cout << "Alice" << endl;
		return 0;
	}
	if (B == 1) {
		cout << "Bob" << endl;
		return 0;
	}

	if (A > B) {
		cout << "Alice" << endl;
		return 0;
	}
	cout << "Bob" << endl;

	return 0;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main(void){
    long long N;
    long long h, pre=0;
    bool des = false;
    cin >> N;
    for(int i = 0;i < N; i++){
        cin >> h;
        //cout << h << ":" << des <<  endl;
        if(pre > h){
            if(((pre - h) > 1) || des == true){
                cout << "No" << endl;
                return 0;
            } else des = true;
        } else if(pre < h) des = false;
        pre = h;
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
vector<ll> ans(n);
rep(i, n){
  cin >> a[i];
  ans[a[i]-1]=i+1;
}

for(auto aa:ans)cout << aa << " ";
return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a, b, v[51], c[51][51];

ll choice(){
	for(ll i = 0; i <= 50; i++){for(ll j = 0; j <=50; j++){c[i][j] = 0;}}
	c[0][0] = 1;
	for(ll i = 1; i <= 50; i++){
		c[i][0] = 1;
		for(ll j = 1; j <=50; j++){
			c[i][j] = c[i-1][j-1]+c[i-1][j];
		}
	}
	return 0;
}

int main() {
	cin >> n >> a >> b;
	for(ll i = 1; i <= n; i++){cin >> v[i];}
	sort(v+1, v+n+1, greater<>());
	double mean = 0.0;
	for(ll i = 1; i <= a; i++){mean += v[i];}
	mean /= a;
	
	ll min = v[a];
	ll ina = 0; for(ll i = 1; i <= a; i++){if(v[i] == min){ina++;}}
	ll all = 0; for(ll i = 1; i <= n; i++){if(v[i] == min){all++;}}
	
	choice();
	ll conb = 0;
	if(ina == a){for(ll i = a; i <= b; i++){conb += c[all][i];}}
	else{conb = c[all][ina];}
	
	cout.precision(20);
	cout << fixed << mean << endl;
	cout << conb << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools

N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = len(list(itertools.combinations(range(N), 2)))

if M == 1:
    c2 = 0
else:
    c2 = len(list(itertools.combinations(range(M), 2)))

c3 = c1 + c2
print(c3)

Measured memory_bytes: 3444
#include<stdio.h>

int main(void)
{
  int A[101][101]={{},{}},r,c,i,j;
  scanf("%d%d",&r,&c);
  for(i=0;i<r;i++)
	{
	  for(j=0;j<c;j++)
	{
	  scanf("%d",&A[i][j]);
	  A[i][c]+=A[i][j];
	  A[r][j]+=A[i][j];
	  A[r][c]+=A[i][j];
	}
	}

  for(i=0;i<=r;i++)
    {
      for(j=0;j<=c;j++)
    {
  	  printf("%d",A[i][j]);
  	  if(j!=c){printf(" ");}
    }
      printf("\n");
    }

  return 0;
}

Measured memory_bytes: 652
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll res = LINF;
    for(ll i = 0; i <= 2 * max(X, Y); i += 2) {
        ll restX = max(0LL, X - i / 2), restY = max(0LL, Y - i / 2);
        res = min(res, A * restX + B * restY + C * i);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vector<int> wsum(n+1);
  rep(i, n) wsum[i+1] = wsum[i]+(s[i] == 'W');
  int ans = INF;
  rep(i, n) {
    int num = wsum[i]+n-i-1-(wsum[n]-wsum[i+1]);
    chmin(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1812
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int main(){
	ll a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	if(a>b){
		swap(a,b);
	}
	if(a+v*t>=b+w*t){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


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

vector<int> adj[100009];
int P[100009], V[100009];
bool chk[100009];
char C[100009];
int id, v = -1;

int f(int now, int par) {
    int c = 0;
    for(auto& it: adj[now]) if(it != par) c += f(it, now);
    return chk[now] = (c == (int)adj[now].size() - 1 && C[now] == 'B');
}

void dfs(int now, int par, int s) {
    if(v < s) id = now, v = s;
    for(auto& it: adj[now]) if(it != par && !chk[it]) dfs(it, now, s + V[it]);
}

int main() {
    int N; scanf("%d",&N);
    for(int i=0; i<N-1; i++) {
        int u, v; scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int cnt = 0;
    for(int i=1; i<=N; i++) {
        scanf(" %c",&C[i]);
        if(C[i] == 'W') ++cnt;
    }
    if(cnt <= 1) return !printf("%d",cnt);

    int st;
    for(int i=1; i<=N; i++) {
        if(C[i] == 'W') {
            st = i;
            f(i, i);
            break;
        }
    }

    int X = -2;
    for(int i=1; i<=N; i++) {
        if(!chk[i]) {
            X += 2;
            int c = 0;
            for(auto& it: adj[i]) if(!chk[it]) ++c;
            V[i] = ((c % 2) ^ (C[i] == 'W'));
            X += V[i];
        }
    }

    dfs(st, st, V[st]);
    v = -1;
    dfs(id, id, V[id]);
    printf("%d", X - 2*v);
    return 0;
}


Measured memory_bytes: 12544
#include <cstdio>
#include <utility>
#include <cctype>
#include <complex>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
#define dbg(...) fprintf(stderr,__VA_ARGS__)
struct range{
	int e,b=0,s=1;range(int b,int e,int s):e(e),b(b),s(s){} range(int b,int e): e(e), b(b){} range(int e):e(e){}
	struct it{int v,s; it(int v,int s):v(v),s(s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

_T using C = complex<T>;
#define R real
#define I imag

struct Q {
	C<C<int>> q;
	Q (C<int> a, C<int> b) : q {a, b} { }
	Q () : q {} { q = {{in, in}, {in, in}}; }
	Q operator * (Q a) {
		return {
			R(q) * R(a.q) - I(q) * conj(I(a.q)),
			R(q) * I(a.q) + I(q) * conj(R(a.q))};
	}
	void dump() {
		outl(R(R(q)), ' ', I(R(q)), ' ', R(I(q)), ' ',I(I(q)));
	}
};

int main() {
	for (int n; (n = in);)
		times(i, n) {
			Q a, b;
			(a * b).dump();
		}
}


Measured memory_bytes: 2528
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
int num[qq];
LL inv[qq];
map<int, int> mp;
LL Power(LL x, LL t){
	LL ret = 1;
	while(t > 0){
		if(t & 1)	ret = (ret * x) % MOD;
		x = (x * x) % MOD;
		t >>= 1;
	}
	return ret;
}
LL Calc(int a, int b){
	if(a < b)	return 0;
	return inv[a] * Power(inv[b], MOD - 2) % MOD * Power(inv[a - b], MOD - 2) % MOD;
}

int main(){
	LL n;	scanf("%lld", &n);
	bool f = false;
	int l, r;
	REP(i, 1, n + 1){
		int x;scanf("%d", &x);
		num[x]++;
		if(!f){
			if(num[x] == 2){
				l = mp[x];
				r = i;
				f = true;
			}
		}
		mp[x] = i;
	}
	++n;
	inv[0] = 1LL;
	REP(i, 1, n){
		inv[i] = inv[i - 1] * (LL)i % MOD;
	}
	REP(i, 1, n){
		printf("%lld\n", (((Calc(n, i) - Calc(n - r + l - 1, i - 1)) % MOD + MOD) % MOD));
	}
	return 0;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = 998244353; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}


ll bit[500000] = {0};
ll n;

void add(ll idx, ll val) {
    for (++idx; idx <= n; idx += idx & -idx) {
        bit[idx] += (MOD + val)%MOD;
        bit[idx]%=MOD;
    }
}

void range_add(ll l, ll r, ll val) {
    add(l, val);
    add(r + 1, -val);
}

int point_query(ll idx) {
    ll ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx) {
        ret += (MOD + bit[idx])%MOD;
        ret%=MOD;
    }
    return ret%MOD;
}

void solve(ll testnum)
{
    ll k;
    cin >> n >> k;
    vpll lrs(k);
    for(ll i = 0; i < k; i++) {
    	cin >> lrs[i].ff >> lrs[i].ss;
    }
    for(ll i = 0; i <= n; i++) {
    	bit[i] = 0;
    }
    // range_add(0, 4, 2);
    range_add(0, 0, 1);
    // cout << point_query(1) << "\n";
    for(ll i = 1; i <= n-1; i++) {
    	int val = point_query(i-1);
    	// cout << i << " " << val << "\n";
    	for(ll j = 0; j < k; j++) {
    		ll lt = i + lrs[j].ff;
    		ll rt = i + lrs[j].ss;
    		if(lt <= n) {
    			if(rt > n) {
    				rt = n;
    			}
    			range_add(lt-1, rt-1, val);
    			// cout << lt << " " << rt << " " << val << " " << point_query(4) << "\n";
    		}
    	}
    }
    cout << point_query(n-1) << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 5212
#include<stdio.h>
long long min(long long a,long long b)
{
	if(a>b)return b;
	else return a;
}
int main()
{
	long long n;
	scanf("%I64lld",&n);
	long long a,b;
	scanf("%I64lld %I64lld",&a,&b);
	long long tem;
	if(b>a)
	{
		tem=a;
		a=b;
		b=tem;
	}
	if((a-b)%2==0)printf("%I64lld\n",(a-b)/2);
	else
	{
		printf("%I64lld\n",min(b-1+1+(a-b-1)/2,n-a+1+(n-(b+n-a)-1)/2));
	}
	return 0;
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(string S, long long K) {
  // vec<ll> s;
  // while(S>0){
  //   s.push_back(S%10); S/=10;
  // }
  // reverse(all(s));
  //dump(s);
  char ret='1';
  rep(k,min(K,(ll)S.size())){
    if(S[k]!='1'){ret = S[k]; break;}
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  string S;
  std::cin >> S;
  long long K;
  std::cin >> K;
  solve(S, K);
  return 0;
}


Measured memory_bytes: 3556
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		PriorityQueue pq = new PriorityQueue (N, new MyComparator());

		for (int index=0; index<N; index++) {
			pq.add(sc.nextInt());
		}
		for (int index=0; index<M; index++) {
			int num = (int) pq.poll();
			pq.add(num/2);
		}
		long total = 0;
		for (int index=0; index<N; index++) {
			total+=(int) pq.poll();
		}
		System.out.println(total);
	}
}

class MyComparator implements Comparator{
	@Override
	public int compare (Object arg0, Object arg1) {
		int x = (int) arg0;
		int y = (int) arg1;

		if (x<y) {
			return 1;
		} else if (x>y) {
			return -1;
		} else {
			return 0;
		}
	}
}


Measured memory_bytes: 62444
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] l = new int[N];
		for (int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}

		int cnt = 0;
		while (true) {
			for (int i = 0; i < N; i++) {
				if (l[i] % 2 != 0) {
					System.out.println(cnt);
					return;
				}
				l[i] /= 2;
			}
			cnt++;
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a.at(i);
    vector<int>ans(n);
    rep(i,n) ans.at(a.at(i)-1)=i+1;
    rep(i,n)cout << ans.at(i) << endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

const int maxn=1e5+5;
int n;
vector<int> g[maxn*2];
int d1[maxn],d2[maxn];

void dfs(int rt,int fa,int d,int dist[])
{
    dist[rt]=d;
    for(int x:g[rt])
    {
        if(x!=fa)
            dfs(x,rt,d+1,dist);
    }
}

int main()
{
	ios :: sync_with_stdio(false);
    while(cin>>n)
    {
        for (int i=0;i<n;i++) {
            g[i].clear();
        }
        int u,v;
        for (int i=0;i<n-1;i++)
        {
            cin >> u >> v;
            u--,v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        dfs(0,-1,0,d1);
        dfs(n-1,-1,0,d2);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if (d1[i]<=d2[i]) {
            	ans++;
			}
            else {
            	ans--;
            }
        }
        if(ans>0)
            cout << "Fennec" << endl;
        else
            cout<<"Snuke"<<endl;
    }
    return 0;
}

Measured memory_bytes: 15104
//ABC163 A

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#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++)
const lint mod = 1000000007;


lint ans = 0;
lint n;
lint a[300000];


int main() {
  cin >> n;

/*   rep(i,n){
    scanf("%lld",&a[i]);
  } */

  
  printf("%lf\n",2*n*M_PI);
}


Measured memory_bytes: 3764