akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        k: i32,
        x: i32,
    }
    println!("{}", if 500 * k >= x {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string div[4] = {"dream", "dreamer", "erase", "eraser"};
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; ++i) reverse(div[i].begin(), div[i].end());

    bool can = true;
    for (int i = 0; i < s.size();) {
        bool can2 = false;
        for (int j = 0; j < 4; ++j) {
            string d = div[j];
            if (s.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }
    if (can) cout << "YES" << '\n';
    else cout << "NO" << '\n';
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    double[] S  = new double[N];
	    
	    for (int i=0; i<N; i++) {
	        S[i]= Double.parseDouble(scanner.next());
	    }
	    
	    Arrays.parallelSort(S);

	    double m=(S[0] + S[1]) /2;
        for (int i=2; i<N; i++) {
	        m = (m+S[i]) / 2;
	    }

        System.out.print(m);
	}

}

Measured memory_bytes: 35900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define openfiles ifstream in("input.txt");ofstream out("output.txt");
const int inf=2e9;
const ll infll=1e18;
typedef pair<int,int> pii;
openfiles;
///---------------------------------------------------------------------------
double a,b;

void init()
{
    faster;
    cin>>a>>b;
    cout<<fixed<<setprecision(9)<<a/b;

}
void solve()
{

}

signed main()
{
    init();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

const ll mod = 1e9+7;

ll fact(ll x) {
  ll ans = 1;
  REP(i,1,x+1) {
    ans = (ans * i) % mod;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  ll ans;
  if(abs(N - M) > 1) {
    ans = 0;
  } else if(N == M) {
    ans = (fact(N) * fact(M) * 2) % mod;
  } else {
    ans = (fact(N) * fact(M)) % mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  
  int a, b, k;
  
  cin >> a >> b >> k;
  
  for(int i = a;i <= b;i++){
    if(i < a + k) cout << i << endl;
    else if(b - k < i) cout << i << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Arrays;
import java.util.Comparator;

class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        int n = Integer.parseInt(br.readLine());

        for(int i = 0; i < n; i++){
            String[] input = br.readLine().split(" ");
            if(map.containsKey(input[0])){
                map.put(input[0], Integer.parseInt(input[1]) + map.get(input[0]));
            }else{
                map.put(input[0], Integer.parseInt(input[1]));
            }
        }

        Object[] products = map.keySet().toArray();

        Arrays.sort(products, new Comparator<Object>(){
            public int compare(Object o1, Object o2){
                String s1 = o1.toString();
                String s2 = o2.toString();

                if(s1.length() == s2.length()){
                    return s1.compareTo(s2);
                }else{
                    return s1.length() - s2.length();
                }
            }
        });

        for(Object obj : products){
            String s = obj.toString();
            System.out.println(s + " " + map.get(s));
        }

    }
}


Measured memory_bytes: 33008
from itertools import permutations
from math import factorial


def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for p in permutations(range(n), n):
        dist = 0
        for i in range(len(p) - 1):
            dist += (abs(xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 +
                     abs(xy[p[i]][1] - xy[p[i + 1]][1]) ** 2) ** 0.5
        ans += dist

    ans /= factorial(n)

    print(f"{ans:.12f}")


if __name__ == "__main__":
    main()


Measured memory_bytes: 74812
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[] a=cin.ArrayInt(2,0);
      Console.WriteLine((a[0]-1)*(a[1]-1));
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 5005;
const int MAX_NN = MAX_N * MAX_N;

ll dp[MAX_NN];

ll solve(ll N, int gA, int sA, int bA, int gB, int sB, int bB) {
  CLR(dp, 0);
  REP(i, N+1) dp[i] = i;
  if (gA < gB) for (int i = 0; i + gA <= N; i++)chmax(dp[i+gA], dp[i] + gB);
  if (sA < sB) for (int i = 0; i + sA <= N; i++)chmax(dp[i+sA], dp[i] + sB);
  if (bA < bB) for (int i = 0; i + bA <= N; i++)chmax(dp[i+bA], dp[i] + bB);
  return *max_element(dp, dp + N + 1);
}

int main2() {
  ll N = nextInt();
  int gA = nextInt();
  int sA = nextInt();
  int bA = nextInt();
  int gB = nextInt();
  int sB = nextInt();
  int bB = nextInt();

  ll t = solve(N, gA, sA, bA, gB, sB, bB);
  ll ans = solve(t, gB, sB, bB, gA, sA, bA);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 196096
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
alpha = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ]
h = {}
for i in range(n):
    ch = {}
    for c in alpha:
        ch[c] = 0
    s = input().strip()
    for j in range(10):
        ch[s[j]] += 1
    x = (ch['a'], ch['b'], ch['c'], ch['d'], ch['e'], ch['f'], ch['g'], ch['h'], ch['i'], ch['j'], ch['k'], ch['l'], ch['m'], ch['n'], ch['o'], ch['p'], ch['q'], ch['r'], ch['s'], ch['t'], ch['u'], ch['v'], ch['w'], ch['x'], ch['y'], ch['z'])
    if x in h:
        h[x] += 1
    else:
        h[x] = 1

sum = 0
for x in h:
    y = h[x]
    if y>1:
        sum += (y*(y-1))//2
print(sum)


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

# Input
s = [input() for i in range(2)]
N = int(s[0])
As = sorted(list(s[1].split()))

# Proccess
pp = "APPROVED"

for i in range(0,N):
	if (int(As[i]) % 2) == 0 :
		if (As[i] == 2)or(As[i] == 4):
			pp = "DENIED"
			break			
		elif (int(As[i]) % 3)*(int(As[i]) % 5) == 0 :
			continue
		else:
			pp = "DENIED"
			break
		
# Output						
print(pp)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = a+a+b+b;
    System.out.println(area + " " + length);
    sc.close();
  }
}



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

#define int long long 

bool cmp(pair<int , int > a  , pair<int , int >  b )
{
	if(a.first < b.first) return true ; 
	if(a.first == b.first) 
	{
		if(a.second < b.second ) return true ; 
	}
	return false; 
}




int32_t main() 
{
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w" , stdout);
	#endif
	

	int t=1;
	//cin >> t;
	while (t-- ) 
	{
		int x ;
		cin>>x ;
		if(x) cout<<"0"<<endl ;
		else cout<<"1"<<endl; 

	}

}
	

Measured memory_bytes: 3484
#include<iostream>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;


int main(){
	double sta[80];
	int sp;
	string s;
	while(getline(cin,s)){
		stringstream ss;
		ss<<s;
		sp=0;
		while(ss>>s){
			if(isdigit(s[0]))sta[sp++]=atoi(s.c_str());
			else if(s[0]=='-'&&s.size()!=1){
				sta[sp++]=-atoi(s.c_str()+1);
			}
			else {
				double a,b;
				b=sta[--sp];
				a=sta[--sp];
				if(s[0]=='+')sta[sp]=a+b;
				else if(s[0]=='-')sta[sp]=a-b;
				else if(s[0]=='*')sta[sp]=a*b;
				else if(s[0]=='/')sta[sp]=a/b;
				sp++;
			}
		}
		printf("%.5f\n",sta[0]);
	}
	return 0;
}

Measured memory_bytes: 1264
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] %2 != 0) {
				continue;
			} else {
				while (true) {
					if (a[i]%2==0) {
						count++;
						a[i] /= 2;
					} else {
						break;
					}
				}
			}
		}
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 37508
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
void solve()
{
	ll a,b,n;
	cin>>a>>b>>n;
	if(n>b)
	{
		cout<<a*(b-1)/b;
    }
    else
    {
    	if(n%b!=0)
    	cout<<a*n/b;
    	else
    	cout<<a*(n-1)/b;
	}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
solve();
}

