akhauriyash/Code-Regression huggingface dataset:
from collections import deque

N = int(input())

CSFs = [list(map(int, input().split())) for _ in range(N-1)]

h = deque([0])

for i in range(N-2,-1,-1):
  t = CSFs[i][1]
  t += CSFs[i][0]
  for j in range(i+1,N-1):
    if t < CSFs[j][1]:
      t = CSFs[j][1]
    else:
      if t%CSFs[j][2] > 0:
        t += CSFs[j][2] - (t%CSFs[j][2])
    t += CSFs[j][0]
  h.appendleft(t)
  
while h:
  print(h.popleft())

Measured memory_bytes: 68832
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    vector<int> dx, dy;
    int cntF = 0, cntT = 0;
    for(char c : s) {
        if(c == 'F')
            cntF++;
        else {
            if(cntT == 0)
                x -= cntF;
            else if(cntF)
                (cntT & 1 ? dy : dx).push_back(cntF);
            cntT++;
            cntF = 0;
        }
    }
    if(cntT == 0)
        x -= cntF;
    else if(cntF)
        (cntT & 1 ? dy : dx).push_back(cntF);

    bitset<40000> X, Y;
    X.set(20000);
    Y.set(20000);
    for(int i : dx)
        X = (X << i) | (X >> i);
    for(int i : dy)
        Y = (Y << i) | (Y >> i);

    cout << (X[20000 + x] && Y[20000 + y] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <ios>
#include <iomanip>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define setp(x) setprecision(x)
using ll = long long;
using ull = unsigned long long;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];

	int mx = 0, smx = 0;
	vector<int> b(n);
	b = a;
	SORT(b);
	rev(b);
	mx = b[0]; smx = b[1];
	if (mx == smx) {
		for (auto& x : a) cout << mx << endl;
		return 0;
	}
	else {
		for (auto& x : a) {
			if (x == mx) cout << smx << endl;
			else cout << mx << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
void solve(std::istream &in, std::ostream &out);
 
int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

void solve(std::istream &in, std::ostream &out) {
  int n, k;
  in >> n >> k;
  if (k > n * (n - 1) / 2 - (n - 1)) {
    out << -1 << '\n';
  } else {
    int edges_to_add = (n - 1) * (n - 2) / 2 - k;
    out << n - 1 + edges_to_add << '\n';
    for (int i = 2; i <= n; ++i) {
      out << 1 << ' ' << i << '\n';
    }
    if (edges_to_add > 0)
    for (int i = 2; i <= n; ++i) {
      for (int j = i + 1; j <= n; ++j) {
        out << i << ' ' << j << '\n';
        if (--edges_to_add == 0) {
          return;
        }
      }
    }
  }
}
 


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  	if (A * B > C * D) {
      cout << A * B << endl;
    }
  	else if (A * B < C * D) {
      cout << C * D << endl;
    }
  	else {
      cout << A * B << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		char[] map = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
				.toCharArray();
		Scanner in = new Scanner(System.in);
		int count;
		while ((count = in.nextInt()) != 0) {
			int[] key = new int[count];
			for (int i = 0; i < count; i++) {
				key[i] = in.nextInt();
			}
			char[] ango = in.next().toCharArray();
			for (int i = 0; i < ango.length; i++) {
				int posi;
				if ('a' <= ango[i] && ango[i] <= 'z') {
					posi = ango[i] - 'a' + 52;
				} else {
					posi = ango[i] - 'A' + 78;
				}
				posi -= (key[i % count]);
				ango[i] = map[posi % 52];
			}
			System.out.println(new String(ango));
		}
	}
}

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

#define all(n) n.begin(),n.end()
#define ll long long

#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>

#define ff first
#define ss second

using namespace std;
const ll maxn=1e6+2;
const ll maxx=1e16;
const ll mod=998244353;
const ll mod1=998244353;

vector<ll>  ans[maxn];

ll a[maxn];
ll b[maxn];
ll f[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("TEAMS.INP","r"))
    {
        freopen("TEAMS.INP", "r", stdin);
        freopen("TEAMS.OUT", "w", stdout);
    }
    ll n, m, k;
    multiset<ll> st;
     cin>>n>>m>>k;
     for (int i=1;i<=n;i++)
     {
          cin>>a[i];
         f[i]=f[i-1]+a[i];

     }
     ll ans=0;
     ll nw=0;
     for (int j=1;j<=m;j++)
     {

       cin>>b[j];
     }
     for (int j=0;j<=m;j++)
     {
         ll mx=j;
         nw+=b[j];
         if (nw>k)
         {
             break;
         }
         else
         {
             ll cl=k-nw;
             ll p= upper_bound(f+1,f+n+1,cl)-f-1;
            // cout <<p<<" "<<cl<<endl;
             mx+=p;
             ans=max(ans,mx);
         }
     }
     cout <<ans<<endl;




}


