akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int n, m, a, b;
vector<int> edge[108000];
vector<P> ans;
int dep[108000];
bool come[108000];

int dfs(int x, int last){
    int cnt = 0;
    int deg = 0;
    come[x] = true;
    vector<P> tmp;
    for(auto to:edge[x]){
        if(to == last)continue;
        if(come[to]){
            if(dep[to] < dep[x]){
                ans.push_back(P(x, to));
                deg++;
            }
        }
        else{
            dep[to] = dep[x] + 1;
            int tocnt = dfs(to, x);
            if(tocnt % 2 == 1)ans.push_back(P(to, x));
            else ans.push_back(P(x, to));
            cnt += tocnt;
            deg++;
        }
    }
    //cout << x << " " << cnt << " "<< deg << endl;
    return cnt + (deg % 2);
}

int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        cin >> a >> b;
        a--,b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    if(dfs(0,-1) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }

    for(auto p:ans)cout << p.first+1 << " " << p.second+1 << endl;

    return 0;
}


Measured memory_bytes: 18672
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */

#include <bits/stdc++.h>

using namespace std;


using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 58) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

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

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

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< typename T >
vector< T > convert_base(T x, T b) {
  vector< T > ret;
  T t = 1, k = abs(b);
  while(x) {
    ret.emplace_back((x * t) % k);
    if(ret.back() < 0) ret.back() += k;
    x -= ret.back() * t;
    x /= k;
    t *= b / k;
  }
  if(ret.empty()) ret.emplace_back(0);
  reverse(begin(ret), end(ret));
  return ret;
}

