akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010

int main()
{
  int N,Q;cin>>N>>Q;
  Graph G(N+1);
  for (int i=1;i<=N-1;i++)
  {
    int a,b;cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<ll> cnt(N+1,0);
  for (int i=1;i<=Q;i++)
  {
    int p,x;cin>>p>>x;
    cnt[p]+=x;
  }
  
  vector<ll> dist(N+1,-1);
  queue<ll> q;
  q.push(1);
  dist[1]=0;
  while (!q.empty())
  {
    int v = q.front();
    q.pop();
    for (auto nv : G[v])
    {
      if (dist[nv]!=-1) continue;
      dist[nv]=dist[v]+1;
      cnt[nv]+=cnt[v];
      //cout<<nv<<" "<<v<<endl;
      q.push(nv);
    }
  }
    
  for (int i=1;i<=N;i++)
    cout<<cnt[i]<<" ";
  cout<<endl;
    
}

Measured memory_bytes: 19440
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[199999];
vector<int> v;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N;
    rep(i, 2*N-1) cin >> A[i], v.push_back(A[i]);

    sort(all(v));
    v.erase(unique(all(v)), v.end());

    int l = 0, r = sz(v)-1;
    while(l < r) {
        int mid = (l+r+1)/2, val = v[mid];
        int a = N-1, b = N-1;
        while(a > 0     and (A[a] >= val) != (A[a-1] >= val)) a--;
        while(b < 2*N-2 and (A[b] >= val) != (A[b+1] >= val)) b++;

        if ((A[a] >= val) == (A[b] >= val)) {
            if (A[a] >= val) {
                l = mid;
            } else {
                r = mid-1;
            }
        } else {
            int da = N-1-a;
            int db = b-N+1;

            if ((da > db and A[b] >= val) or (da < db and A[a] >= val)) {
                l = mid;
            } else {
                r = mid-1;
            }
        }
    }

    cout << v[l] << endl;
}

