akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
import math

n = int(input())

for data in sys.stdin:
    x1, y1, x2, y2, x3, y3 = map(float, data.split())
    a1 = x2 - x1
    b1 = y2 - y1
    a2 = x3 - x1
    b2 = y3 - y1
    px = (b2 * (a1 * a1 + b1 * b1) - b1 * (a2 * a2 + b2 * b2)) / (2 * (a1 * b2 - a2 * b1))
    py = (a1 * (a2 * a2 + b2 * b2) - a2 * (a1 * a1 + b1 * b1)) / (2 * (a1 * b2 - a2 * b1))
    r = math.sqrt(px * px + py * py)
    px += x1
    py += y1
    print("{0:.3f} {1:.3f} {2:.3f}".format(px, py, r))

Measured memory_bytes: 6824
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int n;
  vector<int> a_list;
  map<int, int> a;
  while (cin >> n) {
    a[n]++;
    a_list.push_back(n);
  }
  sort(a_list.begin(), a_list.end());
  a_list.erase(unique(a_list.begin(), a_list.end()), a_list.end());
  int max_n = 0;
  int i;
  for (i = 0; i < a_list.size(); i++) {
    max_n = max(max_n, a[a_list[i]]);
  }
  for (i = 0; i < a_list.size(); i++) {
    if (a[a_list[i]] == max_n) {
      cout << a_list[i] << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3084
program sample
    implicit none
    character(100) :: s,t,u
    integer(8) :: i,j,m,n
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)
    read(*,*) s
    read(*,*) t
    m=len_trim(s)
    n=0
    

    do i=1,m
        if(s .eq. t)then
            write(*,*)'Yes'
            stop
        end if
        do j=2,m
            u(j:j)=s(j-1:j-1)
        end do
        u(1:1)=s(m:m)
        do j=1,m
            s(j:j)=u(j:j)
        end do

    end do

    
 
    write(*,*) 'No'
 
    stop
end program sample
  



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

using namespace std;
int main(){
    int n, n_swaps=0;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    
    //Selection sort
    int m, temp;
    for(int i=0; i<n; i++){
        m = i;
        for(int j=i+1; j<n; j++){
            if(v[j] < v[m]) m=j;
        }
        if(m!=i){
            temp = v[m];
            v[m] = v[i];
            v[i] = temp;
            n_swaps++; 
        }
    }
    
    for(int i=0; i<n; i++) cout << v[i] << " \n"[i==n-1];
    cout << n_swaps << endl;
    
    return 0;
}


Measured memory_bytes: 3100
s = input()
t = input()
ans = 1000
c = 0


for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] == t[j]:
            c += 1
    ans = min(len(t) - c , ans)
    c = 0

print(ans)

Measured memory_bytes: 8964
N = int(input())
S = list(input())
E = [0]*N #i番目より左側に、右向いてる人が何人
W = [0]*N #i番目より右側に、左向いてる人が何人

for i in range(1,N):
    E[i] = E[i-1]
    if S[i-1]=="E":
        E[i]+=1
for i in range(1,N):
    W[N-i-1] = W[N-i]
    if S[N-i]=="W":
        W[N-i-1]+=1

out = [0]*N
for i in range(N):
    out[i] = (N-1) - (W[i]+E[i])
print(min(out))

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

int ele[1000001];
int dp1[1000001];
int dp2[1000001];

int main() {
  rep(i, 181) ele[i] = (i + 1) * (i + 2) * (i + 3) / 6;
  vector<int> nn;
  while (1) {
    int n;
    cin >> n;
    if (n < 1) break;
    nn.push_back(n);
  }
  memset(dp1, 1, sizeof(dp1));
  memset(dp2, 1, sizeof(dp2));

  dp1[0] = 0;
  dp2[0] = 0;
  rep(i, 1000001) rep(j, 180) {
    if (i + ele[j] > 1000001) break;
    dp1[i + ele[j]] = min(dp1[i + ele[j]], dp1[i] + 1);
    if (ele[j] % 2 == 1) dp2[i + ele[j]] = min(dp2[i + ele[j]], dp2[i] + 1);
  }

  for (int n : nn) {
    printf("%d %d\n", dp1[n], dp2[n]);
  }
  return 0;
}