Measured memory_bytes: 31812
#include <iostream>
#include <set>

using namespace std;

int main() {
  int tt;
  set <int> inthis;
  cin >> tt;
  for (int qq = 1; qq <= tt; ++qq) {
    int t;
    cin >> t;
    inthis.insert(t);
  }
  if (inthis.size() == tt) cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 9600
process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ！！

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const N = lines[0]-0;
    const ansmap = {};
    const limit = Math.sqrt(N);
    for(let x=1;x<limit;x++)
    for(let y=1;y<limit;y++)
    for(let z=1;z<limit;z++){
        const a = x*x+y*y+z*z+x*y+x*z+y*z;
        ansmap[a] = (ansmap[a]||0)+1;
    }
    for(let i=1;i<=N;i++){
      console.log(ansmap[i]||0);
    }
});


Measured memory_bytes: 38020
N = int(input())
l = [int(i) for i in input().split()]


count = 0

def div(l):
    for i in range(len(l)):
        l[i] = l[i]/2

    return l

def checkOdd(l):
    for num in l:
        if num % 2 == 1:
            return True

    return False


while 1:
    if checkOdd(l) == True:
        break

    l = div(l)
    count = count + 1


print(count)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    if (N % 1000 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1000 - N % 1000 << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            string ans = str[1] + str[0];
            Console.WriteLine(ans);
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


Measured memory_bytes: 13140
n = int(input())
ktb = []
error = 0
for i in range(n):
    ktb.append(list(input()))
    if i != 0:
        if ktb[i - 1][-1] != ktb[i][0]:
            error = 1
        for j in range(i - 1):
            if ktb[i] == ktb[j]:
                error = 1
                break
if error == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<tuple>
using namespace std;
#define ll long long
#define NMAX 1000
#define MMAX 2000
#define INF 1e+16
struct P{
  int from;
  int to;
  int cost;  
};
ll d[NMAX+1];
bool flag[NMAX+1]={};
vector<P> e;
int n, m;
int loop_cnt = 0;
ll ans;

void bellman_ford(int s){
  for(int i=1; i<=n; i++)
    d[i] = -INF;
  d[s] = 0;
  for(int l=0;l<n-1;l++){
    bool update = false;
    for(int i=0;i<m;i++){
      P edge = e[i];
      if(d[edge.from] != -INF && d[edge.to] < d[edge.from] + edge.cost){
        d[edge.to] = d[edge.from] + edge.cost;
        update = true;
      }
    }
    if(!update) break;
  }
  ans = d[n];
  for(int l=0;l<n;l++){
    bool update = false;
    for(int i=0;i<m;i++){
      P edge = e[i];
      if(d[edge.from] != -INF && d[edge.to] < d[edge.from] + edge.cost){
        d[edge.to] = d[edge.from] + edge.cost;
        flag[edge.to] = true;
        if(flag[edge.from]) flag[edge.to]=true;
      }
    }
    if(!update) break;
  }
}

int main(){
  cin >> n >> m;
  int a, b, c;
  for(int i=0; i<m; i++){
    P tp;
    cin >> tp.from >> tp.to >> tp.cost;
    e.push_back(tp);
  }
  bellman_ford(1);
  if(flag[n]) cout << "inf" << endl;
  else cout << ans << endl;
  return 0;
}

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

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

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

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct task {
    ll duration, deadline, start, index;
};

bool operator<(const task& x, const task& y)
{
    if(x.deadline != y.deadline) return x.deadline < y.deadline;
    else return x.duration < y.duration;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    vector<task> S(N);
    REP(i, N){
        cin >> A[i] >> B[i];
        S[i] = task{A[i], B[i], B[i] - A[i], i};
    }

    sort(S.begin(), S.end());
    ll now = 0;
    REP(i, N) {
        task s = S[i];
        if(s.start < now) {
            cout << "No" << endl;
            return 0;
        } else {
            now += s.duration;
        }
    }
    
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 9600
n = int(input())
A = [a for a in input().split(" ")]

if n == 1:
  print(A[0])
else:
  odd = A[::2]
  even = A[1::2]
  if n % 2 == 0:
    even.reverse()
    print(" ".join(even + odd))
  else:
    odd.reverse()
    print(" ".join(odd + even))

Measured memory_bytes: 29980
from math import ceil
N, H = map(int, input().split())
B = []
maxa = 0
cnt = 0

for i in range(N):
  a,b = map(int, input().split())
  maxa = max(maxa,a)
  B.append(b)

B.sort(reverse=True)

for i in range(N):
  if B[i] < maxa:
    break
  cnt += 1
  H -= B[i]
  if H <= 0:
    print(cnt)
    exit(0)

cnt += ceil(H / maxa)

print(cnt)

Measured memory_bytes: 7404
H, W = map(int, input().split())
S = [input() for _ in range(H)]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
for y in range(H):
    for x in range(W):
        if S[y][x] != '#':
            continue

        for i in range(4):
            if y + dy[i] < 0 or H <= y+dy[i] or x + dx[i] < 0 or W <= x+dx[i]:
                continue
            if S[y + dy[i]][x + dx[i]] == '#':
                break
        else:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 39408
#include <iostream>
using namespace std;
typedef long long ll;
ll n,N;
int main(void){
    cin>>n;
    cout<<50<<endl;
    N=n%50;
    for(int i=0;i<(50-N);i++){
        cout<<49-N+n/50<<" ";
    }
    for(int i=0;i<N;i++){
        cout<<100-N+n/50<<" ";
    }
    cout<<endl;
}


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

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

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int>> keys(M);
	rep(i, M) {
		int a, b; cin >> a >> b;
		keys[i].push_back(a);
		rep(j, b) {
			int c; cin >> c;
			keys[i].push_back(c);
		}
	}
	vector<vector<int>> dp(M + 1, vector<int>((1 << N) + 1, INF));
	dp[0][0] = 0;

	rep(i, M) {
		int num = 0;
		rep(j, keys[i].size() - 1) {
			num += pow(2, keys[i][j + 1] - 1);
		}
		rep(j, 1 << N) {
			// 既に[i+1][j]に値が入っていることがあるので、自身と比較する
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j | num] = min(dp[i + 1][j | num], dp[i][j] + keys[i][0]);
		}
	}
	int ans = dp[M][(1 << N) - 1];
	if (ans < INF)cout << dp[M][(1 << N) - 1];
	else cout << -1;
}


