akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

typedef struct {
    int top;
    int bottom;
    int right;
    int left;
    int front;
    int back;
} Dice;

void roll(Dice *d, char direction)
{
    int present_top = d->top;
    int present_bottom = d->bottom;
    int present_right = d->right;
    int present_left = d->left;
    int present_front = d->front;
    int present_back = d->back;

    if (direction == 'N') {
        d->top = present_front;
        d->bottom = present_back;
        d->front = present_bottom;
        d->back = present_top;
    } else if (direction == 'S') {
        d->top = present_back;
        d->bottom = present_front;
        d->front = present_top;
        d->back = present_bottom;
    } else if (direction == 'E') {
        d->top = present_left;
        d->bottom = present_right;
        d->right = present_top;
        d->left = present_bottom;
    } else {
        d->top = present_right;
        d->bottom = present_left;
        d->right = present_bottom;
        d->left = present_top;
    }
}

void revolve(Dice *d, char direction)
{
    int present_top = d->top;
    int present_bottom = d->bottom;
    int present_right = d->right;
    int present_left = d->left;
    int present_front = d->front;
    int present_back = d->back;

    if (direction == 'R') {
        d->front = present_right;
        d->back = present_left;
        d->right = present_back;
        d->left = present_front;
    } else {
        d->front = present_left;
        d->back = present_right;
        d->right = present_front;
        d->left = present_back;
    }
}

int is_same(Dice *d1, Dice *d2)
{
    int i, j;

    for (i = 0; i < 6; i++) {
        for (j = 0; j < 4; j++) {
            if (d1->top == d2->top && d1->bottom == d2->bottom &&
                d1->right == d2->right && d1->left == d2->left &&
                d1->front == d2->front && d1->back == d2->back) return 1;
            else revolve(d2, 'R');
            }
        if (i % 2 == 0) roll(d2, 'N');
        else roll(d2, 'W');
    }

    return 0;
}

int main(void)
{
    Dice dice1;
    Dice dice2;
    int i;

    for (i = 0; i < 6; i++) {
        switch (i) {
            case 0 : scanf("%d", &dice1.top); break;
            case 1 : scanf("%d", &dice1.front); break;
            case 2 : scanf("%d", &dice1.right); break;
            case 3 : scanf("%d", &dice1.left); break;
            case 4 : scanf("%d", &dice1.back); break;
            case 5 : scanf("%d", &dice1.bottom); break;
        }
    }

    for (i = 0; i < 6; i++) {
        switch (i) {
            case 0 : scanf("%d", &dice2.top); break;
            case 1 : scanf("%d", &dice2.front); break;
            case 2 : scanf("%d", &dice2.right); break;
            case 3 : scanf("%d", &dice2.left); break;
            case 4 : scanf("%d", &dice2.back); break;
            case 5 : scanf("%d", &dice2.bottom); break;
        }
    }

    if (is_same(&dice1, &dice2)) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 580
N,M,X = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(N)]

import numpy as np

ans = N * (10**5)+1


for n in range(2**N):
  ls = [0] * (M+1)
  bin = format(n,'b').zfill(N)
  for i in range(N):
    ls = np.array(ls) + np.array(C[i])*int(bin[i])

  if min(ls[1:]) >= X:
    if ls[0] < ans:
      ans = ls[0]

      
if ans < N * (10**5)+1:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 27212
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
#include<vector>
using namespace std ;
typedef long long ll;

bool f(vector<int> v)
{
    for(auto i:v)
    {
        cout << i;
        if(i>0)
            return false ;
    }
    return true ;
}
// N K
// A_1, ..., A_N
int main(){
    int N ;
    cin >> N ;

    vector<int> h ;
    for(int i = 0; i != N; i++){
        int h_n ;
        cin >> h_n ;
        h.push_back(h_n) ;
    }

    int base_ind = 0 ;
    int cnt = 0 ;

    // cout << "HHH";
    // for(int i=0; i!=N; i++){
    //     cout << "i" << i << ", h[i]" << h[i] << endl;
    // }

    while(true)
    {
        bool mizu = false;
        for(int i=base_ind; i!=N; i++)
        {
            if(h[i] > 0){
                h[i]-- ;
                mizu = true ;
            }else{
                break ;
            }
        }
        if(mizu)
            cnt++ ;

        // cout << "HHH";
        // for(int i=0; i!=N; i++){
        //     cout << "i" << i << ", h[i]" << h[i] << endl;
        // }

        bool renzoku_zero=true;
        for(int i=base_ind; i!=N; i++)
        {
            if(h[i]!=0){
                renzoku_zero = false ;
                break ;
            }else{
                renzoku_zero = true ;
                base_ind = i+1 ;
            }
        }
        if(renzoku_zero)
        {
            cout << cnt << endl ;
            break ;
        }
    }
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

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

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll cnt = B-A+1;
  A--;
  ll G = C*D /gcd(C, D);
  //cout << "lcm:" << G << endl;
  cnt -= B/C - A/C;
  cnt -= B/D - A/D;
  cnt += B/(G) - A/(G);

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    l,r=map(int,input().split())
    a.append(l)
    b.append(r)
x=max(a)
y=min(b)

if y-x<0:
    print('0')
else:
    print(y-x+1)

Measured memory_bytes: 16964
from collections import deque
 
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
 
dirr = ((1, 0), (0, 1), (-1, 0), (0, -1))
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#': continue
        q = deque()
        q.append((i, j, 0))
        visited = [[False] * w for _ in range(h)]
        visited[i][j] = True
        while q:
            x, y, z = q.popleft()
            for dx, dy in dirr:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx][ny] and s[nx][ny] == '.':
                        q.append((nx, ny, z + 1))
                        if z + 1 > ans: ans = z + 1
                        visited[nx][ny] = True
