akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng (chrono::steady_clock::now().time_since_epoch().count() );

const int md = 1e9 + 7;
const ld PI = 3.14159265;
const ll INF = 1e18;
const int N = 3e3 + 12;

ll dp[N][N];
pair<ll, ll>a[N];
ll n, t;

ll fn (ll idx, ll val) {
    if (val >= t) return 0;
    if (idx >= n) return 0;
    if (dp[idx][val] >= 0) return dp[idx][val];
    ll ans = fn (idx + 1, val);
    dp[idx][val] = max (ans, a[idx].s + fn (idx + 1, val + a[idx].f) );
    return dp[idx][val];
}


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

    memset (dp, -1, sizeof (dp) );

    cin >> n >> t;

    FOR (i, 0, n) cin >> a[i].f >> a[i].s;

    sort (a, a + n);

    cout << fn (0, 0) << '\n';

    return 0;
}


Measured memory_bytes: 71296
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
edges = []
for i in range(M):
    a, b, c = getNM()
    edges.append([a - 1, b - 1, c])

def bellman(edges, num_v):
    dist = [-float('inf') for i in range(num_v)]
    dist[0] = 0

    # 一回目のループ
    for i in range(N - 1):
        for edge in edges:
            if dist[edge[1]] < dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]

    # 負閉路検出
    nega = [0] * N
    for i in range(N):
        for edge in edges:
            if dist[edge[1]] < dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                nega[edge[1]] = 1

    if nega[N - 1]:
        print('inf')
        exit()

    return dist

print(bellman(edges, N)[N - 1])

Measured memory_bytes: 84836
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int type[300];
char str[1000];
int main() {
  type[(int)'q'] = 1;
  type[(int)'w'] = 1;
  type[(int)'e'] = 1;
  type[(int)'r'] = 1;
  type[(int)'t'] = 1;
  type[(int)'a'] = 1;
  type[(int)'s'] = 1;
  type[(int)'d'] = 1;
  type[(int)'f'] = 1;
  type[(int)'g'] = 1;
  type[(int)'z'] = 1;
  type[(int)'x'] = 1;
  type[(int)'c'] = 1;
  type[(int)'v'] = 1;
  type[(int)'b'] = 1;
  while (scanf("%s", str), str[0] != '#') {
    int cnt = 0;
    int prev = type[(int)str[0]];
    int len = strlen(str);
    REP(i, len) {
      if (prev != type[(int)str[i]]) {
        cnt++;
      }
      prev = type[(int)str[i]];
    }
    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 0
<?php
fscanf(STDIN, '%f %f %f', $tak, $aok, $cnt);
$takRes = $tak - $cnt;
if ($takRes < 0) {
    $takRes = 0;
}
$tmp = $cnt - $tak;
if ($tmp < 0) {
    $tmp = 0;
}
$aokRes = $aok - $tmp;
if ($aokRes < 0) {
    $aokRes = 0;
}
echo $takRes.' '.$aokRes;

Measured memory_bytes: 4856
import sys

n = int(sys.stdin.buffer.readline())
z, w = [0]*n, [0]*n
for a, i in zip(sys.stdin.buffer.readlines(), range(n)):
    x, y = map(int, a.split())
    z[i] = x+y
    w[i] = x-y
print(max(abs(max(z)-min(z)), abs(max(w)-min(w))))


Measured memory_bytes: 39100
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include <queue>
#include <set>

using namespace std;

const long long MOD = 1000000007;

long long n, m, x[100002], y[100002],r[100002],c[100002],ans = 0;

int main(){
	
	cin >> n >> m;
	
	for (int i = 0; i < n; i++)cin >> x[i];
	for (int i = 0; i < m; i++)cin >> y[i];
	
	c[0] = n-1; c[n - 2] = n-1;
	r[0] = m-1; r[m - 2] = m-1;
	for (int i = 1; i <= n / 2; i++) {
		c[i] = (c[i - 1] + (n - 1 - 2 * i))%MOD;
		c[n - 2 - i] = c[i];
	}
	for (int i = 1; i <= m / 2; i++) {
		r[i] = (r[i - 1] + (m - 1 - 2 * i))%MOD;
		r[m - 2 - i] = r[i];
	}
	long long l = 0;
	for (int i = 0; i < n-1; i++) {
		l += (((x[i + 1] - x[i]) % MOD)*c[i]) % MOD;
		l %= MOD;
	}
	for (int i = 0; i < m - 1; i++) {
		ans += ((((y[i + 1] - y[i]) % MOD)*r[i]) % MOD)*l%MOD;
		ans %= MOD;
	}
	cout << ans << endl;
 	return 0;
}



Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<ctime>
#include<bitset>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 1e9+7;

inline ll max(ll a,ll b) { return a>b?a:b; }
inline ll min(ll a,ll b) { return a<b?a:b; }
inline ll abs1(ll a) { return a>0?a:-a; }

//const int maxn=

inline ll quickmi(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*a%mod;  
        a=a*a%mod;  
        n>>=1;
    }
    return ans;
}


int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll n;
	while(cin>>n)
		cout<<(quickmi(10,n)%mod-quickmi(9,n)%mod*2%mod+quickmi(8,n)%mod+mod)%mod<<endl;
	
	return 0;
}

