akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std; 
 
// Macroes
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)


// declaration


int main() {
    int n; ll k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,0,n) cin >> a[i];

    //訪れた頂点を記録する配列
    vector<int> s;
    //青い文字に対応する配列。-1で初期化している（まだ訪れていないと所は-1）
    vector<int> ord(n+1, -1);
    // c = 周期, l = 例外部分の長さ
    int c = 1, l = 0;
    {
        // 頂点
        int v = 1;
        // すでに訪れたところに来たらwhileが止まる。
        while (ord[v] == -1) {
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }

    if (k < l) cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5888
def main():
    N, M = map(int, input().split())
    if N >=2 and M >=2:
        return (N-2)*(M-2)
    elif [N, M] == [1, 1]:
        return 1
    elif N == 1:
        return M-2
    elif M == 1:
        return N-2

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#!/usr/bin/env python
S = input()
MOD = 10**9+7

a, b, c , d = 0, 0, 0, 1

for s in S:
    if s == 'A':
        a += d
        a %= MOD
    elif s == 'B':
        b += a
        b %= MOD
    elif s == 'C':
        c += b
        c %= MOD
    else:
        a, b, c, d = 3*a+d, 3*b+a, 3*c+b, 3*d
        a %= MOD
        b %= MOD
        c %= MOD
        d %= MOD
ans = c
print(ans)

Measured memory_bytes: 3188
#include "stdio.h"

int main()
{
	const double EPS = 1.0e-10;
	double a, b, c, d, e, f, x, y;

	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
		x = (c*e - f*b)/(a*e - b*d);
		y = (c*d - f*a)/(b*d - a*e);

		if(-0.0005 < x && x < 0.0+EPS) x = 0.0;
        if(-0.0005 < y && y < 0.0+EPS) y = 0.0;

		printf("%0.3f %0.3f\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 648
n=int(input())
low=[]
high=[]
for i in range(n):
    a,b=map(float,input().split())
    low.append(a)
    high.append(b)
low.sort()
high.sort()
if n%2==0:
    low_avg=(low[n//2-1]+low[n//2])/2
    high_avg=(high[n//2-1]+high[n//2])/2
    ans=(high_avg-low_avg)*2+1
else:
    ans=high[(n-1)//2]-low[(n-1)//2]+1
print(int(ans))

Measured memory_bytes: 25420
S = input()
T = input()
ss = []
for i in range(0, len(S) - len(T) + 1):
    for j in range(len(T)):
        if S[i+j] not in ('?', T[j]):
            break
    else:
        s = S[:i] + T + S[i+len(T):]
        ss.append(s.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var hs = new HashSet<int>();
        var count = 0;
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var c2 = int.Parse(line[1]);
            if (c == 0) Console.WriteLine(hs.Add(c2) ? ++count : count);
            else if (c == 1)
                if (hs.Add(c2)) { Console.WriteLine(0); hs.Remove(c2); }
                else Console.WriteLine(1);
            else if (hs.Remove(c2)) count--;
        }
    }
}



Measured memory_bytes: 21540
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define MAX INT_MAX
#define MIN INT_MIN
#define ss second
#define ff first
const int mod = 1e9+7;

int minm(vector<vector<int> > &v){
	int n = v.size();
	vector<vector<int> > dp(n, vector<int>(3, 0));
	dp[0][0] = v[0][0];
	dp[0][1] = v[0][1];
	dp[0][2] = v[0][2];
	for(int i = 1; i < n; i++){
		dp[i][0] = v[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = v[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = v[i][2] + max(dp[i-1][1], dp[i-1][0]);
	}
	return max(dp[n-1][2], max(dp[n-1][0], dp[n-1][1]));
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<vector<int> > v(n,vector<int>(3));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < 3; j++)
			cin >> v[i][j];
	cout << minm(v) << endl;
	return 0;
}


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

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string srs;
getline(cin,srs);
set<char>sajol;
for(int i=0;i<=srs.length();i++)
{
  if(srs[i]>='a' && srs[i]<='z')
  {
    sajol.insert(srs[i]);
  }
}
if(srs.length()==sajol.size()) cout<<"yes"<<endl;
else cout<<"no"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n)-1;i>=0;i--)
#define repf(i,j,n) for(int i=(j);i<(n);i++)

const int maxn=10020;
int dp[maxn];

void amax(int& x,int y){if(x<y)x=y;}

signed main(){
int n,m;cin>>n>>m;
vector<int>a(m);
for(auto&& u:a)cin>>u;
sort(begin(a),end(a),greater<int>());

vector<int>dp(n+15,-1);
dp[0]=0;

vector<int> digit={0,2,5,5,4,5,6,3,7,6};
rep(i,n){
if(dp[i]<0)continue;
rep(j,m){
amax(dp[i+digit[a[j]]],dp[i]+1);
}
}
//rep(i,30)cerr<<dp[i]<<" ";
//cerr<<endl;
int num=dp[n];
int cnt=n;
//cerr<<num;
rep(i,num){
rep(j,m){
if(cnt-digit[a[j]]>=0&&dp[cnt]==dp[cnt-digit[a[j]]]+1){
	cout<<a[j];cnt-=digit[a[j]];break;
}
}
}
cout<<endl;	
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	cout<<(n-k<0?n*x:k*x+(n-k)*y)<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, ans = 0;

  cin >> N;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += i % 2 == 0 && x % 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
using namespace std;

typedef long long int ll;
typedef long double ld;



int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    cin>>n>>m>>x;
    
    int c[n];
    int a[n][m];
    f1(i,0,n)
    {
        cin>>c[i];
        f1(j,0,m)
        cin>>a[i][j];
    }

    int ans = mod;
    int num = 1ll<<n;
    
    for(int i = 0; i < num; i++)
    {
        int cost = 0;
        int arr[m];
        memset(arr, 0, sizeof(arr));

        for(int j = 0; j < n; j++)
        {
            if( (i & (1ll<<j)) > 0)
            {
                cost+=c[j];
                f1(k,0,m)
                arr[k] += a[j][k];
            }
        }
        int flag = 1;
        f1(j,0,m)
        if(arr[j] < x)
            flag = 0;
        
        if(flag)
        ans = min(ans, cost);

    }
    if(ans == mod)
    cout<<-1<<endl;
    else
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll dp[2100][2100] = {0};
ll sum[2100][2100] = {0};
int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> s(n), t(m);
    rep(i, 0, n) cin >> s[i];
    rep(i, 0, m) cin >> t[i];

    dp[0][0] = 0;
    ll ans = 1;
    rep(i, 0, n) rep(j, 0, m) {
        if(s[i] == t[j]) {
            if(i-1 >= 0 && j-1 >= 0) dp[i][j] += sum[i-1][j-1];
            dp[i][j] = (dp[i][j] + 1) % MOD;
        }

        sum[i][j] += dp[i][j];
        if(i-1 >= 0) sum[i][j] += sum[i-1][j];
        if(j-1 >= 0) sum[i][j] += sum[i][j-1];
        if(i-1 >= 0 && j-1 >= 0) sum[i][j] -= sum[i-1][j-1];
        sum[i][j] %= MOD;
        if(sum[i][j] < 0) sum[i][j] += MOD;

        ans += dp[i][j];
        ans %= MOD;
    }

    cout << ans << endl;

}

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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    string S, T;
    cin >> S >> T;
    bool flag = true;
    for(int i=0; i<S.size(); i++){
        if(S[i] != T[i]){
            flag = false;
        }
    }
    
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,n1,n2,n3;
    cin>>n;
    n3=n%10;
    n=n/10;
    n2=n%10;
    n1=n/10;
    if(n1==7||n2==7||n3==7)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



}


Measured memory_bytes: 3632
#include <stdio.h>

int calc(h, w)
{
    int panel[h][w];
    char row[w];

    for (int i = 0; i < h; i++)
    {
        scanf("%s", row);
        // printf("%s\n", row);
        for (int j = 0; j < w; j++)
        {
            if (row[j] == '#')
            {
                panel[i][j] = -1;
            }
            else
            {
                panel[i][j] = 0;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (panel[i][j] == -1)
            {
                continue;
            }

            int count = 0;
            if (0 <= (i - 1) && 0 <= (j - 1) && panel[i - 1][j - 1] == -1)
            {
                //printf("increment a\n");
                count++;
            }
            if (0 <= (i - 1) && panel[i - 1][j] == -1)
            {
                //printf("increment b\n");
                count++;
            }
            if (0 <= (i - 1) && (j + 1) < w && panel[i - 1][j + 1] == -1)
            {
                //printf("increment c\n");
                count++;
            }
            if (0 <= (j - 1) && panel[i][j - 1] == -1)
            {
                //printf("increment d\n");
                count++;
            }
            if ((j + 1) < w && panel[i][j + 1] == -1)
            {
                //printf("increment e\n");
                count++;
            }
            if ((i + 1) < h && 0 <= (j - 1) && panel[i + 1][j - 1] == -1)
            {
                //printf("increment f\n");
                count++;
            }
            if ((i + 1) < h && panel[i + 1][j] == -1)
            {
                //printf("increment g\n");
                count++;
            }
            if ((i + 1) < h && (j + 1) < w && panel[i + 1][j + 1] == -1)
            {
                //printf("increment h\n");
                count++;
            }
            //printf("count: %d\n\n", count);
            panel[i][j] = count;
        }
        //printf("\n");
    }

    // printf("\nHello\n\n");
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (panel[i][j] == -1)
            {
                printf("#");
            }
            else
            {
                printf("%d", panel[i][j]);
            }
        }
        printf("\n");
    }

    return 0;
}

int main()
{
    int h, w;
    scanf("%d %d", &h, &w);

    calc(h, w);

    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int D,c[27],s[365][27],ans[365];
int main() {
	std::random_device rd;
	std::mt19937 mt(rd());
	scanf("%d",&D);
	REP(i,26)scanf("%d",c+i);
	rep(i,D){
		REP(j,26)scanf("%d",&s[i][j]);
	}
	int score=0,last[27]={};
	rep(i,D){
		int max=-INF,cand;
		REP(j,26){
			int cnt=s[i][j];
			REP(k,26){
				if(j!=k)cnt-=c[k]*(D-last[k]);
			}
			if(chmax(max,cnt))cand=j;
		}
		score+=max;
		last[cand]=i;
		std::cout<<cand<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int mm1, mm2;
	mm1 = h1 * 60 + m1;
	mm2 = h2 * 60 + m2;
	cout << mm2 - mm1 - k << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<iostream> 
using namespace std; 
  
int isPalindrome(int n) 
{ 
    
    int rev = 0; 
    for (int i = n; i > 0; i /= 10) 
        rev = rev*10 + i%10; 
  
    
    return (n==rev); 
} 

void countPal(int min, int max) 
{ 
int cnt=0;
    for (int i = min; i <= max; i++)
	{
	 
        if (isPalindrome(i)) 
          {
          	cnt++;
		}
	  }
	  cout<<cnt;
}
int main() 
{ 
    int a,b;
	cin>>a>>b;
	countPal(a,b); 
    return 0; 
} 

Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [f64; n],
  }
  let inv: f64 = a.into_iter().map(|x| 1.0 / x).sum();

  puts!("{:.15}\n", 1.0 / inv);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int N;
int main(){
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(ALL(A));
    int a = A.back();
    int b,d = 1e9;
    rep(i,N-1){
        if(d > abs(a/2 - A[i])) d = abs(a/2 - A[i]), b = A[i];
        if(a%2) if(d > abs(a/2-A[i]+1)) d = abs(a/2-A[i]+1), b = A[i];
    }
    pr(to_s(a)+" "+to_s(b));
}

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

int main(){
	int n,a[100000],sum = 0;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n);
	int l = 0,r = n - 1;
	for(int i = n - 1;i >= 1;i--) a[i] -= a[i - 1];
	while(1){
		int nl = l,nr = r - 1;
		a[l]--;
		while(!a[nl] && nl <= nr) nl++;
		if(nl > nr){
			a[l]++;
			break;
		}
		l = nl;
		r = nr;
	}
	for(int i = l;i <= r;i++) sum += a[i];
	if((l + 1 <= r && (r - l) % 2) || sum % 2 == 0) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];
		sort(a.begin(), a.end());
		vector<int> b(n - 1);
		for (int i = 1; i < n; i++) {
			b[i - 1] = a[i] - a[i - 1];
		}
		sort(b.begin(), b.end());
		cout << b[0] << endl;
	}
}


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

int main() {
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < (int)a.length(); i++) {
        if (a[i] != b[i]) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3916
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;
 

public class Main{
          
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             TreeMap<Integer,Integer> tm_last = new TreeMap<Integer,Integer>();
            while((line=br.readLine())!= null){if(line.isEmpty())break;
                     String[] spl = line.split(",");
                     int n1 = Integer.parseInt(spl[0]),n2 = Integer.parseInt(spl[1]);
                     if(tm_last.containsKey(n1)){
                         tm_last.put(n1, 1+tm_last.get(n1));
                     }else{
                         tm_last.put(n1,1);
                     }
            }        
        TreeMap<Integer,Integer> tm_this = new TreeMap<Integer,Integer>();

            while((line=br.readLine())!= null){if(line.isEmpty())break;
                     String[] spl = line.split(",");
                     int n1 = Integer.parseInt(spl[0]),n2 = Integer.parseInt(spl[1]);
                     if(!tm_last.containsKey(n1)){continue;}
                     if(tm_this.containsKey(n1)){
                         tm_this.put(n1,1+tm_this.get(n1));
                     }else{
                         tm_this.put(n1,1);
                     }
            }
            br.close();
            for(int key : tm_this.keySet()){
                System.out.println(key+" "+(tm_last.get(key)+tm_this.get(key)));
            }
             
         }catch(Exception e){e.printStackTrace();}         
     }
     
}
  

Measured memory_bytes: 15092
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100+7;
struct node{
    int id;
    struct node* next;
};
struct node* graph[MAXN];
int matrix[MAXN][MAXN];
int main() {
    int n;
    scanf("%d", &n);
    int i;
    for(i = 1; i <= n; i++){
        graph[i] = (node*)malloc(sizeof(node));
        graph[i]->next = NULL;
    }
    memset(matrix, 0, sizeof(matrix));
    for(i = 0; i < n; i++){
        int pnum;
        int k;
        scanf("%d", &pnum);
        scanf("%d", &k);

        int j;
        for(j = 0; j < k; j++){
            int r;
            scanf("%d", &r);
            node* newp = (node*)malloc(sizeof(node));
            newp->id = r;
            newp->next = NULL;
            node* p = graph[pnum];
            while(p->next!=NULL){
                p = p ->next;
            }
            p->next = newp;
        }
    }
    for(i = 1; i <= n; i++){
        struct node* p = graph[i]->next;
        while(p!=NULL){
            matrix[i][p->id] = 1;
            p = p->next;
        }
    }
    for(i = 1; i <= n; i++){
        int j;
        for(j = 1; j <= n; j++){
            if(j!=1) printf(" ");
            printf("%d", matrix[i][j]);
        }
        printf("\n");
    }

    return 0;
}



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

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    int N;
    cin >> N;
    multiset<ll> s;
    rep(i,N){
        ll a;
        cin >> a;
        s.insert(a);
    }
    ll cnt;
    vector<Pll> ans(N-1);
    rep(i,N-1){
        ll a,b;
        if (i!=N-2){
            a=*s.begin();
            s.erase(s.begin());
            if (a<0){
                auto itr=s.lower_bound(0);
                if (itr==s.end()) itr=s.end(),--itr;
                b=*itr;
                s.erase(s.lower_bound(b));
                if (s.lower_bound(0)==s.end()) swap(a,b);
                s.insert(a-b);
            }
            else {
                auto itr=s.begin();
                b=*itr;
                s.erase(itr);
                s.insert(a-b);
            }
        }
        else {
            a=*s.rbegin(),b=*s.begin();
            cnt=a-b;
        }
        ans[i]=Pll(a,b);
    }
    cout << cnt << endl;
    rep(i,N-1) cout << ans[i].first << ' ' << ans[i].second << endl;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
#define MAX 5000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> point;
int main(void) {
    ll i, j, h, w, d, q, num, l, r, dis[90002];
    point posi[90001];
    cin >> h >> w >> d;
    for(i=1; i<=h; i++) {
        for(j=1; j<=w; j++) {
            cin >> num;
            posi[num] = make_pair(i, j);
        }
    }
    cin >> q;
    for(i=1; i<=h*w-d; i++)
        dis[i] = 0;
    for(i=1; i<=h*w-d; i++)
        dis[i+d] = dis[i] + abs(posi[i+d].first-posi[i].first) + abs(posi[i+d].second-posi[i].second);
        
    
    for(i=0; i<q; i++) {
        cin >> l >> r;
        cout << dis[r]-dis[l] << endl;
    }
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;

    string ans;

    if(a==b){
        if(a!=c){
            ans="Yes";
        }else{
            ans="No";
        }

    }else if(b==c){
        if(a!=c){
            ans="Yes";
        }else{
            ans="No";
        }
    }else if(c==a){
        if(b!=c){
            ans="Yes";
        }else{
            ans="No";
        }
    }else{
        ans="No";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3616
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

a,b=input2()
print(a*b)



Measured memory_bytes: 27176
m=1e9+7,dp[3333][3333]={1};
c,j;
main(i)
{
	for(gets(&c);c=getchar()%3-1;i++)
	{
		for(;j<=i;j++)dp[i][j]=~c?*dp[i-1]-dp[i-1][j]:dp[i-1][j];
		for(;--j;)dp[i][j-1]=(1L*dp[i][j-1]+dp[i][j]+m)%m;
	}
	printf("%d",*dp[i-1]);
}

Measured memory_bytes: 28800
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val n = 100000
  val prime = eratos(n)
  val table = Array.ofDim[Int](n+1)
  for(i <- 3 to n) {
    if(i % 2 == 1 && prime(i) && prime((i+1)/2)) {
      table(i) = table(i-1) + 1
    }
    else table(i) = table(i-1)
  }

  val q = in.readInt

  Iterator.continually(in.readLine)
    .take(q)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => {
      val l = e(0)
      val r = e(1)
      out.println(table(r) - table(l-1))
    })
  out.flush
  
  def eratos(n:Int):Array[Boolean] = {
    val ret = Array.fill(n+1)(true)
    ret(0) = false
    ret(1) = false
    for(i <- 2 to n) {
      if(ret(i)) {
        var j = i + i
        while(j <= n) {
          ret(j) = false
          j += i
        }
      }
    }
    ret
  }
}

Measured memory_bytes: 49136
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    ll t;
    cin >> n >> t;
    vector<ll> tv(n);
    rep(i, n) cin >> tv[i];
    ll ans = 0;
    ll r = 0;
    rep(i, n) {
        if ( tv[i] < r ) {
            ans += max(0LL, tv[i] + t - r);
        }
        else {
            ans += t;
        }
        r = tv[i] + t;
    } 
    cout << ans << endl;
    return 0;
}


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