int main() {
  int N, K;
  cin >> N >> K;
  cout << convert_base(N, K).size() << endl;

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ar array
#define pii pair<int, int>

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

    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1, 0), b(m + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i + 1];
        a[i + 1] += a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i + 1];
        b[i + 1] += b[i];
    }
    int ans = 0;
    for (int i = 0, j = m; i <= n; i++) {
        if (a[i] > k) break;
        while (a[i] + b[j] > k) j--;
        ans = max(i + j, ans);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6328
m[52][52],C;
R(x,y){
	int i,j;
	if(m[x][y]){
		m[x][y]=0;
		for(i=-1;i<=1;i++)
			for(j=-1;j<=1;j++)
				if(i|j)
					R(x+i,y+j);
	}
}
main(){
	int w,h,x,y;
	for(;scanf("%d%d",&w,&h),w;){
		memset(m,0,sizeof(m));
		for(y=1;y<=h;y++)
			for(x=1;x<=w;x++)
				scanf("%d",&m[x][y]);
		C=0;
		for(y=1;y<=h;y++)
			for(x=1;x<=w;x++)
				if(m[x][y]){
					C++;
					R(x,y);
				}
		printf("%d\n",C);
	}
	exit(0);
}

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

int main() {
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  for(int i = 0; i < n; i++){
    ll x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>

using namespace std;
int main(){
  int N;
  cin >> N;
  int t = 0,x = 0,y = 0;
  for(int i=0;i<N;++i){
    int newt,newx,newy;
    cin >> newt >> newx >> newy;
    int diff = (newt-t) - abs(newx-x) - abs(newy-y);
    if( diff < 0 || diff % 2 == 1 ){
      cout << "No" << endl;
      return 0;
    }
    t = newt , x = newx , y = newy;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}
int main(){
    int x; cin >> x;
    for(int i=x;i<1000000;i++){
        if(is_prime(i)){
            cout << i << endl;
            return 0;
        }
    }
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意)，根の場合は"-(要素数）"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        all_group_members():{根要素：[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            #根を探す&つなぎかえる
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
    ################
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか2,3,4,5,1もダメ．でも2,3,4,5,2はOK
    
    #普通にB:4,5,1,2,3みたいなのもダメ，Bが輪になっているとダメか
    #Bがある地点から昇順になるなら，つなげば1つのグループができる
    
    A1=sorted(A)
    B1=sorted(B)
    
    from collections import defaultdict
    dd = defaultdict(int)
    
    #Bの数字と順番を対応させる．Bないにかぶりがあるときはflag2で引っかかるはず?
    
    for i in range(N):
        dd[B1[i]]=i
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    flag2=0#sortずみのB[i]を1箇所ずらしても条件を満たしうるか，これが1ならOK
    
    for i in range(N-1):
        if B1[i]>=A1[i+1]:
            flag2=1
            break
        
    flag3=0#巡回かどうか
    uf=UnionFind(N)
    
    for i in range(N):
        a=dd[B[i]]
        b=dd[B1[i]]
        uf.union(a,b)
    
    if uf.group_count()==1:
        flag3=1
        
    if flag2==0 and flag3:
        flag=0
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var list = new List<long>();
            var list_p = new List<long>();
            var sa = new List<long>();



            for (long i = 1; i <= Math.Sqrt(N) ; i++)
            {
                if (N % i == 0)
                {
                    list.Add(i);
                    list_p.Add(N / i);
                    sa.Add(Math.Abs(N / i - i));
                }
            }

            var A = sa.IndexOf(sa.Min());

            Console.WriteLine(list[A] + list_p[A] - 2);
        }
    }
}


Measured memory_bytes: 13408
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>
#include<map>
using namespace std;
int main() {
	long long int N, M;
	cin >> N >> M;
	long long int Y = pow(2, M)*(1900 * M + 100 * (N - M));

	cout << Y << endl;
	return 0;
}


Measured memory_bytes: 256
N = input()

B = [map(int,raw_input().split()) for i in range(N)]

A = [map(int,raw_input().split()) for i in range(N)]


A.sort()
B.sort()

for i in A:
    maxy = -1
    for j in B:
        if i[0] > j[0]:
            if maxy < j[1] and i[1] > j[1]:
                maxy = j[1]
                memory = j
        else:
            break
    if maxy != -1:
        B.remove(memory)

print len(A)-len(B)

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

int main(){
    char a,b;
    cin>>a>>b;
    int x,y;
    x=a-'0';
    y=b-'0';
    if(x>y)cout<<">";
    else if(x==y)cout<<"=";
    else cout<<"<";
}


Measured memory_bytes: 256
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
     
    var treasures = +input[read++];
    var pdp = new Int32Array(maxWeight + 1);
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
 
      var dp = new Int32Array(maxWeight + 1);
      for(var w = 1; w <= maxWeight; w++){
        if(w - tw < 0){
          dp[w] = pdp[w];
        }else{
          dp[w] = max(pdp[w-tw] + tv, pdp[w]);
        }
      }
      pdp = dp;
    }
 
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      var pdpi = pdp[i];
      if(pdpi > resultCost){
        resultCost = pdpi;
        resultWeight = i;
      }
    }
     
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

Measured memory_bytes: 14396
N = int(input())
S = sorted([input() for _ in range(N)]) + ['']
ans = []
tmpnum = 1
tmpmax = 1

for i in range(1, N+1):
    if S[i] == S[i-1]:
        tmpnum += 1
    else:
        if tmpnum == tmpmax:
            ans.append(S[i-1])
            tmpnum = 1
        elif tmpnum > tmpmax:
            tmpmax = tmpnum
            ans = [S[i-1]]
            tmpnum = 1
        else:
            tmpnum = 1

for i in ans:
    print(i)

Measured memory_bytes: 20176
'use strict'
function Main(input){
  input=input.split(/\s+/);
  for(let i=0;i<input.length;i++)
    input[i]=parseInt(input[i]);
  var N=input.shift();
  var C=input.shift();
  var D=[];
  for(let i=0;i<C;i++){
    D[i]=[];
    for(let j=0;j<C;j++)
      D[i][j]=input[C*i+j];
  }
  var c=[];
  for(let i=0;i<N;i++){
    c[i]=[];
    for(let j=0;j<N;j++)
      c[i][j]=input[C*C+N*i+j]-1;
  }
  var group=[[],[],[],];//各グループの各色の数を納めた配列
  for(let i=0;i<3;i++)
    for(let j=0;j<C;j++)
      group[i][j]=0;
  for(let i=0;i<N;i++)
    for(let j=0;j<N;j++)
      group[(i+j)%3][c[i][j]]++;
  var cost=[[],[],[]];//cost[i][j]でgroup[i]を色jに揃える違和感
  for(let i=0;i<3;i++)
    for(let j=0;j<C;j++){
      cost[i][j]=0;
      for(let k=0;k<C;k++){
        cost[i][j]+=group[i][k]*D[k][j];
      }
    }
  var bestColors=[[],[],[],];//各groupのbest3を出して全探索
  var bestScores=[[],[],[],];//bestColorsに対応するScore
  for(let i=0;i<3;i++)
    for(let j=0;j<3;j++){
      bestScores[i][j]=Math.min.apply(null,cost[i]);
      bestColors[i][j]=cost[i].indexOf(bestScores[i][j]);
      cost[i][bestColors[i][j]]=Infinity;
    }
  var candidates=[];
  var score=[];
  var color=[];
  for(let i=0;i<3;i++){
    color[0]=bestColors[0][i]
    score[0]=bestScores[0][i];
    for(let j=0;j<3;j++){
      color[1]=bestColors[1][j];
      if(color[0]===color[1])continue;
      score[1]=bestScores[1][j];
      for(let k=0;k<3;k++){
        color[2]=bestColors[2][k];
        if(color[0]===color[2]||color[1]===color[2])continue;
        score[2]=bestScores[2][k];
        candidates.push(score[0]+score[1]+score[2]);
      }
    }
  }
  var min=Math.min.apply(null,candidates);
  console.log(min);
}

var fs=require('fs');
var I=fs.readFileSync('/dev/stdin','utf8');
Main(I);

Measured memory_bytes: 58516
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,ar[]={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};
  cin>>n;
  cout<<ar[n-1]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n;
  cin>>n;
   vector<int> a(n);
   for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
     vector<int> ans(n);
for (int i = 0; i < n; i++) {
  ans[a[i]-1]=i+1;
}
  for (int i = 0; i < n; i++) {
 cout<< ans[i]<< " "<<endl;
}
  
}


