akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = ""; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

using namespace std;

const ll INF = 1e9 + 10;
const ll INF2 = 1e18 + 10;
const int MOD = 1e9 + 7;
const ld EPS = 1e-4;

const int LOGN = 19;
const int MAXN = 1e5;

ll dp[MAXN][2], ans[MAXN];
vector<int> g[MAXN];
int n, mod;

void dfs1(int v, int p) {
	dp[v][0] = 1;
	dp[v][1] = 1;

	for (int u: g[v]) {
		if (u != p) {
			dfs1(u, v);
			dp[v][0] = (dp[v][0] * dp[u][0]) % mod;
			dp[v][1] = (dp[v][1] * (dp[u][0] + dp[u][1])) % mod;
		}
	}
}

void dfs2(int v, int p) {
	// for (int i = 0; i < n; i++) {
	// 	for (int j = 0; j < 2; j++) {
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;

	ans[v] = dp[v][1];
	vector<ll> ap(1, 1), bp(1, 1);
	for (int u: g[v]) {
		ap.push_back(ap.back() * dp[u][0] % mod);
		bp.push_back(bp.back() * (dp[u][0] + dp[u][1]) % mod);
	}
	int m = ap.size() - 1;
	vector<ll> as(m + 1, 1), bs(m + 1, 1);

	int i = m - 1;
	reverse(g[v].begin(), g[v].end());
	for (int u: g[v]) {
		as[i] = (as[i + 1] * dp[u][0]) % mod;
		bs[i] = (bs[i + 1] * (dp[u][0] + dp[u][1])) % mod;
		i--;
	}
	reverse(g[v].begin(), g[v].end());

	i = 0;
	for (int u: g[v]) {
		if (u != p) {
			int v0 = dp[v][0], v1 = dp[v][1], u0 = dp[u][0], u1 = dp[u][1];
			ll t0 = ap[i] * as[i + 1] % mod;
			ll t1 = bp[i] * bs[i + 1] % mod;
		//	cout << v << ' ' << u << ' ' << t0 << ' ' << t1 << endl;
			dp[v][0] = t0; dp[v][1] = t1;
			dp[u][0] = dp[u][0] *  t0 % mod; 
			dp[u][1] = dp[u][1] * (t0 + t1) % mod; 
			dfs2(u, v);
			
			dp[v][0] = v0, dp[v][1] = v1;
			dp[u][0] = u0, dp[u][1] = u1;

		}
		i++;
	}
}

int main() {
	FAST;

	cin >> n >> mod;

	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs1(0, 0);
	dfs2(0, 0);
	for (int i = 0; i < n; i++) cout << ans[i] << '\n';
}



Measured memory_bytes: 37620
from collections import defaultdict

def main():
    num, in_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    x_jiku, y_jiku = set(), set()

    for x, y in data:
        x_jiku.add(x)
        y_jiku.add(y)

    x_jiku = list(x_jiku)
    y_jiku = list(y_jiku)
    x_jiku.sort()
    y_jiku.sort()

    ans = 10 ** 20
    for x_kagen in x_jiku:
        for x_jogen in x_jiku[::-1]:
            if x_kagen >= x_jogen:
                break
            for y_kagen in y_jiku:
                for y_jogen in y_jiku[::-1]:
                    if y_kagen >= y_jogen:
                        break

                    if checl(x_kagen, x_jogen, y_kagen, y_jogen, data, in_num, num):
                        kari = (x_jogen - x_kagen) * (y_jogen - y_kagen)
                        if kari < ans:
                            ans = kari

    print(ans)

def checl(x_kagen, x_jogen, y_kagen, y_jogen, data, in_num, num):
    count = 0
    for i in range(num):
        if x_kagen <= data[i][0] <= x_jogen and y_kagen <= data[i][1] <= y_jogen:
            count += 1
    if count >= in_num:
        return 1
    else:
        return 0




if __name__ == '__main__':
    main()

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