Measured memory_bytes: 11076
# include <bits/stdc++.h>
using namespace std ;
int main () {
string S , T ; cin >> S >> T ;
bool ans = false ;
for ( int i = 0; i < S . size (); ++ i ) {
if ( S == T ) {
ans = true ;
break ;
}
S = S . back () + S . substr (0 , S . size () -1);
}
if ( ans ) {
cout << " Yes " << endl ;
}
else {
cout << "No" << endl ;
}
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

vector<int>dices;
struct masu {
	int num;
	int type;
	int a;
};
map<int, masu>mp;
int X, Y, Z;
vector<vector<ld>>memo;

ld getans(const int nowplace,const int nowmoney) {
	if (memo[nowplace][nowmoney] < -0.5) {
		ld ans = 0;
		
		for (auto di : dices) {
			int nextmoney(nowmoney);
			int next = nowplace + di;
			if (next<Y) {
				if (mp.find(next) != mp.end()) {
					auto it = mp.find(next);
					masu action(it->second);
					if (action.type == 1) {
						next += action.a;
					}
					else if (action.type == 2) {
						nextmoney += action.a;
					}
					else {
						nextmoney -= action.a;
						nextmoney = max(nextmoney, 0);
					}
				}
			}
			if (next < Y) {
				ans += getans(next,nextmoney);
			}
			else {
				ans += nextmoney;
			}
		}
		memo[nowplace][nowmoney] = ans / dices.size();
	}
	return memo[nowplace][nowmoney];
}
int main() {
	while (1) {
		cin >> X >> Y >> Z;
		if (!X)break;
		memo = vector<vector<ld>>(Y, vector<ld>(5001, -1));
		dices.clear();
		for (int i = 0; i < X; ++i) {
			int v; cin >> v;
			dices.emplace_back(v);
		}
		mp.clear();
		for (int i = 0; i < Z; ++i) {
			int n, e, a; cin >> n >> e >> a;
			mp[n] = masu{ n,e,a };
		}
		ld ans = getans(0,0);
		cout << int(ans) << endl;
	}
	return 0; 
}

Measured memory_bytes: 10740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

const int MX = 200005;
vector<P> tim[30];

int main(){
    int n, c;
    cin >> n >> c;
    vector<int> v(MX);
    rep(i, n) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        s *= 2; t *= 2;
        tim[c].emplace_back(s-1, t);
    }
    
    rep(i, 30) {
        if (tim[i].size()==0) continue;
        sort(whole(tim[i]));
        rep(j, tim[i].size()-1) {
            if (tim[i][j].second>tim[i][j+1].first) {
                tim[i][j+1].first = tim[i][j].first;
                tim[i][j] = P(MX-1, MX-1);
            }
        }
        for (auto p: tim[i]) {
            v[p.first]++;
            v[p.second]--;
        }
    }
    
    
    int ans = 0;
    int now = 0;
    rep(i, MX) {
        now += v[i];
        chmax(ans, now);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5160
M = 1000000007

def main():
    n, m = map(int, input().split())
    print(solve(n, m))

def solve(n, m):
    d = abs(n - m)

    if d > 1:
        return 0
    elif d == 1:
        return fact(n) * fact(m) % M
    else:
        return fact(n) * fact(m) * 2 % M

def fact(n):
    s = 1
    for i in range(2, n + 1):
        s = (s * i) % M
    return s

main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    vector<int> y(x);
    sort(y.begin(),y.end());
    int left = y[n/2-1];
    int right = y[n/2];
    for (int i = 0; i < n; i++) {
        int j = lower_bound(y.begin(), y.end(), x[i]) - y.begin();
        if (j < n/2)
            cout << right << endl;
        else
            cout << left << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int a = scanner.nextInt(), b = scanner.nextInt(), k = scanner.nextInt();
        for (int i = Math.max(a, b), c = 0; i > 0; i--) {
            if (a % i == 0 && b % i == 0 && ++c == k) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 23380
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    int a;
    cin>>a;
    bool ok=false;
    for(int i=1;i<=9;i++){
        int b=a/i;
        if(a%i==0&&b<10)ok=true;
    }
    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 import static java.util.stream.Collectors.toList;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Shop> list = new ArrayList<Shop>();
		long money =0;
		long totalAmount =0;
 
		for(int i=0;i<n;i++){
			Shop shop = new Shop();
			shop.setCost(sc.nextInt());
			shop.setAmount(sc.nextInt());
			list.add(shop);
		}

		// ArrayList<Shop> sortedList = list
		// .stream()
		// .sorted((s1, s2) -> s1.getCost()- s2.getCost())
  //       .collect(Collectors.toList());
		list.sort((s1, s2) -> s1.getCost()- s2.getCost());

        // System.out.println("sortedList "+list);
		int countIndex=0;
		while(totalAmount<m){
			long need = m- totalAmount;
			long canGetAmount = list.get(countIndex).getAmount();

        	// System.out.println("target "+target);

			if(canGetAmount<need){
				totalAmount += canGetAmount;
				money += list.get(countIndex).getCost() * canGetAmount;
			}else{
				totalAmount += need;
				money += list.get(countIndex).getCost() * need;
			}

        	// System.out.println("money "+money);
        	// System.out.println("totalAmount "+totalAmount);
			// listA.remove(countIndex);
			// listB.remove(countIndex);
			countIndex++;
		}


        System.out.println(money);
 
	}

	public static int findExpensiveShop(ArrayList<Long> shopList){
		int index =0;
		long min =1000000001;
		for(int i=0;i<shopList.size();i++){
			if(shopList.get(i)<min){
				min =shopList.get(i);
				index =i;
			}
		}
		return index;
	}

	public static class Shop{
		private int cost;
		private int amount;
		public int getCost(){
			return this.cost;
		}
		public int getAmount(){
			return this.amount;
		}

		public void setCost(int cost){
			this.cost = cost;
		}
		public void setAmount(int amount){
			this.amount = amount;
		}
	}
}




Measured memory_bytes: 93540
from sys import stdin
from operator import itemgetter
# stdin = open("sample.txt")

N = int(stdin.readline().rstrip())
hyo = [0,0]
ans = [0,0]

for i in range(N):
    hyo[0],hyo[1] = [int(x) for x in stdin.readline().rstrip().split()]

    if ans[0]<=hyo[0] and ans[1]<=hyo[1]:
        ans[0] = hyo[0]
        ans[1] = hyo[1]
    elif ans[0]>hyo[0] and ans[1]>hyo[1]:
        if ans[0]%hyo[0] == 0:
            which1 = ans[0]//hyo[0]
        else:
            which1 = ans[0]//hyo[0]+1
        if ans[1]%hyo[1] == 0:
            which2 = ans[1]//hyo[1]
        else:
            which2 = ans[1]//hyo[1]+1
        if which1 >= which2:
            which = which1
        else:
            which = which2
        ans[0] = hyo[0] * which
        ans[1] = hyo[1] * which
    elif ans[0]>hyo[0]:
        left = ans[0]//hyo[0]
        if ans[0]%hyo[0] == 0:
            ans[0] = hyo[0]*left
            ans[1] = hyo[1]*left
        else:
            ans[0] = hyo[0]*(left+1)
            ans[1] = hyo[1]*(left+1)
    elif ans[1]>hyo[1]:
        right = ans[1]//hyo[1]
        if ans[1]%hyo[1] == 0:
            ans[0] = hyo[0]*right
            ans[1] = hyo[1]*right
        else:
            ans[0] = hyo[0]*(right+1)
            ans[1] = hyo[1]*(right+1)
    # print(ans)

print(ans[0]+ans[1])

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int n,m,A,B,i,j;
int a[1005][1005];
int main(){
    scanf("%d%d%d%d",&n,&m,&A,&B);
    for(i=1;i<=B;i++)
        for(j=A+1;j<=m;j++)
            a[i][j]=1;
    for(i=B+1;i<=n;i++)
        for(j=1;j<=A;j++)
            a[i][j]=1;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++)
            putchar(a[i][j]+48);
        putchar(10);
    }
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  char C;cin>>C;
  cout<<(char)(C+1)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 100;

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int N1[N+1],N2[N+1][N+1];
  int i,j,k,l,n;
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&N1[i-1],&N1[i]);
  }

  for(i=1;i<=n;i++)N2[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=0;i<=n-l+1;i++){
      j = i+l-1;
      N2[i][j] = (1<<21);
      for(k = i;k <= j-1;k++){
	N2[i][j] = min(N2[i][j],N2[i][k] + N2[k+1][j] + N1[i-1]*N1[k]*N1[j]);
      }
    }
  }

  printf("%d\n",N2[1][n]);
  
  return 0;
}