const int MAX_A = 1e6;
bool exist[MAX_A + 1];

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

  sort(a.begin(), a.end());

  if (a[0] == 1) {
    if (a[1] == 1) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }

  fill(exist, exist + MAX_A + 1, false);

  int ans = 0;

  for (int i = 0; i < n; i++) {
    if (i != 0) {
      if (a[i - 1] == a[i]) continue;
    }

    if (exist[a[i]]) continue;

    int mul = 1;

    while (a[i] * mul <= MAX_A) {
      exist[a[i] * mul] = true;
      mul++;
    }


    if (i + 1 < n) {
      if (a[i + 1] == a[i]) continue;
    }
    ans++;
  }

  cout << ans << endl;

  return 0;
}

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

#define int long long

using namespace std;

double dp[3000 + 1][3000 + 1];

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


    cout << fixed << setprecision(10);


    int n;
    cin >> n;
    double p[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1;

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = (1 - p[i]) * dp[i - 1][j];
            if(j - 1 >= 0){
                dp[i][j] += p[i] * dp[i - 1][j - 1];
            }
        }
    }

    double ans = 0;

    for(int i = n / 2 + 1; i <= n; i++){
        ans += dp[n][i];
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 74132
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
ans = 0
def bfs(dist, s, queue):
    ret = 0
    while len(queue) > 0:
        y, x = queue.pop(0)
        for i, j in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
            h, w = y + i, x + j
            if 0 <= h < H and 0 <= w < W:
                if s[h][w] == "." and dist[h][w] == -1:
                    dist[h][w] = dist[y][x] + 1
                    queue.append([h, w])
    for i in range(H):
        ret = max(ret, max(dist[i]))
    return ret

for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            dist = [[-1] * W for _ in range(H)]
            dist[i][j] = 0
            queue = [(i, j)]
            ans = max(ans, bfs(dist, s, queue))

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int N,W;
vector<int> v,w;

map<pair<int,int>,int> dp;

int dfs(int i,int j){
  if(dp.find(mp(i,j))!=dp.end()){
    return dp[mp(i,j)];
  }
  if(i==N) return 0;
  if(j-w[i]>=0){
    dp[mp(i,j)]=max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i]);
  }else{
    dp[mp(i,j)]=dfs(i+1,j);
  }
  return dp[mp(i,j)];
}