Measured memory_bytes: 1912
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    mt = 10 ** 20
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            mt = min(mt, i + (n // i) - 2)
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll x = (C+B-1)/B;
    ll y = (A+D-1)/D;
    //dump(x)
    //dump(y)

    cout << (x<=y ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#define W 5
int m[99][W];
int main(){
	int H,h,w,i;
	for(;scanf("%d",&H),H;){
		for(h=0;h<H;h++)for(w=0;w<W;w++)scanf("%d",m[h]+w);
		int score=0,score_round=-1,cnt,color;
		for(;score_round;){
			score_round=0;
			for(h=0;h<H;h++){
				cnt=1;
				color=-1; //-1=undefined,0=empty
				for(w=0;w<W;w++){
					if(color==m[h][w])cnt++;
					else{
						if(cnt>=3)for(score_round+=cnt*color,i=w-cnt;i<w;i++)m[h][i]=0;
						cnt=1;
						color=m[h][w];
					}
				}
				if(cnt>=3)for(score_round+=cnt*color,i=w-cnt;i<w;i++)m[h][i]=0;
			}
			for(w=0;w<W;w++){
				for(i=h=H-1;h>=0;h--)if(m[h][w])m[i][w]=m[h][w],i--;
				for(;i>=0;i--)m[i][w]=0;
			}
			score+=score_round;
		}
		printf("%d\n",score);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    string s;
    cin >> s;
    string answer = "";
    repeat (i, s.size()) {
        if (s[i] == ',') {
            answer += ' ';
        } else {
            answer += s[i];
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x;
        string s;
        cin>>s;
        if(s=="SAT")
            x=1;
        else if(s=="SUN")
            x=2;
        else if(s=="MON")
            x=3;
        else if(s=="TUE")
            x=4;
        else if(s=="WED")
            x=5;
        else if(s=="THU")
            x=6;
        else
            x=7;

        if(x==1)
            cout<<1<<endl;
        else
          cout<<(7-x)+2<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int rt[200000],r,n,max,rtmin[200000],i,j;

  scanf("%d",&n);
  for(i=1;i<=n;++i){
    scanf("%d",&rt[i]);
    rtmin[i]=rtmin[i-1];
    if(i==1) rtmin[i]=rt[i];
    else if(rtmin[i]>rt[i]) rtmin[i]=rt[i];
  }
  
  max=rt[2]-rt[1];
  for(i=1;i<n;++i){
    if(rt[i+1]-rtmin[i]>max){
      max=rt[i+1]-rtmin[i];
    }
  }
  printf("%d\n",max);

  return 0;
}



Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();//better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout<<(A + B == C ? "YES" : "NO")<<endl;
//__gcd(a,b)
// string s=to_string(i);
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}
int fact(int n)
{
    if(n==0)
    {
        return 1;
    }
    
        return n*fact(n-1);
    
}

int main(void)
{
    fast();
    int m,n;
    cin>>m>>n;
    int res=0;
    res =  (n)*(n-1)/2 + (m)*(m-1)/2 ;
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int num[3];
  while(n<1000){
    int dummy = n;
    num[0] = dummy%10;
    dummy /= 10;
    num[1] = dummy%10;
    dummy /= 10;
    num[2] = dummy%10;
    if(num[0] == num[1] && num[0] == num[2]){
      cout << n << endl;
      return 0;
    }
    n++;
  }
}

Measured memory_bytes: 256
N = int(input())
m = {
    'S': list(range(1, 14)),
    'H': list(range(1, 14)),
    'C': list(range(1, 14)),
    'D': list(range(1, 14))
}
for i in range(N):
    shape, num = input().strip().split(' ')
    num = int(num)
    m[shape].remove(num)
for k in ['S', 'H', 'C', 'D']:
    if len(m[k]) > 0:
        for x in m[k]:
            print('%s %d' % (k, x))

Measured memory_bytes: 7748
A=[]
B=[]
for i in range(3):
    a1,a2,a3=input().split()
    A.append([int(a1),int(a2),int(a3)])

N=int(input())
for i in range(N):
    B.append(int(input()))

    
ans="No"

for i in range(3):
	if B.count(A[0][0])* B.count(A[0][1])* B.count(A[0][2])!=0\
or  B.count(A[1][0])* B.count(A[1][1])* B.count(A[1][2])!=0\
or  B.count(A[2][0])* B.count(A[2][1])* B.count(A[2][2])!=0\
or  B.count(A[0][0])* B.count(A[1][0])* B.count(A[2][0])!=0\
or  B.count(A[0][2])* B.count(A[1][2])* B.count(A[2][2])!=0\
or  B.count(A[0][1])* B.count(A[1][1])* B.count(A[2][1])!=0\
or  B.count(A[0][0])* B.count(A[1][1])* B.count(A[2][2])!=0\
or  B.count(A[0][2])* B.count(A[1][1])* B.count(A[2][0])!=0:
		ans="Yes"
    
print(ans)
    


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll a,b;cin>>a>>b;
	ll ans=max(a,b)+max(a,b)-1;
	if(a==b)cout<<2*a;
	else
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
  print(X - K * D)
elif X == D:
  if K % 2 == 0:
    print(X)
  else:
    print(abs(X - D)) 
else:
  K -=  X // D
  X = X % D
  if K % 2 == 0:
    print(X)
  else:
    print(abs(X - D))
    


Measured memory_bytes: 9128
n = int(input())
s_list = list(map(int, input().split()))

s_max = max(s_list)
s_min = min(s_list)

# print('s_max')
# print(s_max)
# print('s_min')
# print(s_min)

j = s_min
k = 0
sum_testcase = 0

kingnum = 1000000

# リスト中の最小値から最大値まで全部回してみる
while j <= s_max :

    # print('[j]')
    # print(j)

    sum_testcase = 0
    k = 0

    # リストの中身を1要素ずつ計算
    while k < len(s_list) :

        # print('s_list[k]')
        # print(s_list[k])

        temp =  (s_list[k] - j) * (s_list[k] - j)
        
        # print('[temp]')
        # print(temp)
        
        k = k + 1
        sum_testcase = sum_testcase + temp

    # 答えが最小なら更新
    if sum_testcase < kingnum :
        kingnum = sum_testcase

    # print('[kingnum]')
    # print(kingnum)

    j = j + 1

print(kingnum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k, c = 0;
	vector<int> a(3);
	for(int i = 0; i < 3; i++) cin >> a[i];
	cin >> k;
	for(int i = 1; i < 3; i++) while(a[i] <= a[i - 1])
	{
		a[i] *= 2;
		c++;
	}
	cout << (c <= k ? "Yes" : "No");

	return 0;
}

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

int main(){
    int num;
    cin >> num;
    for(int ii=0; ii<num; ii++){
        // 文字列の受け取り
        string s, t;
        cin >> s >> t;
        int n = s.size(), m = t.size();

        // DPテーブルの準備
        int dp[n+1][m+1] = {};
        //dp[0][0] = 0;

        // DPテーブルを更新
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
                else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }

        // 答えの出力
        cout << dp[n][m] << endl;
    }
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    int ans = 0;
    rep(i,n) {
        ans += a.at(i);
    }
    ans -= n;

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

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<long double> A(N);
    REP(i, N) cin >> A[i];
    long double sum = 0;
    REP(i, N) {
        sum += (long double)1.0 / A[i];
    }
    long double ans = (long double)1.0 / sum;
    printf("%Lf\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>

int func(int a,int b){
  for(int l=0;l<b;l++){
    a=a*2;
  }
  return a;
}

int main(){
  int A,B,C,K,x;
  scanf("%d %d %d",&A,&B,&C);
  scanf("%d",&K);
  x=((A>=B)&&(A>=C))*(func(A,K)+B+C)+((B>A)&&(B>C))*(func(B,K)+A+C)+((C>A)&&(C>B))*(func(C,K)+A+B);
  printf("%d",x);
  return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def main():
  U = 2*10**6+2
  MOD = 10**9+7

  fact = [1]*(U+1)
  fact_inv = [1]*(U+1)

  for i in range(1,U+1):
      fact[i] = (fact[i-1]*i)%MOD
  fact_inv[U] = pow(fact[U], MOD-2, MOD)

  for i in range(U,0,-1):
      fact_inv[i-1] = (fact_inv[i]*i)%MOD

  def comb(n, k):
      if k < 0 or k > n:
          return 0
      z = fact[n]
      z *= fact_inv[k]
      z *= fact_inv[n-k]
      z %= MOD
      return z

  ans = 0
  r1, c1, r2, c2 = map(int, input().split())
  for i in range(c1, c2+1):
    ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  print(ans%MOD)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 163316
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, T; cin >> N >> T;

    map<ll, ll> mp;

    ll mn = INF;
    ll mx = -1;

    for(ll i = 0; i < N; i++){
        ll a; cin >> a;
        if(mn > a){
            mn = a;
        }
        if(mx < a-mn){
            mx = a-mn;
        }
        mp[a-mn]++;
    }


    cout << mp[mx] << endl;

}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  rep(i, h){
    rep(j, w){
      if(s[i][j] == '#')  continue;
      int count = 0;
      for(int left = -1; left <= 1; ++left){
        for(int up = -1; up <= 1; ++up){
          if(i + left >= 0 && i + left < h && up + j >= 0 && up + j < w && s[i + left][j + up] == '#'){
            count++;
          }
        }
      }
      s[i][j] = '0' + count;
    }
  }
  rep(i, h) cout << s[i] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
     int sum1=0;
     sort(a,a+n);
     for(int i=0; i<n; i++)
     {
         sum1=sum1+a[i];
     }
     int avg=(sum1/n);
     int rem=sum1%n;
     int p;
     if(rem>(n/2))
        p=avg+1;
     else
        p=avg;
     int sum=0;
     for(int i=0; i<n; i++)
     {
         sum=sum+(a[i]-p)*(a[i]-p);
     }
     cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c;
  char x[11];
  char y[11];
  char z[11];
  scanf("%s",x);
  scanf("%s",y);
  scanf("%s",z);
  for(a=0;x[a]!='\0';a++);
  for(b=0;y[b]!='\0';b++);
  for(c=0;z[c]!='\0';c++);
  if((x[a-1]==y[0])&&(y[b-1]==z[0])){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL dp[MAXN], odds[MAXN];

int main(){
  fio();
  int n; cin>>n;
  vector<LL> v(n);
  forn(i,n) cin>>v[i];
  forn(i,n) odds[i] = ( i%2 || i<2 ?0:odds[i-2]) + v[i];
  dp[1] = max(v[0],v[1]);
  for(int i=1;i<n;i++)
  	dp[i] = max(dp[i-2]+v[i], i%2?odds[i-1]:dp[i-1]);
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 7920
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const long long inf = (long long)(2e18) + 322;
const int mod = (int)(1e9) + 7; // check modulo


void solve() {
    int n; cin >> n;
    string s; cin >> s;
    int allw = 0, allr = 0;
    for(auto i : s) {
        if (i == 'R') allr++;
        else allw++;
    }
    int r = 0, w = 0;
    int mn = inf;
    for(int i = 0; i <= sz(s); ++i) {
        mn = min(mn, abs((allr - r) - w) + min(w, (allr - r)));
        if (i == sz(s)) continue;
        if (s[i] == 'R') r++;
        else w++;
    }
    cout << mn;
}

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

    int test = 1;//  cin >> test;
    for(int t = 1; t <= test; ++t) {
        solve();
    }
    return 0;
}



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

int main() {
	// your code goes here
	int n;
	while(cin>>n){
	int count=0;
		for(int i=9; i>=0; i--){
			for(int j=9; j>=0; j--){
				for(int k=9; k>=0; k--){
					for(int l=9; l>=0; l--){
						if(i+j+k+l==n)count++;
					}
				}
			}
		
	
	}
	cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t =[input() for _ in range(m)]
sc=Counter(s)
tc=Counter(t)
u=list(set(s)&set(t))
ans=0
for i in u:
    ans=max(ans,max(0,sc[i]-tc[i]))
v=list(set(s)-set(u))
for i in v:
    ans=max(ans,sc[i])
print(ans)

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

using namespace std;
typedef long long ll;


#define MAX 200001
ll a[MAX], hs[MAX], c[MAX];

int ask(int x) {
    int t = 0;
    for(; x; x-=x&-x) t += c[x];
    return t;
}

void add(int x, int N) {
    for(; x<MAX; x+=x&-x) c[x]++;
}

int main(void) {
    int N, K;
    scanf("%d%d", &N, &K);
    a[0] = hs[0] = 0;
    for(int i=1; i<=N; i++) {
        scanf("%d", a+i);
        hs[i] = a[i] += a[i-1] - K; 
        
    }
    sort(hs, hs+N+1);
    for(int i=0; i<=N; i++) a[i] = lower_bound(hs, hs+N+1, a[i]) - hs + 1;
    ll ans = 0;
    for(int i=0; i<=N; i++) {
        ans += ask(a[i]);
        add(a[i], N);
    }

    return !printf("%lld\n", ans);
}

Measured memory_bytes: 4992
import scala.math.min

object Main {
    def main(args: Array[String]) {
        var input = io.Source.stdin.getLines().mkString("\n");
        var ss = input.split("\n").toList;
        val s = ss(0);
        println(if (s(0) == s(1) || s(1) == s(2) || s(2) == s(3)) "Bad" else "Good");
    }
}


Measured memory_bytes: 27300
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int H, W;
    int h, w;
 
    while (1) {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0) break;
         
        for (w = 0; w < W; w++) putchar('#');
        putchar('\n');
 
        for (h = 2; h < H; h++) {
            putchar('#');
            for (w = 2; w < W; w++) putchar('.');
            putchar('#');
            putchar('\n');
        }
 
        for (w = 0; w < W; w++) putchar('#');
        putchar('\n');
 
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2492
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        q_1();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }
}

Measured memory_bytes: 23124
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        a:i64,b:i64,k:i64
    }

    if a <= k {
        let k = k - a;
        let a = 0;
        let b = max(b - k, 0);
        println!("{} {}", a, b);
    } else {
        let a = a - k;
        println!("{} {}", a, b);
    }
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}
//x^n mod m (nが負の時は０)
long myPow(long x, long n, long m){
  if(n<0)return 0;
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
const int N_MAX=(1e5)+1;
long int n,a[3],s[N_MAX];
string tem[3]={"AB","AC","BC"};
pair<int,int> ch[3]={pair<int,int>(0,1),pair<int,int>(0,2),pair<int,int>(1,2)};
char res[N_MAX];
char key[3]={'A','B','C'};

int main(){
    long int i=0;
    string x;
    //入力
    cin>>n>>a[0]>>a[1]>>a[2];
    rep(i,n){
        cin>>x;
        rep(j,3){
            if(tem[j]==x){
                s[i]=j;
                break;
            }
        }
    }
    //処理
    i=0;
    long sum=a[0]+a[1]+a[2]; 
    if(sum==0){
        cout<<"No"<<endl;
        return 0;
    }else{
        while(i<n&&a[ch[s[i]].first]+a[ch[s[i]].second]>0){
            if(i<n-1&&a[ch[s[i]].first]==1&&a[ch[s[i]].second]==1){
                if(ch[s[i+1]].first==ch[s[i]].first||ch[s[i+1]].second==ch[s[i]].first){
                    a[ch[s[i]].first]++;
                    a[ch[s[i]].second]--;
                    res[i]=key[ch[s[i]].first];
                }else{
                    a[ch[s[i]].first]--;
                    a[ch[s[i]].second]++;
                    res[i]=key[ch[s[i]].second];
                }
            }else{
                if(a[ch[s[i]].first]>=a[ch[s[i]].second]){
                    a[ch[s[i]].first]--;
                    a[ch[s[i]].second]++;
                    res[i]=key[ch[s[i]].second];
                }else{
                    a[ch[s[i]].first]++;
                    a[ch[s[i]].second]--;
                    res[i]=key[ch[s[i]].first];
                }
            }
            i++;
        }
    }
    if(i<n){
        cout<<"No"<<endl;
        return 0;
    }
    //出力
    cout<<"Yes"<<endl;
    rep(i,n){
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 4624
#include <iostream>
#include <algorithm>

using namespace std;

int main( void )
{
	int n, m, a;
	char map[1001][101];
	while(cin>> n >> m >> a, n | m | a) {
		for(int y=1; y < 1001; ++y)
			for(int x=1; x <= n; ++x)
				map[y][x] = 0;
		int Maxh = 0;
		for(int i=0; i < m; ++i) {
			int h, p, q;
			cin >> h >> p >> q;
			map[h][p] = q;
			map[h][q] = p;
			Maxh = max(Maxh, h);
		}
		for(int i=Maxh; i > 0; --i) {
			if(map[i][a]) {
				a = (int)map[i][a];
			}
		}
		cout << a << endl;
	}
	return 0;
}

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

typedef long long ll;

#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

int main() {
    int N; cin >> N;
    ll a[300100]; FOR(i, 0, 3 * N) cin >> a[i];

    priority_queue<ll, vector<ll>, greater<ll>> pque_front;
    priority_queue<ll> pque_back;

    ll sum1i= 0, sum2i = 0;

    FOR(j, 0, N) {
        sum1i += a[j];
        pque_front.push(a[j]);
    }

    FOR(j, 2 * N , 3 * N) {
        sum2i += a[j];
        pque_back.push(a[j]);
    }

    ll sum1[300100], sum2[300100];

    sum1[N - 1] = sum1i;
    sum2[2 * N] = sum2i;

    ll ans = sum1i - sum2i;

    FOR(j, N , 2 * N ){
        sum1[j] = sum1[j - 1] + a[j];
        pque_front.push(a[j]);
        sum1[j] = sum1[j] - pque_front.top();
        pque_front.pop();
        
        sum2[3 * N - 1 - j] = sum2[3 * N - j] + a[3 * N - 1 - j];
        pque_back.push(a[3 * N - 1 - j]);
        sum2[3 * N - 1 - j] = sum2[3 * N - j - 1] - pque_back.top();
        pque_back.pop();
    }
    
    FOR(j, N - 1 , 2 * N ){
        ll sum = sum1[j] - sum2[j + 1];
        ans = max(ans, sum);
    }


    printf("%lld\n", ans);

}


Measured memory_bytes: 8820
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0l;
        if(n >= m) {
            ans = m / 2;
        } else {
            long tmp1 = m - (n * 2);
            if(tmp1 < 4) {
                ans = n;
            } else {
                long tmp2 =  tmp1 / 4;
                ans = n + tmp2;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35680
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

var m map[string]int = make(map[string]int)
var mInt map[int]int = make(map[int]int)

func reverseMatch(s []string) bool {
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	s := next()
	slice := strings.Split(s, "")
	extra := 0
	if len(slice)%2 == 0 {
		extra = 1
	}
	if !reverseMatch(slice) {
		fmt.Fprint(out, "No")
		return
	}
	if !reverseMatch(slice[0 : (len(slice)-1)/2+extra]) {
		fmt.Fprint(out, "No")
		return
	}
	if !reverseMatch(slice[(len(slice)+3)/2-1 : len(slice)]) {
		fmt.Fprint(out, "No")
		return
	}
	fmt.Fprint(out, "Yes")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n,a,b,ar[1005][1005];
double ans;

int main()
{
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; ++i)
	{

		for (int j = 0; j < 2; ++j)
		{
			cin >> ar[i][j];
		}
	}

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			ans += sqrt((ar[i][0] - ar[j][0]) * (ar[i][0] - ar[j][0]) + (ar[i][1] - ar[j][1]) * (ar[i][1] - ar[j][1]));
      // cout << i << " " << j << " = " << ans << " = " << (ar[i][0] - ar[j][0]) * (ar[i][0] - ar[j][0]) + (ar[i][1] - ar[j][1]) * (ar[i][1] - ar[j][1]) << endl;
		}
	}
  // cout << ans << "\n";
	printf("%.8lf",1.0*ans/n);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n),b(n);
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
		chmax(ans,a[i]);
	}
	sort(all(a),greater<ll>());
	rep(i,n){
		if(a[0]==b[i]){
			cout<<a[1]<<endl;
		}else{
			cout<<ans<<endl;
	}
	
	}
}

Measured memory_bytes: 4736
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N), sub4(3);
    fill(sub4.begin(), sub4.end(), 0);
    for(int i=0; i<N; i++){
        cin >> a[i];
        if(a[i]%4==0) sub4[2]++;
        else if(a[i]%2==0) sub4[1]++;
        else sub4[0]++;
    }
    if(sub4[1]==0) sub4[1]=1;
    N-=sub4[1]-1;
    if(N/2<=sub4[2]) cout << "Yes";
    else cout << "No";

    
    return 0;
}

Measured memory_bytes: 640
N=int(input())
S=input()
X=[1 if s=='W' else 0 for s in S]
import itertools
cumsumW = list(itertools.accumulate([0]+X))
ans=N
for i in range(1,N+1):
  _=cumsumW[i-1]+(N-i)-(cumsumW[-1]-cumsumW[i])
  if _<ans:
    ans=_
print(ans)

Measured memory_bytes: 20256
S = input()
S = S[::-1]

l = ['maerd','remaerd','esare','resare']
i = 0
while i < len(S):
    for w in l:
        if w == S[i:i+len(w)]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 3188
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int k = sc.nextInt();
      int x = sc.nextInt();
      for(int i = 1;i <= 2*k-1;i++){
      	System.out.println(x-k+i);
      }
    }
}


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

using ll = long long;
static const int MAX = 1e5;
static const ll MOD = 1e9 + 7;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> G[MAX], color(MAX);
vector<ll> white(MAX), black(MAX);
// main関数からこれらを削除すること

ll dfs(int u) {
  color[u] = 1; // GRAY
  ll keepb = 1, keepw = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (color[v] == 0) {
      dfs(v);
      keepb *= white[v];
      keepw *= (white[v] + black[v]);
      keepb %= MOD;
      keepw %= MOD;
    }
  }
  color[u] = 2; // BLACK
  black[u] = keepb;
  white[u] = keepw;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  dfs(0);
  
  cout << (black[0] + white[0]) % MOD << '\n';
}

Measured memory_bytes: 14592
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextLong()
    val H = scanner.nextLong()
    val aList = arrayListOf<Long>()
    val bList = arrayListOf<Long>()
    var count: Long = 0
    (1..N).forEach {
        aList.add(scanner.nextLong())
        bList.add(scanner.nextLong())
    }
    val max = aList.max()!!
    val filterList = bList.filter { it > max }.sorted().reversed()
    var hitpoint=H
    for (it in filterList) {
        hitpoint-=it
        count++
        if(hitpoint<=0){
            println(count)
            return
        }
    }
    count+=hitpoint/max
    hitpoint%=max
    if(hitpoint>0)count++
    println(count)
}


