akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j,k;

int main(){
    ll N,K,C;
    cin>>N>>K>>C;
    string S;
    cin>>S;

    vector<ll> saki,ato;

    ll cnt=0;
    ll ka=0;
    while(cnt<N&&ka<K){
        if(S[cnt]=='o'){
            saki.push_back(cnt);
            cnt+=C+1;
            ka++;
        }
        else{
            cnt++;
        }
    }
    cnt=0;
    ka=0;
    while(cnt<N&&ka<K){
        if(S[N-1-cnt]=='o'){
            ato.push_back(N-1-cnt);
            cnt+=C+1;
            ka++;
        }
        else{
            cnt++;
        }
    }
    sort(saki.begin(),saki.end());
    sort(ato.begin(),ato.end());
    rep(i,K)if(saki[i]==ato[i])cout<<saki[i]+1<<endl;
    
}

Measured memory_bytes: 5108
n=int(input())
shogen=[]
for _ in range(n):
  a=int(input())
  t=[]
  for __ in range(a):
    s=list(map(int,input().split()))
    t.append(s)
  shogen.append(t)

ans=0

for i in range(2**n):
  flag=True
  for j in range(n):
    if not flag:
      break
    if ((i>>j) & 1):
      for s in shogen[j]:
        if ((i>>s[0]-1)&1) !=s[1]:
          flag=False
  if flag:
    mnt = bin(i).count("1")
    ans=max(ans,mnt)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    if(100 <= n and n<=999){
        n %= 100;
        n %= 10;
    }else if(10<= n and n<=99){
        n %= 10;
    }
    string ans;
    if(n == 0 or n == 1 or n==6 or n==8){
        ans = "pon";
    }else if(n==3){
        ans = "bon";
    }else{
        ans = "hon";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	int n,i;
	string s;
	cin>>n>>s;
	if(n%2!=0){cout<<"No"<<endl; return 0;}
	for(i=0;i<n/2;i++){if(s[i]!=s[i+n/2]){cout<<"No"<<endl; return 0;}}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  string s;
  cin>>s;

  int64_t k=stoll(s);

  int64_t s_digit=s.size();
  string s_num={};
  for(int i=0;i<s_digit;i++){
    s_num+="7";
  }


  bool flg = false;
  int64_t num=stoll(s_num);
  int64_t quot,rem;

  int64_t cnt=0;
  while(cnt<1000000){
    int64_t quot,rem;
    quot = num/k;
    rem  = num%k;
    num = 7+rem*10;
    if(rem == 0){
      flg=true;
      break;
    }
    
    cnt++;
  }

  if(flg)
    cout<<cnt+s_num.size()<<endl;
  else
    cout<<-1<<endl;

	return 0;
}

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

int main()
{
  int a, b, c, s1;
  double s2;

  c = s1 = s2 = 0;

  while (scanf("%d,%d", &a, &b) != EOF){
  //while (scanf("%d,%d", &a, &b) != EOF){
    s1 += a * b;
    c++;
    s2 += b;
  }
  printf("%d\n%.0f\n", s1, (s2 + 1) / c);

  return 0;
}

Measured memory_bytes: 1212
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <climits>
#include <ctime>

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

void solve() {
	string s;
	getline(cin, s);
	int n = s.size();
	int l = n / 2 - 1, r = (n + 1) / 2;
	while (l != -1 && r != n && s[l] == s[r] && s[r] == s[r - 1])
		--l, ++r;
	cout << r;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 512
s = str(input())
if len(s) >= 3:
    n = [s[-3], s[-2], s[-1]]
if len(s) == 2:
    n = [s[-2], s[-1]]
if len(s) == 1:
    n = [s[0]]
n = ''.join(n)
n = int(n)
if n == 0:
    print(0)
else:
    print(1000 - n)

Measured memory_bytes: 9128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

struct segtree{
    vector<ll> dat;
    int size;
    segtree(int n):dat(2*n-1,(1LL<<31)-1),size(n){};
    void update(int i,ll a){
        i+=this->size-1;
        dat[i]=a;
        while(i>0){
            i=(i-1)/2;
            dat[i]=min(dat[i+2+1],dat[i*2+2]);
        }
    }
    ll query(int a,int b){
        return querysub(a,b,0,0,this->size);
    }
    ll querysub(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return (1LL<<31)-1;
        else if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=querysub(a,b,k*2+1,l,(l+r)/2);
            ll vr=querysub(a,b,k*2+2,(l+r)/2,r);
            return min(vl,vr);
        }
    }
};

