akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
s=input()
q=int(input())
Q=map(int,input().split())
A=[-1]*(n+1)
C=[-1]*(n+1)
data=[0]*(n+1)
for i,si in enumerate(s):
    if si == "D":
        A[i]=count
    elif si == "M":
        count+=1
    elif si == "C":
        C[i]=count
# for i in range(len(data)-1):
#     data[i+1]+=data[i] 
for k in Q:
    count = ans = 0
    a_num=0
    for i in range(n):
        if A[i]!=-1:
            a_num+=1
            count+=A[i]
        if i-k>=0 and A[i-k]!=-1:
            a_num-=1
            count-=A[i-k]
        if C[i]!=-1:
            ans+=a_num*C[i]-count
    print(ans)
# print(A)
# print(C)
    
# print(data)
          



Measured memory_bytes: 80624
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
string S;
int K;

int toi(char c)
{
    return (c - '0');
}
//=================================================
void input()
{
    cin >> S;
    cin >> K;
}

//=================================================
void solve()
{
    int n = S.size();
    // int cnt = 0;
    // const int f = 5000000000000000; //５千兆
    // int num;
    // for (int i = 0; i < N; ++i)
    // {
    //     num = toi(S[i]);

    //     cnt += (num)

    //     if (cnt >= f){
    //         break;
    //     }
    // }
    int ans;

    int minv=1; 
    int mink=INF;
    for (int i=0; i<n; ++i){
        if (toi(S[i]) != 1) {
            minv = toi(S[i]);
            mink = i+1;
            break;
        }
    }

    if (K < mink) {
        ans = 1;
    }
    else ans = minv;

    cout << ans << endl;
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
arr = list(map(int, input().split()))

dic = {}
j_arr =[]

ans = 0
for i in range(N):
    if i+arr[i] not in dic:
        dic[i+arr[i]] = 0
    dic[i+arr[i]] += 1
    j_arr.append(-1*arr[i]+i)
    if -1*arr[i]+i in dic:
        ans += dic[-1*arr[i]+i]

print(ans)

Measured memory_bytes: 124992
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
#define l first
#define r second

int n;
pair<int,int> a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) {
		scanf("%d %d", &a[i].l, &a[i].r);
		a[i].r++;
	}
	return 1;
}

void init() {
}

long solve() {
	long ans = 0;
	for (int i=0; i<n; i++) {
		int d = a[i].r - a[i].l;
		if (d > ans) {
			ans = d;
		}
	}
	int maxl = INT_MIN, minr = INT_MAX;
	for (int i=0; i<n; i++) {
		maxl = max(maxl, a[i].l);
		minr = min(minr, a[i].r);
	}
	ans += max(0, minr - maxl);

	sort(a, a+n);
	int rx = INT_MAX;
	for (int i=n-1; i>0; i--) {
		rx = min(rx, a[i].r);
		long t = (long)max(0, rx-maxl) + max(0,minr-a[i-1].l);
		ans = max(ans, t);
	}
	return ans;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}






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

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  string S;
  std::cin >> S;
  string T = "";
  char now = '$';
  for(int i=0;i<N;i++){
    if(now==S[i]) continue;
    else{
      T += S[i];
      now = S[i];
    }
  }
  std::cout << T.size() << '\n';
  return 0;
}


Measured memory_bytes: 1144
#include<iostream>
#include<unordered_set>

using namespace std;

int main(){
  unordered_set<int> vars;
  for (int i = 0; i < 3; i++){
    int temp;
    cin >> temp;
    vars.emplace(temp);
  }
  
  string ret = (vars.size() == 2) ? "Yes" : "No";
  cout << ret;
  
  return 0;
}

Measured memory_bytes: 256
# C
import numpy as np
N, K = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

a_order = np.argsort(a_list)
kc = 0
for i in range(N):
    kc += b_list[a_order[i]]
    if kc >= K:
        print(a_list[a_order[i]])
        break


Measured memory_bytes: 21632
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end(),greater<int>());
  int A,B;A=a[0];
  int ma=-1;
  if(a[0]%2){
    for(int i=1;i<n;i++){
      int num;
      if(a[i]>a[0]/2+1)num=a[0]-a[i];
      else num=a[i];
      if(ma<num){ma=num;B=a[i];}
    }
  }else{
    for(int i=1;i<n;i++){
      int num;
      if(a[i]>a[0]/2)num=a[0]-a[i];
      else num=a[i];
      if(ma<num){ma=num;B=a[i];}
    }
  }
  cout<<A<<" "<<B<<endl;
  return 0;
}


Measured memory_bytes: 640
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int n;
	cin>>n;
	cout<<1000*((n+999)/1000)-n<<endl;
	return 0;
}