print(ans)


Measured memory_bytes: 3316
#include <stdio.h>

int main() {
  int a, b, c, i, cnt=0;

  scanf("%d%d%d", &a, &b, &c);

  for(i=0; i <= b-a; i++) {
    if(c % (a+i) == 0) cnt++;
  }
  printf("%d\n", cnt);

  return 0;
}


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

void fnInput(vector<string> &rvsSortBbl, vector<string> &rvsSortSel)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  
  rvsSortBbl.resize(nMaxSiz);
  rvsSortSel.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
  {
    cin >> rvsSortBbl[i];
    rvsSortSel[i] = rvsSortBbl[i];
  }
}

void fnBubbleSort(vector<string> &rvsSortBbl)
{
  int nSorting = 0;
  bool bSorting = true;

  while (bSorting)
  {
    bSorting = false;
    for (int j = rvsSortBbl.size() - 1; j > nSorting; j--)
    {
      if (rvsSortBbl[j].at(1) < rvsSortBbl[j - 1].at(1))
      {
        swap(rvsSortBbl[j], rvsSortBbl[j - 1]);
        bSorting = true;
      }
    }
    nSorting++;
  }
}

void fnOutputBbl(const vector<string> &cnrvsSortBbl)
{
  for (int i = 0; i < cnrvsSortBbl.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvsSortBbl[i];
  }
  cout << endl;
  cout << "Stable" << endl;
}

void fnSelectionSort(vector<string> &rvsSortSel)
{
  for (int nSorting = 0; nSorting < rvsSortSel.size() - 1; nSorting++)
  {
    int nMin = nSorting;
    bool bSorting = false;
    for (int j = nSorting + 1; j < rvsSortSel.size(); j++)
    {
      if (rvsSortSel[j].at(1) < rvsSortSel[nMin].at(1))
      {
        nMin = j;
        bSorting = true;
      }
    }
    if (bSorting == true)  swap(rvsSortSel[nSorting], rvsSortSel[nMin]);
  }
}

void fnOutputSel(const vector<string> &cnrvsSortSel, const vector<string> &cnrvsSortBbl)
{
  string sSortEnd = "Stable";

  for (int i = 0; i < cnrvsSortSel.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvsSortSel[i];
    
    if (cnrvsSortSel[i] != cnrvsSortBbl[i]) sSortEnd = "Not stable";
  }
  cout << endl;
  cout << sSortEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<string> vsSortBbl, vsSortSel;

  fnInput(vsSortBbl, vsSortSel);
  fnBubbleSort(vsSortBbl);
  fnOutputBbl(vsSortBbl); 

  fnSelectionSort(vsSortSel);
  fnOutputSel(vsSortSel, vsSortBbl);

  return 0;
}

