akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
//using System.Numerics;
using static System.Math;
using static System.Console;
namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var n = ri;
			if (n == 1) Console.WriteLine("Hello World");
			else {
				var a = ri;
				var b = ri;
				Console.WriteLine(a + b);
			}
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < n; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion


Measured memory_bytes: 13136
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>

using namespace std;

int main() {
	string s;
	cin>>s;
	int cnt=0;
	int l=s.size();
	for(int i=0; i<l; i++){
		if(i%2==0){
			if(s.at(i)=='0') cnt++;
		}
		else{
			if(s.at(i)=='1') cnt++;
		}
	} 
	cout<<min(cnt,l-cnt)<<endl;
}



Measured memory_bytes: 512
import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = [int(input()) for _ in range(n)]
    cnt = Counter(a)
    maximum = max(a)
    if cnt[maximum] > 1:
        print("\n".join([str(maximum)] * n))
    else:
        second = sorted(a, reverse=True)[1]
        for i in range(n):
            if a[i] != maximum:
                print(maximum)
            else:
                print(second)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25036
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	ll n,ans=0;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ans=arr[0];
	for(int i=1;i<n;i++)
	{
		ans=(arr[i])*(ans/gcd(arr[i],ans));
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int k;
    while(1){
        cin >> k;
        if(k==0) break;
        int sum=0;

        rep(i,k*(k-1)/2){
            int tmp;
            cin >> tmp;
            sum+=tmp;
        }
        // cout << sum << ":sum" << endl;
        cout << sum/(k-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
int n,a[maxn];
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
bool solve(){
	int id,g,cnt[2]={0,0};
	for(int i=1;i<=n;i++){
	    if(a[i]&1){id=i;cnt[1]++;}
	    else{cnt[0]++;}
	}
	if(cnt[0]%2==1){return true;}
	if(cnt[0]%2==0){
		if(cnt[1]!=1){return false;}
		if(a[id]==1){return false;}
		a[id]--;g=a[1];
		for(int i=2;i<=n;i++){g=gcd(a[i],g);}
		for(int i=1;i<=n;i++){a[i]/=g;}
		return !solve();
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);}
	if(solve()){printf("First\n");}
	else{printf("Second\n");}
	return 0;
}

Measured memory_bytes: 640
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
int n, m;
int e[10][10];
void solve() {
    cin >> n >> m;
    vector<int> v;
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        e[x][y] = e[y][x] = 1;
    }
    for (int i = 2; i <= n; i++) {
        v.pb(i);
    }
    int res = 0;
    do {
        bool f = 0;
        if(e[1][v[0] ]) {
            f = 1;
            for (int i = 1; i < v.size(); i++) {
                if(!e[v[i - 1] ][v[i] ]) {
                    f = 0; break;
                }
            }
        }
        if(f) res++;
    } while(next_permutation(v.begin(), v.end()));
    cout << res << endl;
}
int main() {
  //  freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
M=10**9+7
H,W,A,B = map(int,input().split())
C = 1
ans = 1

for I in range(H-1):
  ans = C = C*(W+H-B-2-I)*pow(I+1,M-2,M)%M

for I in range(1,H-A):
  C = C*(B-1+I)*(H-I)*pow(I*(W+H-B-1-I),M-2,M)%M
  ans+=C

print(ans%M)

Measured memory_bytes: 9208
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun minCost(D: Array<IntPair>, N: Int): Int {
    val M = D.size

    val dp = Array(M+1){IntArray(0b01 shl N){INF}}
    // dp[i][s] := [0,i) のカギで開放状態 s を作るための最小コスト
    dp[0][0] = 0
    for (i in 1 .. M) {
        dp[i][0] = 0
    }

    for (i in 1 .. M) {
        val ds = D[i-1].first
        val cost = D[i-1].second
        for (s in 0 until (0b01 shl N)) {
            dp[i][s] = min(dp[i][s], dp[i-1][s])

            dp[i][s or ds] = min(dp[i][s or ds], dp[i-1][s] + cost)
        }
    }

    val ans = dp[M][(0b01 shl N) - 1]
    return if (ans >= INF) -1 else ans
}

fun solve() {
    val (N, M) = rd.readIntArray()
    val A = IntArray(M); val B = IntArray(M)
    val C = Array(M){ArrayList<Int>()}
    for (i in 0 until M) {
        val (a, b) = rd.readIntArray()
        A[i] = a; B[i] = b
        C[i].addAll(rd.readIntArray().toList())
    }

    val D = Array(M){IntPair(0, INF)}
    for (i in 0 until M) {
        var s = 0
        for (c in C[i]) {
            s = s or (0b01 shl (c-1))
        }
        D[i] = IntPair(s, A[i])
    }

    val ans = minCost(D, N)

    print(ans)
}


//val rd = debug.Reader("abc", "142", "e", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 65688
N = int(input())
H = [int(i) for i in input().split()][::-1]
F = True

for i in range(N-1):
  if H[i+1] == H[i] + 1:
    H[i+1] -= 1
  elif H[i+1] > H[i] + 1:
      F = False

if F:
  print("Yes")
else:
  print("No")

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<int>());
    auto comPair = [](const P &firstElof, const P &secondElof) {
        int m1 = min(firstElof.first, firstElof.second);
        int m2 = min(secondElof.first, secondElof.second);
        return m1 < m2;
    };
    priority_queue<P, vector<P>, decltype(comPair)> que(comPair);

    ll ans = a[0];
    que.emplace(a[0], a[1]);
    que.emplace(a[0], a[1]);
    repeat(i, 2, n) {
        auto p = que.top();
        que.pop();

        ans += min(p.first, p.second);

        que.emplace(p.first, a[i]);
        que.emplace(p.second, a[i]);
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 6108
#include <stdio.h>
#include <stdlib.h>
int main() {
	int r, c;
	int s;
	scanf("%d%d", &r, &c);
	int** a = (int**)malloc(sizeof(int*) * (r + 1));
	for (int i = 0; i < r + 1; i++) {
		a[i] = (int*)malloc(sizeof(int) * (c + 1));

	}
	for (int i = 0; i < r; i++) {
		a[i][c] = 0;
		for (int j = 0; j < c; j++) {
			scanf("%d", &a[i][j]);
			a[i][c] = a[i][c] + a[i][j];
		}

	}

	for (int i = 0; i < c + 1; i++) {
		s = 0;
		for (int j = 0; j < r; j++) {
			s = s + a[j][i];
		}
		a[r][i] = s;
	}


	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			if (j == c) {
				printf("%d\n", a[i][j]);
			}
			else {
				printf("%d ", a[i][j]);
			}			
		}
	}



}




Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    int n,k,t;
    cin>>n>>k>>t;
    int a=(n+k-1)/k;
    cout<<a*t<<endl;

}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define A 10
#define B 6
#define C 5