Measured memory_bytes: 3616
N = int(input())
a = list(map(int, input().strip().split()))
free = 0
col1 = 0
col2 = 0
col3 = 0
col4 = 0
col5 = 0
col6 = 0
col7 = 0
col8 = 0
for i in range(N):
	if a[i] <= 399:
		col1 = 1
	elif a[i] <= 799:
		col2 = 1
	elif a[i] <=1199:
		col3 = 1
	elif a[i] <= 1599:
		col4 = 1
	elif a[i] <= 1999:
		col5 = 1
	elif a[i] <= 2399:
		col6 = 1
	elif a[i] <= 2799:
		col7 = 1
	elif a[i] <= 3199:
		col8 = 1
	else:
		free += 1
#print(col1, col2, col3, col4, col5, col6, col7, col8, free)
colsum = col1 + col2 + col3 + col4 + col5 + col6 + col7 + col8
colmax = colsum + free

if colsum == 0:
	colmin = 1
else:
	colmin = colsum
	  
print(colmin, colmax)

Measured memory_bytes: 3064
unittest
{
	assert( [ "3 2", "1 2", "2 3" ].parse.expand.solve == "POSSIBLE" );
	assert( [ "4 3", "1 2", "2 3", "3 4" ].parse.expand.solve == "IMPOSSIBLE" );
	assert( [ "100000 1", "1 99999" ].parse.expand.solve == "IMPOSSIBLE" );
	assert( [ "5 5", "1 3", "4 5", "2 3", "2 4", "1 4" ].parse.expand.solve == "POSSIBLE" );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	// 島1から他の島へ行く定期船を調べる
	auto s1 = abs.filter!( ( ab ) => ab[ 0 ] == 1 || ab[ 1 ] == 1 )
	             .map!( ( ab ) => ( ab[ 1 ] == 1 ) ? ab[ 0 ] : ab[ 1 ] )
	             .array;
	s1.sort();
	
	// 他の島から島Nへ行く定期船を調べる
	auto s2 = abs.filter!( ( ab ) => ab[ 0 ] == n || ab[ 1 ] == n )
	             .map!( ( ab ) => ( ab[ 1 ] == n ) ? ab[ 0 ] : ab[ 1 ] )
	             .array;
	s2.sort();
	
	// 島1と島Nの両方から行ける島を調べる
	while( !s1.empty && !s2.empty )
	{
		if( s1.front == s2.front ) return "POSSIBLE";
		
		if( s1.front < s2.front ) s1.popFront;
		else                      s2.popFront;
	}
	
	return "IMPOSSIBLE";
}