int main(){
    int x;cin>>x;
    cout<<(x>=30?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3600
mod = 10 ** 9 + 7
n, k = map(int, input().split())

a = [1] * (k+1)
b = [ i for i in range(k+1) ]

for i in range(k//2,0,-1):
  cnt = pow( k // i , n, mod )
  for j in range(i*2,k+1,i):
    cnt = ( cnt - a[j] ) % mod
  a[i] = cnt
  b[i] = i * cnt % mod

ans = 0
for i in range(1,k+1):
  ans += b[i]
  if ans >= mod:
    ans %= mod

print(ans)

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    map<string, ll> m;

    int n;
    cin >> n;
    rep(i, n) {
        int command;
        cin >> command;
        if (command == 0) {
            string key;
            cin >> key;

            ll v;
            cin >> v;
            m[key] = v;
        } else if (command == 1) {
            string key;
            cin >> key;
            if (m.find(key) == m.end()) {
                cout << 0 << endl;
            } else {
                cout << m[key] << endl;
            }
        } else if (command == 2) {
            string key;
            cin >> key;

            m.erase(key);
        } else if (command == 3) {
            string l, r;
            cin >> l >> r;

            for (auto it = m.lower_bound(l); it != m.end() && (*it).first <= r; it++) {
                printf("%s %lld\n", (*it).first.c_str(), (*it).second);
            }
        }
    }

}



Measured memory_bytes: 28004
import sys

def main():
    line = sys.stdin.readline()
    lst = line.split()
    a = int(lst[0])
    b = int(lst[1])

    if (a % 3 == 0) or (b % 3 == 0) or ((a+ b) % 3 == 0 ):
        print("Possible")
    else:
        print("Impossible")

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

#コンビネーション
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 1000  # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


n = INT()
a = LIST()
arr = [0 for _ in range(n)]
for i in range(n):
    if a[i] % 2 == 0:
        arr[i] = 2
    else:
        arr[i] = 1
s = 1
for i in range(n):
    s *= arr[i]
ans = 3 ** n - s
print(ans)


Measured memory_bytes: 60268
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0;
    string s,s1,s2;
    cin >> s;   
    rep(i,3){
        if(s[i] == 'a'){
            a++;
        }
        else if (s[i] == 'b'){
            b++;
        }
        else c++;
    }
    if(a==1&&b==1&&c==1)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc148
{
    class atCoder
    {
        static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            List<int> list = new List<int> { 1, 2, 3 };
            list.Remove(A);
            list.Remove(B);
            Console.WriteLine(list[0]);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> b(N), v;
    for (auto& i : b) cin >> i;
    while (!b.empty()) {
        bool f = false;
        for (int i = b.size() - 1; i >= 0; i--) {
            if (b[i] == i + 1) {
                v.push_back(i + 1);
                b.erase(b.begin() + i);
                f = true;
                break;
            }
        }
        if (!f) break;
    }
    reverse(v.begin(), v.end());
    if (!b.empty()) cout << -1 << endl;
    else for (int i : v) cout << i << endl;
}


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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;


int main() {
    ll n; cin >> n;
    ll sum = 0;
    erep(i, n) {
        if(i%15 == 0 || i%3 == 0 || i%5 == 0) {

        } else {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
int main(void){
  string s;
  cin>>s;
  vector<string>sNext;
  size_t size=s.length();
  for(int i(0);i<size-2;i++){
    string t;
    t=s.substr(i,3);
    sNext.push_back(t);
  }
  vector<int>eachNum;
  for(int i(0);i<size-2;i++){
    istringstream ss;
    int t;
    ss=istringstream(sNext[i]);
    ss>>t;
    eachNum.push_back(t);
  }
  vector<int>calNum;
  for(int i(0);i<size-2;i++){
    if(753>eachNum[i])calNum.push_back(753-eachNum[i]);
    else calNum.push_back(eachNum[i]-753);
  }
  int min(calNum[0]);
  for(int i(1);i<size-2;i++){
    if(min>calNum[i])min=calNum[i];
  }
  cout<<min<<endl;
  return 0;
}

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()

if N == 1:
    print(1)
    exit()

# フラグで向かう方向を管理
# 0:flat 1:up 2:down
flag = 0
if aN[0] < aN[1]:
    flag = 1
elif aN[0] == aN[1]:
    flag = 0
else:
    flag = 2

cnt = 1
# 向きが変わる所を区切り位置とする
for i in range(2, N):
    if aN[i-1] == aN[i]:
        continue
    elif aN[i-1] > aN[i]:
        if flag == 1:
            cnt += 1
            flag = 0
        else:
            flag = 2
    elif aN[i-1] < aN[i]:
        if flag == 2:
            cnt += 1
            flag = 0
        else:
            flag = 1
print(cnt)


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

long long int a;
long long int b;
long long int n;
using namespace std;

int main()
{
    cin >> a;
    cin >> b;
    cin >> n;
    long long int m = 0;
    /*
    for(long long int x=0;x<=n;x++){
        long long int t=((a*x)/b)-a*(x/b);
        if(t>m){
            m=t;
        }
    }*/
    if (b <= n)
    {
        long long int x = b - 1;
        cout << ((a * x) / b) - a * (x / b);
    }
    else
    {
        long long int x = n;
        cout << ((a * x) / b) - a * (x / b);
        /*
        for (long long int i = 0; x < n; i++)
        {
            x = b * n - 1;
            if (x > n)
            {
                break;
            }
            long long int t = ((a * x) / b) - a * (x / b);
            if (t > m)
            {
                m = t;
            }
        }*/
    }
    return 0;
    long long int x = 0;
    for (long long int i = 0; x < n; i++)
    {
        x = b * n - 1;
        if (x > n)
        {
            break;
        }
        long long int t = ((a * x) / b) - a * (x / b);
        if (t > m)
        {
            m = t;
        }
    }
    cout << m;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin>>s>>t;
  vector<int>x(1+s.size()-t.size());
  for(int i=0;i< 1 + s.size() - t.size();i++){
    x.at(i)=0;
    for(int j=0;j<t.size();j++){
      if(t.at(j)!=s.at(i+j)){
        x.at(i)++;
      }
    }  
  }
  sort(x.begin(), x.end());
    cout<<x.at(0)<<endl;
}

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int n;
int a[101];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  cin >> n;
  int max_ = -1;
  int min_ = 1000000001;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    max_ = max(max_, a);
    min_ = min(min_, a);
  }
  cout << max_ - min_ << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n;
    cin >> n;
    cout << (n & 1 ? n * 2 : n) << endl;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#endif

#include "bits/stdc++.h"

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

bitset<4 * 1000 * 1000 + 5> czy;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  czy[0] = 1;
  int sum = 0;
  while (n--) {
    int a;
    cin >> a;
    sum += a;
    czy |= (czy << a);
  }
  const int sum_pol = (sum + 1) / 2;
  for (int i = sum_pol; i < (int) czy.size(); i++) {
    if (czy[i]) {
      cout << i << endl;
      return 0;
    }
  }
  assert(false);
  return 0;
}


Measured memory_bytes: 1792
import sys
N=int(input())
A=[int(i) for i in input().split()]
p=1
for i in A:
  if i==0:
    print(0)
    sys.exit()
for i in A:
  p=p*i
  if p>1000000000000000000:
    print(-1)
    sys.exit()
print(p)

Measured memory_bytes: 21784
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    ll n,x,t,ans;
    cin>>n>>x>>t;
    ans=n/x;
    if(n%x!=0)ans++;
    ans*=t;
    cout<<ans;
}


Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 62; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

long long mod = 998244353;
long long A, B, C, D;
long long dp[3009][3009];
long long pv[3009][3009];
long long inv[3009];
long long pows[3009][3009];

void saisho() {
	for (int i = 1; i <= 3000; i++) inv[i] = Div(1, i, mod);
	for (int i = 1; i <= 3000; i++) {
		pows[i][0] = 1;
		for (int j = 1; j <= 3000; j++) pows[i][j] = (1LL * i * pows[i][j - 1]) % mod;
	}
}

void init(int pos) {
	long long ret = 0, r = inv[pos];
	for (int i = 1; i <= D; i++) {
		pv[pos][i] = 1LL * dp[pos][i] * r;
		pv[pos][i] += pv[pos][i - 1];
		pv[pos][i] %= mod;
		r *= inv[pos]; r %= mod;
	}
}

void solve(int px, int py) {
	// 累積和しない
	dp[px][py] += 1LL * py * dp[px - 1][py];

	// 累積和する
	long long val = pv[px - 1][py - 1];
	val *= pows[px - 1][py]; val %= mod;
	dp[px][py] += val;
	dp[px][py] %= mod;
}

int main() {
	cin >> A >> B >> C >> D; saisho();
	dp[A][B] = 1;
	init(A);

	// 計算
	for (int i = A + 1; i <= C; i++) {
		for (int j = B; j <= D; j++) {
			solve(i, j);
		}
		init(i);
	}

	// 答え
	long long Answer = 0;
	for (int i = 1; i <= D; i++) {
		long long R1 = dp[C][i];
		long long R2 = pows[C][D - i];
		Answer += R1 * R2;
		Answer %= mod;
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 215216
#!/usr/bin/env python3
n=int(input())
a=[0]*n
b=list(map(int,input().split()))
for i in range(1,n-1):
    a[i]=min(b[i],b[i-1])
a[0]=b[0]
a[n-1]=b[n-2]
print(sum(a))


Measured memory_bytes: 38256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    if s % ((n+1) * n // 2) != 0:
        print('NO')
        return
    s //= ((n+1) * n // 2)

    b = [a[(i+1)%n] - a[i] for i in range(n)]
    for i in range(n):
        b[i] -= s

    for i in range(n):
        if b[i] > 0 or b[i] % n != 0:
            print('NO')
            return
    print('YES')

main()

Measured memory_bytes: 15060
fun main(args: Array<String>) {
  val (n, m) = readLine()!!.split(" ").map { it.toInt() }
  val h = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
  val g = Array<MutableSet<Int>>(n) { mutableSetOf<Int>() }
  repeat(m) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt()-1 }
    g[a].add(b)
    g[b].add(a)
  }
  var ans = 0
  for (i in h.indices) {
    if (g[i].all { h[i] > h[it] }) ans++
  }
  println(ans)
}

Measured memory_bytes: 87112
#include<iostream>
#define N 100001
#define M 1000000001

int n,k,w[N];

bool check(int P){
  int x=0,sum;
  for(int i=0;i<k;i++){
    sum=0;
    for(int j=x;j<n;j++){
      if(sum+w[j]<=P){
	sum+=w[j];
	x++;
      }else{
	break;
      }
    }
    if(x==n){
      return true;
    }
  }
  return false;
}
 
int bynary_search(){
  int l=0,r=M;
  while(l<r){
    int m=(l+r)/2;
    if(check(m)){
      r=m;
    }else{
      l=m+1;
    }
  }
  return l;
}
 
int main(){
  std::cin>>n;
  std::cin>>k;
  for(int i=0;i<n;i++){
    std::cin>>w[i];
  }
  std::cout<<bynary_search()<<"\n";
  return 0;
}


Measured memory_bytes: 3496
// B - Echo
// https://atcoder.jp/contests/abc145/tasks/abc145_b
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 3e5 + 5;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 7;

/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if(n % 2 != 0)
  {
    cout << "No" << endl;
  }
  else
  {
    ll idx = n / 2;
    bool flag = true;
    for(int i = 0 ; i < idx ; i++)
    {
      if(s[i] != s[i + idx])
      {
        flag = false;
      }
    }
    if(!flag) cout << "No" << endl;
    else
    {
      cout << "Yes" << endl;
    }
    
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    cin.tie(nullptr);
    // ios::sync_with_stdio(false);
 
    long n;
    cin >> n;
    char s[n];
    // cin >> s;
    scanf("%s", &s);
    long right_e = 0;
    for (long i = 1; i < n; i++) right_e += (s[i] == 'E');
    long min_count = right_e;
    // long left_w = 0;
    for (long i = 1; i < n; i++) {
        if (!min_count) break;
        right_e -= s[i] == 'E';
        right_e += s[i - 1] == 'W';
        min_count = min(min_count, right_e);
    }
    // cout << min_count << endl;
    cout << min_count << '\n';
 
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

vector<string> split(const string &s, char delim) {
    vector<string> result;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            result.push_back(item);
        }
    }
    return result;
}

int main() {
    int n; cin >> n;
    vector<int> L(n + 1); rep(i, n+1) cin >> L[i];

    vector<pair<int64, int64>> tmp(n+1);
    rev(i, n+1) {
        if (i == n) {
            tmp[i].first = L[i];
            tmp[i].second = L[i];
        } else {
            tmp[i].first = L[i] + ceil(tmp[i+1].first/2.0);
            tmp[i].second = L[i] + tmp[i+1].second;
        }
    }

    vector<int64> v(n+1);
    rep(i, n+1) {
        if (i == 0) {
            if (tmp[i].first > 1) {
                cout << -1 << endl;
                exit(0);
            }
            v[i] = 1;
        } else {
            v[i] = min(tmp[i].second, (v[i-1]-L[i-1]) * 2);
        }
    }

    // cout << endl;
    // cout << L << endl;
    // cout << tmp << endl;
    // cout << v << endl;

    int64 ans = 0;
    rep(i, n+1) ans += v[i];
    cout << ans << endl;
}


Measured memory_bytes: 6164
var cnt:Int=0

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    bubbleSort(list.toIntArray(),n)
}
fun bubbleSort(A:IntArray, N:Int)
{
     // N 個の要素を含む 0-オリジンの配列 A
    var flag:Boolean = true// 逆の隣接要素が存在する
    var tmp:Int

    while(flag) {
        flag = false
        for (j in ((N - 1) downTo 1))
        {
            if (A[j] < A[j - 1])
            {
                tmp = A[j - 1]
                A[j - 1] = A[j]
                A[j] = tmp
                flag = true
                cnt++
            }
        }
     }
    println(A.joinToString(" "))
    println(cnt)
}


Measured memory_bytes: 33872
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void) {
    string s;cin>>s;
    bool ans=true;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]=='L')ans=false;
        }
        else{
            if(s[i]=='R')ans=false;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[5][105];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
        cin>>dp[i][j];
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
        dp[i][j]=max(dp[i-1][j],dp[i][j-1])+dp[i][j];
    cout<<dp[2][n]<<endl;
    return 0;
}


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