int main(int argc, char** argv){
  int A, B;
  cin >> A >> B;
  int ans;
  ans = A+B;
  if(abs(A-B) >= 2) {
    ans = max(A, B);
    ans += max(A-1, B-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n, m;
	int i;
	int sum = 0;
	int list[10001];
	cin >> n >> m;
	for (i = 0; i < m; i++)
	{
		cin >> list[i];
		sum += list[i];
	}
	if (sum <=n)
		cout << n-sum;
	else
		cout << "-1";
	return 0;
}


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

string s;

int main(){
	ios_base::sync_with_stdio(false);

	cin>>s;
	if(s=="Sunny")cout<<"Cloudy\n";
	else if(s=="Cloudy")cout<<"Rainy\n";
	else if(s=="Rainy")cout<<"Sunny\n";
}

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

int main() {
  long long N,tmp;
  cin>>N;
  
  tmp=sqrt(N);
  while(tmp>0){
    if(N/tmp*tmp==N){break;}
    tmp--;
  }
  cout<<tmp+N/tmp-2<<endl;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> v(4);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end());
    int ans = INF<int>;
    do {
        ans = min(ans, abs(v[0]+v[1]-v[2]-v[3]));
    }while(next_permutation(v.begin(),v.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3244
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var tree = new DiameterForEdge(N);
        for (int i = 0; i < N - 1; i++)
        {
            var line = ReadLine().Split(' ');
            var u = int.Parse(line[0]) - 1;
            var v = int.Parse(line[1]) - 1;
            var w = int.Parse(line[2]);
            tree.Add(u, v, w);
        }
        foreach (var c in tree.Distance(0)) WriteLine(c % 2 == 0 ? "0" : "1");
    }
}

struct Edge
{
    public int to;
    public int dist;
}

class DiameterForEdge
{
    List<Edge>[] graph;
    long[] dp;

    public DiameterForEdge(int cap)
    {
        graph = new List<Edge>[cap];
        for (int i = 0; i < graph.Length; i++)
        {
            graph[i] = new List<Edge>();
        }
        dp = new long[cap];
    }

    public void Add(int u, int v, int d)
    {
        graph[u].Add(new Edge { to = v, dist = d });
        graph[v].Add(new Edge { to = u, dist = d });
    }

    void DFS(int v, int p, ref int s)
    {
        if (p == -1) dp[v] = 0;
        if (dp[s] < dp[v]) s = v;
        foreach (var e in graph[v])
        {
            var u = e.to;
            if (u == p) continue;
            dp[u] = dp[v] + e.dist;
            DFS(u, v, ref s);
        }
    }

    public long[] Distance(int s)
    {
        DFS(s, -1, ref s);
        return dp;//本当はコピーとるべき
    }
}

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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  for (int i = N - 1; i >= 0; i--) {
    if (i != 0)
      cout << A.at(i) << ' ';
    else
      cout << A.at(i) << endl;
  }
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

unsigned long long d[100001];
vector<pair<int, unsigned long long>> e[100001];

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

	for (auto i = 0; i < N - 1; ++i)
	{
		int a, b;
		unsigned long long c;
		cin >> a >> b >> c;
		e[a].push_back(make_pair(b, c));
		e[b].push_back(make_pair(a, c));
	}

	int Q, K;
	cin >> Q >> K;

	priority_queue<pair<unsigned long long, int>, vector<pair<unsigned long long, int>>, greater<pair<unsigned long long, int>>> q;
	fill(d, d + N + 1, LLONG_MAX);
	d[K] = 0;
	q.push(make_pair(0ull, K));

	while (!q.empty())
	{
		auto p = q.top();
		q.pop();
		auto v = p.second;
		if (d[v] < p.first)
		{
			continue;
		}

		auto& list = e[v];
		for (auto& temp : list)
		{
			if (d[temp.first] > d[v] + temp.second)
			{
				d[temp.first] = d[v] + temp.second;
				q.push(make_pair(d[temp.first], temp.first));
			}
		}
	}

	vector<unsigned long long> result;
	for (auto i = 0; i < Q; ++i)
	{
		int x, y;
		cin >> x >> y;
		result.push_back(d[x] + d[y]);
	}

	for (auto i = 0; i < Q; ++i)
	{
		cout << result[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 12528
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed 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")
}

fn main() {
    let n:usize = read();
    let mut arr:Vec<usize> = (0..n).map(|_| read()).collect();
    arr = arr.iter().cloned().rev().collect();
    println!("{}", arr.into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" "));
}


Measured memory_bytes: 5032
s = raw_input()
string = 'keyence'
back = 0
front = 0
ptr = len(string)-1
for i in xrange(len(s)-1, -1, -1):
	if ptr < 0:
		break
	if s[i] == string[ptr]:
		back += 1
		ptr -= 1
	else:
		break
for i in xrange(len(s)):
	if i == len(string):
		break
	if s[i] == string[i]:
		front += 1
	else:
		break
if front + back >= len(string):
	print 'YES'
else:
	print 'NO'


Measured memory_bytes: 28012
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
int a[3];cin>>a[0]>>a[1]>>a[2];
sort(a,a+2);

if(a[0]==a[1]&&a[1]==a[2]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}


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

vector<int> s;

int main(){

  int n,q,sum=0;
  int t;

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

  cin >> q;
  for(int i=0; i<q; i++){
    cin >> t;
    if(binary_search(s.begin(),s.end(),t)==true)sum++;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1532
/*
AtCoder Beginner Contest 085 A - Already 2018
Ver1
結果:
*/

#include<stdio.h>

//#define DEBUG1

int main() {
	char s[11];
	scanf("%s", s);

	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';

#ifdef DEBUG1
	printf("%s", s);
	getch();
#endif
	printf("%s", s);
	return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);
    for(int i=0;i<n;i++) {
        cin >> x.at(i) >> y.at(i) >> h.at(i);
    }

    int xfix, yfix, hfix;
    for(int i=0;i<n;i++) {
        if(h.at(i)!=0) { 
            xfix = x.at(i);
            yfix = y.at(i);
            hfix = h.at(i);
        }
    }

    int hhypo, hreal;
    for(int cx=0;cx<=100;cx++) {
        for(int cy=0;cy<=100;cy++) {
            hhypo = hfix + abs(xfix-cx) + abs(yfix-cy);
            for(int i=0;i<n;i++) {
                hreal = max(hhypo-abs(x.at(i)-cx)-abs(y.at(i)-cy), 0);
                if(hreal!=h.at(i)) {
                    break;
                }
                else if(hreal==h.at(i)&&i==n-1) {
                    cout << cx << " " << cy << " " << hhypo << endl;
                    return 0;
                }
                else continue;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
//Computation - Circle
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		double r = Double.parseDouble(in.readLine());
		
//		double r =34.1201;
		
		System.out.printf("%.6f %.6f\n" ,r*r*Math.PI,2*r*Math.PI);
			

	}
}

Measured memory_bytes: 16984
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll h, w;

int main() {
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
	}
	else {
		cout << (h * w + 1) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;

void main(){
  int n=to!int(chomp(readln()));
  string s, t;
  s=chomp(readln());
  t=chomp(readln());

  if(n==1){
    writeln(3);
    return;
  }
  const mod=1_000_000_000+7;
  bool y=s[0]==t[0];
  long c=y? 3: 6;
  int i=y? 1: 2;
  while(i<n){
    if(i+1<n){
      if(s[i]==t[i]){
        if(y){
          (c*=2)%=mod;
        }else{
          // c*=1;
        }
        y=true;
        i++;
      }else{
        if(y){
          (c*=2)%=mod;
        }else{
          (c*=3)%=mod;
        }
        y=false;
        i+=2;
      }
    }else{
      if(y){
        (c*=2)%=mod;
      }else{
        // c*=1;
      }
      break;
    }
  }

  writeln(c);
}

/*
  1 : 2 2 3
  2 : 1 3 1
*/

Measured memory_bytes: 256
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////
double PI = 3.1415926535897932;
int main(void){
  ioboost();
  
  double a,b;cin >> a >> b;
  double h,m;cin >> h >> m;

  double a1 = 6.0 * m - 90.0;
  a1 = PI * a1 / 180.0;
  double a2 = 30.0*h + 0.5*m - 90.0;
  a2 = PI * a2 / 180.0;

  double x1 = b*cos(a1);
  double y1 = b*sin(a1);
  double x2 = a*cos(a2);
  double y2 = a*sin(a2);

  cout << sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) << '\n';
}


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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int h , w , n;
   cin >> h >> w >> n;
   if(h < w)
      swap(h , w);
   cout << n / h + (n % h > 0);
   return 0;
}


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

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

    map<string, string> mp;
    mp["A"] = "T";
    mp["T"] = "A";
    mp["G"] = "C";
    mp["C"] = "G";

    cout << mp[s] << endl;
    return 0;
}

Measured memory_bytes: 256
def issymmetry(S):
    sym = 1
    N = len(S)
    if N%2 == 0:
        for i in range(0,N//2-1):
            if S[N//2+i] != S[N//2-1-i]:
                sym = 0
                break
    else:
        for i in range(0,N//2+1):
            if S[N//2-i] != S[N//2+i]:
                sym = 0
                break
    return(sym)

A,B=map(int,input().split())

ans=0
for i in range(A,B+1):
    if issymmetry(str(i)):
        ans+=1

print(ans)

Measured memory_bytes: 40684
N = int(input())
L = [list(input().split()) for i in range(N)]
for i in range(len(L)):
  L[i][1] = 100-int(L[i][1])
K = sorted(L)

ans = []
for i in range(len(K)):
  for j in range(len(L)):
    if K[i] == L[j]:
      ans.append(j+1)
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int a,b,x;
int main(){
	while(~scanf("%d%d%d",&x,&a,&b)){
     int ax,bx;
     ax = abs(a-x);
     bx = abs(b-x);
     if(ax>bx)
     	 printf("B\n");
     	 else 
     	 	 printf("A\n");
	}
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
	//?????°
	static int S,h,m,s;
	//????????????
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		S = sc.nextInt();
		h = S/3600;
		m = (S-(h*3600))/60;
		s = S-((h*3600)+(m*60));
		System.out.println(h+":"+m+":"+s);
	}
	public static void main(String[] args) {
		solve();
	}
}

Measured memory_bytes: 26100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,ar[32]= {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    cin>>k;
    for(i=0; i<=32; i++)
    {

        if(i==(k-1))

            cout<<ar[i];

    }
    return 0;
}


Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
void solve()
{
     ll n;
     cin >> n;
     map<ll,ll> y;
     ll a[n];
     for(ll i=0;i<n;i++)   cin >> a[i],y[a[i]]++;
     ll ans = 0;
     for(auto X:y)
     {
          if(X.ss>1)
          {
               ans += X.ss*(X.ss-1)/2;
          }
     }   
     for(ll i=0;i<n;i++)
     {
          ll temp = ans;
          ll fre = y[a[i]];
          temp -= fre*(fre-1)/2;
          fre--;
          temp += fre*(fre-1)/2;
          cout<<temp<<"\n";
     }      
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 11136
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = (1 << 28);
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll n;
ll a[100000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    ll sum = 0;
    for (ll i = 0; i < n; i++)
    {
        sum += abs(a[i]);
    }
    if (a[0] >= 0)
    {
        sum -= 2 * a[0];
    }
    if (a[n - 1] < 0)
    {
        sum += 2 * a[n-1];
    }
    cout << sum << "\n";
    bool plus = false;
    ll temp=a[0];
    ll im;
    for (ll i = 1; i < n-1; i++)
    {
        if (a[i] > 0)
        {
            cout << temp << " " << a[i] << "\n";
            temp -=a[i];
        }
    }
    ll temp1=a[n-1];
    cout << temp1 << " " << temp << "\n";
            temp1 -=temp;
    for(ll i = 1; i < n-1; i++){
        if (a[i] <= 0)
        {
            cout << temp1<< " " << a[i] << "\n";
            temp1 -=a[i];
        }
    }
}

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

using namespace std;

int n,m,i,j,c[100005];
vector <int> edge[100005];
bool vis[11][100005];

struct dat{
	int x,y,z;
}a[100005];

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < m; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	int q;
	scanf("%d", &q);
	
	for(i = 0; i < q; i++)
	scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
	
	for(i = q - 1; i >= 0; i--){
		int color = a[i].z;
		if(vis[a[i].y][a[i].x]) continue;
		vis[a[i].y][a[i].x] = 1;
		
		queue <pair <int, int> > b;
		b.push({a[i].x, a[i].y});
		
		while(b.size()){
			pair <int, int> now = b.front();
			b.pop();
			//printf(">> %d %d\n", now.first, color);
			
			if(c[now.first] == 0)
			c[now.first] = color;
			
			if(now.second == 0) continue;
			
			now.second--;
			
			for(int k = 0; k < edge[now.first].size(); k++){
				int to = edge[now.first][k];
				if(vis[now.second][to]) continue;
				vis[now.second][to] = 1;
				b.push({to, now.second});
			}
		}
	}
	
	for(i = 1; i <= n; i++)
	printf("%d\n", c[i]);
}


Measured memory_bytes: 9560
#include <cmath>
#include <iostream>
using namespace std;
int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> nn;
    const int_fast32_t n = nn;
    if(n == 1) {
        putc_unlocked(49, stdout);
    } else {
        const int_fast32_t sqrtN = sqrt(n);
        ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
        for(int i = 1; i <= sqrtN; ++i) {
            const int_fast32_t a = n / i;
            ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
        }
        cout << ans;
    }
}

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

int main() {

    int n;
    long long int c;

    cin >> n >> c;

    pair<long long int,long long int> s[n+1];

    s[0] = make_pair(0,0);

    for(int i=1; i<n+1; i++){
        cin >> s[i].first>> s[i].second;
    }

    //あらかじめどこまでmaxポイントが手に入るかの計算。
    long long int rev_max[n+1],rdis_point[n+1];

    rev_max[0] = 0;
    rdis_point[0] = 0;

    for(int i=1; i<n+1; i++){
        rdis_point[i] = rdis_point[i-1] + s[i].second - (s[i].first - s[i-1].first);
        rev_max[i] = max(rdis_point[i],rev_max[i-1]);
    }

    for(int i=1; i<n+1; i++){
        s[i].first = c - s[i].first;
    }

    sort(s,s+n+1);

    //順番を入れ替えると反時計回りに回ったときに使える。
    long long int for_max[n+1],dis_point[n+1];

    for_max[0] = 0;
    dis_point[0] = 0;

    for(int i=1; i<n+1; i++){
        dis_point[i] = dis_point[i-1] + s[i].second - (s[i].first - s[i-1].first);
        for_max[i] = max(dis_point[i],for_max[i-1]);
    }

    for(int i=1; i<n+1; i++){
        s[i].first = c - s[i].first;
    }

    sort(s,s+n+1);

    long long int ans = 0;
    long long int mfor = 0;

//*
    for(int i=0; i<n; i++){
        int to_pos = i+1;

        mfor += s[to_pos].second - (s[to_pos].first - s[i].first);
        ans = max(ans,mfor);

        long long int tmp = mfor;

        if(i == n-1){
            break;
        }

        tmp -= s[to_pos].first;

        int index = n - i - 1;
        tmp += for_max[index];
        ans = max(ans,tmp);

    }
//*/
    for(int i=1; i<n+1; i++){
        s[i].first = c - s[i].first;
    }
///*
    sort(s,s+n+1);

    mfor = 0;
    for(int i=0; i<n; i++){
        int to_pos = i+1;

        mfor += s[to_pos].second - (s[to_pos].first - s[i].first);
        ans = max(ans,mfor);

        long long int tmp = mfor;

        if(i == n-1){
            break;
        }

        tmp -= s[to_pos].first;

        int index = n - i - 1;
        tmp += rev_max[index];
        ans = max(ans,tmp);

    }
//*/

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
from operator import itemgetter
N, M = map(int, input().split())
# info = [tuple(map(int, input().split())) for _ in range(M)]
info = []
for i in range(M):
    P, Y = map(int, input().split())
    info.append((P, Y, i))
info.sort()
# print(info)
num = set()
ID = []
for i in range(M):
    if not info[i][0] in num:
        num.add(info[i][0])
        j = 1
    else:
        j += 1
    left = str(info[i][0])
    right = str(j)
    left = left.zfill(6)
    right = right.zfill(6)
    ID.append((left + right, info[i][2]))
    # print(ID)
ID = sorted(ID, key=lambda x: x[1])
# ID = sorted(ID, key=itemgetter())
# print(ID)
for id, index in ID:
    print(id)

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

signed main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());

  if(s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const int inf = (int)(1e9);

int n, k, ar[N], dp[N];

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> ar[i];

	fill(dp + 1, dp + n + 1, inf);

	dp[1] = 0;

	for(int i = 2; i <= n; i++)
		for(int j = 1; j <= k; j++)
			if(i - j >= 1)
				dp[i] = min(dp[i], dp[i - j] + abs(ar[i - j] - ar[i]));

	cout << dp[n];
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0LL, a + b - n) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,x;
	for(i=1;i<i+1;i++){
		scanf("%d",&x);
		if(x!=0){
			printf("Case %d: %d\n",i,x);
		}else{
			break;
	}
	}
	return 0;
}

Measured memory_bytes: 600
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        l:usize,r:usize,d:usize
    }
    let mut ans = 0;
    for i in l..=r {
        if i % d == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2112
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define EPS (1e-10)
#define PI 3.14159265358979323846264
using namespace std;
 
double rad(double d)
{
  return d*(PI/180.0);
}

int main()
{
  int m;
  while(cin >> m,m)
    {
      double v,areaA,areaB;
      areaA = areaB = 0;
      double ano = 360;
      for(int i=0;i<m-1;i++)
	{
	  cin >> v;
	  areaA += sin(rad(v));
	  ano -= v;
	}
      areaA += sin(rad(ano));
 
      cin >> m;
      ano = 360;
      for(int i=0;i<m-1;i++)
	{
	  cin >> v;
	  areaB += sin(rad(v));
	  ano -= v;
	}
      areaB += sin(rad(ano));
            

      if(fabs(areaA-areaB) <= EPS)
	cout << 0 << endl;
      else if(areaA > areaB)
	cout << 1 << endl;
      else 
	cout << 2 << endl;
      
    }
  return 0;
}

Measured memory_bytes: 1260
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i+1, n):
		for k in range(j+1, n):
			if len({l[i], l[j], l[k]}) == 3 and max(l[i], l[j], l[k]) * 2 < l[i] + l[j] + l[k]:
				ans += 1
print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    int n;
    cin >> n;
    int now=0;
    bool ans=0;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        if(x==y) now++;
        else now=0;
        if(now>=3) ans=1;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	

	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);

	A[0] = 0;
	B[0] = 0;

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

	


	for (int i = 1; i < N; i++)
	{
		B[A[i]-1] += 1;
	}

	

	
	

	for (int i = 0; i < N; i++)
	{
		cout << B[i] << endl;

	}
	

	return 0;
}




Measured memory_bytes: 4840
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(N-1):
    for j in range(i+1,N):
        dist = min(j-i, min(abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j)))
        ans[dist-1] += 1
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 48460
S = list(str(input()))
S.insert(0, "L")