Measured memory_bytes: 79308
#include<iostream>
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main() {
	int n, i;
	int a[22], b[51], c[51];//a 料理番号 b 満足度 c ボーナス
	cin >> n;
	rep(i, n) cin >> a[i + 1];
	rep(i, n) cin >> b[i + 1];
	rep(i, n - 1) cin >> c[i + 1];

	int ans = 0;
	for (i = 1; i <= n; i++) {
		ans += b[a[i]];
		if (i >= 2) {
			int tempDish = a[i];
			int prevDish = a[i - 1];
			//if (a[i - 1] + 1 == a[i]) ans += c[a[i - 1]];
			if (tempDish == prevDish + 1) {
				ans += c[a[i - 1]];
				//cout << "prev" << prevDish << " tempdish " << tempDish << endl;
				//cout << "bonus" << a[i - 1] << endl;

			}
			
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc175/tasks/abc175_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll X, K, D;
  cin >> X >> K >> D;

  ll cur = abs(X);

  ll to_positive_min_ct = cur / D;

  if (K <= to_positive_min_ct) {
    cur -= K * D;
    drop(cur);
  }

  cur -= to_positive_min_ct * D;
  ll rest = K - to_positive_min_ct;

  if (rest % 2 == 1) {
    cur -= D;
  }

  ll res = abs(cur);
  cout << res << "\n";
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		/*
		String s = sc.next();
		String[] ss = s.split("");
		boolean check = false;
		for(int i =0;i<3;i++) {
			if(ss[i].equals("7"))check=true;
		}
		if(check) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		*/
		int n = sc.nextInt();
		long sum = 0;
		for(int i=0;i<n+1;i++) {
			if(i%3!=0) {
				if(i%5!=0)sum+=i;
			}
		}
		System.out.println(sum);
	}





}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 35764
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}
int n,m;