using namespace std;

int main(){
	int a,b,c;
  	cin >> a >> b >> c;
 
	if(a == b && a != c || b == c && b != a || a == c && a != b)
      cout << "Yes\n";
    else
      cout << "No\n";
  
  	return 0;
}

Measured memory_bytes: 256
// AOJ 2664: Shopping
// 2017.12.3 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 10007
typedef struct { char *s; int id, w; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int w, int id)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (tp->w == w && memcmp(tp->s, s, w) == 0) return;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id, tp->w = w;
}

int lookup(char *s, int w)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (tp->w == w && memcmp(tp->s, s, w) == 0) break;
		if (++tp == hashend) tp = hash;
	}
	return tp->id;
}

#define MAX 5002
/* UNION-FIND library */
int p[MAX], rank[MAX];

void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

int x[MAX];
char s[MAX][12];

char buf[30], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, ans;
	char *q;

	fgets(bp=buf, 10, stdin), n = getint();
	for (i = 0; i < n; i++) p[i] = i;

	for (i = 0; i < n; i++) {
		fgets(bp=buf, 20, stdin);
		q = bp; while (*bp >= 'a') bp++;
		*bp = 0, memcpy(s[i], q, bp-q), insert(s[i], bp-q, i);
		bp++, x[i] = getint();
	}

	fgets(bp=buf, 10, stdin), m = getint();
	while (m--) {
		fgets(bp=buf, 30, stdin);
		q = bp; while (*bp >= 'a') bp++;
		*bp = 0, i = lookup(q, bp-q);

		q = ++bp; while (*bp >= 'a') bp++;
		*bp = 0, j = lookup(q, bp-q);
		union_set(i, j);
	}

	for (i = 0; i < n; i++) find_set(i);
	for (i = 0; i < n; i++) {
		j = p[i];
		if (x[i] < x[j]) x[j] = x[i];
	}

	ans = 0;
	for (i = 0; i < n; i++) ans += x[p[i]];
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