Measured memory_bytes: 16384
#include <iostream>

using namespace std;

int main() {
    int i,a,b,c;
    for(i=1;i<=3000;i++){
        cin >> a >> b;
        if(a>b){
    
    c=a;
    a=b;
    b=c;
    cout << a << " " << b << endl;
    }
    else{
    if(a==0 && b==0)
    break;
    
    else
    cout << a << " " << b << endl;
    
    }
}

    
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((A==B & B==C & C==A) | (A!=B & B!=C & C!=A)){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

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

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

int dp[5050][5050];
signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++){
    char c;
    cin>>x[i]>>y[i]>>c;
    if(c=='W') x[i]+=k;
  }
  
  memset(dp,0,sizeof(dp));
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      int dx=(x[i]+j*k)%(2*k),dy=(y[i]+j*k)%(2*k);
    
      /*//
	dp[dy][dx]++;
	dp[(dy+k)%(2*k)][dx]--;
	dp[dy][(dx+k)%(2*k)]--;
	dp[(dy+k)%(2*k)][(dx+k)%(2*k)]++;
      //*/
      //cout<<dy<<" "<<dx<<endl;
      dp[dy][dx]++;
      dp[dy+k][dx]--;
      dp[dy][dx+k]--;
      dp[dy+k][dx+k]++;

      int W=2*k;
      dy+=W;
      dp[dy][dx]++;
      dp[dy+k][dx]--;
      dp[dy][dx+k]--;
      dp[dy+k][dx+k]++;
      dy-=W;

      dx+=W;
      dp[dy][dx]++;
      dp[dy+k][dx]--;
      dp[dy][dx+k]--;
      dp[dy+k][dx+k]++;
      dx-=W;
    
      dy+=W;dx+=W;
      dp[dy][dx]++;
      dp[dy+k][dx]--;
      dp[dy][dx+k]--;
      dp[dy+k][dx+k]++;
      dy-=W;dx-=W;
    }
  }
    
  int W=5*k;
  for(int i=0;i<W;i++)
    for(int j=1;j<W;j++)
      dp[i][j]+=dp[i][j-1];
  for(int i=1;i<W;i++)
    for(int j=0;j<W;j++)
      dp[i][j]+=dp[i-1][j];

  if(0){
    for(int i=0;i<W;i++){
      for(int j=0;j<W;j++)
	cout<<dp[i][j]<<" ";
      cout<<endl;
    }
  }

  int ans=0;
  for(int i=0;i<W;i++)
    for(int j=0;j<W;j++)
      chmax(ans,dp[i][j]);
  
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<m; i++) cin >> b[i];

    for(int i=0; i<=n-m; i++) {
        for(int j=0; j<=n-m; j++) {
            bool flag=1;
            for(int k=0; k<m; k++) {
                if(a[i+k].substr(j, m)!=b[k]){
                    flag=0;
                    continue;
                }
            }
            if(flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    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 ABC112
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1) { Console.WriteLine("Hello World"); }
            if (n == 2)
            {
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());
                Console.WriteLine(a + b);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    int len = SIZE(s);
    int K;
    cin >> K;

    vector<string> top5;
    REP(i, len) {
        string t;
        //cerr << "i: " << i << endl;
        FOR(j, i, len) {
            t += s[j];

            auto it = lower_bound(ALL(top5), t);
            if (SIZE(top5) == 5 && it == top5.end()) {
                break;
            }
            else if (SIZE(top5) > 0 && it != top5.end() && t == *it) {
                continue;
            }
            else {
                top5.insert(it, t);
                if (SIZE(top5) > 5) top5.pop_back();
            }
        }
    }
    cout << top5[K-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
struct SegmentTree {  // For Range Sum Query
  vector<T> data;
  int size = -1;

  SegmentTree(int N) {
    size = 1;
    while (size < N) size *= 2;
    data.resize(2 * size - 1, 0);
  }

  void Add(int k, T x) {
    k += size - 1;
    data[k] += x;

    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = data[2 * k + 1] + data[2 * k + 2];
    }
  }

  // return value in [a, b]
  T Query(int a, int b) const { return Query(a, b + 1, 0, 0, size); }
  // return value in [a, b)
  // by searching index k node which cover [l, r) region.
  T Query(int a, int b, int k, int l, int r) const {
    // l/r is out of bound.
    if (r <= a || b <= l) return 0;

    // cover full range.
    if (a <= l && r <= b) return data[k];

    T left  = Query(a, b, 2 * k + 1, l, (l + r) /2);
    T right = Query(a, b, 2 * k + 2, (l + r) /2, r);
    return left + right;
  }

  void Print() {
    int k = 1;
    for (int i = 0; i < data.size(); ++i) {
      if (i == k) {
        k = 2 * k + 1; cout << "| ";
      }
      cout << data[i] << " ";
    }
    cout << endl;
  }
};

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, Q; cin >> N >> Q;
  SegmentTree<LL> tree(N);
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    tree.Add(i, a);
  }

  for (int i = 0; i < Q; ++i) {
    int t; cin >> t;
    if (t == 0) {
      int i, x; cin >> i >> x;
      tree.Add(i, x);
    } else {
      int l, r; cin >> l >> r;
      cout << tree.Query(l, r-1) << endl;
    }
  }
}