struct node {
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};

struct node *root;
struct node *NIL;

void insert (int);
void inorder(struct node *);
void preorder(struct node *);

int main(){

  int n,i,x;
  char *com,*comI="insert",*comP="print";
  
  com = (char*)malloc(A*sizeof(char));  
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s", com);
  
    if(strncmp(com,comI,B)==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strncmp(com,comP,C)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){

  struct node *y = NIL;
  struct node *x = root;
  struct node *z;

  z = (struct node *)malloc(sizeof(struct node));

  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x-> key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y -> right = z;
  }
}

void inorder(struct node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}




Measured memory_bytes: 25164
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var digits = input[0].split('');

    var sum = 0;
    for (var i = 0; i < digits.length; i++) {
        sum += parseInt(digits[i], 10);
    }

    if (n % sum === 0) {
        console.log('Yes');
    }
    else {
        console.log('No');
    }

    return 0;
}


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

int main() {
    int n;
    string s;
    while (cin >> n, n) {
        int cnt = 0;
        int l = 0, r = 0;
        int nl = 1, nr = 1;
        for (int i=0; i<n; ++i) {
            cin >> s;
            if (s == "lu") {
                l = 1;
            } else if (s == "ru") {
                r = 1;
            } else if (s == "ld") {
                l = 0;
            } else if (s == "rd") {
                r = 0;
            }
            if (l == nl && r == nr) {
                cnt ++;
                nl = 1 - l, nr = 1 - r;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))


n = int(input())
l = lmp()
l.sort()
from collections import Counter
lc = list(Counter(l).items())
if len(lc) <= 2:
    print(0)
    exit()
cnt = 0
for i in range(len(lc)-2):
    for j in range(i+1,len(lc)-1):
        for k in range(j+1,len(lc)):
            if lc[i][0] + lc[j][0] > lc[k][0]:
                cnt += lc[i][1] * lc[j][1] * lc[k][1]
print(cnt)








Measured memory_bytes: 68516
#include <iostream>
#include <string>
using namespace std;
string S;

int main(){
	cin >> S;
	int count = 0,k = 0;
	for(int i=1;i<S.size();i++){
		if(S[0]==S[i]){
			count += k-1;
			k = 0;
		}else if(i!=S.size()-1) k++;
		else{
			count += k;
		}
	}
	if(count%2==0) cout << "Second" << endl;
	else cout << "First" << endl;
}

Measured memory_bytes: 512
def selectionSort(arr):
	icnt = 0
	for i in range(0, len(arr)):
		imin = i
		for j in range(i + 1, len(arr)):
			if arr[j][1] < arr[imin][1]:
				#			if arr[j] < arr[imin]:
				imin = j
		if imin != i:
			arr[i], arr[imin] = arr[imin], arr[i]
			icnt = icnt + 1


def bubbleSort(arr):
	flg = True
	cnt = 0
	while flg:
		flg = False
		for i in range(len(arr) - 1, 0, -1):
			if arr[i][1] < arr[i - 1][1]:
				#			if arr[i] < arr[i - 1]:
				arr[i - 1], arr[i] = arr[i], arr[i - 1]
				cnt = cnt + 1
				flg = True

def combine(arr):
	result = ''
	for i in arr:
		result = result + i[0] + str(i[1]) + ' '
	return result.rstrip(' ')

n = int(input())
a = list(input().split())  # [H4, C9, S4, D2, C3]
# a = list(map(int, input().split()))
b = []  # [[H,4], [C,9], [S,4], [D,2], [C,3]]
for i in range(0, len(a)):
	b.append([a[i][0], int(a[i][1])])
c = b.copy()
# c = b

bubbleSort(b)
result_b = combine(b)

selectionSort(c)
result_s = combine(c)

print(result_b)
print('Stable')

print(result_s)
if result_s == result_b:
	print('Stable')
else:
	print('Not stable')




Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)

ll XOR(ll n){
    if(n % 4 == 0) return n;
    if(n % 4 == 1) return 1;
    if(n % 4 == 2) return n + 1;
    else return 0;
}

int main(){
    ll A, B; cin >> A >> B;
    ll ans = XOR(A - 1) ^ XOR(B);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
const int N = 110;
int n, a[N], mx = 0, cnt[N];
int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a + i);
	rep(i,1,n) mx = max(mx, a[i]);
	if (mx >= n) { printf("Impossible\n"); return 0; }
	else {
		rep(i,1,n) {
			if (a[i] < (mx + 1) / 2) { printf("Impossible\n"); return 0; }
			cnt[a[i]]++;
		}
		rep(i,mx / 2 + 1,mx) if (cnt[i] <= 1) { printf("Impossible\n"); return 0; }
		if (mx % 2 == 0) {
			if (cnt[mx / 2] > 1) { printf("Impossible\n"); return 0; }
		} else {
			if (cnt[(mx + 1) / 2] > 2) { printf("Impossible\n"); return 0; }
		}
	}
	printf("Possible\n"); 
	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    for l in buf.lines() {
        let s: Vec<&str> = l.split(' ').collect();
        let a: i32 = s[0].parse().unwrap();
        let b: i32 = s[1].parse().unwrap();
        
        if a == 0 && b == 0 {
            break;
        }
        if a < b {
            println!("{} {}", a, b);
        } else {
            println!("{} {}", b, a);
        }
    }
}


