akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
//#define mod 998244353
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int dp1[310][90909] = { 0 };
int dp2[310][90909] = { 0 };

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

	int N, sum = 0;
	int mod = 998244353;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}

	dp1[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp1[i + 1][j + A[i]] += dp1[i][j];
				dp1[i + 1][j + A[i]] %= mod;
			}
			dp1[i + 1][j] += 2 * dp1[i][j];
			dp1[i + 1][j] %= mod;
		}
	}

	int x = 0;
	REP(j, 90909) {
		if (j * 2 >= sum) {
			x += dp1[N][j];
			x %= mod;
		}
	}

	dp2[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp2[i + 1][j + A[i]] += dp2[i][j];
				dp2[i + 1][j + A[i]] %= mod;
			}
			dp2[i + 1][j] += dp2[i][j];
			dp2[i + 1][j] %=mod;
		}
	}

	int y = (sum % 2 == 0) ? dp2[N][sum / 2] : 0;

	int ans = 1;
	REP(i, N) {
		ans *= 3;
		ans %= mod;
	}
	//cout << x << endl;
	//cout << y << endl;
	//cout << ans << endl;
	//cout << (ans-3*x+3*y)%mod << endl;
	ans = (ans - 3 * x + 8 * mod) % mod;
	ans += 3 * y;

	cout << ans % mod << endl;

	return 0;
}



Measured memory_bytes: 429696
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(a+5*b+10*c+50*d+100*e+500*f>=1000)cout<<"1"<<endl;
	else cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 1156
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

zerokara = S[0::2]
onekara = S[1::2]

ans1 = zerokara.count("1")+onekara.count("0")
ans2 = zerokara.count("0")+onekara.count("1")
ans = min(ans1,ans2)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 3188
import math
import fractions
import collections
import itertools
S=list(input())
T=list(input())
ans=float("inf")
num=0
for i in range(0,len(S)-len(T)+1):
    num=0
    for j in range(len(T)):
        if S[i+j]!=T[j]:
            num=num+1
    ans=min(ans,num)
    #print(num)
print(ans)


Measured memory_bytes: 77552
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

int A[55], B[55], used[55];
vector<int> G[55];
unordered_set<int> S;

void dfs(int s){
    used[s] = 1;
    for(auto u : G[s]) if(!used[u]) dfs(u);
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N;
    cin>>N;
    for(int i=0;i<N;i++) cin>>A[i];
    for(int i=0;i<N;i++) cin>>B[i];
    for(int i=1;i<=51;i++) S.emplace(i);
    for(int i=51;0<i;i--){
        S.erase(i);
        for(int j=1;j<=50;j++){
            G[j].clear();
            for(auto k : S) if(k<=j) G[j].push_back(j%k);
        }
        bool ok = true;
        for(int j=0;j<N;j++){
            for(int k=0;k<=50;k++) used[k] = 0;
            dfs(A[j]);
            ok &= used[B[j]];
        }
        if(!ok)
            S.emplace(i);
    }
    if(S.count(51)) {cout<<-1<<endl; return 0;}
    lint ans = 0;
    for(auto u : S)
        ans += (1LL<<u);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct Node{
  int key;
  struct Node *next,*prev;
};
 
struct Node *nil;
struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}
 
void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}
 
void printList(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}
 
void deleteNode(struct Node *t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}
 
void deleteFirst(){
  deleteNode(nil->next);
}
 
void deleteLast(){
  deleteNode(nil->prev);
}
 
void deleteKey(int key){
  deleteNode(listSearch(key));
}
 
void insert(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}
 
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",com);
    if(com[0]=='i'){scanf("%d",&key);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{
        scanf("%d",&key);
        deleteKey(key); nd++;
      }
      size--;
    }
  }
  printList();
 
  return 0;
}

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

