akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let s: String = read();
    let q: usize = read();
    let mut rev: bool = false;
    use std::collections::VecDeque;
    let mut deque: VecDeque<char> = VecDeque::from(s.chars().collect::<Vec<char>>());
    for _ in 0..q {
        let t: usize = read();
        match t {
            1 => {
                rev = !rev;
            }
            2 => {
                let f: usize = read();
                let c: String = read::<String>();
                let c = c.chars().next().expect("something wrong");
                match f {
                    1 => {
                        if rev {
                            deque.push_back(c);
                        } else {
                            deque.push_front(c);
                        }
                    }
                    2 => {
                        if rev {
                            deque.push_front(c);
                        } else {
                            deque.push_back(c);
                        }
                    }
                    _ => unreachable!(),
                }
            }
            _ => unreachable!(),
        }
    }
    if rev {
        while let Some(c) = deque.pop_back() {
            print!("{}", c);
        }
    } else {
        while let Some(c) = deque.pop_front() {
            print!("{}", c);
        }
        println!("");
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 6780
#include <stdio.h>
#include <bitset>
int n, a[2001], sum;
std::bitset<2000001> B;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
	const int t = sum / 2 + 1;
	B[0] = 1;
	for (int i = 1; i <= n; i++) B |= B << a[i];
	for (int i = sum + 1 >> 1; i <= sum; i++)
		if (B[sum - i]) {
			printf("%d\n", i);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>

int main()
{
	int num[2];
	int Seisu;
	int Amari;
	double Syosu;
	scanf("%d %d",&num[0],&num[1]);
	Seisu = num[0] / num[1]; 
	Amari = num[0] % num[1];
	Syosu = (double)num[0] / num[1];
	printf("%d %d %.5f\n", Seisu,Amari,Syosu);
	return 0;
}


Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	max := -1
	maxCount := 0
	nextMax := -1
	for i := 0; i < N; i++ {
		if A[i] > max {
			max, nextMax = A[i], max
			maxCount = 1
		} else if A[i] == max {
			maxCount++
		} else if A[i] < max && nextMax < A[i] {
			nextMax = A[i]
		}
	}
	for i := 0; i < N; i++ {
		if maxCount >= 2 {
			fmt.Println(max)
			continue
		}
		if A[i] == max {
			fmt.Println(nextMax)
		} else {
			fmt.Println(max)
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 6472
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1005;
const int M = 7005;
int a[N], b[N], c[N], d[N], e[N], f[N];
vector<int> vx, vy;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
bool ma[M][M], vis[M][M];
int get_x(int x) {
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin();
}
int get_y(int x) {
    return lower_bound(vy.begin(), vy.end(), x) - vy.begin();
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vx.push_back(-1.1e9), vx.push_back(0);
    vy.push_back(-1.1e9), vy.push_back(0);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        vx.push_back(a[i]), vx.push_back(b[i]);
        vy.push_back(c[i]);
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &d[i], &e[i], &f[i]);
        vy.push_back(e[i]), vy.push_back(f[i]);
        vx.push_back(d[i]);
    }
    sort(vx.begin(), vx.end()), vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end()), vy.erase(unique(vy.begin(), vy.end()), vy.end());
    for(int i = 0; i < n; i++) {
        a[i] = get_x(a[i]), b[i] = get_x(b[i]), c[i] = get_y(c[i]);
        for(int j = a[i] * 2 - 1; j < 2 * b[i]; j++) {
            ma[j][2 * c[i] - 1] = true;
        }
    }
    for(int i = 0; i < m; i++) {
        d[i] = get_x(d[i]), e[i] = get_y(e[i]), f[i] = get_y(f[i]);
        for(int j = 2 * e[i] - 1; j < 2 * f[i]; j++) {
            ma[2 * d[i] - 1][j] = true;
        }
    }
    int sx = get_x(0) * 2 - 1, sy = get_y(0) * 2 - 1;
    bool flag = false;
    ll ans = 0;
    queue<pair<int, int>> qu;
    qu.push({sx, sy}), vis[sx][sy] = true;
    while(!qu.empty()) {
        int ux = qu.front().first, uy = qu.front().second;
        qu.pop();
        if(ux == M - 1 || uy == M - 1 || ux == 0 || uy == 0) {
            flag = true;
            break;
        }
        if(ux % 2 == 0 && uy % 2 == 0) {
            int x = ux / 2, y = uy / 2;
            ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
        }
        for(int i = 0 ; i < 4; i++) {
            int xx = ux + dx[i], yy = uy + dy[i];
            if(xx >= M || xx < 0 || yy >= M || yy < 0 || vis[xx][yy] || ma[xx][yy]) continue;
            qu.push({xx, yy}), vis[xx][yy] = true;
        }
    }
    if(flag) printf("INF\n");
    else printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 89024
def judge(s):
    N = len(s)
    if s[::-1] != s:
        return False

    a = s[:(N-1)//2]
    if a[::-1] != a:
        return False

    b = s[(N+3)//2-1:]
    if b[::-1] != b:
        return False

    return True


S = input()
print("Yes" if judge(S) else "No")


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 200010
#define rep(i,j,k) for(i=j;i<=k;++i)
int n,i,j,l,r,mid,m,gol,gor,k;
int a[N],b[N],c[N];
void read(int &p){
	p=0; char x=getchar(); bool fu=false;
	if(x=='-') fu=true;
	while(x<'0' || x>'9'){x=getchar(); if(x=='-') fu=true;}
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
	if(fu) p=-p;
}
bool check(int mid){
	rep(i,1,n) c[i]=(a[i]>=mid);
	gol=gor=m;
	while((gol>1)&&(c[gol]!=c[gol-1])) gol--;
	while((gor<n)&&(c[gor]!=c[gor+1])) gor++;
	if(c[gol]!=c[gor]){
		if(gol+1<=m) gol++;
		else gor--;
	}
	k=((gol+gor)>>1);
	if((gol<=m)&&(m<k)){
		return c[gol-1];
	}
	if((k<m)&&(m<=gor)){
		return c[gor+1];
	}
	return c[gol];
}
int main(){
	read(m); n=(m<<1)-1;
	rep(i,1,n) {
		read(a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	l=1; r=n;
	while(l<r){
		if(r-l>1) mid=(l+r)>>1;
		else mid=r;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",b[l]);
	return 0;
}

Measured memory_bytes: 2560
n,m = map(int,input().strip().split())
ns,ms = [],[]
for _ in range(n):
    ns.append(input().strip())
for _ in range(m):
    ms.append(input().strip())

allFlag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if ns[i][j:j+m] == ms[0]:
            Flag = 1
            for k in range(m):
                if ns[i+k][j:j+m]!=ms[k]:
                    Flag = 0
            if Flag and not allFlag:
                print("Yes")
                allFlag = 1
if not allFlag:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, const char * argv[]) {
   
    
    int i,j,count = 0;
    char T[1001],W[11];
    
    scanf("%s",W);
    
    for (i = 0; i < strlen(W); i++) {
        if (W[i] >= 'A' && W[i] <= 'Z') {
            W[i] += 32;
        }
    }
    
    while (1) {
        
        scanf("%s",T);
        
        if (strcmp(T, "END_OF_TEXT") == 0) {
            break;
        }
        
        for (i = 0; i < strlen(T); i++) {
            if (T[i] >= 'A' && T[i] <= 'Z') {
                T[i] += 32;
            }
        }
        
        if (strcmp(W, T) == 0) {
            count++;
        }
        
        
    }
    
    printf("%d\n",count);
    return 0;

}

Measured memory_bytes: 548
#include<stdio.h>
int main(){
	int n,i,index;
	scanf("%d",&n);
	int place[n+1];
	for(i=0;i<n;i++){
		scanf("%d",&index);
		place[index-1]=i;
	}
	for(i=0;i<n;i++)
		printf("%d ",place[i]+1);
	return 0;
} 

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

int main() {
    int x;
    cin >> x;
    vector<int> dp(x + 1, 0);
    dp.at(0) = 1;
    if (x < 100) {
        cout << 0 << endl;
        return 0;
    } else if (x == 100 || x == 101 || x == 102 || x == 103 || x == 104 || x == 105) {
        cout << 1 << endl;
        return 0;
    }
    for (int i = 100; i < 106; ++i) {
        dp.at(i) = 1;
    }
    for (int j = 106; j < x + 1; ++j) {
        if (dp.at(j - 100) == 1 || dp.at(j - 101) == 1 || dp.at(j - 102) == 1 || dp.at(j - 103) == 1 || dp.at(j - 104) == 1 || dp.at(j - 105) == 1) {
            dp.at(j) = 1;
        }
    }
    cout << dp.at(x) << endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String tmp = null;
		
		int i = 0;
		
		ArrayList<Integer> fas = new ArrayList<Integer>();
		ArrayList<Integer> has = new ArrayList<Integer>();
		ArrayList<Integer> las = new ArrayList<Integer>();
		ArrayList<Integer> las2 = new ArrayList<Integer>();
		int counta=0;
		
		try {
			tmp = br.readLine();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
		counta = Integer.parseInt(tmp);
		
		for(i=0;i<counta;i++){
			
			try {
				tmp = br.readLine();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			
			String[] sprite = tmp.split(" ");
			
			fas.add(Integer.parseInt(sprite[0]));
			has.add(Integer.parseInt(sprite[1]));
			
			
		}
		
		int max = 0;
		
		for(i=0;i<counta;i++){
			if(max <= has.get(i)){
				max = has.get(i);
			}
			
			
		}
		
		for(i=0;i<counta;i++){
			if(max == has.get(i)){
				las.add(fas.get(i));
				las2.add(has.get(i));
			}
			
		}
		
		int rrr;
		
		for(i=0;i<las.size();i++){
			for(int j=0;j<las.size();j++){
				if(las.get(j) < las.get(i)){
					rrr = las.get(i);
					las.set(i, las.get(j));
					las.set(j, las.get(i));
					rrr = las2.get(i);
					las2.set(i, las2.get(j));
					las2.set(j, las2.get(i));
				}
			}
		}
		
		System.out.println(las.get(0)+" "+las2.get(0));
		
	}
}

Measured memory_bytes: 24468
#include <iostream>
#include <vector>
#include <string>

int main()
{
    uint32_t nn;
    uint32_t rr;
    std::cin >> nn >> rr;
    if(nn <= 10){
        std::cout << (rr + 100*(10 -nn)) << std::endl;
    }else{
        std::cout << rr << std::endl;
    }
    return 0;
}


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

using ll=long long;
bool ans = 1;
int n;
int t[100010], x[100010], y[100010];
int main(){
  cin >> n;
  rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
  rep(i,n){
    int dt = t[i+1] - t[i];
    int dx = abs(x[i+1] - x[i]);
    int dy = abs(y[i+1] - y[i]); 
    if(dt < dx + dy) ans = 0;
    if((dt- (dx + dy)) % 2 != 0) ans = 0;
  }
  cout << ((ans) ?"Yes" :"No") << endl;
}

Measured memory_bytes: 1408
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			if self.table[self.table[x]] >= 0:
				self.table[x] = self.table[self.table[x]]
			x = self.table[x]
		return x

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
		return

n = int(input())
d = [list(map(int, input().split())) + [i] for i in range(n)]
d = [[x-1, y-1, i] for x, y, i in d]
d.sort()
uf = UnionFind(n)
cum = [0 for _ in range(n)]
for i in range(n-1):
	if d[i][1] < d[i+1][1]:
		cum[d[i][1]] += 1
		cum[d[i+1][1]] -= 1
for i in range(n):
	if i > 0:
		cum[i] += cum[i-1]
	if cum[i] > 0:
		uf.unite(i, i+1)

ans = [0 for _ in range(n)]
for i in range(n):
	ans[d[i][2]] = uf.size[uf.find(d[i][1])]

print(*ans, sep="\n")

Measured memory_bytes: 170060
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  println(Array.fill(n){readLong()}.reduce(lcm))
  @tailrec def gcd(a: Long, b: Long): Long = {
    b match {
      case 0 ⇒ a
      case _ ⇒ gcd(b, a % b)
    }
  }
  def lcm(a: Long, b: Long): Long = {
    a / gcd(a, b) * b
  }
}


Measured memory_bytes: 27340
function Main(input){
	input = input.trim();
  return input % 2 ? input * 2 : input;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
10
`);

Measured memory_bytes: 11468
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    int a,x; cin >> a >> x;
    cout << ((a<x) ? 0 : 10) << endl;
}


Measured memory_bytes: 384
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int fact(int n){
    if(n <= 1){
        return 1;
    }
    return n * fact(n - 1);
}

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

    int n;
    cin >> n;

    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }

    vector<int> q(n);
    rep(i, n){
        cin >> q[i];
    }

    int pp = fact(n);
    int qq = fact(n);

    do{
        --pp;
    }while(next_permutation(p.begin(), p.end()));

    do{
        --qq;
    }while(next_permutation(q.begin(), q.end()));

    cout << abs(pp - qq) << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n, m, a, b, c, d[1005][1005];
int main() {
	int i, j, k;
	cin>>n>>m;
	for(i=1; i<=n; i++) {
		for(j=1; j<=n; j++) d[i][j] = -1e18;
		d[i][i] = 0;
	}
	while(m--) {
		cin>>a>>b>>c;
		d[a][b] = c;
	}
	for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; j++)
		if(d[i][k] + d[k][j] > d[i][j]) d[i][j] = d[i][k] + d[k][j];
	d[1][1]>0 ? cout<<"inf" : cout<<d[1][n];
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int A, B;
    cin >> A >> B;
    if (A >= 13)
        cout << B << endl;
    else if (A <= 5)
        cout << 0 << endl;
    else
        cout << B / 2 << endl;

    // system("pause");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int main() {
    int N; cin >> N;
    int res = N;
    rep(i, N+1) {
        int cc = 0;
        int t = i;
        while (t > 0) {
            cc += t % 6;
            t /= 6;
        }
        t = N - i;
        while (t > 0) {
            cc += t % 9;
            t /= 9;
        }
        if (res > cc) res = cc;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
C = [list(map(int, input().split())) for _ in range(M)]
for a, b in S:
    dist = [abs(a-c) + abs(b-d) for c, d in C]
    print(dist.index(min(dist))+1)


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

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  int i, j;
  int ch = 0;
  int count = 0;
  for(i = 0; i < n; i++)
  {
    cin >> h.at(i);
  }
  for(i = 1; i < n; i++)
  {
    for(j = 0; j < i; j++)
    {
      if(h.at(i)<h.at(j))
      {
        ch = 1;
        break;
      }
    }
    if(ch == 0)
    {
      count++;
    }
    ch = 0;
  }
  cout << count+1 << endl;
}

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

int main(){
 int n;
 cin >> n;
 VI a(n);
 rep(i,n){
     cin >> a.at(i);
 }
 if(n%2==0){
     VI b(n/2);
     VI c(n/2);
     rep(i,n){
         if(i%2==0)b.at(i/2)=a.at(i);
         else if(i%2==1)c.at((i-1)/2)=a.at(i);
     }
     reverse(c.begin(),c.end());
     rep(i,n/2)cout << c.at(i) << " ";
     rep(i,n/2)cout << b.at(i) <<" ";
     cout << endl;
 }
 else{
     VI b((n+1)/2);
     VI c((n-1)/2);
     rep(i,n){
         if(i%2==0)b.at(i/2)=a.at(i);
         else if(i%2==1)c.at((i-1)/2)=a.at(i);
     }
     reverse(b.begin(),b.end());
     rep(i,(n+1)/2)cout << b.at(i) << " ";
     rep(i,(n-1)/2)cout << c.at(i) << " ";
     cout << endl;
 }
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
const LL inf = 1e15;

struct edge{
    int n, ty;
    LL cost;
    bool operator<(const edge& e1) const {
        return e1.cost < cost;
    }
};

int M, N, K;
int z[200010][2];
LL D[200010][2];
vector<int> G[100010][2];
int main(){
    cin >> M >> N >> K;
    for(int i = 0; i <= K; i++){
        D[i][0] = inf;
        D[i][1] = inf;
    }
    z[0][0] = z[0][1] = 1;
    for(int i = 1; i <= K; i++){
        cin >> z[i][0] >> z[i][1];
        G[z[i][0]][0].push_back(i);
        G[z[i][1]][1].push_back(i);
    }
    priority_queue<edge> pq;
    pq.push(edge{0, 0, 0});
    D[0][0] = 0;
    while(!pq.empty()){
        edge e = pq.top();
        pq.pop();
        if(D[e.n][e.ty] < e.cost) continue;
        int inv = (e.ty + 1) & 1;
        for(auto &u : G[z[e.n][e.ty]][e.ty]){
            LL c = e.cost + (LL)abs(z[e.n][inv] - z[u][inv]) + 1;
            if(D[u][inv] > c){
                D[u][inv] = c;
                pq.push(edge{u, inv, c});
            }
        }
    }
    LL ans = inf;
    for(int i = 1; i <= K; i++){
        if(z[i][0] == M){
            ans = min(ans, min(D[i][0],D[i][1] + 1) + abs(N - z[i][1]) );
        }
        if(z[i][1] == N){
            ans = min(ans, min(D[i][0] + 1,D[i][1]) + abs(M - z[i][0]) );
        }
    }
    cout << (ans == inf ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 24032
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
		int b = sc.nextInt();
      	if(a <= 8 && b <= 8) System.out.println("Yay!");
      	else System.out.println(":(");
    }
}

Measured memory_bytes: 35860
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
a,b=map(int,input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)

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

int main(){
    int N, M;  cin >> N >> M;
    vector<bool> red(N+1, false);
    red[1] = true;
    vector<int> nBall(N+1, 1);
    while(M>0){
        int x, y;  cin >> x >> y;
        if(red[x]){
            red[y] = true;
            if(nBall[x]==1 && red[x]){
                red[x] = false;
            }
        }
        nBall[x]--;  nBall[y]++;

        M--;
    }

    int ans = 0;
    for(int i=1; i<=N; i++){
        if(red[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	vector<int64_t> as(n);
	for (auto& a : as) {
		cin >> a;
	}

	bool has_zero = false;
	int count_minus = 0;
	int64_t min_abs = INT_MAX;
	int64_t sum_abs = 0;

	for (auto& a : as) {
		if (a == 0) has_zero = true;

		if (a < 0) count_minus++;
		sum_abs += abs(a);
		min_abs = min(min_abs, abs(a));
	}

	if (has_zero || (count_minus & 1) == 0) {
		cout << sum_abs << endl;
	}
	else {
		cout << (sum_abs - min_abs * 2) << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<ctype.h>
#define PI 3.141592653589
#define N_MAX 1001

int main()
{
  char buf[N_MAX];
  int i, len, tmp, sum = 0;
  while(1)
    {
      scanf("%s",buf);
      if (strcmp(buf,"0") == 0) break;
      sum = 0;
      len = strlen(buf);
      for(i = 0; i < len; i++)
	{
	  if(isdigit(buf[i]) != 0)
	    {
	      tmp = buf[i] - '0';
	      sum += tmp;
	    }
	}
      printf("%d\n",sum);
    }
  return 0;
}

Measured memory_bytes: 536
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#define MAXM 20006
#define MAXN 1006
#define INF 2100000000
using namespace std;
int n,m;
int gcd(int x,int y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
int main()
{
    while(scanf("%d",&n)==1)
    {
        scanf("%d",&m);
        int g=gcd(n,m);
        printf("%d %d\n",g,(n/g)*m);
    }
}

Measured memory_bytes: 2652
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int n, a;
set<int>s;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		auto itr = s.find(a);
		if (itr != s.end())s.erase(a);
		else s.insert(a);
	}
	cout << (int)s.size() << endl;

	return 0;
}

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

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#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, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

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

  int ds = 0;
  int m=n;
  while (true){
    ds += m%10;
    m /= 10;
    if (m==0) break;
  }
  
  dump(ds, n%ds);
  cout << ((n%ds)? "No" : "Yes") << endl;

  return 0;
}


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

const long long MOD = (long long) 1e9 + 7;

int main() {
  int n;
  std::string s;
  std::cin >> n;
  std::cin >> s;
  int cnt[27];
  for (int i = 0; i < 27; ++i) cnt[i] = 0;
  for (int i = 0; i < n; ++i) {
    ++cnt[(int)(s[i] - 'a')];
  }
  long long ans = 1;
  for (int i = 0; i < 27; ++i) {
    ans = ans * (cnt[i] + 1) % MOD;
  }
  ans = (ans - 1 + MOD) % MOD;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] original = new long[n];
        long[] sorted = new long[n];

        for (int i = 0; i < n ; i++) {
            long value = sc.nextLong();
            original[i] = value;
            sorted[i] = value;
        }

        Arrays.sort(sorted);

        int globalMedianIndex = (sorted.length + 1)/2 - 1;
        long median = sorted[globalMedianIndex];

        for (long value: original
             ) {
            long ans;
            if (median >= value) {
                ans = sorted[globalMedianIndex + 1];
            } else {
                ans = median;
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 94228
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

vector<ll> m(1001,0);

int main(){

    ll n,k; cin >> n >> k;
    ll ans = 0;
    vector<ll> h(n);

    for(int i = 0; i < n; i ++){
        cin >> h[i];
    }

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

    if(k >= n) cout << 0;
    else{
        for(int i = 0; i < n-k; i ++){
            ans += h[i];
        }
        cout << ans;
    }



    return 0;
}

Measured memory_bytes: 4800
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

use std::cmp::{min, max};
use std::collections::{HashMap, HashSet, VecDeque, BinaryHeap};

fn main() {
    input!{
        n: usize,
        k: usize,
        mut v: [usize; n]
    }
    v.sort();
    println!("{}", v.iter().take(k).sum::<usize>());
}


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

int main(void){
    string S;
    string T;

    getline(cin,S);
    getline(cin,T);

    int size_S;
    int size_T;

    size_S = S.size();
    size_T = T.size();

    if (size_S != size_T){
        return 0;
    }

    int counter = 0;

    for(int i = 0; i < size_S;i++){
        if (S[i]!=T[i]){
            ++counter;
        }
    }

    cout << counter << "\n";

}


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

N = int(input())
L = []
for n in [int(i) for i in input().split()]:
    L.append(n)

L.sort()
SUM = 0
for i in range(N):
    x = L.pop()
    y = L.pop()
    if x < y:
        SUM = SUM + x
    elif x >= y:
        SUM = SUM + y

print(SUM)


Measured memory_bytes: 3060
import math

N, D = map(int, input().split())

point_list = []

for i in range(N):
    point_list.append(list(map(int, input().split())))

count = 0 

for j in range(N):
    for k in range(j+1,N):
        distance_pow = 0 
        for l in range(D):
            distance_pow += (point_list[j][l] - point_list[k][l]) ** 2
        distance = math.sqrt(distance_pow)
        
        if distance % 1 == 0:
            count += 1

print(count)


Measured memory_bytes: 3064
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(a[0])
        sys.exit()
    l = [0] * (n + 1)
    for i1 in range(n):
        l[i1 + 1] = gcd(l[i1], a[i1])
    r = [0] * (n + 1)
    for j1 in range(n - 1, -1, -1):
        r[j1] = gcd(r[j1 + 1], a[j1])
    m = [0] * (n + 1)
    for k1 in range(n):
        m[k1] = gcd(l[k1], r[k1 + 1])
    r = max(m)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 84056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<ll> H(n+1); rep(i,n+1) cin>>H.at(i);
  vector<ll> A(n+1); rep(i,n) cin>>A.at(i);
  ll ans=0;
  ll restA=0,restH=0;
  rep(i,n){
    ans+=min(H.at(i),restA);
    restH=max(0LL,H.at(i)-restA);
    ans+=min(A.at(i),restH);
    restA=max(0LL,A.at(i)-restH);
  }
  ans+=min(restA,H.at(n));
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
MAXN = 100

n = input()
k = int(input())

dl = [[None] * (MAXN + 1) for _ in range(MAXN + 1)]
de = [[None] * (MAXN + 1) for _ in range(MAXN + 1)]


def n_num_e(d, i):
    # d: n of digits
    # i: n of nonzero digits
    if d == 0:
        if i == 0:
            return 1
        else:
            return 0
    elif de[d][i] is not None:
        return de[d][i]
    else:
        if int(n[d - 1]) == 0:
            result = n_num_e(d - 1, i)
        else:
            result = n_num_e(d - 1, i - 1)
        de[d][i] = result
        return result


def n_num_l(d, i):
    # d: n of digits
    # i: n of nonzero digits
    if d == 0:
        return 0
    elif dl[d][i] is not None:
        return dl[d][i]
    else:
        if int(n[d - 1]) == 0:
            ne = 0
            nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i)
            result = ne + nl
        else:
            ne = (int(n[d - 1]) - 1) * n_num_e(d - 1, i - 1) + n_num_e(d - 1, i)
            nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i)
            result = ne + nl

        dl[d][i] = result
        return result


answer = n_num_e(len(n), k) + n_num_l(len(n), k)
print(answer)



Measured memory_bytes: 9428
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long llong;
using namespace std;



int main() {
	int n, m, l;
	long A[100][100];
	long B[100][100];
	llong C[100][100] = { 0 };

	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int j = 0; j < m; j++) {
		for (int k = 0; k < l; k++) {
			cin >> B[j][k];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int k = 0; k < l; k++) {
			for (int j = 0; j < m; j++) {
				C[i][k] += A[i][j] * B[j][k];
			}
			cout << C[i][k];
			if (k != l - 1)cout << " ";
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3340
#include<stdio.h>

#define N 100000

int lineSearch(int *, int, int);

int main(){
  int n,q,i,j;
  int S[N];
  int c,count = 0;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
    scanf("%d",&q);
  
  for(j = 0;j < q;j++){
    scanf("%d",&c);
    if(lineSearch(S,n,c)) count++;
  }
  printf("%d\n",count);
}

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




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

int main() {
  int N;
  cin >> N;
  int A = 0;

  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l >> r;
     A = A + r - l + 1;
   if(i==(N-1)) {
       cout << A << endl;
   }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;
int n;

int f[100005] = { 0 };
priority_queue<int>V;
int main()
{
	cin >> n;
	int M = -1;
	for (int i = 1; i <= n; i++) {
		int b;
		cin >> b;
	
		V.push(b);
	}
	int ans = 0;
	while (!V.empty()) {
		int t = V.top();
		V.pop();
		if (M != t)ans++;
		M = t;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine, readInt}
  
object Main {
  def toZero(x:Double) = if(x == -0.0) 0.0 else x
  def main(args:Array[String]) = {
   val p = readLine.split(" ").map(_.toDouble)
   val n = readInt

   val (x0,y0,x1,y1) = (p(0),p(1),p(2),p(3))
   for(i<-0 until n) {
     val p1 = readLine.split(" ").map(_.toDouble)
     val (x2,y2) = (p1(0),p1(1))
     val sqrt = Math.pow(x1-x0,2) + Math.pow(y1-y0,2)
     val inner = (x1-x0)*(x2-x0) + (y1-y0)*(y2-y0)
     val (xt,yt) = (inner*(x1-x0)/sqrt + x0, inner*(y1-y0)/sqrt + y0)
     printf("%.10f %.10f\n", toZero(xt), toZero(yt))
   }
  }
}

Measured memory_bytes: 55068
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int a,b,x,i=0;

	while(scanf("%d %d",&a,&b)!=EOF){
		x=a+b;
		i=0;
		while(1){
			x/=10;
			i++;
			if(x==0) break;
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 600
import heapq
n, m, r = map(int, input().split())
G = [{} for i in range(n)]
for j in range(m):
    s, t, d = map(int, input().split())
    G[s][t] = d
inf = 10**20
D = [inf for i in range(n)]
D[r] = 0
Q = [(0, r)]
heapq.heapify(Q)
while Q:
    _, x = heapq.heappop(Q)
    for y in G[x].keys():
        if D[x]+G[x][y] < D[y]:
            D[y] = D[x]+G[x][y]
            heapq.heappush(Q, (D[y], y))
for i in range(n):
    if D[i] == inf:
        print('INF')
    else:
        print(D[i])



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

using namespace std;

int main() {
	int n;
	cin >> n;
	int A[n];

	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	int q, b, e;

	cin >> q;

	for (int j = 0; j < q; j++) {
		cin >> b >> e;

		while (b < e) {
			swap(A[e - 1], A[b]);

			b++;
			e--;
		}
	}

	for (int k = 0; k < n; k++) {
		if(k == 0) cout << A[k];
		else cout << " " << A[k];
	}
	cout << endl;
}




Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
  long long int n,mw,i,j;
  cin>>n>>mw;
  vector<long long int>w(n),v(n);
  vector<long long int>dp(mw+1,0);
  for(i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=mw-w[i];j>=0;j--)
    {
        dp[w[i]+j]=max(dp[w[i]+j],v[i]+dp[j]);
    }
  }
  cout<<dp[mw];
  return 0;
}


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

int n,L,X[1000000];
long long ans;
stack<int>s1,s2;

int dis(int x,int y)
{
	return y>x ? y-x:L+y-x;
}

long long calc(int x,int d)
{
	if(d==1)
	{
		int y=s1.top();
		s1.pop();
		if(x==y)
			return 0;
		return dis(x,y)+calc(y,-1);
	}
	else
	{
		int y=s2.top();
		s2.pop();
		if(x==y)
			return 0;
		return dis(y,x)+calc(y,1);
	}
}

void solve()
{
	for(int i=n;i;--i)
		s1.push(X[i]);
	for(int i=1;i<=n;i++)
		s2.push(X[i]);
	long long sum=calc(0,1);
	ans=max(ans,sum);
	for(int i=n+1;i<=n*3+2;i++)
		X[i]=X[i-n-1];
	int l=(n+1)/2+1,r=n+1+(n+1)/2;
	for(int i=n+2;i<n*2+1;i++)
		if(i&1)
		{
			sum+=dis(X[i],X[r])-dis(X[l],X[i]);
			ans=max(ans,sum);
		}
		else
		{
			sum+=dis(X[i],X[r+1])-dis(X[l],X[i]);
			ans=max(ans,sum);
			++l,++r;
		}
}
int main()
{
	scanf("%d%d",&L,&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&X[i]);
	solve();
	for(int i=1;i<=n;i++)
		X[i]=L-X[i];
	for(int i=1;i<=n/2;i++)
		swap(X[i],X[n-i+1]);
	solve();
	cout<<ans<<endl;
}


Measured memory_bytes: 5020
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll n;
        cin >> n;
        ll a[n]; vi v;
        rep(i, n) cin >> a[i], v.pb(a[i]);
        sort(all(v));
        rep(i, n){
            ll x = lower_bound(all(v), a[i]) - v.begin();
            cout << ( x < n/2 ?  v[n/2] : v[n/2 - 1] ) << endl;
        }
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
/*
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
*/      
      //te
      solve();
      return 0;
    } 

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

namespace ABC086_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int a = int.Parse(strs[0]);
            int b = int.Parse(strs[1]);

            Console.WriteLine(a * b % 2 == 0 ? "Even" : "Odd");
        }
    }
}


Measured memory_bytes: 11092
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string ans="";
    for(char c : s){
        if(c=='1'){
            ans+="9";
        }else{
            ans+="1";
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    char b;
    cin >> b;
    if(b=='A') cout << 'T' << "\n";
    else if(b=='T') cout << 'A' << "\n";
    else if(b=='G') cout << 'C' << "\n";
    else cout << 'G' << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []

for i in range(n):
    temp = []
    temp_temp = []
    temp.append(int(input()))
    for j in range(temp[0]):
        temp_temp.append(list(map(int,input().split())))
    temp.append(temp_temp)
    a.append(temp)

ans = 0

for i in range(2**n):
    ans_t = 0
    id_list =list(bin(i))[2:]
    id_list = [int(x) for x in id_list]
    while len(id_list) != n:
        id_list.insert(0,0)
    for j in range(n):
        flag = 0
        if id_list[j] == 0:
            continue
        else:
            for k in range(a[j][0]):
                if id_list[a[j][1][k][0]-1] != a[j][1][k][1]:
                    flag = 1
                    break
        if flag == 1:
            ans_t = 0
            break
        else:
            ans_t += 1
    if ans_t > ans:
        ans = ans_t

print(ans)


Measured memory_bytes: 9028