Measured memory_bytes: 1664
/*
ID: grandea2
PROG: transform
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> vec;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int>par;
typedef vector<par>vpar;
#define forn(i,n) for(int i=0;i<n;i++)
#define wez(n) ll (n); cin>>(n);
#define setmax(a,b) (a)=max((a),(b))
#define setmin(a,b) (a)=min((a),(b))
#define pb push_back
#define mp make_pair
const ll inf = 1e18+1;
const ll mod=1e9+7;
double pie=3.1415926535897;
#define outa(a,e) forn(i,e) cout << a[i] << (i==e-1?'\n':' ')
#define oute(n) cout<<n<<"\n"
string s;
int n;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("transform.in", "r", stdin);
    freopen("transform.out", "w", stdout);
    #endif
    */
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt","w",stderr);
    #endif*/
    ll n,w;
    cin>>n>>w;
    vector<ll> dp(w+1,0);
    ll weight ,value;
    forn(i,n){
        cin>>weight>>value;
        for(ll curr=w-weight;curr>=0;curr--){
            dp[curr+weight]=max(dp[curr+weight],dp[curr]+value);
        }
    }
    ll answer=0;
    for(int i=1;i<w+1;i++){
        answer=max(answer,dp[i]);
    }
    cout<<answer<<endl;
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    long long int n;
    long long int c;
    long long int i;
    scanf("%lld",&n);


   
    c = 0;
    for (i = 0; i <= n; i++)
    {
       if (i % 3 != 0 && i % 5 != 0)
          c = c + i;
    }
    printf("%lld", c);
    return (0);
}


Measured memory_bytes: 1736
s = input()

s1 = int(s[:2])
s2 = int(s[2:])

def check(s1, s2):
    if 1 <= s1 <= 12 and 1 <= s2 <= 12:
        return 'AMBIGUOUS'
    if 1 <= s1 <= 12:
        return 'MMYY'
    if 1 <= s2 <= 12:
        return 'YYMM'
    return 'NA'

