akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
char field[102][102];
int dx[4] = {-1, 0, 1,  0};
int dy[4] = { 0, 1, 0, -1};

void DFS(int y, int x, char c)
{
	field[y][x] = '.';
	for(int i = 0; i < 4; ++i)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(field[ny][nx] == c)
		{
			DFS(ny, nx, c);
		}
	}
}

void solve()
{
	int H, W;
	while(cin >> H >> W, H || W)
	{
		for(int i = 1; i <= H; ++i)
		{
			for(int j = 1; j <= W; ++j)
			{
				cin >> field[i][j];
			}
		}
		int count = 0;
		for(int i = 1; i <= H; ++i)
		{
			for(int j = 1; j <= W; ++j)
			{
				if(field[i][j] != '.')
				{
					++count;
					DFS(i, j, field[i][j]);
				}
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    if (A >= 2 * C && B >= 2 * C){
        ans = max(X, Y) * 2 * C;
    }
    else if (A >= 2 * C){
        ans = X * 2 * C;
        ans += max(0, Y - X) * B;
    }
    else if (B >= 2 * C){
        ans = Y * 2 * C;
        ans += max(0, X - Y) * A;
    }
    else if (A + B >= 2 * C){
        if (X >= Y){
            ans = Y * 2 * C;
            ans += (X - Y) * A;
        }
        else {
            ans = X * 2 * C;
            ans += (Y - X) * B;
        }
    }
    else {
        ans = X * A + Y * B;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)
    else:
        break


Measured memory_bytes: 5592
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int dfs(int x, int y, int z) {
    if (x == a && y == b && z == c) return 1;
    
    int ans = 0;
    if (x != a) ans += dfs(x + 1, y, z);
    if (x >= y + 1/* && y != b*/) ans += dfs(x, y + 1, z);
    if (y >= z + 1/* && z != c*/) ans += dfs(x, y, z + 1); 

    return ans;
}

uint64_t gcd_impl( uint64_t n, uint64_t m ) {
        for( int i = 0; i < 10; ++i ) {
                uint64_t t = n - m;
                bool q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

uint64_t gcd( uint64_t n, uint64_t m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;

    unsigned long long int aa = 0;
    rep(i, 1, n + 1) {
        rep (j, 1, n + 1) {
            rep (k, 1, n + 1) {
                aa += gcd(i, gcd(j, k));
            }
        }
        
    }

    cout << aa << endl;


    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define rep(i,n) for(int i=0;i<n;i++)
#define ford(i,a,n) for(int i=a;i<n;i++)
#define fors(i,s) for(int i=0;i<s.size();i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define INF 1e9
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	string s;
	cin>>s;
	bool f=true;
	rep(i,s.size()){
		if(i%2==0){
			if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
				continue;
			}
			else{
				f=false;
				break;
			}
		}
		else{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
				continue;
			}
			else{
				f=false;
				break;
			}
		}
	}
	if(f){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 50;

int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
  visited[v] = true;
  for(int v2 = 0;v2 < n; v2++){
    if(graph[v][v2] == false) continue;
    if(visited[v2] == true) continue;
    dfs(v2);
  }
}

int main(){
  cin >> n >> m;
  
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  rep(i,m){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    rep(j,n) visited[j] = false;

    dfs(0);

    bool bridge = false;
    rep(j,n) if(visited[j] == false) bridge = true;
    if(bridge) ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int INF = 1000000000;
const ll BIG_NUM = 1000000000000000000;


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


	vector<vector<int>> e(2 * n);
	for (int i = 0; i < n; i++) {
		int s, t, x;
		cin >> s >> t >> x;
		e[2 * i] = vector<int>{ s - x,1,x };
		e[2 * i + 1] = vector<int>{ t - x,-1,x };
	}
	vector<int> d(q);
	for (int i = 0; i < q; i++) {
		cin >> d[i];
	}


	sort(e.begin(), e.end());
	sort(d.begin(), d.end());
	set<int> c;
	

	int t = 0;
	for (int i = 0; i < q; i++) {
		while (t < (2 * n) && e[t][0] <= d[i]) {
			if (e[t][1] == 1) {
				c.insert(e[t][2]);
			}
			else {
				c.erase(e[t][2]);
			}
			t++;
		}
		if (c.size() > 0) {
			cout << *c.begin() << endl;
		}
		else {
			cout << -1 << endl;
		}
		
	}

}




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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();

            var aliceScore = a.Where((x,i)=>i%2==0).Sum();
            var bobScore = a.Sum() - aliceScore;

            Console.WriteLine(aliceScore - bobScore);
        }
    }
}


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

int main() {
	int n, m;
	int long long a[50], b[50], c[50], d[50];

	cin >> n >> m;

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

	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	for (int i = 0; i < n; i++) {
		int min_distance = abs(a[i]-c[0]) + abs(b[i]-d[0]);
		int check_num=1;
		for (int j = 1; j < m; j++) {//0は調べてある
			int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (min_distance > tmp) {
				min_distance=tmp;
				check_num = j+1;
			}
		}
		cout << check_num << endl;
	}



	return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define MAX(A, B) ((A>B) ? A : B)
#define NUM 4
using namespace std;


int main(void){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    
    long long ans_candidate[NUM] = {a*c, a*d, b*c, b*d};
    for(int i = 0; i < NUM-1; i++){
        ans_candidate[i+1] = MAX(ans_candidate[i], ans_candidate[i+1]);
    }
    cout << ans_candidate[NUM-1] << endl;
    
    return 0;
}


Measured memory_bytes: 3188
n, m = map(int, input().split())
x = list(map(int, input().split()))

x.sort()

if m<=n:
    print(0)
    exit()

distance = [0]*(m-1)
for i in range(m-1):
    distance[i] = x[i+1]-x[i]

distance.sort()

ans = sum(distance[:(m-n)])
print(ans)

Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

int high[100 + 1];
int low[100 + 1];

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

    int N;
    cin >> N;

    for (int i = 1; i <= N; ++i) {
        cin >> high[i];

        high[i] += high[i - 1];
    }

    for (int i = 1; i <= N; ++i) {
        cin >> low[i];

        low[i] += low[i - 1];
    }

    int ans = 0;

    for (int i = 1; i <= N; ++i) {
        ans = max(ans, high[i] + low[N] - low[i - 1]);
    }

    out(ans);

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(N-1):
    L.append(gcd(L[i],A[i+1]))
    R.append(gcd(R[(i)],A[-(i+2)]))
ans = []    
for i in range(N):
    if i == 0:
        ans.append(R[N - 2])
    elif i <= N - 2:
        ans.append(gcd(L[i - 1],R[N - i - 2]))
    else:
        ans.append(L[N - 2])

print(max(ans))

Measured memory_bytes: 16168
#!/usr/bin/env python3
from collections import deque


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    a = input()
    Q = int(input())
    qs = [input().split() for _ in range(Q)]
    ans = deque(a)
    revcount = 0
    for q in qs:
        if len(q) == 1:
            revcount += 1
        else:
            if int(q[1]) == 1:
                if revcount % 2 == 0:
                    ans.appendleft(q[2])
                else:
                    ans.append(q[2])
            else:
                if revcount % 2 == 0:
                    ans.append(q[2])
                else:
                    ans.appendleft(q[2])
    if revcount % 2 == 1:
        ans.reverse()
    print(''.join(list(ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 44660
import numpy as np

H,W = map(int,input().split())
A = []
for i in range(H):
    A.append([0 if i == "#" else H+W for i in list(input())])
A = np.array(A)

for i in range(H-1):
  A[i+1, :] = np.minimum(A[i, :] + 1, A[i+1, :])
for i in range(H-1,0,-1):
  A[i-1,:] = np.minimum(A[i,:]+1,A[i-1,:])
for i in range(W-1):
  A[:,i+1] = np.minimum(A[:,i]+1,A[:,i+1])
for i in range(W-1,0,-1):
  A[:,i-1] = np.minimum(A[:,i]+1,A[:,i-1])
print(np.max(A))

Measured memory_bytes: 60408
local mmi = math.min
local h, w = io.read("*n", "*n")
local a = {}
for i = 1, h do
  for j = 1, w do
    a[(i - 1) * w + j] = io.read("*n")
  end
end
for i = 1, h do
  for j = 1, w do
    local idx = (i - 1) * w + j
    a[idx] = a[idx] - io.read("*n")
  end
end

-- top
local odd, ev = {}, {}
for i = 1, w do
  odd[i] = {}
  ev[i] = {}
  for j = 1, 12801 do
    odd[i][j] = false
    ev[i][j] = false
  end
end
for i = 1, 161 do odd[1][i] = false end
odd[1][81 + a[1]] = true
odd[1][81 - a[1]] = true
for j = 2, w do
  local av = a[j]
  local lim = 160 * j + 1
  for dst = 1, lim do
    local src = dst - 80
    local f = false
    if av < src and odd[j - 1][src - av] then
      f = true
    end
    if not f and src + av <= lim - 160 and odd[j - 1][src + av] then
      f = true
    end
    odd[j][dst] = f
  end
end
local mmi = math.min
-- rem
for i = 2, h do
  local refsrc = i % 2 == 0 and odd or ev
  local refdst = i % 2 == 0 and ev or odd
  do -- j = 1
    local av = a[(i - 1) * w + 1]
    local lim = 160 * i + 1
    for dst = 1, lim do
      local src = dst - 80
      local f = false
      if av < src and refsrc[1][src - av] then
        f = true
      end
      if not f and src + av <= lim - 160 and refsrc[1][src + av] then
        f = true
      end
      refdst[1][dst] = f
    end
  end
  for j = 2, w do
    local av = a[(i - 1) * w + j]
    local lim = mmi(6400, (i + j - 1) * 80) * 2 + 1
    for dst = 1, lim do
      local src = dst - 80
      local f = false
      if av < src then
        if refsrc[j][src - av] or refdst[j - 1][src - av] then
          f = true
        end
      end
      if not f and src + av <= lim - 160 then
        if refsrc[j][src + av] or refdst[j - 1][src + av] then
          f = true
        end
      end
      refdst[j][dst] = f
    end
  end
end
local ret = 1000000007
local mab = math.abs
do
  local lim = (h + w - 1) * 80
  local refdst = h % 2 == 0 and ev or odd
  for p = -lim, lim do
    if refdst[w][p + lim + 1] then
      if mab(p) < ret then
        ret = mab(p)
      end
    end
  end
end
print(ret)


Measured memory_bytes: 21664
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[[0,0,0] for i in range(n+1)]
for i in range(n):
    lis[i+1]=LI()
for i in range(n):
    dt=lis[i+1][0]-lis[i][0]
    dx=abs(lis[i+1][1]-lis[i][1])
    dy=abs(lis[i+1][2]-lis[i][2])
    if dx+dy<=dt and (dx+dy-dt)%2==0:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 27764
#include <stdio.h>

int main(){

  int a, b;
  char op;

  while(1){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?')
      break;
    else if(op == '+')
      printf("%d\n",a+b);
    else if(op == '-')
      printf("%d\n",a-b);
    else if(op == '*')
      printf("%d\n", a*b);
    else if(op == '/')
      printf("%d\n", a/b);
  }

  return 0;
}

Measured memory_bytes: 600
x1,y1,x2,y2=map(int,input().split())

vec12_x=-(y2-y1)
vec12_y=x2-x1

x3=x2+vec12_x
y3=y2+vec12_y

x4=x3-(x2-x1)
y4=y3-(y2-y1)

print(x3,y3,x4,y4)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int N, K;
    cin >> N >> K;
    const int inf = 1 << 30;
    vector<int> A(N, inf);
    REP (i, 0, N) {
        int num;
        cin >> num;
        num--;
        if (A[num] == inf) A[num] = 0;
        A[num]++;
    }
    sort(A.begin(), A.end(), greater<int>());
    int k = 0;
    lli ans = 0;
    REP (i, 0, N) {
        if (A[i] == inf) continue;
        k++;
        if (k > K) ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int A[5], k;
    cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4] >> k;

    bool flag = true;
    for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
            if (A[j] - A[i] > k) {
                flag = false;
                break;
            }
        }
        if (!flag) {
            break;
        }
    }

    if (flag) {
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <cassert>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <random>


using namespace std;

/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    /// caide keep
    template<int N>
    struct bytetype {
        
    };

    /// caide keep
    template<>
    struct bytetype<4> {
        
    };

    /// caide keep
    template<>
    struct bytetype<3> {
        
    };

    /// caide keep
    template<>
    struct bytetype<2> {
        
    };

    /// caide keep
    template<>
    struct bytetype<1> {
        
    };

    /// caide keep
    template<>
    struct bytetype<0> {
        
    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
   int a = next<int>(in); 
   int b = next<int>(in); 
   if (a > b) {
     swap(a, b);

   }
   if (a > 0) {
     out << "Positive\n";
     return;
   }
   if (a <= 0 && b >= 0) {
     out << "Zero\n";
     return;
   }
   int cnt = b - a + 1;
   if (cnt % 2 == 0) {
   
     out << "Positive\n";
   } else {
     out << "Negative\n";
   }
}


int main() {
    solve(cin, cout);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
signed main(){
	int s;
	cin>>s;
	int sum[1000000]={0};
	sum[s]=1;
	int cnt=s;
	rep(i,10000000){
		if(cnt%2==0)cnt/=2;
		else cnt=cnt*3+1;
		if(sum[cnt]==1){
			cout<<i+2<<endl;
			break;
			}
			else sum[cnt]++;
		}

	return 0;
	
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n;
  int a[100005];
  int tmp;
  cin>>n;
  rep(i,n)cin>>a[i];
  
  for(int i=1;i<=n;i++){
    if(i==1)tmp=a[0];
    else tmp=a[tmp-1];
    if(tmp==2){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int n,i,x,y,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&x,&y);
        if(x==y) cnt++;
        else cnt+=y-x+1;
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int bubbleSort(int *,int);
int num=0;
int main(){
  int i,N,*data;
  
  scanf("%d",&N);
  data=(int *)malloc(N*sizeof(data));

  for(i=0;i<N;i++){
    scanf("%d",&data[i]);
  }

  bubbleSort(data,N);

  for(i=0;i<N;i++){
    printf("%d",data[i]);
    if(i!=N-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",num);
    
    return 0;
}

int bubbleSort(int *data,int N){
  int i,j,temp,flag=1;
  while(flag){
    flag=0;
    j=0;
    for(i=N-1;i>=j+1;i--){
      if(data[i]<data[i-1]){
	temp=data[i];
	data[i]=data[i-1];
	data[i-1]=temp;
	flag=1;
	num++;
      }
    }
    j++;
  }
  return *data;
}



Measured memory_bytes: 2144
n=int(input())
x=list(map(int,input().split()))
xm=max(x)
def ra(a): #圧縮された要素を非保持
    ll,l=[0]*xm,1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll[a[i]]+=l
            l=1
    ll.append(l)
    return ll
b=ra(sorted(x))
d=0
for i in b:
    d+=(i*(i-1))//2
for i in range(n):
    print(d-b[x[i]]+1)

Measured memory_bytes: 32484
# -*- coding: utf-8 -*-

N = int(input())
T,A = map(int, input().split())
hN = list(map(int, input().split()))

tN = [0] * N
ans = -1
tmp = float('inf')
for i in range(N):
    tN[i] = T - hN[i] * 0.006
    if abs(tN[i] - A) < tmp:
        tmp = abs(tN[i] - A)
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <iostream>
#include <string>

int main()
{

    int n, z, w;

    scanf("%d", &n);
    scanf("%d", &z);
    scanf("%d", &w);

    int a[2000];

    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }

    int out;
    if (n == 1)
    {
        out = abs(a[0] - w);
    }
    else
    {
        if (abs(a[n - 1] - a[n - 2]) > (abs(a[n - 1] - w)))
        {
            out = abs(a[n - 1] - a[n - 2]);
        }
        else
        {
            out = abs(a[n - 1] - w);
        }
    }

    std::cout << out << "\n";

    return 0;
}

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

int main(){
  int N,A,B,C,X,Y[100],yi,fc;

  while(1){
    cin >> N >> A >> B >> C >> X;
    if (N==0&&A==0&&B==0&&C==0&&X==0)break;

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

    fc=0;
    yi=0;
    while (1){
      if (fc>10000){
	cout << -1 << endl;
	break;
      }
      if (X==Y[yi]){
	yi++;
	if (yi>=N){
	  cout << fc << endl;
	  break;
	}
      }
      X=(A*X+B)%C;
      fc++;
    }
  }
  return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  ll a, b, k;
  cin >> a >> b >> k;

  ll tmpa = a;
  ll tmpb = b;
  vl ans;
  rep(i, k) {
    ans.pb(a);
    ++a;
    ans.pb(b);
    --b;
    if( a >= tmpb || b <= tmpa ) break;
  }

  sort(all(ans));

  rep(i, ans.size() - 1) {
    if( ans[i] == ans[i+1] ) continue;
    cout << ans[i] << endl;
  }
  cout << ans[ans.size()-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  vector<int> st(3);
  for (int i=0;i<3;i++) {
    cin>>st[i];
  }
  sort(st.begin(),st.end());
  cout<<st[2]*10+st[1]+st[0]<<endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

long long dp[200100];

vector<pair<long long, long long> > prime_factorize(long long N){
    vector<pair< long long , long long> > res;
    for(long long a = 2; a* a <= N; a++){
        if(N%a != 0)continue;
        long long ex = 0;
        while(N%a == 0){
            ex++;
            N /= a;
        }

        res.push_back({a,ex});
    }

    if(N!=1)res.push_back({N,1});
    return res;
    
}


int main(){
    int N;
    cin >> N;
    
    int ans  = 0;
    for(int i = 1; i<=N; i+=2){
        const auto &pf = prime_factorize(i);
        long long res = 1;
        for(auto p: pf)res *= p.second + 1;
        if(res == 8)ans +=1;
    }
    cout << ans << endl;



}





Measured memory_bytes: 3584
void main(){
	long n = _scan!long();
	long[] a = _scanln!long();
	long[long] dic;
	bool fl = true;
	foreach(i; 0..n){
		if(dic.get(a[i], 0) == 0)dic[a[i]]++;
		else{
			writeln("NO");
			return;
		}
	}
	writeln("YES");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 21192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    ll ans=1;
    rep(i,N){
        ans=min(ans*2,ans+K);
    }


    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W,D,A,px[90000],py[90000];
  	int Q,L,R,d[90000];
    cin>>H>>W>>D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A;
            px[A]=i,py[A]=j;
        }
    }
    for(int i=D+1;i<=H*W;i++){
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    }
    cin>>Q;
    for(;Q>0;Q--){
        cin>>L>>R;
        cout<<d[R]-d[L]<<endl;
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
int main() {
	int x, y; scanf("%d%d",&x,&y);
	int ans = 0;
	if (ab(x) > ab(y) && x > 0) ans++;
	if (ab(x) < ab(y) && x < 0) ans++;
	ans += ab(ab(x) - ab(y));
	if (ab(x) > ab(y) && y > 0) ans++;
	if (ab(x) < ab(y) && y < 0) ans++;
	if (ab(x) == ab(y) && x != y) ans++;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

lengths = []
for i in range(len(A) - 1):
    try:
        if A[i] == A[i+3] and len(lengths) == 0:
            lengths.append(A[i])
            lengths.append(A[i])
            break
    except:
        pass

    if (A[i] not in lengths) and (A[i] == A[i+1]):
        lengths.append(A[i])

    if len(lengths) == 2:
        break

try:
    ans = lengths[0] * lengths[1]
except:
    ans = 0

print(ans)

Measured memory_bytes: 62704
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int ans  = 0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='+') ans++;
        else ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int64_t imax(const int64_t a, const int64_t b) { return std::max(a, b); } // std::max, std::min は型が違うとエラーになるため、ラッパーを作る。
int64_t imin(const int64_t a, const int64_t b) { return std::min(a, b); }

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

#define input1(begin, end, v1) v1.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i]; }
#define input2(begin, end, v1, v2) v1.resize((end)+1); v2.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i] >> v2[i]; } 
#define input3(begin, end, v1, v2, v3) v1.resize((end)+1); v2.resize((end)+1); v3.resize((end)+1); for (int i = (begin); i <= (end); i++) { std::cin >> v1[i] >> v2[i] >> v3[i]; } 

std::vector<int> irange(const int begin, const int end) {
    std::vector<int> ret; for (int i = begin; i <= end; i++) { ret.push_back(i); }
    return ret;
}

template <typename T>
void printvec(const std::vector<T>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

int A, B, C, D;
//int128_t ;
//std::vector<int> ;
//std::vector<int128_t> ;
//std::string ;
//std::vector<std::string> ;
//double ;
//std::vector<double> ;

int main(int argc, char **argv) {
    std::cin >> A >> B >> C >> D;
    
    if (A + B == C + D) {
        std::cout << "Balanced" << std::endl;
    } else if (A + B > C + D) {
        std::cout << "Left" << std::endl;
    } else {
        std::cout << "Right" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100010],n;
int main() {
    scanf("%d",&n);
    a[0] = 0;
    for (int i = 1;i <= n;i++) scanf("%d",&a[i]);
    a[n+1] = 0;
    int ans = 0,pos = 0,u,v,x,y;
    for (int j = 0;j <= n+1;j++)
        if (j != 1) ans += abs(a[pos]-a[j]),pos = j;
    u = 0,v = 1,x = 2,y = 3;
    printf("%d\n",ans);
    for (int i = 2;i <= n;i++) {
        ans -= abs(a[u]-a[x])+abs(a[x]-a[y]);
        ans += abs(a[u]-a[v])+abs(a[v]-a[y]);
        u++,v++,x++,y++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1664
num_list= list(map(int,input().split()))
li_A=list(range(num_list[0],num_list[1]))
li_B=list(range(num_list[2],num_list[3]))

li_C=range(0, 10)
li_A+=li_B

len_1=len(li_A)
len_2=len(set(li_A))
print(len_1-len_2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b;
  cin>>a>>b;
  if(a==1||b==1){
    cout<<1<<endl;
  }
  else if(a*b%2==1){
  cout<<a*b/2+1<<endl;
  }
  else{
  cout<<a*b/2<<endl;
  }
}


Measured memory_bytes: 3584
from heapq import heappop,heappush
n = int(input())
A = sorted(list(map(int,input().split())))
P = []
M = []
if n == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    exit()
def move():
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
for a in A:
    if a>=0:
        P.append(a)
    else:
        M.append(a)

if A[-1]>=0 and A[0]<0:
    print(sum(abs(a) for a in A))
elif A[0]>=0:
    print(sum(A)-min(A)*2)
    mm = heappop(P)
    pp = heappop(P)
    print(mm,pp)
    heappush(M,mm-pp)
else:
    print(sum(abs(a) for a in A)+max(A)*2)
    mm = M[-1]
    pp = M[-2]
    print(mm,pp)
    M = M[:-2]
    heappush(P,mm-pp)
move()

Measured memory_bytes: 14484
from itertools import combinations
from bisect import bisect

N = int(input())
L = sorted(map(int,input().split()))

def it():
    for i,j in combinations(range(N),2):
        if i+1 < j:
            a,c = L[i],L[j]

            yield max(0,j-bisect(L,abs(a-c), hi=j,lo=i+1))
print(sum(it()))

Measured memory_bytes: 46812
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        //110110011
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        int n=sc.nextInt();
        char c[]=sc.nextString().toCharArray();
        long a[]=new long[26];
        
        for (int i = 0; i < n; i++) {
			a[c[i]-'a']++;
		}
        long ans=1;
        for (int i = 0; i < a.length; i++) {
			ans*=a[i]+1;
			ans%=mod;
		}


        out.println(ans-1);
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int id,T;
    P(int id, int T) {
        this.id=id;
        this.T=T;
    }
    public int compareTo(P p){
        return id-p.id; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 24020
n, k = gets.split.map(&:to_i)

ni = (1r / n)
half = (1r / 2)

ps = (1..n).map do |i|
  if i >= k
    ni
  else
    count = 0
    while i < k
      i *= 2
      count += 1
    end
    ni * half ** count
  end
end

p ps.reduce(:+).to_f


Measured memory_bytes: 2684
from math import sqrt

a, b, c = map(int, input().split())

left = 4 * a * b

r = c - (a + b)
right = r * r

if r < 0 and sqrt(left) < abs(r):
    left = -left
    right = -right

if left < right:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

int main() {
    int n; cin >> n;
    long long k = 1;
    while (k * (k + 1) / 2 < n) k++;
    if (k * (k + 1) / 2 != n) return !(cout << "No" << endl);
    cout << "Yes" << endl << k + 1 << endl;
    vector<vector<int>> res(k + 1, vector<int>(k));
    for (int i = 0, cnt = 1; i < k; i++) {
        for (int j = i; j < k; j++) res[i][j] = res[j][i] = cnt++;
        res[k][i] = res[i][i];
    }
    for (auto &v: res) cout << k << " " << v << endl;
    return 0;
}


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

int main() {
    while (1) {
        int N, X;
        cin >> N >> X;
        if (N == 0 && X == 0) break;
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            for (int j = i + 1; j <= N; j++) {
                for (int k = j + 1; k <= N; k++) {
                    if (i == j || j == k || k == i) continue;
                    if (i + j + k == X) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3120
#define CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int a, b, c, x;
	x = 0;

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

	if (a > b){
		x = x + b;
		b = a;
		a = x;
		x = x * 0;
	}

	if (b > c){
		x = c + x;
		c = b;
		b = x;
		x = x * 0;
	}

	if (a > b){
		x = b + x;
		b = a;
		a = x;
		x = x * 0;
	}
				
	printf("%d %d %d\n", a, b, c);

	return 0;
}


Measured memory_bytes: 1940
function Main(input) {

    input = input.trim();
    var before = '';
    var tmp = '';
    var ans = new Array();
    while (input.length > 0) {
        tmp += input[0];
        input = input.slice(1);
        if (before === tmp) continue;

        ans.push(tmp);
        before = tmp;
        tmp = '';
    }

    console.log(ans.length);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 31924
val memo = hashMapOf<Int, Long>()
fun generatePrime(index: Int): Long {
    if (index == 0) {
        return 2
    }
    if (index == 1) {
        return 3
    }
    memo[index]?.let {
        return it
    }
    val prev = generatePrime(index - 1)
    var next = prev + 2
    var i = 0
    var prime = 0L
    while (i < index - 1 && next > 2 * prime) {
        prime = generatePrime(++i)
        if (next % prime == 0L) {
            next += 2
            i = 1
        }
    }
    memo[index] = next
    return next
}

fun isPrime(candidate: Long): Boolean {
    var i = 0
    var prime = 0L
    while (candidate > 2 * prime) {
        prime = generatePrime(++i)
        if (candidate % prime == 0L) {
            return false
        }
    }
    return true
}

fun main(args: Array<String>) {
    val x = readLine()?.toInt() ?: return
    if (x == 2) {
        println(2L)
        return
    }
    var candidate = x + if (x % 2 == 0) {
        1L
    } else {
        0L
    }
    while (true) {
        val result = isPrime(candidate)
        if (result) {
            println(candidate)
            return
        }
        candidate += 2
    }
}



Measured memory_bytes: 68848
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
#define mp make_pair
#define pb push_back
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int main(){
	int n , m;
	cin>>n;
	cout<<3*n*n;
}

Measured memory_bytes: 4992
#include<iostream>

using namespace std;

#define MOD 1000000007

using lli = long long int;
using ulli = unsigned long long int;

#ifndef EVEL

#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s;
#define dbugln std::cout<<"\n";

#else

#define dbug(X) {X=X;}
#define dbugf(f) {f=f;}
#define dbugln {}

#endif

string A, B;
int main(){
  cin >> A >> B;
  //cout << (int)'0' << ' ' << (int)'1';
  if(A.size() < B.size()){
    cout << "LESS";
  }else if(A.size() > B.size()){
    cout << "GREATER";
  }else if(A == B){
    cout << "EQUAL";
  }else{
    for(int l = 0; l < (int)A.size(); l++){
      if(A[l] == '\0' || B[l] == '\0') break;
      if(A[l] < B[l]){
        cout << "LESS";
        break;
      }else if(A[l] > B[l]){
        cout << "GREATER";
        break;
      }
    }
  }

  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

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

    int D;
    cin >> D;
    ll c[26], a[D][26];
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26) cin >> a[i][j];
    }

    int N = 2400;
    pii pre[D+1][N];
    vector<int> state[D+1][N];
    ll sum[D+1][N];
    fill(sum[0], sum[D+1], -INF);
    sum[0][0] = 0;
    state[0][0].assign(26, -1);

    rep(i, D){
        vector<pair<ll, pii>> next;
        rep(j, N){
            if(sum[i][j] == -INF) break;
            ll pena = 0;
            rep(k, 26){
                pena += c[k]*(i-state[i][j][k]);
            }
            rep(k, 26){
                ll tmp = sum[i][j]+a[i][k]-pena;
                tmp += c[k]*(i-state[i][j][k]);
                next.eb(tmp, pii(j, k));
            }
        }
        sort(all(next), greater<pair<ll, pii>>());
        rep(j, min(N, sz(next))){
            sum[i+1][j] = next[j].first;
            pre[i+1][j] = next[j].second;
            state[i+1][j] = state[i][pre[i+1][j].first];
            state[i+1][j][pre[i+1][j].second] = i;
        }
    }

    ll M = -INF;
    int ptr = 0;
    rep(i, N){
        if(chmax(M, sum[D][i])) ptr = i;
    }

    vector<int> ans(D);
    rep3(i, D, 1){
        ans[i-1] = pre[i][ptr].second;
        ptr = pre[i][ptr].first;
    }
    
    for(auto &e: ans) cout << e+1 << endl;
}

Measured memory_bytes: 135144
#include <iostream>
#include <vector>
using namespace std;
int main(){
  string s;
  cin >> s;
  string c;
  int i;
  for(i=0;i<s.size();i++){
    if(s[i]=='0'){
      c.push_back('0');
    }
    else if(s[i]=='1'){
      c.push_back('1');
    }
    else if(s[i]=='B'){
      if(c.size()==0) continue;
      else c.pop_back();
    }
    else{
      break;
    }
  }
  cout << c << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	private	static	Scanner	stdin = null;

	static {
		stdin = new Scanner(System.in);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]		aParam = new int[2];
		double[]	aPoint = new double[2];
		int			nAngle = 0;

		while(true) {
			aParam = parseParam();
			if (aParam[0] == 0 && aParam[1] == 0) {
				break;
			}

			aPoint[0] = aPoint[0] + (double)aParam[0] * Math.sin(Math.toRadians((double)nAngle));
			aPoint[1] = aPoint[1] + (double)aParam[0] * Math.cos(Math.toRadians((double)nAngle));
			nAngle    = (nAngle + aParam[1] + 360) % 360;
		}

		System.out.printf("%d\n%d\n", (int)aPoint[0], (int)aPoint[1]);
	}

	private static int[] parseParam() {
		int[]		aCross = new int[2];
		String[]	aNum   = stdin.next().split(",");

		aCross[0] = Integer.parseInt(aNum[0]);
		aCross[1] = Integer.parseInt(aNum[1]);

		return aCross;
	}
}

Measured memory_bytes: 17156
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string s;
	cin >> s;
	rep(i, 5) {
		cout << s.at(i);
	}
	cout << " ";
	rep(i, 7) {
		cout << s.at(i+6);
	}
	cout << " ";
	rep(i, 5) {
		cout << s.at(i+14);
	}
	
}


Measured memory_bytes: 256
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))


for i,j in enumerate(permutations(range(1,n+1), n)):
    if j==p:
        a = i+1
    if j==q:
        b = i+1

print(abs(a-b))

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N, K;
    cin >> N >> K;
    int x[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &x[i]);
    }

    int minimum = MOD;
    
    for (int i = 0; i + K - 1 < N; i++) {
        int temp = min(abs(x[i]),  abs(x[i + K - 1])) + x[i + K - 1] - x[i];
        minimum = min(temp, minimum);
    }
    cout << minimum << endl;

    return 0;
}

Measured memory_bytes: 640