void solve() {
  int a, b, c, d;
  cin >> a;
  d = a % 10;
  a /= 10;
  c = a % 10;
  a /= 10;
  b = a % 10;
  a /= 10;

  if (a + b + c + d == 7)
    cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
  else if (a + b + c - d == 7)
    cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
  else if (a + b - c + d == 7)
    cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
  else if (a + b - c - d == 7)
    cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
  else if (a - b + c + d == 7)
    cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
  else if (a - b + c - d == 7)
    cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
  else if (a - b - c + d == 7)
    cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
  else if (a - b - c - d == 7)
    cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
// atcoder/abc088/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  int n, a;
  while (cin >> n >> a) {
    if (n % 500 <= a) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int A,B,C,K;
  scanf("%d%d%d%d", &A,&B,&C,&K);
  
  int max = A;
  if(A < B)max = B;
  if(max < C)max = C;
  
  int sum = A + B + C - max;
  
  for(int i = 0;i < K;i++){
    max = max * 2;
  }
  sum = sum + max;
  
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
# D
# -*- coding: utf-8 -*-
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans_list = [0 for _ in range(N)]
for i in range(N - 1):
    for j in range(i + 1, N):
        ans_list[min(abs(j - i), abs(X - i) + 1 + abs(j - Y))] += 1

for i in range(1, N):
    print(ans_list[i])

Measured memory_bytes: 3444
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = []
if n > m :
    print(0)
    exit()
for i in range(m-1):
    diff = x[i+1] - x[i]
    y.append(diff)
y.sort(reverse = True)
res = x[-1] - x[0]
for i in range(n-1):
    res -= y[i]
print(res)


Measured memory_bytes: 20428
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        double ans = 0.0;
        for (int i = 0; i < n; i++) {
            ans += (double)1/a[i];
        }
        System.out.println(1/ans);
    }
}