Measured memory_bytes: 2788
#include<stdio.h>
int main(){
 
  int a,b,s,r;
 
  scanf("%d", &a);
  scanf("%d", &b);
 
  if(a<b){
    s = a;
    a = b;
    b = s;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  printf("%d\n",b); 
  return 0;
}



Measured memory_bytes: 2124
#include<stdio.h>

struct Process{
    int time;
    char name[10];
};
class Queue{
    private:
        int max;
        Process *array;
        int head;
        int tail;
    public: Queue(int n){
        max = n+1;
        array = new Process[n+1];
        head = 0;tail = 0;
    }
    public: bool isEmpty(){return head==tail;}
    public: bool isFull(){return head == (tail + 1) % max;}
    
    public: int enqueu(Process o){
        if(isFull()) throw "Overflow";
        array[tail] = o;
        if(tail + 1 == max){
            tail = 0;
        } else{
            tail++;
        }
        return 1;
    }
    
    public: Process dequeu(){
        if(isEmpty()) throw "Underflow";
        Process o = array[head];
        if(head + 1 == max){
            head = 0;
        } else{
            head++;
        }
        return o;
    }
    
};

int main(){
    int n,t,tn=0;
    scanf("%d %d",&n,&t);
    Queue q(n);
    Process p;
    for(int i = 1;i <= n;i++){
        scanf("%s %d",p.name,&p.time);
        q.enqueu(p);
    }
    while(!(q.isEmpty())){
        p = q.dequeu();
        if(p.time - t> 0){
            p.time -= t;
            q.enqueu(p);
            tn += t;
        } else {
            tn += p.time;
            printf("%s %d\n",p.name,tn);
        }
        
    }
    
    
}



Measured memory_bytes: 3540
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    map<string, int> m;

    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;

        if (m.find(s) != m.end()) {
            int t = m[s];
            m[s] = t + 1;
        } else {
            m[s] = 1;
        }
    }

    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        string s;
        cin >> s;

        if (m.find(s) != m.end()) {
            int t = m[s];
            m[s] = t - 1;
        } else {
            m[s] = -1;
        }
    }

    map<string, int>::iterator itr = m.begin();
    string max_str = itr->first;
    for (; itr != m.end(); ++itr) {
        if (itr->second > m[max_str])
            max_str = itr->first;
    }

    if (m[max_str] > 0)
        cout << m[max_str] << '\n';
    else
        cout << 0 << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
