akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
struct UnionFind {
    int n;
    vector<int> parent;

    UnionFind() {}
    UnionFind(int nmemb) {
        init(nmemb);
    };

    void init(int nmemb) {
        parent.clear();
        parent.assign(nmemb, -1);
    };

    int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        return parent[x] = root(parent[x]);
    };

    void unite(int x, int y) {
        x = root(x);
        y = root(y);

        if (x == y) return;

        if (parent[y] < parent[x]) swap(x, y);

        parent[x] += parent[y];
        parent[y] = x;
        
        return;
    };
    
    bool same(int x, int y) {
        return root(x) == root(y);
    };
    int size(int x) {
        return -(parent[root(x)]);
    };
};
//===

llong n, m;
llong p[100005];
llong x, y;

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

    UnionFind uf(n + 1);

    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        uf.unite(p[x - 1], p[y - 1]);
    }

    llong ans = 0;
    for (int i = 1; i <= n; i++) {
        if (uf.same(i, p[i - 1])) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll N, res = 0;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    for (int i = 0; i < N+1; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];

    int a, b;
    for (int i = 0; i < N; i++) {
        a = min(A[i], B[i]);
        res += a;
        A[i] -= a; 
        B[i] -= a;
        
        b = min(A[i+1], B[i]);
        res += b;
        A[i+1] -= b;
        B[i] -= b;
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#ABC050C
N=int(input())
A=list(map(int,input().split()))
if N%2==1:
    if A.count(0)!=1:
        print(0)
        exit()
B=[0 for i in range(N//2)]
for a in A:
    if a == 0:
        continue
    elif a%2==(N+1)%2:
        B[a//2-N%2]+=1
    else:
        print(0)
        exit()
if B.count(2)==len(B):
    print(2**(N//2)%(10**9+7))
else:
    print(0)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
struct edge{int to,cost;};
vector<edge> graph[100010];
int color[100010];

void dfs(int now, int prev, int dist){
  color[now]=dist;
  for(auto &e : graph[now]){
    if(e.to != prev){
      dfs(e.to, now, (dist+e.cost)%2);
    }
  }
}

int main(){
  int n,u,v,w;
  cin >> n;
  for(int i=0;i<n-1;i++){
    cin >> u >> v >> w;
    u--;v--;w%=2;
    graph[u].push_back({v,w});
    graph[v].push_back({u,w});
  }
  dfs(0,-1,0);
  for(int i=0;i<n;i++){
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <vector>
#include <array>
#include <cmath>
#include <queue>

#define r(i, v, n) for(int i = v; i < n; i++)
#define re(i, v, n) for(int i = v; i <= n; i++)
#define rr(e, v) for(auto&& (e) : (v))

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

int main() {
    int r, g;
    cin >> r >> g;
    int x = (g - r) * 2 + r;
    cout << x;

    return 0;
}


Measured memory_bytes: 256
# 初期入力
import sys
input = sys.stdin.readline
N = input().strip()
if N[-1] =="2":
    print("hon")
if N[-1] =="4":
    print("hon")
if N[-1] =="5":
    print("hon")
if N[-1] =="7":
    print("hon")
if N[-1] =="9":
    print("hon")
if N[-1] =="0":
    print("pon")
if N[-1] =="1":
    print("pon")
if N[-1] =="6":
    print("pon")
if N[-1] =="8":
    print("pon")
if N[-1] =="3":
    print("bon")


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

int gcd(int x , int y){
  if(x < y){
    swap(x,y);
  }
  if(y == 0){
    return x;
  }
  return(gcd(x%y , y));
}

int main(){
  
  int n;
  cin >> n;
  vector<int> cont(n);

  for(int i = 0 ; i < n ; i++){
    cin >> cont.at(i);
  }
  
  int ans = 0;
  for(int i = 0 ; i < n ; i++){
    ans = gcd(ans , cont.at(i));
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    int x[n+1],y[m+1];
    rep(i,0,n) cin >> x[i];
    x[n] = X;
    rep(i,0,m) cin >> y[i];
    y[m] = Y;
    sort(x,x+n+1);
    sort(y,y+m+1);
    if(x[n] < y[0]) cout << "No War" << endl;
    else cout << "War" << endl;
}


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int strikes(int n, int a){
  if(n<=a)
    return 1;
  if(n%a == 0)
    return n/a;
  else return (n/a)+1;
}
int main(){
  int n, a;
  cin>>n>>a;
  cout<<strikes(n,a);
  return 0;
}
    

Measured memory_bytes: 256
import scipy.sparse.csgraph as c,numpy
s=numpy.int8([list(t[:-1])for t in open(0)][1:])
m=c.dijkstra(s)
i=m[0]%2<1
j=i^True
print((s[i][:,i].any()|s[j][:,j].any()or~int(m.max()))*-1)

Measured memory_bytes: 25320
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if((a * b) % 2 == 0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}


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

int main(){

  int a,b,q;
  string str,command,s;
  cin >>str>>q;
  for(int i=0;i<q;i++){
    cin >>command>>a>>b;
    if(command=="print"){
      cout <<str.substr(a,b-a+1)<<endl;}
    else if(command=="reverse"){
      reverse(str.begin()+a,str.begin()+b+1);
    }
    else if(command=="replace"){
      cin >>s;
      str.replace(str.begin()+a,str.begin()+b+1,s);
    }
      
  }


    return 0;
  }
      

    

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    cout << (N - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

str = [int(i) for i in input().split()]
n, d = str

s = [[int(j) for j in input().split()] for i in range(n)]
s = np.array(s)
count = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        tmp = np.sqrt(np.sum(np.power(s[i] - s[j], 2)))
        if tmp.is_integer() == True:
            count += 1
print(int(count/2))



Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int t[1000005];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < k; ++i) scanf("%d", &t[i]);
	sort(t, t + k);
	if(t[k-1] <= (n + 1) / 2) puts("0");
	else {
		printf("%d\n", 2 * t[k-1] - n - 1);
	} 
}


Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.trim().split(' ').map(Number)
	if (args[0] === 1) args[0] += 13
	if (args[1] === 1) args[1] += 13
	if (args[0] > args[1]) console.log('Alice')
	else if (args[1] > args[0]) console.log('Bob')
	else console.log('Draw')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e3+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N][N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			for(int j =1;j<=n;j++){
				dp[i][j]=1e18;
				if(i==j){
					dp[i][j]=0;
				}
			}
		}
		dp[x][y]=1;
		dp[y][x]=1;
		for(int i=1;i<n;i++){
			for(int j =i+1;j<=n;j++){
				int d =j-i;
				dp[i][j]=min(dp[i][j],d);
				dp[j][i]=min(dp[j][i],d);
			}
		}
		for(int i=1;i<n;i++){
			for(int j =i+1;j<=n;j++){
				dp[i][j]=min(dp[i][j],dp[i][x]+dp[x][y]+dp[y][j]);
				dp[j][i]=min(dp[i][j],dp[j][i]);
			}
		}
		map<int,int>mp;
		fn1{
			for(int j=i+1;j<=n;j++){
				mp[dp[i][j]]++;
			}
		}
		for(int i=1;i<n;i++)cout<<mp[i]<<endl;
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

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

int main()
{
	int a,b,c,d,sum=0;
	char s[100];

	cin>>a>>b>>c;

	if(a+b>=c && a<=c)	
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}
	

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

if N%2:
	S = N*(N+1)//2 - N
else:
	S = N*(N+1)//2 - N - 1

ans = []
for i, j in combinations(range(1, N+1), 2):
	p = N*(N+1)//2 - i
	if j == p-S:
		continue
	ans.append((i, j))

print(len(ans))
for x in ans:
	print(*x)

Measured memory_bytes: 10632
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int a,b,c;
    cin>> a >> b >> c;
    if(a == b && b == c){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
}

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

namespace AtCoder.Abc
{
    class QuestionE
    {
        /// <summary>
        /// B - Battle
        /// https://atcoder.jp/contests/abc164/tasks/abc164_b
        /// </summary>
      
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var num_ABCD = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            do
            {
                num_ABCD[2] = num_ABCD[2] - num_ABCD[1];
                num_ABCD[0] = num_ABCD[0] - num_ABCD[3];

            } while (num_ABCD[0] > 0 & num_ABCD[2] > 0);

            if (num_ABCD[2] <= 0) //高橋の勝ち
            {
                Console.WriteLine("Yes");
            }
            else if (num_ABCD[0] <= 0)　//青木の勝ち
            {
                Console.WriteLine("No");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28112
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int n,a[21],maxx,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a[i];
		if (a[i]>=maxx) ans++;
		maxx=max(maxx,a[i]);
	}
	cout<<ans;
	return 0;
}

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

unsigned long long ruijou(int n){
	if(n ==0) return 1;
	return 2 * ruijou(n-1);
}
int main(){
	unsigned long long h;
	cin >> h;
	int count = 0;
	unsigned long long ans = 0;
	while(h != 0){
		h = h/2;
		ans += ruijou(count);
		count++;
	}
	cout << ans << endl;
	
}

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

int main()
{
  int n,m,a;
  int yoko[3][1000];
  int i,j;

  while(1){
    cin>>n>>m>>a;
    if(n==0 && m==0 && a==0) break;
    for(i=0;i<m;i++){
      cin>>yoko[0][i]>>yoko[1][i]>>yoko[2][i];
    }

    for(i=1000;i>0;i--)
      for(j=0;j<m;j++)
	if(yoko[0][j]==i)
	  if(yoko[1][j]==a){
	    a=yoko[2][j];
	    break;
	  }else if(yoko[2][j]==a){
	    a=yoko[1][j];
	    break;
	  }

    cout<<a<<endl;
  }
}

Measured memory_bytes: 1168
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
if s % (n*(n+1)//2) != 0:
    print('NO')
    quit()
K = s // (n*(n+1)//2)
    
d = [a[(i+1)%n]-a[i] for i in range(n)]
cnt = 0
for x in d:
    if (K-x) % n != 0 or K-x < 0:
        print('NO')
        quit()
    cnt += (K-x) // n
print('YES' if cnt == K else 'NO')

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

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int main() {
	int n;
	while(cin >> n, n) {
		int ans = 0;
		int lim = sqrt(n);
		for(int i=0; i<=lim; i++) {
			for(int j=i; j<=lim && i*i+j*j<=n; j++) {
				for(int k=j; k<=lim && i*i+j*j+k*k<=n; k++) {
					int sq = n - i*i - j*j - k*k;
					if( k*k<=sq && ((int)sqrt(sq))*((int)sqrt(sq)) == sq ) {
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
//12/04/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
struct OverloadedNode{
    ll val,pos;
    bool operator < (const OverloadedNode &rhs) const {
        if(val==rhs.val) return pos<rhs.pos;
        else return val<rhs.val;
    }
};
//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//typedef tree<OverloadedNode,null_type,less<OverloadedNode>,rb_tree_tag,tree_order_statistics_node_update>OverloadedPbds;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
//vector<ll>v;
//deque<ll>dq;
//stack<ll>stk;
//map<ll,ll>mp;
//unordered_map<ll,ll>ump;
//set<ll>st;
//multiset<ll>mst;
//unordered_set<ll>ust;
//unordered_multiset<ll>umst;
//priority_queue<ll,deque<ll>,greater<ll>>pq;
//Pbds<ll>ost;
/*OverLoaded Containers*/
//vector<OverloadedNode>v;
//deque<OverloadedNode>dq;
//stack<OverloadedNode>stk;
//map<OverloadedNode,OverloadedNode>mp;
//set<OverloadedNode>st;
//multiset<OverloadedNode>mst;
//priority_queue<OverloadedNode>pq;
//OverloadedPbds oost;
/*Global Variables*/

int main(){
    _fastio
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout<<"Yes"<<en;
    else cout<<"No"<<en;



    return 0;
}


Measured memory_bytes: 3636
function main(input) {
  const [n, l] = input.trim().split(" ").map(n => Number(n));
  let result = 0;
  let reduce = l;
  for (let i = 0; i < n; i++) {
  	const taste = l + i;
    result += taste;
    if (Math.abs(taste) < Math.abs(reduce)) reduce = taste;
  }
  console.log(result - reduce);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N, K = list(map(int, input().split()))
C = 998244353
L = [None]*K
for j in range(K):
    l, r = list(map(int, input().split()))
    L[j] = [l, r+1]

dp = [0]*N
dp[0] = 1
imos = [0]*(N+1)
imsm = [0]*N

for i in range(N-1):
    if i > 0:
        imsm[i] = imsm[i-1]+imos[i]
        dp[i] = imsm[i] % C
    a = dp[i]
    # print(i,dp)
    for j in range(K):
        l, r = L[j]
        nl = min(i+l, N)
        nr = min(i+r, N)
        imos[nl] += a
        imos[nr] -= a
        # print(i, imos)
dp[N-1] = (imsm[N-2]+imos[N-1]) % C
print(dp[N-1])


Measured memory_bytes: 78960
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n,k;
  cin>>n>>k;
  cout<<dup(n-1,k-1)<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    long S[n];
    
    for(int i = 0; i < n; i++){
        long s;
        cin >> s;
        S[i] = s;
    }
    
    int q;
    cin >> q;
    long T[q];
    
    for(int j = 0; j < q; j++){
        long t;
        cin >> t;
        T[j] = t;
    }
    
    int sum = 0;
    for(int k = 0; k < q; k++){
        for(int l = 0; l < n; l++){
            if(T[k] == S[l]){
                sum++;
                break;
            }
        }
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3172
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


//https://atcoder.jp/contests/abc089/tasks/abc089_d

signed main(){

	int N, C;
	cin >> N >> C;
	vector<int> s(N), t(N), c(N);
	rep(i, N){
		cin >> s[i] >> t[i] >> c[i];
		c[i]--;
	}
	
	vector<int> used[30];
	rep(i, C) used[i].resize(100002);

	// imos
	rep(ch, C){
		rep(i, N){
			if (c[i] == ch){
				// 前とつながっている場合
				if (used[ch][s[i] + 1] < 0){
					used[ch][s[i] + 1] = 0;
					used[ch][t[i] + 1]--;
				}
				else{
					used[ch][s[i]]++; used[ch][t[i] + 1]--;
				}
			}
		}
	}
	rep(ch, C){
		rep(i, 100000){
			used[ch][i + 1] += used[ch][i];
		}
	}
	int ans = 0;
	rep(i, 100001){
		int ret = 0;
		rep(ch, C){
			if (used[ch][i]) ret++;
		}
		ans = max(ans, ret);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 26112
#include<iostream>
using namespace std;
static const int MAX = 1000000;

int insertionSort(int *A, int n, int g){
  int cnt=0;
  for(int i=g; i<n; i++){
    int v = A[i];
    int j = i - g;
    while(j>=0 && A[j]>v){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
  return cnt;
}

void shellSort(int *A, int n){
  int G[n], cnt=0;
  int i=0;
  G[0] = 1;

  while(1){
    if(3*G[i]+1 > n) break;
    i++;
    G[i] = 3*G[i-1] + 1;
  }

  int m = i + 1;
  for(int j=m-1; j>=0; j--){
    cnt += insertionSort(A, n, G[j]);
  }
  cout << m << endl;
  for(int i=m-1; i>=0; i--){
    if(i!=m-1) cout << " ";
    cout << G[i];
  }
  cout << endl << cnt << endl;
  for(int i=0; i<n; i++){
    cout << A[i] << endl;
  }
  return;
}

int main(){
  int n, A[MAX];
  
  cin >> n;
  for(int i=0; i<n; i++)
    cin >> A[i];

  shellSort(A, n);
  return 0;
}



Measured memory_bytes: 7044
#include <stdio.h>

int main(void){
	int Sec=0;
	int h, m, s;
	scanf("%d", &Sec);
	h = Sec / 3600;
	m = (Sec-h*3600) / 60;
	s = Sec - h*3600 - m*60;
	printf("%d:%d:%d\n",h,m,s);
	scanf("%d", &Sec);
	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int, int> P;


class UnionFind{
public:
	vector<int> par,num;
 
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    for(int i=0;i<m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        uf.unite(x-1,y-1);
    }
    int count=0;
    vector<bool> check(n,false);
    for(int i=0;i<n;i++){
          if(check.at(uf.find(i))==false){
              count++;
              check.at(uf.find(i))=true;
          }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    char c;
   int  i , x=0, y=0;

   for(i=0; i<4; i++){
            scanf("%c" , &c);
            if(c=='+'){
               x=x+1 ;
            } else if(c == '-') {
                x=x-1 ;
            }
   }
       printf ("%d",x) ;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
piys = [[] for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y, i))

ans = [None]*M
for p, iys in enumerate(piys):
    iys.sort()
    for k, (y, i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1, k+1)

for i in ans:
    print(i)

Measured memory_bytes: 35920
#include <iostream>
using namespace std;
string b[8];
int main() {
    for (int i=0; i<8; i++) cin>>b[i];
    cout<<90<<endl;
    for (int i=0; i<8; i++) {
        for (int j=7; j>=0; j--) {
            cout<<b[j][i];
        }
        cout<<endl;
    }
    cout<<180<<endl;
    for (int i=7; i>=0; i--) {
        for (int j=7; j>=0; j--) {
            cout<<b[i][j];
        }
        cout<<endl;
    }
    cout<<270<<endl;
    for (int i=7; i>=0; i--) {
        for (int j=0; j<8; j++) {
            cout<<b[j][i];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1180
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, X, T; cin >> N >> X >> T;

	if (N%X) {
		cout << (N / X)*T + T << endl;
	}
	else cout << (N / X)*T << endl;

	return 0;
}



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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  ll N, K, temp;
  cin >> N >> K;

  int da = 0, dk = 0;
  vector<ll> A(N);
  vector<ll> B(41, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    temp = A[i];
    for (int j = 0; j < 41; j++) {
      B[j] += temp % 2;
      temp /= 2;
      da = max(da, j);
      if (temp == 0) break;
    }
  }

  vector<ll> K2(41, 0);
  temp = K;
  for (int j = 0; j < 41; j++) {
    K2[j] += temp % 2;
    temp /= 2;
    dk = max(dk, j);
    if (temp == 0) break;
  }

  vector<ll> X(41, 0);
  for (int j = 0; j <= da; j++) {
    ll count1 = B[j];
    ll count0 = N - B[j];
    if (count0 > count1) X[j] = 1;
  }

  ll ans = 0;
  ll d = max(da, dk);
  bool isSmall = false;

  for (int j = d; j >= 0; j--) {

    ll count1 = B[j];
    ll count0 = N - B[j];
    ll pow2 = pow(2, j);

    if (j > dk) {
      ans += pow2 * count1;
      continue;
    }
    
    if ( count1 >= count0 ) {
      ans += pow2 * count1;
      if (K2[j] > X[j]) isSmall = true;

    } else if (isSmall || K2[j] == 1) {
      ans += pow2 * count0;
    } else {
      ans += pow2 * count1;
      if (K2[j] > X[j]) isSmall = true;
      
    }
  }

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

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int max = -1;
    int sum = 0;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        if(tmp >= max){
            max = tmp;
            sum += 1;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import math

a,b,x=map(int,input().split())

if a*b/2 <= x/a:
  t=(a*b-x/a)*2/(a*a)
  ans=math.degrees(math.atan(t))
  
else:
  t=x*2/(a*b*b)
  ans=90-math.degrees(math.atan(t))
  
  
print(ans)




Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int endA = 0, startB = 0, both = 0, contain = 0;
	int result = 0;

	Main(List<String> list) {
		for (int i = 0; i < list.size(); ++i) {
			String str = list.get(i);
			if (str.endsWith("A") && str.startsWith("B")) {
				++both;
			} else if (str.endsWith("A")) {
				endA++;
			} else if (str.startsWith("B")) {
				startB++;
			}
			if (str.contains("AB")) {
				for (int j = 0; j < str.length() - 1; ++j) {
					if (str.substring(j).startsWith("AB")) {
						++contain;
					}
				}
			}
		}
		result += contain;
		if (both >= 2) {
			result += both - 1;
		}
		if (both >= 1) {
			if (endA > 0) {
				result++;
				endA--;
			}
			if (startB > 0) {
				result++;
				startB--;
			}
		}
		result += Math.min(endA, startB);
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		List<String> list = new ArrayList<>();
		for (int i = 0; i < N; ++i) {
			list.add(in.readLine());
		}

		in.close();
		Main main = new Main(list);
		System.out.println(main.result);
	}

}

Measured memory_bytes: 25940
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    string s;
    cin >> s;
    ll K;
    cin >> K;
    ll i=0;
    for(;i<K-1; i++){
        if(s[i]!='1'){
            break;
        }
    }
    cout << s[i] << el;
}



Measured memory_bytes: 3532
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	int n;
	scanf("%d", &n);
	if (n == 1) {
		puts("Hello World");
	}
	else {
		int a, b;
		scanf("%d%d", &a, &b);
		PRINTD(a+b);
	}
}

Measured memory_bytes: 128
h, w = map(int, input().split())

S = [input() for _ in range(h)]

for i in range(h):
    s = ''
    for j in range(w):
        if S[i][j] == '#':
            s += S[i][j]
        else:
            x = 0
            for dx in [-1, 0, 1]:
                for dy in [-1, 0, 1]:
                    ii = i + dy
                    jj = j + dx
                    if 0 <= ii < h and 0 <= jj < w and S[ii][jj] == '#':
                        x += 1
            s += str(x)
    print(s)






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

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define REP1(i, n) for(ll i = 1; i <= n; ++i)
#define REP2(i, B, E) for(ll i = B; i <= E; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

template<class T> T& chmin(T &obj, T val){ return obj = min(obj, val); }
template<class T> T& chmax(T &obj, T val){ return obj = max(obj, val); }

// 二分探索 : [low, high) の範囲で述語 pred がtrue を返す最大の値を返す
template<class Pred>
ll bsearch(ll low, ll high, Pred pred){
    while(low + 1 < high){
        const ll mid = low + (high - low) / 2;
        if(pred(mid)){ low = mid; }
        else{ high = mid; }
    }
    return low;
}


const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e15;

//! 二項係数のmod
class BinomialCoefficientMod
{
    const static ll MAX = (ll)1e5 + 10;

    long long fac[MAX], finv[MAX], inv[MAX];
public:
    // テーブルを作る前処理
    BinomialCoefficientMod()
    {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    long long value(ll n, ll k) const {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {

    ll N, K; cin >> N >> K;
    auto A = read<ll>(N);
    sort(A.begin(), A.end());
    
    BinomialCoefficientMod C;
    
    ll maxv = 0;
    ll minv = 0;
    for(ll i = K - 1; i < N; ++i){
        maxv += ((A[i] + MOD) % MOD) * C.value(i, K - 1) % MOD;
        maxv %= MOD;
        minv += ((A[i-K+1] + MOD) % MOD) * C.value(N - (i - K + 2), K - 1) % MOD;
        //cout << A[i-K+1] << endl;
        //cout << C.value(N - i + 1, K - 1) << endl;
        minv %= MOD;
    }
    //cout << maxv << " " << minv << endl;
    ll ans = (maxv - minv + MOD) % MOD;
    write(ans);
}



Measured memory_bytes: 3328
import math
import itertools
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for comb in itertools.combinations_with_replacement(list(range(1, K + 1)), 3):
    dup = len(set(comb))
    if dup == 1:
        ans += comb[0]
    elif dup == 2:
        ans += gcd(*comb) * 3
    elif dup == 3:
        ans += gcd(*comb) * 6
print(int(ans))

Measured memory_bytes: 9640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(30);
  for(int i=0;i<M;i++)cin >> B[i];
  int A[30][30];
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++)cin >> A[i][j];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    int sum=C;
    for(int j=0;j<M;j++){sum+=A[i][j]*B[j];}
    if(sum>0)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){


	int n;
	cin>>n;
	vector<int> a(n);
	fo(i,n) cin>>a[i];
	int maax=INT_MAX;
	fo(i,101){
		int ans=0;
		fo(j,n){
			ans=ans+(a[j]-i)*(a[j]-i);


		}
		maax=min(ans,maax);
	}
	cout<<maax<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector <int> x(5);
    for(auto &i : x) cin >> i;
    for(int i = 0 ; i < 5 ; i++){
        if(x[i] == 0) finish(i + 1);
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Graph Template
//-------------------------------------------------
template<class E>
struct Graph
{
    vector<vector<E> > adj;
    Graph(int N):adj(N){}
    virtual void add_edge(int v, E e){adj[v].push_back(e);}
    vector<E>& operator[](int v){return adj[v];}
    inline int size(){return adj.size();}
};

struct NormalEdge {
    int to;
    NormalEdge(int to):to(to){}
};

struct UWGraph : public Graph<NormalEdge>
{
    UWGraph(int N):Graph(N){}
    void add_edge(int v, int e){adj[v].push_back({e});}
};

//-------------------------------------------------
//--Bellman-Ford
//-------------------------------------------------
template<class T, class E>
vector<T> bellman_ford(Graph<E> &G, int s, T inf)
{
    int V = G.size();
    vector<T> dist(V);
    for(int i=0;i<V;i++) dist[i]=inf; dist[s]=0;
    int idx=0;
    bool update=true;
    while(update){
        update=false;
        for(int v=0;v<V;v++)for(auto e:G[v]){
            if (dist[v]!=inf && dist[e.to]>dist[v]+e.cost){
                dist[e.to]=dist[v]+e.cost;
                update=true;
            }
        }
        if (update && idx==V-1) return vector<T>();
        idx++;
    }
    return dist;
}


struct Edge{int to; ll cost;};

const ll INF=1e15;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,r; cin>>N>>M>>r;
    Graph<Edge> G(N);
    rep(i,M){
        int a,b; ll c; cin>>a>>b>>c;
        G.add_edge(a,{b,c});
    }
    auto dist = bellman_ford(G,r,INF);
    if (dist.empty()){
        cout<<"NEGATIVE CYCLE\n";
        return 0;
    }
    for(auto d:dist){
        if (d!=INF) cout<<d<<"\n";
        else cout<<"INF\n";
    }
    return 0;
}



Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    long long s = 0;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        s += A[i];
    }
    long long k = 0;
    long long kk = 0;
    for (int i = 0; i < n; i++) {
        k += A[i];
        if (k > s-k) {
            kk = k;
            k -= A[i];
            break;
        }
    }
    cout << min((s-k)-k, kk-(s-kk)) << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int n, b, f, r, v;
    int i, j;
    
    int info[12][10];
    for(i = 0; i < 12;i++)
        for(j = 0; j < 10;j++)
            info[i][j] = 0;
    
    scanf("%d", &n);
    for(i = 0;i < n;i++){
        scanf("%d%d%d%d", &b, &f, &r, &v);
        info[(b-1)*3+(f-1)][r-1] = info[(b-1)*3+(f-1)][r-1] + v;
    }
    
    for(i = 0;i < 12;i++){
        for(j = 0; j < 10; j++){
            printf(" %d", info[i][j]);
        }
        if((i+1) % 3 == 0 && i != 11) printf("\n####################");
        printf("\n");
    }
    return 0;
}


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

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec){
    os << "[";
    for(int i=0;i<vec.size();i++){
        os << (i==0?"":" ") << vec[i];
    }
    os <<  "]";
    return os;
}


int main(){
    int n;
    cin >> n;
    int ki=0, gu=0;
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        if(t%2)
            ki++;
        else
            gu++;
    }
    
    cout << (ki%2==0?"YES":"NO") << endl;

    return 0;

}


Measured memory_bytes: 256
#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

bool debug = false;
string ans_debug;

bool ask(const vector<int>& v){
  if(debug){
    dbg(v);
    assert(v.size() == ans_debug.size() / 2);
    int r = 0,b=0;
    for(auto x : v){
      if(ans_debug[x]=='R') r++;
      else b++;
    }
    return r > b;
  } else {
    cout << "?";
    for(auto x : v) cout <<" " << x+1;
    cout << endl;
    string s;
    cin>>s;
    return s == "Red";
  }
}

int main(int argc, char* argv[]){
  if(argc==2){
    debug = true;
    ans_debug = string(argv[1]);
  }

  int n;
  cin>>n;

  if(n==1) {
    bool r = ask({0});
    if(r) cout << "! RB";
    else cout << "! BR";
    cout << endl;
    return 0;
  }

  int RED = 1;
  int BLK = 0;
  int UK = -1;
  vector<int> ans(2*n, UK);
  // find half set
  vector<int> h1,h2;

  auto f = [&](int i) {
    vector<int> cand;
    rep(j,n) cand.pb(i+j);
    return ask(cand);
  };

  int l=0, r=n;
  bool il = f(0);
  bool ir = !il;
  while(r-l>1) {
    int m = (l+r)/2;
    bool im = f(m);
    if(il == im) l = m;
    else r = m;
  }

  rep(i,n-1) h1.pb(l+i+1);

  rep(i,n-1) h2.pb((n+r+i)%(2*n));

  ans[l] = (il ? RED : BLK);
  ans[n+l] = (il ? BLK : RED);

  rep(i,2*n) if(ans[i] == UK){
    bool use_h1 = true;
    for(auto x : h1) if(x == i) use_h1 = false;
    vector<int> q = (use_h1) ? h1 : h2;
    q.pb(i);
    bool rep = ask(q);
    ans[i] = rep ? RED : BLK;
  }

  cout << "! ";
  rep(i,2*n) cout << (ans[i] == RED ? "R" : "B");
  cout << endl;

  return 0;
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,k,a[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
int main()
{
	m=read();k=read();
	if(m==1)
	{
		if(k==0)cout<<0<<" "<<0<<" "<<1<<" "<<1;
		else puts("-1");
		return 0;
	}
	int x=pow(2,m),n=x*2;
	if(k>x-1){puts("-1");return 0;}
	a[n/2]=k;
	int xu=0;
	for(int i=1;i<n/2;i++)
	{
		if(xu==k)xu++;
		a[i]=a[n-i]=xu;
		xu++;
	}
	a[n]=k;
	for(int i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++)
	{
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end(), greater<int>());
	int64_t ans = 0;
	for (int i = 0; i < N-2; i++)
	{
		for (int j = i+1; j < N-1; j++)
		{
			for (int k = N-1; k > j; k--)
			{
				if (vec.at(i) < vec.at(j) + vec.at(k)) {
					if (vec.at(j) < vec.at(i) + vec.at(k)) {
						if (vec.at(k) < vec.at(i) + vec.at(j)) {
							ans += k - j;
							break;
						}
					}
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
from operator import itemgetter

N, T = map(int, input().split())
c = []
t = []
IDX = []

for idx in range(N):
    tmp, tmp2 = map(int, input().split())
    c.append(tmp)
    t.append(tmp2)
    IDX.append(idx+1)

ctIDX = [list(x) for x in zip(c,t,IDX) if x[1] <= T]
ctIDX = sorted(ctIDX, key=itemgetter(0))

try:
    print(ctIDX[0][0])
except:
    print("TLE")

Measured memory_bytes: 3064
N, L = map(int, input().strip().split())

if L > 0:
  print(sum([i + L for i in range(1, N)]))
elif L + N > 0:
  print(sum([i + L for i in range(0, N)]))
else:
  print(sum([i + L for i in range(0, N - 1)]))

Measured memory_bytes: 3064