c = 0
for s in S:
    if c%2 == 0:
        if not((s=='L') or (s=='U') or (s=='D')):
            print('No')
            exit()
    else:
        if not((s=='R') or (s=='U') or (s=='D')):
            print('No')
            exit()
    c += 1
print('Yes')


Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
class Main
{
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in); 
		int i;	
		int n=sc.nextInt();
		double p[]=new double[n];
		for(i=0;i<n;i++)
			p[i]=sc.nextDouble();
		double dp[][]=new double[n][n+1];
		for(i=0;i<n;i++)
		{
			if(i==0)
				dp[i][0]=(1-p[i]);
			else
				dp[i][0]=dp[i-1][0]*(1-p[i]);
			for(int j=1;j<=i+1;j++)
			{
				if(i>0)
					dp[i][j]=dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
				else
					dp[i][j]=p[i];
			}
		}
		double ans=0;
		for(i=(n+1)/2;i<=n;i++)
			ans+=dp[n-1][i];
		System.out.println(ans);
	}
}

Measured memory_bytes: 116332
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int L; cin >> L;
  int tmp = 0;
  vector<pair<P, int>> vec;

  if (L==1) {
    cout << "2 1" << endl;
    cout << "1 2 0" << endl;
    return 0;
  }

  int k=0;
  while(L >= (1<<k)) {
    k++;
  }
  k--;

  for(int i=1; i<=k; i++) {
    vec.push_back(make_pair(P(i, i+1), 0));
    vec.push_back(make_pair(P(i, i+1), 1<<(k-i)));
  }
  //sdebugln(tmp);
  tmp = (1<<k);

  L -= tmp;
  //debugln(L);
  int pos = tmp;
  int n = vec.size()/2;
  //debugln(n);

  while(L>0) {
    int i=0;
    while(L >= (1<<i)) {
      i++;
    }
    vec.push_back(make_pair(P(1, n+2-i), pos));
    //debugln(i);
    pos += (1<<(i-1));
    L -= (1<<(i-1));
  }

  cout << n+1 << ' ' << vec.size() << endl;
  rep(i, vec.size()) {
    cout << vec.at(i).first.first << ' ' << vec.at(i).first.second << ' ' << vec.at(i).second << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	vector<ll> L(n);
	for (int i = 0; i < n; i++)
		cin >> L[i];

	int ans = 0;
	for (int i = 0; i < n-2; i++)
	{
		for (int j = i+1; j < n-1; j++)
		{
			for (int k = j+1; k < n; k++)
			{
				if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i] &&
					L[i] < L[j] + L[k] &&
					L[j] < L[k] + L[i] &&
					L[k] < L[i] + L[j])
					ans++;
			}
		}
	}
	cout << ans << endl;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  string s;cin>>s;
  ll k;cin>>k;
  rep(i, s.size()){
    if(i==s.size()-1){
      cout<<(char)((s[s.size()-1]-'a' + k)%26 + 'a');
      break;
    }

    ll need = ('z'-s[i]+1)%26;
    if(need>k)need=0;

    cout<<(char)((s[i]+need-'a')%26+'a');
    k-=need;

  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef long long ll;

const int MAX = 100010;
const ll MOD = 1e9 + 7;

ll fact[MAX];
void compute_factorials() {
    fact[0] = 1;
    for (int i = 1; i < MAX; ++i) {
        fact[i] = fact[i - 1]*i;
        fact[i] %= MOD;
    }
}

ll myPower(ll a, ll b, ll mod = MOD) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1ll;
    }
    return res;
}

