akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init();
void printList();
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
void delete(int);
void insert(int);

main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


NodePointer listSearch(int key){
  NodePointer x;
  x=nil->next;
  while(x!=nil && x->key!=key){
    x=x->next; 
 }
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
    x=listSearch(key);
    if ( x == nil ) return;
    deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

Measured memory_bytes: 31788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;


int prime[1000001];

bool fact(int x){
    for (int i = 2; i * i <= x; i++){
        if(x % i == 0){
            while(x % i == 0){
                x /= i;
            }
            if(prime[i] != 0) return false;
            prime[i]++;
        }
    }
    if(x != 1){
        if(prime[x] != 0) return false;
        prime[x]++;
    }
    return true;
}

int gcd(int x, int y){
    if(y == 0) return x;
    else return gcd(y, x % y);
}



int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    rep(i, n){
        if(!fact(a[i])) break;
        if(i == n - 1){
            cout << "pairwise coprime" << endl;
            return 0;
        }
    }
    int gcd_ = a[0];
    rep(i, n-1){
        gcd_ = gcd(a[i+1], gcd_);
    }
    if(gcd_ == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;

    // rep(i, 6){
    //     cout << prime[i] << endl;
    // }
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	vector<vector<int>> ans(n, vector<int>(n, -1));
	vector<vector<int>> vv(n, vector<int>());
	rep(i, n){
		if(i != n-1)vv.at(i).push_back(i+1);
		if(i != 0) vv.at(i).push_back(i-1);
		if(i == x) vv.at(i).push_back(y);
		if(i == y) vv.at(i).push_back(x);
	}
	
	rep(i, n){
		queue<int> q;
		q.push(i); ans.at(i).at(i) = 0;
		while(!q.empty()){
			int fr = q.front(); q.pop();
			for(auto a : vv.at(fr)){
				if(ans.at(i).at(a) == -1){
					ans.at(i).at(a) = ans.at(i).at(fr) + 1;
					q.push(a);
				}
			}
		}
	}
	vector<int> ans_2(n-1, 0);
	rep(i, n){
		rep2(j, i+1, n){
			int add = ans.at(i).at(j);
			add--;
			ans_2.at(add)++;
		}
	}
	rep(i, n-1){
		cout << ans_2.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 16128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    int ans = 0;
    rep(i,N) {
        int val = 0;
        rep(j,N) {
            if (j <= i) val += A[j];
            if (j >= i) val += B[j];
        }
        chmax(ans,val);
    }

    cout << ans << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N){
  ll ans=0;
  if(N%2==0){
    N/=2;
    while(N){
      N/=5;
      ans+=N;
    }
  }else{

  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

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

	if(x>y)
	  cout << ">" <<endl;
	else if(x == y)
	  cout <<"=" <<endl;
	else
	  cout <<"<" <<endl;
 	 
	return 0; 
 }


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

int get_cost(int n, vector<int> vec) {
    int cost = 0;
    for (int i : vec) {
        cost += (n - i) * (n - i);
    }

    return cost;
}

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

    vector<int> a;
    int k;
    for (int i = 0; i < N; i++) {
        cin >> k;
        a.push_back(k);
    }

    int min_cost = -1;
    for (int i = -100; i <= 100; i++) {
        int cost = get_cost(i, a);
        if (cost < min_cost || min_cost == -1) {
            min_cost = cost;
        }
    }

    cout << min_cost << endl;

    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a != 0 ? gcd (b % a, a) : b; }

int n;
int m;

int main () {
	scanf ("%d", &n);
	if (n == 1) {
		printf ("1\n1\n");
		re 0;
	}
	m = (n + 3) / 4;
	m *= 2;
	printf ("%d\n", m);
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			int k = (i + j) % m + (i % 2) * m;
			if (k >= n) k -= m;
			printf ("%d ", k + 1);
		}
		printf ("\n");
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

int main(){
    int n,w; cin >> n >> w;
    vector<Pll> v;
    rep(i,n){
        ll a,b; cin >> a >> b;
        v.pb({a,-b});
    }
    sort(ALL(v));
    vector<Pll> v1;
    vector<Pll> v2;
    vector<Pll> v3;
    vector<Pll> v4;
    rep(i,n){
        if(v[i].fi==v[0].fi) v1.pb({v[i].fi,v[i].se});
        else if(v[i].fi==v[0].fi+1) v2.pb({v[i].fi,v[i].se});
        else if(v[i].fi==v[0].fi+2) v3.pb({v[i].fi,v[i].se});
        else v4.pb({v[i].fi,v[i].se});
    }
    ll va1[n+1],va2[n+1],va3[n+1],va4[n+1];
    va1[0]=va2[0]=va3[0]=va4[0]=0;
    rep(i,v1.size()){
        va1[i+1]=va1[i]-v1[i].se;
    }
    rep(i,v2.size()){
        va2[i+1]=va2[i]-v2[i].se;
    }
    rep(i,v3.size()){
        va3[i+1]=va3[i]-v3[i].se;
    }
    rep(i,v4.size()){
        va4[i+1]=va4[i]-v4[i].se;
    }
    ll ans=0;
    ll a=v[0].fi;
    rep(i,v1.size()+1){
        rep(j,v2.size()+1){
            rep(k,v3.size()+1){
                rep(l,v4.size()+1){
                    //i,j,k,l個上から取る
                    if(a*(i+j+k+l)+j+2*k+3*l<=w){
                        chmax(ans,va1[i]+va2[j]+va3[k]+va4[l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Edge
{
    int x,y,v;
}e[200005];
int n,f[100005],cnt=0;
inline void Addedge(int x,int y,int v)
{
    e[++cnt]=(Edge){x,y,v};return;
}
inline bool cmp(const Edge& a,const Edge& b){return a.v<b.v;}
struct Node
{
    int x,y;
}a[100005];
inline int dis(int x,int y)
{
    return min(abs(a[x].x-a[y].x),abs(a[x].y-a[y].y));
}
inline int GetFather(int x)
{
    if(f[x]==x)return x;
    else return f[x]=GetFather(f[x]);
}
inline int Kruskal(void)
{
    int i,x,y,ans=0;
    for(i=1;i<=n;++i)f[i]=i;
    for(i=1;i<=cnt;++i)
    {
        x=GetFather(e[i].x);
        y=GetFather(e[i].y);
        if(x==y)continue;
        f[x]=y;ans+=e[i].v;
    }
    return ans;
}
pair<int,int>sx[100005],sy[100005];
int main(void)
{
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        sx[i]=make_pair(a[i].x,i);
        sy[i]=make_pair(a[i].y,i);
    }
    sort(sx+1,sx+n+1);
    sort(sy+1,sy+n+1);
    for(i=2;i<=n;++i)
    {
        Addedge(sx[i-1].second,sx[i].second,dis(sx[i-1].second,sx[i].second));
        Addedge(sy[i-1].second,sy[i].second,dis(sy[i-1].second,sy[i].second));
    }
    sort(e+1,e+cnt+1,cmp);
    printf("%d\n",Kruskal());
    return 0;
}


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

void solve (int test_case) {
   int n ;
   cin >> n ;
   int x = 0 ;
   vector<int> a(n) ;
   for (int i = 0 ; i < n ; ++i){
       cin >> a[i] ;
       x ^= a[i] ;
   }
   for (int i = 0 ; i < n ; ++i) {
       a[i] ^= x ;
   }
   for (int i = 0 ; i < n ; ++i) {
       cout << a[i] << ' ' ;
   }
   cout << '\n' ;
}

int main () {
   ios_base::sync_with_stdio(false) ;
   cin.tie(NULL) ;
   cout.tie(NULL) ;
   int tc = 1 ;
   //cin >> tc ;
   for (int i = 1 ; i <= tc ; ++i) {
      solve(i) ;
   }
}


Measured memory_bytes: 3992
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int numtotal = 0;
    int pricetotal = 0;
    int num, price;
    int counter = 0;
    int ave;
    
    while (scanf("%d,%d", &price, &num) != EOF) {
        if (price == 0) {
            break;
        }
        pricetotal += price * num;
        numtotal += num;
        counter++;
    }
    ave = numtotal * 10 / counter;
    if (ave % 10 >= 5) {
        ave -= ave % 10;
        ave += 10;
        ave /= 10;
    }
    else {
        ave /= 10;
    }
    printf("%1.0d\n%1.0d\n", pricetotal, ave);
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    set<int> cur{3, 5, 7};
    for (int _ = 0; _ < 8; _++) {
        set<int> tmp(cur);
        for (int x: tmp) for (int d: {3, 5, 7}) cur.emplace(x * 10 + d);
    }
    auto count = [&](int x) {
        set<int> se;
        while (x) se.emplace(x % 10), x /= 10;
        return se.size();
    };
    int n; cin >> n;
    int cnt = 0;
    for (int x: cur) if (x <= n && count(x) == 3) cnt++;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define for1(i,n) for(int i=1;i<=(int)(n);i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){  a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      int a[n+1];
      for(int i=1;i<=n;i++) cin>>a[i];
      int an[n+1];
      for(int i=1;i<=n;i++) an[i]=0;
      for(int i=n;i>=1;i--)
      {
            int cnt=0;
            for(int j=i;j<=n;j+=i)
            {
                  cnt+=an[j];
            }
            if(cnt%2!=a[i])
            {
                  // cout<<i<<" "<<cnt<<"\n";
                  an[i]^=1;
            }
      }
      // for(int i=1;i<=n;i++) cout<<an[i]<<" ";
      for(int i=1;i<=n;i++)
      {
            int cnt=0;
            for(int j=i;j<=n;j+=i)
            {
                  cnt+=an[j];
            }
            if(cnt%2!=a[i])
            {
                 // assert(false);
                 cout<<"-1";
                  return 0;
            }
      }
      vector<int> ans;
      for(int i=1;i<=n;i++)
      {
            if(an[i]==1) ans.pb(i);
      }
      cout<<ans.size()<<"\n";
      for(auto x:ans) cout<<x<<" ";
}
/*
4
0 1 0 1
1 0 0 1
*/
// I never lose. I either win or I learn

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

int main(){
    int N;
    cin >> N;
    vector<int> h(N), c(N);
    rep(i, N) cin >> h.at(i);
    c.at(0) = 0;
    c.at(1) = abs(h.at(1) - h.at(0));
    for(int i=2;i<N;i++){
        int h1 = abs(h.at(i) - h.at(i-1));
        int h2 = abs(h.at(i) - h.at(i-2));
        c.at(i) = min(c.at(i-1) + h1,c.at(i-2) + h2);
    }
    cout << c.at(N-1) << endl;
    return 0;
}


Measured memory_bytes: 3976
# https://atcoder.jp/contests/abc065/tasks/arc076_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

def main():
    N, M = map(int, input().split())

    mod = 10**9 + 7

    if abs(N - M) > 1:
        print(0)
        exit()

    n = 1
    m = 1
    for i in range(1, N + 1):
        n = (n * i) % mod
    for i in range(1, M + 1):
        m = (m * i) % mod

    if N == M:
        print((n * m * 2) % mod)
    else:
        print((n * m) % mod)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

a,b,c,d = inL()
l = []
l.append(a*c)
l.append(a*d)
l.append(b*c)
l.append(b*d)
print(max(l))

Measured memory_bytes: 61896
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;


// Inputs
int D;
vector<int> c;
vector<vector<int>> s;

class Answer {
public:
    // 0~25の構造体
    vector<int> ans;
    explicit Answer() {
        ans.resize(D,0);
    }

    void print_ans() {
        for(const auto &it: ans) cout << it+1 << endl;
    }
};


// スコア計算を行う
ll calc(const Answer& ans) {
    // あるコンテストi-1が開催されていない日数
    vector<int> not_open_term(26,0);
    ll manzoku = 0;
    REP(day,D) {
        manzoku += s[day][ans.ans[day]];
        REP(typ,26) not_open_term[typ]++;
        REP(typ,26) if(typ != ans.ans[day])manzoku -= not_open_term[typ] * c[typ];
        not_open_term[ans.ans[day]] = 0;
        // For B その日終了時に満足度を出力する。
        // cout << manzoku << endl;
    }
    return manzoku;
}


void read() {
    cin >> D;
    c.resize(26);
    REP(i,26) cin >> c[i];
    s.resize(D);
    REP(i,D) {
        s[i].resize(26);
        REP(j,26) cin >> s[i][j];
    }
}

// 下がりやすさを無視して一番点が高い物を選ぶ
Answer greedy1() {
    Answer answer = Answer();
    REP(day,D) {
        int mx = 0;
        REP(typ,26) if(chmax(mx,s[day][typ])) answer.ans[day] = typ;
    }
    return answer;
}

// 下がりやすさを考慮して一番高い物を選ぶ
Answer greedy2() {
    Answer answer = Answer();
    // あるコンテストi-1が開催されていない日数
    vector<int> not_open_term(26,0);

    REP(day,D) {
        // 期待値の最大値
        int mx = 0;
        REP(typ,26) {
            // そのコンテストを開催した際の満足度変動値を計算する。
            int manzoku = s[day][typ];
            REP(_typ,26) if(_typ != typ )manzoku-=(not_open_term[_typ] * c[_typ]);
            if(chmax(mx,manzoku)) answer.ans[day] = typ;
        }
        REP(i,26) not_open_term[i]++;
        // 開催するコンテストが決定されたらそれの日数を0にする。
        not_open_term[answer.ans[day]] = 0;
    }
    return answer;

}

void solveB() {
    Answer answer = Answer();
    REP(i,D) {
        cin >> answer.ans[i];
        answer.ans[i]--;
    }
    cerr << calc(answer) << endl;
}

void solveC() {
    Answer answer = Answer();
    REP(i,D) {
        cin >> answer.ans[i];
        answer.ans[i]--;
    }
    int M;
    cin >> M;
    REP(i,M) {
        int d,q;
        cin >> d >> q;
        d--; q--;
        answer.ans[d] = q;
        cout << calc(answer) << endl;
    }

}

void solve() {
    // auto ans = Answer();
    // ans.print_ans();
    auto ans = greedy2();
    ans.print_ans();
}

int main() {
    read();
    solveC();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

ll a[e];

int main()
{
   ll a, b, t;
   cin >> a >> b >> t;
   cout << t/a * b;
}


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

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

平均値求めて、差が最小になるの選んでいくだけ
誤差が怖いので全てをN倍しておくことで、誤差が消滅するよ
*/

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

using namespace std;

bool solve(string s) {
    // 条件1
    if (s[0] != 'A') return false;

    // 条件2
    auto cnt_C = 0;
    for (int i = 2; i < s.length() - 1; ++i) {
        if (s[i] == 'C') cnt_C++;
    }
    if (cnt_C != 1) return false;

    // 条件3
    int cnt_lower = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] >= 'a' and s[i] <= 'z') cnt_lower++;
    }
    return cnt_lower == s.size() - 2;
}

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

    if (solve(s)) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }
    return 0;
}


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

int main() {
  int N,S=0;
  cin >> N;
  vector<int> vecA(N);
  vector<int> vecB(N-1);
  for(int i = 0; i < N-1; i++){
    cin >> vecB[i];
  }
  vecA[0] = vecB[0];
  vecA[N-1] = vecB[N-2];
  S += vecA[0] + vecA[N-1];
  for(int i = 0; i < N-2; i++){
    vecA[i+1]= min(vecB[i],vecB[i+1]);
    S += vecA[i+1];
  }
  cout << S <<endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ;

    vi v ( n ) ;
    for ( int i=0 ; i < n ; i++ ) cin >> v[i] ;

    vb dec ( n ) ;
    v[0] -- ;
    dec[0] = true ;

    int minn = v[0] ;
    for ( int i=1 ; i < n ; i++ )
    {
        if ( v[i] > v[i-1] )
        {
            v[i] -- ;
            dec[i] = true ;
        }

        else if ( v[i] < v[i-1] ) { cout << "No" ; line ; R ; }
        else if ( v[i] < minn ) { cout << "No" ; line ; R ; }

        minn = min ( minn , v[i] ) ;
    }

    cout << "Yes" ; line
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

int main(){

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

}

Measured memory_bytes: 256
let rec routable (pTxy: int [], txy: int []) =
    let [|pt; px; py|] = pTxy
    let [|t; x; y|] = txy
    ((px + py) % 2 = pt % 2) && ((x + y) % 2 = t % 2) && (abs (x - px) + abs (y - py)) <= t - pt

let n = stdin.ReadLine() |> int
let txys = Seq.append [[|0; 0; 0|]] [for i in 1..n do yield stdin.ReadLine().Split(' ') |> Array.map int]
txys
|> Seq.pairwise
|> Seq.forall routable
|> fun r -> if r then "Yes" else "No"
|> printfn "%s"


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

int main() {
  int A;
  int B;
  
  cin >> A >> B;
  
  int i=0;
  while(true) {
    if(i*(A-1)+1 >= B) {
      break;
    } else {
      i++;
    }
  }
  
  cout << i;
  
  return 0;
}


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

int main(){
  int n, d; cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> x.at(i).at(j);
    }
  }
  int out = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+ 1; j < n; j++){
      long long tmp = 0;
      for(int k = 0; k < d; k++){
        tmp += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
      }
      for(int k = 0; k < 10000; k++){
        if(tmp == k * k){
          out++;
          break;
        }
      }
    }
  }
  cout << out;
}

Measured memory_bytes: 256
A,B = map(int, input().split())

def gf(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    return n ^ 1

print( gf(B) ^ gf(A-1))

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main()
{
    int N,i;
    scanf("%d",&N);
    char S[N+1],T[N+1],A[205];
    scanf("%s %s",S,T);
    int j=0;
    for(i=0; i<N; i++)
    {
        A[j]=S[i];
        j++;
        A[j]=T[i];
        j++;
    }
    A[j]='\0';
    printf("%s\n",A);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
ll const mod = 1e9+7;
ll cnt[100][2];
ll pw[100];
ll n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    

    
    cin >> n;
    pw[0] = 1;
    for(ll i = 1; i <= 75; ++i)
        pw[i] = pw[i-1]*2%mod;
    ll ans = 0;
    while(n--){
        ll x;
        cin >> x;
        for(ll i = 0; i < 70; ++i){
            ll bit = x%2;
            ans += cnt[i][bit^1]*pw[i]%mod;
            ans %= mod;
            cnt[i][bit]++;

            x /= 2;
        }
    }
    cout << ans << "\n";
}


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

void trace(int A[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}


int main()
{
    int maxN = 1000;
    int A[maxN];

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

    //selection sort
    int swp = 0;
    for (int i = 0; i < N; i++)
    {
        int mini = i;
        for (int j = i; j < N; j++)
        {
            if (A[j] < A[mini])
            {
                mini = j;
            }
        }
        
        if (mini != i)
        {
            int tmp = A[i];
            A[i] = A[mini];
            A[mini] = tmp;
            swp++;
        }
    }
    
    trace(A,N);
    cout << swp << endl;
  
    return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
long long modpow(long long a, long long n, long long mod) { //累乗の余剰
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vector< ll > divisor(ll n) {  //約数の列挙
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main(){
    int n,k;
    std::cin >> n>>k;
    std::vector<ll> a(k+1);
    rrep(i,1,k+1){
        ll d=k/i;
        a[i]=modpow(d,n,MOD);
    }
    std::vector<ll> aa(a);
    irep(i,k+1){
        if(i==0)break;
        std::vector<ll> di=divisor(i);
        di.pop_back();
        erep(j,di){
            a[j]-=a[i];
            if(a[j]<0)a[j]+=MOD;
        }
    }
    ll ans=0;
    rep(i,k+1){
    //    std::cout << a[i] << std::endl;
        ans+=a[i]*i;
    }
    std::cout << ans%MOD << std::endl;
}

Measured memory_bytes: 4796
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i:=0; i<n;i++ {
		fmt.Scan(&A[i])
	}
	var sum float64
	for i:=0; i<n;i++ {
		sum += 1 / float64(A[i])
	}
	ans := 1 / sum
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main(){
  int n; cin >> n;
  map<ll,int> mp;
  for(int i = 0; i < n; i++){
    ll now; cin >> now;
    if(mp[now] == 1) mp[now]--;
    else mp[now]++;
  }
  int ans = 0;
  for(P p: mp){
    if(p.second == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9720
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
cnt = 0
if len(A) != len([a for a in A if a % 2 == 0]):
  print(0)
  exit()

while True:
  cnt += 1
  A = [a / 2 for a in A]
  if len(A) != len([a for a in A if a % 2 == 0]):
    break
print(cnt)

Measured memory_bytes: 12272
n = int(input())
lis = list(map(int,input().split()))
lis[0]-=1
for i in range(n-1):
  if lis[i] < lis[i+1]:
    lis[i+1] -= 1
  elif lis[i] > lis[i+1]:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
 
int main() {
  string s;
  cin >> s;
  int res = 0;
  if (s[0] == '1') {
    ++res;
  }
  if (s[1] == '1') {
    ++res;
  }
  if (s[2] == '1') {
    ++res;
  }
  cout << res << endl;
}

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

int main()
{
    int n, ans;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    for (int i = 0; i < n - 1; i++)
        cin >> c[i];

    ans = b[a[0] - 1];
    for (int i = 1; i < n; i++)
    {
        if (a[i] - a[i - 1] == 1)
        {
            ans += b[a[i] - 1] + c[a[i] - 2];
        }
        else
        {
            ans += b[a[i] - 1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        static void Main()
        {
            int n = NextInt;
            var list = LongList;
            var order = Enumerable.Range(0, n).OrderByDescending(i => list[i]).ToArray();
            var dp = Enumerable.Range(0, n + 1).Select(_ => Enumerable.Repeat(long.MinValue >> 2, n + 1).ToArray()).ToArray();
            dp[0][0] = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    dp[j + 1][i - j] = Math.Max(dp[j][i - j] + list[order[i]] * Math.Abs(j - order[i]), dp[j + 1][i - j]);
                    dp[j][i - j + 1] = Math.Max(dp[j][i - j] + list[order[i]] * Math.Abs(n - i + j - 1 - order[i]), dp[j][i - j + 1]);
                }
            }

            System.Console.WriteLine(Enumerable.Range(0, n).Max(i => dp[i][n - i]));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 61232
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-b)<=d && abs(b-c)<=d) cout<<"Yes"<<endl;
  else if(abs(a-c)<=d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




Measured memory_bytes: 256
def main():
    a, b, k = map(int, input().split())

    for i in range(k):
        if i % 2 == 0:
            if a % 2 == 1:
                a -= 1
            b += a // 2
            a //= 2
        else:
            if b % 2 == 1:
                b -= 1
            a += b // 2
            b //= 2

    print(a, b)


if __name__ == "__main__":
    main()


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

int main (int argc, char **argv) {
  long a, b;
  cin >> a >> b;

  long d, r;
  double f;

  d = a / b;
  r = a % b;
  f = (double)a / (double)b;

  cout << d << " " << r << " " << fixed << setprecision(5)<< f << endl;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

ll f[300300], finv[300300];

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a) {
  return modpow(a, mod - 2);
}

ll nCr(ll n, ll r) {
  if (r < 0 || r > n) return 0;
  return f[n] * finv[n - r] % mod * finv[r] % mod;
}

void init() {
  f[0] = 1, finv[0] = 1;
  FOR(i, 1, 300300) {
    f[i] = i * f[i - 1] % mod;
    finv[i] = modinv(f[i]);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  init();
  ll ans = 0;
  rep(i, n + 1) {
    if (a * i > k) break;
    if ((k - a * i) % b != 0) continue;
    ll j = (k - a * i) / b;
    ans = (ans + nCr(n, i) * nCr(n, j) % mod) % mod;
  }
  cout << ans << '\n';
  

  
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define int long long
#define vi vector<int>
#define vii vector<pair<int,int>>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
int mod=1e9+7;
int max(int a,int b){if(a>b) return a; else return b;}
int max3(int a, int b, int c){ if(a>b){if(a>c) return a; else return c;}else{if(b>c)return b;else return c;}}
int power(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
signed main()
{
	IOS;
    int t;
    //cin>>t;
	t=1;
    while(t--)
    {
		int n;
		cin>>n;
		int ans=0;
		for(int i=1;i<=n;i++)
		{
 			if(i%3!=0 && i%5!=0)
			 ans+=i;
 		}
		 cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

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

const int B = 200;
int color[100010],  par[100010], depth[100010];
int depthTop[100010];
int goUp[100010];
bool vis[100010];
int n;
vector<vector<int>> g;

void decomp(int root){
    rep(i,n) vis[i] = false, par[i] = -1;
    queue<int> q;
    q.push(root);
    vector<int> tord;
    while(q.size()){
        int v = q.front(); q.pop();
        vis[v] = true;
        tord.push_back(v);
        for(int c : g[v]){
            if(!vis[c]){
                q.push(c);
                par[c] = v;
                depth[c] = depth[v] + 1;
            }
        }
    }
    rep(i,n) vis[i] = false;
    int c = 0;
    for(int u : tord){
        if(vis[u]) continue;
        q.push(u);
        int k = 0;
        while(q.size() && k < B){
            int v = q.front(); q.pop();
            vis[v] = true;
            color[v] = c;
            goUp[v] = par[u];
            depthTop[v] = depth[u];
            k++;
            for(int c : g[v]){
                if(!vis[c]) q.push(c);
            }
        }
        while(q.size()) q.pop();
        c++;
    }
}

int solve(int u, int v){
    while(color[u] != color[v]){
        if(depthTop[u] > depthTop[v]) u = goUp[u];
        else v = goUp[v];
    }
    while(u != v){
        if(depth[u] > depth[v]) u = par[u];
        else v = par[v];
    }
    return u;
}

int main(){
    cin >> n;
    g.assign(n,{});
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g[i].push_back(c);
            par[c] = i;
        }
    }
    decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << solve(u,v) << endl;
    }
}

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


int main(){
ll A,B,C,D,c=0,d=0,e=0,f=0,r=0;
  cin >> A >> B >> C >>D;
  ll a=C,b=D;
  if(A%C==0)
  c=B/C-A/C+1;
  else
    c=B/C-A/C;
  
  if(A%D==0)
  d=B/D-A/D+1;
  else
    d=B/D-A/D;
  
   r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
f=C*D/b;
  
  if(A%f==0)
  e=B/f-A/f+1;
  else
    e=B/f-A/f;

  c=c+d-e;
  
  A=B-A+1-c;
  
  cout << A << endl;
  
  
  
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 998244353;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

const int MAXN = 2000 + 5;
ll h, w;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//	freopen("a.in","r",stdin);
	//	freopen("a.out","w",stdout);
	cin >> h >> w;
	if (h > w) swap(h, w);
	ll ans = (h*w) / 2;
	if ((h & 1) && (w & 1)) ans++;
	if (h == 1) ans = 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int inf=1e9;
const ll INF=1e18;
const double pi=3.1415926535897932384626433832;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,dp[100005]={};
  cin >> n;
  for(int i=1; i<=n; i++) {
    dp[i]=dp[i-1]+1;
    for(int j=6; j<=i; j*=6) {
      dp[i]=min(dp[i],dp[i-j]+1);
    }
    for(int j=9; j<=i; j*=9) {
      dp[i]=min(dp[i],dp[i-j]+1);
    }
  }
  cout << dp[n] << endl;
}

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

int main()
{
  ll l,r;
  cin >> l >> r;
  
  if(r - l >= 2019)
  {
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = 2020;
  for(ll i = l; i < r; i++)
  {
    for(ll j = i+1; j <= r; j++)
    {
      if(j % 2019 == 0)
      {
        cout << 0 << endl;
        return 0;
      }
      ans = min(ans,(i*j)%2019); 
    }
  }
  
  cout << ans << endl;
  
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M,A,B,P,Q;

void dfs(int k,int n,int s,vint &v,vint &latte){
    if(k==n){
        latte.pb(s);
        return;
    }
    dfs(k+1,n,s,v,latte);
    dfs(k+1,n,s+v[k],v,latte);
}

signed main(){
    cin>>N>>M>>A>>B>>P>>Q;

    if(A==1&&B==1){
        P+=Q;
        int ans=M;
        if(M/P>N)chmin(ans,abs(M-P*N));
        else{
            chmin(ans,abs(M-M/P*P));
            if(M/P+1<=N)chmin(ans,abs(M-M/P*P-P));
        }
        cout<<ans<<endl;
        return 0;
    }
    vector<int>v;
    int x=P,y=Q;
    for(int i=0;i<N;i++){
        v.pb(x+y);
        if(1.0*x*A>1e15||1.0*y*B>1e15||x+y>M)break;
        x*=A;y*=B;
    }

    int n=v.size()/2;
    vint latte,malta;
    dfs(0,n,0,v,latte);
    dfs(n,v.size(),0,v,malta);
    sort(all(latte));
    sort(all(malta));


    int ans=M;

    int cur=latte.size()-1;
    for(int i=0;i<malta.size();i++){
        while(cur&&latte[cur]+malta[i]>M)cur--;
        chmin(ans,abs(M-latte[cur]-malta[i]));
    }

    cur=0;
    for(int i=(int)malta.size()-1;i>=0;i--){
        while(cur+1!=latte.size()&&latte[cur]+malta[i]<M)cur++;
        chmin(ans,abs(M-latte[cur]-malta[i]));
    }

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

Measured memory_bytes: 27556
#include<bits/stdc++.h>
using namespace std;
int L;
struct Front_star{
	int u,v,w;
}e[90];
int ecnt=0;
void add(int u,int v,int w){
	ecnt++;
	e[ecnt].u=u;
	e[ecnt].v=v;
	e[ecnt].w=w;
}
int main(){
	cin>>L;
	int cnt=0;
	int tmp=L;
	while(tmp)cnt++,tmp/=2;
	for(int i=1;i<cnt;i++){
		add(i,i+1,0);
		add(i,i+1,(1<<(i-1)));
	}
	cnt--;
	int ret=L-(1<<cnt);
	int Use=(1<<cnt);
	for(int i=0;i<20;i++){
		if((1<<i)&ret){
			add(i+1,cnt+1,Use);
			Use+=(1<<i);
		}
	}
	cout<<cnt+1<<" "<<ecnt<<'\n';
	for(int i=1;i<=ecnt;++i){
		cout<<e[i].u<<" "<<e[i].v<<" "<<e[i].w<<'\n';
	}
} 

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,k;
    cin>>n>>m>>k;
    char arr[n][m];
    int b=0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            cin>>arr[i][j];
            if(arr[i][j]=='#')
                b++;
        }
    }   
    int ans = 0;
    for(int i=0;i<(1<<n);i++) {
        for(int j=0;j<(1<<m);j++) {
            int br = 0;
            for(int a=0;a<n;a++) {
                if(i&(1<<a)) {
                    for(int i=0;i<m;i++) {
                        if(arr[a][i]=='#') {
                            br++;
                        }
                    }
                }
            }
            int am = i;
            for(int a=0;a<m;a++) {
                if(j&(1<<a)) {
                    for(int i=0;i<n;i++) {
                        if(am&(1<<i))
                            continue;
                        if(arr[i][a]=='#') {
                            br++;
                        }
                    }
                }
            }
            if(b-br==k) {
                ans++;
            }
        }
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3648
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ") //ブランクで区切られている場合

let x = split[0]
//String -> Intの型変換はnilが返る可能性があるので、ラップされたOptional<Int>型が返るので強制アンラップ
let y = split[1]

let z = split[2]


print("A"+y.prefix(1)+"C")

Measured memory_bytes: 14088