void solve()
{
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n)
    {
        if (i == n - 1)
            ans += t;
        else
            ans += min(a[i + 1] - a[i], t);
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

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

signed main() {
    int n, m, h[100000], a, b, ans;
    vector<int> conect[100000];
    bool best;

    cin >> n >> m;
    for ( int i = 0; i < n; i++ ) {
        cin >> h[i];
    }
    for ( int i = 0; i < m; i++ ) {
        cin >> a >> b;
        a--;
        b--;

        conect[a].push_back(b);
        conect[b].push_back(a);
    }

    ans = 0;
    for ( int i = 0; i < n; i++ ) {
        best = true;

        for ( int j = 0; j < conect[i].size(); j++ ) {
            if ( h[i] <= h[conect[i][j]] ) {
                best = false;
            }
        }

        ans += best;
    }

    cout << ans << endl;

    return (0);
}

Measured memory_bytes: 9092
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;


int main(void){
  int N;
  cin >> N;
  vector<long long> v(N);
  cin >> v[0];
  for(int i=1;i<N;i++){
    cin >> v[i];
  }
  long long maxv = -10000000007;
  long long minv = 10000000007;
  for(int i=0;i<N;i++){
    maxv = max(maxv, v[i] - minv);
    minv = min(minv, v[i]);
  }
  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 2588
#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;
  int max = 0;
  map<string, int> mp;
  rep(i, n) {
    string a; cin >> a;
    if (mp.count(a)) mp[a]++;
    else mp[a] = 1;
    if (mp[a] > max) max = mp[a];
  }
  for (auto p : mp) {
    auto k = p.first;
    auto v = p.second;
    if (v == max)
      cout << k << endl;
  }
  return 0;
}

Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

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

const ll mod = 1e9 + 7;

int main(){
    int n,q;
    cin >> n;
    vector<int> a(n),m(q);
    for (int i = 0;i < n;i++)cin >> a[i];
    cin >> q;
    for (int i = 0;i < q;i++) cin >> m[i];
    vector<ll> sum(1<<n);
        
        for (int bit = 0;bit < (1 << n);bit++){
            for (int j = 0;j < n;j++){
                if (bit & (1 << j)){
                    sum[bit] += a[j];
                }
            }
        }
        bool ans = false;
    
    for (int i = 0;i < q;i++){
        ans = false;
        for (int bit = 0;bit < (1 << n);bit++){
            if (sum[bit] == m[i]){
                cout << "yes" << endl;
                ans = true;
                break;
            }
        }
        if (!ans) cout << "no" << endl;
    }
}


Measured memory_bytes: 27372
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

ll eval(ll x, vector<ll> &A) {
	ll ret=0;
	for (auto a : A)
		ret+=(a+x-1)/x-1;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,K; cin>>N>>K;
	vector<ll> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	ll low=1, high=1e9+7;
	while(low<high) {
		int mid=(low+high)/2;
		if(eval(mid,A)<=K) high=mid;
		else low=mid+1;
	}
	cout<<min(*max_element(A.begin(),A.end()),high)<<"\n";
	return 0;
}

Measured memory_bytes: 4752
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); ++i)

using namespace std;

int main(){
  long double A, B, K, l;
  long double pi, H, M, x1, x2, y1, y2, ans, ans2;

  pi = 3.1415926535897932384626433832795028841971693993751058209749;

  cin >> A >> B >> H >> M;

  x1 = A * sin(H*pi/6 + M*pi/360);
  y1 = A * cos(H*pi/6 + M*pi/360);

  x2 = B * sin(M*pi/30);
  y2 = B * cos(M*pi/30);

  ans2 = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
  ans = sqrt(ans2);

  cout << setprecision(20)<< ans << endl;

  return 0;
}


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

typedef struct vector{
    int *a;
    int length, size;
}vector;

vector *init(){
    vector *v = (vector *)malloc(sizeof(vector));
    v->length = v->size = 0;
    v->a = (int *)malloc(sizeof(int));
    return v;
}

int get(vector *v, int i){
    return v->a[i];
}

void set(vector *v, int i, int x){
    v->a[i] = x;
}

void resize(vector *v){
    int *b = (int *)malloc(sizeof(int) * (v->size == 0 ? 1 : v->size * 2));
    for(int i=0; i<v->size; ++i) b[i] = v->a[i];
    free(v->a);
    v->a = b;
    v->length = (v->size == 0 ? 1 : v->size * 2);
}

void insert(vector *v, int i, int x){
    if(v->size == v->length) resize(v);
    for(int k=v->size-1; k>=i; --k) v->a[k+1] = v->a[k];
    v->a[i] = x;
    ++v->size;
}

void erase(vector *v, int i){
    for(int k=i; k<v->size; ++k) v->a[k] = v->a[k+1];
    --v->size;
    if(v->length >= 3 * v->size) resize(v);
}

void push_back(vector *v, int x){
    insert(v, v->size, x);
}

void pop_back(vector *v){
    erase(v, v->size);
}

typedef vector stack;

void push(stack *st, int x){
    push_back(st, x);
}

int top(stack *st){
    return get(st, st->size-1);
}