ll modInverse(ll a, ll mod = MOD) {
    return myPower(a, mod - 2, mod);
}

int main() {

    FAST_IO;

    int n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for (auto &i: a) {
        cin >> i;
    }

    ll res = 0;
    ll add = 0;
    ll subt = 0;

    compute_factorials();
    sort(a.begin(), a.end());

    ll div = fact[k - 1];
    for (int i = k - 1; i < n; ++i) {
        ll multiplier = fact[i];
        ll div2 = fact[i - (k - 1)];
        multiplier *= modInverse(div);
        multiplier %= MOD;
        multiplier *= modInverse(div2);
        multiplier %= MOD;
        add += (a[i] * multiplier) % MOD;
    }

    for (int i = 0; i < n - k + 1; ++i) {
        ll multiplier = fact[n - i - 1];
        ll div2 = fact[n - i - 1 - (k - 1)];
        multiplier *= modInverse(div);
        multiplier %= MOD;
        multiplier *= modInverse(div2);
        multiplier %= MOD;
        subt += (a[i] * multiplier) % MOD;
        // cout << subt << " ";
    }
    // cout << endl;
    res = (add - subt + MOD) % MOD;

    // cout << add << " " << subt << endl;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            
        	int range = in.nextInt();
        	
        	Random rand = new Random();
        	int number = rand.nextInt(range+1);
        	
        	if(range == 1)
        		System.out.println((double) 1);
        	else if(range %2 == 0)
        		System.out.println((double) 1/2);
        	else{
        		int num_odds = range/2 + 1;
        		System.out.println((double) num_odds/range);
        	}
        		
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 33524
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define int long long
signed main() {
	int h, w;
	cin >> h >> w;
	char C[h + 2][w + 2];
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			C[i][j] = 'Z';
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> C[i][j];
		}
	}
	for (int i = 1; i < h + 1; i++) {
		for (int j = 0; j < w + 1; j++) {
			if (C[i][j] == '#') {
				bool fl = false;
				for (int k = 0; k < 4; k++) {
					int nx = i + dx[k], ny = j + dy[k];
					if (C[nx][ny] == '#') {
						fl = true;
					}
				}
				if (!fl) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var A, B int 
    fmt.Scanln(&A, &B) 

    var ans int 
    if 6 <= A && A <= 12 {
        ans = B / 2 
    } else if 12 < A { 
        ans = B 
    }   
    fmt.Println(ans)
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int A = in.nextInt();
      final int B = in.nextInt();
      final int Q = in.nextInt();

      long[] s = new long[A+1];
      for (int i = 0; i < A; i++) {
        s[i] = in.nextLong();
      }
      s[A] = 1L << 40;

      long[] t = new long[B+1];
      for (int i = 0; i < B; i++) {
        t[i] = in.nextLong();
      }
      t[B] = 1L << 40;

      for (int q = 0; q < Q; q++) {
        long x = in.nextLong();
        long dist = 1L << 50;

        for (int c = 0; c < 2; c++) {
          long[] af = c == 0 ? s : t;
          long[] as = c == 0 ? t : s;

          for (int i = 0; i < 2; i++) {
            int posF = binarySearch(af, x) + i;
            long df = af[posF];

            for (int j = 0; j < 2; j++) {
              int posS = binarySearch(as, x) + j;
              long ds = as[posS];
              
              long d = Math.abs(x - df);
              d += Math.abs(df - ds);
              dist = Math.min(dist, d);
            }
          }
        }

        out.println(dist);
      }
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private int binarySearch(long[] arr, long x) {
    int left = 0;
    int right = arr.length;

    return loop(arr, x, left, right);
  }

  private int loop(long[] arr, long x, int left, int right) {
    if(right - left < 2) return left;
    else {
      int mid = (left + right) / 2;
      if(arr[mid] <= x) return loop(arr, x, mid, right);
      else return loop(arr, x, left, mid);
    }
  }

  static class InputReader implements AutoCloseable {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    @Override
    public void close() throws IOException {
      reader.close();
    }
  }
}

Measured memory_bytes: 47992
#include<stdio.h>
typedef struct{
	int lch,rch,par,ll,rl;
}N;
N node[100];
void swap(int& a,int& b){int p=a;a=b;b=p;}
int gcd(int a,int b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(b,a%b);
}
int dfs(int v){
	int lw=1,rw=1;
	N nd=node[v];
	if(nd.lch!=-1)lw=dfs(nd.lch);
	if(nd.rch!=-1)rw=dfs(nd.rch);
	int l=nd.ll;
	int r=nd.rl;
	int mom=r*rw;
	rw*=l/gcd(mom,l);
	mom=r*rw/l;
	int d=gcd(lw,mom);
	rw*=lw/d;
	lw*=mom/d;
	return rw+lw;
}
	
int main(){
	int n;
	int i,j;
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++){
		N nd={-1,-1,-1,-1,-1};
		node[i]=nd;
	}
	for(i=0;i<n;i++){
		int ll,rl,lch,rch;
		scanf("%d %d %d %d",&ll,&rl,&lch,&rch);
		if(lch!=0)node[lch-1].par=i;
		if(rch!=0)node[rch-1].par=i;
		node[i].lch=lch-1;
		node[i].rch=rch-1;
		node[i].ll=ll;
		node[i].rl=rl;
	}
	int p=0;
	while(node[p].par!=-1)p=node[p].par;
	printf("%d\n",dfs(p));
	}
}