char ch;
int main() {
	scanf("%c", &ch);
	if (ch == 'A') ch = 'T';
	else if (ch == 'T') ch = 'A';
	else if (ch == 'G') ch = 'C';
	else if (ch == 'C') ch = 'G';
	printf("%c\n", ch);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(N: int, M: int, S: "List[int]", T: "List[int]"):
    dp = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i+1][j+1] += dp[i][j] + 1
            dp[i+1][j+1] %= MOD
    return (dp[-1][-1] + 1) % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    T = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    result = solve(N, M, S, T)
    print(result)

if __name__ == '__main__':
    main()

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

using namespace std;

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

    vector<int> d_ {};

    for (int i { 0 }; i < N; ++i) {
        int tmp;
        cin >> tmp;
        d_.push_back(tmp);
    }

    int result { 0 };

    for (int i { 0 }; i < N; ++i) {
        for (int k { i + 1 }; k < N; ++k) {
            if (i == k) { continue; }
            result += d_[i] * d_[k];
        }
    }


    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
queue<ll> q;
int k;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> k;
	for(int i = 1;i <= 9;i++){
		q.push(i);
	}
	ll cnt = 0;
	ll t;
	while(!q.empty()){
		cnt++;
		t = q.front();
		q.pop();
		if(cnt == k){
			cout << t << endl; 
			break;
		}
		if(t % 10 != 0){
			q.push(t * 10 + t % 10 - 1);
		}
		q.push(t * 10 + t % 10);
		if(t % 10 != 9){
			q.push(t * 10 + t % 10 + 1);
		}
	}

	return 0;
}

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

 using namespace std;

 int main() {
   int H, W, i, j;

   cin >> H >> W;

   vector<vector<char>> a(H + 1, vector<char>(W + 1));

   for (i = 1; i <= H; i ++) {
     for (j = 1; j <= W; j++) {
       cin >> a.at(i).at(j);
     }
   }

   for (i = 1; i <= W + 2; i++) cout << "#";
   cout << endl;

   for (i = 1; i <= H; i++) {
     cout << "#";
     for (j = 1; j <= W; j++) {
       cout << a.at(i).at(j);
     }
     cout << "#" << endl;
   }

   for (i = 1; i <= W + 2; i++) cout << "#";
   cout << endl;
 }


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
L = []
flag = 0
for i in range(N-1):
    if A[i] == A[i+1] and flag == 0:
        L.append(A[i])
        flag = 1
    else:
        flag = 0