void pop(stack *st){
    if(st->size == 0) return;
    pop_back(st);
}

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    stack* st[n];
    for(int i=0; i<n; ++i) st[i] = init();
    while(q--){
        int c, t, x;
        scanf("%d%d", &c, &t);
        if(c == 0){
            scanf("%d", &x);
            push(st[t], x);
        }
        else if(c == 1){
            if(st[t]->size > 0) printf("%d\n", top(st[t]));
        }
        else pop(st[t]);
    }
}


Measured memory_bytes: 2824
/* # */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
void sol() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    sol();


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  ll a=0;
  ll b=0;
  ll c=0;
  FOR(i,0,n){
    ll A;
    	ci(A);
    if(A%4==0) a++;
    else if(A%2==0) b++;
    else c++;
  }
  
  if(b==0&&c<=a+1) co("Yes")
  else if(c<=a) co("Yes")
  else co("No")
    }
    
    

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

typedef long long ll;

using namespace std;

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

	ll tmp_x = x;
	int res = 0;
	while (tmp_x <= y) {
		res++;
		tmp_x *= 2;
	}

	cout << res << endl;

	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  sort(va.begin(), va.end());
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    ans += va[i + 1] - va[i];
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    if(N<10){
    if(N==2||N==4||N==5||N==7||N==9){
        cout<<"hon";
       }
    if(N==0||N==1||N==6||N==8){
        cout<<"pon";
       }
    if(N==3){
        cout<<"bon";
       }
    }
    if(N>=10){
        if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9){
            cout<<"hon";
        }
        if(N%10==0||N%10==1||N%10==6||N%10==8){
            cout<<"pon";
        }
        if(N%10==3){
            cout<<"bon";
        }
    }
    

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";
   
void solve(long long a, long long b, long long c){
	if(4*a*b < (c-a-b)*(c-a-b) && (c-a-b) > 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
}


Measured memory_bytes: 256
def solve():
    N, H = map(int, input().split())
    A = []
    B = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    A = sorted(A, reverse=True)
    a = max(A)
    B = [b for b in B if b > a]
    B = sorted(B, reverse=True)
    ans = 0
    damage = 0
    for b in B:
        H -= b
        ans += 1
        if H <= 0:
            return ans
    ans += (H // a)
    if H % a > 0:
        ans += 1
    return ans

print(solve())


Measured memory_bytes: 65880
n,k = map(int,input().split())

if n % k == 0:
  print(0)
elif n / k != 0:
  min = n % k
  if min > abs(min - k):
    min = abs(min - k)
  print(min)
elif n > abs(n - k):
  print(abs(n - k))
else:
  print(n)

Measured memory_bytes: 9180
//AtCoder ABC117 B - Polygon
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N; cin>>N;
    vector<ll> ln(N);
    for(auto&& l:ln){
        cin>>l;
    }
    sort(ln.begin(),ln.end());
    ll sum=0;
    for(ll i=0;i<ln.size()-1;++i){
        sum+=ln[i];
    }
    cout<<(ln[N-1]<sum?"Yes":"No")<<endl; 
    return 0;
}

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

typedef long long ll;
using namespace std;

ll paths = 0;

void dfs(vector<vector<int>> &graph, vector<bool> &visited, int current) {
  bool ok = true;
  for (ll i = 0; i < visited.size(); i++) {
    if (visited[i] == false && i != current) {
      ok = false;
      break;
    }
  }

  if (ok) {
    paths++;
    return;
  }

  visited[current] = true;
  for (ll i = 0; i < graph[0].size(); i++) {
    if (graph[current][i] == 1 && visited[i] == false) {
      dfs(graph, visited, i);
    }
  }
  visited[current] = false;
}

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

  vector<vector<int>> graph(N, vector<int>(N, 0));
  for (ll i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    graph[a - 1][b - 1] = 1;
    graph[b - 1][a - 1] = 1;
  }

  vector<bool> visited(N, false);

  dfs(graph, visited, 0);

  cout << paths << endl;
}

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;
using P =pair<int,int>;

int main(){
    int h,w,a,b;
    cin >> h >> w >> b >> a;
    vector <vector <int>> s(h,vector <int>(w,0));

    rep(i,h-a){
        rep(j,b){
            s[i][j]=1;
        }
    }

    rep(i,a){
        rep(j,w-b){
            s[h-a+i][b+j]=1;
        }
    }

    rep(i,h){
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
    }
    

    return 0;
}

