akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	xx := nextInt()
	x := nextInts(n)

	ans := absInt(xx - x[0])

	for i := 1; i < n; i++ {
		ans = gcd(ans, absInt(xx-x[i]))
		if ans == 1 {
			break
		}
	}

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

/* 最大公約数 */
func gcd(m, n int) int {
	if m < n {
		return gcd(n, m)
	}
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}


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

int main(){
  int n;
  cin >> n;
  
  map<string,int> mp;
  for(int i=0; i<n;i++){
    string s;
    cin >> s;
    mp[s]++;
  }
  
  int maxv=0;
  for(const auto& x : mp){
    int v=x.second;
    if(v>maxv) maxv = v;
  }
  for(auto it = mp.begin(); it != mp.end(); it++){
    if(it->second==maxv) cout << it->first << endl;
  }
  return 0;
}


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

int main() {
    int N; cin >> N;
    string res[] = { "AC", "WA", "TLE", "RE" };
    int ans[4] = {}; 
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        for (int j = 0; j < 4; j++) {
            if (s == res[j]) ans[j]++;
        }
    }

    for (int i = 0; i < 4; i++) {
        cout << res[i] << " x " << ans[i] << endl;
    }
}

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

class KMP():
	def __init__(self, sentence):
		self.sentence = sent = sentence
		self.l = l = len(sent)
		self.table = table = [0 for _ in range(l+1)]
		table[0] = -1
		j = -1
		for i in range(l):
			while j >= 0 and sent[i] != sent[j]:
				j = table[j]
			j += 1
			if i < l-1 and sent[i+1] == sent[j]:
				table[i+1] = table[j]
			else:
				table[i+1] = j

	def search(self, key):
		table = self.table
		sent = self.sentence
		l = self.l
		i = 0
		res = []
		for j in range(len(key)):
			while i > -1 and sent[i] != key[j]:
				i = table[i]
			i += 1
			if i >= l:
				res.append(j-i+1)
				i = table[i]
		return res


s = input()
s_concat = s
t = input()
ns, nt = len(s), len(t)

if ns == 1:
	if {s} == set(list(t)):
		print(-1)
	else:
		print(0)
	sys.exit()

while len(s_concat) < ns + nt - 1:
	s_concat += s

adj = [-1 for _ in range(ns)]

kmp = KMP(t)
matches = kmp.search(s_concat)

for i in matches:
	if i >= ns:
		break
	if i == (i+nt)%ns:
		print(-1)
		sys.exit()
	adj[i] = (i+nt)%ns


visited = [False for _ in range(ns)]
path_len = [0 for _ in range(ns)]

def dfs(x):
	cur = x
	res = 0
	while adj[cur] >= 0:
		visited[cur] = True
		if adj[cur] == x:
			print(-1)
			sys.exit()
		res += 1
		if path_len[adj[cur]] > 0:
			path_len[x] = path_len[adj[cur]] + res
			return path_len[adj[cur]] + res
		cur = adj[cur]
	path_len[x] = res
	return res

ans = 0
for i in range(ns):
	if not visited[i]:
		d = dfs(i)
		ans = max(ans, d)

if ans == ns:
	print(-1)
else:
	print(ans)

Measured memory_bytes: 56848
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>

#define ALL(v) (v).begin(), (v).end()

using namespace std;