return 0;
}




Measured memory_bytes: 3612
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    int n; cin>>n; cin.ignore();

    vector<int> freq(n+1,0); //freq[i] counts how many balls have value i;
    vector<int> a(n);
    for (int t = 0; t<n; ++t) {
        int v; cin>>v;
        a[t]=v;
        ++freq[v];
    }

    long long totwaysnorestrict = 0;
    for (int val = 1; val<=n; ++val) {
        if (freq[val]>=2) {
            long long f = (ll) freq[val];
            totwaysnorestrict += (f*(f-1))/2;
        }
    }

    for (int i=0; i<n; ++i) {
        int v = a[i];

        if (freq[v]<2) {
            cout<<totwaysnorestrict<<el;
            continue;
        }

        long long thisans = totwaysnorestrict;
        long long f = (ll) freq[v];
        thisans -= (f*(f-1))/2;

        if (f-1>=2) {
            thisans += ((f-1)*(f-2) )/2;
        }
        cout<<thisans<<el;

    }
}

Measured memory_bytes: 4224
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int s,sum=0,vis,t,k;
for(int i=1;i<=a;i++){
	vis=0;
	s=i;
	while(s){
	   vis+=s%10;
	   s/=10;
	}
	if(vis>=b&&vis<=c)sum+=i;
}
cout<<sum;
    return 0;
}


Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  a,b,k=pM(split(readline()))
  ans=Int[]
  for i=0:k-1
    if a+i<=b
      push!(ans,a+i)
    end
    if b-i>=a
      push!(ans,b-i)
    end
  end
  ans=unique(ans)
  sort!(ans)
  foreach(println,ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 168572
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define L size()

#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ----------------------
    string s; 
    cin >> s;
    int m = 10000 ; 
    for (int i = 0; i < s.L - 2; i++)
    {
        string a = s.substr(i,3);
        int c = (a[0]-'0')*100 + (a[1]-'0')*10 + (a[2]-'0');
        // cout << c << endl ;
        m = min(m,abs(c - 753));
    }
    cout << m << endl ;
    return 0 ;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[][] c = new int[h][w];
        int idx = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int j2 = i%2==0 ? j : w-1-j;
                c[i][j2] = idx+1;
                if(--a[idx] == 0) idx++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                sb.append(c[i][j] + " ");
            }
            sb.append("\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 32280
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=105;
struct edge{
	int to,next,f;
}e[N*N*2];
int head[N*2],tot,S,T;
int n,m,a[N][N],q[N*2],dis[N*2];
vector<int> vec[N][N];
void add(int x,int y,int f){
	e[++tot]=(edge){y,head[x],f};
	head[x]=tot;
	e[++tot]=(edge){x,head[y],0};
	head[y]=tot;
}
bool bfs(){
	For(i,1,T) dis[i]=-1;
	int h=0,t=1;
	q[1]=S; dis[S]=0;
	while (h!=t){
		int x=q[++h];
		for (int i=head[x];i;i=e[i].next)
			if (dis[e[i].to]==-1&&e[i].f){
				dis[e[i].to]=dis[x]+1;
				q[++t]=e[i].to;
				if (e[i].to==T) return 1;
			}
	}
	return 0;
}
int dfs(int x,int flow){
	if (x==T) return flow;
	int k,rest=flow;
	for (int i=head[x];i&&rest;i=e[i].next)
		if (dis[e[i].to]==dis[x]+1&&e[i].f){
			k=dfs(e[i].to,min(rest,e[i].f));
			e[i].f-=k; e[i^1].f+=k; rest-=k;
		}
	if (rest) dis[x]=-1;
	return flow-rest;
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n) For(j,1,m){
		int x;
		scanf("%d",&x);
		int be=(x-1)/m+1;
		vec[i][be].PB(x);
	}
	For(i,1,m){
		memset(head,0,sizeof(head));
		tot=1; S=2*n+1; T=2*n+2;
		For(j,1,n){
			add(S,j,1);
			add(j+n,T,1);
			For(k,1,n)
				if (vec[j][k].size())
					add(j,k+n,1);
		}
		for (;bfs();dfs(S,1<<30));
		For(j,1,n)
			for (int k=head[j];k;k=e[k].next)
				if (e[k].f==0&&e[k].to!=S){
					int op=e[k].to-n;
					a[j][i]=vec[j][op].back();
					vec[j][op].pop_back();
				}
	}
	For(i,1,n) For(j,1,m)
		printf("%d%c",a[i][j],j==m?'\n':' ');
	For(i,1,n) For(j,1,m) For(k,i+1,n)
		if (a[i][j]>a[k][j]) swap(a[i][j],a[k][j]);
	For(i,1,n) For(j,1,m)
		printf("%d%c",a[i][j],j==m?'\n':' ');
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
typedef long long ll;
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l)for(int i=r;i>=l;i--)
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1e9+7
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf  INT_MAX
#define lnf LLONG_MAX
#define mii map<int,int>
#define mll map<ll,ll>
#define mil map<int,ll>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define boots ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
using namespace std;
const int MX = 3e5 + 7;
ll modulo(ll num, ll MOD = mod) { return ((num%MOD) + MOD) % MOD; }
ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e % 2) ans = (ans*b) % MOD; b = (b*b) % MOD; e /= 2; } return ans; }
ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a%b)); }
ll dp[MX];
int main()
{
    boots;
    int n,k;
    cin>>n;
    int a;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        dp[a]=i;
    }
    for(int i=1;i<n;i++)
        cout<<dp[i]<<" ";
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1664
N,A,B = map(int,input().split())
X = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    if (X[i+1] - X[i]) * A <= B:
        ans += (X[i+1] - X[i]) * A
    else:
        ans += B