if len(L) >= 2:
    print(L[0]*L[1])
else:
    print(0)

Measured memory_bytes: 62704
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char    mp[305][305];
char temp[305];
int n;


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

  
  for ( int i = 0; i < n; i++) {
    strcpy(temp, mp[0]);
    for ( int j = 0; j < n - 1; j++) {
      strcpy(mp[j], mp[j + 1]);
    }
    strcpy(mp[n - 1], temp);

    int y, x;
    y = 0; x = n;
    while(y < n && mp[y][x] == mp[x][y] && x == n) {
      x = 0;
      while(x < n && mp[y][x] == mp[x][y]) {
	x++;
      }
      y++;
    }
    if ( y == n && x == n ) {
      ans++;
    }
    
  }

  ans *= n;

  printf("%d\n", ans); 
  

  return (0);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};
const double EPS = 1e-10;
const double PI = acos(-1.0);

int liner_Search(vector<int> s, vector<int> t){
    int res = 0;
    REP(i,(int)t.size()){
        for(int s: s){
            if(s == t[i]){
                res++;
                break;
            }
        }
    }

    return res;
}


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

    int n; cin >> n;
    vector<int> s;
    REP(_, n){int num; cin >> num; s.PB(num);}

    int q; cin >> q;
    //vector<int> t;
    int count = 0;
    REP(_, q){
        int num; cin >> num;
        REP(i,n){
            if(s[i] == num){
                count++;
                break;
            }
        }
    }

    cout << count << endl;

   
}


Measured memory_bytes: 3160
#include <cstdio>

using namespace std;