Measured memory_bytes: 3648
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], x[22][22], y[22][22], ans[16], res;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 0; i < n; i ++) {
      cin >> a[i];
      for (int j = 1; j <= a[i]; j ++)
         cin >> x[i][j] >> y[i][j], x[i][j] --;
   }
   for (int mask = 0; mask < (1 << n); mask ++) {
      for (int i = 0; i < n; i ++) ans[i] = ((mask & (1 << i)) > 0);
      bool ok = 1;
      for (int i = 0; i < n; i ++) {
         bool hon = 1;
         if (mask & (1 << i)) hon = 0;
         for (int j = 1; j <= a[i]; j ++) {
            if (hon == 0 && ans[x[i][j]] != (y[i][j] ^ hon)) {
               ok = 0;
            }
         }
      }
      if (ok) {
         res = max (res, bpp (mask));  
      }
   }
   cout << res;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

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

int main(){
	int a, b;
	cin>>a>>b;
	if(a==b){
		cout<<"Draw";
		return 0;
	}
	if(a==1){
		a+=15;
	}
	if(b==1){
		b+=15;
	}
	if(a>b){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Bob"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007



int main() {
	int n, k;
	cin >> n >> k;
	if (n%k)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 768
H, W, K = map(int, input().split())
S = [[int(c) for c in input()] for i in range(H)]

s = [[0 for i in range(W+1)] for j in range(H + 1)]
for i in range(H):
    for j in range(W):
        s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + S[i][j]

n = H - 1
ans = H * W
for i in range(2 ** n):
    horizon = [0]
    length = 2
    for j in range(n):
        if ((i >> j) & 1):
            horizon.append(j + 1)
            length += 1
    horizon.append(H)
    vertical = 0
    y1 = 0
    for y2 in range(1, W + 1):
        for k in range(length - 1):
            x2 = horizon[k + 1]
            x1 = horizon[k]
            sq = s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]
            sq_pre = s[x2][y2 - 1] - s[x1][y2 - 1] - s[x2][y1] + s[x1][y1]

            if(sq > K):
                if(sq_pre > K):
                    vertical = 1e+9
                else:
                    vertical += 1
                    y1 = y2 - 1
                break
    if (vertical >= W):
        vertical = 1e+9
    ans = min(ans, (vertical) + (length - 2))
print(ans)


Measured memory_bytes: 44124
A,B,C,X,Y = map(int,input().split())
ans = float('inf')
for i in range(0,2*max(X+1,Y+1)):
    cnt = 0
    a = X - i//2
    b = Y - i//2
    if a<=0:
      a = 0
    if b<= 0:
      b =0
      
    cnt += (a)*A + C*i+(b)*B
    ans  = min(ans,cnt)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 500;
int adj[N+1][N+1], ans[N+1][N+1], vis[N+1], col[N+1];
bool has_unfilled(int n) {
    bool ret = false;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            ret |= i != j and ans[i][j] == 0;
        }
    }
    return ret;
}
void dfs(int n, int u, int col_node, int col_edge) {
    col[u] = col_node;
    vis[u] = true;
    for(int v = 1; v <= n; v++) {
        if(adj[u][v]) {
            if(not vis[v] or col[u] != col[v]) {
                adj[u][v] = adj[v][u] = false;
                ans[u][v] = ans[v][u] = col_edge;
            }
            if(not vis[v]) {
                dfs(n, v, not col_node, col_edge);
            }
        }
    }
}
void dfs(int n, int col_edge) {
    for(int i = 1; i <= n; i++) {
        vis[i] = false;
    }
    for(int i = 1; i <= n; i++) {
        if(not vis[i]) {
            dfs(n, i, 0, col_edge);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            adj[i][j] = true;
        }
    }
    int c = 1;
    do {
        dfs(n, c++);
    } while(has_unfilled(n));
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            cout << ans[i][j];
            if(j < n) cout << " ";
        }
        if(i < n) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2560
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

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

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int N, A, B;
	std::cin >> N;
	if (N == 1) {
		std::cout << "Hello World\n";
	} else {
		std::cin >> A >> B;
		std::cout << (A + B) << "\n";
	}
}


Measured memory_bytes: 512
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
cngh=0
bkh=0
for i in range(n):
  if bkh>h[i]:
    if cngh!=h[i-1]:
      if bkh-1==h[i]:
      	cngh=h[i]
      else:
        ans="No"
        break
    else:
      if cngh!=h[i]:
        ans="No"
        break
  bkh=h[i]
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  vector<string>v;
  map<string,int>mp;
  rep(i,0,n) {cin>>s;
  sort(s.begin(),s. end());
  //v.pb(s);
  if(mp.find(s)==mp. end())
  mp[s]=1;
  else mp[s]++;
  }
  sort(all(v));
 /* rep(i,0,v.size())
  {
   /* rep(j,i+1,v.size())
    {
      string r=v[i],y=v[j];
      sort(r.begin(),r. end());
      sort(y.begin(),y. end());
      if(r==y) k++;
    }*/
    /*  rep(j,i+1,v.size())
      {
        if(v[i]==v[j]) k++;
      }
  }*/
    for(auto& it : mp) {m=it.ss;k+=(m*(m-1))/2;}
  cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 11452