int main()
{
  int N;
  cin >> N;
  if (N <= 999)
  {
    cout << "ABC" << endl;
  }
  else
  {
    cout << "ABD" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
rds = [[0]]*m
for i in range(m):
  rds[i] = list(map(int,input().split()))
rdct = [0]*n
for i in range(m):
  rdct[rds[i][0]-1] += 1
  rdct[rds[i][1]-1] += 1
for i in range(n):
  print(rdct[i])

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    set<int> ds;
    for (int i = 0; i < n; ++i)
    {
        cin >> d[i];
        ds.insert(d[i]);
    }
    cout << ds.size() << endl;
    return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (N, K) = {
    let v = read_vec();
    (v[0], v[1])
  };

  let mut v: Vec<(i64, i64)> = Vec::new();
  for _ in 0..N {
    let a = read_vec();
    v.push((a[0], a[1]));
  }
  let mut ans: u64 = std::u64::MAX;
  for &(_, up) in &v {
    for &(_, down) in &v {
      for &(left, _) in &v {
        for &(right, _) in &v {
          let mut tmp = 0;
          for &(i, j) in &v {
            count(i, j, left, right, up, down, &mut tmp);
          }
          if tmp == K {
            ans = min(ans, (left - right).abs() as u64 * (down - up).abs() as u64);
          }
        }
      }
    }
  }
  println!("{}", ans);
}

fn count(i: i64, j: i64, side1: i64, side2: i64, top1: i64, top2: i64, count: &mut u64) {
  let left = min(side1, side2);
  let right = max(side1, side2);
  let down = min(top1, top2);
  let top = max(top1, top2);

  if left <= i && i <= right && down <= j && j <= top {
    *count += 1;
  }

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define debug(x)  cout<<#x<<" " <<x<<endl;
#define dbg(x,y)  cout<<#x<<" " <<x<<" "<<#y<<" "<<y<<endl;
#define all(v) v.begin(),v.end()
#define si(x) x.size()

const int e = 100005;
const ll INF = 1e18+5;
template<typename T>void show2(T& dp)
{
    for( auto row:dp)
    {
        for(auto col:row)
            cout<<col<<" ";
        cout<<endl;
    }
}
template<typename T>void show1(T &a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<endl;
}
void solve()
{
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k);
}
int main() {
	// your code goes here
	io;
	int t ;
	
    solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    ll m, f, r;
    ll scores[60][3] = {0};

    ll i(0);
    while (cin >> m >> f >> r)
    {
        scores[i][0] = m;    
        scores[i][1] = f;    
        scores[i][2] = r;    
        i++;

        if (m == -1 && f == -1 && r == -1)
            break;
    }

    const ll n(i);
    char result;
    for (ll j=0; j<n; j++)
    {
        m = scores[j][0];
        f = scores[j][1];
        r = scores[j][2];

        if (m == -1 && f == -1 && r == -1)
            break;

        //cout << m << ' ' << f  << ' ' << r << endl;

        if (m == -1 || f == -1 || m+f < 30)
            result = 'F';
        else if (m + f >= 80)
            result = 'A';
        else if (m + f >= 65 && m + f < 80)
            result = 'B';
        else if (m + f >= 50 && m + f < 65)
            result = 'C';
        else if (m + f >= 30 && m + f < 50)
        {
            if (r >= 50)
                result = 'C';
            else
                result = 'D';
        }
    
        cout << result << endl;
    }


    return 0;
}



Measured memory_bytes: 3080
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	var grid [3][3]int

	for i := 0; i < 3; i++ {
		for ii := 0; ii < 3; ii++ {
			grid[i][ii] = getNextInt(scanner)
		}
	}

	ans := "No"
	if valid(grid) {
		ans = "Yes"
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func valid(grid [3][3]int) bool {
	for y := 1; y < 3; y++ {
		im := IntMap{}
		for x := 0; x < 3; x++ {
			im.increment(grid[y][x] - grid[y-1][x])
		}
		if len(im) != 1 {
			return false
		}
	}
	for x := 1; x < 3; x++ {
		im := IntMap{}
		for y := 0; y < 3; y++ {
			im.increment(grid[y][x] - grid[y][x-1])
		}
		if len(im) != 1 {
			return false
		}
	}

	return true
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(void){
  int i,j,k,n,s;
  char ca[201],can[201];

  while(1){
    scanf("%s\n%d", ca, &n);
    if(!strcmp(ca, "-")) break;
   
    for(i=0;i<n;i++){
      scanf("%d", &s);
      for(j=s;ca[j]!='\0';j++)
        can[j-s] = ca[j];
      for(k=0;k<s;k++)
        can[j-s+k] = ca[k];
     
      for(j=0;ca[j]!='\0';j++)
        ca[j] = can[j];
    }

    printf("%s\n", ca);
  }

  return 0;
}


Measured memory_bytes: 2040
#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 long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
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;
}

int ctoi(const char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return -1;
    }
}

signed main()
{
    string N;
    cin >> N;
    int ans = 0;
    bool flg = false;
    REP(i, N.size())
    {
        if (i == 0)
            ans += ctoi(N[i]);
        else
            ans += 9;
        if (!flg and i > 0 and N[i] != '9')
        {
            flg = true;
            ans--;
        }
    }
    cout << ans << endl;
    //system("pause");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD=1000000007;
clock_t time_ini = clock();
double time_diff(){
  ll time_tmp = clock();
  const double time = static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
  return time;
}
#define saiaku if(time_diff() > 1990)

vector<vector<ld>> dp(100, vector<ld>(100));

void solve_old(long long N, std::vector<long long> a){
    dp[0][0] = 1;
    ll tryn = 10;
    for (ll i = 1; i <= tryn; i++) {
        for (ll j = 1; j <= N; j++) {
            dp[i][j] = dp[i-1][j-1] * (N-j+1)/(ld)N + dp[i-1][j] * (j/(ld)N);
        }
    }
    for (ll i = 0; i <= tryn; i++) {
        for (ll j = 0; j <= N; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

// vector<vector<vector<ld>>> dpE(300, 300, vector<ld>(300));
double dpE[310][310][310]; // dynamic planning table for expected value
ll num[4]={0};
void solve(long long N, std::vector<long long> a){
  for (ll i = 0; i < N; i++) {
      num[a[i]]++;
  }

  // for (ll i = 0; i < 4; i++) {
  //     cout << num[i] << " ";
  // }
  // cout << endl;
  // cout << endl;

  for (int k = 0; k <= N; k++) {
    for (int j = 0; j + k <= N; j++) {
      for (int i = 0; i + j + k <= N; i++) {
        if (i + j + k == 0) continue;

        double e1 = 0.0, e2 = 0.0, e3 = 0.0;
        if (i) e1 = dpE[i - 1][j][k] * (1.0 * i / N);
        if (j) e2 = dpE[i + 1][j - 1][k] * (1.0 * j / N);
        if (k) e3 = dpE[i][j + 1][k - 1] * (1.0 * k / N);

        dpE[i][j][k] = 1.0 * N / (i + j + k) * (e1 + e2 + e3 + 1);
          }
      }
  }
  sp(dpE[num[1]][num[2]][num[3]]);
  // std::cout << dpE[num[1]][num[2]][num[3]] << std::endl;
  // cout<<endl;

  // for (ll i = 0; i <= N; i++) {
  //     for (ll j = 0; j <= N; j++) {
  //         for (ll k = 0; k <= N; k++) {
  //           cout << dpE[i][j][k] << " ";
  //         }
  //     cout << endl;
  //     }
  //     cout << endl;
  // }

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 225664
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0); 
int ans;
string s;
int ns;
int r,w;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> ns >> s;

    rep1(i,0,ns){
        if(s[i] == 'R') r++;
        else w++;
    } 

    rep1(i,0,r)
        if(s[i] == 'W') 
                ans++;
    cout << ans;
	return 0;
}


Measured memory_bytes: 3784
/**
*    created: 25.07.2020 04:21:19
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    int r = a[n-1];
    int l;
    int dif = INF;
    rep(i,n) {
        if (abs(r/2-a[i]) < dif) {
            dif = abs(r/2-a[i]);
            l = a[i];
        }
        if (r % 2 == 0) continue;
        else if (abs(r/2+1-a[i]) < dif) {
            dif = abs(r/2+1-a[i]);
            l = a[i];
        }
    }
    cout << r;
    cout << " ";
    cout << l;
    cout << endl;
    return 0;
}

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

namespace kaibun_4_28
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            //文字列の取得
            List<string> charalist = new List<string>();
            for (int i = 0; i < n; i++)
            {
                charalist.Insert(i, Console.ReadLine());
            }
            
           
            //文字のカウント
            string kaitou = "";
            int[] charanumber = new int[n];
            for (int k = 0; k < charalist[0].Length; k++)
            {
                if (CountChar(charalist[0].Substring(k + 1, charalist[0].Length-k-1), charalist[0][k]) == 0)
                {
                    for (int j = 0; j < n; j++)
                    {
                        charanumber[j] = CountChar(charalist[j], charalist[0][k]);
                    }

                    for (int i = 0; i < Min(charanumber); i++)
                    {
                        kaitou = kaitou + charalist[0][k];
                    }
                }
            }



                string[] kaitouchara = new string[kaitou.Length];
                for (int i = 0; i < kaitou.Length; i++)
                {
                    kaitouchara[i] = kaitou.Substring(i, 1);
                }

                Array.Sort(kaitouchara);
                foreach (string val in kaitouchara)
                {
                    Console.Write("{0}", val);
                }

           


        }
         


        public static int CountChar(string s, char c)
            {
                return s.Length - s.Replace(c.ToString(), "").Length;
            }

        public static int Min(params int[] nums)
        {
            if (nums.Length == 0) return 0;
            int min = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                min = min < nums[i] ? min : nums[i];
            }
            return min;
        }

    }

    

} 


Measured memory_bytes: 13408
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

T = 0
for a in A:
    T ^= a

ANS = []
for a in A:
    ANS.append(T ^ a)

print(" ".join(map(str, ANS)))



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

int main()
{
    int H,W;

    while(1){
        cin>>H>>W;

        if(H==0&&W==0)break;

        for(int i=1;i<=H;i++){
            for(int i=1;i<=W;i++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;

    }

    return 0;
}


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

vector<vector<int> > e;
vector<int> gr;

void dfs(int i,int p)
{
  gr[i]=0;
  for(int x=0;x<e[i].size();x++){
    int j=e[i][x];
    if(j==p)continue;
    dfs(j,i);
    gr[i]^=gr[j]+1;
  }
}

int main()
{
  int n;
  scanf("%d",&n);
  e=vector<vector<int> >(n);
  for(int t=0;t<n-1;t++){
    int x,y;
    scanf("%d%d",&x,&y);
    x--,y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  gr=vector<int>(n);
  dfs(0,-1);
  puts(gr[0]?"Alice":"Bob");
  return 0;
}


Measured memory_bytes: 12416
def main():
    A, B, C, D = map(int, input().split())

    def lcm(v1, v2):
        v3 = v1 % v2
        if v3 == 0:
            return v2
        return lcm(v2, v3)

    def gcd(v1, v2):
        return v1 * v2 // lcm(v1, v2)

    count = B - (A - 1)

    c = B // C - (A - 1) // C
    d = B // D - (A - 1) // D

    CD = gcd(C, D)
    cd = B // CD - (A - 1) // CD

    print(count - c - d + cd)


main()


Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
char a[5];
int main()
{
	int i,j;
	scanf("%s",a);
	for(i=0;i<=3;i++)
	{
	    if(a[i]==a[i+1])
	    {
	        printf("Bad");
	        return 0;
		}
	}
	printf("Good");
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int x = reader.nextInt();
		int a = reader.nextInt();
		int b = reader.nextInt();
		int xa = Math.abs(a-x);
		int xb = Math.abs(b-x);
		String ans = "A";
		if (xa > xb) {
			ans = "B";
		}
		System.out.println(ans);


		reader.close();
	}


}





Measured memory_bytes: 22996
from collections import defaultdict
N,W=map(int,raw_input().split())

a=defaultdict(lambda:[])
for i in range(N):
	w,v=map(int,raw_input().split())
	a[w]=a[w]+[v]

for i,j in a.items():
	a[i]=sorted(j,reverse=True)



lst=[]
for i,j in a.items():
	lst.append( (i,len(j)) )

max_val=0
if len(lst)==1:
	w1=lst[0][0]
	c1=lst[0][1]
	for i in range(c1+1):
		if i*w1<=W:
			max_val=max(max_val, sum(a[w1][:i]))

elif len(lst)==2:
	w1=lst[0][0]; w2=lst[1][0]
	c1=lst[0][1]; c2=lst[1][1]
	for i in range(c1+1):
		for j in range(c2+1):
				if i*w1+j*w2<=W:
					max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j]))

elif len(lst)==3:
	w1=lst[0][0]; w2=lst[1][0]; w3=lst[2][0]
	c1=lst[0][1]; c2=lst[1][1]; c3=lst[2][1]
	for i in range(c1+1):
		for j in range(c2+1):
			for k in range(c3+1):
				if i*w1+j*w2+k*w3<=W:
					max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j])+sum(a[w3][:k]))

elif len(lst)==4:
	w1=lst[0][0]; w2=lst[1][0]; w3=lst[2][0]; w4=lst[3][0]
	c1=lst[0][1]; c2=lst[1][1]; c3=lst[2][1]; c4=lst[3][1]
	for i in range(c1+1):
		for j in range(c2+1):
			for k in range(c3+1):
				for m in range(c4+1):
					if i*w1+j*w2+k*w3+m*w4<=W:
						max_val=max(max_val, sum(a[w1][:i])+sum(a[w2][:j])+sum(a[w3][:k])+sum(a[w4][:m]))

print max_val



Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<vector<int>> plan(N, vector<int>(3));
	for (int i = 0; i < N; i++) cin >> plan[i][0] >> plan[i][1] >> plan[i][2];

	vector<vector<int>> dp(N, vector<int>(3));
	dp[0] = plan[0];
	for (int i = 1; i < N; i++) {

		for (int j = 0; j < 3; j++) {

			dp[i][j] = max(dp[i - 1][(j + 1) % 3] + plan[i][j], dp[i - 1][(j + 2) % 3] + plan[i][j]);
		}

	}

	cout << max({ dp[N - 1][0], dp[N - 1][1], dp[N - 1][2] });

	return 0;
}

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

int main()
{
	int n, l[16]{};
	scanf("%d", &n);
	for (int i{}; i < n; i++)
		scanf("%d", l + i);
	std::sort(l, l + n);
	int sum{};
	for (int i{}; i < n - 1; i++)
		sum += l[i];
	if (l[n - 1] < sum)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,pair<int,int>> P;

class Edge
{
	public:
	int cost;
	int from;
	int to;

	Edge(int n,int c)
	{
		to=n;
		cost=c;
	}

	Edge(int f,int t,int c)
	{
		from=f;
		to=t;
		cost=c;
	}
};

vector<Edge> g[100000];

ll dp[100000][3];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(Edge(v,1));
	}
	int s,t;
	cin>>s>>t;
	s--;t--;
	fill(dp[0],dp[100000],1e8-1);
	dp[s][0]=0;
	priority_queue<P,vector<P>,greater<P>> q;
	q.push(P(dp[s][0],make_pair(s,0)));
	while(!q.empty())
	{
		P p=q.top();q.pop();
		if(p.first>dp[p.second.first][p.second.second])
			continue;
		for(int i=0;i<g[p.second.first].size();i++)
		{
			Edge e=g[p.second.first][i];
			int tmp=p.second.second+1;
				if(tmp==3)
					tmp=0;
			if(e.cost+dp[p.second.first][p.second.second]<dp[e.to][tmp])
			{
				dp[e.to][tmp]=e.cost+dp[p.second.first][p.second.second];
				q.push(P(dp[e.to][tmp],make_pair(e.to,tmp)));
			}
		}
	}
	if(dp[t][0]==1e8-1)
		cout<<-1<<endl;
	else
		cout<<dp[t][0]/3<<endl;
	return 0;
}

Measured memory_bytes: 8632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_A&lang=jp

#define NMAX 2000005
#define VMAX 10005

int main() {
    int n; cin >> n;
    int A[n];
    int C[VMAX]; REP(i, VMAX) C[i] = 0;
    REP(i, n) {
        cin >> A[i];
        C[A[i]]++;
    }

    REP(i, VMAX) {
        if (i) C[i] += C[i-1];
    }

    int B[n];
    REP(i, n) {
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }

    arrdump(n, B);


    return 0;
}


Measured memory_bytes: 18780
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<pair<int,int>> vpii;
typedef pair<int,int> pr;

int main(){
    int i,res=0;
    string s,t;
    cin >> s >> t;
    forN(i,3){
        if(s[i]==t[i]) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 760
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll in[200050];
int main() {
	ll N, i;
	scanf("%lld", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &in[i]);
	for (i = 1; i <= N; i++) in[i] -= i;

	sort(in + 1, in + N + 1);
	ll ans = 0;
	for (i = 1; i <= N; i++) ans += abs(in[i] - in[(N + 1) / 2]);
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		String ans = Integer.toString(x-k+1);
		if(k>1){
		for(int i=x-k+2;i<x+k;i++){
			ans += " " + Integer.toString(i);
		}
		}
        System.out.println(ans);
	}
}

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll  a,b,c,s,t,i,j,k,x,y,z;
 ll A,B,C,S,T,X,Y,Z;
 ll count;
signed main(){
	string N;
	cin>>N;

	if(N[1]=='B') cout<<"ARC";
	else cout<<"ABC";

	
 return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a;
    cin>>a;
    ll x=a,y=a;
    rep(i,1,sqrt(a)){
        if(a%i==0){
            // cout<<x+y<<endl;
            // cout<<a/i+i<<endl;
            // cout<<i+a/i<<endl;
            if((i+a/i)<(x+y)){
                x=i;
                y=a/i;
            }
        }
    }
    cout<<x+y-2;
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

ll gcd(ll a, ll b){
	if(a<b) swap(a, b);
	if(b==0) return a;
	else return gcd(b, a%b);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	ll ans=a[0];
	for(int i=1; i<n; i++) ans=gcd(ans, a[i]);
	cout << ans << endl;
	return 0;
}

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

//vector<vector<int>> flag(210, vector<int>(210, -1));
//---------- 最大公約数 ----------
Int gcd(Int a, Int b){
    if (b > a) return gcd(b, a);

    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

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

    Int ans = 0;
    rep1(a,K) rep1(b,K) rep1(c,K){
        ans += gcd(gcd(a,b), c);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3680
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

a,b,c,x,y = map(int,input().split())
"""
AとBのみ
"""
cost = x*a + y*b
"""
ABと個数あわせ
"""
cost2 = c*2*min(x,y)
if x>y:
    cost2 += (x-y)*a
else:
    cost2 += (y-x)*b
"""
ABのみ
"""
cost3 = c*2*max(x,y)
ans = min(cost,cost2)
ans = min(ans,cost3)
print(ans)


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

typedef long long ll;

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

	ll t=1;
	//cin >> t;

	for(ll i=1;i<=t;i++){
		string s;
		cin >> s;

		if(s=="RRR")
			cout << 3 << "\n";
		else if(s=="RRS" || s=="SRR")
			cout << 2 << "\n";
		else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR")
			cout << 1 << "\n";
		else
			cout << 0 << "\n";  
	}
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N,M;
    int tar[1000]={0},pt[1000]={0};
    cin>>N>>M;
    for(int i=0;i<M;i++)cin>>tar[i];
    for(int i=0;i<M;i++){
        for(int j=1;j<=N;j++){
            int kari;
            cin>>kari;
            if(kari==tar[i])pt[j]++;
            else pt[tar[i]]++;
        }
    }
    for(int i=1;i<=N;i++)cout<<pt[i]<<endl;
    return 0;
}

Measured memory_bytes: 1168
#define DEBUG 1
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
#define pb push_back
#define all(v) v.begin(), v.end()
#define for1(i, n) for (ll i = 0; i < (n); i++)
#define for2(i, m, n) for (ll i = (m); i < (n); i++)
#define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d))
#define INF (1LL << 60)
#if DEBUG
#define dump(v1) dump_1(#v1, v1)
#define dump2(v1, v2) dump_2(#v1, v1, #v2, v2)
#define dump3(v1, v2, v3) dump_3(#v1, v1, #v2, v2, #v3, v3)
#else
#define dump(v1)
#define dump2(v1, v2)
#define dump3(v1, v2, v3)
#endif
#if DEBUG
template <typename T> void dump_1(const string &n1, const T &v1)
{
    cerr << n1 << ": " << v1 << endl;
}
template <typename T1, typename T2>
void dump_2(const string &n1, const T1 &v1, const string &n2, const T2 &v2)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << endl;
}
template <typename T1, typename T2, typename T3>
void dump_3(const string &n1, const T1 &v1, const string &n2, const T2 &v2,
            const string &n3, const T3 &v3)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << "  " << n3 << ": "
         << v3 << endl;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v)
{
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v)
{
    os << "(" << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << " ";
        }
        os << *it;
    }
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v)
{
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << " ";
        }
        os << *it;
    }
    return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << it->first << ":" << it->second;
    }
    os << "}";
    return os;
}
#endif // DEBUG
void Yes(void) { cout << "Yes" << endl; }
void No(void) { cout << "No" << endl; }
void YES(void) { cout << "YES" << endl; }
void NO(void) { cout << "NO" << endl; }
template <typename T> void print(const T &v) { cout << v << endl; }
//---------------------------------------------------------
void solve()
{
    ll ans = 0;
    ll a, b;
    cin >> a >> b;
    print(max({a + b, a - b, a * b}));
}

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


Measured memory_bytes: 256
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  double P = 3.141592653;
  int n;cin>>n;
  cout << fixed << setprecision(10) << n*2*P << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
struct shop{int a,b;};
bool comp(const shop &s1,const shop &s2){
    return s1.a*(s2.b+1)>s2.a*(s1.b+1);
}
int n,t;
vector<shop>s;
vector<int>v={0};
int dp[200010][40];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>t;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if(a>0){
            s.pb({a,b});
        }
        else{
            v.pb(b+1);
        }
    }
    sort(all(s),comp);
    sort(all(v));
    for(int i=1;i<v.size();i++)v[i]+=v[i-1];
    rep(i,s.size()+1)rep(j,40)dp[i][j]=t+1;
    dp[0][0]=0;
    int ans=0;
    rep(i,s.size()){
        rep(j,39){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][j+1],(s[i].a+1)*(dp[i][j]+1)+s[i].b);
        }
    }
    rep(i,40){
        if(t<dp[s.size()][i])continue;
        chmax(ans,i+(upper_bound(all(v),t-dp[s.size()][i])-v.begin()-1));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 68852
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vi p(n);
  rep(i, n) cin >> p[i];
  sort(all(p));
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+21);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e18+4);

void max_self(int &a, int b){
    a= max(a,b);
}

void min_self(ll &a, ll b){
    a=min(a,b);
}


ll run() {
    int n,m;
    cin>>n>>m;
    vector<int> adj[n+1];
    vector<int> dp(n+1,0);
    vector<int> vis(n+1,0);
    vector<int> in(n+1,0);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].emplace_back(y);
        in[y]++;
    }

    queue<int> q;
    for(int i=1;i<=n;i++){
        if(!in[i]){
            q.push(i);
        }
    }
    while(!q.empty()){
        int u = q.front();
        q.pop();

        for(int v:adj[u]){
            max_self(dp[v],dp[u]+1);
            in[v]--;
            if(!in[v])
                q.push(v);
        }
    }

    int ans =0 ;
    for(int i=1;i<=n;i++){
        max_self(ans,dp[i]);
    }
    cout<<ans;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	map<ll,ll> mp;
	ll he = 0;
	FOR(i,0,n)
	{
		ll a;
		cin>>a;
		he+=a;
		mp[a]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll a,b;
		cin>>a>>b;
		ll now = mp[a];
		ll h = now*(b-a);
		he+=h;
		cout<<he<<endl;
		mp[b] += mp[a];
		mp[a] = 0;
	}
	return 0;
}


Measured memory_bytes: 9444
/*C - Exception Handling*/

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int tam;
	int maximo;
	int antMax;

	cin >> tam;

	vector <int> arr(tam);

	for (int i = 0; i < tam; ++i){
		cin >> arr[i];
		if (i == 0){
			maximo = arr[i];
		}
		else if( i == 1){
			antMax = arr[i];

			if(antMax > maximo){
				swap(antMax, maximo);
			}
		}
		else{
			if(arr[i] > antMax){
				antMax = arr[i];

				if(antMax > maximo){
					swap(antMax, maximo);
				}
			}
		}
	}

	for (int i = 0; i < tam; ++i)
	{
		if(arr[i] == maximo){
			cout << antMax << '\n';
		}
		else{
			cout << maximo << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 2432
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

num_v = input()
num_h = input()
lis = range(num_v+1)
for s in sys.stdin:
  d = map(int , s.split(",") )
  lis[d[0]], lis[d[1]] = lis[d[1]], lis[d[0]]
for e in lis[1:]:
  print e

Measured memory_bytes: 4204
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	ll ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; ++j) {
			auto ite = lower_bound(all(a), a[i] + a[j]);
			int dist = distance(ite, a.end());
			ans += n - j - 1 - dist;
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256