char s[30'009];
int l[19];
int r[19];
bool was[1'009];

int main() {
  int n;
  scanf("%d%s", &n, s);
  for (int i = 0; i < 10; ++i) {
    l[i] = 0;
    r[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    ++r[(int)(s[i] - '0')];
  }
  for (int i = 0; i < 1'000; ++i) {
    was[i] = false;
  }
  for (int i = 0; i < n; ++i) {
    int t = (int)(s[i] - '0');
    --r[t];
    for (int a = 0; a < 10; ++a) {
      if (l[a] == 0) {
        continue;
      }
      for (int b = 0; b < 10; ++b) {
        if (r[b] == 0) {
          continue;
        }
        was[a * 100 + t * 10 + b] = true;
      }
    }
    ++l[t];
  }
  int ans = 0;
  for (int i = 0; i < 1'000; ++i) {
    if (was[i]) {
      ++ans;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int r = Integer.parseInt(sc.next());
    if (n >= 10) {
      pw.println(r);
    } else {
      pw.println(r + (100 * (10 - n)));
    }
  }
}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
	  public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int n = sc.nextInt();
		  int m = sc.nextInt();
		  int k[]=new int[n];
		  int h[]=new int[m];;
		  int count[]=new int[n];;
		  for(int i=0;i<n;i++){
			  k[i] = sc.nextInt();
		  }			
		  for(int j=0;j<m;j++){
			  h[j]=sc.nextInt();
		  }
		  for(int a=0;a<m;a++){
			  
			  for(int b=0;b<n;b++){
				  if(k[b]<=h[a]){count[b]++;
				  break;
			  }  
			 }
		  }
			  int max = 0;
			  int event =0;
			  for (int i = 0; i<n;i++){
			  if(max<=count[i]){
				  max=count[i];
				  event=i+1;}
			  }
			  System.out.println(event);		
	 }
}
	 

Measured memory_bytes: 32548
#include <stdio.h>

int search(int s[],int key,int head,int tail){
    if(head>tail)return -1;
    
    int mid=(head+tail)/2;
    
    if(s[mid]==key)return mid;
    else if(s[mid]>key)tail=mid-1;
    else if(s[mid]<key)head=mid+1;
    
    return search(s,key,head,tail);
}
int getLB(int s[],int key,int head,int tail){
    if(s[0]>key)return 0;
    if(s[tail]<key)return tail+1;
    
    int mid=(head+tail)/2;
    
    if(s[mid]<key)head=mid+1;
    else if(s[mid]>key)tail=mid-1;
    else if(s[mid]==key){
        if(s[mid-1]<key)return mid;
        else tail=mid-1;
    }
        
    return getLB(s,key,head,tail);
}
int insert(int s[],int key,int cnt){
    int d;
    if(cnt==0)d=0;
    else d=getLB(s,key,0,cnt-1);
    
    int i;
    for(i=cnt;i>d;i--)s[i]=s[i-1];
    s[i]=key;
    return 1;
}
int delete(int s[],int key,int cnt){
    int d;
    d=search(s,key,0,cnt-1);
    if(d<0)return -1;
    
    int i;
    for(i=d;i<cnt-1;i++)s[i]=s[i+1];
    return 1;
}
int main(void){
    int q;
    scanf("%d\n",&q);
    
    int s[q];
    int cnt=0;
    
    int com,x;
    while(q--){
        scanf("%d %d\n",&com,&x);
        switch(com){
            case 0:
                //insert
                if(search(s,x,0,cnt-1)==-1){
                    if(insert(s,x,cnt)==1)cnt++;
                }
                printf("%d\n",cnt);
                break;
            case 1:
                //find
                if(search(s,x,0,cnt-1)==-1)printf("0\n");
                else printf("1\n");
                break;
            case 2:
                //delete
                if(delete(s,x,cnt)==1)cnt--;
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2464
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;

    ll ans = LL_MAX;
    for (ll i=1; i*i<=n; i++)
    {
        if (n%i != 0) continue;
        ll j = n/i;
        ans = min(ans, i+j-2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

func :: String -> [[String]]
func [] = [[[]]]
func xs = concat $  map (\(a,b) -> if null b then [[a]] else map (a:) (func b)) [splitAt i xs|i<-[1..length xs]]

main :: IO()
main = do
  s <- getLine
  print $ sum $ map (sum . map (read::String->Integer)) $ func s


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  int a[n][m];
  REP(i,n){
    cin >> c[i];
    REP(j,m) cin >> a[i][j];
  }


  int INF = 2000000000;
  int mxcost = INF;

  REP(i, 1 << n){
    vector<int> know(m);
    int cost = 0;

    REP(j,n) if(i >> j&1){
      cost += c[j];
      REP(mi,m){
        know[mi] += a[j][mi];
      }
    }

    //cout <<"cost" <<cost << endl;

    //--
    // for(auto x: know) cout << x << " ";
    // cout <<  endl;

    bool ok = true;
    REP(mi,m){
      if(know[mi] < x) ok = false;
    }
    if(ok) mxcost = min(mxcost,cost);
  }

  if(mxcost == INF){
    cout << -1 << endl;
    return 0;
  }

  cout << mxcost << endl;

  return 0;
}


Measured memory_bytes: 3600
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[N+1];
        a[0]=0;
        for(int n=0;n<N;n++)a[n]=sc.nextInt();
        
        long ans = 0;
        for(int n=1;n<=N;n++){
        	int eat = (a[n-1]+a[n]<=x) ? 0 : a[n-1]+a[n]-x;
        	ans += eat;
        	a[n] -= eat;
        }
        System.out.println(ans);
    }
}


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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    string s,t;

    cin >> s >> t;
    int ans = 0;
    REP(i,3)if(s[i] == t[i])ans++;

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c);
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define mod          1000000007

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

#define scan(x)      do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A ;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S, T, U;
ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    //scan(n);
    cin>>n>>S;
    if(n<3200)
    {
        cout<<"red"<<endl;
    }
    else
    {
        cout<<S<<endl;
    }
    return 0;
}


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

typedef struct {
  char s[100];
  int p;
  int a;
} res;

void swap_b(res *x, res *y)
{
  res temp = *x;
  *x = *y;
  *y = temp;
}
  
int main()
{
  int n, i, j;
  res b[100];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> b[i].s >> b[i].p;
    b[i].a = i+1;
  }
  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      if (strcmp(b[j-1].s, b[j].s) > 0) {
	swap_b(&b[j-1], &b[j]);
      }
      else if (strcmp(b[j-1].s, b[j].s) == 0) {
	if (b[j-1].p < b[j].p) {
	  swap_b(&b[j-1], &b[j]);
	}
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << b[i].a << endl;
  }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>i;
	if(i<1200) cout<<"ABC"<<endl;
	else if(i<2800) cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;

    deque<char> d;
    for (ll i = 0; i < s.size(); i++)
    {
        d.push_back(s[i]);
    }

    ll q;
    cin >> q;
    ll r = 1;
    for (ll i = 0; i < q; i++)
    {
        ll t;
        cin >> t;
        if (t == 1)
        {
            r++;
        }
        else
        {
            ll f;
            char c;
            cin >> f >> c;
            if (f == 1)
            {
                if (r % 2 == 1)
                {
                    d.push_front(c);
                    // s = c + s;
                }
                else
                {
                    d.push_back(c);
                    // s = s + c;
                }
            }
            else
            {
                if (r % 2 == 1)
                {
                    d.push_back(c);
                    // s = s + c;
                }
                else
                {
                    d.push_front(c);
                    // s = c + s;
                }
            }
        }
    }

    if (r % 2)
    {
        for(auto m : d){
            cout << m;
        }
        cout << endl;
        // cout << s << endl;
    }
    else
    {
        reverse(ALL(d));
        for (auto m : d)
        {
            cout << m;
        }
        cout << endl;
        // reverse(s.begin(), s.end());
        // cout << s << endl;
    }
    // deque<char> d;
    // for (ll i = 0; i < s.size(); i++)
    // {
    //     d.push_back(s[i]);
    // }

    // ll q;
    // cin >> q;
    // for (ll i = 0; i < q; i++)
    // {
    //     ll t;
    //     cin >> t;
    //     if (t == 1)
    //     {

    //     }
    //     else
    //     {
    //         ll f;
    //         char c;
    //         cin >> f >> c;
    //     }
    // }


}

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

void Main()
{
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> H;
    for(int64_t i = 0; i < N; ++i)
    {
        int64_t h;
        cin >> h;
        H.push_back(h);
    }
    vector<int64_t> A, B;
    for(int64_t i = 0; i < M; ++i)
    {
        int64_t a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    vector<vector<int64_t>> V(N, vector<int64_t>());
    for(int64_t i = 0; i < M; ++i)
    {
        V[A[i] - 1].push_back(B[i] - 1);
        V[B[i] - 1].push_back(A[i] - 1);
    }

    int64_t result = 0;
    for(int64_t i = 0; i < N; ++i)
    {
        auto& v = V[i];
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());

        bool b = true;
        for(auto j : v)
        {
            if(H[i] <= H[j])
            {
                b = false;
            }
        }
        if(b)
        {
            ++result;
        }
    }

    cout << result << endl;
}

int main()
{
    Main();
}


Measured memory_bytes: 11420
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()


Measured memory_bytes: 33540
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  vector<ll> q(n);
  REP(i, n) q[a[i]-1] = i;
  ll ans = 0;
  ll tmp = 1;
  REP_FROM(i, 1, n) {
    if(q[i] - q[i-1] > 0) {
      tmp++;
    }
    else {
      ans = max(tmp, ans);
      tmp = 1;
    }
  }
  ans = max(tmp, ans);
  cout << n - ans << endl;
  return 0;
}