unittest
{
	assert( [ "5", "3 2 4 1 2" ].parse.expand.solve == 2 );
	assert( [ "10", "10 71 84 33 6 47 23 25 52 64" ].parse.expand.solve == 36 );
	assert( [ "7", "1 2 3 1000000000 4 5 6" ].parse.expand.solve == 999999994 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 累積和表に変換
	as = 0 ~ as;
	for( auto i = 1L; i < as.length; i++ )
	{
		as[ i ] += as[ i - 1 ];
	}
	
	// QとRの境界を仮置き
	auto ans = long.max;
	auto cs = [ 0L, 1L, 2L, 3L, as.length.signed - 1 ];
	for( ; cs[ 2 ] + 2 < as.length; cs[ 2 ]++ )
	{
		// PとQの差が最小になる境界を探索
		for( auto c = cs[ 1 ], e = long.max; c < cs[ 2 ]; c++ )
		{
			auto p = as[ c ] - as[ cs[ 0 ] ];
			auto q = as[ cs[ 2 ] ] - as[ c ];
			auto d = max( p, q ) - min( p, q );
			if( e <= d ) break;
			e = d;
			cs[ 1 ] = c;
		}
		
		// RとSの差が最小になる境界を探索
		if( cs[ 3 ] <= cs[ 2 ] ) cs[ 3 ] = cs[ 2 ] + 1;
		for( auto c = cs[ 3 ], e = long.max; c < cs[ 4 ]; c++ )
		{
			auto r = as[ c ] - as[ cs[ 2 ] ];
			auto s = as[ cs[ 4 ] ] - as[ c ];
			auto d = max( r, s ) - min( r, s );
			if( e <= d ) break;
			e = d;
			cs[ 3 ] = c;
		}
		
		// PQRSの最大値と最小値の差を計算
		auto p = as[ cs[ 1 ] ] - as[ cs[ 0 ] ];
		auto q = as[ cs[ 2 ] ] - as[ cs[ 1 ] ];
		auto r = as[ cs[ 3 ] ] - as[ cs[ 2 ] ];
		auto s = as[ cs[ 4 ] ] - as[ cs[ 3 ] ];
		ans = min( ans, max( p, q, r, s ) - min( p, q, r, s ) );
	}
	return ans;
}


Measured memory_bytes: 11476
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;

int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    
    ll k;
    string s;
    cin >> k >> s;
    if (s.size() > k)
    {
        cout << s.substr(0, k) + "..." << endl;
    }
    else
    {
        cout << s << endl;
    }
    
    

    return 0;
}

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

using namespace std;

#define for_(i,a,b) for(int i=a;i<b;i++)
#define minit(a,b) memset(a,b,sizeof(a))

int N;
int l[300];
int MOD = 256;

int r[300], o[300];

void make_str(int S, int A, int C) {
	minit(r,0); minit(o,0);
	r[0] = (A*S + C) % MOD;
	for_(i,1,N) r[i] = (A * r[i - 1] + C) % MOD;
	for_(i,0,N) o[i] = (l[i] + r[i]) % MOD;
}

int occur[300];
double entropy() {
	minit(occur,0);
	for_(i,0,N) occur[o[i]]++;
	double ret = 0;
	for_(i,0,300) {
		if (occur[i] == 0) continue;
		double mul = (double)occur[i] / (double)N;
		ret -= mul * log(mul);
	}
	return ret;
}

void solve() {
	double minH = 1e9;
	int ansS = -1, ansA = -1, ansC = -1;
	
	for_(S,0,16) {
		for_(A,0,16) {
			for_(C,0,16) {
				make_str(S, A, C);
				double H = entropy();
				
				if (minH > H + 1e-9) {
					minH = H;
					ansS = S; ansA = A; ansC = C;
				}
			}
		}
	}
	
	cout << ansS << " " << ansA << " " << ansC << endl;
}


int main() {
	while (cin >> N, N) {
		for_(i,0,N) cin >> l[i];
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  reverse(all(v));
  ll a=0;ll b=0;
  rep(i,n) {
    if(i%2==0) a+=v[i];
    else b+=v[i];
  }
  cout<<a-b<<endl;

}

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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	ps := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ps[i])
	}

	sort.Ints(ps)


	fmt.Println(Sum(ps[0:k]...))

}


