akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
 
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
 
void pp(vector<vi> &v){
    rep(i, v.size()){
        rep(j, v.size()){
            cout << v[i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
}
 
bool check(vector<vi> &v, int nx, int ny, int revdir){
    rep(i, 4){
        if(revdir == i) continue;
        int x = nx+dx[i];
        int y = ny+dy[i];
        if(v[y][x] == 1) return false;
    }
    return true;
}
 
int main(){
    int d;
    cin >> d;
    rep(k, d){
        if(k)cout << endl;
        int n;
        cin >> n;
        vector<vi> v(n+4, vi(n+4, 0));
        rep(i, n+4) rep(j, n+4) if(i == 0 || i == n+3 || j == 0 || j == n+3) v[i][j] = 1;
        int x = 2;
        int y = n+3-2;
        int dir = 0;
        v[y][x] = 1;
 
        bool end = false;
        while(1){
            int nx = x+dx[dir];
            int ny = y+dy[dir];
            if(check(v, nx, ny, (dir+2)%4)){
                v[ny][nx] = 1;
                x = nx, y = ny;
                end = false;
            }else{
                dir = (dir+1)%4;
                if(end) break;
                end = true;
            }
        }
 
        //pp(v);
        for(int i = 2; i < n+2; i++){
            for(int j = 2; j < n+2; j++){
                cout << (v[i][j]?'#':' ');
            }
            cout << endl;
        }
    }
 
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int ans = 0;
  ans = ans + vec.at(0) /2;
  
  for(int j=1; j<N; j++){
    ans = ans + vec.at(j);
  }
  cout << ans << endl;
}
    

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


int main(){
    int n;
    cin >> n;
    int W;
    cin >>W;
    int v[n+10],w[n+10];


    rep(i,n){
        cin >> v[i] >> w[i];

    }

    ll dp[n+10][W+10];

    rep(j,W+1){
        dp[0][j]=0;
    }

    rep(i,n){
        rep(j,W+1){
            if(j>=w[i]){
                dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            else{
                dp[i+1][j]=dp[i][j];
            }
        }
    }

    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 10992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    char s[4];
    cin>>s;
    if(s[1]=='B')cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vi ans(n);
    rep(i,n){
        int x; cin >> x;
        ans[x-1] = i+1;
    }
    for(int i: ans) cout << i << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 1152
import math

N, M = map(int, input().split())
A_list = list(map(int, input().split()))

cnt = 0
A_sum = sum(A_list)

for i in range(N):
    if A_list[i] >= math.ceil(A_sum/4/M):
        cnt += 1
if cnt >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9100
N, M = map(int,input().split())
number = M
ans = 0
ABlist = []
for i in range(N):
    A, B = map(int,input().split())
    ABlist.append([A,B])
ABlist.sort()
for x in ABlist:
    if x[1] >= number:
        ans += x[0] * number
        break
    else:
        ans += x[0] * x[1]
        number -= x[1]
print(ans)

Measured memory_bytes: 20064
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))
bucket = [0]*(10**5+1)

for _ in range(n):
    a,b = list(map(int,input().split()))
    bucket[a]+=b

ret = 0
cum = 0
while cum < k:
    ret+=1
    cum+=bucket[ret]
print(ret)


Measured memory_bytes: 5868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	if(n == 1){
		if(a == 1 && b == 1){
			cout << 1 << endl;
		}else{
			cout << -1 << endl;
		}
		return 0;
	}
	if(a + b - 1 > n){
		cout << -1 << endl;
		return 0;
	}
	if(n > a * b){
		cout << -1 << endl;
		return 0;
	}
	ll last = 0;
	for(ll i = 0; i < a; ++i){
		const ll length = min(b, (n - last) - (a - i - 1));
		for(ll j = 0; j < length; ++j){
			cout << last + length - j << " ";
		}
		last += length;
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 2176
import java.util.Scanner;

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

        int n = sc.nextInt();
        int d = sc.nextInt();

        int x[] = new int[n];
        int y[] = new int[n];
        int count = 0;
        for (int i = 0; i < x.length; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();

            double xd = Math.pow(x[i], 2);
            double yd = Math.pow(y[i], 2);


            // System.out.println("x:" + x[i] + " y:" + y[i] + " sqrt:" + Math.sqrt(xd + yd));
            if(Math.sqrt(xd + yd) <= d) {
                count++;
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 60984
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::cout << 800 * N - (N / 15) * 200 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int input_int(void)
{
	int i;
	cin >> i;
	return i;
}
int main()
{
	
	string s;
	cin >> s;
	for (int i = 0; i < static_cast<int>(s.length()); i++)
	{
	

		if (i % 2 == 1)
		{
			if (s.substr(i, 1) == "L" || s.substr(i, 1) == "U" || s.substr(i, 1) == "D")
			{

			}
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s.substr(i, 1) == "R" || s.substr(i, 1) == "U" || s.substr(i, 1) == "D")
			{

			}
			else {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

int main( void )
{
	ll n;
	cin >> n;

	ll x = 1000;
	while ( n > x ) {
		x += 1000;
	}

	cout << (x - n) << endl;

	return 0;
}


Measured memory_bytes: 3636
a=list(map(int,input().split()))
a.sort()
#print(a)
b1=a[2]-a[0]
b2=a[2]-a[1]

if b1%2==0 and b2%2==0:
    print(b1//2+b2//2)
elif b1%2==1 and b2%2==1:
    print(b1//2+b2//2+1)
else:
    print(b1//2+b2//2+2)


Measured memory_bytes: 8904
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().ToDecimal();
            decimal ans = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0) continue;
                if (i % 5 == 0) continue;
                ans += i;
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 18024
#include<bits/stdc++.h>
using namespace std;
main(){
  string r,a;
  while(cin>>r>>a,r.size()!=1){
    int h=0,b=0;
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(i==j&&r[i]==a[j]){
	  h++;
	}
	if(i!=j&&r[i]==a[j]){
	  b++;
	}
      }
    }
    cout<<h<<" "<<b<<endl;
  }
}
       

Measured memory_bytes: 1180
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        TreeMap<String,Integer> hm = new TreeMap<String,Integer>();
        int max = 0;
        for(int i = 0; i < a; i++){
            String str = sc.next();
            if(hm.containsKey(str)){
                hm.put(str, hm.get(str) + 1);
            }else{
                hm.put(str, 1);
            }
            if(max < hm.get(str)){
                max = hm.get(str);
            }
        }
        for(Map.Entry<String,Integer> e : hm.entrySet()){
            if(max == e.getValue()){
                System.out.println(e.getKey());
            }
        }
    }
}


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

int main()
{
    int q;
    cin >> q;
    int arr[4] = {0,0,0,0};
    while(q--)
    {
        string s;
        cin >> s;
        if(s[0] == 'A')
            arr[0]++;
        if(s[0] == 'W')
            arr[1]++;
        if(s[0] == 'T')
            arr[2]++;
        if(s[0] == 'R')
            arr[3]++;
    }
    cout << "AC x " << arr[0] << "\n";
    cout << "WA x " << arr[1] << "\n";
    cout << "TLE x " << arr[2] << "\n";
    cout << "RE x " << arr[3];
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

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

    if (a <= c && c <= b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,m; cin>>n>>m;
	vl v(n);
	rep(i,0,n)cin>>v[i];
	sort(all(v));
	reverse(all(v));
	ll ans=0;
	rep(i,0,n){
		if(m>0){
			m--;
		}
		else ans+=v[i];
	}
	cout<<ans<<endl;
		
	
	return 0;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define temT template<typename T>
using namespace std;
typedef long long ll;
const int N=int(1e6)+10;

int n; ll res;

int pr[N],ct,d[N],nm[N]; bool ntp[N];

void euler_sieve(){
	ntp[1]=1; d[1]=1;
	for(int i=2;i<=N-10;i++){
		if(!ntp[i]) pr[++ct]=i,d[i]=2,nm[i]=1;
		for(int j=1,t;j<=ct && (t=i*pr[j])<=N-10;j++)
			if(i%pr[j]) ntp[t]=1,d[t]=d[i]*d[pr[j]],nm[t]=1;
			else{ ntp[t]=1,d[t]=d[i]/(nm[i]+1)*(nm[i]+2),nm[t]=nm[i]+1; break; }
	}
}

int main(){
	cin>>n; euler_sieve();
	FOR(i,1,n-1) res+=d[i];
	return cout<<res,0;
}

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

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

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

	static long long dp[51][3030];
	dp[0][0] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = i; j >= 0; j--) {
			for (int k = 3000 - x[i]; k >= 0; k--) {
				dp[j + 1][k + x[i]] += dp[j][k];
			}
		}
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (a * i < 3000) {
			ans += dp[i][a * i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;


int main(void) {
    string s;
    cin >> s;
    Int length = (Int)s.length();
    bool result = false;
    for (Int i = 0; i < length - 1; ++i) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            result = true;
        }
    }
    if (result) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
import math
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N):
    time = 0
    for j in range(i,N-1):
        if time <= S[j]:
            time = S[j]+C[j]
        else:
            time = S[j]+C[j]+F[j]*math.ceil((time-S[j])/F[j])
    print(time)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    long l;
    int n;
    cin >> l >> n;
    vector<long> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    vector<long> ps(n + 1);
    for (int i = 0; i < n; i++) ps[i + 1] = ps[i] + x[i];
    long res = 0;

    for (int ttt = 0; ttt < 2; ttt++) {

        for (int nl = 0; nl <= n; nl++) {
            int nr = n - nl;

            if (nl > 0) {
                int pl = std::min(nl, nr);
                int pr = pl;
                if (nl > nr) pl++;
                long s = x[nl - 1] + (ps[nl - 1] - ps[nl - pl]) * 2 +
                         (l * pr - (ps[nl + pr] - ps[nl])) * 2;

//                cout << nl << " " << nr << " " << pl << " " << pr << " " << s << "\n";
//                cout << x[nl - 1] << " " << (ps[nl - 1] - ps[nl - pl]) * 2 << " " <<
//                       (ps[nl + pr] - ps[nl]) << "\n";
                res = std::max(res, s);
            }

        }

//        cout << "\n";

        for (int i = 0; i < n; i++) {
            x[i] = l - x[i];
        }
        std::reverse(x.begin(), x.end());
        for (int i = 0; i < n; i++) ps[i + 1] = ps[i] + x[i];

    }

    cout << res << "\n";

    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

----解説ここまで---- */



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


	LL N, M; cin >> N >> M;
	VL a(M);
	FOR(i, 0, M) {
		cin >> a[i];
	}
	SORT(a);
	LL ans = 0;
	VL diff(N - 1);
	FOR(i, 0, M - 1) {
		ans += a[i + 1] - a[i];
		diff.push_back(a[i + 1] - a[i]);
	}
	RSORT(diff);
	FOR(i, 0, N - 1) {
		ans -= diff[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3592
n=int(input())
x=[0]*n
l=[0]*n
for i in range(n):
    x[i],l[i]=list(map(int,input().split()))

a=[0]*n
b=[0]*n


for i in range(n):
    a[i],b[i]=x[i]-l[i],x[i]+l[i]


c=[[0]*2  for i in range(n)]


for j in range(n):
    c[j][0]=b[j]
    c[j][1]=a[j]


c.sort()


ans=0
z=c[0][1]
for i in range(n):
    if c[i][1]>=z:
        ans+=1
        z=c[i][0]

print(ans)   

Measured memory_bytes: 29616
n=gets.to_i
a=gets.split.map(&:to_i)

def gcd(a,b)
  if b==0 
    return a
  end
  return gcd(b, a%b)
end

g=a[0]
for i in 1...n do
  g=gcd(g,a[i])
end
p g

Measured memory_bytes: 8452
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N,M;
map<Int,Int> card;
int main(void) {
    cin>>N>>M;

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

    for(int i = 0;i < M;i++) {
        Int b,c;
        cin>>b>>c;
        card[c] += b;
    }

    Int sum = 0;
    for(auto it = card.rbegin();N > 0;it++) {
        if(it->second <= N) {
            N -= it->second;
            sum += it->first*it->second;
        } else {
            sum += it->first*(N);
            
            break;
        }
    }

    cout<<sum<<endl;

    return 0;
}





Measured memory_bytes: 12800
H, n = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])


Measured memory_bytes: 42204
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      sum += d.at(i) * d.at(j);
    }
  }
  cout << sum / 2 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]
ans = 0
b = [i[:] for i in a[:]]

for k in range(n):
    for i in range(n):
        for j in range(n):
            b[i][j] = min(b[i][j],b[i][k]+b[k][j])

flag = False
for i in range(n):
    for j in range(n):
        if b[i][j] < a[i][j]:
            ans = -1
            flag = True
            break
        if b[i][j] == a[i][j]:
            for k in range(n):
                if k == i or k == j: continue
                if b[i][j] == b[i][k] + b[k][j]: break
            else:
                ans += b[i][j]
    if flag: break

ans //= 2
print(ans)

Measured memory_bytes: 45916
#!/usr/bin/env python3
import sys
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    
    return table

def solve(N: int):
    from collections import Counter
    counter = Counter(prime_decomposition(math.factorial(N)))
    prime_counts = sorted(list(counter.values()),reverse=True)

    ## key個以上あるもののindex
    d = {74:[],24:[],14:[],4:[],2:[],1:[]}
    for i,count in enumerate(prime_counts):
        for key,_ in d.items():
            if count>=key:
                d[key].append(i)

    answer = 0
    ## ○**74の形のものが何個作れるか
    if d.get(74):
        answer += len(d[74])
    ## ○**24○*2の形のものが何個作れるか
    if d.get(24):
        answer += len(d[24])*(len(d[2])-1)

    ## ○**14○*4の形のものが何個作れるか
    if d.get(14):
        answer += len(d[14])*(len(d[4])-1)

    if len(d.get(4))>=2:
        answer += combinations_count(len(d[4]),2)*(len(d[2])-2)

    print(answer)
    return


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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3380
#include<stdio.h>
#define N 10000

int linearSearch();

int main(){
  int i,n,A[N], a,b,c = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &a);
  for(i = 0; i < a; i++){
    scanf("%d", &b);
    if( linearSearch(A,b,n) == 1 ) c++;
  }
  printf("%d\n",c);
  return 0;
}

int linearSearch(int A[], int b, int n){
  int i;
  for(i = 0 ; i < n-1; i++){
    if(A[i] == b) return 1;
  }
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;



int main(){

    int a,x;

    cin >> x >> a;
    if(x>=a)cout << "10" <<endl;
    else cout << "0" << endl;


    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60
num = [0]*60
ans = 0

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            count[g] += 1
            num[g] += i+1 - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans % mod)


Measured memory_bytes: 124424
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val ls = List.fill(n)(sc.nextLong)

  val res = ls.reduceLeft { (a, b) => (a / gcd(a, b)) * b }
  println(res)

  def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)
}

Measured memory_bytes: 27208
from bisect import bisect_left

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

A.sort()
left=0
right=max(A) * 2 + 1

while left+1<right:
  mid=(left + right) // 2
  
  cnt=0
  for i in range(N):
    cnt+=N - bisect_left(A, mid - A[i])
  if cnt>=M:
    left=mid
  else:
    right=mid

mon=[0]
for a in A:
  mon.append(mon[-1] + a)

ans=0
cnt=0
for i in range(N):
  bi = bisect_left(A, left - A[i])
  ans+=(mon[-1] - mon[bi]) + (N - bi) * A[i]
  cnt+=(N - bi)
ans-=(cnt - M) * left

print(ans)

Measured memory_bytes: 60172
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
  ll n,m,ans=0;cin>>n>>m;
  vl a(n),b(m),c(m);
  vp p(m);
  fr(i,n)cin>>a[i];
  fr(i,m){
    cin>>b[i]>>c[i];
    p[i] = mp(c[i],b[i]);
  }
  sort(a);
  sort(p);
  reverse(p);
  int k = 0;
  fr(i,n){
    if(k == m){
      ans+=a[i];
      continue;
    }
    if(a[i]>=p[k].ft){
      ans+=a[i];
    }else{
      ans+=p[k].ft;
      p[k].sd--;
      if(p[k].sd==0)k++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4224
// j;main(i){for(;9/i;i+=!(j%=9))printf("%dx%d=%d\n",i,j,++j*i);}

// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?log10(a+b)+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?floor(log10(a+b))+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?floor(log10(a+b)+.5)+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:1));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:1));}
k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:14347389));}////////////

// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",b))for(a+=b,b=1;a/=10;b++);}

// #include <stdio.h>
 
// int main( void ) {
//     int a, b, d, tmp;
 
//     for ( ; scanf( "%d %d", &a, &b ) == 2; printf( "%d\n", d ) ) {
//         tmp = a + b;
//         for ( d = 1; tmp /= 10; d++ ) ;
//     }
 
//     return 0;
// }

// main(i,a,t,p,j){for(;~scanf("%d",&t)?i++<4?t<p?p=t:1:t<j?j=t:1:!printf("%d\n",p+j-50););}




// double a,b,c,d;i;main(){scanf("%lf%lf%lf%lf",&a,&b,&c,&d);i=!printf("%f\n",hypot(a-c,b-d));}
// double c[4];i;main(){for(;~scanf("%lf",c+i++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[4],*p=c;i;main(){for(;~scanf("%lf",p++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[],*p=c;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double a,b,c,d,*p=&d;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(d-c,b-a));}




// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%.f\n",s,.5+1.*n/i);i++)n+=y;}
// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%.f\n",s,floor(.5+1.*n/i));i++)n+=y;}////
// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%d\n",s,(int)(.5+1.*n/i));i++)n+=y;}////


// L;main(A,B,C,D){scanf("%d%d%d%d%d",&L,&A,&B,&C,&D);L=!printf("%.f\n",L-fmax(--A/C,--B/D)-1);}
// a,b,c,d,e,*p=&d;main(){for(;~scanf("%d",p++););p=!printf("%.f\n",d-fmax(--b/c,--e/a)-1);}



// char c[];p;main(t){for(;gets(c)**c;p=!puts(strncat(c,c,p%=strlen(c))+p))for(gets(&t);scanf("%d ",&t);p+=t);}

Measured memory_bytes: 644
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};

#define lengthof(x) (sizeof(x) / sizeof(*(x)))


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}