Measured memory_bytes: 3456
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
cs = []
ss = []
fs = []
for i in range(n-1):
    c, s, f = na()
    cs.append(c)
    ss.append(s)
    fs.append(f)

for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t <= ss[j]:
            t = ss[j]
        else:
            t = (t + fs[j] - 1) // fs[j] * fs[j]
        t += cs[j]
    print(t)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; long long int L; 
	long long int INF = 1e16; 
	cin >> N >> M >> L; 
	long long int D[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i != j) D[i][j] = INF; 
		}
	}
	for(int i = 0; i < M; i++){
		int a, b, c; 
		cin >> a >> b >> c; 
		a--; b--; 
		if(c > L) continue; 
		D[a][b] = c; D[b][a] = c; 
	}
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				D[i][j] = min(D[i][k] + D[k][j], D[i][j]); 
			}
		}
	}
	long long int P[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i == j) continue; 
			if(D[i][j] <= L) P[i][j] = 1; 
			else P[i][j] = INF; 
		}
	}	
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				P[i][j] = min(P[i][k] + P[k][j], P[i][j]); 
			}
		}
	}
	int Q; cin >> Q; 
	for(int q = 0; q < Q; q++){
		int s, t; cin >> s >> t; 
		s--; t--; 
		if(P[s][t] == INF) cout << -1 << endl; 
		else cout << P[s][t] - 1 << endl; 
	}
}