print(ans)

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

using namespace std;

const int INFTY=1<<29;

int main()
{
	for(int n,k;cin>>n>>k,n|k;){
		int dist[100][100];
		for(int i=0;i<n;i++)
			fill(dist[i],dist[i]+n,INFTY);
		while(k--){
			int q; cin>>q;
			if(q==0){
				int s,d; cin>>s>>d; s--; d--;
				int res[100],vis[100]={};
				fill(res,res+n,INFTY);
				res[s]=0;
				for(;;){
					int cur=-1;
					for(int i=0;i<n;i++)
						if(!vis[i] && (cur==-1 || res[cur]>res[i]))
							cur=i;
					if(cur==-1 || vis[cur]==INFTY)
						break;
					vis[cur]=1;
					for(int i=0;i<n;i++)
						if(!vis[i])
							res[i]=min(res[i],res[cur]+dist[cur][i]);
				}
				
				if(res[d]==INFTY)
					cout<<-1<<endl;
				else
					cout<<res[d]<<endl;
			}
			if(q==1){
				int s,d,c; cin>>s>>d>>c; s--; d--;
				dist[s][d]=min(dist[s][d],c);
				dist[d][s]=min(dist[d][s],c);
			}
		}
	}
	
	return 0;
}

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

using namespace std;


