akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on
const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
  // solver code

  if ((A == B) && (B != C) || (A != B) && (C == B) || (A == C) && (A != B)) {
    cout << YES << endl;

  } else {
    cout << NO << endl;
  }
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string o, e;
  cin >> o >> e;
  rep(i, min(o.size(), e.size())) cout << o[i] << e[i];
  if (o.size() != e.size()) cout << o[o.size() - 1];
  cout << endl;
  return 0;
}


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

int main() {
  ll n; cin >> n;
  ll x;
  for(ll i = 1; i<=9; i++){
    if(n%i==0 && n/i<=9) x++;
  }
  if(x>0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

string s;

int main()
{
    cin>>s;

    if( s[0] == 'R' && s[1] == 'R' && s[2] == 'R' )
    {
        cout<<3<<endl;
        return 0;
    }

    if( ( s[0] == 'R' && s[1] == 'R' ) || ( s[1] == 'R' && s[2] == 'R' ) )
    {
        cout<<2<<endl;
        return 0;
    }

    if( s[0] == 'R' || s[1] == 'R' || s[2] == 'R' )
    {
        cout<<1<<endl;
        return 0;
    }

    cout<<0<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    
    int reminder = a % b;
    //cout << "reminder " << reminder << endl;
    
    int box[100];
    int i = 0;
    while(1){
        box[i] = (reminder * (i + 1)) % b;
        //cout << "box[" << i << "] " <<  box[i] << endl;
        if(box[i] == 0) break;
        i++;
    }
    i++;
    
    bool judge = false;
    int limit = i;
    //cout << judge << endl;
    for (int i = 0; i < limit; ++i)
    {
        if(box[i] == c) judge = true;
    }
    //cout << judge << endl;
    if(judge)   cout << "YES" <<endl;
    else    cout << "NO" <<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
ans = 0
n.times do |i|
  ans += b[a[i]-1]
  if i > 0 && a[i] - a[i-1] == 1
    ans += c[a[i-1]-1]
  end
end
p ans


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int main() {
    int n;
    scanf("%d", &n);
    int m = INT_MAX;
    for (int i = 1; i < n; i++) {
        int a = i;
        int b = n - a;
        int sa = 0;
        while (a) {
            sa += a % 10;
            a /= 10;
        }
        int sb = 0;
        while (b) {
            sb += b % 10;
            b /= 10;
        }
        m = min(m, sa + sb);
    }
    printf("%d\n", m);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  ll x,y;cin>>x>>y;
  ll z=y/x;
  ll ans=0;
  while(z>=1){
    ans++;
    z/=2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    int ans;
    rep(i,N) cin >> A[i];
    rep(i,N){
        if(i==0){
            ans = A[N-1]-A[0];
        }
        else{
            ans = min(K-A[i] + A[i-1], ans);
        }
    }
    cout << ans << endl;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  ll a,b,k;cin >> a >> b >> k;
  if(k<=a){cout << a-k << ' '<<b;}
  else if(k>a && k<=a+b){cout << 0 <<' '<< a+b-k;}
  else cout << 0 <<' '<< 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 1'000'005;
map<int, int> prime;

ll solve(int n) {
  ll ret = 1;
  for (int i = 2; i * i <= n; i++) {
    int j = 1;
    while (n % i == 0) {
      n /= i;
      j++;
    }
    if (j > 1) ret *= j;
  }
  if (n > 1) ret *= 2;
  return ret;
}

int main(void)
{
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = n - 1; i >= 2; i--) ans += solve(i);
  cout << ans << endl;
  return 0;
}

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

int main()
{
    string s;
    getline(cin, s);

    if(s.length() != 3)
    {
      cout << "-1\n";
      return 0;
    }
    else
    {
      cout << (s[0] - '0') * (s[2] - '0') << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int frower[7][2] = {{0,0},{2,380},{3,550},{5,850},{10,1520},{12,1870},{15,2244}};
  int dp[51][7] = {0};
  for(int i=1; i<51; i++){
    for(int j=0; j<7; j++){
      dp[i][j] = 100000;
    }
  }
  for(int i=0; i<51; i++){
    for(int j=1; j<7; j++){
      for(int k=0;i+k*frower[j][0]<51;k++){
	dp[i+k*frower[j][0]][j] = min(dp[i+k*frower[j][0]][j],dp[i][j-1]+frower[j][1]*k);
      }
    }
  }
  int n;
  while(cin>>n,n){
    for(int i=n/100; i<51; i++){
      if(dp[i][6]){cout <<dp[i][6]<<endl;break;}
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    map<string,int>cnt;
    ll ans=0;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        cnt[s]++;
    }
    for(auto c:cnt){
        ans +=(ll)c.second*(c.second-1)/2;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 11136
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    char m='&';
    vector<ll> R,L;
    vector<char>r,l;
    map<ll,ll> mp;
    cin>>s;
    string S=s;
    reverse(s.begin(),s.end());
    string V=s;
    ll n=s.size(),cnt=0,M=-1;


    cnt=0;
    rep(i,n){
        if(S[i]!='x'){
            r.pb(S[i]);
            R.pb(cnt);
            cnt=0;
        } else{
            cnt++;
        }
        if(i==n-1) R.pb(cnt);
    }
    cnt=0;
    rep(i,n){
        if(V[i]!='x'){
            l.pb(V[i]);
            L.pb(cnt);
            cnt=0;
        } else{
            cnt++;
        }
        if(i==n-1) L.pb(cnt);
    }
    rep(i,r.size()){
        if(r[i]!=l[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll ans=0;
    rep(i,R.size()){
        // cout<<R[i]<<" "<<L[i]<<endl;
        ans+=(abs(R[i]-L[i]));
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 3268
N,K = map(int,input().split())
alist = list(map(int,input().split()))
p = 0
q = 0
for i in range(K):
    p = p+alist[i]
for i in range(N-K):
    q = max(q,p)
    p = p-alist[i]+alist[K+i]
q = max(q,p)
print((q+K)/2)

Measured memory_bytes: 25060
N,M = map(int,input().split())
X = list(map(int,input().split()))

X.sort()

X_len = [X[i+1]-X[i] for i in range(len(X)-1)]

X_len.sort(reverse=True)
ans = X[-1] - X[0]    
for i in range(min(N-1,len(X_len))):
    ans -= X_len[i]    
    
print(ans)


Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
long long modinv(long long a,long long mod)
{
  return modpow(a,mod-2,mod);
}
int mod=1e9+7;

ll fact[100007],inv[100007];
ll c(int a,int b)
{
  if(a<b)return 0;
  return fact[a]*inv[b]%mod*inv[a-b]%mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0]=1;
  rep(i,1e5+6)fact[i+1]=fact[i]*(i+1)%mod;
  inv[100006]=modinv(fact[100006],mod);
  rep(i,1e5+6)inv[100006-i-1]=inv[100006-i]*(100006-i)%mod;
//  rep(i,100)cout<<inv[i]*fact[i]%mod<<endl;
  int l=0;
  int n;cin>>n;
  vector<int>id(n+1,-1);
  rep(i,n+1)
  {
    int a;cin>>a;
    if(id[a]==-1)id[a]=i;
    else
    {
      l+=id[a]+n-i;
    }
  }
  //cout<<c(4,2)<<endl;
  //cout<<fact[4]<<endl;

  repi(k,1,n+2)
  {
    ll res=c(n+1,k)-c(l,k-1);
    cout<<(mod+res)%mod<<"\n";
  }

  return 0;

}


Measured memory_bytes: 3200
package main
import(
    "fmt"
    "os"
)

func main(){
    var n, y int
    fmt.Scan(&n, &y)
    for i := 0; i <= n; i++ {
        for j := 0; j <= n - i; j ++ {
            k := n - i - j
            if 10000 * i + 5000 * j + 1000 * k == y {
                fmt.Println(i, j, k)
                os.Exit(0)
            }
        }
    }
    fmt.Println("-1 -1 -1")
}

Measured memory_bytes: 1836
import sys
sys.setrecursionlimit(10**7)

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


par=[index for index in range(N+1)]

def root(x):
    global par

    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]


def same(x,y):
    global par

    if root(x)==root(y):
        return True
    else:
        return False

def unite(x,y):
    global par

    if root(x)!=root(y):
        par[root(x)]=root(y)


friends=[[] for index1 in range(N+1)]
for index2 in range(M):
    a,b=map(int,input().split())
    unite(a,b)
    friends[a].append(b)
    friends[b].append(a)


block=[[] for index3 in range(N+1)]
for index4 in range(K):
    c,d=map(int,input().split())
    block[c].append(d)
    block[d].append(c)


relates=[0]*(N+1)
for i in range(1,N+1):
    relates[root(i)]+=1


Ans=[]
for j in range(1,N+1):
    ans=relates[root(j)]-1    #高速化可能   #1
    for k in friends[j]:
        if same(j,k):
            ans-=1
    for l in block[j]:
        if same(j,l):   #まとめられる
            ans-=1

    Ans.append(ans)

print(*Ans)



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root,NIL;
int maxh;

Node treeSearch(Node x,int k){
  while(x !=NIL && k != x->key){
    if( k< x->key ){
      x = x->left;
    }
    else x = x->right;
  }
    return x;
  
}

void insert(int x){
  int H;
  Node b = NIL;
  Node a = root;
  Node c;

  c = malloc(sizeof(struct node));
  c->key = x;
  c->left = NIL;
  c->right = NIL;

  while( a != NIL ){
    b = a;
    if ( c->key < a->key ){
     a  = a->left;
    } else {
      a = a->right;
    }
  }

  c->parent = b;
  if ( b == NIL ){
    root = c;
  } else {
    if (c->key < b->key) {
      b->left = c;
    } else {
      b->right =c;
    }
  }
}


  void inorder(Node x){
    if(x == NIL){
      return;
    }
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }

  void preorder(Node x){
    if( x == NIL){
      return ;
    }
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }

  int main(){
    int num,i,x;
    char com[20];
    scanf("%d",&num);
    maxh = 0;
    for(i=0; i<num; i++){
      scanf("%s",com);
      if(com[0] == 'f'){
	scanf("%d",&x);
	Node tn = treeSearch(root ,x);
	if(tn != NIL){
	  printf("yes\n");
	}
	else {
	  printf("no\n");
	}
      }
	else if(com[0] == 'i'){
	  scanf("%d",&x);
	  insert(x);
	}
	else if(com[0] == 'p'){
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      }
    
      return 0;
    }



Measured memory_bytes: 20516
/*
 * ex 4_2
 * kamecha
 */
#include<stdio.h>
#include<math.h>

int main(void){
    double h_hand, m_hand, hour, minute;
    scanf("%lf %lf %lf %lf", &h_hand, &m_hand, &hour, &minute);
    double time = 60*hour + minute;
    //角速度の差を出しておく
    double theta = time*M_PI*11/360;
    //余弦定理
    double ans = sqrt(h_hand*h_hand + m_hand*m_hand - 2*h_hand*m_hand*cos(theta));
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 2580
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	rep(i, n) {
		cout << s.at(i) << t.at(i);
	}
	cout << endl;
	return 0;
}

// abc : 141 , aoj : ITP1_6_D

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int main(void) {
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	ll res = 0;
	REP(i, n) cin>>a[i]>>b[i];
	for(ll i = n - 1; i >= 0; --i) {
		ll k = (a[i] + res - EPS) / b[i] + 1;
		res += k * b[i] - (res + a[i]);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 1024
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
    string s;cin >> s;
    sort(s.begin(),s.end());
    if(s == "abc"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BNiceShopping {
public:
    void solve(istream& cin, ostream& cout) {
        int a, b, m;
        cin >> a >> b >> m;
        int minA = INT_MAX, minB = INT_MAX;
        vector<int> sa, sb;
        for(int i=0; i<a; i++) {
            int tp;
            cin >> tp;
            minA = min(minA, tp);
            sa.push_back(tp);
        }
        for(int i=0; i<b; i++) {
            int tp;
            cin >> tp;
            minB = min(minB, tp);
            sb.push_back(tp);
        }
        int mincost = minA+minB;
        for(int i=0; i<m; i++) {
            int x, y, c;
            cin >> x >> y >> c;
            mincost = min(mincost, sa[x-1] + sb[y-1] - c);
        }
        cout << mincost << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BNiceShopping solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
using namespace std;
string UP(string s){
	string t=s;
	for(int i=0;i<s.size();i++)
		t[i]=toupper(s[i]);
return t;
}

int main(){
string ch;
string K;
char ty[11],m[11];
int n;n=0;
cin>>ch;
ch=UP(ch);
while(1){
cin>>K;

if(K=="END_OF_TEXT")break;
K=UP(K);
if((ch)==(K))n++;

}
printf("%d\n",n);
return 0;
}

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

int main() {
    int D;
    cin >> D;
    int d[26];
    vector<int> last(26, 1);

    rep(i, 26) {
        cin >> d[i];
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> ans(D);

    ll level = 0;
    rep(i, D) {
        ll now = 0;
        ll maxnow = -INF;

        if (i <= D - 3) {
            maxnow = -INF;
            rep(j, 26) {
                rep(k, 26) {
                    rep(l, 26) {
                        now = 0;
                        int t[3] = {j, k, l};
                        vector<int> tlast = last;

                        rep(m, 3) {
                            now += s[i + m][t[m]];
                            tlast[t[m]] = 0;

                            rep(n, 26) {
                                now -= d[n] * tlast[n];
                                tlast[n]++;
                            }
                        }

                        //更新
                        if (now > maxnow) {
                            maxnow = now;
                            ans[i] = j;
                            ans[i + 1] = k;
                            ans[i + 2] = l;
                        }
                    }
                }
            }
        }
        //計算
        level += s[i][ans[i]];
        last[ans[i]] = 0;
        rep(j, 26) {
            level -= d[j] * last[j];
            last[j]++;
        }
    }

    rep(i, D) {
        cout << ans[i] + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3684
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N = int(input())

div = 10**9 + 7

def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
       primfac.append(n)
    return primfac

primfac = primes(math.factorial(N))
fcnt = {}
for a in primfac:
    if a in fcnt:
        fcnt[a] += 1
    else:
        fcnt[a] = 1

ans = 1
for k,v in fcnt.items():
    ans *= v + 1

# print(fcnt)
print(ans%div)


# primfac.extend([1])
# print(math.factorial(N))
# print(primfac)
# print(math.factorial(N)%(10**9+7))


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  rep(i, n) {
    cin >> b[i];
  }
  rep(i, n-1) {
    cin >> c[i];
  }
  int ans = 0;
  int prev = -2;
  rep(i, n) {
    ans += b[a[i]];
    if (a[i] == prev + 1) {
      ans += c[prev];
    }
    prev = a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    VL dp(n);
    dp[0] = 1000;
    REP(i,n){
        if (i < n - 1) chmax(dp[i + 1], dp[i]);
        ll c = dp[i] / a[i];
        ll r = dp[i] % a[i];
        FOR(j,i+1,n-1){
            ll x = r + c * a[j];
            chmax(dp[j], x);
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 3696
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + '=7')
        break

Measured memory_bytes: 3060
import sys
def I(): return int(sys.stdin.readline().rstrip())


N = I()
mod = 10**9+7


fac = [1]*(N+1)
for i in range(1,N+1):
    fac[i] = (fac[i-1]*i) % mod

fac_inverse = [1]*(N+1)
for i in range(1,N+1):
    fac_inverse[i] = pow(fac[i],mod-2,mod)


def nCr(n,r):
    if n < r:
        return 0
    return (fac[n]*fac_inverse[r]*fac_inverse[n-r]) % mod


A = [0]*(N+1)  # Ai = i回以下マシンを稼働することで、全て黒く塗られるような順列の個数
for i in range(N+1):
    A[i] = (fac[i]*fac[N-1-i]*nCr(i-1,N-1-i)) % mod

ans = 0
for i in range(1,N):
    ans += i*(A[i]-A[i-1])
    ans %= mod

print(ans)


Measured memory_bytes: 156284
/* ex5_3
   cy_an  */

#include <stdio.h>

int main(void){

    // 変数宣言
    int num_r, num_c, i, j, r_flag, c_flag, printflag;
    // numの入力
    scanf("%d %d", &num_r, &num_c);
    // 変数宣言
    char matrix[num_r+1][num_c+1];
    // raw,colの入力
    for(i=0; i<num_r; i++){
        scanf("%s", matrix[i]);
    }

    // 行の削除
    for(i=0; i<num_r; i++){
        r_flag = 1;
        for(j=0; j<num_c; j++){
            if(matrix[i][j] == '#'){
                r_flag = 0;
                break;
            }
        }
        // 全て'.'のとき
        if(r_flag){
            for(j=0; j<num_c; j++){
                matrix[i][j] = '\0';
            }
        }
    }
    // 列の削除
    for(j=0; j<num_c; j++){
        c_flag = 1;
        for(i=0; i<num_r; i++){
            if(matrix[i][j] == '#'){
                c_flag = 0;
                break;
            }
        }
        // 全て'.'のとき
        if(c_flag){
            for(i=0; i<num_r; i++){
                matrix[i][j] = '\0';
            }
        }
    }

    // matrixの出力
    for(i=0; i<num_r; i++){
        printflag = 0;
        for(j=0; j<num_c; j++){
            if(matrix[i][j] != '\0'){
                printf("%c", matrix[i][j]);
                printflag = 1;
            }
        }
        if(printflag){
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int dp[105][4][2];

int main()
{
    string s;
    int K;
    cin >> s >> K;
    int n = s.size();
    dp[0][0][0] = 1;

    rep(i, n) rep(j, 4) rep(k, 2)
    {
        int nd = s.at(i) - '0';
        rep(d, 10)
        {
            int ni = i + 1, nj = j + min(d, 1), nk = k;
            if (nj > K)
                continue;
            if (nk == 0)
            {
                if (d > nd)
                    continue;
                if (d < nd)
                    nk = 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		int[][] c = new int[10][10];
		for (int i = 0; i <= 9; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j <= 9; j++) {
				c[i][j] = Integer.parseInt(sa[j]);
			}
		}
		int[][] a = new int[h][w];
		for (int i = 0; i < h; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < w; j++) {
				a[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		Obj[] arr = new Obj[10];
		for (int i = 0; i <= 9; i++) {
			Obj o = new Obj();
			o.idx = i;
			o.c = c[i][1];
			arr[i] = o;
		}

		for (int k = 0; k < 8; k++) {
			Arrays.parallelSort(arr, new Comparator<Obj>() {
				public int compare(Obj o1, Obj o2) {
					return o1.c - o2.c;
				}
			});
			for (int i = 2; i <= 9; i++) {
				Obj oi = arr[i];
				int min = Integer.MAX_VALUE;
				for (int j = 1; j <= i; j++) {
					Obj oj = arr[j];
					min = Math.min(min, c[oi.idx][oj.idx] + oj.c);
				}
				oi.c = min;
			}
		}

		Arrays.parallelSort(arr, new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				return o1.idx - o2.idx;
			}
		});

		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int aa = a[i][j];
				if (aa != -1) {
					ans += arr[aa].c;
				}
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int idx, c;
	}
}


Measured memory_bytes: 26964
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> as(n); cin >> as;
    ll a = as[0], b = as[1], c = 0;
    for(int i = 2; i < n; i++){
        c ^= as[i];
    }
    printde(as);
    printde(a, b, c);
    ll ans = 0;
    for(int i = 60; i >= 0; i--){
        bool ab = a >> i & 1, bb = b >> i & 1, cb = c >> i & 1;
        ll mask = (1ll << (i + 1)) - 1;
        if((ab ^ bb) == cb){
            continue;
        }
        if(cb){
            if(!ab & !bb){
                ll num = (1ll << i) - (b & mask);
                if(a < num){
                    cout << -1 << '\n';
                    return 0;
                }
                a -= num;
                b += num;
                ans += num;
            }else{
                ll num = (a & mask) - (1ll << i) + 1;
                a -= num;
                b += num;
                ans += num;
                if((b >> i & 1) == 0){
                    cout << -1 << '\n';
                    return 0;
                }
            }
        }else{
            if(ab){
                ll num = min((1ll << i) - (b & mask), (a & mask) - (1ll << i) + 1);
                if(a < num){
                    cout << -1 << '\n';
                    return 0;
                }
                a -= num;
                b += num;
                ans += num;
            }else if(bb){
                ll num = (1ll << i) - (b & (1ll << i) - 1);
                if(a < num){
                    cout << -1 << '\n';
                    return 0;
                }
                a -= num;
                b += num;
                ans += num;
                i++;
                // cout << -1 << '\n';
                // return 0;
            }
        }
    }
    if(a == 0 || (a ^ b) != c){
        cout << -1 << '\n';
        return 0;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3128
fun main(args: Array<String>) {
    val (h, w) = readInputLine().split(" ").map{it.toInt()}
    val sArr = Array(h, {CharArray(w)})

    for (i in 0 until h) {
        sArr[i] = readInputLine().toCharArray()
    }

    val l = Array(h, {IntArray(w)})
    val r = Array(h, {IntArray(w)})
    val u = Array(h, {IntArray(w)})
    val d = Array(h, {IntArray(w)})
    
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (sArr[i][j] == '#') {
                u[i][j] = 0
                l[i][j] = 0
                continue
            }
            if (i == 0) {
                u[i][j] = 1
            }  else {
                u[i][j] = u[i - 1][j] + 1
            }
            if (j == 0) {
                l[i][j] = 1
            } else {
                l[i][j] = l[i][j - 1] + 1
            }
        }
    }

    for (i in h - 1 downTo 0) {
        for (j in w - 1 downTo 0) {
            if (sArr[i][j] == '#') {
                d[i][j] = 0
                r[i][j] = 0
                continue
            }
            if (i == h - 1) {
                d[i][j] = 1
            }  else {
                d[i][j] = d[i + 1][j] + 1
            }
            if (j == w - 1) {
                r[i][j] = 1
            } else {
                r[i][j] = r[i][j + 1] + 1
            }
        }
    }
    
    var ans = 0
    for (i in 0 until h) {
        for (j in 0 until w) {
            val tmp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
            if (ans < tmp) {
                ans = tmp
            }
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 136004
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int main(){
    int r;
    cin >> r;
    cout<<r*r<<endl;
    return 0;
}

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

int main() {
	vector<int> v;
	bool flag=true;
	
	while(flag){
		int n;
		cin >> n;
		
		if(n==0) break;
		
		v.push_back(n);
		
		cout << "Case" << ' ' << v.size() << ": " << v[v.size() - 1] << endl;
	}
}

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

using namespace std;

long long func(int a[],int ans, int n){
	long long re = 0;
	for(int i = 0; i < n; i++){
		re+=(ans-a[i])*(ans-a[i]);
	}
	return re;
}

int main(void)
{
	int n; cin>>n;
	int a[n]; for(int i = 0; i < n; i++) cin>>a[i];
	long long cost = 1000000000;
	long long tmp;
	for(int i = -100; i < 101; i++){
		tmp = func(a,i,n);
		if(cost > tmp) cost = tmp;
	}
	cout<<cost<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a;
  int count1=0,count2=0;
  for(int i=1;i<=3;i++){
    scanf("%d ",&a);
    if(a==5) count1++;
    else if(a==7) count2++;
  }
  if(count1==2 && count2==1) printf("YES\n");
  else printf("NO\n");
  return 0;
}

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

using namespace std;

int a,b,x;

int main()
{
    cin >> a >> b;
    if (b<10) x=10*a+b;
    else if (b<100) x=100*a+b;
    else x=1000*a+b;
    int y=sqrt(x);
    if (y*y==x) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  REP(i, C) REP(j, C) { cin >> D[i][j]; }
  vector<vector<int>> color(N, vector<int>(N));
  vector<vector<int>> color_count(3, vector<int>(C));
  vector<int> cell_count(3);
  REP(i, N) REP(j, N) {
    int c;
    cin >> c;
    c--;
    color[i][j] = c;
    color_count[(i + j) % 3][c]++;
    cell_count[(i + j) % 3]++;
  }
  vector<vector<pair<i64, int>>> min_bad(3);
  REP(i, 3) {
    REP(y, C) {
      i64 dsum = 0;
      REP(x, C) { dsum += color_count[i][x] * D[x][y]; }
      if (min_bad[i].size() < 3) {
        min_bad[i].emplace_back(dsum, y);
        sort(min_bad[i].begin(), min_bad[i].end());
      } else if (dsum < min_bad[i][2].first) {
        min_bad[i][2] = make_pair(dsum, y);
        sort(min_bad[i].begin(), min_bad[i].end());
      }
    }
  }
  i64 ans = 1LL << 50;
  for (auto [d1, c1] : min_bad[0]) {
    for (auto [d2, c2] : min_bad[1]) {
      if (c2 == c1) continue;
      for (auto [d3, c3] : min_bad[2]) {
        if (c3 == c1 || c3 == c2) continue;
        i64 ds = d1 + d2 + d3;
        if (ans > ds) {
          ans = ds;
          DEBUG(ans, c1, c2, c3, d1, d2, d3);
        }
      }
    }
  }
  cout << ans << endl;
}


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

typedef long long int ll;

vector < vector <ll> > vec;
ll par[15];
ll n,m;
ll dp[15][2048];
ll solve(ll i,ll dr)
{
    //cout<<i<<" "<<dr<<endl;
    if(i==n)
    {

       //cout<<dr<<" ";

        for(ll j=0;j<m;j++){
            ll c = 0;
            for(ll k=0;k<vec[j].size();k++){
                if( (dr>>(vec[j][k]-1))&1 == 1 )
                {
                    c++;
                }
            }
           // cout<<dr<<" "<<j<<" "<<c<<endl;
            if(par[j]==0){
                if(c%2 == 1){
                    return 0;
                }
            }
            else{
                if(c%2 == 0){
                    return 0;
                }
            }
        }
        return 1;

    }
    else{
        if(1){

            return   solve(i+1,dr)+solve(i+1,dr+(1<<i));


        }
        //return dp[i][dr];
    }
}

int main()
{


        cin>>n>>m;
        memset(dp,-1,sizeof(dp));
        for(ll i=0;i<m;i++)
        {
            ll k;
            cin>>k;
            vector <ll> ve;
            for(ll j=0;j<k;j++){
                ll x;
                cin>>x;
                ve.push_back(x);
            }
            vec.push_back(ve);
        }
        for(ll i=0;i<m;i++)cin>>par[i];

        cout<<solve(0,0LL)<<endl;

}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int LMAX = 100000;
int n, maxDepth;
vector<int> w, v;
vector<vector<pair<int, int> > > query;
vector<int> ans;

void solve(int pos, int depth, vector<int>& dp, vector<pair<int, int> >& half)
{
    if(pos >= n)
        return;

    vector<int> nextDp;
    if(depth < maxDepth / 2){
        nextDp = dp;
        for(int i=LMAX; i>=w[pos]; --i)
            nextDp[i] = max(nextDp[i], nextDp[i-w[pos]] + v[pos]);
        dp.swap(nextDp);
    }
    else{
        for(int i=half.size()-1; i>=0; --i)
            half.push_back(make_pair(half[i].first + w[pos], half[i].second + v[pos]));
    }

    for(const auto& q : query[pos]){
        int l = q.first;
        for(const auto& p : half){
            if(p.first <= l){
                int v = dp[l-p.first] + p.second;
                ans[q.second] = max(ans[q.second], v);
            }
        }
    }

    solve(2 * pos + 1, depth + 1, dp, half);
    solve(2 * pos + 2, depth + 1, dp, half);

    if(depth < maxDepth / 2)
        dp.swap(nextDp);
    else
        half.resize(half.size() / 2);
}

int main()
{
    cin >> n;
    w.resize(n);
    v.resize(n);
    for(int i=0; i<n; ++i)
        cin >> v[i] >> w[i];

    maxDepth = 1;
    while((1 << maxDepth) <= n)
        ++ maxDepth;

    int q;
    cin >> q;
    query.resize(n);
    for(int i=0; i<q; ++i){
        int v, l;
        cin >> v >> l;
        -- v;
        query[v].push_back(make_pair(l, i));
    }

    vector<int> dp(LMAX + 1, 0);
    vector<pair<int, int> > half = {{0, 0}};
    ans.resize(q);
    solve(0, 0, dp, half);
    for(int i=0; i<q; ++i)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 18888
#include<bits/stdc++.h>
using namespace std;
int lcm(int x,int y){
  return x / __gcd(x,y) * y;
}
int main(){
  int n,ans=1,a;cin>>n;
  while(n--) cin>>a,ans=lcm(ans,a); 
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int N = 1e6;
long long int e[N],mod=1e9+7;

long long int tav(long long int x, long long int y) {
    if(y==0)
        return 1;
    long long int ret = tav(x,y/2);
    ret%=mod;
    ret*=ret;
    ret%=mod;
    if(y&1)
        ret*=x;
    return ret%mod;
}

long long int varon(long long int x) {
    return tav(x,mod-2)%mod;
}

int main () {
    long long int a, b;
    cin >> a >> b;
    //cout << tav(a,b);
    e[0]=1;
    for(int i = 1 ; i <= 30 ; i++ ) {
        e[i]=e[i-1]*((varon(i)*(a+i-1))%mod);
        e[i]%=mod;
    //    cout << varon(i) << ' ' << e[i] << '\n';
    }
    long long int ans = 1;
    for(int i = 2 ; i*i <= b ; i++ ) {
        if(b%i==0) {
            long long int t = 0;
            while(b%i==0) {
                b/=i;
                t++;
            }
            ans*=e[t];
            ans%=mod;
        }
    }
    if(b!=1)
        ans*=e[1];
    ans%=mod;
    cout << ans;
}


Measured memory_bytes: 256
local N, X = io.read("*n", "*n")
local m = {}

local m_sum = 0
for i = 1, N do
    m[i] = io.read("*n")
    m_sum = m_sum + m[i]
end
table.sort(m)

print(N + math.modf((X - m_sum) / m[1]))

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  int num;
  cin >> num;
  int tmp = 111;
  if(num <= 1 * tmp) {
    cout << 111 << endl;
  }
  else if(num <= 2 * tmp) {
    cout << 222 << endl;
  }
  else if(num <= 3 * tmp) {
    cout << 333 << endl;
  }
  else if(num <= 4 * tmp) {
    cout << 444 << endl;
  }
  else if(num <= 5 * tmp) {
    cout << 555 << endl;
  }
  else if(num <= 6 * tmp) {
    cout << 666 << endl;
  }
  else if(num <= 7 * tmp) {
    cout << 777 << endl;
  }
  else if(num <= 8 * tmp) {
    cout << 888 << endl;
  }
  else if(num <= 9 * tmp) {
    cout << 999 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] a = new int[m];
		int count = 0;
		
		for(int i=0;i<m;i++) {
			a[i] = scan.nextInt();
			count += a[i];
		}
		
		if(n >= count) {
			System.out.println(n-count);
		}else {
			System.out.println(-1);
		}

	}

}


Measured memory_bytes: 46536
import copy
def bfs(count, x, y, cheese):
    queue = [(count,x,y)]
    tempVisited = copy.deepcopy(visited)
    tempVisited[x][y] = True
    
    while len(queue)>0:
        tempc,tempx,tempy = queue.pop(0)
        if geo[tempx][tempy] == cheese:
            return tempc,tempx,tempy
        for i in range(4):
            neox = tempx+dx[i]
            neoy = tempy+dy[i]
            if canGoTo(neox,neoy, tempVisited):
                if (tempc+1,neox,neoy) not in queue:
                    queue.append((tempc+1,neox,neoy))
                    tempVisited[neox][neoy]=True
    return (-1,-1,-1)

def canGoTo(x,y,tempVisited):
    if 0<=x<H and 0<=y<W:
        return not tempVisited[x][y]
    return False

dx = [0,1,0,-1]
dy = [-1,0,1,0]

data = input().split(' ')
H,W,N = map(int, data)

#maps
geo = [[None for i in range(W)] for j in range(H)]
visited = [[False for i in range(W)] for j in range(H)]

x,y=-1,-1
for i in range(H):
    line = input()
    for j in range(W):
        p = line[j:j+1]
        geo[i][j] = p
        if p == 'X':
            visited[i][j] = True
        elif p == 'S':
            x,y, = i,j
            
count = 0
for n in range(1,N+1):
    count,x,y = bfs(count,x,y,str(n))
print(count)

Measured memory_bytes: 34704
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

monsters = 0
for i in range(N):
    monsters += min(A[i],B[i])
    B[i] -= min(A[i],B[i])
    monsters += min(A[i+1],B[i])
    A[i+1] -= min(A[i+1],B[i])

print(monsters)

Measured memory_bytes: 24120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
int main(){
    int n,m,lma=0,rmi=1e5;
    cin>>n>>m;
    int l,r;
    rep(i,0,m){
        cin>>l>>r;
        lma=max(lma,l);
        rmi=min(rmi,r);
    }
  	rmi=rmi-lma+1;
  	if(rmi<0)cout<<0<<endl;
    else cout<<rmi<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	long long ans;
	long long cntp=0;
	long long n;
	cin>>s;
	n=s.length();
	for(int i=1;i<n;i++){
		if(s[i]=='p'){
			cntp++;
		}
	}
	if(s[0]=='p'){
		ans=n/2-cntp-1;
	}
	else {
		ans=n/2-cntp;
	}
	cout<<ans;
}


Measured memory_bytes: 512