print(check(s1, s2))


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define maxn 5010
#define maxint 0x7fffffff/2
using namespace std;
int gcd(int x,int y) {
	if(y==0) return x;
	return gcd(y,x%y);
}
int main() {
	int n;
	cin>>n;
	int sum=0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			for(int k=1; k<=n; k++) {
				sum+=gcd(gcd(i,j),k);
			}
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<3;i++){
		if(s.substr(i,1)=="o"){
			cnt++;
		}
	}
	cout<<700+cnt*100<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

# define pi           3.14159265358979323846 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,n;
  vector<int> has(101,0);
  cin >> x >> n;
  REP(i,n) {
    int p;
    cin >> p;
    has[p] = 1;
  }
  int diff = 0;
  int pos = x;
  while(1) {
    if( pos - diff < 1 && pos + diff > 100 ) {
      break;
    }
    if( has[pos - diff] == 0){
      cout << pos - diff << endl;
      break;
    }
    else if( has[pos + diff] == 0 ) {
      cout << pos + diff << endl;
      break;
    }
    diff ++;
  }
  return 0;
}



Measured memory_bytes: 3188
[A,B,C]=[int(i) for i in input().split()]
if A==B:
	if B!=C:
		print("Yes")
	else:
		print("No")
else:
	if B==C:
		print("Yes")
	else:
		if A==C:
			print("Yes")
		else:
			print("No")

Measured memory_bytes: 38256
import itertools as it

n = int(input())
lst = []
for i in range(n):
	x, y = list(map(int, input().split()))
	lst.append([x, y])
perm = list(it.permutations(lst))

cost = []
for i in perm:
	temp = 0
	for j in range(len(i)-1):
		temp += (((i[j][0] - i[j+1][0])**2) + ((i[j][1] - i[j+1][1])**2))**0.5
	cost.append(temp)

print(sum(cost) / len(cost))

Measured memory_bytes: 15600
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        a=0
        for i in range(1,n+1):
            for j in range(2,n+1):
                for k in range(3,n+1):
                    if i+j+k==x and i<j and j<k :
                        a+=1
        print(a)


Measured memory_bytes: 5596
#[allow(unused)]
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    // 複数行ベクトル
    let mut a: Vec<Vec<usize>> = Vec::new();
    for _ in 0..n {
        let a_i = {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right().to_owned();
            s.split_whitespace().map(|x| x.parse().unwrap()).collect()
        };
        a.push(a_i)
    }

    let mut result = vec![vec![a[0][0], a[0][1], a[0][2]]];
    for i in 0..n-1 {
        result.push(vec![0; 3]);
        for curr in 0..3 {
            for next in 0..3 {
                if curr != next {
                    result[i + 1][next] = std::cmp::max(result[i + 1][next], result[i][curr] + a[i + 1][next])
                }
            }
        }
    }

    let max = result[n - 1].iter().max().unwrap();
    println!("{}", max);
}


Measured memory_bytes: 18684
#include <iostream>
#include <vector>
#include <map>
#include <string>

#define PI 3.14159265359	

using namespace std;