Measured memory_bytes: 21332
#include <stdio.h>

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

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

int main(void)
{
    int a, b;

    while (scanf("%d %d", &a, &b) != EOF){
        printf("%d %d\n", gcd(a, b), lcm(a, b));
    }

    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<unordered_set>
#include<stack>
#include<vector>
#include<deque>
#define mod 998244353
using namespace std;
struct str {
	int idx, cnt;
};
int n, m, k, arr[300010];
int ans[300100];
string s, temp;
map<int, int> mp;
bool chk[30];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		mp[arr[i]]++;
	}
	int sum = 0,ans=0;

	for (auto i = mp.rbegin(); i != mp.rend(); i++) {
		sum += i->second;
		if (sum == n - sum) {
			auto next = i;
			next++;
			ans = i->first - next->first;
			printf("%d", ans);
			return 0;
		}
	}
	printf("0");
	return 0;
}

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

int main()
{
  int A,B,C,a,b,c,K;
  cin >> A >> B>>C>>K;
  for(int i=0;i<=K;i++)
    for(int j=0;j<=K-i;j++)
      for(int s=0;s<=K-i-j;s++){
        a = (i==0)? A : A*pow(2.0,(double)i);
        b = (j==0)? B : B*pow(2.0,(double)j);
        c = (s==0)? C : C*pow(2.0,(double)s);
        if(a<b&&b<c){ cout << "Yes" << endl; return 0; }
      }
  cout << "No" << endl;
}