Measured memory_bytes: 8188
#include<stdio.h>
#include<string.h>
int main(void){
    int q,i,a,b,slen,j;
    char str[1001];
    char ope[10];
    char rep[1001];
    char tmp;
    scanf("%s",&str);
    scanf("%d",&q);
    for(i = 0;i<q;i++){
        scanf("%s",&ope);
        if(ope[0] == 'p'){
                scanf("%d%d",&a,&b);
                for(j = a;j<=b;j++){
                    printf("%c",str[j]);
                }
                printf("\n");
        }
        else if(ope[2] == 'p'){
            scanf("%d%d%s",&a,&b,rep);
            for(j=a;j<=b;j++){
                str[j] = rep[j-a];
            }
        }
        else{
            scanf("%d%d",&a,&b);
            slen = (b - a+1)/2 ;
            for(j=0;j<slen;j++){
                tmp = str[a+j];
                str[a+j] = str[b-j];
                str[b-j] = tmp;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll linf = 9e18;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    cout << n + 1 - k << endl;
    return 0;
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))
grid = [input() for i in range(H)]

for h in range(H):
  for w in range(W):
    flag1 = 0
    flag2 = 0
    if grid[h][w] == "#":
      if 0 <= h-1 < H:
        if grid[h-1][w] == "#":
          flag1 += 1
      if 0 <= w-1 < W:
        if grid[h][w-1] == "#":
          flag1 += 1
      if 0 <= h+1 < H:
        if grid[h+1][w] == "#":
          flag2 += 1
      if 0 <= w+1 < W:
        if grid[h][w+1] == "#":
          flag2 += 1

      if (h == 0 and w == 0):
        if flag1 == 0 and flag2 == 1:
          continue
        else:
          print("Impossible")
          exit()
      if (h == H-1 and w == W-1):
        if flag1 == 1 and flag2 == 0:
          continue
        else:
          print("Impossible")
          exit()
      else:
        if flag1 == 1 and flag2 == 1:
          continue
        else:
          print("Impossible")
          exit()
else:
  print("Possible")

Measured memory_bytes: 38384
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
t = sum(T)
ans = []
for i in range(M):
    p, x = [int(i) for i in input().split()]
    ans.append(t - T[p - 1] + x)
for i in range(M):
    print(ans[i])


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
void solve() {
	int n, x, y; cin >> n >> x >> y;
	--x; --y;
	vector<int> ans(n);
	rep (sv, n) {
		vector<int> dist(n, INF);
		queue<int> q;
		auto push = [&](int v, int d) {
			if (dist[v] != INF) return;
			dist[v] = d;
			q.push(v);
		};
		push(sv, 0);
		while(!q.empty()) {
			int v = q.front(); q.pop();
			int d = dist[v];
			if (v - 1 >= 0) push(v - 1, d + 1);
			if (v + 1 < n) push(v + 1, d + 1);
			if (v == x) push(y, d + 1);
			if (v == y) push(x, d + 1);
		}		
		rep (i, n) ans[dist[i]]++;
	}
	for (int i = 1; i <= n - 1; ++i) {
		cout << ans[i] / 2 << endl;
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

const int MAXN = 100100;
const int NIL  = -1;

struct Node {
   int p, l, r;
};

Node T[MAXN];
int  n, D[MAXN];

void print(int u) {
   int i, c;

   cout << "node " << u << ": ";
   cout << "parent = " << T[u].p << ", ";
   cout << "depth = " << D[u] << ", ";

   if (T[u].p == NIL) cout << "root, ";
   else if (T[u].l == NIL) cout << "leaf, ";
   else cout << "internal node, ";

   cout << "[";

   for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
      if (i) cout << ", ";
      cout << c;
   }
   cout << "]" << endl;
}

void rec(int u, int p) {
   D[u] = p;
   if (T[u].r != NIL) rec(T[u].r, p);
   if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
   int j, k, c, c2, root, n;

   cin >> n;
   rep(i, n) T[i].p = T[i].r = T[i].l = NIL;
   rep(i, n) {
      cin >> j >> k;
      rep(l, k) {
         cin >> c;
         if (l == 0) T[j].l = c;
         else T[c2].r = c;
         T[c].p = j;
         c2 = c;
      }
   }
   rep(i, n) {
      if (T[i].p == NIL) root = i;
   }
   rec(root, 0);
   rep(i, n) print(i);
   return(0);
}



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

#define MAXN 120
#define MAXK 100020

int N, K;
int a[MAXN];
int dp[MAXK];

int main() {
	cin >> N >> K;
  	for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
  	dp[0] = 0;
  	for (int i = 1; i <= K; i++) {
      for (int j = 0; j < N; j++) {
        if (a[j] <= i) {
          if (dp[i-a[j]] == 0) {
            dp[i] = 1;
          }
        }
      }
    }
  cout << (dp[K]==0?"Second":"First") << endl;
}

Measured memory_bytes: 640
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define pb push_back

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

string s;
int c[26];

int ans=1;

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

  cin>>s;

  for(int i=0;i<s.size();i++)
    c[s[i]-'a']++;

  for(int i=0;i<26;i++)
    for(int j=0;j<i;j++)
      ans+=c[i]*c[j];

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


Measured memory_bytes: 720
import sys


class Node:
    left = None
    right = None
    key = None

    def __init__(self, key):
        self.key = key
        return


class Tree:

    def __init__(self):
        self.root = None


def insert(T, z):
    '''
    T : Tree
    z : 要素
    '''

    p = None  # x の親（を入れる変数）
    x = T.root

    while x:  # 子がいなかったら
        p = x  # 親を設定
        if z.key < x.key:
            x = x.left  # 左の子へ移動
        else:
            x = x.right  # 右の子へ移動

    if p is None:  # T が空の場合
        T.root = z
    elif z.key < p.key:
        p.left = z  # z を y の左の子にする
    else:
        p.right = z  # z を y の右の子にする


def inorder(v):

    if v.left is not None:
        inorder(v.left)

    print("", v.key, end="")

    if v.right is not None:
        inorder(v.right)

    return


def preorder(r):

    print("", r.key, end="")

    if r.left is not None:
        preorder(r.left)
    if r.right is not None:
        preorder(r.right)

    return


def display(v):

    inorder(v)
    print("")
    preorder(v)
    print("")
    return


def main():

    T = Tree()

    # print(T)

    N = int(sys.stdin.readline().rstrip())
    for _ in range(N):
        op = sys.stdin.readline().rstrip().split()

        if len(op) == 2:
            v = Node(int(op[1]))
            insert(T, v)

        if len(op) == 1:
            display(T.root)


main()



Measured memory_bytes: 168936
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	vector<int> x(6, 0);
	int ans = -1;
	for (int i = 1; i <= 5; i++) {
		cin >> x[i];
		if (x[i] == 0) ans = i;
	}

	cout << ans;



	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    double arr[n+1];
    forii(1,n) cin>>arr[i];
    double dp[n+1][n+1];
    forii(1,n)
        forkk(1,n)
            dp[i][k]=0;
    dp[0][0]=1;
    forii(1,n) dp[i][0]=0;
    dp[0][1]=1-arr[1];
    forii(2,n)
        dp[0][i]=(1-arr[i])*dp[0][i-1]*1.0;
    double ans=0.0;
    forii(1,n)
    {
        forkk(1,n)
        {
            dp[i][k]=(arr[k]*dp[i-1][k-1]*1.0)+(1-arr[k])*dp[i][k-1]*1.0;
        }
    }
    /* forii(0,n) */
    /* { */
    /*     forkk(0,n) */
    /*         cout<<dp[i][k]<<" "; */
    /*     cout<<endl; */
    /* } */
    forii((n+1)/2,n)
    {
        ans+=dp[i][n];
    }
    cout<<setprecision(10)<<ans<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;

namespace _061_RankChecker
{
	class Program
	{
		static void Main ( string[] args )
		{
			//??´???????????¨?????°??????????????????
			List<Pair> pointList = new List<Pair> (100);

			string inputStr;

			while ((inputStr = Console.ReadLine ()) != "0,0")
			{
				int[] split = inputStr.Split (',').Select (int.Parse).ToArray ();
				Pair p = new Pair (split[0], split[1]);
				pointList.Add (p);
			}

			//????????????????????????
			pointList.Sort (( item, item2 ) => item2.Point - item.Point);

			//???????????????????????????????????????????????\??????
			//index = number, value = rank
			int[] rankArray = new int[pointList.Count + 1];	//???????????¨??´????????????????????????

			int rank = 1;
			int previousPoint = pointList[0].Point;

			rankArray[pointList[0].Number] = rank;

			for (int lp = 1; lp < pointList.Count; lp++)
			{
				int currentPoint = pointList[lp].Point;

				if (currentPoint != previousPoint)
				{
					rank++;
					previousPoint = currentPoint;
				}

				rankArray[pointList[lp].Number] = rank;
			}

			//???????????\??§????????????
			string inputStr2;

			while ((inputStr2 = Console.ReadLine ()) != null)
			{
				int number = int.Parse (inputStr2);
				int result = rankArray[number];
				Console.WriteLine (result);
			}
		}
	}

	//?????°
	class Pair
	{
		public Pair ( int number, int point )
		{
			this.Number = number;
			this.Point = point;
		}

		public int Number { private set; get; }
		public int Point { private set; get; }
	}
}

Measured memory_bytes: 9576
def resolve():
    H, W, M = list(map(int, input().split()))
    HW = [list(map(int, input().split())) for _ in range(M)]
    rowsum = [0 for _ in range(H)]
    colsum = [0 for _ in range(W)]
    for h, w in HW:
        rowsum[h-1] += 1
        colsum[w-1] += 1
    rmax = 0
    ridx = []
    for i, r in enumerate(rowsum):
        if rmax < r:
            rmax = r
            ridx = [i]
        elif rmax == r:
            ridx.append(i)
    maxr = [False for _ in range(H)]
    for i in ridx:
        maxr[i] = True
    
    cmax = 0
    cidx = []
    for j, c in enumerate(colsum):
        if cmax < c:
            cmax = c
            cidx = [j]
        elif cmax == c:
            cidx.append(j)
    maxc = [False for _ in range(W)]
    for i in cidx:
        maxc[i] = True
    
    cnt = 0
    for h, w in HW:
        if maxr[h-1] and maxc[w-1]:
            cnt += 1
    
    print(rmax + cmax if cnt < len(cidx)*len(ridx) else rmax + cmax - 1)

    
    


if '__main__' == __name__:
    resolve()



Measured memory_bytes: 215140
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int a,b,c,d;
    int e,f,g,h;
    cin >> a >> b >> c >> d;
    cin >> e >> f >> g >> h;
    
    int x = a+b+c+d;
    int y = e+f+g+h;
    if(x>y) {
        cout << x << endl; 
    }
    else if(x==y) {
        cout << x << endl; 
    }
    else {
        cout << y << endl;
    }
}


Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main()
{
    int n,i=0;
    char s[10000];
    cin >> n >> s;
    while(s[i]){
        s[i]+=n;
        if(s[i]>0x5A) s[i]-=26;
        cout << char(s[i]);
        i++;
    }
    return 0;
}

Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
vll v(MAXN);
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
cin>>k;
vector<ll> neg;
vector<ll> pos;
for(int i=0;i<n;i++)
{
    cin>>v[i];
    if(v[i]<0)
    neg.pb(v[i]);
    else
    pos.pb(v[i]);
}
ll nn,np;
nn=neg.size();
np=pos.size();
ll ans=llmax;
sort(neg.begin(),neg.end(),greater<>());
for(int i=0;i<=min(k,nn);i++)
{
    if(pos.size()<(k-i))
    continue;
    if(i<k)
    temp=2*pos[k-1-i];
    if(i!=0)
    temp-=neg[i-1];
    ll temp1=0;
    if(i!=0)
    {
        temp1-=2*neg[i-1];
    }
    if(i<k)
    temp1+=pos[k-1-i];
    //deb(temp);
    //deb(temp1);
    ans=min(temp,ans);
    ans=min(temp1,ans);
}
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 2424
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn gcd(x: u64, y: u64) -> u64 {
    if x == 0 {
        y
    } else {
        gcd(y % x, x)
    }
}

fn main() {
    let v = read_vec::<u64>();
    let a = v[0];
    let b = v[1];
    let k = v[2];

    let g = gcd(a, b);

    let mut d = 0;
    for i in (1..g+1).rev() {
        if g % i == 0 {
            d += 1;
            if d == k {
                println!("{}", i);
                break;
            }
        }
    }
}


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

using namespace std;

void b_bounding(void) {
	int n, x;
	int* l;
	cin >> n >> x;
	l = (int*)calloc(n + 2, sizeof(int));
	for (int i = 1; i <= n; i++) cin >> l[i];

	int cnt = 1;
	int now = 0;
	for (int i = 2; i <= n + 1; i++) {
		int before = now;
		now = before + l[i - 1];
		if (now <= x) cnt++;
	}

	cout << cnt << endl;
}

int main()
{
    b_bounding();

    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	set<int> S;
	REP(i,3) S.emplace(in());
	if(S.size()==2) out("Yes");
	else out("No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=998244353;
ll a[100005],n,x,maxn,ans=1;
ll POW(ll k,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*k%M;
		k=k*k%M;
		b>>=1;
	}
	return res%M;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>x;
		if(i==1&&x!=0){
			cout<<0<<endl;
			exit(0);
		}
		a[x]++;
		maxn=max(maxn,x);
	}
	for(int i=0;i<maxn;++i){
		ans*=POW(a[i],a[i+1]);
		ans%=M;
	}
	if(a[0]==1)
	cout<<ans<<endl;
	else cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	int n;
	cin>>n;
	cout<<!n<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)solve();
}


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

int main() {
   double A,B,H,M;
   cin >> A >> B >> H >> M;
   double minutes = 360 * (M/60);
   double times = (360 * H/12)+M*1/2;
   double kakudo = min(abs(times-minutes),360-abs(times-minutes));
   double ans = sqrt(A*A+B*B-2*A*B*cos(M_PI*kakudo/180));
   printf("%.10lf",ans);
  return 0;
}


Measured memory_bytes: 4196
#include<stdio.h>
#include<string.h>
int main(){
    int str_n;
    char str[1000];

    scanf("%s",str);
    str_n=strlen(str);
    if(str_n%2)str_n--;
    else str_n-=2;
    int flg=0;
    while(1){
        flg=0;
        for(int i=0;i<str_n/2;i++){
            if(str[i]!=str[str_n/2+i]){
                flg=1;
                break;
            }
        }
        if(!flg){
            printf("%d\n",str_n);
            break;
        }
        else str_n-=2;
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,m;
ll A[100010] = {0},B[100010] = {0};

int main(){
	cin >> n >> m;
	ll sum = 0;
	vector<P> v(n);
	for(int i=0;i<n;i++){
		cin >> A[i];
		B[i] = A[i];
		if(i>=1){
			if(B[i-1]>A[i]) A[i] += m;
			sum += A[i]-B[i-1];
			v[i-1] = {B[i-1],A[i]};
		}
	}
	sort(v.begin(),v.end());
	P F[2*(m+2)];
	for(int i=0;i<2*(m+2);i++){
		F[i] = {0,0};
	}
	for(int i=0;i<n;i++){
		F[v[i].first+1].second++;
		F[v[i].second+1].second--;
		F[v[i].second+1].first -= v[i].second-v[i].first;
	}
	ll ans = 0;
	for(int i=2;i<2*(m+2);i++){
		F[i].second += F[i-1].second;
		F[i].first += F[i].second + F[i-1].first;
	}
	for(int i=1;i<=m;i++){
		ans = max(ans,F[i].first+F[i+m].first-F[i].second-F[i+m].second);
	}
	cout << sum - ans << endl;
}

Measured memory_bytes: 6528
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val H, W = ni()
    val A = nm_c(H, W)
    val fH = Array.fill[Boolean](H)(true)
    val fW = Array.fill[Boolean](W)(true)
    rep(H) { i =>
      rep(W) { j =>
        fH(i) &&= A(i)(j) == '.'
        fW(j) &&= A(i)(j) == '.'
      }
    }

    rep(H) { i =>
      if (!fH(i)) {
        rep(W) { j =>
          if (!fW(j)) {
            out.print(A(i)(j))
          }
        }
        out.println()
      }
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    rep(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    rep(n) { i =>
      rep(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 27960
#include<bits/stdc++.h>
using namespace std;
const int nmax=100005;
vector<vector<int>> g(nmax);
vector<int> d(nmax);
int f(int s){
  if(d[s]){
    return d[s];
  }
  int res=0;
  for(auto x:g[s]){
    res=max(res,f(x)+1);
  }
  return d[s]=res;
}
int main(){
  int n,m;cin >> n >> m;
  vector<int> h(n);
  for(int i=0;i<m;i++){
    int x,y;cin >> x >> y;
    x--,y--;
    g[x].push_back(y);
    h[y]++;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(!h[i]){
      ans=max(ans,f(i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long[] x = new long[n];
        long score = 0;
        for(int i = 0; i<n; i++) x[i] = sc.nextLong();
        for(int i = 1; i<n; i++)  {
            score += Math.min(a*(x[i]-x[i-1]), b);
        }
	    System.out.println(score);
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21816
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    x,k,d=parseMap(split(readline()))
    tmp=min(abs(x)÷d,k)
    if x>0
        x,k=x-tmp*d,k-tmp
    else
        x,k=x+tmp*d,k-tmp
    end
    if k%2==0
        println(abs(x))
    else
        println(d-abs(x))
    end
end
main()

Measured memory_bytes: 163664
#include <bits/stdc++.h>#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
 
int main() {
    int n;
    cin>>n;
   int m =0;
   rep(i,n+10000){
   if(i*1.08<n+1&&i*1.08>=n&&m==0){
   cout << i <<endl;
   m = 1;
   }
   }if(m==0)
   cout<<":("<<endl;
     
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

char s[200005];
int next1[200005][26];
int p[26];
int deep[200005],dir[200005];
int len;


void dfs(int i)
{
    if (deep[i]!=0)
        return ;
    for (int j=0;j<26;j++)
        if (next1[i][j]==0)
            {
            dir[i]=j;
            deep[i]=1;
            return ;
            }

    int minn=1999999999;
    for (int j=0;j<26;j++)
        {
        dfs(next1[i][j]);
        if (deep[next1[i][j]]<minn)
            {
            minn=deep[next1[i][j]];
            dir[i]=j;
            }
        }
    deep[i]=minn+1;
}

void work()
{
    dfs(0);
    int i=0;
    while (1)
        {
        printf ("%c",dir[i]+'a');
        if (next1[i][dir[i]]==0) break;
        else i=next1[i][dir[i]];
        }
}

int main()
{
    scanf ("%s",s+1);
    len=strlen(s+1);
    for (int i=len;i>=0;i--)
        {
        for (int j=0;j<26;j++)
            next1[i][j]=p[j];
        p[s[i]-'a']=i;
        }
    work();
}


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

using namespace std;
#define int long long

signed main(){
	int n,m;cin>>n>>m;
	int ans=0,t=0;
	t=min(n,m/2);
	ans+=t;
	ans+=(m-t*2)/4;
	cout<<ans;
	return 0;
}

/*
dreamer
0123456
7
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Elhabashy ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
const int N=1e5+5,mod=1e9+7;
typedef long long ll;
int n,m,k;
string s[10];
char arr[10][10];
set<string>se;
void solve(){
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            for(int r=0;r<n;r++){
                for(int c=0;c<m;c++){
                    arr[r][c]=s[r][c];
                }

            }
            for(int r=0;r<n;r++){
                if((1<<r)&i){
                    for(int c=0;c<m;c++)arr[r][c]='R';
                }
            }
            for(int c=0;c<m;c++){
                if((1<<c)&j){
                    for(int r=0;r<n;r++)arr[r][c]='R';
                }
            }
            int cnt=0;
            string ans="";
            for(int r=0;r<n;r++){
                for(int c=0;c<m;c++){
                    if(arr[r][c]=='#')cnt++;
                    ans+=arr[r][c];
                }

            }
            if(cnt==k){
                se.insert(ans);
            }

        }
    }
}
int main()
{
    Elhabashy
    input();
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
        cin>>s[i];
    solve();
    cout<<se.size()<<endl;

}


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

int c[100001];
int sc[100001];
int f(int n) {
    if (n == 1)
        return 0;
    for (int i = 2; i*i <= n; i++)
        if (n % i == 0)
            return 0;
    return 1;
}

int main() {

    int q;
    scanf("%d", &q);
    
    c[1] = 0;
    sc[1] = 0;
    
    for (int i = 2; i <= 100001; i++) {
        if (i % 2 == 1)
            if (f(i) && f((i+1)/2))
                c[i] = 1;
    }
    
    for (int i = 2; i <= 100001; i++) {
        sc[i] = sc[i-1]+c[i];
    }
    
    for (int i = 0; i < q; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        printf("%d\n", sc[b] - sc[a-1]);
    }
    
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) b.rbegin(),v.rend()
typedef long long ll;
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int x,y,z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 256
N = int(input())
ans = []

for i in range(N):
    s = input()
    ans.append(s)

print('AC x {0}'.format(ans.count('AC')))
print('WA x {0}'.format(ans.count('WA')))
print('TLE x {0}'.format(ans.count('TLE')))
print('RE x {0}'.format(ans.count('RE')))

Measured memory_bytes: 16288
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 



int main()
{
   
                        
     fio

     
    map<string,lli> m;

    lli n;
    string s;
    cin>>n;
    fr(i,0,n){cin>>s;m[s]++;}
    
    cout<<"AC x "<<m["AC"]<<'\n';
    cout<<"WA x "<<m["WA"]<<'\n';
    cout<<"TLE x "<<m["TLE"]<<'\n';
    cout<<"RE x "<<m["RE"]<<'\n';
     



     


     
    
     




      
     

     
              


return 0;}    


Measured memory_bytes: 3664
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string> 
#include <map>
#include <iomanip>

using namespace std;


typedef int INT;
#define int long long

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

	string s;
	int n;
	cin >> s >> n;
	

	char k = char(-1 + 'a'), r;

	set <int> st;
	while (true)
	{
		r = k;
		k = 'z';
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] < k && s[i] > r)
				k = s[i];
		}

		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == k)
			{
				int t = 0, y = 31 * 31 * 31 * 31;
				for (int j = i; j < min((int)s.size(), j + n); j++)
				{
					t = t + (s[j] - 'a' + 1LL) * y;
					y /= 31LL;
					st.insert(t);
				}
			}
		}
		if (st.size() >= n)
		{
			int o = 1;
			for (auto a : st)
			{
				if (o == n)
				{
					string u;
					while (a != 0)
					{
						u = char((a % 31 - 1) + 'a') + u;
						a /= 31;
					}
					for (int i = 0; i < u.size(); i++)
						if (u[i] >= 'a' && u[i] <= 'z')
							cout << u[i];
					return 0;
				}
				o++;
			}
		}
	}



	return 0;
}

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

int main() {
	int N; cin >> N;
	int k; cin >> k;
	long long h[110000];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h, h + N);
	long long ans = 1000000000;
	for (int i = 0; i < N - k + 1; i++) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans;
}

Measured memory_bytes: 1024