func Sum(arr ...int) (sum int) {
	for _, x := range arr {
		sum += x
	}
	return
}


Measured memory_bytes: 1888
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;

void solve() {
	int N, K;
	string S;
	cin >> N >> S >> K;
	for (int n = 0; n < N; n++) {
		if (S[n] != S[K - 1])cout << "*";
		else cout << S.substr(n,1);
	}
	cout << endl;
	return;
}

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

using namespace std;

int main(){
  string str;
  int a=0;
  cin >> str;
  if(str=="SUN")a=7;
  if(str=="MON")a=6;
  if(str=="TUE")a=5;
  if(str=="WED")a=4;
  if(str=="THU")a=3;
  if(str=="FRI")a=2;
  if(str=="SAT")a=1;
  
  
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	int R;
	cin >> R;
	cout << R*R << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;

int k;
vector<long long> run;

void dfs(long long cur) {
  if (cur != 0)
    run.push_back(cur);
  if (cur > 3234566667) {
    return;
  }
  long long now = cur % 10;
  for (long long c = 0; c <= 9; c++) {
    if (cur == 0 && c == 0) {
      continue;
    }
    if (cur == 0) {
      dfs(cur * 10 + c);
    } else if (abs(now - c) <= 1) {
      dfs(cur * 10 + c);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  cin >> k;
  dfs(0LL);
  sort(run.begin(), run.end());
  cout << run[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 6256
#include<stdio.h>
int main()
{
    int a,b,d;
    scanf("%d%d",&a,&b);
    if(a<=5)
        d=0;
    else if(a>=6 && a<=12)
        d=b/2;
    else if(a>12)
        d=b;
    printf("%d\n",d);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)


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

	ll X;
	cin >> X;
	ll a = 100;
	ll c = 0;
	while (true) {
		a = a * 1.01;
		c++;
		if (a >= X) {
			break;
		}
	}
	cout << c << endl;
}


Measured memory_bytes: 3608
while True:
    H,W = map(int,raw_input().split())
    if H == 0 and W == 0:
        break
    for i in range(0,H/2):
        print ("#."* (W/2) + "#"* (W%2))
        print (".#"* (W/2) + "."* (W%2))
    if H%2 == 1:
        print ("#."* (W/2) + "#"* (W%2))
    print""


         

Measured memory_bytes: 6344
import java.util.Scanner;
public class Main {
	static int all_day;
	static final int set_data = 10000;
	static long[][] tomato = new long[2][]; 
	static long[][] cream = new long[2][];
	static long[][] basilico = new long[2][];
	
	static void setData(int[][] data, int today) {
		boolean flag = false;
		for(int r = 0; r < data.length; r++) {
			if((data[r][0] - 1) == today) {
				Type_accumulate(data[r][1], today);
				flag = true;
			}
			if(flag == false && r == data.length - 1) {
				Not_Only_accumulate(today);
			}
		}
	}
	
	static void set_first_day() {
		tomato[1][0] = 1;
		cream[1][0] = 1;
		basilico[1][0] = 1;
	}
	
	static void Not_Only_accumulate(int today) {
		//トマト
		tomato[0][today] = tomato[1][today - 1] % set_data;
		tomato[1][today] = cream[0][today - 1] + cream[1][today - 1] + basilico[0][today - 1] + basilico[1][today - 1] % set_data;
		//クリーム
		cream[0][today] = cream[1][today - 1] % set_data;
		cream[1][today] = tomato[0][today - 1] + tomato[1][today - 1] + basilico[0][today - 1] + basilico[1][today - 1] % set_data;
		//バジル
		basilico[0][today] = basilico[1][today - 1] % set_data;
		basilico[1][today] = tomato[0][today - 1] + tomato[1][today - 1] + cream[0][today - 1] + cream[1][today - 1] % set_data;
	}
	
	static void Type_accumulate(int kind, int today) {
		switch(kind) {
		case 1: //トマトの場合
			tomato[0][today] = tomato[1][today - 1] % set_data; 
			tomato[1][today] = cream[0][today - 1] + cream[1][today - 1] + basilico[0][today - 1] + basilico[1][today - 1] % set_data;
			break;
		case 2: //クリームの場合
			cream[0][today] = cream[1][today - 1] % set_data;
			cream[1][today] = tomato[0][today - 1] + tomato[1][today - 1] + basilico[0][today - 1] + basilico[1][today - 1] % set_data;
			break;
		case 3: //バジルの場合
			basilico[0][today] = basilico[1][today - 1] % set_data;
			basilico[1][today] = tomato[0][today - 1] + tomato[1][today - 1] + cream[0][today - 1] + cream[1][today - 1] % set_data;
			break;
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		all_day = stdIn.nextInt();
		for(int r = 0; r < tomato.length; r++) {
			tomato[r] = new long[all_day];
			cream[r] = new long[all_day];
			basilico[r] = new long[all_day];
		}
		int decided_day = stdIn.nextInt();
		int[][] data = new int[decided_day][2];
		boolean flag = true;
		
		for(int r = 0; r < decided_day; r++) { //読み込み
			data[r][0] = stdIn.nextInt(); //day
			data[r][1] = stdIn.nextInt(); //kind
	
			if(flag == true && data[r][0] == 1) {
				switch(data[r][1]) {
				case 1: tomato[1][0] = 1; break;
				case 2: cream[1][0] = 1; break;
				default: basilico[1][0] = 1; break;
				}
				flag = false;
			} else if(flag == true && r == decided_day - 1){
				set_first_day();
				flag = false;
			}
		}	
		for(int r = 1; r < all_day; r++) { //r + 1 = 日にち
			setData(data, r);
		}
		
		System.out.println((tomato[0][all_day - 1] + tomato[1][all_day - 1] + cream[0][all_day - 1] + cream[1][all_day - 1] + basilico[0][all_day - 1] + basilico[1][all_day - 1]) % set_data);		
	}
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int n;
    cin >> n;
    ll sum = 0;
    FOR(i, 0, n) {
        int a, b;
        cin >> a >> b;
        sum += (b-a+1);
    }
    cout << sum << "\n";
    return 0;
}


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

#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<ll> dlist;
typedef vector<dlist> matrix;

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

    int t, n, a , b;
   string s;

   cin >> s; cin >> n;
   deque<char> ss;
   for(auto &x:s)
       ss.push_back(x);

   char p;
   int c = 1;
   while(n--)
   {
       cin >> a;
       if(a == 1){
           c = 1 - c;
       }
       else{
           cin >> a >> p;
           if(a == 2) a = 0;
           if(a == c)
                ss.push_front(p);
           else
               ss.push_back(p);
       }
   }
   if(c == 0)
       reverse(all(ss));
   for(auto &x:ss)
       cout << x;
   cout << "\n";

    return 0;
}//RUL0


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    string s;
    cin >> s;
    reverse(all(s));
    o(s);
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int r = n%10;
	if(r == 2 || r == 4 || r == 5 || r == 7 || r == 9){
		cout <<  "hon";
	}else if(r==3){
		cout << "bon";
	}else{
		cout << "pon";
	}
	return 0;
}


Measured memory_bytes: 3580
# = map(int, input().split())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input()) - 1
print(a[k])


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


int n, X, Y;
string mes[9];

int bomb(int a, int b){
	if( a < 1 || a > 8 || b < 0 || b > 7){
		return 0;
	}
	else{
		if (mes[a][b] == '1') {
			mes[a][b] = '0';
			bomb(a-1,b );
			bomb(a-2, b);
			bomb(a-3, b);
			bomb(a+1, b);
			bomb(a+2, b);
			bomb(a+3, b);
			bomb(a, b-1);
			bomb(a, b-2);
			bomb(a, b-3);
			bomb(a, b+1);
			bomb(a, b+2);
			bomb(a, b+3);
			return 0;
		}
		else{
			return 0;
		}
	}
}

int main(){
	cin >> n;
	for(int z=1;z<n+1;z++){
		for(int k = 1;k<9;k++){
			cin >> mes[k];
		}
		cin >> X >> Y;
		bomb(Y, X-1);
		cout << "Data " << z << ":" << endl;
		for(int e=1;e<9;e++){
			cout << mes[e] << endl;
		}
	}
	return 0;
}

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

int main()
{
  int a, b, c, big;
  long long int x, y, x_amari, y_amari, money, ans;
  long long int i, ooi, data_i, data_x, data_y;
  ans = INT_MAX;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  cin >> y;
  big = c*2;
  ooi = max(x, y);
  for(i=0; i<=ooi; i++)
  {
    x_amari = x-i;
    y_amari = y-i;
    if(x_amari < 0)x_amari = 0;
    if(y_amari < 0)y_amari = 0;
    money = big*i;
    money += a*x_amari;
    money += b*y_amari;
    ans = min(ans, money);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// 0 1 1
// 1 0 1
// 0 1 1

// 行列
template <typename R>
struct Matrix {
    vector<vector<R>> a;
    Matrix() {}
    Matrix(int n, int m) : a(n, vector<R>(m)) {}
    int h() const { return a.size(); }
    int w() const { return a[0].size(); }
    vector<R> &operator[](size_t i) { return a[i]; }
    const vector<R> &operator[](size_t i) const { return a[i]; }
    Matrix &operator*=(const Matrix &b) {
        assert(w() == b.h());
        int n = h(), m = w(), r = b.w();
        Matrix c(n, r);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < r; j++)
                for (int k = 0; k < m; k++) c[i][j] += a[i][k] * b[k][j];
        return *this = c;
    }
    static Matrix I(int n) {
        Matrix m(n, n);
        for (int i = 0; i < n; i++) m[i][i] = 1;
        return m;
    }
};

template <typename R>
inline ostream &operator<<(ostream &os, const Matrix<R> &m) {
    os << "[" << endl;
    rep(i, 0, m.h()) {
        rep(j, 0, m.w()) { os << " " << m[i][j]; }
        os << endl;
    }
    os << "]" << endl;
    return os;
}

int MAX = 1000000000000000000LL;
// Verified: https://atcoder.jp/contests/dp/submissions/4906423
template <typename R>
Matrix<R> pow(Matrix<R> a, unsigned long long k) {
    Matrix<R> r = Matrix<R>::I(a.h());
    while (k) {
        if (k & 1) r *= a;
        a *= a;
        k >>= 1;
    }
    return r;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    Matrix<int> m(3, 3);
    rep(i, 0, 3) rep(j, 0, 3) {
        if (i == j) continue;
        m[i][j] = 1;
    }
    auto r = pow(m, K);
    dump(r);
    Matrix<int> x(3, 1);
    x[0][0] = A;
    x[1][0] = B;
    x[2][0] = C;
    r *= x;
    dump(r);
    if (r[0][0] - r[1][0] > MAX) {
        cout << "Unfair" << endl;
    } else {
        cout << r[0][0] - r[1][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int M_NUM = 2 * 123457;
bool prime[M_NUM + 1];

void put_prime()
{
    for (int i = 0; i < M_NUM; i++)
        prime[i] = true;

    prime[0] = prime[1] = false;
    for (int i = 2; i * i < M_NUM; i++) 
        if (prime[i])
            for (int j = 2 * i; j < M_NUM; j += i)
                prime[j] = false;
}

int main()
{
    int n;

    put_prime();

    while (cin >> n, n) {
        int ans = 0;

        for (int i = n + 1; i <= 2 * n; i++)
            if (prime[i])
                ans++;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int n,x,y,color,ans;
int a[100010];

int main(){
	scanf("%d",&n);
	color=0;
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		color=max(color,a[i]);
	}
	for (int i=1;i<=n;++i){
		if (color-1>a[i]){
			puts("No");
			return 0;
		}
		if (color-1==a[i]) ++x;
	}
	y=n-x;
	if (x==0 && color==n-1){
		puts("Yes");
		return 0;
	}
	if (color==x){
		puts("No");
		return 0;
	}
	if (y/(color-x)>1) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 512
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        w: u64,
        h: u64,
        x: u64,
        y: u64
    };

    let center_x = w as f64 / 2.0;
    let center_y = h as f64 / 2.0;

    if center_x == x as f64 && center_y == y as f64 {
        println!("{} 1", (w * h) as f64 / 2.0);
    } else {
        println!("{} 0", (w * h) as f64 / 2.0);
    }
}


Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  string s;cin>>s;
  int front=0;
  int rear=0;
  bool flag=true;
  for(int i=n-1;i>=0;--i){
    if(!flag){
      if(s[i]==')'){
        flag=true;
        ++front;
      }
    }
    else{
      if(s[i]==')')++front;
      else --front;
      if(front<0)front=0;
    }
  }
  flag=true;
  for(int i=0;i<n;++i){
    if(!flag){
      if(s[i]=='('){
        flag=true;
        ++rear;
      }
    }
    else{
      if(s[i]=='(')++rear;
      else --rear;
      if(rear<0)rear=0;
    }
  }
  rep(i,front){
    cout<<'(';
  }
  cout<<s;
  rep(i,rear){
    cout<<')';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 200005
#define M N*8
int n, m, a[N], b[N];
int f[M], g[M], flag[M], sum[M], p[M];
void pushup(int t){
	f[t]=min(f[t<<1], f[(t<<1)+1]);
	if (p[t<<1]+g[t<<1]<p[(t<<1)+1]+g[(t<<1)+1])
		p[t]=p[t<<1],
		g[t]=g[t<<1];
	else
		p[t]=p[(t<<1)+1],
		g[t]=g[(t<<1)+1];
}
void build(int t, int l, int r){
	if (l==r){
		f[t]=p[t]=-l;
		g[t]=l;
		return;
	}
	int mid=l+r>>1;
	build(t<<1,l,mid);
	build((t<<1)+1,mid+1,r);
	pushup(t);
}
void pushdown(int t, int l, int r){
	if (flag[t]){
		int mid=l+r>>1;
		f[t<<1]=f[(t<<1)+1]=f[t];
		p[t<<1]=p[(t<<1)+1]=f[t];
		g[t<<1]=l;
		g[(t<<1)+1]=mid+1;
		sum[t<<1]=sum[(t<<1)+1]=0;
		flag[t<<1]=flag[(t<<1)+1]=1;
		flag[t]=sum[t]=0;
	}
	if (sum[t]){
		f[t<<1]+=sum[t];
		p[t<<1]+=sum[t];
		sum[t<<1]+=sum[t];
		f[(t<<1)+1]+=sum[t];
		p[(t<<1)+1]+=sum[t];
		sum[(t<<1)+1]+=sum[t];
		sum[t]=0;
	}
}
void add(int t, int l, int r, int le, int ri){
	if (le<=l && r<=ri){
		f[t]++;
		p[t]++;
		sum[t]++;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) add(t<<1, l, mid, le, ri);
	if (ri>mid) add((t<<1)+1, mid+1, r, le, ri);
	pushup(t);
}
void upd(int t, int l, int r, int le, int ri, int x){
	if (le<=l && r<=ri){
		flag[t]=1;
		f[t]=p[t]=x;
		g[t]=l;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) upd(t<<1, l, mid, le, ri, x);
	if (ri>mid) upd((t<<1)+1, mid+1, r, le, ri, x);
	pushup(t);
}
int query(int t, int l, int r, int x){
	if (r<=x) return f[t];
	pushdown(t,l,r);
	int mid=l+r>>1;
	int mi=9999999;
	if (x>mid) mi=min(query((t<<1)+1, mid+1, r, x), mi);
	mi=min(query(t<<1,l,mid,x), mi);
	return mi;
}
int main(){
	n=read(), m=read();
	for (int i=1;i<=n;i++) a[i]=read(), b[i]=read();
	build(1,1,m);
	for (int i=1;i<=n;i++){
		int mi=a[i]>1?query(1,1,m,a[i]-1):999999;
		upd(1,1,m,a[i],b[i],mi+1);
		if (a[i]>1) add(1,1,m,1,a[i]-1);
		if (b[i]<m) add(1,1,m,b[i]+1,m);
		if (f[1]>=999999) puts("-1");
		else printf("%d\n", p[1]+g[1]);
	}
    return 0;
}
/*
4 4
3 4
1 1
2 3
2 4
*/

Measured memory_bytes: 15432
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){

	int a,b;
	cin>>a>>b;
	if(a<=5)cout<<0<<endl;
	else if(a<=12)cout<<b/2<<endl;
	else cout<<b<<endl;

	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  no.3
//
//  Created by MacBook_Virgo on 2015/05/12.
//  Copyright (c) 2015??´ MacBook_Virgo. All rights reserved.
//

#include <iostream>
#define rep(i,n) for(int (i) = 0;(i) < (n); (i)++)
using namespace std;
int n,r,p,c;
int main(int argc, const char * argv[]) {
    while(cin >> n >> r,(n!=0)||(r!=0)){
        int A[2][60];
        rep(i,n){
            A[0][i] = n-i;
        }
        int now = 0;
        int next = 1;
        rep(i,r){
            cin >> p >> c;
            rep(j,c){A[next][j]=A[now][p-1+j];}
            for(int j = p+c-1; j < n; j++){
                A[next][j] = A[now][j];}
            for(int j = c; j<c+p-1; j++){
                A[next][j] = A[now][j-c];}
            int temp;
            temp = now;
            now = next;
            next = temp;
            
        }
        cout << A[now][0] << endl;
    }
    
    return 0;
}

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

const long long MOD = 1e9 + 7;

int main(){

    long long n, m; cin >> n >> m;

    vector<vector<char>> grid(n + 2, vector<char>(m + 2, '#'));
    for(long long i = 1; i <= n; i++){
    	for(long long j = 1; j <= m; j++){
    		cin >> grid[i][j];
    	}
    }

    vector<vector<long long>> dp(n + 2, vector<long long>(m + 2, 0));
    dp[1][1] = 1;

    for(long long i = 1; i <= n; i++){
    	for(long long j = 1; j <= m; j++){
    		if(grid[i][j + 1] == '.'){
    			dp[i][j + 1] += dp[i][j];
    			dp[i][j + 1] %= MOD;
    		}
    		if(grid[i + 1][j] == '.'){
    			dp[i + 1][j] += dp[i][j];
    			dp[i + 1][j] %= MOD;
    		}
    	}
    }

    cout << dp[n][m];
	
	return 0;
}

Measured memory_bytes: 9216
lines = STDIN.read.split("\n")
lines.each do |line|
  m, f, r = line.split(" ").map(&:to_i)
  break if m == -1 && f == -1 && r == -1
  n = m + f
  if m == -1 || f == -1
    puts "F"
  elsif 80 <= n
    puts "A"
  elsif 65 <= n
    puts "B"
  elsif 50 <= n
    puts "C"
  elsif 30 <= n
    if 50 <= r
      puts "C"
    else
      puts "D"
    end
  else
    puts "F"
  end
end

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

signed main(){
  
  string s;  
  cin>>s;
  
  int len = (int)s.size();
  int ans = 0;
  
  for(int i=0;i<(1<<(len-1));i++){
    
    int num = 0, sum = 0;
    
    for(int j=0;j<len;j++){
      
      num = num * 10 + s[j] - '0';
      
      if( ( i >> j & 1 ) || j == len - 1 ){
	sum += num;
	num = 0;
      }
      
    }
    
    ans += sum;
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
N, Y = [int(_) for _ in input().split()]

for i in range(N+1):
    p = (Y - 9000 * i - 1000 * N) // 4000
    q = N - i - p
    if p < 0 or q < 0:
        continue
    if 10000 * i + 5000 * p + 1000 * q == Y:
        print(i, p, q)
        exit(0)
print(-1, -1, -1)


Measured memory_bytes: 9120
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int h, w, K;
    cin >> h >> w >> K;
    K--;  // Kを0-indexにする

    vector<vector<ll>> dp(h+1, vector<ll>(w));  // dp[i+1][j] : i行目を通過した直後にj列目にいる場合の数のmodでの剰余(i,jは0-index)

    dp[0][0] = 1LL;
    rep(i, h) {
        rep(j, w) {
            for(int b = 0; b < (1 << (w-1)); b++) {  // bのjビット目が1ならj列目とj+1列目の間に横棒を引き、0なら引かない
                
                // 横棒がつながっていないか調べる
				int flag = 1;
				rep(L, w-2) {
					if ( (b & (1 << L)) && (b & (1 << (L+1))) ) {  // bのLビット目もL+1ビット目も1のとき
						flag = 0;  // 横棒はつながっている
					}
				}

                //横棒がつながっていないとき
                if(flag) {
                    // bのj-1ビット目が1だったら、j列目からj-1列目に移動する(左方向に横棒を通過する場合)
                    if( j >= 1 && (b & (1 << (j-1))) ) {
                        dp[i+1][j-1] += dp[i][j];
                        dp[i+1][j-1] %= mod;
                    }
                    // bのjビット目が1だったら、j列目からj+1列目に移動する(右方向に横棒を通過する場合)
                    else if( j <= w-2 && (b & (1 << j)) ) {
                        dp[i+1][j+1] += dp[i][j];
                        dp[i+1][j+1] %= mod;
                    }
                    // 横棒を通過せず下に降りる場合
                    else {
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= mod;
                    }
                }

            }
        }
    }

    cout << dp[h][K] << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

// input に使うやつ
var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// string から int へ
func atoi(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

// 一つの文字を int として読み込み
func readInt() int {
	return atoi(readLine())
}

// 複数の文字を int のスライスとして読み込み
func readInts() []int {
	in := readLine()
	ins := strings.Split(in, " ")
	out := make([]int, len(ins))
	for i, v := range ins {
		out[i] = atoi(v)
	}
	return out
}

// sortしたスライスを返す
func sorted(a []int) []int {
	sort.Ints(a)
	b := a
	return b
}

// 逆順のsort
func reverse(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	b := a
	return b
}

func main() {
	in := readInts()
	n := in[0]
	d := in[1]

	var c int
	a := 2*d + 1
	if n%a != 0 {
		c = (n / a) + 1
	} else {
		c = n / a
	}
	// for i := 1; i <= n; i++ {
	// 	a := i + d - (i - d) + 1
	// 	if n%a != 0 {
	// 		c = (n / a)
	// 	}
	// }
	fmt.Println(c)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const MOD = 10007LL;

int main() {
  ll N, K;
  cin >> N >> K;
  if (K % 2 == 0) {
    ll cnt_zero = 0, cnt_half = 0;
    for (int i = 1; i <= N; i++) {
      if (i % K == 0) cnt_zero++;
      if (i % K == K / 2) cnt_half++;
    }
    ll comb_zero = cnt_zero * cnt_zero * cnt_zero;
    ll comb_half = cnt_half * cnt_half * cnt_half;
    cout << comb_zero + comb_half << endl;
  } else {
    ll cnt_zero = 0;
    for (int i = 1; i <= N; i++) {
      if (i % K == 0) cnt_zero++;
    }
    ll comb_zero = cnt_zero * cnt_zero * cnt_zero;
    cout << comb_zero << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main () {
    long long int n, m;
    
    scanf("%lld%lld", &n, &m);
    
    if (n * 2 >= m) {
        printf("%lld", m / 2);
    }
    else {
        printf("%lld", (m + 2 * n) / 4);
    }
}

Measured memory_bytes: 128