int main()
{      
  fastio();
  int i,j,t;
  cin>>n>>m;
  vector<pair<LL,LL>> objs(n);
  for(i=0;i<n;i++)
  {
  	cin>>objs[i].first>>objs[i].second;
  }
  sort(objs.begin(),objs.end());
  LL c=0,p=0;
  for(i=0;i<n;i++)
  {
  	if(c+objs[i].second>=m)
  	{
  		p+=(m-c)*objs[i].first;
  		break;
  	}
  	else
  	{
  		c+=objs[i].second;
  		p+=objs[i].first*objs[i].second;
  	}
  }

  cout<<p;
  return 0;
}

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

int main() {
	long long n,a,b,x,ans,mx;
	cin>>a>>b>>n;
	if(n>=b-1){
	    x=b-1;
	    ans=(a*x-(a*x)%b)/b;
	}
	else{
	    mx=((a*n)/b)*b;
	    x=((mx-1)/a+1)*a;
	    ans=max((a*(x%b)-(a*x)%b)/b,(a*(n%b)-(a*n)%b)/b);
	}
	cout<<ans;
	return 0;
}

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

void chmin(int &x, int y) { x = min(x, y); }

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

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

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

  int ans = 1e9;
  for (int i = 0; i <= n - k; i++) {
    chmin(ans, h[i + k - 1] - h[i]);
  }

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

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = 998244353;
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (200000 + 2)