Measured memory_bytes: 1028
from scipy.sparse.csgraph import *;from scipy.sparse import *;H,W,*S=open(0).read().split();H,W=int(H),int(W);m=H*W;A=[]
for i in range(m):
 h,w=divmod(i,W)
 if S[h][w]=='S':A=[m*2,h,m*2,w+m]+A
 elif S[h][w]=='T':A=[h,m*3,w+m,m*3]+A
 elif S[h][w]=='o':A+=[h,w+m,w+m,h]
f=maximum_flow(csr_matrix(([999]*4+[1]*(len(A)//2-4),(A[::2], A[1::2])),shape=(m*4,m*4)),m*2,m*3).flow_value;print(f if f<999 else -1)

Measured memory_bytes: 41008
if __name__ == "__main__":

    a,b,c,d = (int(x) for x in input().split())

    if b <= 0 :
        if d <= 0:
            xy = a * c
        elif d > 0:
            if c > 0:
                xy = b * c
            elif c == 0:
                xy = 0
            elif c < 0:
                xy = a * c
    elif b > 0:
        if a >= 0:
            if d <= 0:
                xy = a * d
            elif d > 0:
                xy = b * d
        elif a < 0:
            if d <= 0:
                xy = a * c
            elif d > 0:
                if c >= 0:
                    xy = b * d
                elif c < 0:
                    if abs(a * c) > abs(b * d):
                        xy = a * c
                    else:
                        xy = b * d

    print(xy)



Measured memory_bytes: 9144
//ΔAGC030F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 666;
const int M = 333;
const int MO = 1e9+7;
void ad(int&x,int y){
	x+=y;
	if(x>=MO)
		x-=MO;
}
int mul(int x,int y){
	return (LL)x*y%MO;
}
int n,m,w,a[N],e[N];
int f[N][M][M];
int main()
{
	int i,j,k,x;
	cin>>n;
	n=n+n;
	for(i=1;i<=n;i=i+1){
		cin>>a[i];
		if(a[i]>0)
			e[a[i]]=1;
	}
	for(i=1;i<=n;i=i+2){
		if((a[i]>0)^(a[i+1]>0))
			e[max(a[i],a[i+1])]=2,m++;
		if(a[i]<0&&a[i+1]<0)
			w++;
	}
	f[n][0][0]=1;
	for(i=n;i;i=i-1){
		for(j=0;j<=n/2;j=j+1){
			for(k=0;k<=n/2;k=k+1){
				if(!f[i][j][k])
					continue;
				//cout<<i<<j<<k<<f[i][j][k]<<endl;
				if(e[i]==1){
					ad(f[i-1][j][k],f[i][j][k]);
					continue;
				}
				if(e[i]==2){
					ad(f[i-1][j+1][k],f[i][j][k]);
					if(k)
						ad(f[i-1][j][k-1],f[i][j][k]);
					continue;
				}
				if(j)
					ad(f[i-1][j-1][k],mul(f[i][j][k],j));
				ad(f[i-1][j][k+1],f[i][j][k]);
				if(k)
					ad(f[i-1][j][k-1],f[i][j][k]);
			}
		}
	}
	x=f[0][0][0];
	for(i=1;i<=w;i=i+1)
		x=mul(x,i);
	cout<<x;
	return 0;
}

Measured memory_bytes: 260224
def solve(candidates):
    curr_time = 0
    candidates = sorted(candidates)
    while len(candidates) > 0:
        if curr_time % 10 != 0:
            curr_time += 10 - (curr_time % 10)
        losses = list(map(lambda c: calc_loss(curr_time, c), candidates))
        min_loss = losses[0]
        min_loss_candidate_idx = 0
        for i, loss in enumerate(losses):
            if loss <= min_loss:
                min_loss = loss
                min_loss_candidate_idx = i
        dish = candidates.pop(min_loss_candidate_idx)
        curr_time += dish
    return curr_time


def calc_loss(curr_time, candidate):
    return (10 - ((curr_time + candidate) % 10)) % 10


candidates = []
for _ in range(5):
    candidates.append(int(input()))

print(solve(candidates))

Measured memory_bytes: 3064