signed main(){
  string s,t; cin>>s>>t;
  vector<char> u,v;
  rep(i,s.size()) u.PB(s[i]);
  rep(i,t.size()) v.PB(t[i]);
  sort(ALL(u)); sort(RALL(v));
  bool flg = true;
  rep(i,u.size()){
    if(u[i]<v[i]) return cout<<"Yes"<<endl,0;
    if(u[i]!=v[i]) flg=false;
  }
  if(flg&&u.size()<v.size()) return cout<<"Yes"<<endl,0;
  cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  string input;
  cin >> input;

  for (int i = 0; i < input.size(); i++)
  {
      /* code */
      cout << (char)((input[i] + N - 'A') % 26 + 'A');
    //   cout << (char)(input[i] + N);
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int h, w;

vector<string> board; string row;

int main() {
    GI(h); GI(w);

    FOR1(i, h) {
        cin >> row;
        board.PB(row);
    }

    int x = 0, y = 0;

    while ((x != h - 1 || y != w - 1) && board[x][y] == '#') {
        bool okr = (y + 1 < w && board[x][y + 1] == '#');
        bool okd = (x + 1 < h && board[x + 1][y] == '#');

        if (okr + okd != 1) {
            printf("Impossible\n");
            return 0;
        }
        else if (okr) {
            board[x][y] = 'O';
            y++;
        }
        else {
            board[x][y] = 'O';
            x++;
        }
    }

    board[h-1][w-1] = 'O';

    FORN(i, h) FORN(j, w) {
        if (board[i][j] == '#') {
            printf("Impossible\n");
            return 0;
        }
    }

    printf("Possible\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007

lli p,n;
string str;

int main()
{
    cin>>n>>p;
    cin>>str;

    lli ans=0;
    if(p==2)
    {
        for(lli i=0;i<n;i++)
        {
            if( (str[i]-'0') %2==0)
            {
                ans+=i+1;
            }
        }
    }
    else if(p==5)
    {
        for(lli i=0;i<n;i++)
        {
            if( (str[i]-'0')%5==0)
            {
                ans+=i+1;
            }
        }
    }
    else{

        map<lli,lli> m;
        m[0]++;
        lli r=1;
        lli t=0;
        for(lli i=n-1;i>=0;i--)
        {
            t=(t+(str[i]-'0')*r)%p;
            //cout<<t<<"\n";
            ans+=m[t];
            m[t]++;
            r=(r*10)%p;

        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1028
#!/usr/bin python3
# -*- coding: utf-8 -*-

n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)

def f(x):
    if x < p:
        return True
    if a[p-1] > a[x] + m:
        return False
    else:
        cnt = m * ((n-x)+(p-1))
        for i in range(p-1, x):
            cnt += max(0,a[x]+m-a[i])
        return cnt >= m*v

ok = 0
ng = n
while ng - ok > 1:
    nw = (ok+ng) // 2
    if f(nw):
        ok = nw
    else:
        ng = nw
print(ng)


Measured memory_bytes: 20644
#include<cstdio>

int main(){
  int a, b, d, r;
  double f;

  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = (double)a / (double)b;
  printf("%d %d %f\n", d, r, f);

  return 0;
}


Measured memory_bytes: 2732
#include <stdio.h>

int main (void){
  long long int h,n;
  scanf("%lld%lld",&h,&n);
  long long int a[n],sum=0;
  for(long long int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    sum+=a[i];
  }

  if(h<=sum){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        vi d(n);
        REP(i, n) {
            cin >> d[i];
            d[i] -= i;
        }
        sort(ALL(d));
        ll mid = d[d.size() / 2];
        ll ans = 0;
        REP(i, n) ans += abs(d[i] - mid);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>


int main(void){
	unsigned long long i;
	unsigned long long  k;//<=50*10^16
	scanf("%lld",&k);
	unsigned long long n=50LL;//数列長は50以下
	unsigned long long a[n];//<=10^16+1000
	for(i=0;i<n;i++){a[i]=n-1;}

	unsigned long long roop=0L;
	unsigned long long amari=0L;
	
	roop=k/50LL;
	amari=k%50LL;
	for(i=0;i<n;i++){a[i]=n-1+roop;}

	for(i=0;i<amari;i++){a[i]+=(n-amari+1LL);}
	for(i=amari;i<n;i++){a[i]-=amari;}



	printf("%lld\n", n);
	for(i=0;i<n;i++){printf("%lld ", a[i]);}
	return 0;
} 

Measured memory_bytes: 128
def main():
    from collections import Counter

    n = int(input())
    a = tuple(int(x) for x in input().split())

    c = Counter(a)
    c1 = c[1]
    c2 = c[2]
    c3 = c[3]

    x1 = 310 ** 2
    x2 = 310

    dp = [0.0] * (310 ** 3)
    dp[0] = 0.0
    # dp[x * x1 + y * x2 + z]:=1,2,3個の皿がx,y,z残っているときの期待値

    for r3 in range(c3 + 1):
        d3 = c3 - r3
        for r2 in range(c2 + d3 + 1):
            for r1 in range(c1 + d3 + c2 - r2 + 1):
                ind = r1 * x1 + r2 * x2 + r3
                if ind != 0:
                    dp[ind] = (n \
                               + (dp[ind - x1] * r1 if r1 > 0 else 0) \
                               + (dp[ind + x1 - x2] * r2 if r2 > 0 else 0) \
                               + (dp[ind + x2 - 1] * r3 if r3 > 0 else 0)) \
                              / (r1 + r2 + r3)

    print(dp[c1 * x1 + c2 * x2 + c3])


if __name__ == '__main__':
    main()

# dp[now] =
# 1
# + dp[1個の皿を食べた] * p
# + dp[2個の皿を食べた] * p
# + dp[3個の皿を食べた] * p
# + dp[0個の皿を食べた==now] * p

# if mainの追加
# 初期値None->-1.0にした
# checked配列を辞めた
# チェック済みかどうかの判定を-1.0と一致するかの比較にした

# カウントはCounterを使う方が速い
# 1次元にした
# resの加算を複数回に分けると
# 三項演算子より遅くなる
# 再帰関数を辞めた


Measured memory_bytes: 267416
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		int t[11][11] = {0};
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> t[i][j];
				t[i][n] += t[i][j];
				t[n][j] += t[i][j];
			}
			t[n][n] += t[i][n];
		}
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= n; j++){
				printf("%5d", t[i][j]);
			}
			printf("\n");
		}
	}
	return (0);
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;

int a[1010]; //钥匙花费 
int c[1010]; //c[i] 的二进制位标记了钥匙能开的宝箱 
int dp[5000];//dp[i] 标记了目标状态需要的最小开销, 其中i的二进制位标记了待开启的宝箱  
int n, m;

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int b,x;
		cin >> a[i] >> b;
		while(b--)
		{
			cin >> x;
			c[i] |= (1<<x-1);
		}
	}
	
	memset(dp,inf,sizeof dp);
	dp[0] = 0;
	
	for(int i = 1; i < (1<<n); i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if((c[j]|i)==i)
			{
				for(int k = 0; k < i; k++)
				{
					if((c[j]|k)==i)
					{
						dp[i] = min(dp[i], dp[k]+a[j]);
					}
				}
			}
			
		}
	}
	
	cout << (dp[(1<<n)-1]==inf ? -1 : dp[(1<<n)-1]);
	
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

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

	ins := make([]int, n+1)
	g := make([][]int, n+1)
	var a, b int
	for i := 0; i < n-1+m; i++ {
		fmt.Scan(&a, &b)
		g[a] = append(g[a], b)
		ins[b]++
	}

	q := make([]int, 0)
	for i := 1; i <= n; i++ {
		if ins[i] == 0 {
			q = append(q, i)
		}
	}

	ans := make([]int, n+1)
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		for _, v := range g[u] {
			ins[v]--
			if ins[v] == 0 {
				q = append(q, v)
				ans[v] = u
			}
		}
	}

	for i := 1; i <= n; i++ {
		fmt.Println(ans[i])
	}
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int l, r;
  cin >> l >> r;
  rep(i,m-1) {
    int a,b;
    cin >> a >> b;
    l = max(l, a);
    r = min(r, b);
  }
  int ans = r-l+1;
  if (ans < 0) cout << 0 << endl;
  else cout << ans << endl;
  return 0;
}

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

