akhauriyash/Code-Regression huggingface dataset:
'use strict'

function main(input) {

    input = input.split(' ').map(x => Number(x))

    if (input[0] <= 8 && input[1] <= 8) {
        console.log('Yay!')
    } else {
        console.log(':(')
    }
}

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


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

int make_number(vector<int> &a, int l) {
  int res = 0;
  for (int ll=l-1; ll>=0; --ll) {
    res += a[l-ll-1] * pow(10, ll);
  }
  return res;
}

int main() {
  int a0_raw, l, d;
  vector<int> a, a0;

  int i, j;
  int ak_raw;


  while (cin >> a0_raw >> l, a0_raw || l) {
    a0.resize(0); a.resize(0);
    bool reached = false;

    for (int ll=l-1; ll>=0; --ll) {
      d = a0_raw / pow(10, ll);
      a0_raw -= d * pow(10, ll);
      a0.push_back(d);
    }

    a.push_back(make_number(a0, l));

    while (1) {
      sort(a0.begin(), a0.end());
      int amin = make_number(a0, l);

      reverse(a0.begin(), a0.end());
      int amax = make_number(a0, l);

      a0_raw = amax - amin;
      a.push_back(a0_raw);

      i = a.size() - 1;
      rep (j_, i) {
        if (a[i] == a[j_]) {
          j = j_; reached = true;
          break;
        }
      }

      if (reached) break;

      a0.resize(0);
      for (int ll=l-1; ll>=0; --ll) {
        d = a0_raw / pow(10, ll);
        a0_raw -= d * pow(10, ll);
        a0.push_back(d);
      }
    }

    cout << j << " " << a0_raw << " " << i-j << endl;
  }

  return 0;
}

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

void _139() {
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == t[i])
            count++;
    }
    cout << count << endl;
}

void _138() {
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

void _137() {
    int a, b;
    cin >> a >> b;

    int add = a + b;
    int mult = a * b;
    int sub = a - b;

    cout << max(add, max(mult, sub)) << endl;
}

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



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int m, i, n;
	
	m = 100000;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		m *= 1.05;
		
		if (m % 1000 != 0){
			m = (m / 1000 + 1) * 1000;
		}
	}
	
	printf("%d\n", m);
	
	return (0);
}

Measured memory_bytes: 592
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

calc :: Int -> Int -> Int -> Int -> Int
calc d i j k
  | d >= i && d < j = k
  | otherwise = calc d j (2 * j) (k + 1)

main = do
  [x, y] <- getIntList
  let d = y `div` x
  print $ 1 + calc d 1 2 0


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

class Cmondai
{
    static void Main()
    {
        var line = new List<long>();
        long N = 0;
        for (int i = 0; i < 6; ++i)
        {
            var a = Int64.Parse(Console.ReadLine());
            if (i == 0) N = a;
            else line.Add(a);
        }
        var min = line.Min();
        var ans = 0L;
        if (min < N) ans = ((N+min-1) / min) + 4;
        else ans = 5;
        Console.WriteLine(ans);
    }
}


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

int main() {

  int N;
  cin >> N;
  
  set<int> A;
  int same = 0;
  
  for (int i=0; i<N; i++) {
    int x;
	cin >> x;
    int size1 = A.size();
    A.insert(x);
    int size2 = A.size();
    if ( size1 == size2 ) {
      same = 1;
      break;
    }
  }
    
  if (same == 0) {
	cout << "YES" << endl;
  } else if (same == 1) {
	cout << "NO" << endl;
  }
  
  
  
  return 0;
}

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