Measured memory_bytes: 3208
/*---> 26 January 2020 <--- > 17:32:59 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n,h,x;
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		h-=x;
	}
	if(h<=0){
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
	int n=1,i,j,sum=0;
	scanf("%d",&n);
	int tako[100]={0};
	for (i=0;i<n;i++) {
		scanf("%d",&tako[i]);
	}
	for (i=0;i<n;i++) {
		for (j=0;j<n;j++) {
			if (i!=j && i>j) {
				sum+=(tako[i]*tako[j]);
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	ll r; cin >> r;
	cout << 3 * r*r << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <complex>
#include <iomanip>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define vvd std::vector<std::vector<long double> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;

long double rad(long double r){
  if(r >= 0) return (r/M_PI)*180;
  else return ((M_PI + r)/M_PI)*180 + 180;
}
int main(int argc, char const *argv[]) {
  ld N, a, b, ans = 0;
  std::cin >> N;
  vvd T = vv(2*N, 3, 0, ld);
  for(ld i=0;i<N;i++){
    std::cin >> a >> b;
    T[i][0] = rad(arg(complex<ld>(a, b)));
    T[N+i][0] = T[i][0] + 360.0;
    T[i][1] = T[N+i][1] = a, T[i][2] = T[N+i][2] = b;
  }
  sort(T.begin(), T.end());
  for(ld i=0;i<N;i++){
    ld x = 0, y = 0;
    for(ld j=i;j<2*N&&T[j][0]-T[i][0]<=180;j++){
      x += T[j][1], y += T[j][2];
      ans = max(ans, sqrt(x*x + y*y));
    }
  }
  std::cout << fixed << setprecision(20) << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
def main():
    N =int(input())
    X = list(map(int, input().split()))

    minimum = float("inf")
    for i in range(1,101):
        hpmin = 0
        for j in X:
            hpmin += (i-j)**2
        minimum = min(hpmin, minimum)
    print(minimum)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
# n,m = map(int,input().split())
n = int(input())
# n = input()
p = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if p[i] != i + 1:
        cnt += 1
if cnt == 0 or cnt == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n,answer = 0;
  cin >> n;
  for(int i = 0;i<n;++i) {
    int x; cin >> x; answer+= x - 1;
  }
  cout << answer << endl;
  return 0; 
}

Measured memory_bytes: 256
<?php

$N = stdin();
$X = explode(' ', stdin());
$C = explode(' ', stdin());

$sum = 0;
for ($i = 0; $i < $N; $i++) {
  $p = $X[$i] - $C[$i];
  if ($p > 0) {
    $sum += $p;
  }
}

echo $sum, PHP_EOL;

function stdin()
{
  return trim(fgets(STDIN));
}


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

int main() {
  int n;
  cin >> n;
  map<int,int> cnt;

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

  int ans = 0;

  for (auto &iter : cnt) {
    int key = iter.first;
    int val = iter.second;

    if (val >= key) {
      ans += val - key;
    } else {
      ans += val;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int sum = 0;
    sum += p[N-1]/2;
    for(int i = 0; i < N-1; i++)
    {
        sum += p[i];
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        char[] s = f.readLine().toCharArray();
        char[] t = f.readLine().toCharArray();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < s.length && s.length - i >= t.length; i++) {
            int diff = 0;
            for (int j = i, k = 0; k < t.length; k++, j++) {
                if (s[j] != t[k]) diff++;
            }
            min = Math.min(min, diff);

        }

        out.println(min);
        out.close();
    }
}

Measured memory_bytes: 32652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<P> z(n);
	REP(i,n) cin>>z[i].first>>z[i].second;
	vector<ll> cnt(n,0);
	REP(i,1000000) {
		ld x=1000000000000ll*cos(2*acos(-1)/(ld)1000000*i);
		ld y=1000000000000ll*sin(2*acos(-1)/(ld)1000000*i);
		ld maxi=INF*INF;
		ll pos=-1;
		REP(j,n) {
			if(sqrt(abs(x-z[j].first)*abs(x-z[j].first)+abs(y-z[j].second)*abs(y-z[j].second))<maxi) {
				maxi=sqrt(abs(x-z[j].first)*abs(x-z[j].first)+abs(y-z[j].second)*abs(y-z[j].second));
				pos=j;
			}
		}
		cnt[pos]++;
	}
	REP(i,n) cout<<fixed<<setprecision(39)<<cnt[i]/(ld)1000000<<endl;
}


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

int main() {
  int n,ans;
  bool t=false;
  cin>>n;
  ans=n;
 for(int i=0;i<n;i++){
    for(int j=1;j<32;j++){
      for(int k=2;k<10;k++){
        if(ans==pow(j,k)){
          t=true;
          break;
        }
      }
        if(t)break;
    }
    if(t)break;
   ans--;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(N)]
for n, a in enumerate(reversed(A)):
    l = N - 1 - n
    if sum(B[l:: l + 1]) % 2 != a:
        B[l] = 1
M = sum(B)
print(M)
ans = [str(n + 1) for n in range(N) if B[n] == 1]
print(' '.join(ans))

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n; cin >> n;
    vector<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.push_back(Ai);
    }
    auto B = A;
    sort(A.begin(), A.end());
    vector<int> ori_A;
    rep(i,n) ori_A.push_back(-1);

    bool is = false;
    bool is2 = false;
    do{
        if(A == B){
            if(ori_A[0] != -1){
                rep(i,n){
                    cout << ori_A[i];
                    if(i != n-1) cout << " ";
                }
                cout << endl;
            }
            rep(i,n){
                cout << A[i];
                if(i != n-1) cout << " ";
            }
            cout << endl;
            is = true;
        }
        ori_A = A;
        if(is2){
            rep(i,n){
                cout << A[i];
                if(i != n-1) cout << " ";
            }
            cout << endl;
            break;
        }
        if(is) is2 = true;
    }while(next_permutation(A.begin(), A.end()));
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define ll 			long long
#define vl 			vector<ll>
#define vi 			vector<int>
#define pi 			pair<int,int>
#define pl 			pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define trace(x) 	cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;


int main()
{
	fast_io;
	
	int n;
	cin>>n;int t;
	vi a(n);
	for(int i=0;i<n;i++)
		{
			int cn=0;
			cin>>t;//trace(t)
			while(t%2==0 && t>0)
			{
				cn++;//trace(t)
				t/=2;
			}
		a[i]=cn;//trace(cn)
	}
	int ans=*min_element(all(a));
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))
sa = [t[i+1]-t[i] for i in range(N-1)]
hazimari = t[0]
las = t[0]
ans = 0

for i in range(N-1):
    
    if sa[i] <= T:
        las = t[i+1]
        
    else:
        ans += las-hazimari+T
        hazimari = t[i+1]
        las = t[i+1]
        
if hazimari != las:
    ans += las -hazimari+T
else:
    ans += T

print(ans)

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

using namespace std;

#define ll long long

#define DEBUG (0)

ll getgcd(ll a, ll b);

int main()
{
  ll N = 0;
  cin >> N;

  if(N < 4){
    cout << 0 << "\n";
    return 0;
  }
  string S;

  ll countR = 0;
  ll countG = 0;
  ll countB = 0;
  ll countSum = 0;

  cin >> S;

  for(int i = 0; i < N; i++){
    if(S[i] == 'R') countR++;
    if(S[i] == 'G') countG++;
    if(S[i] == 'B') countB++;
  }

  countSum = countR * countG * countB;

  /* (j - i) == (k - j) の組み合わせを除去 */
  ll diff = 0;    //j - i
  for(diff = 1; diff <= N/2; diff++){
    for(ll i = 0; i <= N - 2; i++){
      ll j = i + diff;
      ll k = j + diff;
      if(k <= N -1){
        if((S[i] != S[j]) && (S[i] != S[k]) &&(S[j]!= S[k])){
          #if DEBUG
          cout << "====HIT====" << "\n";
          #endif
          countSum--;
        }
      }

    }

  }
  cout << countSum << "\n";