Measured memory_bytes: 12524
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;
    vector<int> D(26);

    rep(i, S.size()) {
        D.at(S.at(i) - 'a')++;
    }

    rep(i, 26) {
        if(D.at(i) == 0) {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
N, K = map(int, input().split())

counter = 0
for i in range(K, N+2):
    smallest = (i-1) * i // 2
    largest = ((2 * N + 1) - i) * i // 2
    counter += (largest - smallest + 1)
    counter %= (10 ** 9 + 7)

print(counter)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D)
    cout << "Left" << endl;
  else if (A+B < C+D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}


Measured memory_bytes: 3608
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	fmt.Println(n * n)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Pos{
  int x,y;
  Pos(int a,int b){
    x=a;
    y=b;
  }
  bool operator==(const Pos& another)const{
    return x==another.x&&y==another.y;
  }
  bool operator!=(const Pos& another)const{
    return !(*this==another);
  }
};

class Line{
  std::vector<Pos> point;
public:
  Line(std::vector<Pos>& p){
    point=p;
  }
  void RotateClock(){
    for(auto &p:point){
      std::swap(p.x,p.y);
      p.y*=(-1);
    }
  }
  void Move(Pos begin){
    Pos diff(begin.x-point[0].x,begin.y-point[0].y);
    for(auto &p:point){
      p.x+=diff.x;
      p.y+=diff.y;
    }
  }

  bool operator==(const Line& another) const{
    if(point.size()!=another.point.size()) return false;
    bool result=true;
    for(int i=0;i<point.size();i++){
      if(point[i]!=another.point[i]){
        result=false;
        break;
      }



    }
    if(result)return true;
    for(int i=0;i<point.size();i++){
      if(point[i]!=another.point[point.size()-1-i]){
        return false;
      }
    }
    return true;
  }




};

std::vector<int> Solve(int n){
  std::vector<int> result;
  std::vector<Pos> tgt_pos;

  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    tgt_pos.push_back(Pos(x,y));
  }
  Pos tgt_first(tgt_pos[0].x,tgt_pos[0].y);
  Pos tgt_last(tgt_pos.back().x,tgt_pos.back().y);
  Line target_line(tgt_pos);
  for(int i=1;i<=n;i++){
    std::vector<Pos> p;
    int a;
    cin>>a;
    for(int j=0;j<a;j++){
      int x,y;
      cin>>x>>y;
      p.push_back(Pos(x,y));
    }
    Line line(p);

    for(int rotate=0;rotate<4;rotate++){
      line.RotateClock();
      line.Move(tgt_first);
      if(target_line==line){
        result.push_back(i);
        break;
      }
      line.Move(tgt_last);
      if(target_line==line){
        result.push_back(i);
        break;
      }
    }
  }

  return result;
}