Measured memory_bytes: 7560
#include <bits/stdc++.h>
#define ll long long int
#define f(i,a,n) for(i=a;i<n;i++)
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define test() ll tc;cin>>tc;while(tc--)

using namespace std;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;


int main()
{
        fast();
        ll n,i,w,j,V=0;
        cin>>n>>w;
        ll prices[n];
        ll weight[n];

        f(i,0,n)
        {
            cin>>weight[i]>>prices[i];
            V+=prices[i];
        }
        ll dp[V+1];
        dp[0]=0;
        f(i,1,V+1)
        {
            dp[i]=INF;
        }
        for(i=0;i<n;i++)
        {
            ll w=weight[i],v=prices[i];
            for(j=V;j>=v;j--)
            {
                    dp[j]=min(dp[j],dp[j-v]+w);
            }
        }

        for(ll i=V;i>=0;i--)
        {
            if(dp[i]<=w)
            {
                cout<<i<<endl;
                break;
            }
        }
        return 0;
}


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

lli n;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(void){
    cin >> n;
    vector<lli> a(n);
    lli g = 0;
    rep(i, n){
        cin >> a[i];
        g = __gcd(g, a[i]);
    }
    if(g != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    map<lli, bool> used;
    rep(i, n){
        auto f = prime_factor(a[i]);
        for(auto j : f){
            if(used[j.first]){
                cout << "setwise coprime" << endl;
                return 0;
            }
            used[j.first] = true;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}


Measured memory_bytes: 11088
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)













int main(){
    ll n;
    string s;
    cin >> n >> s;
    REP(i, s.size()){
        s[i] = s[i] + n;
        if(s[i] > 'Z'){
            s[i] -= 26;
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    //int ch_d = 1;
    //int cnt = 0;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        // cnt++;
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 1000;
        int old_c = res[ch_d - 1];
        int old_d = ch_d;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        res[ch_d - 1] = ch_c;
        ch_d = rand() % D + 1;
        ch_c = rand() % 26 + 1;
        new_score = ch_sch(res, ch_d, ch_c, new_score);
        if(cur_score < new_score){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            // ch_d--;
            // if(ch_d == 0) ch_d = D;
        }else{
            res[old_d - 1] = old_c;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    ls = len(s)
    t = input().rstrip()
    lt = len(t)
    alphabet = 'abcdefghijklmnopqrstuvwxyz' #26
    dic = {}
    for i in range(26):
        dic[alphabet[i]] = i
    moji = [[] for _ in range(26)]
    for i in range(ls):
        moji[dic[s[i]]].append(i+1)
    
    cnt = 0
    res = 0
    while cnt < lt:
        for i in range(cnt, lt):
            if not moji[dic[t[i]]]:
                print(-1)
                exit()
            if i == cnt:
                now = moji[dic[t[i]]][0] + 1
            else:
                nex = bisect_left(moji[dic[t[i]]], now)
                if nex == len(moji[dic[t[i]]]):
                    res += ls
                    cnt = i
                    break
                now = moji[dic[t[i]]][nex] + 1
        else:
            res += now - 1
            break
    print(res)

if __name__ == '__main__':
    main()

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

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    const long long MOD = 1e9 + 7;

    int n;
    cin >> n;
    vector<int> a(n);

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

    long long ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + sum * a[i]) % MOD;
        sum = (sum + a[i]) % MOD;
    }
    cout << ans << '\n';
}

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

int main()
{
    char ans[4];
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            if(i == j) ans[i] = fgetc(stdin);
            else fgetc(stdin);
        }
        fgetc(stdin);
    }
    ans[3] = '\0';
    cout << ans << endl;
    return 0;
}

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;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e5+5;

vector <char> adj[L];
vector <ll> dp[L];

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

    ll N, K;
    cin >> N >> K;

    ll R, S, P;
    cin >> R >> S >> P;

    string T;
    cin >> T;

    for(ll i=0; i<K; i++)
    {
        ll j = i;

        while(j < N)
        {
            adj[i].pb(T[j]);
            j += K;
        }
    }

    ll res = 0;

    for(ll i=0; i<K; i++)
    {
        if(adj[i][0] == 'r')
        {
            dp[i].pb(P);
        }

        else if(adj[i][0] == 's')
        {
            dp[i].pb(R);
        }

        else
        {
            dp[i].pb(S);
        }

        ll len = sz(adj[i]);

        for(ll j=1; j<len; j++)
        {
            ll temp = 0;

            if(adj[i][j] == 'r')
            {
                temp = P;
            }

            else if(adj[i][j] == 's')
            {
                temp = R;
            }

            else
            {
                temp = S;
            }

            if(T[i + K*j] != T[i + K*(j-1)])
            {
                dp[i].pb(dp[i][j-1] + temp);
                continue;
            }

            ll ans = 0;

            if(j > 1)
            {
                ans = max(dp[i][j-1], dp[i][j-2] + temp);
            }

            else
            {
                ans = max(dp[i][j-1], temp);
            }

            dp[i].pb(ans);
        }

        res += dp[i][len-1];

        // cout << res << endl;
    }

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

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int dx[4] = {0, 0, 1, -1};
	int dy[4] = {1, -1, 0, 0};
	int res = 0;
    int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep (i, h) cin >> s[i];
	rep (i, h) {
	  rep (j, w) {
		if (s[i][j] == '#') continue;
		vector<vector<int> > d(h, vector<int>(w, Inf));
		queue<pair<int, int> > q;
		q.push({i, j});
		d[i][j] = 0;
		while (!q.empty()) {
		  int x, y;
		  x = q.front().first, y = q.front().second;
		  q.pop();
		  res = max(res, d[x][y]);
		  rep (k, 4) {
			int nx, ny;
			nx = x + dx[k], ny = y + dy[k];
			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (s[nx][ny] == '#') continue;
			if (d[nx][ny] != Inf) continue;
			d[nx][ny] = d[x][y] + 1;
			q.push({nx, ny});
		  }
		}
	  }
	}
	cout << res << endl;
	
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;

int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	for(ll i=0; i<n; i++){
		if(i<n-1) sum += abs(a[i]-a[i+1]);
	}
	sum += abs(a[0])+abs(a[n-1]);
	
	cout<<(sum+abs(a[1])) -(abs(a[0]) + abs(a[0]-a[1]))<<endl;
	
	for(ll i=1; i<=n-2; i++){
		cout<<(sum+abs(a[i-1]-a[i+1])) -(abs(a[i-1]-a[i]) +abs(a[i]-a[i+1]))<<endl;
	}
	cout<<(sum +abs(a[n-2]))-(abs(a[n-2]-a[n-1])+abs(a[n-1]));
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
using namespace std;
ll H,n,ans,sum,dp[N],p,x,y,fix[N];
pair <ll,ll> a[N],P;
vector <ll> mas;
vector <pair<ll,ll> > v;
int main(){

	ios::sync_with_stdio(0);
	
	cin>>H>>n;
	p=1;
	for(int i=0;i<=log2(H)+3;i++){
		mas.pb(p);
		p*=2;
	}
	
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		for(int j=0;j<mas.size();j++){
			v.pb({x*mas[j],y*mas[j]});
		}
	}
	
	fix[0]=1;
	
	for(int i=0;i<=H;i++){
		if(fix[i]!=1)continue;
		for(int j=0;j<v.size();j++){
			if(i+v[j].f>100000)continue;
			if(fix[i+v[j].f]==0){
				fix[i+v[j].f]=1;
				dp[i+v[j].f]=dp[i]+v[j].s;
			} else {
				if(dp[i+v[j].f]>dp[i]+v[j].s){
					dp[i+v[j].f]=dp[i]+v[j].s;
				}
			}
		}
	}
	
	ans=inf;
	for(int i=H;i<=100000;i++){
		if(fix[i]==1){
			if(dp[i]<ans)ans=dp[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 9084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <queue>
using namespace std;

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

	set<int> stamp;
	for(int i=0; i<n; ++i){
		int h, w;
		cin >> h >> w;
		for(int j=-3; j<4; ++j){
			for(int k=-3; k<4; ++k){
				bitset<16> bs;
				for(int y=j; y<j+h; ++y){
					for(int x=k; x<k+w; ++x){
						if(0 <= y && y <4 && 0 <= x && x < 4)
							bs[y*4+x] = true;
					}
				}
				if(bs.any())
					stamp.insert(bs.to_ulong());
			}
		}
	}

	vector<bitset<16> > color(3);
	for(int i=0; i<16; ++i){
		char c;
		cin >> c;
		if(c == 'R')
			color[0][i] = true;
		else if(c == 'G')
			color[1][i] = true;
		else
			color[2][i] = true;
	}

	vector<int> memo(1<<16, -1);
	queue<int> q;
	memo[0] = 0;
	q.push(0);
	for(;;){
		bitset<16> bs = q.front();
		q.pop();

		set<int>::iterator it;
		for(it=stamp.begin(); it!=stamp.end(); ++it){
			for(int i=0; i<3; ++i){
				bitset<16> bs2 = color[i] & bitset<16>(*it);
				if(bs2.none())
					continue;
				bs2 |= bs & ~bitset<16>(*it);
				if(memo[bs2.to_ulong()] == -1){
					memo[bs2.to_ulong()] = memo[bs.to_ulong()] + 1;
					q.push(bs2.to_ulong());
					if(bs2.all()){
						cout << memo[bs2.to_ulong()] << endl;
						return 0;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1268
H,W=(int(i) for i in input().split())
Field=[]
for i in range(H):
    Field.append(list(input()))
for i in range(0,H):
    for j in range(W):
        if Field[i][j]=="#":continue
        cnt=0
        for x in range(-1,2):
            for y in range(-1,2):
                if (x==0 and y==0) or 0>x+i or 0>y+j or x+i>=H or y+j>=W:
                    continue
                if Field[i+x][j+y]=="#":
                    cnt+=1
        Field[i][j]=str(cnt)

for i in range(H):
    Out=Field[i][0]
    for j in range(1,W):
        Out+=Field[i][j]
    print(Out)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];
ll n, k;
ll a[201010];

bool ok(ll x) {
	ll now = 0;
	rep(i, n) {
		now += (a[i] - 1) / x;
	}
	return now <= k;
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
	}
	ll l = 0, r = INF;
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		if (ok(mid)) {
			r = mid;
		}
		else {
			l = mid;
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>

int main(){
  int N, M, a[50] = {0}, i, p, q;
  scanf("%d %d", &N, &M);
  for (i = 0; i < M; i++){
    scanf("%d %d", &p, &q);
    a[p - 1]++;
    a[q - 1]++;
  }
  for (i = 0; i < N; i++){
    printf("%d\n", a[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

move = [abs(a[i - 1] - a[i]) for i in range(1, n + 2)]
msum = sum(move)
for i in range(1, n + 1):
    tmp = - move[i - 1] - move[i] + abs(a[i - 1] - a[i + 1])
    print(msum + tmp)


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

#define INF 1e9;

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

void calc(vector<int> v) {
		int a = 0, b = 0, c = 0, tmp = 0;
		for ( int i = 0; i < N; i++ ) {
				switch (v[i]) {
						case 0:
								if (a) tmp += 10;
								a += l[i];
								break;
						case 1:
								if (b) tmp += 10;
								b += l[i];
								break;
						case 2:
								if (c) tmp += 10;
								c += l[i];
								break;
						case 3:
								break;
				}
		}
		if ( a == 0 || b == 0 || c == 0 ) {
				tmp = INF;
		} else {
				tmp += (abs(A - a) + abs(B - b) + abs(C -c) );
		}
		if ( ans > tmp ) ans = tmp;
}

void dfs(int depth, vector<int> v) {
		if (depth == N) calc(v);
		else {
				// 0:A, 1:B, 2:C, 3:not use
				for ( int i = 0; i < 4; i++ ) {
						v[depth] = i;
						dfs(depth + 1, v);
				}
		}
}

int main() {
		cin >> N >> A >> B >> C;
		for ( int i = 0; i < N; i++ ) {
				int t;
				cin >> t;
				l.push_back(t);
		}

		vector<int> v(N, 0);
		dfs(0, v);

		cout << ans << endl;

		return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n,k,c,t,ans=10000;
	scanf("%d%d",&n,&k);
	while(n--){
		scanf("%d%d",&c,&t);
		if(t<=k&&c<ans)ans=c;
	}
	if(ans==10000)puts("TLE");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(n); i++)

int main(){
	while(1){
		ll m,n,t,p; cin >> m >> n >> t >> p;
		if(m+n+t+p == 0) break;
		vector<int> d(t),c(t),x(p),y(p);
		ll idn = 0; ll idm = 0;
		ll backn = n-1; ll backm = m-1;
		vector<vector<int>> a(1000,vector<int>(1000,0));
		rep(i,n) rep(j,m) a[i][j] = 1;
		rep(z,t){
			cin >> d[z] >> c[z];
			if(d[z] == 1){
				for(ll i=idn; i<=backn; i++){
					for(ll j=idm; j<idm+c[z]; j++){
						a[i][idm+2*c[z]-1+(idm-j)] += a[i][j];
						backm = max(backm, idm+2*c[z]-1);
					}
				}
				idm += c[z];
			}else{
				for(ll j=idm; j<=backm; j++){
					for(ll i=idn; i<idn+c[z]; i++){
						a[idn+2*c[z]-1+(idn-i)][j] += a[i][j]; 
						backn = max(backn, idn+2*c[z]-1);
					}
				}
				idn += c[z];
			}
		}
		/*rep(i,6){
			rep(j,6) cout << a[i][j] << " ";
			cout << "\n";
		}
		cout << idm << " " << idn << "\n";*/
		rep(i,p){
			cin >> x[i] >> y[i];
			x[i] = x[i] + idm;
			y[i] = y[i] + idn;
			cout << a[y[i]][x[i]] << "\n";
		}
	}
}


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

int main() {
	int n;
	cin >> n;
	int r = n%10;
	if (r==2 || r==4 || r==5 || r==7 || r==9) cout << "hon" << endl;
	else if (r==0 || r==1 || r==6 || r==8) cout << "pon" << endl;
	else cout << "bon" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(){

  int in;
  while(cin >> in && in){
    int sum = 0;
    for(int i = 0; i < in*(in-1)/2; i++){
      int num;
      cin >> num;
      sum += num;
    }
    cout << sum / (in-1) << endl;
  }

  return 0;
}

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

int main(void){
  int H,W;
  char s;
  cin >> H >> W;
  int vec[55][55]={-1};
  int mine[55][55]={};
  int dx[8]={1,1,0,-1,-1,-1,0,1};
  int dy[8]={0,1,1,1,0,-1,-1,-1};
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> s;
      if(s=='#'){
        vec[i][j]=1;
        mine[i][j]=1;
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(vec[i][j]==1) continue;
      else if(vec[i][j]==0){
        for(int d=0;d<8;d++){
          if(vec[i+dx[d]][j+dy[d]]==1) mine[i][j]++;
        }
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(vec[i][j]==1) cout << '#';
      else if(vec[i][j]==0) cout << mine[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import math
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = []
a.append(a1)
a.append(a2)
a.append(a3)

n = int(input())
b = []
for _ in range(n):
  b.append(int(input()))

bingo = [ [0 for _ in range(3)] for __ in range(3)]

for bt in b:
  for i, at in enumerate(a1):
    if at == bt:
      bingo[0][i] = 1
  for i, att in enumerate(a2):
    if att == bt:
      bingo[1][i] = 1
  for i, attt in enumerate(a3):
    if attt == bt:
      bingo[2][i] = 1

for l in range(3):
  if sum(bingo[l]) == 3:
    print("Yes")
    quit()
  if bingo[0][l] + bingo[1][l] +bingo[2][l] == 3:
    print("Yes")
    quit()
if bingo[0][0] + bingo[1][1] +bingo[2][2] == 3:
    print("Yes")
    quit()
if bingo[0][2] + bingo[1][1] +bingo[2][0] == 3:
    print("Yes")
    quit()

print("No")









Measured memory_bytes: 3064
def s(x):
    print('',x,end='')
def p(u):
    if u+1:s(u);p(R[u]);p(L[u])
def i(u):
    if u+1:i(R[u]);s(u);i(L[u])
def o(u):
    if u+1:o(R[u]);o(L[u]);s(u)
        
n = int(input())
R, L = [0]*n, [0]*n
for _ in range(n):
    a, b, c = map(int, input().split())
    R[a] = b
    L[a] = c

root = (set(range(n))-set(R)-set(L)).pop()
print('Preorder');p(root)
print('\nInorder');i(root)
print('\nPostorder');o(root)
print()
     


Measured memory_bytes: 5628
import sys
import numpy as np
input = sys.stdin.readline

N,M,X = list(map(int,input().split()))
CA = [ list(map(int,input().split())) for _ in range(N)]
bit = 2**N
cost = float('inf')

for bi in range(1,bit):
    tmp=[]
    for i in range(N):
        if bi & 1<<i:
            tmp.append(CA[i-1])
    tmp = np.array(tmp)        
    a = sum(tmp)
    if all( [a[j]>=X for j in range(1,M+1)]):
        cost = min(cost,a[0])
print( -1 if cost == float('inf') else cost)


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

using namespace std;

int ss[13],n,bb[13],tt[5];
inline int cc(int xx)
{
	for(int i=0;i<13;i++) if(ss[i]>=3) return 0;
	int bb=30;
	for(int i=0;i<13;i++) if(ss[i]==2) 
		bb=min(bb,min(2*i%24,24-2*i%24));
	for(int i=0;i<13;i++) if(ss[i])
	{
		for(int j=i+1;j<13;j++) if(ss[j])
		{
			tt[0]=0;
			if(ss[i]==2) tt[++tt[0]]=i,tt[++tt[0]]=-i;
			else tt[++tt[0]]=i*(xx&(1<<i)? -1:1);
			if(ss[j]==2) tt[++tt[0]]=j,tt[++tt[0]]=-j;
			else tt[++tt[0]]=j*(xx&(1<<j)? -1:1);
			for(int t=1;t<=tt[0];t++)
				for(int s=t+1;s<=tt[0];s++)
					bb=min(bb,min(abs(tt[t]-tt[s])%24,24-abs(tt[t]-tt[s])%24));
		}
	}
	return bb;
}
int main()
{
	scanf("%d",&n); ss[0]++;
	for(int i=1;i<=n;i++)
	{
		int k; scanf("%d",&k);
		ss[k]++;
	}
	int ans=0;
	for(int i=0;i<(1<<14);i++)
		ans=max(ans,cc(i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	double a, b, c, d, e, f, x, y;
	
	while (1) {
		if (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) == EOF)
			break;
		
		if ((d * b - e * a) == 0 || a == 0)
			continue;
		
		y = (d * c - f * a) / (d * b - e * a); 
		x = (c - b * y) / a;

		printf("%.3lf %.3lf\n", x, y);
	}	
	
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   int[] A= new int[5];
   for(int i=0;i<5;i++){
     A[i]=kbd.nextInt();
     if(A[i]==0){
       System.out.println(i+1);
     }
 }
}
}


Measured memory_bytes: 35828
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
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; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  string s,t; cin >> s >> t;
  int ns = s.size(), nt = t.size();
  vii dp(ns+1, vi(nt+1, 0));
  rep1(i,ns) {
    rep1(j,nt) {
      if(s[i-1] == t[j-1]) {
	dp[i][j] = max({dp[i-1][j-1] + 1, dp[i][j-1], dp[i-1][j]});
      }
      else {
	dp[i][j] = max(dp[i][j-1], dp[i-1][j]);	
      }
    }
  }

  string res = "";
  while(dp[ns][nt] > 0) {
    if(s[ns-1] == t[nt-1]) {
      if(dp[ns-1][nt-1] + 1 == dp[ns][nt]) {
	res.push_back(s[ns-1]);
	ns--; nt--;
	continue;
      }
    }
    if(dp[ns-1][nt] == dp[ns][nt]) {
      ns--;
    }
    else if(dp[ns][nt-1] == dp[ns][nt]) {
      nt--;
    }
  }
  reverse(res.begin(), res.end());
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 38632
def main():
    import sys
    input = sys.stdin.readline
    inputs = lambda:map(int, input().split())
    n, q = inputs()
    e = [[] for _ in range(n)]
    counter = [0] * n
    m = n-1
    for _ in range(m):
        v1, v2 = inputs()
        v1 -= 1
        v2 -= 1
        e[v1] += v2,
        e[v2] += v1,
    for _ in range(q):
        p, x = inputs()
        p -= 1
        counter[p] += x
    used = [False] * n
    s = 0
    used[s] = True
    stack = [s]
    while stack:
        s = stack.pop()
        for c in e[s]:
            if used[c]:
                None
            else:
                used[c] = True
                counter[c] += counter[s]
                stack += c,
    print(*counter)
main()

Measured memory_bytes: 55844
/*#pragma GCC optimize("O3")*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000001
#define PI 3.14159265358979323846
using namespace std;
vector<int>v[100005];
int dp[100005];
int dfs(int idx)
{
	if(dp[idx])
		return dp[idx];
	for(int i = 0; i < v[idx].size(); i++)
		dp[idx]=max(dp[idx], dfs(v[idx][i]));
	dp[idx]++;
	return dp[idx];
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	int x, y;
	for(int i = 0; i < m; i++)
	{
		cin >> x >> y;
		v[x].push_back(y);
	}
	int ans=0;
	for(int i = 1; i <= n; i++)
		ans=max(ans, dfs(i));
	cout << ans-1 << '\n';
}
//size

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

int n, a[201000];
long long ans;

int main(void) {
  scanf("%d", &n);
  a[0] = -1;
  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if(a[i] > a[i - 1] + 1) return puts("-1"), 0;
  }
  for(int i = 1; i <= n; i++) {
    int j = i;
    while(a[j + 1] == a[j] + 1 && j < n) j++;
    ans += a[j];
    i = j;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 1024