#if DEBUG
  for(int i = 0; i < N; i++){
//    cout <<  S[i] << endl;
  }
  cout << "countR:" << countR << endl;
  cout << "countG:" << countG << endl;
  cout << "countB:" << countB << endl;
#endif
}

Measured memory_bytes: 3644
#include<set>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (lc|1)
using namespace std;
inline int read(){
	int x=0; bool f=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return f?-x:x;
}
const long long inf=0x3f3f3f3f3f3f3f3f;

int n,x,d;
int m[55],f[55];
long long sz[55],s[55];
int head[55],nx[55],to[55],ec=1;
inline void add(int a,int b){
	nx[++ec]=head[a]; head[a]=ec; to[ec]=b;
}
void dfs(int x){
	sz[x]=1; s[x]=m[x];
	for(int i=head[x];i;i=nx[i]){
		int t=to[i];
		dfs(t); sz[x]+=sz[t]; s[x]+=s[t];
	}
}
struct node{
	int id;
	long long val,co;
	inline bool friend operator < (node a,node b){
		return a.val*b.co>b.val*a.co;
	}
}nd[55];

inline int solve(int v){
	int ret=0;
	for(int i=1;i<=n;++i){
		if(nd[i].co>v) continue;
		int tmp=min((long long)nd[i].id==1?inf:d-min(d,n),v/nd[i].co);
		ret+=tmp*nd[i].val;
		v-=tmp*nd[i].co;
	}
	return ret;
}

long long dp[55*55*55],tmp[55*55*55];
int q[55*55*55],h,t;