int main(void) {
  // cout << std::fixed << std::setprecision(10);
  // cin.tie(0);
  // std::ios::sync_with_stdio(false);

  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    std::vector<int> result=Solve(n);
    for(auto x:result){
      cout<<x<<endl;
    }
    cout<<"+++++"<<endl;
  }



  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define ll long long
#define INF 100000000000000000LL
using namespace std;
signed main() {
  int n, m, cun, ans = 0;
  string s[10000], t[10000];
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> t[i];   
  } 
  
  for (int i = 0; i < n; i++) {
    cun = 0;
    for (int j = 0; j < n; j++) {
      if (s[i] == s[j]) {
        cun++;
      }
    }
    
    for (int j = 0; j <m; j++) {
      if (s[i] == t[j]) {
        cun--;
      }
    }
    ans = max(ans, cun);
  }
  
  cout << ans << "\n";
  return (0);
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	int n,a;
	cin >> n >> a;
	if (n % 500 > a) {cout << "No" << endl;}
	else {cout << "Yes" << endl;}
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) {
		string s = to_string(i);
		if (s[0] == s[4] && s[1] == s[3])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int main(void){

  int N;
  cin >> N;

  vector<int> p(N);

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

  vector<int> conf(N);
  for (int i = 0; i < N; i++){conf[i] = i + 1;}

  bool flag = false;

  if (p == conf){flag =true;}

  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      vector<int> q(N);
      copy (p.begin(), p.end(), q.begin());
      q[i] = p[j];
      q[j] = p[i];
      if (q == conf){flag = true;}
    }
  }
  if (flag == true){cout << "YES" << endl;}
  if (flag == false){cout << "NO" << endl;}



  return 0;
}



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