int main() {
    int N,M;

    cin >> N >> M;
    vector<vector<int>> pref_year(N+1);
    vector<int> P(M), Y(M);
    for(int i=0;i<M;i++){
        cin >> P[i] >> Y[i];
        pref_year[P[i]].push_back(Y[i]);
    }

    map<int,int> year_rank;
    for(int i=0;i<N+1;i++){
        sort(pref_year[i].begin(), pref_year[i].end());
        for(int j=0;j<pref_year[i].size();j++){
            year_rank[pref_year[i][j]] = j+1;
        }
    }

    // for(int i=0;i<N+1;i++){
    //     cout << "pref:" << i << endl;
    //     for(int j=0;j<pref_year[i].size();j++){
    //         cout << "  year:" << pref_year[i][j] << endl;
    //     }
    // }
    for(int i=0;i<M;i++){
            cout << setfill('0') << right << setw(6) << P[i];
            cout << setfill('0') << right << setw(6) << year_rank[Y[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 13312
N, K = map(int, input().split())

MOD = 10**9+7
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1, N+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)

comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
ans = 0

for i in range(1+min(N-1, K)):
  ans += comb(N, i) * comb(N-1, i)
ans %= MOD
print(ans)


Measured memory_bytes: 18764
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
import numpy as np

num_count = [0]*(10**5+1)
num_count = np.array(num_count)
tmp = np.arange(10**5+1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1

for q in range(Q):
    B,C = map(int,input().split())
    tmp_C = C*(num_count[B])
    tmp_B = B*(num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + tmp_C - tmp_B
    print(tmp_sum)

Measured memory_bytes: 32092
H,W=map(int,input().split())
S=[[] for _ in range(H)]

for i in range(H):
    S[i]=input()
    
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n=H*W
inf=10**9

d = [[inf]*n for _ in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            if j+1<W:
                if S[i][j+1]==".":
                    d[i*W+j][i*W+j+1]=1
                    d[i*W+j+1][i*W+j]=1
            if i+1<H:
                if S[i+1][j]==".":
                    d[i*W+j][(i+1)*W+j]=1
                    d[(i+1)*W+j][i*W+j]=1
    
        
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
ans=0

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if d[i][j]>=ans and d[i][j]<=inf-10:
            ans=d[i][j]

print(ans)

Measured memory_bytes: 42864
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int n;

void dfs(string s, char mx){
    if (s.length() == n) {
        printf("%s\n", s.c_str());
    } else {
        for (char c = 'a'; c <= mx; c++) {
            char nmx;
            if (c == mx) {
                nmx = (char) (mx+1);
            } else {
                nmx = mx;
            }
            string ns = s+c;
            // printf("called dfs( %s , %c ) .\n", ns.c_str(), nmx);
            dfs(ns, nmx);
        }
    }
}
int main() {
    cin >> n;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
h,w = map(int,input().split())

al_l = []

for _ in range(h):
    al = list(map(int,input().split()))
    al_l.append(al)
    
ansl = []
get = False
for i in range(h):
    for j in range(w-1):
        if not get:
            if al_l[i][j] % 2 == 1:
                get = True
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
        elif get:
            if al_l[i][j] % 2 == 0:
                get = False
            else:
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            
get = False  
for i in range(h-1):
    if not get:
        if al_l[i][-1] % 2 == 1:
            get = True
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))
    elif get:
        if al_l[i][-1] % 2 == 0:
            get = False
        else:
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))

print(len(ansl))
for ans in ansl:
    print(ans)
        



Measured memory_bytes: 64860
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = (int)1e5 + 10;
ll l[maxN], r[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
    }
    if (n == 1) {
        cout << 0;
        return 0;
    }
    multiset < ll > S1, S2;
    S1.insert(r[1]);
    S2.insert(r[1]);
    ll shift1 = 0;
    ll shift2 = 0;
    ll ans = 0;
    for (int i = 2; i <= n; i++) {
        ll len1 = r[i] - l[i];
        ll len2 = r[i - 1] - l[i - 1];
        shift1 -= len2;
        shift2 += len1;
        ll stL = *(prev(S1.end())) + shift1;
        ll stR = *S2.begin() + shift2;
        if (r[i] >= stR) {
            S2.erase(S2.find(stR - shift2));
            S2.insert(r[i] - shift2);
            S2.insert(r[i] - shift2);
            S1.insert(stR - shift1);
            ans += r[i] - stR;
        }
        else if (r[i] <= stL) {
            S1.erase(S1.find(stL - shift1));
            S1.insert(r[i] - shift1);
            S1.insert(r[i] - shift1);
            S2.insert(stL - shift2);
            ans += stL - r[i];
        }
        else {
            S1.insert(r[i] - shift1);
            S2.insert(r[i] - shift2);
        }
        // should take min(x - len1,
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 11264
using System;
using System.Linq;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var count = inputLongArray[0];
            var legs = inputLongArray[1];


            string result = judge(count, legs);

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        public static string judge(long count, long legs)
        {
            if ((4 * count - legs) % 2 != 0) return "No";
            var result = (4 * count - legs) / 2;
            if (result < 0 || result > count) return "No";
            return "Yes";
        }
    }
}


Measured memory_bytes: 28168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> s(1 << n);
    rep(i, 1 << n)
    {
        rep(k, n)
        {
            if (i & (1 << k))
            {
                s[i] += a[k];
            }
        }
    }
    sort(s.begin(), s.end());

    int q;
    cin >> q;
    rep(i, q)
    {
        int m;
        cin >> m;
        bool ans = binary_search(s.begin(), s.end(), m);

        if (ans)
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6940
#include <iostream>
#include <cstdio>
#define inf 0x3f3f3f3f

using namespace std;

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)==2){
        long long ans;
        if(m==n) printf("-1\n");
        else{
            int i=1;
            ans=n*i;
            int flag=0;
            while(ans<inf){
                if(ans%m!=0)
                {
                    flag=1;
                    break;
                }
                i++;
                ans=n*i;
            }
            if(flag) printf("%lld\n",ans);
            else printf("-1\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
//Author- Vaibhav Singh


#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
*/
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//?????????
   return a * b / gcd(a, b);
}

/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
*/
/*
bool is_prime(ll n){
    for(ll i = 2;i*i<=n;i++){
        if(n%i == 0) return false;
    }
    return true;
}
*/
int inv(int a){
    return powerm(a,mod-2,mod);
}

ll const N=1e5;
ll fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
ll ncr(ll n, ll r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}


//*88888*********5555555555555555******88888888$$$$$$$$$$******!!!!!!!!!!

       int main()
       {
           //????????
    fast

    ll a,b;
    cin>>a>>b;
    ll z=a*b;
    if(a>9||b>9)
    {
        o("-1")
        re
    }
        o(z)












//?????????
re}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

int step[100010];

int main(){
    int n, m;
    cin >> n >> m;
    int a[m];
    for(int i = 0; i < m; i++){
        cin >> a[i];
        step[a[i]] = 1;
    }
    long long l[n+1];
    l[0] = 1;
    if(step[1] != 1){
        l[1] = 1;
    }else{
        l[1] = 0;
    }
    for(int i = 2; i <= n; i++){
        if(step[i] == 1){
            l[i] = 0;
        }else{
            l[i] = (l[i-1]+l[i-2]) % MOD;
        }
    }

    cout << l[n] << endl;
    
    return 0;
}


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

int f(int a, int b, int c, int cnt) {
  if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0)
    return cnt;
  if (a == b && b == c)
    return -1;
  int aa = a / 2, bb = b / 2, cc = c / 2;
  return f(bb + cc, cc + aa, aa + bb, cnt + 1);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << f(a, b, c, 0) << endl;
}

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

struct Node {
	int key;
	Node *left = nullptr;
	Node *right = nullptr;
	Node *parent = nullptr;

	Node(int k): key(k) {}
};

Node *bst;

void bst_insert(int key) {
	Node *p = nullptr;
	Node *n = bst;

	while (n) {
		p = n;
		if (key < n->key) {
			n = n->left;
		} else if (key > n->key) {
			n = n->right;
		}
	}

	Node *node = new Node(key);
	node->parent = p;
	if (p == nullptr) {
		bst = node;
	} else if (key < p->key) {
		p->left = node;
	} else {
		p->right = node;
	}
}

void preorder(Node *tree) {
	if (tree) {
		std::cout << " " << tree->key;
		preorder(tree->left);
		preorder(tree->right);
	}
}

void inorder(Node *tree) {
	if (tree) {
		inorder(tree->left);
		std::cout << " " << tree->key;
		inorder(tree->right);
	}
}

int main()
{
	int m;
	std::cin >> m;
	while (m--) {
		std::string operation;
		std::cin >> operation;
		if (operation == "insert") {
			int key;
			std::cin >> key;
			bst_insert(key);
		} else {
			inorder(bst);
			std::cout << std::endl;
			preorder(bst);
			std::cout << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 26572
#include <bits/stdc++.h>
#define MAX 100010
using namespace std;

int mark[MAX], counter = 0;
int bit[MAX];
bool isPrime[MAX];

void genSieve()
{
    memset(isPrime, false, sizeof(isPrime));

    int limit = sqrt(MAX) + 1;

    mark[1] = 1;
    for(int i = 4; i < MAX; i += 2){
        mark[i] = 1;
    }

    isPrime[2] = true;

    for(int i  = 3; i < MAX; i += 2){
        if(!mark[i]){
            isPrime[i] = true;
            if(i <= limit){
                for(int j = i * i; j < MAX; j += i * 2){
                    mark[j] = 1;
                }
            }
        }
    }
}


void update(int idx, int value)
{
    while(idx <= MAX){
        bit[idx] += value;
        idx += (idx & -idx);
    }
}

int query(int idx)
{
    int sum = 0;
    while(idx > 0){
        sum += bit[idx];
        idx -= (idx & -idx);
    }

    return sum;
}

int main()
{
    genSieve();
    int q, l, r;

    for(int i = 1; i < MAX; i++){
        if(isPrime[i] && isPrime[(i + 1) / 2]){
            update(i, 1);
        }
    }

    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%d %d", &l, &r);
        printf("%d\n", query(r) - query(l-1));
    }

    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main (){
     string s;
     cin >> s ;
     ll n = s.size();
     for(int i=0;i<n;i++){
          ll a = s.at(i)-48;
          ans += a ;
          ans %= 9;
     }
     if(ans == 0) cout << "Yes"  << endl;
     else cout << "No" << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

#define N 3
#define N2 9

struct Puzzle {
  int f[N2];
  int space;
  string path;
  bool operator < (const Puzzle &p) const {
    rep(i, 0, N2) {
      if (f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = { -1, 0, 1, 0};
static const int dy[4] = { 0, -1, 0, 1};
static const char dir[4] = { 'u', 'l', 'd', 'r'}; // up, left, down, right

bool isTarget(Puzzle p) {
  rep(i, 0, N2) {
    if (p.f[i] != (i+1)) {
      return false;
    }
  }
  return true;
};

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    if (isTarget(u)) return u.path;
    int sx = u.space / N; // row
    int sy = u.space % N; // column

    rep(r, 0, 4) {
      // tx, ty 交換する先のrow, column
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;

      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if (!V[v]) {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";
};

int main() {
  Puzzle in;
  rep(i, 0, N2) {
    cin >> in.f[i];

    if (in.f[i] == 0) {
      in.f[i] = N2; // set space
      in.space = i;
    }
  }

  string ans = bfs(in);
  cout << ans.size() << endl;
};



Measured memory_bytes: 30592
# include <iostream>
# include <vector>

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

int main() {
    int n, t; cin >> n >> t;
    vector<pair<int, int>> routes(n);

    int _c, _t;
    rep (i, n) {
        cin >> _c >> _t;
        routes[i] = make_pair(_c, _t);
    }

    int idx = 1;
    int cst = 1001001001;

    for (pair<int, int> route: routes) {
        if (route.second <= t and route.first < cst) {
            cst = route.first;
        }
    }

    if (cst != 1001001001) cout << cst << endl;
    else cout << "TLE" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){

    int n;
    cin >> n;
    const int t = n;
    vector<int> v(t);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
    int count = 0;
    vector<vector<int>> ve;
    do {
        vector<int> c;
        for(auto x : v) {
            c.emplace_back(x);
            //cout << x << " "; cout << "\n";    // v の要素を表示
        }
        ve.emplace_back(c);
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成
    rep(i,10){
        rep(j,n){
            //cout << ve[i][j];
        }
        //cout << endl;
    }

    vector<int> p;
    rep(i,n){
        int x;
        cin >> x;
        p.emplace_back(x);
    }
    int pi=0;
    rep(i,ve.size()){
        bool b=true;
        rep(j,n){
            if(ve[i][j]!=p[j]) b=false;
        }
        if(b){
            pi=i;
            break;
        }
        else{
            b=true;
        }
    }

    vector<int> q;
    rep(i,n){
        int x;
        cin >> x;
        q.emplace_back(x);
    }
    int qi=0;
    rep(i,ve.size()){
        bool b=true;
        rep(j,n){
            if(ve[i][j]!=q[j]) b=false;
        }
        if(b){
            qi=i;
            break;
        }
        else{
            b=true;
        }
    }

    cout << abs(pi-qi) << endl;

}

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


Measured memory_bytes: 3384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> ans(n + 1, 0);
    int a, b;
    rep(i, m)
    {
        cin >> a >> b;
        ans[a]++;
        ans[b]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << endl;
    }
    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 pb push_back
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

int main(){
  int h, a;
  cin >> h >> a;
  if(h%a==0){
    cout << h / a << endl;
  }else{
    cout << h / a + 1 << endl;
    
  }
}

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

int main(void) {
	int n;
	while (scanf("%d", &n) == 1 && n > 0) {
		int i;
		int64_t a[12345];
		int64_t sum = 0;
		int count = 0;
		for (i = 0; i < n; i++) {
			if (scanf("%" SCNd64, &a[i]) != 1) return 1;
			sum += a[i];
		}
		for (i = 0; i < n; i++) {
			if (a[i] * n <= sum) count++;
		}
		printf("%d\n", count);
	}
	return 0;
}



Measured memory_bytes: 2040
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  string A, B;
  rep(i, b) A += to_string(a);
  rep(i, a) B += to_string(b);
  if (A < B)
    cout << A << endl;
  else
    cout << B << endl;
  return 0;
}


Measured memory_bytes: 256
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let perm n k =
  Array.fold_left ( *^ ) 1 @@
  Array.init k @@ fun i -> (i + n - k + 1) mod m
let comb n k = power ( *^ ) (perm n k) (perm k k) (m - 2)

let () = Scanf.scanf "%d %d %d" @@ fun n a b ->
  Printf.printf "%d\n" @@ power ( *^ ) 1 2 n -^ comb n a -^ comb n b -^ 1

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  string s;
  cin >> s;

  string result = "";
  int n = (int)(s.length());
  REP(i,n){
    if(((i+1)%2 != 0 && s[i] != 'L') || ((i+1)%2 == 0 && s[i] != 'R')){
      result = "Yes";
      continue;
    }
    result = "No";
    break;
  }

  cout << result << endl;
  return 0;
}


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

int N;
int t[111111], x[111111], y[111111];

int main() {
   cin >> N;
   for (int i = 1; i <= N; i++) {
      cin >> t[i] >> x[i] >> y[i];
   }

   for (int i = 1; i <= N; i++) {
      int dist = abs(x[i-1]-x[i]) + abs(y[i-1]-y[i]);
      int tt = t[i] - t[i-1];
      if (dist > t[i] || (dist + tt) % 2) {
         puts("No");
         return 0;
      }
   }

   puts("Yes");

   return 0;
}

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

int main(){
  string s;
  cin >> s;
  cout << s.at(0) << s.at(1) << s.at(2) << s.at(3) << s.at(4) << " " << s.at(6) << s.at(7) << s.at(8) << s.at(9) << s.at(10) << s.at(11) << s.at(12) << " " << s.at(14) << s.at(15) << s.at(16) << s.at(17) << s.at(18) <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define QWQ puts("successfully enter.")
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define FILL(a,val) memset(a,val,sizeof(a))
#define ll long long
ll a,b,k;
void display(initializer_list<int> out)
{
	cout<<"DISPLAY:";
	for(auto x:out) cout<<x<<' ';
	puts("");
}
int main()
{
	cin>>a>>b>>k;
	if(a>=k) a-=k;
	else b=max(b-(k-a),0LL),a=0;
	cout<<a<<' '<<b;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
long long dist[1 << 18];
long long group[1 << 18]; string q;
long long n, Q, a, b, c;
vector<long long>gr[1 << 18];
int main() {
	for (int i = 0; i < (1 << 18); i++) {
		dist[i] = 0; group[i] = i; gr[i].clear(); gr[i].push_back(i);
	}
	cin >> n >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> q;
		if (q == "COMPARE") {
			cin >> a >> b;
			if (group[a] != group[b])cout << "WARNING" << endl;
			else cout << dist[b] - dist[a] << endl;
		}
		if (q == "IN") {
			cin >> a >> b >> c;
			long long L = group[a], M = group[b];
			if (group[a] != group[b] && gr[L].size() >= gr[M].size()) {
				long long K = dist[a] + c - dist[b];
				for (int j = 0; j < gr[M].size(); j++) {
					group[gr[M][j]] = L;
					gr[L].push_back(gr[M][j]);
					dist[gr[M][j]] += K;
				}
				gr[M].clear();
			}
			else if (group[a] != group[b]) {
				long long K = dist[b] - c - dist[a];
				for (int j = 0; j < gr[L].size(); j++) {
					group[gr[L][j]] = M;
					gr[M].push_back(gr[L][j]);
					dist[gr[L][j]] += K;
				}
				gr[L].clear();
			}
			dist[a] += c; dist[b] += c;
		}
	}
	return 0;
}

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

import itertools
import math

n = int(input())

ans = 0
ans1 = 0
ans2 = 0
ans3 = 0
for i, j, k in itertools.combinations(range(1, n+1), 3):
    ans1 += math.gcd(math.gcd(i, j), k)*6

for i, j in itertools.combinations(range(1, n+1), 2):
    ans2 += math.gcd(i, j) * 3 * 2

ans3 += (1 + n)*n//2

# print(ans1, ans2, ans3)
print(ans1+ans2+ans3)


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

void dfs(int i, string const& s, string now, vector<bool>& used, vector<string>& res) {
    if(i == s.size()) {
        res.push_back(now);
        return;
    }
    if(s[i] == 'a' || used[s[i]-'a']) {
        dfs(i+1, s, now+s[i], used, res);
    }
    if(s[i] != 'z' && !used[s[i]-'a'+1]) {
        used[s[i]-'a'+1] = true;
        dfs(i+1, s, now+(char)(s[i]+1), used, res);
        used[s[i]-'a'+1] = false;
    }
}
int main() {
    string s;
    while(cin >> s, s != "#") {
        vector<bool> used(26, false);
        vector<string> res;
        dfs(0, s, "", used, res);
        cout << res.size() << endl;
        if(res.size() <= 10) {
            for(auto& x : res) {
                cout << x << endl;
            }
        } else {
            for(int i=0; i<5; ++i) {
                cout << res[i] << endl;
            }
            for(int i=0; i<5; ++i) {
                cout << res[res.size()-5+i] << endl;
            }
        }
    }
}


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


int main(){
    //int A,B,C,D,E;
    //cin >> A >> B >> C >> D >> E;
    
    vector<int> cook_time(5);
    vector<int> ret_cook_time(5);
    rep(i,5){
        cin >> cook_time[i];
    }
    
    int total;
    int min_time = 130*5;
    rep(i,5){
        total=0;
        ret_cook_time = cook_time;
        for(int j=0; j<5; j++){
            if(i !=j ){
                if(ret_cook_time[j] % 10 != 0){
                    ret_cook_time[j] = (ret_cook_time[j]/10)*10 + 10;
                }
            }
            total += ret_cook_time[j];
        }
        
        min_time = min(min_time, total);
    }
    cout << min_time << endl;
}


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


int main()
{   
    long long X;
    cin >> X;
    vector<long long> array5(1, 0);
    long long a, n;
    n = 1;
    while(true){
        a = 1;
        for(int i=0; i<5; i++){
            a *= n;
        }

        if(a-array5[n-1] > X){
            break;
        }
        
        array5.push_back(a);

        n += 1;
    }
    
    
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            // i: pos
            if(array5[i] - array5[j] == X){
                cout <<  i << " " <<  j << endl;              
                return 0;
            }   
            if(array5[i] + array5[j] == X){
                cout <<  i << " " << -j << endl;            
                return 0;
            }
            
            // i: neg
            if(-array5[i] - array5[j] == X){
                cout <<  -i << " " <<  j << endl;              
                return 0;
            }
            // neg
            if(-array5[i] + array5[j] == X){
                cout <<  -i << " " << -j << endl;            
                return 0;
            }
        }
    }
  

}


Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,pair<int,int> > > g[11000];
int v[11000];
int ijk[11000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)g[i].clear();
		for(int i=0;i<b;i++){
			int p,q,r,s;
			scanf("%d%d%d%d",&p,&q,&r,&s);
			p--;q--;
			g[p].push_back(make_pair(q,make_pair(r,s)));
			g[q].push_back(make_pair(p,make_pair(r,s)));
		}
		for(int i=0;i<a;i++)ijk[i]=999999999;
		for(int i=0;i<a;i++)v[i]=0;
		priority_queue<pair<pair<int,int>,int> > Q;
		Q.push(make_pair(make_pair(0,0),0));
		ijk[0]=0;
		int ret=0;
		while(Q.size()){
			int cost=-Q.top().first.first;
			int at=Q.top().second;
			int val=-Q.top().first.second;
			Q.pop();
			if(v[at])continue;
			v[at]=1;
			ret+=val;
			for(int i=0;i<g[at].size();i++){
				if(!v[g[at][i].first]&&ijk[g[at][i].first]>=cost+g[at][i].second.first){
					ijk[g[at][i].first]=cost+g[at][i].second.first;
					Q.push(make_pair(make_pair(-ijk[g[at][i].first],-g[at][i].second.second),g[at][i].first));
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long n;
	cin >> n;
	long long min = -1;
	for (long long i = 1; i*i <= n; i++) {
		if (n%i != 0)
			continue;
		long long a = n/i;
		long long tmp = (i-1)+(a-1);
		if (min == -1)
			min = tmp;
		else {
			if (tmp < min)
				min = tmp;
		}
	}
	cout << min << endl;
	return 0;
}

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

int main(){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
     
  if((e - a) > k){
      cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            if i % a[0] == 1:
                print(1)
                exit()
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])


Measured memory_bytes: 14864
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
int f1[MAX],f2[MAX];
int n,k,l;
map<int,map<int,int>>mp;
void init(int n){
	for(int i=0;i<=n;i++)
		f1[i]=f2[i]=i;
}
int FIND(int x,int f[]){
	return  f[x]==x?x:f[x]=FIND(f[x],f);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>k>>l;
	init(n);
	for(int i=1;i<=k;i++){
		int x,y;cin>>x>>y;
		int fx=FIND(x,f1),fy=FIND(y,f1);
		if(fx!=fy) f1[fx]=fy;
	}
	for(int i=1;i<=l;i++){
		int x,y;cin>>x>>y;
		int fx=FIND(x,f2),fy=FIND(y,f2);
		if(fx!=fy) f2[fx]=fy;
	}
	for(int i=1;i<=n;i++)
		mp[FIND(i,f1)][FIND(i,f2)]++; 
	 for(int i=1;i<=n;i++)
	 	cout<<mp[FIND(i,f1)][FIND(i,f2)]<<" "; 
	
   return 0;
} 

Measured memory_bytes: 30716
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

N = int(input())
print(N ** 3)


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

int main(){
    int N,M,K;
    cin>>N>>M>>K;
    vector<int> D(M);
    for(int i=0;i<M;i++){
      cin>>D[i];
      D[i]--;
    }

    vector<int> darkness(N,-1);
    for(int i=0;i<M;i++){
      darkness[D[i]]=i;
    }

    vector<vector<int> > v(N, vector<int>(K));
    for(int i=0;i<N;i++){
      for(int j=0;j<K;j++){
        cin>>v[i][j];
        v[i][j]--;
      }
    }
    vector<int> dist((1<<M),2000);
    queue<int> que;
    que.push((1<<M)-1);
    dist[(1<<M)-1]=0;
    while(!que.empty()){
      int now=que.front();
      que.pop();
      for(int k=0;k<K;k++){
        int next_mask=0;
        for(int m=0;m<M;m++){
          if(now & (1<<m)){
            int next = v[D[m]][k];
            if(darkness[next]<0)continue;
            next_mask |= (1<<darkness[next]);
          }
        }
        if(dist[next_mask]>dist[now]+1){
          dist[next_mask]=dist[now]+1;
          que.push(next_mask);
          if(next_mask==0){
            cout<<dist[0]<<endl;
            return 0;
          }
        }
      }
    }
}

Measured memory_bytes: 3472
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import javax.management.monitor.CounterMonitor;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="Yes";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();

        PriorityQueue pq=new PriorityQueue();

        pq.add(P);
        pq.add(Q);
        pq.add(R);

        answer+=(int)pq.poll();
        answer+=(int)pq.poll();
        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        //System.err.println(space);
        //System.err.println(sSwitch);
        System.out.println(answer);
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll N, K, ans;

int main()
{
	int i, j;

	scanf("%lld%lld", &N, &K);

	ll p=0;
	for(i=1; i<=N; i++) if(i%K==0) p++;
	ans+=p*p*p;

	if(K%2==0)
	{
		p=0;
		for(i=1; i<=N; i++) if(i%K==K/2) p++;
		ans+=p*p*p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
import sys
from collections import deque
from bisect import bisect_right
from math import ceil
def input(): return sys.stdin.readline().strip()

N, D, A = map(int, input().split())
monsters = [(-1, -1)]
for _ in range(N):
    x, h = map(int, input().split())
    monsters.append((x, h))
monsters.sort()
#print("monsters = {}".format(monsters))
"""
どうせ左端のモンスターはいつか倒さないといけない（かつ爆弾投下順は不問）ので、
左端のモンスターから順に、なるべく爆弾を右に寄せて落としていけば良い。

別解としてBITでも殴ってみた
"""
class BIT:
    """
    https://tjkendev.github.io/procon-library/python/range_query/bit.html
    Binary index treeの実装
    配列[a1, a2,...,an]に対して以下のクエリをO(logn)で行う:
        1. aiにxを加える
        2. 区間和 ai + a(i+1) + ... + aj の和を求める
    """
    def __init__(self, n):
        """
        添字は1スタート
        """
        self.n = n
        self.data = [0] * (n + 1)
        self.el = [0] * (n + 1)

    def add(self, i, x):
        """
        i>0に対してaiにxを加算(x < 0でもOK)
        """
        if i <= 0 or self.n < i:
            print("i should be within 1 to n")
        else:
            self.el[i] += x
            while i <= self.n:
                self.data[i] += x
                i += i & -i

    def sum(self, i):
        """
        添字1からiまでの累積和を求める
        """
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def get(self, i, j=None):
        """
        添字iからjまでの累積和を求める
        j=Noneの場合はaiの値を返す
        """
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i - 1)

"""
BITで区間に対する加算をする場合はimos法を利用することに注意する
"""

Damage = BIT(N)
ans = 0
for i in range(1, N + 1):
    x, h = monsters[i]
    d = Damage.sum(i) # モンスターiに入っているダメージ
    if d < h:
        times = ceil((h - d) / A)
        ans += times
        new_damage = times * A
        #print("ans+={} for monster {}".format(times, i))

        idx = bisect_right(monsters, (monsters[i][0] + 2 * D, 10**10))
        Damage.add(i, new_damage)
        if idx != N + 1:
            Damage.add(idx, -new_damage)

print(ans)


Measured memory_bytes: 107100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
const int maxn = 1e5 + 100;
int t[maxn], x[maxn], y[maxn];
int N;

bool pd(int x1, int x2, int y1, int y2, int t1, int t2)
{
	if (x1 == x2&&y1 == y2) return false;
	int tmp = abs(x1 - x2) + abs(y1 - y2);
	int t = abs(t1 - t2);
	if (t < tmp) return false;
	else {
		if ((tmp % 2 == 1) && (t % 2 == 1)) return true;
		if ((tmp % 2 == 0) && (t % 2 == 0)) return true;
		return false;
	}
}

int main()
{
	while (cin>>N)
	{
		t[0] = x[0] = y[0] = 0;
		for (int i = 1; i <= N; i++) {
			cin >> t[i] >> x[i] >> y[i];
		}
		int flag = 1;
		for (int i = 1; i <= N; i++) {
			if (!pd(x[i], x[i - 1], y[i], y[i - 1], t[i], t[i - 1])) {
				flag = 0; break;
			}
		}
		if (flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(void){
    
    int i,n,r[100000],l[100000],s=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&l[i],&r[i]);
    }
    for(i=0;i<n;i++){
        s+=r[i]-l[i]+1;
    }
    
    printf("%d\n",s);
    return 0;
}


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

using namespace std;

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

	int n,t;
	vector <int> v;
	long long int sum = 0;
	long long int res = 0;
	const long long int MOD = 1e9 + 7;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	for(int i=0;i<n;i++)
	{
		res = ((res%MOD) + (sum*v[i]%MOD)%MOD)%MOD;
		res%=MOD;
		sum = ((sum%MOD) + (v[i]%MOD)%MOD)%MOD;
		sum%=MOD;
	}

	cout << res << '\n';
	
	return 0;	
}

Measured memory_bytes: 4256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL P[200000];

LL ans = 0;

void solve(){
	vector<int> index_P(N+1);
	for(int i=0;i<N;i++) index_P[P[i]] = i;

	int max_seq = 1;
	int seq = 1;
	for(int i=1;i<=N-1;i++){
		if(index_P[i]<index_P[i+1]){
			seq++;
			if(i==N-1) max_seq = max(max_seq,seq);
		}
		else{
			max_seq = max(max_seq,seq);
			seq = 1;
		}
	}
	ans = N - max_seq;
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> P[i];
 
    solve();

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

Measured memory_bytes: 2560
N,A,B=list(map(int, input().split()))
sum=0
count=0
flag=False
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            for l in range(0,10):
                if count==N+1:
                    break

                count+=1

                if count==1:
                    continue

                if i+j+k+l>=A and i+j+k+l<=B:
                    sum+=i*1000+j*100+k*10+l
    if flag:
        break

if count==10000 and A==1:
    sum+=10000
print(sum)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    ll sum = 0;
    ll minnum = 1ll << 60;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        sum += a;
        if (a > b)
            minnum = min(minnum, (ll)b);
    }

    cout << (minnum == (1ll << 60) ? 0 : sum - minnum) << endl;
    return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<ll> a(51), b(51), c(51), d(51);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];

    int ans[51];
    for(int i=0; i<n; i++){
        ll tmp =400000000;
        int ids = 0;
        for(int j=0; j<m; j++){
            ll dis =0;
            dis = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(dis < tmp){
                tmp = dis; ids = j+1;
            }
        }
        ans[i] = ids;
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool mp[401][401];

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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    REP(i,401)REP(j,401)mp[i][j]=false;
    mp[200][200] = true;
    vector<pii> pos(n);
    pos[0] = make_pair(200,200);
    REP(i,n-1){
      int x,d;
      cin>>x>>d;
      pii t = pos[x];
      mp[t.first+dx[d]][t.second+dy[d]] = true;
      pos[i+1] = make_pair(t.first+dx[d],t.second+dy[d]);
    }
    int l=200,r=200,t=200,b=200;
    REP(i,401)REP(j,401){
      if(mp[i][j]){
        l = min(l,i);
        r = max(r,i);
        t = max(t,j);
        b = min(b,j);
      }
    }
    cout << (r-l+1) << " " << (t-b+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100002
ll max(ll a,ll b){return a>b?a:b;}
struct node{
	ll b,c;
}op[maxn];
bool cmp(node a,node b){return a.c>b.c;}
ll n,m,a[maxn],s,pn,pop;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<m;i++)
		cin>>op[i].b>>op[i].c;
	sort(op,op+m,cmp);
	while(pn<n&&pop<m){
		ll chg=op[pop].b;
		while(chg&&pn>=0)a[pn]=max(a[pn],op[pop].c),chg--,pn++;
		pop++;
	}
	for(int i=0;i<n;i++)
		s+=a[i];
	cout<<s;
    return 0;
}

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

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

    long long n, a, b;
    cin >> n >> a >> b;
    long long allblue = (n / (a + b)) * a;
    long long amari = n % (a + b);
    if(amari >= a) {
      allblue += a;
    }else {
      allblue += amari;
    }
    cout << allblue << endl;
}

Measured memory_bytes: 256