int main(){
	n=read(); x=read(); d=read(); m[1]=read();
	for(int i=2;i<=n;++i) m[i]=read(),add(f[i]=read(),i); dfs(1);
	for(int i=1;i<=n;++i) nd[i].id=i,nd[i].val=sz[i],nd[i].co=s[i];
	sort(nd+1,nd+1+n); memset(dp,0x3f,sizeof(dp));
	int tot=n*n*n,lim=min(n,d); dp[0]=0;
	for(int i=1;i<=n;++i){
		long long v=nd[i].val,c=nd[i].co,ttmp=lim;
		if(nd[i].id==1) lim=n;
		for(int u=0;u<v;++u){
			h=1; t=0;
			memcpy(tmp,dp,sizeof(dp));
			for(int j=u;j<=tot;j+=v){
				//printf("%lld %lld %d %d\n",v,c,u,j);
				if(h<=t&&(j-q[h])>lim*v) ++h;
				if(h<=t) tmp[j]=min(tmp[j],dp[q[h]]+c*((j-q[h])/v));
				while(h<=t&&dp[q[t]]-c*(q[t]/v)>=dp[j]-c*(j/v)) --t; q[++t]=j;
			}
			memcpy(dp,tmp,sizeof(dp));
		}
		lim=ttmp;
	}
	int ans=0;
	for(int i=0;i<=tot;++i) if(dp[i]<=x) ans=max(ans,i+solve(x-dp[i]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6320
N = int(input())
char = ["a","b","c","d","e","f","g","h","i","j"]
pre = [("",0)]
for i in range(N):
    nx = []
    for s,cnt in pre:
        for c in char[:cnt]:
            nx.append((s+c,cnt))
        c = char[cnt]
        nx.append((s+c,cnt+1))
    pre = nx

for s,_ in pre:
    print(s)








Measured memory_bytes: 21592
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 500010;

struct Segment_Tree{
	int Min[N << 2];

	#define lc (o << 1)
	#define rc (o << 1 | 1)
	#define M ((L + R) >> 1)

	Segment_Tree(){
		memset(Min, 0x3f, sizeof Min);
	}

	void modify(int o, int L, int R, int x, int v){
		if(L == R) Min[o] = v;
		else{
			if(x <= M) modify(lc, L, M, x, v);
			else modify(rc, M + 1, R, x, v);
			Min[o] = min(Min[lc], Min[rc]);
		}
	}

	int query(int o, int L, int R, int l, int r){
		if(l <= L && R <= r) return Min[o];
		else{
			int ret = 1e9;
			if(l <= M) ret = query(lc, L, M, l, r);
			if(r > M) ret = min(ret, query(rc, M + 1, R, l, r));
			return ret;
		}
	}
}T;

int n, k;
int Begin[N], Next[N << 1], to[N << 1], deg[N], e;

inline void Add(int u, int v){
	to[++e] = v, Next[e] = Begin[u], Begin[u] = e, ++deg[v];
}

int P[N], A[N];

priority_queue<int> q;

void work(){
	For(i, 1, n) if(!deg[i]) q.push(i);
	Forr(i, n, 1){
		int s = q.top(); q.pop();
		A[s] = i;
		for(int j = Begin[s]; j; j = Next[j]){
			int u = to[j];
			deg[u]--;
			if(!deg[u]) q.push(u);
		}
	}
	For(i, 1, n) printf("%d\n", A[i]);
}

int main(){
	scanf("%d%d", &n, &k);
	For(i, 1, n){
		int x;
		scanf("%d", &x);
		P[x] = i;
	}
	Forr(i, n, 1){
		int x = T.query(1, 1, n, P[i], P[i] + k - 1);
		if(x <= n) Add(P[x], P[i]);
		if(k > 1 && P[i] > 1){
			x = T.query(1, 1, n, P[i] - k + 1, P[i] - 1);
			if(x <= n) Add(P[x], P[i]);
		}
		T.modify(1, 1, n, P[i], i);
	}
	work();
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,K;
  cin >> N >> K;
  map<int, int> m;
  for(int i = 1; i <= N; i++){
    m[i] = 0;
  }
  for(int i = 0; i < K; i++){
    int tmp;
    cin >> tmp;
    for(int j = 0; j < tmp; j++){
      int tmp2;
      cin >> tmp2;
      m[tmp2]++;
    }
  }

  int ans = 0;
  for(auto x: m){
    if(x.second == 0) ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3632
n,m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1 for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] = 0
    elif h[a-1] > h[b-1]:
        ans[b-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0


print(sum(ans))

Measured memory_bytes: 20032
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


H, N = fetch_int_input()
attacks = fetch_int_input()

answer = ["No", "Yes"]

print(answer[int(H <= sum(attacks))])


Measured memory_bytes: 52676
x=[]
for i in range(int(input())):
    a,b=map(int,input().split())
    x.append([a,b])
    an=0
for j in range(len(x)-2):
    if x[j][0]==x[j][1] and x[j+1][1] == x[j+1][0] and x[j+2][1] == x[j+2][0]:
        an=1
if an:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9196
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int number;
	cin >> number;
	string s;
	cin >> s;

	if (number >= 3200)
	{
		cout << s << endl;
	}
	else
	{
		cout << "red" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int dp[20010];
int main(){
	m=read();n=read();
	dp[0]=0;
	for(register int i=1;i<=20000;i++)dp[i]=1000000000;
	while(n--){
		int x=read(),y=read();
		for(register int i=x;i<=20000;i++){
			dp[i]=min(dp[i],dp[i-x]+y);
		}
		for(register int i=20000-1;i>=1;i--)
			dp[i]=min(dp[i],dp[i+1]);
	}
	printf("%d\n",dp[m]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

bool cond(pair<pii, string> a, pair<pii, string> b) {
  if (a.S == b.S) return a.F.S > b.F.S;
  return a.S < b.S;
}

int main() {
#ifdef LOCAL
  freopen("j.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  int n, x;
  string s;
  cin >> n;
  vector<pair<pii, string>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> s >> x;
    v[i] = {{i + 1, x}, s};
  }
  sort(v.begin(), v.end(), cond);
  for (pair<pii, string> p : v) cout << p.F.F << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const INF = 1e9+5;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<int> V(N), S(N+1, 0);
  for(int i = 0; i < N; ++i) std::cin >> V[i];
  for(int i = 0; i < N; ++i) S[i+1] = S[i] + V[i];
  int ans = 0;
  auto calc = [&](int nt, int np)->int {
    int sum = -INF, q = N-nt;
    int res = 0;
    for(int p = 0; p <= nt; ++p) {
      int cur = S[N] - S[p+q] + S[p];
      std::vector<int> dis(V.begin(), V.begin()+p);
      for(int i = p+q; i < N; ++i) dis.push_back(V[i]);
      std::sort(dis.begin(), dis.end());
      int cnt = 0;
      for(int v: dis) {
        if(v >= 0) break;
        if(++cnt > np) break;
        cur -= v;
      }
      res = std::max(res, cur);
    }
    return res;
  };
  for(int i = 0; i <= std::min(N, K); ++i) {
    // take i jems, then put <=j jems back
    int j = std::min(K-i, i);
    ans = std::max(ans, calc(i, j));
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)
ans = 0
c = 0
if "B" in s:
    b = s.index("B")
else:
    print(0)
    exit()
for i in range(b+1, n):
    if s[i] == "W":
        ans += i - b - c
        c += 1
print(ans)


Measured memory_bytes: 4840
//
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			TreeSet<Long> set = new TreeSet<Long>();  //自動ソートができるように
			for (int i = 0; i<times; i++){
				int query = sc.nextInt();
				long x = sc.nextLong();
				switch (query) {
				case 0:
					set.add(x);
					System.out.println(set.size());
					break;
				case 1:
					if (set.contains(x)) {
						System.out.println(1);
					} else System.out.println(0);
					break;
				case 2:
					set.remove(x);
					break;
				case 3:
					long large = sc.nextLong();
					SortedSet<Long> subset = set.subSet(x,true,large,true);
					for (long l :subset) {
						System.out.println(l);
					}
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 187312
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back


void input(){
    int n;
    cin >> n;
   vector<int>h(n);
   f(i,n ) cin >> h[i];
   h[0]--;
   for(int i = 1; i < n; ++i){
     if(h[i] - 1 >= h[i - 1])--h[i];
   }
   for(int i = 1; i < n; ++i){
     if(h[i] < h[i - 1]){
        cout << "No" << endl;return ;
     }
   }
   cout << "Yes" << endl;
}
int main()
{
 input();
 return 0;
}


Measured memory_bytes: 640
class Dice:

    def __init__(self):
        # 初期値がない場合
        self.t = 1
        self.s = 2
        self.e = 4
        self.w = 8
        self.n = 16
        self.b = 32

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b

    def rot(self, way):
        if way == "S":
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == "N":
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == "E":
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == "W":
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():

    t,s,e,w,n,b = map(int, input().split())
    cmd = input().upper()
    dice1 = Dice(t,s,e,w,n,b)

    for i in range(len(cmd)):
        dice1.rot(cmd[i])
    
    print(dice1.t)

if __name__ == '__main__':
    main()




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

int main() {
    vector<char>s;
  while(1){
      int m=0, f=0, r=0;
      scanf("%d %d %d", &m, &f, &r);
      //cout << m << f << r << endl;
    if(m==-1 && f==-1 && r==-1) break;
    if(m==-1 || f==-1){
         s.push_back('F');
          continue;
    }
    if(m+f>=80) s.push_back('A');
    if(65<=m+f && m+f<80) s.push_back('B');
    if(50<=m+f && m+f<65) s.push_back('C');
    if(30<=m+f && m+f<50){
        if(r>=50) s.push_back('C');
        else s.push_back('D');
    }
    if(m+f<30) s.push_back('F');
  }
  for(char x : s){
      cout << x << endl;
  }
    return 0;
}




Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		int sum=0,mx=-1,mn=1001;
		for(int i=0;i<n;i++){
			int a;	scanf("%d",&a);
			sum+=a;
			mx=max(mx,a);
			mn=min(mn,a);
		}
		printf("%d\n",(sum-mx-mn)/(n-2));
	}
	return 0;
}

Measured memory_bytes: 0
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll INF = 10000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
ll at[30][30];
ll bt[30][30];
ll ar[30];
ll upt[30][30][30];
ll mid(ll x, ll y, ll z) {
	if (x <= y && y <= z) {
		return y;
	}
	else if (y <= x && x <= z) {
		return x;
	}
	else return z;
}
int c[30];
ll ggd(ll x, ll v) {

	if (v == 0) return 0;
	ll rem = x % v;
	ll di = ((x / v) * v) * 2;
	ll r = di + x;
	return r + ggd(v, rem) - rem;

}
//]
void solv() {
	string s;
	cin >> s;
	int r = 0;
	int b = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		r += s[i] == '0';
		b += s[i] == '1';
	}
	cout << (min(r, b) * 2) << endl;

	//string s;
	//cin >> s;

	//cin >> n >> m;
	//fill(memo, memo + n, -1);
	//for (size_t i = 0; i < m; i++)
	//{
	//	int p, q,c;
	//	cin >> p >> q >> c;
	//	co[p, q] = c;
	//	co[q, p] = co[p, q];
	//	ve[p].push_back(q);
	//	ve[q].push_back(p);
	//}

	//
	//cout << rec(1, 0) << endl;

}


int main() {
	solv();

	return 0;
}


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

int n, x;
int a[2005];
int mn[2005][2005];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> x;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) {
		mn[i][i] = a[i];
		for (int j = i + 1; j < n; ++j) mn[i][j] = min(mn[i][j - 1], a[j]);
	}

	long long ans = 1e18;
	for (int r = 0; r < n; ++r) {
		long long add = 1ll * x * r;
		for (int i = 0; i < n; ++i) {
			int j = (i + r) % n;
			int cur;
			if (j >= i) cur = mn[i][j]; else cur = min(mn[i][n - 1], mn[0][j]);

			add += cur;
		}
		ans = min(ans, add);
	}

	cout << ans << endl;
}

Measured memory_bytes: 15360
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int N;
LL F[100005], S[100005];

LL mustF[100005], mustS[100005];

int imp() {
	for (int i = 0; i < N; i++) {
		if (mustF[i] != -1 && mustS[i] != -1 && mustF[i] != mustS[i]) {
			return 1;
		}
	}

	LL mx = -1;
	for (int i = 0; i < N; i++) {
		mx = MAX(mx, mustS[i]);
		if (mx > F[i]) return 1;
	}

	mx = -1;
	for (int i = N - 1; i >= 0; i--) {
		mx = MAX(mx, mustF[i]);
		if (mx > S[i]) return 1;
	}
	return 0;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &F[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%lld", &S[i]);
	}

	for (int i = 0; i < N; i++) {
		if (i == 0 || F[i - 1] != F[i]) mustF[i] = F[i];
		else mustF[i] = -1;
	}
	for (int i = N - 1; i >= 0; i--) {
		if (i == N - 1 || S[i + 1] != S[i]) mustS[i] = S[i];
		else mustS[i] = -1;
	}

	if (imp()) {
		printf("0\n");
		return 0;

	}
	
	LL ans = 1;
	LL MOD = 1000000007;
	for (int i = 0; i < N; i++) {
		if (mustS[i] != -1 || mustF[i] != -1) continue;
		ans = (ans * MIN(F[i], S[i])) % MOD;
	}
	printf("%lld\n", ans);

	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
constexpr int M = 1e9 + 7;
constexpr int INF = 1e9;

int main() {
    string S, T;
    cin >> S >> T;
    vector<string> cand;
    for(int i = (int)S.size() - (int)T.size(); i >= 0; --i) {
        bool check = true;
        for(int j = 0; j < T.size(); ++j) {
            check &= S[i + j] == '?' || S[i + j] == T[j];
        }
        if(check) {
            string res;
            for(int j = 0; j < i; ++j) {
                res += (S[j] == '?' ? 'a' : S[j]);
            }
            res += T;
            for(int j = i + T.size(); j < S.size(); ++j) {
                res += (S[j] == '?' ? 'a' : S[j]);
            }
            cand.push_back(move(res));
        }
    }
    if(cand.size() == 0) {
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(cand.begin(), cand.end());
        cout << cand[0] << endl;
    }
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args) {
        String ret;
        ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));

        //Console.WriteLine(ret);
        //Console.ReadLine();
    }

    static string process(System.IO.TextReader input) {
        int n   = int.Parse(input.ReadLine());
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = int.Parse(input.ReadLine());
        }

        int max = 0;
        int second = 0;

        for(int i=0; i<n; i++) {
            if(max < a[i]) {
                second = max;
                max = a[i];
            }else if(second < a[i]) {
                second = a[i];
            }
        }
        
        for(int i=0; i<n; i++) {
            if(a[i] == max) {
                Console.WriteLine(second);
            } else {
                Console.WriteLine(max);
            }
        }
        return null;
    }

    static string process(string input) {
        return process(new System.IO.StringReader(input));
    }
}

Measured memory_bytes: 17108
#include "bits/stdc++.h"
//#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll& a, const pll& b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}
ll nCr(ll n, ll r);//コンビネーション
int permutation(int n, int r);//nPk パーミュテーション
int factorial(int k);//階乗

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	//priority_queue<int> q;
	string s = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[100005] = {};
	ll y[100005] = {};
	string str[200005] = {};
	//char* ch[200005] = {};
	char* ch1 = {};
	//ll z[302][302] = {};
	//std::vector<string> data;
	//sort(data.begin(), data.end());//昇順ソート

	cin >> a;
	cin >> b;
	if (a>=10)
	{
		cout << b << endl;

	}
	else
	{
		cout << b +(100*(10-a))<< endl;

	}

	//cout << ans << endl;

	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}

int permutation(int n, int r) {
	int n_sum, r_sum;
	int i;
	r = n - r;
	n_sum = factorial(n);
	r_sum = factorial(r);
	return n_sum / r_sum;
}

ll nCr(ll n, ll r) {
	ll ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int factorial(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

const int INF = 1001001001;

int main(){
    int n, m, x;
    std::cin >> n >> m >> x;
    std::vector<int> c(n);
    std::vector<std::vector<int>> a(n, std::vector<int>(m));

    for (int i = 0; i < n; i++)
    {
        std::cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            std::cin >> a[i][j];
        }
    }

    int min_cost = INF; //大きな数で初期化
    for (int i = 0; i < 1 << n; i++) //買う・買わないの組み合わせを二進数で列挙（pow(2, n)通り）
    {
        int cost = 0; //金額
        std::vector<int> skill(m);
        for (int j = 0; j < n; j++) //それぞれの本について買うか買わないかチェック
        {
            if (i >> j & 1) //二進数i(ex. 110)の左からj桁目(=初めからj番目の本)が1(=買う)のとき
            {
                cost += c[j]; //j番目の本の金額を足す
                for (int k = 0; k < m; k++) /* 今回の本のチョイスのとき、m種類全てのアルゴリズムについて得られるskillを計算 */
                {
                    skill[k] += a[j][k]; //skill[k]にj番目の本で得られるk個目のアルゴリズムのskill(a[j][k])を足す
                }
            }    
        }
        /* 後はm種類のアルゴリズムのskillがxを超えているかチェック */
        bool over = true;
        for (int k = 0; k < m; k++) 
        {
            if (skill[k] < x) //k番目のアルゴリズムのskillがxを超えていなかったとき
            {
                over = false;
            }
        }
        if(over) //overがtrueのままのとき
        {
            min_cost = std::min(min_cost, cost); //min_costより少ないcostが見つかったら置き換える
        }
    }
    if (min_cost == INF) //min_costがINFのままのとき（条件を満たす本の選び方が見つからなかったとき）
    {
        std::cout << -1 << std::endl;
    }
    else //条件を満たす本の選び方が見つかったとき
    {
        std::cout << min_cost << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a[410000],now,ans;
int main()
{
	while(~scanf("%d",&n))
	{
		ans=0;
		if(n==0) return 0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		for(int l=1,r=1,now=0;l<=n;)
		{
			for(;r<=n&&!(now&a[r]);)
			{
				now^=a[r++];
				ans+=r-l;
			}
			now^=a[l++];
		}
		printf("%lld",ans);
	}
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

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

  ll dis = abs(X);

  ll n = dis / D;
  if(n > K) {
    ans = abs(dis - D * K);
  } else {
    if((K - n) % 2 == 0) {
      ans = dis % D;
    } else {
      ans = D - dis % D;
    }
  }

  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int A[3][3];
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin >> A[i][j];
    }
  }
  int N, B;
  cin >> N;
  int f[3][3];
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      f[i][j] = 0;
    }
  }
  for (int k=0; k<N; k++) {
    cin >> B;
    for (int i=0; i<3; i++) {
      for (int j=0; j<3; j++) {
        if (A[i][j] == B) {
          f[i][j] = 1;
        }
      }
    }
  }
  int ret = 0;
  for (int i=0; i<3; i++) {
    int d = 0;
    for (int j=0; j<3; j++) {
      d += f[i][j];
    }
    if (d == 3) {
      ret = 1;
    }
  }
  for (int i=0; i<3; i++) {
    int d = 0;
    for (int j=0; j<3; j++) {
      d += f[j][i];
    }
    if (d == 3) {
      ret = 1;
    }
  }
  int d = 0, e = 0;
  for (int i=0; i<3; i++) {
    d += f[i][i];
    e += f[2-i][i];
    if (d == 3) {
      ret = 1;
    }
    if (e == 3) {
      ret = 1;
    }
  }
  if (ret) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll x[n+1]={};
  ll y[n+1]={};
  ll z[n+1]={};

  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    z[i]=abs(x[i])+abs(y[i]);
  }

  for(int i=0;i<n;i++){
    if(z[i]%2!=z[0]%2){
      cout<<"-1"<<endl;
      return 0;
    }
  }

  vector<ll> d;
  for(int i=30;i>=0;i--){
    d.push_back(1<<i);
  }
  if(z[0]%2==0) d.push_back(1ll);

  int m=d.size();
  cout<<m<<endl;
  for(int i=0;i<m-1;i++) cout<<d[i]<<" ";
  cout<<d[m-1]<<endl;

  for(int i=0;i<n;i++){
    ll u=x[i]+y[i];
    ll v=x[i]-y[i];
    vector<char> ans;

    for(int j=0;j<m;j++){
      if(u>=0){
        if(v>=0){
          ans.push_back('R');
          u-=d[j];
          v-=d[j];
        }else{
          ans.push_back('U');
          u-=d[j];
          v+=d[j];
        }
      }else{
        if(v>=0){
          ans.push_back('D');
          u+=d[j];
          v-=d[j];
        }else{
          ans.push_back('L');
          u+=d[j];
          v+=d[j];
        }
      }
    }

    for(int j=0;j<m;j++) cout<<ans[j];
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256