int main(){
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++){
		if (65 <= s[i] && s[i] <= 90) cout << (char)(s[i] + 32);
		else if (97 <= s[i] && s[i] <= 122) cout << (char)(s[i] - 32);
		else cout << s[i];
	}
	cout << endl;
}

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

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

	long long a;
	long long res = 1;

	for (int i = 0; i < n; ++i)
	{
		cin >> a;

		if (a == 0) 
		{
			res = 0;
			break;
		}

		else if (log10(res) + log10(a) > 18 || res * a > (long long) 1e18)
		{
			res = -1;
		}

		else if (res > 0)
		{
			res *= a;
		}
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3988
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
const int MAX=50;
//ここまでテンプレ
int main(){
	ll X,Y;
	cin>>X>>Y;
	ll len=1;
	for(X;X<=Y;X*=2,len++);
	cout<<len-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
  string S;
  cin >> S;

  if(S == "ARC"){
    cout << "ABC" << endl;
  }
  else{
    cout << "ARC" << endl;
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
	long long a[55][2];
	long long b[55][2];
	int n,m,i,j,k,x,y;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i][0] >> a[i][1];
	}
	for(i=0;i<m;i++){
		cin >> b[i][0] >> b[i][1];
	}

	for(i=0;i<n;i++){
		k=abs(a[i][0]-b[0][0])+abs(a[i][1]-b[0][1]);
		x=k;
		y=0;
		for(j=1;j<m;j++){
			k=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
			if(k<x){
				x=k;
				y=j;
			}
		}
		cout << y+1 << endl;
	}
	cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
tmp = 1
ans = 0
for i in range(n):
    if a[i] == tmp:
        tmp += 1
        ans += 1
if ans == 0:
    print(-1)
else:
    print(n-ans)

Measured memory_bytes: 70988
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define M 1000000
#define N 10000

int main(){
	
	int i;
	int count=0;
	int *ans;
	int str_length;
	int cmp_length;
	char *str;
	char *cmp;
	
	str = (char *)malloc(sizeof(char) * M);
	cmp = (char *)malloc(sizeof(char) * N);
	ans = (int *)malloc(sizeof(int) * M);
	
	scanf("%s %s",str,cmp);
	
	str_length = strlen(str);
	cmp_length = strlen(cmp);
	
	 for(i=0;i<str_length;i++){
	if( strncmp(str+i,cmp,cmp_length) ==0 ){
	ans[count] = i;
	count++;
	 }
	}
	
	for(i=0;i<count;i++){
	printf("%d\n",ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 5476
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<string,string> P;

int N;
string S;
LL g()
{
	int t[18]={};
	for(int i=0;i<N;i++){
		t[i+N]=1;
	}
	LL ret=0;
	do{
		int p=0;
		int q=2*N-1;
		bool ok=true;
		for(int i=0;i<N;i++){
			while(t[p]){
				p++;
			}
			while(!t[q]){
				q--;
			}
			if(S[p]!=S[q]){
				ok=false;
				break;

			}
			p++;
			q--;
		}
		if(ok){
			ret++;
		}
	}while(next_permutation(t,t+2*N));
	return ret;
}

map<P,int> r;
LL ret=0;
string c;
void f(string& a,string& b, int k,int m)
{
	if(c.size()==k){
		if(m==0){
			//cerr << a << ", " << b << endl;
			r[P(a,b)]++;
		}
		else{
			//cerr << a << ", " << b << ": " << r[P(a,b)]<<endl;
			ret+=r[P(a,b)];
		}
		return;
	}
	a.push_back(c[k]);
	f(a,b,k+1,m);
	a.pop_back();
	b.push_back(c[k]);
	f(a,b,k+1,m);
	b.pop_back();
}

int main() {
	cin >> N >> S;
	c=S.substr(0,N);
	//cerr << c << endl;
	string a,b;
	f(a,b,0,0);
	c=S.substr(N,N);
	reverse(c.begin(),c.end());
	//cerr << c << endl;
	f(a,b,0,1);
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 86272
#include <bits/stdc++.h>
#define int int64_t
#define rp(i, N) for(int i=0; i<N; i++);
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int A, B; cin >> A >> B;
	int ans = A+B;
	if (ans < A-B) ans = A-B;
	if (ans < A*B) ans = A*B;

	cout << ans << endl;
}


Measured memory_bytes: 256
list_gra = []
while True:
    m, f, r = list(map(int, input().split()))
    if m == -1 and f == -1 and r == -1:
        break
    list_gra.append([m, f, r])
for count in range(len(list_gra)):
    if list_gra[count][0] >= 0 and list_gra[count][1] >= 0:
            if sum(list_gra[count][: 2]) >= 80:
                print("A")
            elif 65 <= sum(list_gra[count][: 2]) < 80:
                print("B")
            elif 50 <= sum(list_gra[count][: 2]) < 65:
                print("C")
            elif 30 <= sum(list_gra[count][: 2]) < 50 and list_gra[count][2] < 50:
                print("D")
            elif 30 <= sum(list_gra[count][: 2]) < 50 and list_gra[count][2] >= 50:
                print("C")
            elif 0 <= sum(list_gra[count][: 2]) < 30:
                print("F")
    else:
        print("F")


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

using namespace std;

//#define FILE_IO

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int N, A, B;
    scanf("%d%d%d", &N, &A, &B);

    if(A > B)
    {
        printf("0\n");
        return 0;
    }

    if(N >= 3)
    {
        long long ans = 1LL * (N - 2) * (B - A) + 1;
        printf("%lld\n", ans);
        return 0;
    }

    if(N == 2)
    {
        printf("1\n");
        return 0;
    }

    if(N == 1 && A == B)
    {
        printf("1\n");
        return 0;
    }

    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin >> n >> k;
	vector<int> h(n);
	for(auto &x:h) cin >> x;
	vector<int> dp(n,inf);
	dp[0] = 0; dp[1] = abs(h[1]-h[0]);
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j < n) dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

ll f(ll b, ll n) {
  ll ans = 0;
  while(n > 0) {
    ans += n % b;
    n /= b;
  }
  return ans;
}

ll solve(ll n, ll s) {
  if (n < s) {
    return -1;
  }
  if (n == s) {
    return n + 1;
  }
  
  for (ll b = 2; b * b <= n; b++) {
    if (f(b, n) == s) {
      return b;
    }
  }
  
  ll ans = LLONG_MAX;
  for (ll p = 1; p * p < n; p++) {
    ll b = (n - s) / p + 1;
    if (b <= 1) {
      continue;
    }
    if (f(b, n) == s) {
      ans = min(ans, b);
    }
  }
  if (ans != LLONG_MAX) {
    return ans;
  }
  return -1;
}

int main(){
  ll n, s;
  cin >> n >> s;
  cout << solve(n, s) << endl;
  return 0;
}


Measured memory_bytes: 256
#define	Rd(s) scanf("%d",&s)
#define	Rs(s) scanf("%s",&s)
#define	Rf(s) scanf("%f",&s)

#define RTNd(n,s,i) for(int i=0;(i<n)?scanf("%d",&s),true:false;i++)
#define RTNf(n,s,i) for(int i=0;(i<n)?scanf("%lf",&s),true:false;i++)

#define RTEs(s) while(fgets(s,sizeof(s),stdin)!=NULL)
#define RTEc(s) while(scanf("%c",&s)!=EOF)

#define Pd(s) printf("%d",s);
#define Pf(s) printf("%f",s);

#define Pn printf("\n");

#define SORTV(v) sort(v.begin(),v.end())
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#include<stdio.h>

int main() {
	int c;
	char st[10000];
	bool e = false,w = false,n = false,s = false;
	fgets(st, 10000, stdin);
	for (int i = 0;i < strlen(st);i++) {
		c = st[i];
		switch (c) {
		case 'W':
			w = true;break;
		case 'N':
			n = true;break;
		case 'S':
			s = true;break;
		case 'E':
			e = true;break;
		}
	}
	if ((w && !e) || (e && !w) || (n && !s) || (s && !n)) {
		printf("No");
	}
	else
		printf("Yes");



	Pn;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
	string s1,s2;
  cin>>s1>>s2;
  rep(i,min(s1.size(),s2.size())) cout<<s1[i]<<s2[i];
	if (s1.size()>s2.size()) cout<<s1[s1.size()-1]<<endl;
	else if (s1.size()<s2.size()) cout<<s2[s2.size()-1]<<endl;
	else cout<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    for(int i = 0 ; i <= x; i++){
        int C = i;
        int T = x - i;
        if(((T * 4) + (C * 2)) == y){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3632
# include "algorithm"
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e5+10;

int A,B,K;
int Num[maxm],Top;

int main(){
	register int i;
	scanf("%d%d%d",&A,&B,&K);
	for(i=1;i<=K;i++){
		Num[++Top]=(A+i-1);
		Num[++Top]=(B-i+1);
	}
	sort(Num+1,Num+1+Top);
	for(i=1;i<=Top;i++){
		if(Num[i]==Num[i-1] || Num[i]<A || Num[i]>B) continue;
		printf("%d\n",Num[i]);
	}
	return 0;
}

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

int H,pre(int i),left(int i),right(int i);
void swap(int *a, int *b);
void maxHeapify(int *A, int i);
void buildmaxHeap(int *A);

int main(){
  int i,*A;
  scanf("%d",&H);
  A=malloc(sizeof(int)*(H+1));
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildmaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

int pre(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

void maxHeapify(int *A, int i){
  int l,r,largest;
  l=left(i);
  r=right(i);
  if(l<=H&&A[l]>A[i]){
    largest=l;
  }
  else{
    largest=i;
  }
  if(r<=H&&A[r]>A[largest]){
    largest=r;
  }
  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(A,largest);
  }
}

void buildmaxHeap(int *A){
  int i;
  for(i=H/2;i>0;i--){
    maxHeapify(A,i);
  }
}



Measured memory_bytes: 3660
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        int k = (N-1)*(N-2)/2;
        if(k < K){
            println(-1);
            return;
        } else{
            int extra = k-K;
            int M = N-1+k-K;
            println(M);
            int n = 1;
            for(int i = 1; i < N; i++)
                println(i+" "+N);
            for(int i = 1; i < N-1 && extra > 0; i++)
                for(int j = i+1; j < N && extra > 0; j++, extra--)
                    println(i+" "+j);                            
        }
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21332
s = input()
n = len(s)

ans = 0
for bit in range(1 << n - 1):
    formula = ""
    for i in range(n):
        formula += s[i]
        if i != n - 1:
            formula += "+" if (bit & 1 << i) else ""
    ans += eval(formula)

if n == 0:
    print(0)
elif n == 1:
    print(int(s))
else:
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,m;cin>>n>>m;
    vin a(n);
    rep(i,n){
        cin>>a[i];
        a[i]%=m;
    }
    vll b(n+1);//b[i]:先頭i個の和
    map<ll,ll> r;
    b[0]=0;
    r[0]++;
    rep(i,n){
        b[i+1]=a[i]+b[i];
        b[i+1]%=m;
        r[b[i+1]]++;
    }
    ll sum=0;ll tmp;
    for (auto p=r.begin();p!=r.end();p++){
        tmp=p->second;
        sum+=tmp*(tmp-1)/2;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,d,ans=0;cin>>n>>d;
  vector<lvector> points(n,lvector(d,0));
  rep(i,n)rep(j,d) cin>>points[i][j];
  for(ll i=0;i<n-1;++i) {
    for(ll j=i+1;j<n;++j) {
      ll dist=0;
      rep(k,d) dist+=(points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
      ll v=round(sqrt(dist));
      if(dist==v*v) ans++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  int i, j;
  vector<bool> isPrime(100010, true);
  vector<bool> is2017(100010, false);
  isPrime[0] = isPrime[1] = false;
  for (i = 0; i < 100005; i++) {
    if (isPrime[i]) {
      for (j = 2; i*j <100005; j++) {
	isPrime[i*j] = false;
      }
      if (isPrime[(i + 1) / 2]) {
	is2017[i] = true;
      }
    }
  }
  vi sum(100010);
  for (i = 1; i < 100005; i++) {
    if (is2017[i]) {
      sum[i] = sum[i - 1] + 1;
    }
    else {
      sum[i] = sum[i - 1];
    }
  }
  int q;
  cin >> q;
  for (int unko = 0; unko < q; unko++) {
    int l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l - 1] << endl;
  }
    
  
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define endl "\n"
#define int long long
typedef long double ld;
typedef vector<vector<int> > matrix;
typedef vector<int> arr;
typedef vector<string> vs;
typedef vector<pair<int,int> > pv;
#define test() int t;cin>>t;while(t--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int bx[]={0,0,1,-1,1,-1,-1,1};
int by[]={1,-1,0,0,1,-1,1,-1};

//=================================================================//
int n;

int dp[100001][3];
int solve(int pos,int i, int arr[][3]) {
    if(pos==n) return 0;

    //recursive case
    int &ans = dp[pos][i];
    if(ans != -1) return ans;


    int op1 = arr[pos][i] + solve(pos+1,(i+1)%3,arr); 
    int op2 = arr[pos][i] + solve(pos+1,(i+2)%3,arr);
    return ans = max(op1,op2);
}

#undef int
int main(){
#define int long long 
    fast;
    cin>>n;
    int arr[n][3];
    FOR(i,0,n-1) cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    memset(dp, -1, sizeof dp);
    int ans1 = solve(0,0,arr);
    int ans2 = solve(0,1,arr);
    int ans3 = solve(0,2,arr);
    cout<<max(ans1,max(ans2,ans3));
    
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

long long k = 0, mn = 1e9, sum = 0;
vector <int > a;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mn = min(mn, (long long)abs(a[i]));
		if (a[i] < 0)
			k++;
		sum += abs(a[i]);
	}
	sum -= mn;
	if (k % 2 == 1)
		mn *= (-1);
	sum += mn;
	cout << sum;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<int> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.assign(n, 1);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

int main() {
        int w, h;
        while (scanf("%d%d", &w, &h), w) {
                vector<vector<int>> s(h, vector<int> (w));
                int lands = 0;
                map<pair<int, int>, int> ptol;
                for (int i = 0; i < h; i ++) {
                        for (int j = 0; j < w; j ++){
                                scanf("%d", &s[i][j]);
                                if (s[i][j]) {
                                        ptol[make_pair(i, j)] = lands;
                                        lands ++;
                                }
                        }
                }
                UnionFind uf(lands);
                auto get = [&](int a, int b) { return ptol[make_pair(a, b)]; };
                for (int i = 0; i < h; i ++) {
                        for (int j = 0; j < w; j ++) {
                                if (s[i][j]) {
                                        if (i - 1 >= 0 && j + 1 < w && s[i - 1][j + 1]) uf.unite(get(i, j), get(i - 1, j + 1));
                                        if (j + 1 < w && s[i][j + 1])                   uf.unite(get(i, j), get(i, j + 1));
                                        if (i + 1 < h && j + 1 < w && s[i + 1][j + 1])  uf.unite(get(i, j), get(i + 1, j + 1));
                                        if (i + 1 < h && s[i + 1][j])                   uf.unite(get(i, j), get(i + 1, j));
                                }
                        }
                }
                printf("%d\n", uf.get());
        }
        return 0;
}

Measured memory_bytes: 3412
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop

X=n0()

def primes(n):
    num = [True]*n
    num[0] = num[1] = False
    for i in range(2,int(n**0.5)+1):
        if num[i]:
            for j in range(i**2, n, i):
                num[j] = False
    return [i for i in range(2,n) if num[i]]

sosuu=primes((10**5)+1000)
while True:
    if X in sosuu:
        print(X)
        break
    X+=1

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

using namespace std;

int main() {

	long n;
	cin >> n;

	vector<long> a(n + 1);
	vector<long> b(n + 1,0	);

	long tmp;

	for (long i = 1; i <= n; i++) {
		cin >> tmp;
		if (n % 2 == 1) {
			if (tmp % 2 != 0) {
				cout << 0 << endl;
				return 0;
			}
			b[tmp / 2]++;
		}
		else {
			if (tmp % 2 != 1) {
				cout << 0 << endl;
				return 0;
			}
			b[(tmp - 1) / 2]++;
		}
	}

	if (n % 2 == 1 && b[0] != 1) {
		cout << 0 << endl;
		return 0;
	}

	long ed = 0;
	ed = n / 2;
	if (n % 2 != 0) { ed++; }

	for (long i = 0; i < ed; i++) {
		if (b[i] != 2) {
			if (i == 0 && n % 2 == 1 && b[i] == 1) {
			}
			else {
				cout << 0 << endl;
				return 0;
			}
		}
	}

	long long ans = 1;
	for (long i = 1; i <= n / 2; i++) {
		ans = (ans * 2) % 1000000007;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1792