Measured memory_bytes: 2048
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
LL n,a[30],dp[1<<21],sum,ans;
int main(){
   while(cin>>n&&n!=0){ 
       ans=INF<LL>();
       sum=0;
    REP(i,n){
       cin>>a[i];
       sum+=a[i];
    }
    REP(i,1<<n){
        dp[i]=0;
        LL cnt=0;
        REP(j,n){
            if(i&(1<<j))
            dp[i]+=a[j],cnt++;
        }
        if(cnt>0&&cnt<n)
        ans=min(ans,abs(sum-dp[i]*2));
    }
    cout<<ans<<endl;
   }
    return 0;
}


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

int main(){
  int N,m;
  cin >> N;
  int flag = 0;
  for(int i=0; i<N; i++){
    cin >> m;
    if(m%2==0){
      if(m%3!=0&&m%5!=0){
      	flag=1;
      	break;
      }
    }
  }
  
  if(flag==1){
    cout << "DENIED" << endl;
  }
  else{
    cout << "APPROVED" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }







void solve(){
    ll n,d;
    cin>>n>>d;
    ll x[200010],y[200010];
    rep(i,n) cin>>x[i]>>y[i];
    ll cnt=0;
    rep(i,n){
        if(x[i]*x[i]+y[i]*y[i]<=d*d){
            cnt++;
        }
    }
    cout<<cnt<<endl;

}

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


    solve(); 


    return 0;
}


Measured memory_bytes: 6792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int flag=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2<<endl;
            flag=1;
            break;
        }
        else if(i<s.size()-2&&s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }
    }
    if(!flag)
    cout<<-1<<" "<<-1<<endl;
    return 0;    
} 

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int f[100002];
int high[100002];
int main()
{
	int n,i,j,k;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&high[i]);
	}
	f[1]=0;
	for(i=2;i<=n;i++)
	{
		f[i]=INT_MAX;
		for(j=1;i-j>0&&j<=k;j++)
		{
			f[i]=min(f[i-j]+abs(high[i]-high[i-j]),f[i]);
		}
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

ll r,d,x[10005];

int main(void){
	scanf("%lld %lld %lld",&r,&d,&x[0]);
	for(int i=1;i<=10;i++)
	x[i]=x[i-1]*r-d;
	for(int i=1;i<=10;i++)
	printf("%lld\n",x[i]);
}

Measured memory_bytes: 128