int op(int a, int b, char op){
    if (op == '+') return a+b;
    else if (op == '-') return a-b;
    else return -1000000000;
}

int main(){
    string s;
    cin >> s;
    int a = (int)s[0] - '0';
    int b = (int)s[1] - '0';
    int c = (int)s[2] - '0';
    int d = (int)s[3] - '0';
    string pm = "+-";
    rep(i, 2){
        rep(j, 2){
            rep(k, 2){
                if (op(op(op(a, b, pm[i]), c, pm[j]), d, pm[k]) == 7){
                    cout << a << pm[i] << b << pm[j] << c << pm[k] << d << "=7" << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

using namespace std;

int main() {
  int64_t A;
  long double B;
  cin >> A >> B;
  int64_t C = floor(B);
  long double D = B - C;
  int64_t answer = A * C + D * A;
  cout << answer << endl;
  return 0;
}


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

int main()
{
	int N,M,X;
	cin >> N >> M >> X;
	int cnt = 0;
	rep(i,M)
	{
		int a;
		cin >> a;
		if (a < X) cnt++;
	}
	cout << min(cnt,M-cnt) << 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 n=Integer.parseInt(sc.next());
int[] t=new int[n+1];
int[] x=new int[n+1];
int[] y=new int[n+1];
t[0]=0;x[0]=0;y[0]=0;
for(int i=1;i<=n;i++){
t[i]=Integer.parseInt(sc.next());
x[i]=Integer.parseInt(sc.next());
y[i]=Integer.parseInt(sc.next());
}
String ans;
int count=0;
for(int i=0;i<n;i++){
    int dx=Math.abs(x[i+1]-x[i]);
    int dy=Math.abs(y[i+1]-y[i]);
    int dt=Math.abs(t[i+1]-t[i]);
    if(dt%2==(dx+dy)%2){
        if(dx+dy<=dt){count++;}
    }
}
if(count==n){ans="Yes";}else{ans="No";}
System.out.println(ans);
}}

Measured memory_bytes: 61992
#include <iostream>

using namespace std;
/*
考察ノート
Xの倍数かつYの倍数でない <= 10^18の数
Xの約数にYが含まれていたら条件を満たす数は存在しない
*/
int main(){
  int X ,Y;
  cin >> X >> Y;
  if(X%Y == 0) cout << -1 << endl;
  else cout << X << endl;
  return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main()
{
  int x,y;
  in x>>y;
  bool flag=true;
 



  rep(i,101)
  {
    rep(j,101)
    {
      if(i+j==x&&2*i+4*j==y)flag=false;
    }
  }

  if(flag==false)py;
  else pn;

  return 0;
}


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

int main() {
	
	//解説PDFを見ました(迫真)
	//速度の様子うかがい

	int N;
	string S;
	cin >> N >> S;

	map<pair<ll, ll>, int> GOD;

	rep(i, 1 << N) {
		ll blue = 0;
		ll red = 0;
		rep(ii, N) {
			if (i >> ii & 1) {
				blue = blue * 27 + S[ii] - 'a' + 1;
			}
			else {
				red = red * 27 + S[ii] - 'a' + 1;
			}
		}
		GOD[make_pair(blue, red)]++;
	}
	ll kotae = 0;
	rep(i, 1 << N) {
		ll blue = 0;
		ll red = 0;
		rep(ii, N) {
			if (i >> ii & 1) {
				blue = blue * 27 + S[2 * N - ii - 1] - 'a' + 1;
			}
			else {
				red = red * 27 + S[2 * N - ii - 1] - 'a' + 1;
			}
		}
		kotae += GOD[make_pair(blue, red)];
	}
	cout << kotae << "\n";
	Would you please return 0;

}


Measured memory_bytes: 33024
//
//  main.cpp
//  atcoderX
//
//  Created by 村井真奈美 on 2018/06/16.
//  Copyright © 2018年 村井真奈美. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    int N,M;
    
    cin >> N;
    vector<string> plus(N);

    for (int i =0 ;i<N;i++){
        cin >> plus.at(i);
    }
    
    cin >> M;
    vector<string> minus(M);
    
    for (int i = 0;i<M;i++){
        cin >> minus.at(i);
    }
    
    int counter1,counter2;
    
    
    int result = 0;
    

    for(int i=0 ; i<N;i++){
        
        counter1 = counter2 =0;
        
        for(int k=0 ; k<N;k++){
            if(plus[i]==plus[k]) counter1++;
        }
        for(int j=0;j<M;j++){
            if(plus[i] == minus[j]) counter2++;
        }
        
        if(result < (counter1-counter2)) result = counter1-counter2;
        
        
    }
    
    cout << result << endl;

}


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << '\n'
#define pns(x) std::cout << x << ' '
#define read(x) std::cin >> x
#define read2(x,y) std::cin >> x >> y
#define read3(x, y, z) std::cin >> x >> y >> z
#define read4(a, b, c, d) std::cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<Arrete>	vg;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

bool	is_palindrome(int n)
{
	std::string s = std::to_string(n);

	int	l(0), r(s.size() - 1);
	while (l < r)
		if (s[l++] != s[r--]) return false;
	return true;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
	
	int	A, B;
	read2(A,B);
	int	ans(0);
	FOR(i,A,B+1)
	ans += is_palindrome(i);
	pnl(ans);
}



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

using namespace std;

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

    string s;
    cin >> s;
    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';
    cout << s;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[100];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    bool key;
    key = prev_permutation(arr, arr + n);
    if (key) {
        for (int i = 0; i < n; i++) {
            if (i == n - 1) {
                cout << arr[i] << endl;
            }
            else cout << arr[i] << " ";
        }
    }
    next_permutation(arr, arr + n);
    for (int i = 0; i < n; i++) {
        if (i == n - 1) {
            cout << arr[i] << endl;
        }
        else cout << arr[i] << " ";
    }
    key = next_permutation(arr, arr + n);
    if (key) {
        for (int i = 0; i < n; i++) {
            if (i == n - 1) {
                cout << arr[i] << endl;
            }
            else cout << arr[i] << " ";
        }
    }
}


Measured memory_bytes: 3100
import heapq
import bisect

n = int(input())
n = n*3
a = list(map(int,input().split()))

left = a[0:n//3]
right = list(-i for i in a[2*n//3:])

leftsum = [0 for i in range(n//3+1)]
rightsum = [0 for i in range(n//3+1)]

heapq.heapify(left)
leftsum[0] = sum(left)
for i in range(n//3):
    k = i + n//3
    heapq.heappush(left,a[k])
    temp = heapq.heappop(left)
    leftsum[i+1] = leftsum[i]+a[k]-temp

heapq.heapify(right)
rightsum[-1] = -sum(right)
for i in range(n//3)[::-1]:
    k = i + n//3
    heapq.heappush(right,-a[k])
    temp = -heapq.heappop(right)
    rightsum[i] = rightsum[i+1] - temp + a[k]




mxm = -sum(a)
for i in range(n//3+1):
    if leftsum[i]-rightsum[i] > mxm:
        mxm = leftsum[i]-rightsum[i]
print(mxm)

Measured memory_bytes: 37212