akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>

using namespace std;

int q;
int c,a,n;

int main(void){
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d%d%d",&c,&a,&n);
		int res=0;
		while(c>0 && a>0 && n>0){
			c--;
			a--;
			n--;
			res++;
		}
		while(c>1 && a>0){
			c-=2;
			a--;
			res++;
		}
		while(c>2){
			c-=3;
			res++;
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const int MAX = 100005;

int main() {
    int n, c; cin >> n >> c;
    vvint d(c,vint(c));
    vvint x(3);
    rep(i,c)rep(j,c) cin >> d[i][j];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int a; cin >> a;
            x[(i+j)%3].push_back(a);
        }
    }
    vvint y(3,vint(c));
    for (int color = 0; color < c; color++) {
        rep(i,3) {
            int sum = 0;
            rep(j,x[i].size()) {
                sum += d[x[i][j]-1][color];
            }
            y[i][color] = sum;
        }
    }
    int ans = inf;
    rep(i,c) {
        rep(j,c) {
            if (i == j) continue;
            rep(k,c) {
                if (k == j || k == i) continue;
                ans = min(ans,y[0][i]+y[1][j]+y[2][k]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1524
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int K =sc.nextInt();
    if(K<=16){
    int M[] ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14};
    System.out.println(M[K-1]);}
    else{int N[] ={ 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    System.out.println(N[K-17]);}
  }
}

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

long long ans, x, y=1, M=2019, d[2025]={1};
string s;
int main() {
	cin >> s;
	for(int i=s.size()-1; i>=0; i--) {
		x = (x + (s[i]-'0')*y) % M;
		ans += d[x]++;
		y = y * 10 % M;
	}
	cout << ans;
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll ans = 0;
    if (p == 2 || p == 5) {
        repr(i, n) {
            if ((s[i] - '0') % p == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    vi sum(n+1);
    int ten = 1;
    repr(i, n) {
        // sum[i] = (sum[i+1] + (s[i] - '0') * ten) % p;
        // ten = ten * 10 % p;
        int a;
        a = (s[i] - '0') * ten % p;
        sum[i] = (sum[i+1] + a) % p;
        ten = ten * 10 % p;
    }
    vi r(p);
    repr(i, n+1) {
        ans += r[sum[i]];
        r[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
int main() {
    ll N, T;
    cin >> N >> T;

    vector<ll> times(N);
    for (ll i = 0; i < N; ++i) {
        cin >> times[i];
    }

    ll sum = T;
    for (ll i = 0; i < N - 1; ++i) {
        ll next = times[i] + T;
        if (next > times[i + 1]) {
            sum += T - (next - times[i + 1]);
        } else {
            sum += T;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            StringBuilder _s2 = new StringBuilder();
            for (int i = 0; i < s.length(); ++i) {
                if (s.charAt(i) != 'x') {
                    _s2.append(s.charAt(i));
                }
            }
            String s2 = _s2.toString();
            for (int i = 0; i < s2.length(); ++i) {
                if (s2.charAt(i) != s2.charAt(s2.length() - i - 1)) {
                    out.println(-1);
                    return;
                }
            }
            int ans = 0;
            int p1 = 0, p2 = s.length() - 1;
            for (int i = 0; i < (s2.length() + 1) / 2; ++i) {
                int cnt1 = 0;
                while (s.charAt(p1) != s2.charAt(i)) {
                    p1++;
                    cnt1++;
                }
                int cnt2 = 0;
                while (s.charAt(p2) != s2.charAt(i)) {
                    p2--;
                    cnt2++;
                }
                p1++;
                p2--;
                ans += Math.abs(cnt1 - cnt2);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 22996
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	vector<vector<int>>edge(N);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
	}
	vector<long double>turn(N);
	for (int i = N - 2; i >= 0; i--) {
		for (auto j : edge[i]) {
			turn[i] += turn[j] + 1;
		}
		turn[i] /= edge[i].size();
	}
	vector<long double>p(N);
	p[0] = 1;
	for (int i = 0; i < N; i++) {
		long double add = p[i];
		add /= edge[i].size();
		for (auto j : edge[i])p[j] += add;
	}
	long double ans = turn[0];
	//cout << turn[0] << endl;
	for (int i = 0; i < N; i++) {
		if (edge[i].size() == 1)continue;
		long double nturn = turn[i] * edge[i].size();
		for (auto j : edge[i]) {
			long double nnturn = nturn - turn[j] - 1;
			nnturn /= edge[i].size() - 1;
			//cout << i << " " << j << " " << turn[0] + (nnturn - turn[i])*p[i] << endl;
			ans = min(ans, turn[0] + (nnturn - turn[i])*p[i]);
		}
	}
	cout << setprecision(20) << ans << endl;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N;
    cin >> N;
    if (N <= 9 || N % 2 == 1) {
        cout << "0\n";
        return 0;
    }
    ll ans = 0;
    ll t = 5;
    while (t <= N) {
        ll v = N / t;
        ans += v / 2;
        t *= 5;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 998244353;

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    vector<vector<ll>> dp(C+1, vector<ll> (D+1));
    dp[A][B] = 1;
    for (ll c = 0; c < C+1; c++) {
        dp[c][B-1] = 0;
    }
    for (ll d = 0; d < D+1; d++) {
        dp[A-1][d] = 0;
    }

    ll s;
    ll d;
    for (ll s = A+B+1; s <= C+D; s++) {
        for (ll c = A; c <= C; c++) { //dp[c][s-c]の計算
            if(s-c < B || s-c >D){
                continue;
            }
            d = s-c;
            dp[c][d] = (d*dp[c-1][d] %MOD) + (c*dp[c][d-1]%MOD) - ((c-1)*(d-1)*dp[c-1][d-1]%MOD);
            dp[c][d] = (MOD+dp[c][d])%MOD;

        }
    }

    

    printf("%lld\n", dp[C][D]);


}


Measured memory_bytes: 73744
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int n;
int ans[10010];
vector<int> E[10010];
int par[10010];
ll c[10010];

void dfs(int v, int &i)
{
  for (auto c : E[v])
  {
    if (c == par[v])
      continue;
    par[c] = v;
    dfs(c, i);
  }
  ans[v] = c[i];
  i++;
}

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

  int n;
  cin >> n;

  rep(i, n - 1)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  rep(i, n) cin >> c[i];
  sort(c, c + n);

  int index = 0;
  par[0] = -1;
  dfs(0, index);
  ll sum = 0;
  rep(i, n - 1) sum += c[i];
  cout << sum << "\n";
  rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 1536
# 161 B

n, m = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
num = 0

for j in range(len(a)):
    sum += a[j]

for i in range(len(a)):
    if a[i] >= ((1/(4*m)) * sum):
        num += 1
        # print(a[i])


if num >= m:
    print("Yes")
else:
    print("No")

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

int main(){
  int n;
  cin >> n;
  int p[n];
  
  for (int i = 0; i < n; i++){
    cin >> p[i];
  }
  
  int count = 0;
  for (int i = 1; i < n - 1; i++){
    if(p[i-1] < p[i]){
      if(p[i+1] > p[i]){
        count++;
      }
    }
    else if (p[i-1] > p[i]){
      if (p[i+1] < p[i]){
        count++;
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    println!(
        "{}",
        s.chars().fold(0, |a, c| match c {
            '+' => a + 1,
            '-' => a - 1,
            _ => unreachable!(),
        })
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int n,m,fig[1001];
  while(cin >> n >> m,n||m){
    int ans = 0;
    for(int i=0;i<n;i++) cin >> fig[i];
    sort(fig,fig+n,greater<int>());
    for(int i=0;i<(n/m)*m;i++){
      if((i+1) % m) ans += fig[i];
    }
    for(int i=n-1,j=0;j<(n%m);i--,j++) ans += fig[i];
    fill(fig,fig+1001,0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1184
def dfs(now, mx):
    if len(now) == n:
        print(now)
    else:
        for i in range(1, mx + 2):
            mmx = max(mx, i)

            dfs(now + al[i], mmx)


n = int(input())

al = ['.', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

dfs('a', 1)


Measured memory_bytes: 4412
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

ll w, h;
ll p[100010], q[100010];
ll imos[100010];
int main(void){
	cin >> w >> h;
	vector<ll> yoko;
	ll sum = 0;
	rep(i, w){
		cin >> p[i];
		sum += (p[i] * (h + 1));
		yoko.push_back(p[i]);
	}
	sort(yoko.begin(), yoko.end());
	imos[0] = 0;
	for (int i = 0; i < w; ++i){
		imos[i + 1] = imos[i] + yoko[i];
	}

	rep(i, h){
		cin >> q[i];
		sum += (q[i] * (w + 1));
	}

	ll lim = w;

	ll kesu = 0;
	rep(i, h){
		 auto it1 = upper_bound(yoko.begin(),yoko.end(),q[i]);
		 ll size = yoko.end() - it1;
		 // printf("size %d\n", size);
		 if(size > 0){
		 	// printf("imo %d\n", it1 - yoko.begin());
		 	kesu += imos[w] - imos[it1 - yoko.begin()];
		 	// printf("kesu %d\n", kesu);
		 }
		 kesu += q[i] * (lim - size);
		 // printf("lim - size %d\n", lim - size);
		 // printf("%d kesu\n", kesu);
	}
	printf("%lld\n", sum - kesu);
	return 0;
}

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

int main() {
  string X, Y;
  cin >> X >> Y;
  int A = 10, B = 11, C = 12, D = 13, E = 14, F = 15;
  if (X < Y) {
    cout << "<" << endl;
  }
  else if (X > Y) {
    cout << ">" << endl;
  }
  else if (X == Y) {
    cout << "=" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine();
            Dictionary<char, int> word = new Dictionary<char, int>();
            foreach (var c in r)
            {
                if (word.ContainsKey(c))
                {
                    word[c]++;
                }
                else
                {
                    word.Add(c,1);
                }
            }

            foreach (var pair in word)
            {
                if (pair.Value %2 != 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13140
// 2019/06/27
// AtCoder Beginner Contest 085 - A

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // Input
       String s = sc.next();
       String ans;

        // Make string
       ans = "";
       for(int i=0; i<s.length(); i++){
           if(i==3){
               ans = ans + "8";
           } else {
ans = ans + s.charAt(i);
           }
       }
       
       // Output
       System.out.println(ans);
    }
}

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

int main() {
  int S, W;
  cin >> S >> W;
  if (S<=W) {
    cout << "unsafe" << endl;
  }
  else {
    cout << "safe" << endl;
  }
}


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

int x,y,gx,gy;

int main () {
	cin >> x >> y;
	if (x==2) {
		gx=1;
	} else if (x==4||x==6||x==9||x==11) {
		gx=2;
	} else {
		gx=3;
	}	
	
	if (y==2) {
		gy=1;
	} else if (y==4||y==6||y==9||y==11) {
		gy=2;
	} else {
		gy=3;
	}
	
	if (gx==gy) {
		cout << "Yes" << endl;
	} else 
		cout << "No" << endl;
		
		
		
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 20;

struct P
{
	int x,y,id;
};

bool cmpx(P &a,P &b)
{
	return a.x<b.x;
}

bool cmpy(P &a,P &b)
{
	return a.y<b.y;
}

P Tree[(1<<20)];

void init(int depth,int l,int r,int now)
{
	if(r==l+1)return;
	if(depth%2)
	{
		sort(Tree+l,Tree+r,cmpx);
		Tree[now] = Tree[(l+r)/2];
		Tree[now].id=-1;
		init(depth+1,l,l+(r-l)/2,now*2);
		init(depth+1,l+(r-l)/2,r,now*2+1);
	}
	else
	{
		sort(Tree+l,Tree+r,cmpy);
		Tree[now] = Tree[(l+r)/2];
		Tree[now].id = -1;
		//if(now==1)cout<<(l+r)/2<<endl;
		init(depth+1,l,l+(r-l)/2,now*2);
		init(depth+1,l+(r-l)/2,r,now*2+1);
	}	
}

vector<int> ans;
int sx, sy, tx,ty;
void serch(int mnx,int mny,int mxx,int mxy,int now,int depth)
{

	//cout<<depth<<endl;
	if(tx<mnx||mxx<sx||ty<mny||mxy<sy)return;
	if(depth==20)
	{
		if(sx<=Tree[now].x&&Tree[now].x<=tx&&
		sy<=Tree[now].y&&Tree[now].y<=ty)
		ans.push_back(Tree[now].id);
		return;
	}
	if(depth%2)
	{
		serch(mnx,mny,mxx,Tree[now].y,now*2,depth+1);
		serch(mnx,Tree[now].y,mxx,mxy,now*2+1,depth+1);
	}
	else
	{	
		serch(mnx,mny,Tree[now].x,mxy,now*2,depth+1);
		serch(Tree[now].x,mny,mxx,mxy,now*2+1,depth+1);
	}
	
	
}

int main()
{
	//cout<<(1<<20)<<endl;
	for(int i = 0;i<(1<<20);i++)
	{
		P now;
		now.x = INT_MAX;
		now.y = INT_MAX;
		now.id = -1;
		Tree[i]=now;
	}
	int n;
	cin >> n;
	for(int i = 0;i<n;i++)
	{
		int x,y,id;
		cin >> x >> y;
		id = i;
		Tree[i+(1<<19)]= P{x,y,id};
	}
	init(0,(1<<19),(1<<20),1);
	int q;
	cin >> q;
	for(int i = 0;i<q;i++)
	{
		//int sx,tx,sy,ty;
		cin >> sx >> tx >> sy >> ty;
		ans = vector<int>();
		if(sx>tx)swap(sx,tx);
		if(sy>ty)swap(sy,ty);
		serch(INT_MIN,INT_MIN,INT_MAX,INT_MAX,1,1);
		sort(ans.begin(),ans.end());
		for(auto i: ans)cout<<i<<'\n';
		cout<<endl;
	}
}


Measured memory_bytes: 15444
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  long n;
  cin>>n;
  cout << n * (n-1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n >> m;
  cin >> s;

  vpll v;
  ll cur = 1;
  FOR(i, 1, n) {
    tmp = s[i] - '0';
    if (s[i] == s[i - 1]) cur++;
    else {
      v.pb(make_pair(cur, (tmp + 1) % 2));
      cur = 1;
    }
  }
  tmp = s[n - 1] - '0';
  v.pb(make_pair(cur, tmp));
  ll num = 0, le = 0;
  cur = 0;
  rep(i, v.size()) {
    if (v[i].second == 0) num++;
    cur += v[i].first;
    while (num > m) {
      if (v[le].second == 0) num--;
      cur -= v[le].first;
      le++;
    }
    ans = max(ans, cur);
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 2548
def solve(N, H):
    ans = 0
    val = 0

    for i in range(N - 1):
        if H[i] >= H[i+1]:
            val += 1
        else:
            val = 0

        ans = max(val, ans)

    return ans


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

print(solve(N, H))


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(min(b, d) - max(a, c) > 0)
    cout << min(b, d) - max(a, c) << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  string year = S.substr(0,4);
  string month = S.substr(5,2);
  string day = S.substr(8,2);
  
  if(year <= "2019" && month <= "04" && day <= "30"){
  	cout << "Heisei" << endl;
  }else{
  	cout << "TBD" << endl;
  }
 
}

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

int main(){
  int i,j,n,k,max;
  string str,ans;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> str;
    ans = str[0];
    k = 0;
    max = 1;
    for(j=2;j<str.size();j+=3){
      if(str[j] == '>'){
	k++;
	if(k == max){
	ans += str[j+1];
	max++;
	}
      }
      else if(str[j-1] == '<'){
	if(k == 0){
	  ans = str[j+1] + ans;
	  max++;
	}
	else k--;
      }
    }

    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        long sum = 0;
        for(int i = 1; i <= h; i++){
            if(i%3 != 0 && i%5 != 0){
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35856
#include<cctype>
#include<cstdio>
#include<cassert>
#include<cstring>

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

using namespace std;

int inv[2011];
char E[20][81];

int parse(int t,int l,int b,int r);
int expr(int &idx,int y,int y1,int y2);
int term(int &idx,int y,int y1,int y2);
int factor(int &idx,int y,int y1,int y2);
int powexpr(int &idx,int y,int y1,int y2);
int primary(int &idx,int y,int y1,int y2);
int fraction(int &idx,int y,int y1,int y2);

int expr(int &idx,int y,int y1,int y2){
	int a=term(idx,y,y1,y2);
	while(1){
		char c=E[y][idx];
		if(c!='+' && c!='-') break;
		idx+=2;
		int b=term(idx,y,y1,y2);
		if(c=='+') a=(a+b)%2011;
		if(c=='-') a=(a-b+2011)%2011;
	}
	return a;
}

int term(int &idx,int y,int y1,int y2){
	int a=factor(idx,y,y1,y2);
	while(1){
		char c=E[y][idx];
		if(c!='*') break;

		idx+=2;
		int b=factor(idx,y,y1,y2);
		a=a*b%2011;
	}
	return a;
}

int factor(int &idx,int y,int y1,int y2){
	if(E[y][idx]=='-' && E[y][idx+1]!='-'){
		idx+=2;
		return (-factor(idx,y,y1,y2)+2011)%2011;
	}

	if(E[y][idx]=='-' && E[y][idx+1]=='-'){
		return fraction(idx,y,y1,y2);
	}

	return powexpr(idx,y,y1,y2);
}

int powexpr(int &idx,int y,int y1,int y2){
	int a=primary(idx,y,y1,y2);
	if(y>0 && isdigit(E[y-1][idx-1])){
		int b=E[y-1][idx-1]-'0',c=1;
		rep(i,b) c=c*a%2011;
		a=c;
		idx++;
	}
	return a;
}

int primary(int &idx,int y,int y1,int y2){
	int a;
	if(isdigit(E[y][idx])){
		a=E[y][idx]-'0';
	}
	else{
		idx+=2;
		a=expr(idx,y,y1,y2);
	}
	idx+=2;
	return a;
}

int fraction(int &idx,int y,int y1,int y2){
	int x1=idx+1;
	while(E[y][idx]=='-') idx++;
	int x2=idx-1;
	idx++;
	return parse(y1,x1,y,x2)*inv[parse(y+1,x1,y2,x2)]%2011;
}

int find_base_line(int t,int l,int b,int r){
	for(int j=l;j<r;j++) for(int i=t;i<b;i++) if(E[i][j]!='.') return i;
	assert(0);
}

int parse(int t,int l,int b,int r){
	int y=find_base_line(t,l,b,r);
	int idx=l;
	while(E[y][idx]=='.') idx++;
	return expr(idx,y,t,b);
}

int main(){
	rep(i,2011) rep(j,2011) if(i*j%2011==1) inv[i]=j;

	for(int h;scanf("%d",&h),h;){
		rep(i,h){
			rep(j,81) E[i][j]='\0';
			scanf("%s",E[i]);
		}
		printf("%d\n",parse(0,0,h,strlen(E[0])));
	}

	return 0;
}

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

int ctoi(char c) {
  return c - '0';
}

int main() {
  char s[4];
  for (int i = 0; i < 4; i++) {
    cin >> s[i];
  }
  int d12 = ctoi(s[0]) * 10 + ctoi(s[1]);
  int d34 = ctoi(s[2]) * 10 + ctoi(s[3]);

  if (d12 == 00 || d12 > 12) {
    if (d34 <= 12 && d34 >= 1) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
  else {
    if (d34 <= 12 && d34 >= 1) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] count = new int[N+1];
		for( int i=1; i<=N-1; i++ ){
			for( int k=i+1; k<=N; k++ ){
				if( k<=X ){
					count[k-i]++;                      
				}
				if( i>=Y ){
					count[k-i]++; 
				}
				if( i<Y && k>X ){
					count[ Math.min( k-i, Math.abs(i-X)+Math.abs(k-Y)+1 ) ]++; 
				}
			}
		}
		for( int i=1; i<=N-1; i++ ){
			System.out.println(count[i]);
		}
	}
}


Measured memory_bytes: 23636
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T &a, T b) { return a > b ? (a = b, 1) : 0; }

int main() {
    const int MAX = 400;
    int n; cin >> n;
    int ma, mb; cin >> ma >> mb;
    vector<vector<int>> dp(MAX + 1, vector<int>(MAX + 1, INF));
    dp[0][0] = 0;
    while (n--) {
        int a, b, c; cin >> a >> b >> c;
        for (int na = MAX; na >= a; na--) {
            for (int nb = MAX; nb >= b; nb--) {
                chmin(dp[na][nb], dp[na - a][nb - b] + c);
            }
        }
    }
    int mi = INF;
    for (int a = 1; a <= MAX; a++) for (int b = 1; b <= MAX; b++) {
        if (a * mb == b * ma) chmin(mi, dp[a][b]);
    }
    cout << (mi == INF ? -1 : mi) << endl;
    return 0;
}


Measured memory_bytes: 896
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,t = lr()
a = lr()
min_num = inf
ans = 0
max_num = 0
for num in a:
    if max_num == num-min_num:
        ans+=1
    elif max_num < num-min_num:
        ans = 1
        max_num = num-min_num
    min_num = min(num,min_num)
print(ans)

Measured memory_bytes: 90988
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int sum = 0;
    for (int i = 1; i <= n; i++) {
      sum = sum + i;
    }

    System.out.println(sum);
  }
}

Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int N;
    scanf("%d",&N);
    int F[N];
    for(int i=0;i<N;i++)F[i]=0;
    for(int i=0;i<N;i++)for(int j=0;j<10;j++){int kari;scanf("%d",&kari);F[i]*=2;F[i]+=kari;}
    int P[N][11];
    for(int i=0;i<N;i++)for(int j=0;j<11;j++)scanf("%d",&P[i][j]);
    int ans=-1000000007;
    for(int i=1;i<(1<<10);i++){
        int karians=0;
        for(int j=0;j<N;j++){
            karians+=P[j][__builtin_popcount(i&F[j])];
        }
        if(ans<karians)ans=karians;
    }
    printf("%d",ans);
    return 0;
}


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

int ans = 0;
int n, m, q;
vector<int> a, b, c, d;

void dfs(vector<int> v)
{
    if (v.size() == n)
    {
        int score = 0;
        rep (i, q)
            if (v[b[i] - 1] - v[a[i] - 1] == c[i])
                score += d[i];

        ans = max(score, ans);
        return;
    }

    v.push_back(v.back());
    while (v.back() <= m)
    {
        dfs(v);
        v.back()++;
    }
}

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

    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    rep (i, q)
        cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> v(1, 1);
    dfs(v);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rei register int
#define pb push_back
using namespace std;
const int maxn = 300010;
int h,w,m;
int cw[maxn];
vector<int>ch[maxn];
int main(){;
	cin >> h >> w >> m;
	for(rei i = 1;i <= m;++i){
		int x,y; scanf("%d%d",&x,&y);
		ch[x].pb(y); ++cw[y];
	} int maxx(0),maxcnt(0);
	for(rei i = 1;i <= w;++i) if(cw[i] > maxx) maxx = cw[i],maxcnt = 1;
	else if(cw[i] == maxx) ++maxcnt; int ans(0);
	for(rei i = 1;i <= h;++i){ int rec = maxcnt;
		for(rei j = 0;j < ch[i].size();++j) if(cw[ch[i][j]] == maxx) --rec;
		if(rec == 0) ans = max(ans,(int)ch[i].size() + maxx - 1);
		else ans = max(ans,(int)ch[i].size() + maxx);
	} cout << ans ; return 0;
}

Measured memory_bytes: 21232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if((1 <= a && a <= 9) && (1 <= b && b <= 9)) cout << a * b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3616
N = 4
ARR = [1, 1, 1, 1]
Q = 3
SRR = [
    [1, 2],
    [2, 1],
    [3, 5]
]

N = 4
ARR = [1, 2, 3, 4]
Q = 3
SRR = [
    [1, 2],
    [3, 4],
    [2, 4],
]


#
# N = 2
# ARR = [1, 2]
# Q = 3
# SRR = [
#     [1, 100],
#     [2, 100],
#     [100, 1000]
# ]

N = int(input())
ARR = list(map(int,input().split()))
Q = int(input())
SRR = []

for i in range(Q):
    SRR.append(list(map(int,input().split())))


def calculate(n, arr, q, srr):
    dict = {}
    sumValue = sum(arr)
    for i in range(n):
        value = arr[i]
        if dict.get(value) == None:
            dict.__setitem__(value, 1)
        else:
            dict.__setitem__(value, dict.get(value) + 1)

    for i in range(q):
        fromValue = srr[i][0]
        toValue = srr[i][1]

        if dict.get(fromValue) == None:
            print(sumValue)
        else:
            fromNum = dict.get(fromValue)
            dict.__setitem__(fromValue, 0)
            sumValue += fromNum * (toValue - fromValue)
            if dict.get(toValue) == None:
                dict.__setitem__(toValue, fromNum)
            else:
                dict.__setitem__(toValue, dict.get(toValue) + fromNum)
            print(sumValue)


calculate(N, ARR, Q, SRR)


Measured memory_bytes: 35980
n,k = (int(i) for i in input().split())
l = list([])
for i in range(n):
    h = int(input())
    l.append(h)
l2 = sorted(l, reverse=True)

d = k-1
d_min = 1000000000
for i in range(n-d):
    tmp = l2[i] - l2[i+d]
    if (d_min > tmp ):
        d_min = tmp
print(d_min)

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

int main(){
    int H,W; cin >> H >> W;
    vector<string> S(H); rep(i,H) cin >> S[i];
    
    //書くマスから左、右、上、下に何マス'.'が続いてるか
    vector<vector<int>> L(H,vector<int>(W)),R(H,vector<int>(W)),U(H,vector<int>(W)),D(H,vector<int>(W));
    rep(i,H){
        rep(j,W){
            if(S[i][j] == '#'){
                L[i][j] = 0;
            }else if(j == 0){
                L[i][j] = 1;
            }else{
                L[i][j] = L[i][j-1] + 1;
            }
            if(S[i][j] == '#'){
                U[i][j] = 0;
            }else if(i == 0){
                U[i][j] = 1;
            }else{
                U[i][j] = U[i-1][j] + 1;
            }
        }
    }
    for(int i = H-1; i >= 0; i--){
        for(int j = W-1; j >= 0; j--){
            if(S[i][j] == '#'){
                R[i][j] = 0;
            }else if(j == W-1){
                R[i][j] = 1;
            }else{
                R[i][j] = R[i][j+1] + 1;
            }
            if(S[i][j] == '#'){
                D[i][j] = 0;
            }else if(i == H-1){
                D[i][j] = 1;
            }else{
                D[i][j] = D[i+1][j] + 1;
            }
        }
    }

    int ans = -1;
    rep(i,H){
        rep(j,W){
            if(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3 > ans) ans = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 67200
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int add(int a, int b){return  a + b > mod ? a + b - mod : a + b;}
int mul(int a, int b){return a * b > mod ? a * b % mod : a * b;}
int main(){
    //FL;
    FIN;
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << '\n';
    EjecuteTime;
    return 0;
}       


Measured memory_bytes: 3796
///
// File:  alds1_11_c.cpp
// Author: ymiyamoto
//
// Created on Wed Oct 18 00:49:05 2017
//

#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
static uint32_t graph[100][100];
static vector<int32_t> d(100, -1);
static queue<uint32_t> q;

static void bfs(uint32_t n)
{
  q.push(0);
  d[0] = 0;

  while (!q.empty()) {
    uint32_t index = q.front();
    q.pop();

    for (uint32_t i = 0; i < n; i++) {
      if (d[i] == -1 && graph[index][i] == 1) {
        q.push(i);
        d[i] = d[index] + 1;
      }
    }
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t id, k;
    cin >> id >> k;
    for (uint32_t j = 0; j < k; j++) {
      uint32_t val;
      cin >> val;
      graph[id - 1][val - 1] = 1;
    }
  }

  bfs(n);

  for (uint32_t i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A = 0;
  int B = 0;
  for(int i = 0;i < N;i++){
    cin >> A;
    if(A % 2 == 0){
      if(A % 3 != 0 && A % 5 != 0){
        B++;
        cout << "DENIED" << endl;
        break;
      }
    }
  }
  if(B == 0){
    cout << "APPROVED" << endl;
  }
}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
con = 10 ** 9 + 7

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#素因数分解
L = [1 for i in range(1001)]
L[0] = 0
L[1] = 0
plist = []
for i in range(1001):
	if L[i] == 1:
		plist.append(i)
		c = 2
		while True:
			if i * c <= 1000:
				L[i * c] = 0
				c += 1
			else:
				break

#処理内容
def main():
	N = int(input())
	A = getlist()
	D = defaultdict(int)
	for k in range(N):
		K = A[k]
		Dpre = defaultdict(int)
		for i in plist:
			while True:
				if K % i == 0:
					Dpre[i] += 1
					K = int(K // i)
				if K % i != 0:
					break
		if K != 1:
			Dpre[K] += 1
		# print(Dpre)
		for i in Dpre:
			D[i] = max(D[i], Dpre[i])
	# print(D)
	lcm = 1
	for i in D:
		for j in range(D[i]):
			lcm = (lcm * i) % con
	# print(lcm)

	ans = 0
	for i in range(N):
		inv_A = pow(A[i], con - 2, con)
		ans += (lcm * inv_A) % con
	ans = ans % con
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 48880
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20;

int n,x,y;
vector <int> vx,vy;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		vx.push_back(x);
		vy.push_back(y);
	}

	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());

	if(n&1) printf("%d",vy[n/2]-vx[n/2]+1);
	else printf("%d",vy[n/2-1]+vy[n/2]-(vx[n/2-1]+vx[n/2])+1);
}

Measured memory_bytes: 4988
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<iterator>
#include <stack>
#define ll long long
typedef long double ld;
#define all(v) ((v).begin()),((v).end())
#define vec2(n,m) vector<vector<ll>>vv(n + 10, vector<ll>(m + 10, 0));
#define p_q1   priority_queue<int,vector<int>,greater<int>>pq1;
#define format(n) fixed<<setprecision(n)
#define ll_min LLONG_MIN;
#define ll_max LLONG_MIN;
#define endl "\n"
#define F first 
#define S second
#define mkpr(x,y)  make_pair(x,y)
using namespace std;
void weza()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    weza();
    double n;
    cin >> n;
    cout << format(2);
    cout << 2 * n * 22/7<< endl;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	lld A[n];
	lld B[n];
	lld C[n-1];
	foi(i,n){
		cin >> A[i];
	}
	foi(i,n){
		cin >> B[i];
	}
	foi(i,n-1){
		cin >> C[i];
	}
	lld prev = -1;
	lld curr = -1;
	lld sum  = 0;
	foi(i,n){
		if (i == 0){
			curr = A[i];
			sum += B[A[i]-1];
		}
		else{
			curr = A[i];
			sum += B[A[i]-1];
			if (curr == prev+1){
				sum+= C[prev-1];
			}
		}
		prev = curr;
	}
	cout << sum;
	return 0;
}

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

vector<int> ga[101010];
vector<int> gb[101010];
vector<int> g[202020];
vector<bool> zero_a;
vector<bool> zero_b;
vector<int> ans;
int used[101010];

int dfs_a(int v) {
        vector<int> matching;

        if (!zero_a[v]) matching.push_back(v);

        for (int u : ga[v]) {
                int get = dfs_a(u);
                if (get == -1) continue;
                matching.push_back(get);
        }
        if (ga[v].size() == 0) return (zero_a[v] ? -1 : v);
        while (matching.size() >= 2) {
                int s1 = matching.back();
                matching.pop_back();
                int s2 = matching.back();
                matching.pop_back();
                g[s1].push_back(s2);
                g[s2].push_back(s1);
        }
        if (matching.size() == 1) return matching[0];
        else return -1;
}

int dfs_b(int v) {
        vector<int> matching;

        if (!zero_b[v]) matching.push_back(v);

        for (int u : gb[v]) {
                int get = dfs_b(u);
                if (get == -1) continue;
                matching.push_back(get);
        }
        if (gb[v].size() == 0) return (zero_b[v] ? -1 : v);
        while (matching.size() >= 2) {
                int s1 = matching.back();
                matching.pop_back();
                int s2 = matching.back();
                matching.pop_back();
                g[s1].push_back(s2);
                g[s2].push_back(s1);
        }
        if (matching.size() == 1) return matching[0];
        else return -1;
}

void dfs(int v, int w) {
        used[v] = true;
        ans[v] = w;
        for (int u : g[v]) if (!used[u]) {
                dfs(u, -w);
        }
}

int main() {
        int n;
        cin >> n;
        vector<int> a(n), b(n);
        int aroot, broot;
        for (int i = 0; i < n; i ++) {
                cin >> a[i];
                if (a[i] == -1) { 
                        aroot = i;
                        continue;
                }
                a[i] --;
                ga[a[i]].push_back(i);
        }
        for (int i = 0; i < n; i ++) {
                cin >> b[i];
                if (b[i] == -1) { 
                        broot = i;
                        continue;
                }
                b[i] --;
                gb[b[i]].push_back(i);
        }
        zero_a.resize(n, false);
        zero_b.resize(n, false);
        for (int i = 0; i < n; i ++) {
                if (ga[i].size() & 1) zero_a[i] = true;
                if (gb[i].size() & 1) zero_b[i] = true;
        }
        bool ok = true;
        for (int i = 0; i < n; i ++) ok &= zero_a[i] == zero_b[i];
        if (!ok) {
                cout << "IMPOSSIBLE" << endl;
                return 0;
        }
        dfs_a(aroot);
        dfs_b(broot);
        ans.resize(n, 0);
        for (int i = 0; i < n; i ++) {
                if (!zero_a[i] && !used[i]) { 
                        dfs(i, 1);
                }
        }
        cout << "POSSIBLE" << endl;
        for (int i = 0; i < n; i ++) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
        return 0;
}


Measured memory_bytes: 20736