Measured memory_bytes: 5028
#include<bits/stdc++.h>
#define debug(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
const int INF = 1<<29;

using namespace std;



int main()
{
	
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//clock_t time_req;time_req = clock();  
	int n;cin>>n;
	float ans = n/3.00000000;
	printf("%.7f",ans*ans*ans);




	//time_req = clock()- time_req;cout << "Time Compexity:"<< (float)time_req/CLOCKS_PER_SEC << " seconds" << endl; 
	return 0;
}

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

int main()
{
    int v_x, v_y, p;
    cin>>v_x>>v_y>>p;
    int x, y, c, xf = 0, xl = v_x, yf = 0, yl = v_y, ans;

    for(int i = 0; i < p; i++)
    {
        cin>>x>>y>>c;

        if(c == 1)
            xf = max(x, xf);

        else if(c == 2)
            xl = min(x, xl);

        else if(c == 3)
            yf = max(y, yf);

        else if(c == 4)
            yl = min(y, yl);
    }
    ans = (xl - xf) * (yl - yf);
    if(xf >= xl || yf >= yl)
        ans = 0;
    cout<<ans<<endl;

}


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

int main() {
    int n;
	cin >> n;
	int y[n];
	for(int i=0; i<n;i++){
	    cin >> y[i];
	}
	sort(y,y+sizeof(y)/sizeof(y[0]),greater<int>());
	int a=0;
	int b=0;
	for(int i=0; i<n;i++){
	    if(i%2==0){
	        a=a+y[i];
	    }
	    else{
	        b=b+y[i];
	    }
	}
	std::cout << a-b << std::endl;
}


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

