akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let z: i32 = sc.read();
    let w: i32 = sc.read();
    let mut a = vec![z, w];
    for _ in 0..n {
        a.push(sc.read::<i32>());
    }

    let n = n + 2;
    let mut dp = vec![vec![vec![-1; 2]; n]; n];
    println!("{}", rec(&a, 0, 1, 0, &mut dp));
}

fn rec(cards: &Vec<i32>, xi: usize, yi: usize, turn: usize, dp: &mut Vec<Vec<Vec<i32>>>) -> i32 {
    let last = cmp::max(xi, yi);
    if last == cards.len() - 1 {
        return (cards[xi] - cards[yi]).abs();
    }

    if dp[xi][yi][turn] >= 0 {
        return dp[xi][yi][turn];
    }

    if turn == 0 {
        let m1 = rec(cards, last + 1, yi, 0, dp);
        let m2 = rec(cards, last + 1, yi, 1, dp);
        dp[xi][yi][0] = cmp::max(m1, m2);
        return dp[xi][yi][0];
    } else {
        let m1 = rec(cards, xi, last + 1, 0, dp);
        let m2 = rec(cards, xi, last + 1, 1, dp);

        dp[xi][yi][1] = cmp::min(m1, m2);
        return dp[xi][yi][1];
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 141692
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Panel{
  string name;
  int size;
  int coords[4];
  Panel* children[100];
  Panel() : size(0) {}
};
struct Result{
  Panel* value;
  int p;
  Result(Panel* v, int p) : value(v), p(p) {}
};
Result expr(const string& s, int p){
  Panel* panel = new Panel;
  assert(s[p] == '<');
  int tag_end = s.find('>', p);
  panel->name = s.substr(p + 1, tag_end - (p + 1));
  p = tag_end + 1;
  REP(i, 4){
    int& v = panel->coords[i];
    v = 0;
    assert(isdigit(s[p]));
    while(isdigit(s[p])){
      v = v * 10 + s[p++] - '0';
    }
    if(s[p] == ',') p++;
  }
  while(s[p + 1] != '/'){
    assert(s[p] == '<');
    Result r = expr(s, p);
    panel->children[(panel->size)++] = r.value;
    p = r.p;
  }
  tag_end = s.find('>', p);
  return Result(panel, tag_end + 1);
}
bool contain(int x, int y, Panel* p){
  return p->coords[0] <= x && x <= p->coords[2] && p->coords[1] <= y && y <= p->coords[3];
}
Panel* find(int x, int y, Panel* p){
  for(int i = 0; i < p->size; i++){
    if(contain(x, y, p->children[i])){
      return find(x, y, p->children[i]);
    }
  }
  return p;
}
int main(){
  int N;
  while(cin >> N && N){
    string s;
    cin >> s;
    Result r = expr(s, 0);
    assert(r.p == s.size());
    Panel* main = r.value;
    REP(i, N){
      int x, y; cin >> x >> y;
      if(contain(x, y, main)){
        Panel* res = find(x, y, main);
        cout << res->name << " " << res->size << endl;
      }else{
        cout << "OUT OF MAIN PANEL 1" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    string s;
    cin >> s;
    ll prev = 0;
    ll now = 0;
    ll ans = 0;
    ll conLef = 0;
    for (ll i=0;i<s.length();i++){
        if(s[i]== '<'){
            if(i != 0 and s[i-1] == '>'){
                if(now < 0){
                    conLef++;
                }
                ans -= (conLef)*(now);
                now = 0;
            }
            conLef = 0;
            now++;
            ans += now;
        }else{
            now--;
            ans += now;
            conLef++;
        }
//        cout << ans << endl;
    }
    if(now < 0){
        ans += (conLef+1)*abs(now);
        now = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 900
#include<stdio.h>

int main(){

	int n,s,k=100000;
	
	scanf("%d",&n);
	for(s=1;s<=n;s++){
		k=k*1.05;
		if(k%1000>0)k=k/1000*1000+1000;
	}
	printf("%d\n",k);
        return 0;
} 

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n;cin>>n;
  int64_t ans=0;
  int64_t tmp;
  for(int64_t i=1;i*i<n;i++){
  	tmp=n/i;
    if(n%i==0)tmp--;
    ans+=2*(tmp-i+1);
    ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vvll vector<vll>
#define wh(t) while(t--)
#define fi(n) for(ll i = 0; i < n; i++)
#define fj(n) for(ll j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fr first
#define se second
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){ll a = 1;while(n > 0){if(n & 1) a = (a * x)%M;x = (x * x)%M;n = n>>1;}return a;}
ll n,m;
bool in(ll x, ll y){
	if(x >= 0 && x < n && y>=0 && y< m) return true;
	return false;
}
void dfsm(vvll &mat, ll x, ll y, ll c){
	mat[x][y] = c;
	if(in(x+1,y) && mat[x+1][y] == 0) dfsm(mat,x+1,y,c);
	if(in(x-1,y) && mat[x-1][y] == 0) dfsm(mat,x-1,y,c);
	if(in(x,y+1) && mat[x][y+1] == 0) dfsm(mat,x,y+1,c);
	if(in(x,y-1) && mat[x][y-1] == 0) dfsm(mat,x,y-1,c);
}

void solve(){
	cin >> n >> m;
	ll cx,cy,dx,dy;
	cin >> cx >> cy >> dx >> dy;
	--cx;--cy;--dx;--dy;
	vector<string> s(n);
	fi(n) cin >> s[i];
	vvll mat(n,vll(m));
	fi(n){
		fj(m){
			if(s[i][j] == '#')
				mat[i][j] = -1;
		}
	}
	ll c = 0;
	fi(n){
		fj(m){
			if(mat[i][j] == 0){
				c++;
				dfsm(mat,i,j,c);
			}
		}
	}
	vvll g(c);
	fi(n){
		fj(m){
			if(mat[i][j]==-1) continue;
			fu(h,-2,2){
				fu(w,-2,2){
					if(in(i+h,j+w)){
						if(mat[i+h][j+w]!=-1){
							// cout << i << " " << j << " " << h << " " << w << " " << mat[i][j] << endl;
							g[mat[i][j]-1].pb(mat[i+h][w+j]-1);
							// cout << "Hullo" << endl;
						}
					}
				}
			}
		}
	}
	ll sc = mat[cx][cy]-1;
	ll t = mat[dx][dy]-1;
	if(sc==-2 || t==-2){
		cout << -1 << endl;
		return;
	}
	vll lev(c,-1);
	lev[sc] = 0;
	qll q;
	q.push(sc);
	vll v(c);
	v[sc] = 1;
	while(!q.empty()){
		ll x = q.front();
		q.pop();
		for(auto y:g[x]){
			if(!v[y]){
				v[y] = 1;
				lev[y] = lev[x]+1;
				q.push(y);
			}
		}
	}
	cout << lev[t] << endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif
	ll t;
	t = 1;
	//cin >> t;
	wh(t){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 85288
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define MAX 14
#define SMAX (1<<14)
#define QMAX 17000

class State{
    public:
    int used, n, size, cost, remain;
    State( int n=0, int size=0):n(n), size(size){
	used = 0;
	cost = 0;
	remain = n;
    }
    State( int n, int size, int cost, int remain): n(n), size(size), cost(cost), remain(remain){}

    bool operator < ( const State &s) const{
	return used < s.used;
    }
};

int n, m;
pair<int, int> F[MAX];
int head, tail;

void rec(State &u, State &v, int pos, int fsize, State Q[QMAX], set<State> &visited){
    if ( pos == n ){
	v.size += fsize;

	if ( visited.insert(v).second ){
	    //	if ( !visited[v] ){
	    //	    visited[v] = true;
	    v.cost = u.cost + 1;
	    //Q.push(v);
	    Q[tail++] = v;
	}
	return;
    }

    if ( !(v.used & (1<<pos)) && v.size >= F[pos].second) {
	State vv = v;
	vv.used |= (1<<pos);
	vv.remain--;
	vv.size -= F[pos].second;
	rec(u, vv, pos+1, fsize + F[pos].first, Q, visited );
    }

    rec(u, v, pos+1, fsize, Q, visited);
}

int bfs(){
    State s = State(n, m);
    //queue<State> Q;
    static State Q[QMAX];
    head = tail = 0;
    //    map<State, bool> visited;
    set<State> visited;

    //Q.push(s);
    Q[tail++] = s;
    //visited[s] = true;
    visited.insert(s);

    State u, v;
    //    while( !Q.empty() ){
    while( head < tail ){
	//u = Q.front(); Q.pop();
	u = Q[head++];
	if ( u.remain == 0 ) return u.cost;
	rec(u, u, 0, 0, Q, visited);
	
    }

    return -1;
}

void compute(){
    int cost = bfs();
    if ( cost < 0 ) cout << "Impossible" << endl;
    else cout << cost << endl;
}

main(){
    while( cin >> n >> m && n ){
	for ( int i = 0; i < n; i++ ) cin >> F[i].first >> F[i].second;
	compute();
    }
}

Measured memory_bytes: 1884
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * AtCoder Beginner Contest 130<br>
 * B - Bounding<br>
 * <br>
 * https://atcoder.jp/contests/abc130/tasks/abc130_b<br>
 */
public class Main {

    public static void main(String[] args) {

        // 入力
        InputValues value = input(System.in);

        // 計算
        int result = calc(value);

        // 出力
        System.out.println(result);
    }

    private static InputValues input(InputStream in) {
        InputValues inputs = new InputValues();

        try (Scanner sc = new Scanner(System.in)) {
            String[] input1 = sc.nextLine().split(" ");
            String[] input2 = sc.nextLine().split(" ");

            inputs.N = Integer.parseInt(input1[0]);
            inputs.X = Integer.parseInt(input1[1]);

            for (String str : input2) {
                inputs.list.add(Integer.parseInt(str));
            }
        }
        return inputs;
    }

    private static int calc(InputValues inputs) {
        int ans = 0;
        int count = 1;
        for (int i = 0; i < inputs.N; i++) {
            ans = ans + inputs.list.get(i);
            if (inputs.X < ans) {
                break;
            }
            count++;
        }
        return count;
    }

    private static class InputValues {
        int N;
        int X;
        List<Integer> list = new ArrayList<Integer>();
    }
}


Measured memory_bytes: 23380
from collections import defaultdict

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

edges = defaultdict(set)
used = [False] * N
for i in range(M):
    a, b = map(int, input().split())
    edges[a-1].add(b-1)
    edges[b-1].add(a-1)

def count(index):
    if all(used):
        return 1

    total = 0
    for dest in edges[index]:
        if not used[dest]:
            used[dest] = True
            total += count(dest)
            used[dest] = False
    return total

used[0] = True
print(count(0))

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

int main() {
    string N;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N.size(); i++) {
        int num = N[i] - '0';
        sum += num;
    }

//    std::cout << sum << std::endl;

    if (sum % 9 == 0) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 3764
#import<iostream>
#import<deque>
#import<algorithm>
using namespace std;main(){int n,i;deque<int> h;for(i=0;i<10;++i)cin>>n,h.push_back(n);sort(h.begin(),h.end());for(i=9;i>6;i--)cout<<h[i]<<endl;}

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

int main()
{
    char A[11];
    char B[11];
    char C[11];

    scanf("%s %s %s", A, B, C);

    int lastA = strlen(A) - 1, lastB = strlen(B) - 1;

    if (A[lastA] == B[0] && B[lastB] == C[0])
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 1628
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const check = (arr, k, n, p) => {
    let i = 0;
    for (let j = 0; j < k; j++) {
        let s = 0;
        while(s + arr[i] <= p) {
            s += arr[i];
            i++;
            if (i === n) return n;
        }
    }

    return i;
};

const solve = (k, n, arr) => {
    let l = 0;
    let r = 100000 * 10000;

    while(r - l > 1) {
        let mid = Math.floor((l + r) / 2);
        const v = check(arr, k, n, mid);
        if (v >= n) r = mid;
        else l = mid;
    }

    return r;
};

const N = Number(line[0].split(' ')[0]);
const K = Number(line[0].split(' ')[1]);
const Arr = line.slice(1, N+1).map(Number);
console.log(solve(K, N, Arr));



Measured memory_bytes: 29996
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long> A(N + 2);
	long long t = 0;
	A[0] = 0;
	A[N + 1] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		t += abs(A[i] - A[i - 1]);
	}
	t += abs(A[N]);
	for (int i = 1; i <= N; i++) {
		cout << t - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1]) << endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 2296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Grid
    {
        readonly int[] moveX = new int[] { -1, 0, +1, 0, -1, +1 };
        readonly int[] moveY = new int[] { 0, -1, 0, +1, +1, +1 };

        readonly int n;

        char[][] map;

        public Grid(int n)
        {
            this.n = n;
            map = new char[n][];
        }

        public void MakeMap()
        {
            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                map[i] = input.ToCharArray();
            }
        }

        public int SearchMax()
        {
            int ret = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (map[i][j] == '0') continue;

                    ret = Math.Max(ret, Search(j, i));
                }
            }
            return ret;
        }

        private int Search(int x, int y)
        {
            int ret = 0;

            for (int i = 0; i < moveX.Length; i++)
            {
                int tempX = x;
                int tempY = y;
                int count = 1;

                while (true)
                {
                    tempX += moveX[i];
                    tempY += moveY[i];

                    if (IsValid(tempX, tempY))
                    {
                        if (map[tempY][tempX] == '1') count++;
                        else break;
                    }
                    else break;
                }
                ret = Math.Max(ret, count);
            }
            return ret;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0) return false;
            if (x >= n) return false;
            if (y < 0) return false;
            if (y >= n) return false;
            return true;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                Grid g = new Grid(n);
                g.MakeMap();
                sb.AppendLine(g.SearchMax().ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;
int main()
{
    int N;
    cin >> N;

    vector<int> ds(N);
    
    for (int i = 0; i < N; i++)
        cin >> ds[i];

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

    cout << ds[N / 2] - ds[(N / 2) - 1] << '\n';

    return 0;
}


Measured memory_bytes: 640
A, B = map(int, input().split())

gain = 0

if A >= B:
  gain += A
  A -= 1
  if A >= B:
    gain += A
  else:
    gain += B
else:
  gain += B
  B -= 1
  if A >= B:
    gain += A
  else:
    gain += B

print(gain)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i)
{
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if (l <= H && A[l] > A[i])
        largest = l;
    else
        largest = i;
    if (r <= H && A[r] > A[largest])
        largest = r;

    if (largest != i)
    {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main()
{
    cin >> H;

    for (int i = 1; i <= H; i++)
        cin >> A[i];

    for (int i = H / 2; i >= 1; i--)
        maxHeapify(i);

    for (int i = 1; i <= H; i++)
    {
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 5052
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
while loop:
  if not all([n % 2 is 0 for n in nums]):
    loop = False 
    break
    
  for i, n in enumerate(nums):
    nums[i] = n//2
  cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define int long long
#define ll long long
#define us unsigned
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define nin(ary, n) for (int i = 0; i < (n); i++) cin >> ary[i]
#define nnin(ary, h, w) for (int i = 0; i < (h); ++i) for (int j = 0; j < (w); ++j) cin >> ary[i][j]
#define opt(conditions, a, b) cout << ((conditions) ? #a : #b) << endl
using namespace std;
const double PI = acos(-1.0);
const int MOD = 1e9 + 9;

int max_n(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_o(int ary[], int length) {
	int max;
	max = max_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_n(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_o(int ary[], int length) {
	int min;
	min = min_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int gcm(int a, int b) {
	int result = a;
	int k = 0;
	int n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while (k != 0);
	return result;
}

int gcm_n(int ary[], int length) {
	int g = ary[0];
	for (int i = 0; i < length; i++)
		g = gcm(g, ary[i]);
	return g;
}

int lcm(int a, int b) {
	int g, n;
	g = gcm(a, b);
	n = gcm(a, g);
	a = a / n;
	b = b / (g / n);
	return a*b;
}

int lcm_n(int ary[], int length) {
	int l = ary[0];
	for (int i = 0; i < length; i++)
		l = lcm(l, ary[i]);
	return l;
}

signed main() {

	int n, p[100000], cnt = 0;
	cin >> n;
	nin(p, n);

	rep(i, n) {
		if (p[i] == i+1) {
			cnt++;
			i++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll N;

signed main() {
    cin >> N;
    ll ans = 0;
    FOR(i, 1, N) { ans += i; }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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;


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

  vector<vector<pair<int,int>>> v;
  rep(i,N){
    int a;
    cin >> a;
    vector<pair<int,int>> tmp;
    rep(j,a){
      int x, y;
      cin >> x >> y;
      x--;
      tmp.emplace_back(x,y);
    }
    v.push_back(tmp);
  }

  int ret = 0;
  for(ll S=1; S<(1<<N); S++){
    bool ok = true;
    int num = 0;
    rep(i,N){
      if((S>>i)&1) num++;
    }

    rep(i,N){
      if((S>>i)&1){
        rep(j,v[i].size()){
          int x = v[i][j].first;
          int y = v[i][j].second;
          if( (y == 1 && !((S>>x)&1)) || (y == 0 && ((S>>x)&1)) ){
            ok = false;
          }
        }
      }
    }

    if(ok) ret = max(ret, num);
  }

  cout << ret << endl;

  return 0;
}



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

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

  int m = s.length();
  int n = t.length();
  vector<vector <int>> length(n + 1, vector<int>(m + 1, 0));

  for (int i = 0; i < m; i++) {
    length[n][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    length[i][m] = 0;
  }

  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      int max_length = 0;

      if (t[i] == s[j]) {
        max_length = 1 + length[i + 1][j + 1];
      }
      if (length[i + 1][j] > max_length) {
        max_length = length[i + 1][j];
      }

      if (length[i][j + 1] > max_length) {
        max_length = length[i][j + 1];
      }
      length[i][j] = max_length;
    }
  }

  string seq;
  int l = length[0][0], row = 0, col = 0;

  while(l > 0) {
    if (l == length[row + 1][col]) {
      row = row + 1;
    } else if (l == length[row][col + 1]) {
       col = col + 1;
    } else if (l == length[row + 1][col + 1] + 1) {
      seq += s[col];
      row = row + 1;
      col = col + 1;
      l--;
    }
  }

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

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

int check(char *colors, int len){
	char *p = colors;
	int count1 = 0, count2 = 0, i;
	for(i = 0; i < len; i++){
		if(i % 2 == 0){
			if(*p == '0'){
				count1++;
			}else{
				count2++;
			}
		}else{
			if(*p == '1'){
				count1++;
			}else{
				count2++;
			}			
		}
		p++;
	}
	return count1 <= count2 ? count1 : count2;
}

int main(void){
	char colors[100000] = {};
	char *p;
	int len;
	scanf("%s", colors);
	len = strlen(colors);
	printf("%d", check(colors, len));
	return 0;
}

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

int power(ll a, ll b) {
    int c = 1;
    while (b) {
        if (b & 1) c = c * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return c;
}

int nCr(int a, int b) {
    ll x = 1, y = 1;
    rep(i, b) {
        x = x * (a - i) % MOD;
        y = y * (i + 1) % MOD;
    }
    return x * power(y, MOD - 2) % MOD;
}

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

    ll ans = power(2, n) - 1 - nCr(n, a) - nCr(n, b);

    cout << (ans % MOD + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 3600
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1
    for i in range(n):
        if a[i] == 0:
            print(0)
            exit()
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            ans = -1
            print(ans)
            exit()
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 23068
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

struct pos {
	int x, y;
	int cost;
	pos() {}
	pos(int x_, int y_, int cost_) {
		x = x_; y = y_; cost = cost_;
	}
	bool operator<(const pos p) const {
		return cost > p.cost;
	}
};

const int INF = 1000000;

int main() {
	int n, m;
	while(cin >> n >> m, n | m) {
		char in[128][128];
		int cost[128][128];
		for(int i = 0; i < 128; i++) {
			for(int j = 0; j < 128; j++) {
				in[i][j] = '.';
				cost[i][j] = INF;
			}
		}

		for(int i = 0; i < m; i++) {
			scanf("%s", in[i + 1] + 1);
			in[i + 1][n + 1] = '.';
		}

		priority_queue<pos> q;
		for(int i = 1; i < m + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				if(in[i][j] == '&') {
					q.push(pos(j, i, 0));
					i = m + 1;
					j = n + 1;
				}
			}
		}
		int dx[] = {-1, 1, 0, 0};
		int dy[] = {0, 0, -1, 1};
		int ans = -1;
		while(!q.empty()) {
			pos p;
			p = q.top(); q.pop();
			if(cost[p.y][p.x] == INF) {
				if(p.x <= 0 || n + 1 <= p.x || p.y <= 0 || m + 1 <= p.y) {
					ans = p.cost;
					break;
				}
				cost[p.y][p.x] = p.cost;
				for(int i = 0; i < 4; i++) {
					if(cost[p.y + dy[i]][p.x + dx[i]] == INF) {
						int c = p.cost;
						if(in[p.y][p.x] == '#' && in[p.y + dy[i]][p.x + dx[i]] == '.') {
							c++;
						}
						q.push(pos(p.x + dx[i], p.y + dy[i], c));
					}
				}
			}
		}

		/*
		for(int i = 1; i < m + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				cout << (cost[i][j] == INF ? in[i][j] : '*');
			}
			cout << endl;
		}
		*/
		cout << ans << endl;
	}
}

Measured memory_bytes: 1436
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	while(k--) a[2]*=2;
	cout<<a[0]+a[1]+a[2];
	re 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <atcoder/all>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int n,q;
  cin >> n >> q;
  atcoder::fenwick_tree<ll> tree(n);
  vi a(n);
  rep(i,n) {
    int x;
    cin >> x;
    tree.add(i,x);
  }
  rep(i,q) {
    int t;
    cin >> t;
    if(t) {
      int l,r;
      cin >> l >> r;
      cout << tree.sum(l,r) << endl;
    } else {
      int p,x;
      cin >> p >> x;
      tree.add(p,x);
    }
  }
  return 0;
}

Measured memory_bytes: 10180
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>
#include <queue>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

vector<int> graph[100010];
vector<bool> visit(100010,false);
vector<int> parent(100010,-1);

void dfs(int p){
    if(!visit[p]){
        visit[p] = true;
        for(auto e: graph[p]){
            if(!visit[e]){
                parent[e] = p;
                dfs(e);
            }
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    int a,b;
    rep(i,m){
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }


    queue<int> qu;
    qu.push(1);
    int cnt = 1;
    visit[1] = true;

    while(!qu.empty()){
        int p = qu.front();
        qu.pop();
        for(auto e : graph[p]){
            if(!visit[e]){
                visit[e] = true;
                cnt++;
                qu.push(e);
                parent[e] = p; 
            }
        }
    }

    if(cnt == n){
        cout << "Yes" << endl;
        reps(i,2,n+1){
            cout << parent[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  int x[N];
  ll dp[N+1][2501], ans = 0;
  for (int i=0; i<N; i++)
    cin >> x[i];
  for (int i=0; i<=N; i++)
    for (int j=0; j<=2500; j++)
      dp[i][j] = 0;
  dp[0][0] = 1;
  for (int i=0; i<N; i++) {
    for (int k=N; k>0; k--)
      for (int j=2500; j>=x[i]; j--) {
        dp[k][j] += dp[k-1][j-x[i]];
    }
  }
  for (int i=1; i<=N; i++)
    ans += dp[i][i*A];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4616
mod = 10**9+7
mod2 = 998244353
rng = 100100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
s = 0
for a,b in ab:
  s = max(s,a,b)
dp = [[0 for i in range(2*s+2)] for j in range(2*s+2)]
for a,b in ab:
  dp[s+1-a][s+1-b] += 1
for i in range(1,2*s+2):
  for j in range(1,2*s+2):
    dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod
x = 0
for a,b in ab:
  x = (x+dp[s+1+a][s+1+b])%mod
t = 0
for a,b in ab:
  t = (t+cmb(2*a+2*b,2*a))%mod
ans = (x-t)*pow(2,mod-2,mod)%mod
print(ans)

Measured memory_bytes: 194488
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int k, n;
    cin >> n >> k;
    if ((k <= n) && (n == 0)) {
      return 0;
    }

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

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    int m = s;
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t >= m) {
        m = t;
      }
      s = t;
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 3748
n = int(input())

if n == 1:
    print(0)
    exit()

import math
def div(m):
  d = {}
  temp = int(math.sqrt(m))+1
  for i in range(2, temp):
    while m%i== 0:
      m //= i
      if i in d:
        d[i] += 1
      else:
        d[i] = 1
  if d == {}:
    d[m] = 1
  else:
    if m in d:
      d[m] += 1
    elif m != 1:
      d[m] =1
  return d

D = {}
for i in range(2, n+1):
    d = div(i)
    for k, v in d.items():
        if k in D:
            D[k] += v
        else:
            D[k] = v
#print(D)

A = set()
B = set()
P = set()
Q = set()
R = set()
for k, v in D.items():
    if v >= 74:
        R.add(k)
    if v >= 24:
        P.add(k)
    if v >= 14:
        Q.add(k)
    if v >= 4:
        B.add(k)
    if v >= 2:
        A.add(k)

ans = 0
b = len(B)
for a in A:
    if a not in B:
        ans += b*(b-1)//2
    else:
        ans += (b-1)*(b-2)//2

p = len(P)
for a in A:
    if  a not in P:
        ans += p
    else:
        ans += p-1

q = len(Q)
for b in B:
    if b not in Q:
        ans += q
    else:
        ans += q-1

ans += len(R)
print(ans)

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

int main(void) {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    ostringstream sout;
    sout << setfill('0') << setw(3) << i;
    string text = sout.str();
    int index = 0;
    for (int j = 0; j < S.length(); j++) {
      if (index == 3) break;
      if (text[index] == S[j]) index++;
    }
    if (index == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

ll N, X ,T;


int main(void){

    cin >> N >> X >> T;

    ll ans = 0;

    ll times = N / X;
    if (N % X != 0) times++;

    ans = T * times;

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

#define dump(a) (cerr << #a << " = " << (a) << endl)
#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

constexpr int W = 4;
constexpr int H = 5;
constexpr int N = W * H;

constexpr int dx[] = {1, 1, 0, -1};
constexpr int dy[] = {0, 1, 1, 1};

bool out(int x, int y) {
  return x < 0 || y < 0 || x >= W || y >= H;
}

int get_index(int x, int y) {
  return x + y * W;
}

int ans;

void dfs(const vector<int> &cards) {
  ans = min<int>(ans, cards.size());

  rep(i, cards.size()) {
	const int x = i % W;
	const int y = i / W;

	rep(d, 4) {
	  const int nx = x + dx[d];
	  const int ny = y + dy[d];
	  const int idx = get_index(nx, ny);

	  if(out(nx, ny) || idx >= cards.size()) continue;

	  if(cards[i] == cards[idx]) {
		vector<int> tmp(cards);
		const int a = min(i, idx);
		const int b = max(i, idx);
		tmp.erase(tmp.begin() + b);
		tmp.erase(tmp.begin() + a);
		dfs(tmp);
	  }
	}
  }
}

void solve() {
  vector<int> cards(N);
  for(auto &e : cards) cin >> e;

  ans = N;
  dfs(cards);
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  while(t--) solve();

  return 0;
}

Measured memory_bytes: 1212
function Main(inp) {
    var input = inp.split('\n')[0].split(' ').map(function(n) {
        return Number(n);
    });
    var n = input[0];
    var power = 1;
    for(var i = 1; i <= n; i++) {
      power = i * power % (Math.pow(10, 9) + 7); 
    }
    console.log(power);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8268
#include <iostream>
#include <algorithm>
using namespace std;
long long int b[100000];
long long int combination(int n, int k){
  long long int a = 1;
  long long int b = 1;
  for(int i = 0;i < k;i++){
    a *= (n - i);
    b *= (i + 1);
  }
  return (a / b);
}
int main(){
  long long int n, m;
  long long int a;
  cin >> n >> m;
  cin >> a;
  b[0] = a % m;
  for(int i = 1;i < n;i++){
    cin >> a;
    a = a % m;
    b[i] = (b[i - 1] + a) % m;
  }
  sort(b, b + n);
  int count = 1;
  long long int count2 = 0;
  if(b[0] == 0){
    count ++;
  }
  for(int i = 1;i < n;i++){
    if(b[i] == b[i - 1]){
      count ++;
    }else{
      count2 += combination(count, 2);
      count = 1;
    }
  }
  count2 += combination(count, 2);
  cout << count2 << endl;
}

Measured memory_bytes: 1024
import sys
N = int(input())

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

listH = list(map(int, input().split()))

listT = [T-i*0.006 for i in listH]



min = sys.maxsize
ans = 0
for j in range(0,len(listT)):
    dif = abs(A - listT[j])
    if min > dif:
        min = dif
        ans = j+1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int main() {
  ios::sync_with_stdio(false);
  string a,b;
  int c,d;
  cin>>a>>b>>c>>d;
  string e;
  cin>>e;
  if(e==a)cout<<c-1<<' '<<d;
  else cout<<c<<' '<<d-1;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int NUM = scan.nextInt();
		int[] id = new int[NUM];		// 食べた料理の順番
		int[] satisfuction = new int[NUM];		// 各料理の満足度
		int[] plusSatisfuction = new int[NUM - 1];		// 連番のときに追加で得られる満足度
		int memory = Integer.MIN_VALUE;		// 直前に食べた料理の番号
		int answer = 0;			// 満足度の合計

		for(int i = 0; i < NUM; i++) {
			id[i] = scan.nextInt();
		}
		for(int i = 0; i < NUM; i++) {
			satisfuction[i] = scan.nextInt();
		}
		for(int i = 0; i < NUM - 1; i++) {
			plusSatisfuction[i] = scan.nextInt();
		}

		for(int i = 0; i < NUM; i++) {
			answer += satisfuction[id[i]-1];
			if(id[i] - 1 == memory) {
				answer += plusSatisfuction[id[i] - 2];
			}
			memory = id[i];
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INF = 1<<21;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, m[MAX][MAX];

void dijkstra() {
	int color[n],d[n],p[n];
	for(int i=0;i<n;i++){
		color[i]=WHITE;
		d[i]=INF;
		p[i]=-1;
	}
	d[0]=0;
	while(true){
		int minv=INF;
		int u=-1;
		for(int i=0;i<n;i++){
			if(color[i]==BLACK) continue;
			if(minv>d[i]){
				minv=d[i];
				u=i;
			}
		}
		if(u==-1) break;
		color[u]=BLACK;
		for(int v=0;v<n;v++){
			if(color[v]==BLACK) continue;
			if(m[u][v]==INF) continue;
			if(d[v]>m[u][v]+d[u]){
				d[v]=m[u][v]+d[u];
				color[v]=GRAY;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << i << " " << d[i] << endl;
	}
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			m[i][j]=INF;

	for(int i=0;i<n;i++){
		int id, k;
		cin >> id >> k;
		for(int j=0;j<k;j++){
			int id2,w;
			cin >> id2 >> w;
			m[i][id2]=w;
		}
	}
	dijkstra();
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
 int A,B;
cin>>A>>B;
if((1<=A<=13)&&(1<=A<=13)){

if(A==B){
cout<<"Draw";
      }
 else if((A==1)&&(B!=1))
{
cout<<"Alice";
}
else if((B==1)&&(A!=1))
{
cout<<"Bob";
}
else if(A>B)
{
cout<<"Alice";
}
else {
cout<<"Bob";
}}
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rep2(i,n) for(i=2;i<=n;i++)
#define test(a) cout << "*" << a << endl
#define ll long long
int main(){
  ll i,j;
  ll n; 
  ll nSyou=0;
  ll a;
  ll b = 0;
  ll countWari=0;
  ll maxAB;
  
  cin >> n;
  
  rep1(i,sqrt(n)+1){
    if(n%i==0){  
      a = i;
      b = n/i;        
    }
    //nSyou = n/i;            
  }
  
  //test(a);
  //test(b);
  maxAB = max(a,b);
  while(maxAB > 0){
    maxAB /= 10;
    countWari++;
  }
  
  cout << countWari << endl;
  //if(max(a,b)
 
}

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

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(N: int, p: "List[int]"):
    s = 0
    for i, j in zip(p, sorted(p)):
        if i != j:
            s += 1
    if s == 0 or s == 2:
        print('YES')
    else:
        print('NO')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *r;
  struct node *l;
  struct node *par;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node treeSearch(Node,int);
Node root;

Node treeSearch(Node u, int k){
  if(u == NIL || u->key == k) return u;
  if(k<u->key){
    return treeSearch(u->l,k);
  }
  else if(k>u->key){
    return treeSearch(u->r,k);
  }
  return NIL;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->l;
    else x = x->r;
  }
  z->par = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->l = z; // z を y の左の子にする
    else y->r = z; // z を y の右の子にする
}

void inorder(Node u){
  if(u->l!=NIL) inorder(u->l);
  printf(" %d",u->key);
  if(u->r!=NIL) inorder(u->r);
  return;
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->l!=NIL) preorder(u->l);
  if(u->r!=NIL) preorder(u->r);
  return;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}


Measured memory_bytes: 20480
package main

import "fmt"

func main() {
	// Code for A - Regular Triangle
	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	if A == B && B == C {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1832
MOD = 1000000007
N, K = map(int, input().split())
ans = 0
f = [0] * (K+1)
g = [0] * (K+1)
for t in range(K, 0, -1):
    f[t] = pow(K//t, N, MOD)
    g[t] = f[t]
    for s in range(2 * t, K+1, t):
        g[t] -= g[s]
    ans = (ans + t * g[t]) % MOD
print(ans)

Measured memory_bytes: 13684
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int x;
    cin >> x;
    if(x){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	char a,b;
	cin>>a>>b;
	if (a==b){
		cout<<"=";
	}
	else if (a>b){
		cout<<">";
	}
	else {
		cout<<"<";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,A[200001],ans=0;
    cin>>n;
    rep(i,n) cin>>A[i];
    vec B(n,0);
    rep(i,n){
        if(i-A[i]>=0&&i-A[i]<=n-1) B[i-A[i]]++;
    }
    rep(i,n){
        if(A[i]+i<=n-1) ans+=B[A[i]+i];
    }
    cout<<ans;
}

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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 510;
ll cnts[MAX_N][MAX_N];
int N, M, Q;
int main()
{
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++)
  {
    int L, R;
    cin >> L >> R;
    cnts[R][L]++;
  }
  for (int i = 0; i < MAX_N; i++)
  {
    for (int j = 1; j < MAX_N; j++)
    {
      cnts[i][j] += cnts[i][j - 1];
    }
  }
  
  for (int i = 0; i < Q; i++)
  {
    int p, q;
    cin >> p >> q;
    ll res = 0;
    for (int j = p; j <= q; j++)
    {
      res += cnts[j][q] - cnts[j][p - 1];
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2944