Measured memory_bytes: 4004
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll dp[MAXN], MOD = MODBASE;

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

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

ll solve(int s) {
    if (dp[s] != -1) return dp[s];
    if (s == 0) return 1;
    ll res = 0;
    FOR(i,3,s) res = add(res, solve(s-i));
    return dp[s] = res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int s;
    cin >> s;
    MS(dp, -1);
    cout << solve(s);
    return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>
int main(void){
	int i,j,l,k,s,cnt;
	scanf("%d %d",&k,&s);
	cnt=0;
	for(i=0;i<=k;i++){
		if(i>s)break;
		for(j=0;j<=k;j++){
			if(i+j>s)break;
			l=s-i-j;
			if(l>=0&&l<=k)cnt++;
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n));
    rep(i, n) rep(j, n) cin >> a[i][j];
    rep(k, n) rep(i, n) rep(j, n) {
        if (a[i][j]>a[i][k]+a[k][j]) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    rep(i, n) rep(j, n) {
        if (i>=j) continue;
        bool flg = false;
        rep(k, n) {
            if (k==i || k==j) continue;
            if (a[i][j]==a[i][k]+a[k][j]) flg = true;
        }
        if (!flg) {
            ans += a[i][j];
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4332
N = int(input())
flg = True
cnt,now,posx,posy=0,0,0,0
while cnt < N and flg:
  t,x,y=map(int,input().split())
  if abs(x-posx)+abs(y-posy) > (t-now):
    flg = False
    print('No')
  elif (t-now)%2==0 and ((abs(x-posx)+abs(y-posy))%2 ==1):
    flg =False
    print('No')
  elif (t-now)%2==1 and ((abs(x-posx)+abs(y-posy))%2 ==0):
    flg =False
    print('No')
  else:
    now = t
    posx = x
    posy = y
    cnt += 1
if flg:
  print('Yes')

Measured memory_bytes: 3064
//abc144A

#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>9||b>9)printf("-1");
  else printf("%d",a*b);
  return 0;
}


Measured memory_bytes: 128
x, y = map(int, input().split())
ans = abs(abs(x) - abs(y))
if y < x:
    if x < 0:
        ans += 2
    elif 0 < y:
        ans += 2
    elif y <= 0 <= x:
        ans += 1
elif x < 0 < y:
    ans += 1
# 0 <= x < y, x < y <= 0のときはansのまま
print(ans)

Measured memory_bytes: 38384
def cost_for_next_a(c):
    return 123 - ord(c)

s = input()
K = int(input())

new_s = ""


for i in range(len(s)):
    c = s[i]
    if i == len(s) - 1:
        if cost_for_next_a(c) <= K:
            new_s += chr(97 + (K - cost_for_next_a(c)) % 26)
        else:
            new_s += chr(ord(c) + K)
    elif c == 'a':
        new_s += 'a'
    elif cost_for_next_a(c) <= K:
        new_s += "a"
        K -= cost_for_next_a(c)
    else:
        new_s += c

print(new_s)


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

int main() {
    int sum_a = 0, sum_b = 0, tmp;
    for (int i = 0; i < 4; i++) {
        cin >> tmp;
        sum_a += tmp;
    }
    for (int j = 0; j < 4; j++) {
        cin >> tmp;
        sum_b += tmp;
    }
    cout << max(sum_a, sum_b) << endl;
}


Measured memory_bytes: 3100
NUM_MAX = 10**5
is_prime = [True] * NUM_MAX
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, NUM_MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, NUM_MAX, i):
            is_prime[j] = False

def solve(n, a):
    def f(m):
        return sum([m % p for p in a])
    D = {}
    for v in a:
        d = {}
        for prime in primes:
            while v % prime == 0:
                v /= prime
                if not prime in d:
                    d[prime] = 0
                d[prime] += 1
        for prime, num in d.items():
            if not prime in D:
                D[prime] = 0
            D[prime] = max(D[prime], num)
    m = 1
    for prime, num in D.items():
        for i in range(num):
            m *= prime
    return f(m-1)

assert solve(3, [3,4,6]) == 10
assert solve(5, [7,46,11,20,11]) == 90
assert solve(7, [994,518,941,851,647,2,581]) == 4527

n = input()
a = map(int, raw_input().split())
print solve(n, a)

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

int main(void){
  int n,x,y;
  scanf("%d %d %d",&n,&x,&y);
  int count[n-1];
  for(int i=0;i<n-1;i++){
    count[i]=0;
  }
  for(int i=1;i<n;i++){
    for(int j=i+1;j<n+1;j++){
      int length = j-i ;
      int xy = abs(x-i)+1+abs(y-j);
      int temp =xy;
      if (temp >length){
        temp =length;
      }
      count[temp-1] +=1;
    }
  }
  for (int i=0;i<n-1;i++){
    printf("%d\n",count[i]);
  }
  return 0;
}


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

using namespace std;

#define ll long long

vector <int> divisor(int n){
    vector<int> vec;
    for(int i = 1;i*i<=n;i++){
        if(n % i == 0){
            vec.push_back(i);
            if(n / i != i){
                vec.push_back(n/i);
            }
        }
    }
    return vec;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
    cin>>n;
    map<int,int> mp;
    int x;
    for(int i = 0;i<n;i++){
        cin>>x;
        mp[x]++;
    }
    int ans = 0;
    for(auto it : mp){
        if(it.second > 1)continue;
        vector<int> v = divisor(it.first);
        sort(v.begin(),v.end());
        v.pop_back();
        bool ok = true;
        for(int j = 0;j<v.size();j++){
            if(mp.find(v[j]) != mp.end()){
                ok = false;
                break;
            }
        }
        if(ok)ans ++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12936
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;

	return 0;
}


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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int N;
	cin >> N;
	int odd = 0;
	REP(i, N)
	{
		int a;
		cin >> a;
		if (a % 2 == 1) { odd++; }
	}

	if (odd % 2 == 0) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 256
integer p(20)
read *,n
read *,(p(i),i=1,n)
k = 0
do i = 2, n-1
   if (p(i-1) < p(i) .and. p(i) < p(i+1)) then
      k = k + 1
   else if (p(i-1) > p(i) .and. p(i) > p(i+1)) then
      k = k + 1
   endif
enddo
print '(i0)',k
end

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define pb push_back
#define fo(i,a,b) for(int i=a;i<b;i++)
#define foe(i,a,b) for (int i=a;i<=b;i++)
ll dp[3000][3000];
ll fundp(int i,int j, ll *a){
    //cout<<i<<" "<<j<<endl;
    if (dp[i][j]!=1000000000000001) return dp[i][j];
    if (i==j)
    dp[i][j]=a[i];
    else
    {
        dp[i][j]=max(a[i]-fundp(i+1,j,a),a[j]-fundp(i,j-1,a));
    }
    return dp[i][j];
    
}
void solve()
{
    int n;
    cin>>n;
    ll a[n];
    fo(i,0,n) cin>>a[i];
    fo(i,0,n){
        fo(j,0,n) dp[i][j]=1000000000000001;
    }
    cout<<fundp(0,n-1,a)<<endl;

}
signed main()
{
   faster;
    //int t;cin>>t;
   // while(t--)
        solve();
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
typedef pair<double,int> id;
int n,m;
double ans;
P a[10000];
vector<int> G[10000];
bool used[10000];

double getl(P a,P b){
  return sqrt((a.f-b.f)*(a.f-b.f)+(a.s-b.s)*(a.s-b.s));
}

void prin(){
  for(int i=0;i<n;i++){
    if(used[i])continue;
    priority_queue<id> q;
    q.push(id(0,i));
    while(!q.empty()){
      id t=q.top();
      q.pop();
      if(used[t.s])continue;
      used[t.s]=1;
      ans-=t.f;
      for(int j=0;j<G[t.s].size();j++)
	q.push(id(getl(a[t.s],a[G[t.s][j]]),G[t.s][j]));
    }   
  }
  printf("%f\n",ans);
}


int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)
    cin>>a[i].f>>a[i].s;
  for(int i=0,p,q;i<m;i++){
    cin>>p>>q;
    p--,q--;
    G[p].push_back(q);
    G[q].push_back(p);
    ans+=getl(a[p],a[q]);
  }
  prin();
  return 0;
}

Measured memory_bytes: 2520
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt(){
		int n = sc.nextInt();
		int cnt = 0;
		while(n > 1) {
			if(n % 10 == 2) cnt++;
			n /= 10;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 23252
import java.util.Scanner;
class Main{
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    for(int i = 0; i < n; i ++) {
      a[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i ++) {
    	b[a[i]- 1] =i;
    }
    for(int i = 0; i < n; i ++) {
      System.out.println(b[i]  + 1);
    }
    
  }
}


Measured memory_bytes: 62368