using namespace std;

const int maxN = 1e5 + 10;
int nodeN, tot;
int val[maxN], cntHas[maxN], dp[1 << 16], num[20], xorSum[1 << 16];

int main () {
	scanf("%d", &nodeN);
	for (int nodeI = 1; nodeI < nodeN; ++nodeI) {
		int n1, n2, len;
		scanf("%d%d%d", &n1, &n2, &len);
		++n1, ++n2;
		val[n1] ^= len;
		val[n2] ^= len;
	}
	for (int nodeI = 1; nodeI <= nodeN; ++nodeI) ++cntHas[val[nodeI]];
	int ans = 0;
	for (int valI = 1; valI < 16; ++valI) {
		ans += cntHas[valI] >> 1;
		cntHas[valI] &= 1;
		if (cntHas[valI] != 0) {
			num[++tot] = valI;
		}
	}
	for (int stI = 0; stI < (1 << tot); ++stI) {
		for (int weiJ = 0; weiJ < tot; ++weiJ) {
			if ((stI & (1 << weiJ)) != 0) {
				xorSum[stI] ^= num[weiJ + 1];
			}
		}
	}
	for (int stI = 0; stI < (1 << tot); ++stI) {
		if (xorSum[stI] > 0) {
			dp[stI] = 0x3f3f3f3f;
			continue;
		}
		for (int weiJ = 0; weiJ < tot; ++weiJ) {
			if ((stI & (1 << weiJ)) != 0) {
				++dp[stI];
			}
		}
		--dp[stI];
	}
	dp[0] = 0;	//dp[0]要特殊处理
	for (int stI = 0; stI < (1 << tot); ++stI) {
		if (xorSum[stI] != 0) continue;	//这里开始写成了 dp[stI]
		for (int son = stI & (stI - 1); son; son = stI & (son - 1)) {
			if (xorSum[son] == 0) {
				dp[stI] = min(dp[stI], dp[stI ^ son] + dp[son]);
			}
		}
	}
	ans += dp[(1 << tot) - 1];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  /*  cout<<n/1000<<endl;
  cout<<(n/100)%10<<endl;
  cout<<(n/10)%100%10<<endl;
  cout<<(n%1000)%100%10<<endl;*/
  if((n/1000==(n/100)%10)&&((n/100)%10==(n/10)%100%10))
    cout<<"Yes"<<endl;
  else if(((n/100)%10==(n/10)%100)&&((n/10)%100%10==((n%1000)%100%10)))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
X = int(input())
N = 300
ABs = []
for i in range(N):
    ABs.append(i**5)
    
for i in range(N):
    for j in range(N):
        if ABs[i]-ABs[j] == X:
            print(i,j)
            sys.exit()
        elif ABs[i]+ABs[j] == X:
            print(i,-j)
            sys.exit()

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

int main(){
	string s;
	cin >> s;
	int flag = 0;
	for(int i = 0;i<3;i++){
		if(s[i]=='a'){
			flag++;
		    break;
		    }
	}
	for(int i = 0;i<3;i++){
		if(s[i]=='b'){
			flag++;
		    break;
		}
	}	
	for(int i = 0;i<3;i++){
		if(s[i]=='c'){
			flag++;
		    break;
		   }
	}
	if(flag==3){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli a,b,c;
lli a_,b_,c_;
lli ans = 0;

int main(){
    cin >> a >> b >> c;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        a_ = b/2+c/2;
        b_ = a/2+c/2;
        c_ = a/2+b/2;
        a = a_;b = b_;c = c_;
        ans++;
        if(ans > 100){
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
ll h,w,a,b;
ll ans[1005][1005]={0};
void solve(ll x,ll y){
  ll zany[1005]={0};
  for(int i=1;i<=y;i++) zany[i]=b;
  for(int i=y+1;i<=w;i++) zany[i]=h-b;

  for(int i=1;i<=h;i++){
    ll zanx=a;
    if(i>x) zanx=w-a;
    for(int j=1;j<=w;j++){
      if(zany[j]>0&&zanx>0){
        zany[j]--;
        ans[i][j]=1;
        zanx--;
      }
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cout<<ans[i][j];
    cout<<endl;
  }
}
int main(){
  cin>>h>>w>>a>>b;
  if(a*2>w||b*2>=h){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<=h;i++){
    for(int j=0;j<=w;j++){
      ll hp=a*i+(w-a)*(h-i);
      ll wp=b*j+(h-b)*(w-j);
      if(hp==wp){
        solve(i,j);
        //cout<<i<<" "<<j<<" "<<hp<<" "<<wp<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<vector<int> > F(N, vector<int>(10, 0));
  REP(i, N){
    REP(j, 10){
      cin >> F[i][j];
    }
  }
  vector<vector<ll> > P(N, vector<ll>(11, 0));
  REP(i, N){
    REP(j, 11){
      cin >> P[i][j];
    }
  }
  ll ans = -1e18;
  REP(i, 1<<10){
    if(i == 0) continue;
    vector<int> cnt(N, 0);
    ll res = 0;
    REP(j, 10){
      if((i >> j)&1){
        REP(k, N){
          if(F[k][j]) cnt[k]++;
        }
      }
    }
    REP(j, N){
      res += P[j][cnt[j]];
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
            if((-100 > a)|(-100 > b)){
    			// 出力
    			System.out.println("Err1");
    			return;
            }
            if(c > 100){
    			// 出力
    			System.out.println("Err2");
    			return;
            }          
            if((a <= c) & (c <= b)){
    			// 出力
    			System.out.println("Yes");
            }else{
    			// 出力
    			System.out.println("No");            	
            }

		}
}


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

typedef long long ll;

const int Maxn = 100005;

int n;
int a[Maxn], b[Maxn];
ll add;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &a[i], &b[i]);
    for (int i = n - 1; i >= 0; i--) {
        ll cur = add + a[i];
        ll nd = cur / b[i];
        if (cur % b[i]) nd++;
        nd *= b[i];
        add += nd - cur;
    }
    cout << add << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

bool smaller(vector<int>& x, vector<int>& r) {
	int n = x.size();
	for (int i = 0; i < n; i++) {
		if (x[i] < r[i])
			return true;
		else if (x[i] > r[i])
			return false;
	}
	return false;
}
int main() {
	int n;
	cin >> n;

	vector<int> p(n), q(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}

	if (!smaller(p, q))
		swap(p, q);
	int cnt = 0;
	while (p != q) {
		next_permutation(p.begin(), p.end());
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static char str;
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    str = sc.next().charAt(0);
    if('A'==str){
      System.out.println("T");
    }
    else if('T'==str){
		System.out.println("A");
    }
    else if('G'==str){
      System.out.println("C");
    }
    else if('C'==str){
      System.out.println("G");
    }
    else{
      System.out.println("No");
    }
  }
}


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

using namespace std;

int N, L;
int A[100001];

int main()
{
    scanf("%d%d", &N, &L);
    for(int i=1; i<=N; i++)
        scanf("%d", A+i);
    int idx=-1;
    for(int i=1; i<N; i++) if(A[i]+A[i+1]>=L)
        idx=i;
    if(idx==-1)
        printf("Impossible\n");
    else
    {
        printf("Possible\n");
        for(int i=1; i<idx; i++)
            printf("%d\n", i);
        for(int i=N-1; i>idx; i--)
            printf("%d\n", i);
        printf("%d\n", idx);
    }
    return 0;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  cin >> x;
  cout << x * x * x << endl;
  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INFTY powl(2,60)

int n,m;
vector<vector<long long>> A(101,vector<long long>(101,INFTY));

int warshallFloyd(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
                if(A[j][j]<0) return -1;
            }
        }
    }
    return 0;    
}

int main(){
    int a,b;
    long long c;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        A[i][i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        A[a][b]=c;
    }

    int x=warshallFloyd();
    if(x==-1) cout<<"NEGATIVE CYCLE"<<endl;
    else{
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j) cout<<' ';
                if(A[i][j]>powl(2,50)) cout<<"INF";
                else cout<<A[i][j];
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 3236
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;

static const int MAX = 100;
static const int long long INFTY = (1LL << 32);

int n;
long long d[MAX][MAX];

void floyd() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (d[i][k] == INFTY) continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int e, u, v, c;
  cin >> n >> e;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = (i == j) ? 0 : INFTY;
    }
  }
  for (int i = 0; i < e; i++) {
    cin >> u >> v >> c;
    d[u][v] = c;
  }

  floyd();

  bool negative = false;
  for (int i = 0; i < n; i++)
    if (d[i][i] < 0) negative = true;

  if (negative) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j) cout << " ";
        if (d[i][j] == INFTY)
          cout << "INF";
        else
          cout << d[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3184
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
vector<string> split(const string &str, char delim) {
	vector<string> res;
	size_t current = 0, found;
	while ((found = str.find_first_of(delim, current)) != string::npos) {
		res.push_back(string(str, current, found - current));
		current = found + 1;
	}
	res.push_back(string(str, current, str.size() - current));
	return res;
}
long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
vector<int>tha{ 19,7,0,19 };
vector<int>thi{ 19,7,8,18 };

int main() {
	int N; cin >> N;
	string st;
	getline(cin, st);
	while (N--) {
		getline(cin, st);
		vector<string>sts(split(st, ' '));
		vector<vector<int>>numss(sts.size());
		for (int i = 0; i < sts.size(); ++i) {
			for (auto c : sts[i]) {
				numss[i].emplace_back(c - 'a');
			}
		}

		vector<vector<int>>finans;
		for (int a = 1; a < 26; ++a) {
			if (gcd(a, 26) != 1)continue;
			for (int b = 0; b < 26; ++b) {
				bool ok = false;
				vector<vector<int>>anss(numss);
				for (auto& nums : anss) {
					for (auto&num : nums) {
						num = (a*num + b) % 26;
					}
					if (nums == tha || nums == thi) {
						ok = true;
					}
				}
				if (ok)finans = anss;
			}
		}
		//finans.emplace_back(tha);
		for (int i = 0; i < finans.size(); ++i) {
			for (int j = 0; j < finans[i].size(); ++j) {
				cout << char(finans[i][j] + 'a');
			}
			if (i == finans.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 3224
from bisect import bisect_right

def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7

N = I()
A = [I() for _ in range(N)]

# 広義単調減少列の長さの最大値を求めれば良い = Aを逆順に見ればLISと同値
# dp[i] := 長さがi以下の部分列で作られる広義単調減少列の最後の要素の最大値
dp = [-1]  # A[i] >= 0 なのでそれ以下の値を設定し、数列の単調性を保つ
for a in reversed(A):
    if dp[-1] <= a:
        dp.append(a)
    else:
        idx = bisect_right(dp, a)  # "広義"のため、同じ値が複数の場合は最も右のもの(right)
        dp[idx] = a
print(len(dp) - 1)


Measured memory_bytes: 56152
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<vector<ll>> edge;

ll k;

ll dfs(ll where,ll parent,ll dist){
    ll cost=0;
    for(auto &i:edge[where]){
        if(i==parent){continue;}
        cost+=dfs(i,where,dist+1);
    }
    if(dist>=k){cost++;}
    return cost;
}

int main(){
    ll n;
    cin>>n>>k;
    edge.resize(n);
    for(int i=0;i+1<n;i++){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    ll ans=E;
    if(k%2==0){
        k/=2;
        for(int i=0;i<n;i++){
            ans=min(ans,dfs(i,-1,-1));
        }
    }
    else{
        (k+=1)/=2;
        for(int i=0;i<n;i++){
            for(auto &t:edge[i]){
                if(i<=t){continue;}
                ans=min(ans,dfs(i,t,0)+dfs(t,i,0));
            }
        }
    }
    
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			double a = scanner.nextDouble();
			double b = scanner.nextDouble();
			System.out.println(slove(a, b));
		}
	}


	private static String slove(double a, double b) {
		if (a < 35.5 && b < 71)
			return "AAA";
		else if (a < 37.5 && b < 77)
			return "AA";
		else if (a < 40 && b < 83)
			return "A";
		else if (a < 43 && b < 89)
			return "B";
		else if (a < 50 && b < 105)
			return "C";
		else if (a < 55 && b < 116)
			return "D";
		else if (a < 70 && b < 148)
			return "E";
		else
			return "NA";
	}
}

Measured memory_bytes: 20556
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
//using mint = modint998244353;



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

  dsu d(N);
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d.merge(a, b);
  }

  vector<vector<int>> res = d.groups();
  cout << res.size() - 1 << endl;
  
  
  return 0;
}


Measured memory_bytes: 9052
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (a>b) swap(a,b);
	if (b>c) swap(b,c);
	int ans=1e9;
	for (int i=0; i<=100; i++)
	{
		int x=max(0,(i-a+1)/2),y=max(0,(i-b+1)/2),z=max(0,(i-c+1)/2);
		ans=min(ans,a+x*2-i+x+b+y*2-i+y+c+z*2-i+z);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char s[10]; cin >> s;
	int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
	if (a + b + c + d == 7)
		cout << a << '+' << b << '+' << c << '+' << d;
	else if (a + b + c - d == 7)
		cout << a << '+' << b << '+' << c << '-' << d;
	else if (a + b - c + d == 7)
		cout << a << '+' << b << '-' << c << '+' << d;
	else if (a + b - c - d == 7)
		cout << a << '+' << b << '-' << c << '-' << d;
	else if (a - b + c + d == 7)
		cout << a << '-' << b << '+' << c << '+' << d;
	else if (a - b + c - d == 7)
		cout << a << '-' << b << '+' << c << '-' << d;
	else if (a - b - c + d == 7)
		cout << a << '-' << b << '-' << c << '+' << d;
	else if (a - b - c - d == 7)
		cout << a << '-' << b << '-' << c << '-' << d;
	cout << "=7\n";
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

string s;
string t = "keyence";

int main() {
  cin >> s;
  int n = (int)s.size();
  REP(i, n) {
    for (int j = n - 1; j >= i + 1; j--) {
      if (s.substr(0, i) + s.substr(j, n - 1 - j + 1) == t) {
        puts("YES");
        return 0;
      }
    }
  }
  if (s == t) {
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

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

int main(){
    int N; cin >> N;
    vector<int> W(N);
    REP(i,N) cin >> W[i];

    ll left=0, res=INF;
    ll total = accumulate(W.begin(), W.end(),0);
    int ans;

    REP(i,N){
        left+=W[i];
        total-=W[i];
        if(abs(left-total)<res){
            res = abs(left-total);
            ans = i;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
(let ((a (read))
    (b (read))
    (k (read)))
    (if (< (- b a) (* 2 k))
        (loop for i from a to b do
            (format t "~D~%" i)
        )
        (progn  
            (loop for i from a to (+ a (- k 1)) do
                (format t "~D~%" i)
            )
            (loop for i from (- b k (- 1)) to b do
                (format t "~D~%" i)
            )
        )
    )  
)

Measured memory_bytes: 24344
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n, q;
vector<vector<int>> g;
map<int,int> mp;
vector<ll> ans;
void dfs(int now, ll sum, int pa){
    sum += mp[now];
    ans[now] = sum;
    for(int i = 0; i < g[now].size(); i++){
        int next = g[now][i];
        if(next == pa) continue;
        dfs(next, sum, now);
    }
}
int main(void){
    cin >> n >> q;
    g.resize(n);
    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);
    }

    for(int i = 0; i < q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        mp[p] += x;
    }

    ans.resize(n, 0);

    dfs(0, 0, -1);

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

Measured memory_bytes: 39936
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    ll k = n / (a + b);
    ll c = n % (a + b);

    ll res;
    if (c > a) {
        res = k * a + a;
    }
    else {
        res = k * a + c;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI bc;
VI cr;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,m;
  cin>>n>>m;
  bc.resize(n+1,1);
  cr.resize(n+1,0);
  cr[1]=1;
  in x,y;
  forn(z,m){
    cin>>x>>y;
    assert(bc[x]>=1);
    if(cr[x])
      cr[y]=1;
    --bc[x];
    ++bc[y];
    if(bc[x]==0)
      cr[x]=0;
  }
  in sm=0;
  for(in i=1;i<=n;++i)
    sm+=cr[i];
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


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

	int n, m, p[1024];
	char num[1024][16];
	while (cin >> n, n)
	{
		cin >> m;
		rep (i, n)
			cin >> num[i] >> p[i];
		
		int res = 0;
		while (m--)
		{
			char s[16];
			cin >> s;

			rep (i, n)
			{
				bool ok = true;
				rep (j, 8)
					if (num[i][j] != '*' && num[i][j] != s[j])
						ok = false;
				if (ok)
				{
					res += p[i];
					break;
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0