int main(){
    map<char, string> s;
    cin >> s['A'] >> s['B'] >> s['C'];
    char n = 'A', x;

    while(1){
        if (s[n].length() == 0){
            break;
        }else if (s[n][0] == 'a'){
            x = 'A';
        }else if (s[n][0] == 'b'){
            x = 'B';
        }else if (s[n][0] == 'c'){
            x = 'C';
        }
        s[n].erase(0, 1);
        n = x;
    }
    cout << n << endl;
    return 0;

}

Measured memory_bytes: 3604
#                         author:  kagemeka 
#                         created: 2019-11-08 15:54:47(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 
# import numpy as np


def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    # editorial より
    f = sum(a) - n
    print(f)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[201010]={0};
int sum1[201010]={0};
int sum2[201010]={0};
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    int sum=a[0];
    sum1[0]=a[0];
    for(int i=1;i<n;i++)
    {
        sum=__gcd(sum,a[i]);
        sum1[i]=sum;
    }
    sum2[n-1]=a[n-1];
    sum=a[n-1];
    for(int i=n-2;i>=0;--i)
    {
        sum=__gcd(sum,a[i]);
        sum2[i]=sum;
    }
    int ans=0;
    for(int i=1;i<n-1;i++)
    {
        ans=max(ans,__gcd(sum1[i-1],sum2[i+1]));
    }
    ans=max({ans,sum1[n-2],sum2[1]});
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    if(n % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - (n % 1000) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 200050
#define LL long long
using namespace std;
struct node
{
	LL fi,se;
}a[maxn];
multiset<LL>m1,m2;
int cmp(node a,node b){
	if(a.fi==b.fi) return a.se<b.se;
	return a.fi<b.fi;
}
int main(){
//	freopen("input.txt","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i].fi,&a[i].se);
		if(a[i].fi>a[i].se) swap(a[i].fi,a[i].se);
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++) m1.insert(a[i].fi),m2.insert(a[i].se);
	LL ans=(*m1.rbegin()-*m1.begin())*(*m2.rbegin()-*m2.begin());
	for(int i=1;i<=n;i++){
		m1.erase(m1.find(a[i].fi)),m2.erase(m2.find(a[i].se));
		m1.insert(a[i].se),m2.insert(a[i].fi);
		ans=min(ans,(*m1.rbegin()-*m1.begin())*(*m2.rbegin()-*m2.begin()));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 24192
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c;
		if (a > b&&a > c) { d= a, a = c, c = d; }
		else if (b > c&&b > a) { d =b , b = c, c = d; }
    else if(c>a&&c>b){}
    if (a > b) { d =a , a = b, b= d; }
	cout << a << " " << b << " " << c<<endl;

	return 0;
}

Measured memory_bytes: 1168
// AOJ 2447 A Two Floors Dungeon
// 2018.2.2 bal4u

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define QMAX 800000
typedef struct { short s; char f, r, c; } Q;
Q q[QMAX+10]; int top, end;

int S;
char map[53][53];
char sw[11][53][53];
int mov[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int memo[1024][2][53][53];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check(int s, int f, int r, int c)
{
	int i, g;

	if (map[r][c] == '|') return 1;
	g = map[r][c] == '^' || isupper(map[r][c]);
	for (i = 0; i < S; i++) if ((s >> i) & 1) g ^= sw[i][r][c];
	return g == f;
}

void enq(int ns, int nf, int nr, int nc, int k)
{
	if (memo[ns][nf][nr][nc]) return;
	memo[ns][nf][nr][nc] = k;
	q[end].s = ns, q[end].f = nf, q[end].r = nr, q[end++].c = nc;
}

int calc(int sr, int sc)
{
	int i, k, s, f, r, c, nr, nc;

	q[0].r = sr, q[0].c = sc, top = 0, end = 1;
	memo[0][0][sr][sc] = 1;
	while (top != end) {
		if (end >= QMAX) break;
		s = q[top].s, f = q[top].f, r = q[top].r, c = q[top++].c;
		k = memo[s][f][r][c] + 1;
		if (map[r][c] == '&') return k-2;
		if (map[r][c] == '|') enq(s, f ^ 1, r, c, k);
		if (isalpha(map[r][c])) {
			i = (map[r][c] & 0x1f) - 1;
			enq(s ^ (1 << i), f ^ sw[i][r][c], r, c, k);
		}
		for (i = 0; i < 4; i++) {
			nr = r + mov[i][0], nc = c + mov[i][1];
			if (map[nr][nc] == '#') continue;
			if (check(s, f, nr, nc)) enq(s, f, nr, nc, k);
		}
	}
	return -1;
}

int main()
{
	int W, H, i, r, c, sr, sc; 
	char buf[53];

	W = in(), H = in();
	sr = -1;
	for (r = 0; r < H; r++) {
		fgets(map[r], 53, stdin);
		if (sr >= 0) continue;
		for (c = 0; c < W; c++) {
			if (map[r][c] == '%') sr = r, sc = c;
		}
	}

	S = in();
	for (i = 0; i < S; i++) {
		for (r = 0; r < H; r++) {
			fgets(buf, 53, stdin);
			for (c = 0; c < W; c++) {
				if (buf[c] == '*') sw[i][r][c] = 1;
			}
		}
	}
	printf("%d\n", calc(sr, sc));
	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll k, x; cin >> k >> x;
  if(500 * k >= x) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LLINF = 4e18;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

template<class Monoid> struct SegmentTree {
private:
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int n;
    vector<Monoid> node;
public:
    //m=size, f=[](M a,M b){return ;}
    SegmentTree(int m, const Func f, const Monoid &unity) : F(f), UNITY(unity) {
        n = 1; while (n < m) n <<= 1;
        node.resize(n * 2 - 1, UNITY);
    }

    SegmentTree(const vector<Monoid>& v, const Func f, const Monoid &unity) : F(f), UNITY(unity) {
        int sz = v.size();
        n = 1; while (n < sz) n <<= 1;
        node.resize(n * 2 - 1, UNITY);
        REP(i, sz) node[i + n - 1] = v[i];
        REPR(i, n - 2) node[i] = F(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int x, int val) {
        if (x >= n || x < 0) return;
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) >> 1;
            node[x] = F(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    // [a,b)
    Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return UNITY;
        if (a <= l && r <= b) return node[k];
        int vl = get(a, b, 2 * k + 1, l, (r - l) / 2 + l);
        int vr = get(a, b, 2 * k + 2, (r - l) / 2 + l, r);
        return F(vl, vr);
    }
};

int main() {
    int n; input(n);
    vector<int> a(n); input(a);
    SegmentTree<int> seg(a, [](int a, int b) {return max(a, b); }, 0);
    REP(i, n) {
        cout << max(seg.get(0, i), seg.get(i + 1, n)) << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 4480
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll T[1010], A[1010];
    rep(i,0,N) cin >> T[i] >> A[i];
    ll v1 = T[0], v2 = A[0];
    rep(i,1,N){
        if(T[i] >= v1 && A[i] >= v2){
            v1 = T[i];
            v2 = A[i];
            continue;
        }
        ll x1 = (v1+T[i]-1) / T[i];
        ll x2 = (v2+A[i]-1) / A[i];
        ll x = max(x1,x2);
        v1 = x * T[i];
        v2 = x * A[i];
    }
    print(v1 + v2);
    

}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

long long gcd(long long m, long long n) {
	long long temp;
	if (n > m) swap(m , n);
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
vector<ll> divisor(ll n) {
	vector<ll> ret;
	for(ll i=1;i*i<=n;i++) {
		if (n%i==0) {
			ret.push_back(i);
			if (i*i!=n) ret.push_back(n/i);
		}
	}
	//sort(ret.begin(),ret.end());
	return ret;
}
int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	
	cin >> n;
	vector<ll>	aa(n);
	for(i=0;i<n;i++) cin >> aa[i];
	ans = gcd(aa[0],aa[1]);
	for(i=2;i<n;i++) ans = gcd(ans , aa[i]);
	if (ans > 1) {
		cout << "not coprime" << endl;
		return 0;
	}
	vector<ll> an(1000001);
	bool f = false;
	for(i=0;i<n;i++) {
		for(j=1;j*j<=aa[i];j++) {
			if (aa[i]%j==0) {
				an[j]++;
				if (j!=1 && an[j]>1) {
					cout << "setwise coprime" << endl;
					return 0;
				}
				if (j*j!=aa[i]) {
					an[aa[i]/j]++;
					if ( (aa[i]/j!=1) && (an[aa[i]/j]>1) ) {
						cout << "setwise coprime" << endl;
						return 0;
					}
				}
			}
		}
	}

	cout << "pairwise coprime" << endl;

	return 0;
}


Measured memory_bytes: 18812
import sys

S=input()
if len(S)<2: print(0),sys.exit()
elif len(S)==3:
    print(1 if S=="ABC" else 0)
    sys.exit()



s=[S[i] for i in range(len(S))]
tmp=0
abc,bca=["A","B","C"],["B","C","A"]
ans=0
a,bc=0,0
i=0
while i<len(s)-1:
    if s[i]=="A": a+=1
    elif s[i]=="B" and s[i+1]=="C":
        bc+=1
        i+=1
        ans+=a
    
    else:
        a,bc=0,0
    i+=1
print(ans)

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

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

  int deadLine = x + a;
  if(b <= a) {
    cout << "delicious" << endl;
  } else if (b <= deadLine) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int N;
    cin >> N;

    set<array<ll, 3>> pieces;

    vll ds(N);
    for (int i = 0; i < N; i++) {
        cin >> ds[i];
        pieces.insert({ ds[i], 1, i });
    }

    vector<pair<int, int>> edges;
    while (pieces.size() > 1) {
        auto p = *pieces.rbegin();
        pieces.erase(p);

        ll match = p[0] + 2 * p[1] - N;
        auto qi = pieces.lower_bound({ match, -1, -1 });
        if (qi == pieces.end() || (*qi)[0] != match) {
            cout << -1 << endl;
            return 0;
        }
        auto q = *qi;

        edges.emplace_back(p[2], q[2]);
        array<ll, 3> comb = { q[0], p[1] + q[1], q[2] };

        pieces.erase(q);
        pieces.insert(comb);
    }

    vvi adj(N);
    for (auto p : edges) {
        adj[p.first].push_back(p.second);
        adj[p.second].push_back(p.first);
    }

    vi dist(N, -1);
    dist[0] = 0;
    for (queue<int> bfs({0}); !bfs.empty(); bfs.pop()) {
        for (int nbr : adj[bfs.front()]) if (dist[nbr] == -1) {
            dist[nbr] = dist[bfs.front()] + 1;
            bfs.push(nbr);
        }
    }

    ll tot0 = 0;
    for (int v : dist)
        tot0 += v;

    if (tot0 != ds[0]) {
        cout << -1 << "\n";
    } else for (auto p : edges) {
        cout << p.first + 1 << " " << p.second + 1 << "\n";
    }

    return 0;
}



Measured memory_bytes: 9336
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int not_mon_sat_prime[3000001];//initialized to zero

int is_mon_sat(int num)
{
    if(num % 7 == 1 || num % 7 == 6){
        return 1;
    }else{
        return 0;
    }
}


int next_mon_sat(int num)
{
    num++;
    for(; !is_mon_sat(num); num++) ;

    return num;
}

void mon_sat_prime(int num)
{
    int i;
    int limit = sqrt(num);

    not_mon_sat_prime[1] = 1;

    for(i = 2; i <= num; i++){//mon_sat number is 0 others are 1
        if(!is_mon_sat(i)){
            not_mon_sat_prime[i] = 1;
        }
    }

    for(i = 6; i <= limit; i = next_mon_sat(i)){
        int j;
        for(j = 2; j <= num / i; j++){
            not_mon_sat_prime[i * j] = 1;//not a mon_sat_prime number
        }
    }

}

int main(void)
{
    mon_sat_prime(3000000);

    while(1){
        int num;
        int i;

        scanf("%d", &num);

        if(num == 1)
            break;

        printf("%d:", num);

        for(i = 1; i <= num; i++){
            if(!not_mon_sat_prime[i] && num % i == 0){
                printf(" %d", i);
            }
        }

        printf("\n");
    }

    return 0;
}

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

bool seisu(int x){
    double y=(double)x;
    int z= (int)sqrt(y);
    if(z*z==x){
        return true;
    }

    
    return false;
}
int ans=0;
  
int main(){
    int n,d;
    cin>>n>>d;
    int x[20][10];
    rep(i,n){
        rep(j,d)cin>>x[i][j];
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            int y=0;
            rep(k,d){
                y+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            if(seisu(y)){
                ans++;
            }
        }
    }

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

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

#define rep(i, from, to) for (int i = from; i < to; ++i)
#define REP(i, from, to) for (int i = from; i <= to; ++i)

using namespace std;
struct node {
	int x, y;
};
int taikaku(int x, int y) {
	return x * x + y * y;
}
bool cmp(const node &n1, const node &n2) {
	if (taikaku(n1.x, n1.y) < taikaku(n2.x, n2.y)) return true;
	if (taikaku(n1.x, n1.y) > taikaku(n2.x, n2.y)) return false;
	if (n1.y < n2.y) return true;
	return false;
}
bool eq(node n1, node n2) {
	if (n1.x == n2.x && n1.y == n2.y) return true;
	return false;
}
vector<node> data;
void solve() {
	REP(i, 1, 149) {
		REP(j, i + 1, 150) {
			node n;
			n.x = j; n.y = i;
			data.push_back(n);
		}
	}
	sort(data.begin(), data.end(), cmp);
	//rep (i, 0, 80) {
	//cout << data[i].y << " " << data[i].x << endl;
	//}

	while (true) {
		int x, y;
		cin >> y >> x;
		if (y == 0 && x == 0) return;
		node now; now.x = x; now.y = y;
		for(int i = 0; true; ++i) {
			node n = data[i];
			if (eq(now, n)) {
				cout << data[i + 1].y << " " << data[i + 1].x << endl;
				break;
			}
		}
	}
}

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

Measured memory_bytes: 3228
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
s_l = []
for i in range(q):
    s = list(map(int, input().split()))
    s_l.append(s)

A = []
for v in combinations_with_replacement(range(1,m+1), n):
    A.append(v)

ans = 0
for a in A:
    cnt = 0
    for i in range(q):
        if a[s_l[i][1] - 1] - a[s_l[i][0] - 1] == s_l[i][2]:
            cnt += s_l[i][3]
    ans = max(ans, cnt)

print(ans)

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

int main()
{
 int n;
  vector<int> b;
  cin >> n;
  for (int i = 0;i < n-1;i++)
  {
   	int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }
  
  int bag[1000] = {b[0]};
	for (int i = 1;i < n-1; i++)
    {
      bag[i] = min(b[i], b[i-1]);
    }
  bag[n-1] = b[n-2];

  int sum = 0;
  for (int i = 0;i < n; i++)
  {
//    cout << bag[i] << " ";
    sum+= bag[i];
  }
//  cout << endl;
  cout << sum << endl;
  //db
 }


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


int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    long long r,d,x;
    cin>>r>>d>>x;
    long long ans=0;
    long long now=x;
    for(long long i=1;i<=10;i++){
        cout<<r*now-d<<endl;
        now=r*now-d;        
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

struct Edge{
  int to;
  long long cost;
};
struct NODE{
  int pos;
  long long cost;
};

bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
class dijkstra{
  public:
  const int MAX_V = 1000000;
  vector<Edge> g[10000],rg[10000];
  vector<ll> T[10000];

  int N;
  const ll INF = 1e15;
  dijkstra(){};
  dijkstra(int n):N(n){};
  void push(int p,int to,int c){
    g[p].push_back({to,c});
    rg[to].push_back({p,c});
    T[p].push_back(-1);
  }
  ll visit(int i,int j){
    if(T[i][j] >= 0) return T[i][j];
    T[i][j] = g[i][j].cost;
    int u = g[i][j].to;
    rep(k,g[u].size()){
      if(g[u][k].to == i) continue;
      ll r = visit(u,k);
      T[i][j] = max(T[i][j],r + g[i][j].cost);
    }
    return T[i][j];
  }
  vector<ll> height(){
    rep(i,N){
      rep(j,g[i].size()){
        if(T[i][j] < 0){
          T[i][j] = visit(i,j);
        }
      }
    }
    vector<ll> res(N);
    rep(i,N){
      rep(j,g[i].size()){
        res[i] = max(res[i],T[i][j]);
      }
    }
    return res;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll s,t,w;
  dijkstra d(n);
  rep(i,n-1){
    cin >> s >> t >> w;
    d.push(s,t,w);
    d.push(t,s,w);
  }
  auto res = d.height();
  rep(i,n){
    cout << res[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5792
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=100010;
const int INF=1e9;
int n;
int a[N];
inline int abs(int x){
	return x>=0?x:-x;
}
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
}
void solve(){
	sort(a+1,a+1+n);
	int p=lower_bound(a+1,a+1+(n-1),(a[n]+1)>>1)-a;
	if(p==n)
		p--;
	if(!(a[n]&1)){
		int dis1=abs(a[p]-(a[n]>>1)),val1=a[p];
		int dis2=INF,val2=-1;
		if(p>1){
			p--;
			dis2=abs(a[p]-(a[n]>>1));
			val2=a[p];
		}
		printf("%d %d\n",a[n],dis1<=dis2?val1:val2);
	}
	else{
		int dis1=(a[p]>=((a[n]+1)>>1))?abs(a[p]-((a[n]+1)>>1)):abs(a[p]-(((a[n]+1)>>1)-1)),val1=a[p];
		int dis2=INF,val2=-1;
		if(p>1){
			p--;
			dis2=(a[p]>=((a[n]+1)>>1))?abs(a[p]-((a[n]+1)>>1)):abs(a[p]-(((a[n]+1)>>1)-1));
			val2=a[p];
		}
		printf("%d %d\n",a[n],dis1<=dis2?val1:val2);
	}
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 512
#include <iostream>                                                
#include <vector>  
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#define endl "\n"

using ll = long long;
using namespace std;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
    
        
    
    return 0;
}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int H1,H2,M1,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int buffer1,buffer2;
  buffer1 = H1*60+M1;
  buffer2 = H2*60+M2-K;
  cout << buffer2-buffer1;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


map<pair<int, int>, bool> is_black;

int black_cnt_arount(pair<int, int> point) {
    int hh = point.first;
    int ww = point.second;
    int cnt = 0;
    FOR(dh, -1, 1)FOR(dw, -1, 1)
        if(is_black[make_pair(hh + dh, ww + dw)]) cnt++;
    return cnt;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> black_p(n);
    map<pair<int, int>, int> black_cnt;
    REP(i, n) {
        cin >> black_p[i].first >> black_p[i].second;
        black_p[i].first--;
        black_p[i].second--;
        is_black[black_p[i]] = true;
    }

    REP(i, n) {
        int hh = black_p[i].first;
        int ww = black_p[i].second;
        FOR(dh, -1, 1)FOR(dw, -1, 1) {
            if(hh + dh <= 0 or hh + dh >= h - 1 
                or ww + dw <= 0 or ww + dw >= w - 1) continue;
            pair<int, int> point = make_pair(hh + dh, ww + dw);
            black_cnt[point] = black_cnt_arount(point);
        }
    }

    VL ans(10, 0);
    int comp_cnt = 0;
    for(auto& p : black_cnt) {
        ans[p.second]++;
        comp_cnt++;
    }
    ans[0] = (h - 2) * (w - 2) - comp_cnt;
    REP(i, 10) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 213504