int main(){
    int n, num = 1;
    string s;
    cin >> n >> s;
    char tmp = s[0];
    for(int i = 1; i < n; i++){
        if(s[i] != tmp){
            num++;
            tmp = s[i];
        }   
    }
    cout << num;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#include <queue>
#include <stdlib.h>
#define F first
#define S second
#define ll long long
#define ull unsigned long long
using namespace std;
ll n,x,a[20000],b[20000],ans;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> x;
    for (int i=0;i<n;i++) {
        cin >> a[i];
        ans+=a[i];
        b[i]=a[i];
    }
    for (int i=0;i<n;i++){
        ll t=0;
        for (int j=0;j<n;j++)
        b[j]=min(b[j],a[(j-i+n)%n]);
        for (int j=0;j<n;j++) t+=b[j];
        ans=min(ans,t+x*i);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  string s;
  cin >> s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a,b,c,d,e;
  scanf("%i %i %i %i %i",&a,&b,&c,&d,&e);
  int p=a-e;
  int o=b-e;
  if(c >= e && d >= e && p >= c && o >= d)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 2100
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.IntMap ((!))
import qualified Data.IntMap as M
import Data.Maybe
import qualified Data.Set as S
import qualified Data.Tuple as T

addToSet set xs = foldl' (\ acc x -> S.insert (T.swap x) acc) set xs

addToMap m xs = foldl' (\ acc (x, d) -> M.insert x d acc) m xs

dijkstra graph source = dijkstra' graph (S.singleton (0, source)) (M.singleton source 0)

dijkstra' graph pq res
    | S.null pq = res
    | otherwise = dijkstra' graph (addToSet pq' info) (addToMap res info)
    where
      fwd = M.findWithDefault
      ((dis, node), pq') = S.deleteFindMin pq
      nodes = fwd [] node graph
      update = filter (\ (x, e) -> M.notMember x res || dis + e < res!x) nodes
      info = map (\ (x, e) -> (x, dis + e)) update

buildGraph edges = 
 let g = groupBy (\ (x, _, _) (y, _, _) -> x == y) edges
 in M.fromDistinctAscList (map (\ x -> (f1 $ head x, map (\ (_, y, z) -> (y, z)) x)) g)

readInt = fst . fromJust . B.readInt
f1 (x, _, _) = x
f3 (_, _, x) = x

main = do
  ((nv,_,r):edges) <- map (\[x,y,z]->(x,y,z)) . map (map readInt . B.words) . B.lines <$> B.getContents
  let g = buildGraph (sort edges)
  let res = dijkstra g r
  mapM_ (putStrLn . maybe "INF" show . flip M.lookup res) [0..nv-1]

Measured memory_bytes: 253756
import math
def readinput():
    a,b,c,d=map(int,input().split())
    return a,b,c,d

def main(a,b,c,d):
    lcm=c*d//math.gcd(c,d)
    #print(lcm)
    return b-a+1 - ( b//c-(a-1)//c + b//d-(a-1)//d - ( b//lcm - (a-1)//lcm ) )


if __name__=='__main__':
    a,b,c,d=readinput()
    ans=main(a,b,c,d)
    print(ans)


Measured memory_bytes: 9192
#include<stdio.h>

int main(void) {
	char c[4];
	int i;
	int abc[3] = { 0,0,0 };
	scanf("%s", &c);

	for (i = 0; i < 3; i++) {
		if (c[i] == 'a') {
			abc[0] += 1;
		}
		else if(c[i] == 'b'){
			abc[1] += 1;
		}
		else {
			abc[2] += 1;
		}
	}

	if (abc[0] == 1 && abc[2] == 1 && abc[2] == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

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

int	main()
{
	int		N;
	string	S;
	cin >> N >> S;
	int i = 0;
	int	cnt = 0;
	while (i < N - 2) {
		if (S.at(i) != 'A')
			++i;
		else if (S.at(i + 1) != 'B')
			++i;
		else if (S.at(i + 2) != 'C')
			i += 2;
		else {
			++cnt;
			i += 3;
		}
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,dp[100001],a[100001],b;
int main() {
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> b;
    a[b]=1;
  }
  dp[0]=1;
  for(int i=1; i<=n; i++) {
    if(a[i-1]==0) {
      dp[i]+=dp[i-1];
    }
    if(a[i-2]==0) {
      dp[i]+=dp[i-2];
    }
    dp[i]%=1000000007;
  }
  cout << dp[n] << '\n';
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;
map<ll, ll> mp;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n+1);  
  for(ll i=1;i<=n;i++){
     cin >> a[i];
     a[i] += i;
     mp[a[i]]++;
  }
  ll ans = 0;
  for(ll i=1;i<=n;i++){
    ans+=mp[i*2-a[i]];
  }
  cout << ans << endl;
}

Measured memory_bytes: 27464
using System;
using System.Linq;

class Program {
  static void Main() {
    var s = Console.ReadLine().OrderBy(x => x).ToArray();
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13268
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 1000000007
#define ciN cin

////////////////////////////////////////////////////////////////


void solve() {
	int n, x, t; ciN >> n >> x >> t;
	int j = n / x;
	if (n % x > 0)j++;
	cout << t*j << endl;
}




////////////////////////////////////////////////////////////////


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

//	int t; cin >> t;
//	while (t--)
	solve();

	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???



Measured memory_bytes: 3608
#include <iostream>

using namespace std;

typedef long long ll;

#define M 998244353

#define Z 3000000

ll pot(int a, int b) {
	if (b == 0) return 1;
	ll x = pot(a,b/2);
	x = x*x%M;
	if (b%2) x = x*a%M;
	return x;
}

ll inv(ll x) {
	return pot(x,M-2);
}

ll ff[Z+1];
ll ii[Z+1];

ll ncr(int a, int b) {
	return ff[a]*ii[b]%M*ii[a-b]%M;
}

ll calc(int n, int k) {
	return ncr(k+n-1,k);
}

int n, m;

int main() {
	ff[0] = 1;
	for (int i = 1; i <= Z; i++) ff[i] = ff[i-1]*i%M;
	ii[Z] = inv(ff[Z]);
	for (int i = Z-1; i >= 0; i--) ii[i] = ii[i+1]*(i+1)%M;
	cin >> n >> m;
	ll x = calc(n,2*m+m);
	for (int i = 2*m+1; i <= 2*m+m; i++) {
		ll u = n*calc(n-1,2*m+m-i)%M;
		x = (x-u)%M;
		if (x < 0) x += M;
	}

	if (m < n) {
		for (int i = m+1; i <= n; i++) {
			if (2*m+m-i < 0 || (2*m+m-i)%2 == 1) continue;
			ll u = ncr(n,i)*calc(n,(2*m+m-i)/2)%M;
			x = (x-u)%M;
			if (x < 0) x += M;
		}
	}
	cout << x << "\n";
}


Measured memory_bytes: 47104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String n = sc.next();

			n = n.replace('9', '*');
			n = n.replace('1', '9');
			n = n.replace('*', '1');
			System.out.println(n);
		}
	}

Measured memory_bytes: 22612
import std.stdio;
import std.typecons;
import std.conv;

void main() {
    int N, T; readf("%d %d\n", &N, &T);
    int[string] times;
    string[] names;
    foreach (i; 0 .. N) {
        int h1, h2, m1, m2;
        string n1, n2;
        readf("%d:%d %s %d:%d %s\n", &h1, &m1, &n1, &h2, &m2, &n2);
        if (i != 0) {
            times[n1] += h1 * 60 + m1;
            names ~= n1;
        }
        if (i != N - 1) {
            times[n2] -= h2 * 60 + m2;
        }
    }
    string[] ans;
    foreach (name; names) {
        if (times[name] >= T) {
            ans ~= text(name, " ", times[name]);
        }
    }
    ans.length.writeln;
    foreach (a; ans) {
        a.writeln;
    }
}

Measured memory_bytes: 1092
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<stdlib.h>
//#include <algorithm>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
int main(void){
  int n;
  cin >> n;
  int a;
  deque<int> d;
  rep(i,n){
    cin >> a;
    if(i%2==0){
      d.push_back(a);
    }else{
      d.push_front(a);
    }
  }
  if(n%2==0){
    rep(i,n){
      cout<<d.front()<<" ";
      d.pop_front();
    }
  }else{
    rep(i,n){
      cout<<d.back()<<" ";
      d.pop_back();
    }
  }
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n == 5 || n == 3 || n == 7)
		cout<<"YES"<<endl;
	else 
		cout<<"NO"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  set<int> st;
  rep(i,n) {
    if (st.count(v[i])) st.erase(v[i]);
    else st.insert(v[i]);
  }
  int ans = st.size();

  cout << ans << endl;
}

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

Measured memory_bytes: 8060
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        Console.ReadLine();
        double ans = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).OrderBy(x => x).Aggregate((sum, x) => (sum + x) / 2);

        Console.WriteLine(ans);
    }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int field[21][21];

int main()
{
    int n;
    while(cin>>n, n) {
        memset(field, 0, sizeof(field));
        rep(i,n) {
            int x, y;
            cin >> x >> y;
            field[x][y] = 1;
        }
        int m;
        cin >> m;
        int x = 10, y = 10;
        rep(i, m) {
            char dir;
            int dist;
            cin >> dir >> dist;
            if(dir=='N') {
                rep(i,dist) {
                    y += 1;
                    field[x][y] = 0;
                }
            }
            else if(dir=='S') {
                rep(i,dist) {
                    y-=1;
                    field[x][y] = 0;
                }
            }
            else if(dir=='E') {
                rep(i,dist) {
                    x+=1;
                    field[x][y] = 0;
                }
            }
            else if(dir=='W') {
                rep(i,dist) {
                    x-=1;
                    field[x][y] = 0;
                }
            }
        }

        string ans = "Yes";
        rep(i,21) {
            rep(j,21)
                if(field[i][j]==1) {
                    ans = "No";
                    break;
                }
        }
        P(ans);
    }
    return 0;
}

Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl			    "\n"
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


int32_t main()
{
	FIO;

	int n, weight;int val=0;
	cin >> n >> weight;
	int v[n], w[n];
	fr(i,n){cin>>w[i]>>v[i];}
    val=n*1000;
	int dp[n+1][val+1];
	fr(i,n+1){fr(j,val+1) dp[i][j]=inf;}
	dp[0][0]=0;
	fr(i,n+1) dp[i][0]=0;

	int i,j;
	for(i=1;i<n+1;i++){

		for(j=1;j<val+1;j++){
			if(v[i-1]<=j){
				dp[i][j]=min(dp[i-1][j-v[i-1]]+w[i-1],dp[i-1][j]);
			}
			else {dp[i][j]=dp[i-1][j];};
		}
	}
	//fr(i,n+1){fr(j,val+1) {cout<<dp[i][j]<<" ";}cout<<nl;}
	i=0;
int pos=0;
	for( i=0;i<val+1;i++){
		if(dp[n][i]==inf) continue;
		if(dp[n][i]>weight) continue;
		else pos=i;
	}
	cout<<pos;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, A;
  cin >> H >> A;
  cout << (H + (A - 1)) / A << endl;
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const LL MAXN = 100010;

LL n, m, k, y[MAXN], x[MAXN], z[MAXN], t[MAXN];

LL abs(LL x) {return x < 0 ? -x : x;}

int main()
{
	in(n);
	FOR(i, 1, n) in(x[i]);
	FOR(i, 1, n - 1) y[i] = x[i + 1] - x[i], z[i] = i;

	in(m); in(k);
	FOR(i, 1, m) {LL x; in(x); std::swap(z[x - 1], z[x]);}

	static LL ret[MAXN];
	FOR(i, 1, n - 1) ret[i] = i;

	while (k) {
		if (k & 1) FOR(i, 1, n - 1) ret[i] = z[ret[i]];
		FOR(i, 1, n - 1) t[i] = z[i];
		FOR(i, 1, n - 1) z[i] = t[t[i]];
		k >>= 1;
	}

	//if (x[1] < 0) putchar('-'); out(abs(x[1])); putchar(10);
	printf("%lld\n", x[1]);
	
	FOR(i, 1, n - 1) {
		x[i + 1] = x[i] + y[ret[i]];
		//if (x[i + 1] < 0) putchar('-'); out(abs(x[i + 1])); putchar(10);
		printf("%lld\n", x[i + 1]);
	}
	
	return 0;
}


Measured memory_bytes: 5248