#define MAX_FACT 1000000
ll facts[MAX_FACT + 5];
void makeFacts(int n){
  facts[0] = 1;
  for (int i = 1; i < n + 1; i++){
    facts[i] = i * facts[i-1] % MOD;
  }
}

// a x + b y = gcd(a, b)
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

// 1/a mod m
ll mod_inverse(ll a){
  ll x, y;
  extgcd(a, MOD, x, y);
  return (MOD + x % MOD) % MOD;
}

int fcomb(int n, int k){
  ll l = 1, c = 1, ans;
  if(n < k) return 0;
  if(n - k < k) k = n - k;
  ans = facts[n];
  ans = ans * mod_inverse(facts[k]) % MOD;
  ans = ans * mod_inverse(facts[n - k]) % MOD;
  return (int)ans;
}

//modを引数にとるバージョン

//n**p % m
int _powMod(int n, int p, int m){
  ll ans = 1, ln = n;
  if(p <= 0) return 1;
  while(p != 0){
	if((p & 1) == 1) ans = (ans*ln) % m;
	ln = (ln * ln) % m;
	p = p >> 1;
  }
  return (int)ans;
}

// 隣り合うブロックの組で、色が違うのがK組
ll getDiffK(ll n, ll m, ll k) {
  ll tmp = fcomb(n - 1, k);
  ll colors = m * _powMod(m - 1, k, MOD) % MOD;

  // printf("getDiffK(%lld, %lld, %lld) = %lld, tmp = %lld, colors = %lld\n", n, m, k, (tmp * colors) % MOD, tmp, colors);
  return (tmp * colors) % MOD;
}

void exec(){
  ll n, m, k;
  cin >> n >> m >> k;
  makeFacts(n + 1);

  ll ans = 0;

  for (int i = 0; i <= k; i++){
    ans = (ans + getDiffK(n, m, n - 1 - i)) % MOD;
  }

  cout << ans << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 5196
import math
import queue
import bisect
import heapq

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def main():
    n = int(input())
    a = [x for x in map(int,input().split())]
    A = []
    for i in range(1,n+1):
        A.append([a[i-1],i])
    A.sort()
    for i in range(n):
        print(A[i][1])
    return

if __name__ == '__main__':
    main()

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

int main()
{
    int n;
    int sum = -1;
    cin >> n;
    int a[2][100];
    for(int i = 0; i < n; i++) cin >> a[0][i];
    for(int i = 0; i < n; i++) cin >> a[1][i];
    for(int i = 0; i < n; i++){
        int temp = 0;
        for(int j = 0; j <= i; j++) temp += a[0][j];
        for(int j = i; j < n; j++) temp += a[1][j];
        sum = max(sum, temp);
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256