signed main(){
    cin>>N>>W;
    v.resize(N),w.resize(N);
    rep(i,N)cin>>v[i]>>w[i];

    cout<<dfs(0,W)<<endl;


  return 0;
}

Measured memory_bytes: 55236
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 202
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int ans,n,a[MAX<<1];
int main()
{
	n=read();
	for(int i=1;i<=n+n;++i)a[i]=read();
	sort(&a[1],&a[n+n+1]);
	for(int i=1;i<=n+n;i+=2)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = [i+1 for i in range(N)]
H = [0 for i in range(N)]
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for j in A:
        for k in S:
            if j==k:
                H[k-1] += 1

ans = 0
for i in H:
    if i==0:
        ans += 1

print(ans)

Measured memory_bytes: 9096
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int, int> P;
int main(){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    if(s.size()==2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline())

for i in range(1,n+1):
    x = i
    if x % 3 == 0 or x % 10 == 3:
        print('', i, end='')
        continue

    x //= 10
    while x != 0:
        if x % 10 == 3:
            print('', i, end='')
            break

        x //= 10
print()

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

const int MAX_N = 1000*100;

int main() {
	int N;
	scanf("%d", &N);

	int A[MAX_N], B[MAX_N], C[MAX_N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &B[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &C[i]);
	}
	sort(A, A+N);
	sort(B, B+N);
	sort(C, C+N);

	lli sum = 0;
	for (int i = 0 ; i < N; i++) {
		lli an = lower_bound(A, A+N, B[i]) - A;
		lli cn = C + N - upper_bound(C, C+N, B[i]);
		sum += an*cn;
	}
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#define rep(i,n) for (int i = 0; i < n; ++i)
const int INF = 1001001001;
const double PI = 3.14159265358979323846;

using namespace std;

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double hx, hy, mx, my;
    hx = a * cos((h*60.0 + m) *2*PI / (60.0*12));
    hy = a * sin((h*60.0 + m) *2*PI / (60.0*12));
    mx = b * cos(m*2*PI/60);
    my = b * sin(m*2*PI/60);

    double dx, dy;
    dx = hx - mx;
    dy = hy - my;

    double dist = sqrt(dx*dx + dy*dy);

    printf("%.11f\n", dist);
    return 0;
}

Measured memory_bytes: 4128
n = int(input())
comments = []
for i in range(n):
    a = int(input())
    temp = []
    for j in range(a):
        temp.append([int(x) for x in input().split()])
        
    comments.append(temp)

# 正直者と仮定した人が矛盾した発言をしていないかどうか調べる
# n=5でiが２進数でb00001の時、1番目の人が正直者と仮定している。
max_honest = 0
for member_state in range(2**n):
    flg = False
    for member_num in range(n):
        # member_state で1が立っているということは、正直者と仮定しているということ
        if member_state & 1<< member_num :
            #comments_check(member_state,com)
            for co in comments[member_num]:
                if member_state>>(co[0] - 1) & 1 != co[1] : #コメントが指し示す人物と証言の内容があっていれば矛盾なしとする
                    flg = True
                    break
        if flg == True:
            break
    else:
        # コメントに矛盾がないことが証明されたので正直者の人数を数え、max_honestを更新する
        member_num = 0
        for x in range(n):
            if member_state & 1<< x:
                member_num += 1

        if max_honest < member_num:
            max_honest = member_num

print(max_honest)

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

int main(){

  int N,n,p,c,t;
  int a[51],b[51];
  while(1){
  cin>>N>>n;
  if(N+n==0) break;
  for(int i=1;i<=N;i++){
    a[i]=N+1-i;
    b[i]=N+1-i;
  }

  for(int i=1;i<=n;i++){
    cin>>p>>c;
    t=1;
    for(int j=p;j<p+c;j++){
      b[t]=a[j];
      t++;
    }
      for(int s=1;s<p;s++){
	b[t]=a[s];
	t++;
      }
      for(int w=1;w<=N;w++){
	a[w]=b[w];
      }  
  }

  cout<<b[1]<<endl;
  }
  return 0;
}
  

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

using namespace std;

int arr[500];
long long int dp[500][500], pre[420];
int N;

long long int solve(int i, int j){

    if(i == j-1)
        return arr[i] + arr[j];
    if(i == j)
        return 0;

    if(dp[i][j] != 1e15)
        return dp[i][j];

    for(int low = i; low < j; low++)
        dp[i][j] = min(dp[i][j], solve(i, low) + solve(low+1, j) + pre[j] - pre[i-1]);

    return dp[i][j];

}

int main(){


    cin >> N;

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

    for(int i = 1; i <= N; i++)
        pre[i] = pre[i-1] + arr[i];

    for(int i = 0; i <= N; i++) for(int j = 0; j <= N; j++) dp[i][j] = 1e15;

    cout << solve(1, N);

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int a, b, c; cin >> a >> b >> c;

  if ((a < c && c < b) || (b < c && c < a)) cout << YES << endl;
  else cout << NO << endl;
  
  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    val list = mutableListOf<Int>()
    repeat(n) {
        list.add(readLine()!!.toInt())
    }
    var cnt = 0
    var idx = 1
    while (cnt <= n) {
        if(idx == 2) {
            print(cnt)
            return
        }
        else {
            cnt++
            idx = list[idx-1]
        }
    }
    print(-1)
}

Measured memory_bytes: 58452
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var input2 = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var num = input2[0] >= 3200 ? input2[1] : "red"
  

  
  console.log(num)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import fractions
N = int(input())
A = [int(x) for x in input().split()]
kouho_set = set()
kouho_set = [0] * (N + 1)
kouho_set[0] = set()
kouho_set[0].add(A[1])
nowgcd = A[0]
for i in range(1, N):
    kouho_set[i] = set()
    for j in kouho_set[i-1]:
        kouho_set[i].add(fractions.gcd(A[i], j))
    kouho_set[i].add(nowgcd)
    nowgcd = fractions.gcd(A[i], nowgcd)
# print(kouho_set)
print(max(kouho_set[N-1]))


Measured memory_bytes: 32032
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  if(n % 2 == 1){
    cout << 0 << endl;
    return 0;
  }
  int r = 10, ans = 0;
  while(n >= r){
    ans += n / r;
    r *= 5;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// 2011/02/10 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int m;
		cin >> m;
		if(m==0)
			break;

		int DP[1001];
		DP[0] = 1;
		for(int i=1; i<=1000; i++)
			DP[i] = 0;

		for(int i=0; i<m; i++){
			int a, b;
			cin >> a >> b;

			int DP_tmp[1001];
			for(int j=0; j<=1000; j++){
				DP_tmp[j] = DP[j];
			}

			for(int j=0; j<=1000; j++){
				if(DP[j]==0)
					continue;

				for(int k=1; k<=b; k++){
					if(j+a*k>1000)
						break;

					DP_tmp[j+a*k] += DP[j];
				}
			}

			for(int j=0; j<=1000; j++){
				DP[j] = DP_tmp[j];
			}
		}

		int g;
		cin >> g;

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

			cout << DP[n] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define mxn 200005

using namespace std;
typedef long long ll;

int N, M;

int main(){
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    cin >> M >> N;
    if (N >= M)
        cout << "unsafe\n";
    else cout << "safe\n";

    return 0;
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
	"math"
)

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

	c := 0
	for i := 0; i < n; i++ {
		var z int
		fmt.Scan(&z)

		if isPrime(z) {
			c++
		}
	}

	fmt.Println(c)
}

func isPrime(z int) bool {
	if z == 2 {
		return true
	}
	if z % 2 == 0 {
		return false
	}
	for i := 3; i <= int(math.Sqrt(float64(z))); i = i+2 {
		if z % i == 0 {
			return (z / i < 2)
		}
	}
	return true
}



Measured memory_bytes: 1760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0,cnt=0;
    rep(i,n){
        if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
            ans=max(ans,++cnt);
        }
        else cnt=0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#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;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    cin >> s;
    int aCnt=0;
    int bCnt=0;
    F0R(i,3)
    {
        if(s[i]=='A')
            aCnt++;
        if(s[i]=='B')
            bCnt++;
    }
    if(aCnt && bCnt)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


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

int main() {
  int N,M, S=0 ;
     cin >> N , M=N ; 
   for (int i = 0; ; i++) {
   S += M%10;
   M -= M%10;
   if (M==0) {
    break;}
  M /= 10;    }
  if ( N % S == 0) {
  cout << "Yes" <<endl;}
  else {
  cout << "No" <<endl;}
}



Measured memory_bytes: 256