akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif


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

	vector<ll> a(n);
	rep(i, 0, n)
	{
		cin >> a[i];
		a[i]--;
	}

	ll ans = 0;
	rep(i, 0, 100001)
	{
		if (ans == 1)
		{
			cout << i;
			return 0;
		}
		ans = a[ans];
	}
	cout << -1;
	return 0;
}




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

typedef std::pair<int, int> P;

int main(){
	int a = 0, b = 0;
	while(std::cin >> a >> b, !std::cin.eof()){
		std::vector<P> v;
		while(a%b){
			a *= 10;

			if(std::find(v.begin(), v.end(), P(a%b, a/b)) != v.end())break;
			v.push_back(P(a%b, a/b));
			a %= b;
		}
		int first = std::find(v.begin(), v.end(), P(a%b, a/b)) - v.begin();

		for(int i=0;i<v.size();i++){
			std::cout << v[i].second;
		}std::cout << std::endl;

		if(a%b == 0)continue;
		for(int i=0;i<v.size();i++){
			if(i >= first)
				std::cout << "^";
			else
				std::cout << " ";
		}std::cout << std::endl;
	}
}

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

int main() {
int N;
  cin >> N;
  vector<pair<int, int>> pairs(N);
  rep(i, N){
  cin >> pairs.at(i).first;
    pairs.at(i).second = i+1;
  }
  
sort(pairs.begin(), pairs.end());
  rep(i, N){
    if(i <= N-1)
    cout <<  pairs.at(i).second << " ";
    else
       cout <<  pairs.at(i).second << endl;
  }
}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy";
	}else if(s == "Cloudy") {
		cout << "Rainy";
	}
	else {
		cout << "Sunny";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  string str;
  cin >> str;
  for(int i=0; i<str.length(); i+=2){
    if(str[i] == '0' && str[i+1] == 'U'){
      cout << "nn";
      continue;
    }
    switch(str[i]){
    case '2': cout << "k"; break;
    case '3': cout << "s"; break;
    case '4': cout << "t"; break;
    case '5': cout << "n"; break;
    case '6': cout << "h"; break;
    case '7': cout << "m"; break;
    case '8': cout << "y"; break;
    case '9': cout << "r"; break;
    case '0': cout << "w"; break;
    }
    switch(str[i+1]){
    case 'T': cout << "a"; break;
    case 'L': cout << "i"; break;
    case 'U': cout << "u"; break;
    case 'R': cout << "e"; break;
    case 'D': cout << "o"; break;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>

int main(){
    long long int n, sum=0;
    
    scanf("%lld", &n);
    for (int i=1; i<=n; i++){
        if (i % 5 != 0){
            if (i % 3 != 0){
                sum += i;
            }
        }
    }
    printf("%lld\n", sum);

return 0;
}

Measured memory_bytes: 3244
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner cin = new Scanner(System.in);
    double r = cin.nextDouble();

    System.out.printf("%.6f %.6f\n", cal_area(r), cal_cirum(r));
  }

  private static double cal_cirum(double r) {
    return (r * 2 * Math.PI);
  }

  private static double cal_area(double r) {
    return (r * r * Math.PI);
  }
}

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

using namespace std;

int main(){
    int64_t n, k;
    cin >> n >> k;
    if (n <= k){
        cout << min(n, abs(k - n)) << endl;
        return 0;  
    }

    cout << min(n % k, k - n % k) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main()
{
    int x, a;
    cin >> x >> a;
    if (x < a)
        cout << 0 << endl;
    else
    {
        cout << 10;
    }
}

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

string ans[] = {"", "", "", "",
"aacd"
"bbcd"
"efgg"
"efhh",
"abc.."
"abc.."
"deeff"
"d.ghh"
"iigjj",
"abc..."
"abc..."
"d.eeff"
"dghh.."
".g.ijj"
"kk.ill",
"abc...."
"abc...."
"def...."
"def...."
"g..hhii"
"g..jjkk"
".llmmnn"};

int main() {
    int n; cin >> n;
    if (n <= 2) { cout << "-1\n"; return 0; }
    if (n == 3) { cout << "aa.\n..b\n..b\n"; return 0; }
    vector<string> s(n, string(n, '.'));
    int offset = 4 + n % 4;
    for (int x = 0; x < offset; x++)
        for (int y = 0; y < offset; y++) s[x][y] = ans[offset][offset*x+y];
    for (int i = offset; i < n; i += 4) {
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++) s[i+x][i+y] = ans[4][4*x+y];
    }
    for (string l : s) cout << l << endl;

    // // check
    // unordered_set<char> st;
    // for (int x = 0; x < n; x++) if (s[x][0] != '.') st.insert(s[x][0]);
    // int k = st.size();
    // assert (k != 0);

    // for (int x = 0; x < n; x++) {
    //     st.clear();
    //     for (int y = 0; y < n; y++) if (s[x][y] != '.') st.insert(s[x][y]);
    //     assert (st.size() == k);
    // }
    // for (int y = 0; y < n; y++) {
    //     st.clear();
    //     for (int x = 0; x < n; x++) if (s[x][y] != '.') st.insert(s[x][y]);
    //     assert (st.size() == k);
    // }
    // cerr << "OK" << endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	ll n;
 	cin >> n;
 	cout << (n-1)*n/2;
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

class PriorityQueue:

    #初期化
    def __init__(self,heap):
        self.heap = heap
        heapify(self.heap)
    
    #値の追加
    def push(self,item):
        heappush(self.heap,item)
    
    #値の取り出し
    def pop(self):
        return heappop(self.heap)
    
    #値を追加して取り出し
    def pushpop(self,item):
        return heappushpop(self.heap,item)
    
    #データ構造の中身を見る
    def __call__(self):
        return self.heap
    
    #heapの長さ
    def __len__(self):
        return len(self.heap)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    heap = []
    q = PriorityQueue(heap)
    q.push(-a[0])
    ans = 0
    for i in range(n-1):
        p = q.pop()
        ans += -p
        q.push(-a[i+1])
        q.push(-a[i+1])
    print(ans)    

Measured memory_bytes: 32048
#include<iostream>
#include<iomanip>

using namespace std;

void Main(){
  string s;
  cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000
using namespace std;
int f[410][410],g[410][410],n,Ma,Mb,a[50],b[50],c[50],ans;
int main()
{
    cin >> n >> Ma >> Mb;
    for (int i = 0;i < n;i++)
        cin >> a[i] >> b[i] >> c[i];
    for (int i = 0;i <= 400;i++)
        for (int j = 0;j <= 400;j++)
            f[i][j] = inf;
    f[0][0] = 0;
    for (int k = 0;k < n;k++)
    {
        memcpy(g,f,sizeof(f));
        for (int i = 0;i <= 400;i++)
            for (int j = 0;j <= 400;j++)
            {
                int x = i+a[k];
                int y = j+b[k];
                if (x>400||y>400) continue;
                g[x][y] = min(g[x][y],f[i][j]+c[k]);
            }
        memcpy(f,g,sizeof(f));
    }
    ans = f[Ma][Mb];
    for (int i = 2;(Ma*i<=400)&&(Mb*i<=400);i++) ans = min(ans,f[Ma*i][Mb*i]);
    if (ans >= inf) printf("-1\n");
    else printf("%d\n",ans);
}


Measured memory_bytes: 1536
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<vector>
#include<map>
#include<queue>
#define ll long long
using namespace std;
int main(){
    ll ans=0;
    ll n;
    int m;
    cin>>n>>m;
    while(m--){
    	ll a;
    	cin>>a;
    	ans+=a;
	}
	if(n>=ans){
		cout<<n-ans<<endl;
	}else{
		cout<<"-1\n";
	}
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<char>> C(H, vector<char>(W, '*'));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> C[i][j];
		}
	}
	ll result = 0;
	for (int i = 0; i < (1 << H); i++) {
		for (int j = 0; j < (1 << W); j++) {
			//db(i); db(j);
			vector<vector<char>> T = C;
			for (int r = 0; r < H; r++) {
				if (i & (1 << r)) {
					for (int cc = 0; cc < W; cc++) {
						T[r][cc] = 'r';
					}
				}
			}
			for (int c = 0; c < W; c++) {
				if (j & (1 << c)) {
					for (int rr = 0; rr < H; rr++) {
						T[rr][c] = 'r';
					}
				}
			}
			int counter = 0;
			for (int r = 0; r < H; r++) {
				for (int c = 0; c < W; c++) {
					if (T[r][c] == '#') counter++;
				}
			}
			if (counter == K) result++;
		}
	}
	cout << result << endl;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        cout << 'x';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    vi v(n);
    forn(n) cin >> v[i];
    sort(all(v));
    ll res = 0;
    for(int i = 0; i < n - 2; i++) {
        for(int j = i + 1; j < n - 1; j++) {
            for(int k = j + 1; k < n; k++) {
                if(v[i] + v[j] > v[k]) {
                    res++;
                }
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
w, h, x, y, r = gets.chomp.split.map(&:to_i)

if x < 0 || y < 0
  puts "No"
elsif x + r == 0 || y + r == 0
  puts "No"
elsif x + r > w || y + r > h
  puts "No"
else
  puts "Yes"
end



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

#define int long long
const int MOD = 1000000007LL;

signed main(){

    int n, m; cin >> n >> m;
    vector<vector<int> > adj(n);
    vector<int> d(n, 0);
    vector<int> dp(n, 0);
    vector<bool> used(n, false);
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--;
        y--;
        adj[x].push_back(y);
        d[y]++;
    }

    queue<int> q;
    for(int i = 0; i < n; i++){
        if(d[i] == 0){
            q.push(i);
            used[i] = true;
        }
    }

    while(!q.empty()){

        int u = q.front();
 
        q.pop();
        for(auto v : adj[u]){
            if(!used[v]){
                dp[v] = max(dp[v], dp[u] + 1);
                d[v]--;
                if(d[v] == 0){
                    used[v] = true;
                    q.push(v);
                }
            }
        }
    }

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

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

Measured memory_bytes: 7296
import itertools
N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
G = [list(map(int, input().split())) for _ in range(N)]
count_color = [[0 for _ in range(C+1)] for _ in range(3)]
for y in range(N):
  for x in range(N):
    count_color[(x+y)%3][G[y][x]] += 1
ans = 10**12
for colors in itertools.permutations(range(1, C+1), 3):
  iwakan = 0
  for mod in range(3):
    for c in range(1, C+1):
      iwakan += D[c-1][colors[mod]-1]*count_color[mod][c]
  if iwakan < ans:
    ans = iwakan
print(ans)



Measured memory_bytes: 5620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
//#include <tr1/unordered_map>
#define maxn 100005
#define maxint 1000000007
//using namespace tr1;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",n%2==0?n/2-1:n/2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 5010, mod = 1e9 + 7;
int nt[N << 1], to[N << 1], head[N], cnt = 0;

void add(int x, int y) {
  to[++cnt] = y;
  nt[cnt] = head[x];
  head[x] = cnt;
}

int n, s[N], sz[N];
void predfs(int u, int fa) {
  sz[u] = 1;
  for(int i = head[u]; i; i = nt[i]) {
    if(to[i] != fa) {
      predfs(to[i], u);
      sz[u] += sz[to[i]];
      s[u] = max(s[u], sz[to[i]]);
    }
  }
  s[u] = max(s[u], n - sz[u]);
}

int ny[N], jc[N];
int pls(int x, int y) {
  return (x += y) >= mod ? x - mod : x;
}

void Add(int &x, int y) {
  x = pls(x, y);
}

int sub(int x, int y) {
  return (x -= y) < 0 ? x + mod : x;
}

void Sub(int &x, int y) {
  x = sub(x, y);
}

int mul(int x, int y) {
  return 1ll * x * y % mod;
}

void Mul(int &x, int y) {
  x = mul(x, y);
}

int q_pow(int x, int y) {
  int ans = 1;
  for(; y; y >>= 1) {
    if(y & 1) Mul(ans, x);
    Mul(x, x);
  }
  return ans;
}

int C(int x, int y) {
  if(x < y) return 0;
  int pos = mul(jc[x], mul(ny[y], ny[x - y]));
  return pos;
}

void init() {
  jc[0] = 1;
  for(int i = 1; i < N; ++i)
    jc[i] = mul(jc[i - 1], i);
  ny[N - 1] = q_pow(jc[N - 1], mod - 2);
  for(int i = N - 2; i >= 0; --i)
    ny[i] = mul(ny[i + 1], i + 1);
}

int val[N], f[N];
int main() {
  init();
  scanf("%d", &n);
  for(int i = 2, x, y; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  predfs(1, 0);
  int zx = 0;
  for(int i = 1; i <= n; ++i) {
    if(!zx || s[zx] > s[i]) zx = i;
  }
//  printf("zx = %d\n", zx);
  if(n % 2 == 0 && s[zx] == n / 2) {
    printf("%d\n", mul(jc[n / 2], jc[n / 2]));
    exit(0);
  }
  int tot = 0;
  for(int i = head[zx]; i; i = nt[i]) {
    if(sz[to[i]] < sz[zx]) val[++tot] = sz[to[i]];
  }
  if(zx != 1) val[++tot] = n - sz[zx];
  int now = 0;
  f[0] = 1;
  for(int i = 1; i <= tot; ++i) {
    for(int v = now + val[i]; v >= 1; --v) {
      for(int t = 1; t <= val[i]; ++t) {
        if(v < t) break;
        Add(f[v], mul(mul(C(val[i], t), C(val[i], t)), mul(jc[t], f[v - t])));
      }
    }
    now += val[i];
  }
  int ans = 0;
  for(int i = 0; i < n; ++i) {
//    printf("f[%d] = %d\n", i, f[i]);
    if(i & 1) Sub(ans, mul(f[i], jc[n - i]));
    else Add(ans, mul(f[i], jc[n - i]));
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
    string S;
    cin >> S;
    set<int> st(S.begin(), S.end());
    if (S.size() == st.size()) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	string s;

	cin >> s;

	if (s == "AKIHABARA") { printf("YES");return 0; }
	if (s == "KIHABARA") { printf("YES");return 0; }

	if (s == "AKIHBARA") { printf("YES");return 0; }
	if (s == "AKIHABRA") { printf("YES");return 0; }
	if (s == "AKIHABAR") { printf("YES");return 0; }
	if (s == "KIHBARA") { printf("YES");return 0; }
	if (s == "KIHABRA") { printf("YES");return 0; }
	if (s == "KIHABAR") { printf("YES");return 0; }
	if (s == "AKIHBRA") { printf("YES");return 0; }
	if (s == "AKIHBAR") { printf("YES");return 0; }
	if (s == "AKIHABR") { printf("YES");return 0; }
	if (s == "KIHBRA") { printf("YES");return 0; }
	if (s == "KIHBAR") { printf("YES");return 0; }
	if (s == "KIHBRA") { printf("YES");return 0; }
	if (s == "KIHABR") { printf("YES");return 0; }
	if (s == "AKIHBR") { printf("YES");return 0; }
	if (s == "KIHBR") { printf("YES");return 0; }
	cout << "NO";
	
	

}


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

long x[333];
void s0(int i) {
    cout << "< 2 2 " << i << '\n';
    x[i] = x[2] < x[2];
}
void s1(int i) {
    cout << "+ 0 1 7\n< 8 7 " << i << '\n';
    x[7] = x[0] + x[1];
    x[i] = x[8] < x[7];
}
void sh(int i, int j) {
    while(j--) {
        cout << "+ " << i << ' ' << i << ' ' << i << '\n';
        x[i] = x[i] + x[i];
    }
}
void add(int i, int j) {
    cout << "+ " << i << ' ' << j << ' ' << i << '\n';
    x[i] = x[i] + x[j];
}
void cmp(int k, int i, int j) {
    cout << "< " << i << ' ' << j << ' ' << k << '\n';
    x[k] = x[i] < x[j];
}
int main() {
    // cin >> x[0] >> x[1];
    cout << 36307 << '\n';
    for(int l = 0; l < 2; l++) {
        s0(3), s0(4), s0(5);
        for(int i = 31; i--;) {
            s1(6);
            sh(6, i);
            add(3, 6);
            s1(6);
            s0(5);
            add(5, l);
            add(5, 6);
            cmp(5, 3, 5);
            add((l + 1) * 100 + i, 5);
            sh(5, i);
            add(4, 5);
            s0(3);
            add(3, 4);
        }
        for(int i = 31; i--;)
            cerr << x[(l + 1) * 100 + i];
        cerr << endl;
    }
    for(int i = 0; i < 31; i++) {
        for(int j = 0; j < 31; j++) {
            s1(3);
            cmp(4, 100 + i, 3);
            cmp(3, 4, 200 + j);
            sh(3, i + j);
            add(2, 3);
        }
    }
    cerr << x[2] << endl;
    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((p[0] * p[1]) % 2 == 0 ? "Even" : "Odd");
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

struct obj
{
	long int a,b,c,d;
};

long int n,m,q, ans = 0;
vector<obj> v;
vector<long int> cur;

void solve(long int idx){
	if(idx == n + 1){
		long int sum = 0;
		for(auto ele : v){
			if(cur[ele.b] - cur[ele.a] == ele.c)
				sum += ele.d;
		}
		ans = max(ans,sum);
		return;
	}

	for(long int i = cur[idx - 1]; i <= m; i++){
		cur[idx] = i;
		solve(idx + 1);
	}
}

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   cin>>n>>m>>q;
   v.resize(q);
   cur.resize(n + 1);

   cur[0] = 1;

   for(long int i = 0; i < q; i++)
   	   cin>>v[i].a>>v[i].b>>v[i].c>>v[i].d;

   solve(1);
   cout<<ans;

   return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
k = []
s = []
for i in range(M) :
    ks = list(map(int,input().split()))
    k.append(ks[0])
    s.append(ks[1:])
p = [int(x) for x in input().split()]

ans = 0
for i in range(2**N) :
    pat = str("{:0>{}b}".format(i, N))
    flag = True
    for j in range(M) :
        swit = 0
        for x in range(k[j]) :
            if pat[s[j][x]-1] == "1" :
                swit += 1
        if swit%2 != p[j] :
            flag = False
    if flag == True :
        ans += 1

print(ans)



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  string s;
  cin >> s;
  if(s == "ABC")cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


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

using namespace std;

#define N 104730

bool table[N];
vector<int> prime;

int main() {
    int size = 0;
    for (int i = 2; i < N; i++) {
        if (table[i] == false) {
            for (int j = i; j < N; j += i) {
                table[j] = true;
            }
            prime.push_back(i);
            size++;
        }
    }
    int n;
    while (cin >> n && n != 0) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += prime[i];
        }
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1424
N = int(input())
a = [0]*32
i = 0
ans = 0

if(N==0):	print(0)

else:
  while N != 1 :
    if(N%2==0):
      a[i] = 0
      N=N/(-2)
      i = i+1
    else:
      a[i] = 1
      N = (N-1)/(-2)
      i = i+1
  a[i] = 1
  for k in range(i+1):
    ans = ans + a[k] * 10**k
  print(ans)

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

int main(){
    int n;
    cin>>n;
    int p[n];
    int i =0, l;
    while(i<n && cin>>l){
        p[i] = l;
        i++;
    }

    int c = 0;
    for(i = 1; i < n-1; i++){
        int q[3];
        for(int j = 0; j < 3; j++){
            q[j] = p[i+j-1];
        }
        for(int s = 0; s < 2; s++){
            for(int t = 2; t > s; t--){
                if(q[s] > q[t]){
                    int tmp = q[s];
                    q[s] = q[t];
                    q[t] = tmp;
                }
            }
        }
        if(q[1] == p[i])
            c++;
    }

    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

string S, T;

int main(void){
    cin >> S >> T;
    int s = S.size(), t = T.size();

    int res;
    for(int i = s - t; i >= 0; i--){
        bool flag = true;
        for(int j = 0; j < t; j++){
            if(S[i+j] != '?' and S[i+j] != T[j]) flag = false;
        }

        if(flag){
            for(int j = 0; j < i; j++) cout << (S[j] == '?' ? 'a' : S[j]);
            cout << T;
            for(int j = i + t; j < s; j++) cout << (S[j] == '?' ? 'a' : S[j]);
            cout << '\n';
            return 0;
        }
    }

    cout << "UNRESTORABLE" << '\n';

    return 0;
}

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

string itos(int n){
int a,b,c,d;
a=n/1000;
n=n%1000;
b=n/100;
n=n%100;
c=n/10;
n=n%10;
d=n;
string s=""; 
if(a>1) s=s+to_string(a);
if(a>0) s=s+"m";
if(b>1) s=s+to_string(b);
if(b>0) s=s+"c";
if(c>1) s=s+to_string(c);
if(c>0) s=s+"x";
if(d>1) s=s+to_string(d);
if(d>0) s=s+"i";
return s;
}


int sstoi(string s){
int l=s.length();
int ans=0,k=1;
for(int i=0;i<l;i++){
if('1'<s[i] && s[i]<='9'){
k=s[i]-'0';
}
else if(s[i]=='m'){
ans=ans+k*1000;
k=1;
}
else if(s[i]=='c'){
ans=ans+k*100;
k=1;
}
else if(s[i]=='x'){
ans=ans+k*10;
k=1;
}
else if(s[i]=='i'){
ans=ans+k;
k=1;
}

}

return ans;
}










int main() {
string s,t;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s>>t;
int ans=sstoi(s)+sstoi(t);
//cout<<sstoi(s)<<" "<<sstoi(t)<<endl;
cout<<itos(ans)<<endl;

}

	return 0;
}

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

long n,m,k,mod=998244353,ans=0;

long modpow(long modpow_x,long modpow_y) {
  long modpow_return=1;
  for(long i=1;i<=modpow_y;i*=2) {
    if(modpow_y/i%2==1) modpow_return=modpow_return*modpow_x%mod;
    modpow_x=modpow_x*modpow_x%mod;
  }
  return modpow_return;
}

int main() {
  cin >> n >> m >> k;
  long g=modpow(m-1,n-1)*m%mod;

  long ncr=1;
  for(long i=0;i<=k;i++) {
    ans=(g*ncr%mod+ans)%mod;
    ncr=ncr*(n-1-i)%mod;
    ncr=ncr*modpow(i+1,mod-2)%mod;
    g=g*modpow(m-1,mod-2)%mod;
  }
  if(k==n-1&&m==1) ans=1;
  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String moji = sc.next();
		char[] c = moji.toCharArray();
		moji = sc.next();
		char[] d = moji.toCharArray();
		moji = sc.next();
		char[] e = moji.toCharArray();
System.out.print(c[0]);


System.out.print(d[1]);
System.out.print(e[2]);
	}}

Measured memory_bytes: 21844
#include<cstdio>
#include <algorithm>
 
int main(){
  int n;
  scanf("%d", &n);

  double v[n];
  for(int i=0; i<n; i++){
    scanf("%lf", &v[i]);
  }
  
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(v[i] > v[j]){
        double tmp = v[i];
        v[i] = v[j];
        v[j] = tmp;
      }
    }
  }
  printf("\n");
  
  double x, y, ans;
  for(int i=0; i<n-1; i++){
    x = v[i];
    y = v[i+1];
    ans = (x + y) / 2;
    v[i+1] = ans;
  }
  
  
  printf("%lf\n", v[n-1]);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
   
int n,k;
cin>>n>>k;
int h[n+1];
for(int i=1;i<=n;i++)
cin>>h[i];
h[0]=INF;
int dp[n+1];
dp[0]=INF;
dp[1]=0;
for(int i=2;i<=n;i++)
{
dp[i]=INF;
for(int j=i-1;j>=max((int)1,i-k);j--)
dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
}
cout<<dp[n]<<endl; 
    
}




int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

Measured memory_bytes: 5252
#include<stdio.h>
#include<math.h>
 
int main(){
    int i,j,n,m,total;
    while(1){
        total=0;
        scanf("%d",&n);
        if(n==0) break;
        m=n;
        for(i=2;i<sqrt(n);i++){
            if(n%i==0){
                if(i==n/i){
                    total+=i;
                    continue;
                }
                total=total + i + n/i;
            }
        }
        if(total) total++;
        if(total==m){ 
            printf("perfect number\n");
        }else if(total>m){
            printf("abundant number\n");
        }else if(total<m){
            printf("deficient number\n");
        }
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const int MOD = 1000000007;

vector<int> brdgs(7, -1);

int calc(int n){
  if(n < 0) return 1;
  if(brdgs[n] != -1) return brdgs[n];
  
  if(n == 0) return 1;
  if(n == 1) return 2;
  else{
    brdgs[n] = calc(n-2) + calc(n-1);
    return brdgs[n];
  }
}



int main(){
  int H, W, K;
  cin >> H >> W >> K;

  ll dp[110][10];
  for(int i = 0; i < 110; i++){
    for(int j = 0; j < 10; j++){
      dp[i][j] = 0;
    }
  }

  for(int i = 0; i < 7; i++) brdgs[i] = calc(i);

  dp[0][0] = 1;

  for(int i = 0; i < H; i++){
    for(int k = 0; k < W; k++){
      
      if(k==0){
        dp[i+1][k] += dp[i][k] * calc(W-2);
        dp[i+1][k] %= MOD;
        dp[i+1][k+1] += dp[i][k] * calc(W-3);
        dp[i+1][k+1] %= MOD;
        continue;
      } else if(k < W-1){

        dp[i+1][k] += dp[i][k] * calc(k-1) * calc(W-k-2);
        dp[i+1][k] %= MOD;
        dp[i+1][k+1] += dp[i][k] * calc(k-1) * calc(W-k-3);
        dp[i+1][k+1] %= MOD;
        dp[i+1][k-1] += dp[i][k] * calc(k-2) * calc(W-k-2);
        dp[i+1][k-1] %= MOD;
      } else {
        dp[i+1][k] += dp[i][k] * calc(W-2);
        dp[i+1][k] %= MOD;
        dp[i+1][k-1] += dp[i][k] * calc(W-3);
        dp[i+1][k-1] %= MOD;
      }
    }
  }

  cout << dp[H][K-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VVI = vector<vector<int>>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    vector<ll> mid(n + 1);
    for (int i = 0; i < n; i++)
    {
        int idx = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
        mid[i + 1] = mid[i] + idx;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        int idx = distance(b.begin(), lower_bound(b.begin(), b.end(), c[i]));
        ans += mid[idx];
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

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

using namespace std;

#define ll long long;
#define pb push_back



int main()
{
   stack<char>st;

   string str;
   cin >> str;

   int cnt = 0;

   for(int i = 0; i < str.length(); i++)
   {
       if( st.empty() )st.push( str[i] );
       else{
          if(  str[i] != st.top() )
          {
               st.pop();
               cnt += 2;
          }
          else st.push(str[i]);
       }
   }

   cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();

        long R = (N+1L)*N-1L;

        for (long i = 2; 2*i <= N; i++) {
            R += (((N/i)*i+i*2L)*((N-i)/i))/2L;
        }

        System.out.println(R);
    }

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


Measured memory_bytes: 35632
using System;

public class Test {
  public static void Main() {
    string[] input = Console.ReadLine().Trim().Split(' ');    
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int sum = 0;
    int count = 0;
    
    if(B == 1) {
      Console.WriteLine(0);
      return;
    }
    while(sum < B) {
      if(sum == 0) {
        sum += A;
      } else {
        sum += (A - 1);
      }
      count++;
    }
    Console.WriteLine(count);  
  }
}

Measured memory_bytes: 13140
//Tsundoku
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
#include <stack>
using namespace std;
const int INF = 1 << 29;

template<class T>
bool isOK(vector<T> a, int index, T key) 
{
    // ここの比較でupper boundかlower bound か決まる
    if (a[index] > key) {
        return true;
    }
    else {
        return false;
    }
}

template<class T>
T binarysearch(vector<T> a, T key) 
{
    int left = -1;
    int right = (int) a.size();
    while (abs(right - left) > 1) {
        int mid = left + (right - left) / 2;
        /*
        cout << "left " << left << endl;
        cout << "right " << right << endl;
        cout << "mid " << mid << endl;
        */
        if (isOK(a, mid,key)) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    //cout << "return " << right << endl;
    return right;
}


int main ()
{
    unsigned long long N,M,K;
    cin >> N >> M >> K;
    vector<long long> A(N);
    vector<long long> accA(N+1,0);
    //stack<int>A;
    
    // 累積和をつくる
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        accA[i+1] = accA[i] + A[i];
    }
    vector<long long> B(M);
    vector<long long> accB(M+1,0);
    //stack<int> B;
    for (int j = 0; j < M; j++) {
        cin >> B[j];
        accB[j+1] = accB[j] + B[j];
    }
    long long ans = 0;
    int ok = M;
    for (int i = 0; i <= N; i++) {
        if (accA[i] > K) {
            break;
        }
        while (ok >= 0 && accA[i] + accB[ok] > K) {
            ok--;
        }
        if (ok >= 0) {
            ans = max(ans, (long long) i + ok);
        }
    }

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


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,k,v[200001],minim=1e10;
bool ok(ll val)
{
    ll x=val;
    ll nrop=0;
    for(int i=1;i<=n;i++)
    {
        ll bc=v[i]/x;
        if(v[i]%x)
            bc++;
        nrop+=bc-1;
    }
    return nrop<=k;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    ll st=1;
    ll dr=1e9;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        if(ok(mij))
        {
            minim=min(mij,minim);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    cout<<minim;
    return 0;
}


Measured memory_bytes: 5168
#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 "ctime"

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-9;

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

int Search(vector<string>&s, int y, int x) {
	int ret = MOD;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (i == 0 && j == 0)continue;
			bool flag = false;
			int ny = y + i, nx = x + j;
			while (ny >= 0 && ny < H&&nx >= 0 && nx < W&&s[ny][nx] == 'X') {
				flag = true;
				s[ny][nx] = '.';
				ny += i, nx += j;
			}
			if (flag&&ny >= 0 && ny < H&& nx >= 0 && nx < W) {
				ret = min(ret, Search(s, ny, nx));
			}
			if (flag&&(ny + 1 > H||(ny+1==H&&nx>=0&&nx<W))) {
				ret = 0;
			}
			ny -= i, nx -= j;
			while (ny != y || nx != x) {
				s[ny][nx] = 'X';
				ny -= i, nx -= j;
			}
		}
	}
	return ret + 1;
}

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

	H = 19, W = 15;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	int sy, sx;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 'O') {
				sy = i,sx = j, s[i][j] = '.';
			}
		}
	}
	int ans = Search(s, sy, sx);
	if (ans >= MOD)ans = -1;
	cout << ans << endl;
}


Measured memory_bytes: 3256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[200010], k;
int cnt[200010];
bool bl[200010];
int cnt2;

signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	int p = 1;
	bl[1] = true;
	while (1) {
		cnt2++;
		p = a[p];
		if (cnt2 == k) {
			cout << p << endl;
			return 0;
		}
		if (bl[p]) {
			int x = cnt2 - cnt[p];
			int s = cnt[p] + (k - cnt[p]) % x;
			if (s == 0)cout << 1 << endl;
			else for (int j = 1; j <= n; j++)if (cnt[j] == s)cout << j << endl;
			return 0;
		}
		cnt[p] = cnt2;
		bl[p] = true;
	}
}

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

const int MAX_N = 100;
const int64_t MOD = 1e9 + 7;
int n;
int64_t dp[MAX_N + 1][4][4][4];

void solve() {
    dp[0][0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int a = 0; a < 4; a++) {
            for (int b = 0; b < 4; b++) {
                for (int c = 0; c < 4; c++) {
                    for (int d = 0; d < 4; d++) {
                        if ((b == 1 && c == 2 && d == 3) || // AGC*
                        (b == 1 && c == 3 && d == 2) ||     // ACG*
                        (b == 2 && c == 1 && d == 3) ||     // GAC*
                        (a == 1 && b == 2 && d == 3) ||     // AG*C
                        (a == 1 && c == 2 && d == 3)) {     // A*GC
                            continue;
                        }
                        dp[i][b][c][d] = (dp[i][b][c][d] + dp[i - 1][a][b][c]) % MOD;
                    }
                }
            }
        }
    }

    int64_t ans = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                ans = (ans + dp[n][i][j][k]) % MOD;
            }
        }
    }

    cout << ans << endl;
}

int main() {
    cin >> n;
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 110000
using namespace std;
struct sl
{
	int l,r;
} a[N];
int i,j,n,m,k,ans;
bool cmp(sl a,sl b)
{
	return a.r<b.r;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		a[i].l=x-y;
		a[i].r=x+y;
	}
	sort(a+1,a+n+1,cmp);
	k=1;ans=1;
	for (i=2;i<=n;i++)
	if (a[i].l>=a[k].r) ans++,k=i;
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  int INF = INT_MAX;
  ll mod = 998244353;
  // lld PI = 3.141592653;







  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      int n;
      cin>>n;
      int k;
      cin>>k;
      vector<pair<int,int>> seg;
      for (int i = 0;i<k;i++){
        int a,b;
        cin>>a>>b;
        seg.push_back({a,b});
      }
      vector<ll> pref(n+1);
      vector<ll> dp(n+1);
      dp[1] = 1;
      dp[0] = 0;
      pref[0] = 0;
      pref[1] = 1;
      for (int i = 2;i<=n;i++){
        for (int t = 0;t<k;t++){
          dp[i] = (dp[i] + pref[max(i - seg[t].first, 0)] - pref[max(i - seg[t].second-1, 0)] + mod)%mod;
          // cout<<i<<" "<<max(i - seg[t].first, 0)<<" "<<max(i - seg[t].second-1, 0)<<endl;
        }
        // cout<<i<<" "<<dp[i]<<endl;
        pref[i] = (pref[i-1] + dp[i])%mod;
      }
      cout<<dp[n]<<"\n";

}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: usize = read();
    let a: usize = read();
    let b: usize = read();
    let mut ans = "NG".to_string();

    for i in a..=b {
        if i % k == 0 {
            ans = "OK".to_string();
            break;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 2124
import numpy as np

n,k=[int(i) for i in input().split()]
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

h.sort()

mini=10000000000
for i in range(n-k+1):
    diff=h[i+k-1]-h[i]
    if(mini>diff):
        mini=diff
print(mini)


Measured memory_bytes: 21776
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {

int N,M;
cin>>N>>M;
Graph G(N+1);
map<pair<int,int>,ll> diff;
rep(i,M){
  int L,R,D;
  cin>>L>>R>>D;
  G[L].push_back(R);
  G[R].push_back(L);
  diff[make_pair(L,R)]=D;
  diff[make_pair(R,L)]=-D;
  
}
vector<ll> place(N+1, -1e10); // 全頂点を「未訪問」に初期化
    queue<int> que;
    bool judge=true;
rep3(i,N){
  if((G[i].size()!=0)&&(place[i]!=-1e10))continue;
    // 初期条件 (頂点 0 を初期ノードとする)
    place[i] = 0;
    que.push(i); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (place[nv] != -1e10){
              if(place[nv]!=place[v]+diff[make_pair(v,nv)]){
                judge=false;
              }
            }
            else{

            

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            place[nv] = place[v] + diff[make_pair(v,nv)];
            que.push(nv);
            }
        }
    }
}
if(judge){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
}

Measured memory_bytes: 35572
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long 
#define db double
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
#define N 100010
int n, a[N], Ans = 0, cnt = 0, t; 
int main()
{
   scanf("%d", &n);
   memset(a, 0, sizeof(a)); 
   for (int i = 1; i <= n; i++)
      scanf("%d", &t), a[t]++;
   for (int i = 1; i <= 100000; i++)
      if (a[i] & 1) {
	 Ans += (a[i] - 1) / 2;
	 a[i] = 1;
      }
      else if (a[i] > 0) {
	 Ans += (a[i] - 2) / 2;
	 a[i] = 2; cnt++; 
      }
   Ans += cnt / 2; cnt %= 2;
   if (cnt > 0) Ans++;
   printf("%d\n", n - Ans * 2); 
   return 0; 
}


Measured memory_bytes: 640