akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<int> v[100001];
int indegree[100001];
int len[100001];

int main(){
	cin>>n>>m;
	for(int i=0; i<m; i++){
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		indegree[b]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++){
		if(indegree[i]==0) q.push(i);
	}
	while(!q.empty()){
		int here=q.front();
		q.pop();
		for(int next:v[here]){
			len[next]=max(len[next],len[here]+1);
			if((--indegree[next])==0) q.push(next);
		}
	}
	cout<<*max_element(len,len+n+1);
	return 0;
}

Measured memory_bytes: 6528
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		myBTree tree=new myBTree();

		int q=in.nextInt();
		for(int i=0;i<q;i++) {
			String odr=in.next();

			switch(odr.charAt(0)) {
			case 'i':
				tree.inset(Integer.parseInt(in.next()));
				break;
				
			case 'f':
				System.out.println((tree.contains(Integer.parseInt(in.next()))? "yes":"no"));
				break;
				
			case 'p':
				tree.walk('m');
				tree.walk('f');
				break;
			}
		}

		in.close();

	}

}

class BTNode{
	int v;
	BTNode p,lc,rc;

	BTNode(int n){
		v=n;
	}
}

class myBTree{
	private BTNode EDG,ROOT;

	myBTree(){
		EDG=new BTNode(-1);
		ROOT=EDG;
	}

	void inset(int v) {
		BTNode NEW=new BTNode(v);
		NEW.lc=EDG; NEW.rc=EDG;

		if(ROOT==EDG) {
			ROOT=NEW;
			ROOT.p=EDG;
		}
		else {
			BTNode NOW=ROOT;
			while(true) {
				if(NEW.v<NOW.v) {
					if(NOW.lc==EDG) {
						NOW.lc=NEW;
						NEW.p=NOW;
						break;
					}
					else NOW=NOW.lc;
				}
				else {
					if(NOW.rc==EDG) {
						NOW.rc=NEW;
						NEW.p=NOW;
						break;
					}
					else NOW=NOW.rc;
				}
			}
		}
	}
	
	public boolean contains(int key) {
		BTNode NOW=ROOT;
		
		while(NOW!=EDG) {
			if(key==NOW.v)return true;
			
			if(key<NOW.v)NOW=NOW.lc;
			else NOW=NOW.rc;
		}
		
		return false;
	}
	
	/*-----walk-----*/
	public void walk(char opt) {
		BTNode NOW=ROOT;

		switch(opt) {
		case 'f':
			preWalk(NOW);
			break;

		case 'm':
			inWalk(NOW);
			break;

		case 'l':
			postWalk(NOW);
			break;
		}

		System.out.println();
	}

	private void preWalk(BTNode NOW) {
		System.out.print(" "+NOW.v);
		if(NOW.lc!=EDG)preWalk(NOW.lc);
		if(NOW.rc!=EDG)preWalk(NOW.rc);
	}

	private void inWalk(BTNode NOW) {
		if(NOW.lc!=EDG)inWalk(NOW.lc);
		System.out.print(" "+NOW.v);
		if(NOW.rc!=EDG)inWalk(NOW.rc);
	}

	private void postWalk(BTNode NOW) {
		if(NOW.lc!=EDG)postWalk(NOW.lc);
		if(NOW.rc!=EDG)postWalk(NOW.rc);
		System.out.print(" "+NOW.v);
	}



}


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

int n, k;
string str;
int nxt[26];
vector<int> v[26];
int bit[200005];
inline void add(int i, int x){
  i++;
  while(i<200005){
    bit[i]+=x;
    i+=i&-i;
  }
}
inline int sum(int i){
  i++;
  int ret=0;
  while(i){
    ret+=bit[i];
    i-=i&-i;
  }
  return ret;
}

void gonext(int i){
  
}
int main(){
  cin >> str >> k;
  n=str.length();
  fill(bit, bit+200005, 0);
  fill(nxt, nxt+26, 0);
  for(int i=0; i<n; i++){
    add(i, 1);
    v[str[i]-'a'].push_back(i);
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<26; j++){
      if(nxt[j]==v[j].size()) continue;
      int cnt=sum(v[j][nxt[j]]-1);
      if(cnt<=k){
        k-=cnt;
        add(v[j][nxt[j]], -1);
        cout << (char)('a'+j);
        if(nxt[j]<v[j].size()) nxt[j]++;
        break;
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 4880
#include <iostream>
#include <cstdlib>
#define ll long long
#define ar array
using namespace std;
const ll V = 1e5;
int weight[105];
int value[105];
ll dp[105][V+5];

int main(){
    ios_base::sync_with_stdio(0);
    int n, w;
    cin>>n>>w;
    for(int i=1; i<=n; i++)
        cin>>weight[i]>>value[i];

    for(int i=0; i<=n; i++){
        for(int j=0; j<=V; j++){
            dp[i][j] = -1;
        }
    }

    for(int i=0; i<=n; i++)
        dp[i][0] = 0;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=V; j++){
            if(value[i]>j)
                dp[i][j] = dp[i-1][j];
            else{
                ll w1 = dp[i-1][j];
                ll w2 = dp[i-1][j-value[i]];
                if(w1==-1&&w2==-1)
                    dp[i][j]=-1;
                else if(w1==-1)
                    dp[i][j]=w2+weight[i];
                else if(w2==-1)
                    dp[i][j]=w1;
                else
                    dp[i][j] = min(w1, w2+weight[i]);
            }
        }
    }

    ll result;
    for(int i=0; i<=V; i++){
        if(dp[n][i]==-1)
            continue;
        else if(dp[n][i]<=w){
            //cout<<dp[n][i]<<endl;
            result = i;
        }
    }

    cout<<result<<endl;
}

Measured memory_bytes: 82076
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=1; i<(n); i++)

int main() {
    long long n,ans=10000000000000;
    cin>>n;
    rep(i,1000001){
        if(n%i==0){
            ans=min(ans,(i+n/i)-2);
        }
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[100100];
ll b[100100];

int main(void){
	int n,i,k;
	ll ans=0ll,tmp=0ll;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> a[i] >> b[i];
		if((a[i]|k)==k){
			ans += b[i];
		}
	}
	while(k){
		--k;
		tmp = 0ll;
		for(i=0; i<n; ++i){
			if((a[i]|k)==k){
				tmp += b[i];
			}
		}
		++k;
		k -= (k&-k);
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {
	//static List<Integer> primenumbers;
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		//setPrimeNumbers(300000);
		while(stdin.hasNext()) {
			int n = stdin.nextInt();
			if (n == 1) break;
			Iterator it = calculateMSPF(n).iterator();
			System.out.print(n + ": ");
			if (! it.hasNext()) System.out.print(n);
			while (it.hasNext()) {
				System.out.print(Integer.parseInt(it.next().toString()));
				if (it.hasNext()) System.out.print(" ");
			}
			System.out.println("");
		}
		System.exit(0);
	}

	/*public static void setPrimeNumbers(int n) {
		BitSet isntprime = new BitSet(n);
		isntprime.set(0, true);
		isntprime.set(1, true);
		for ()
	}*/

	public static boolean isMSNumber(int n) {
		int d = n % 7;
		return d == 1 || d == 6;
	}

	public static boolean isMSPrime(int n) {
		if (! isMSNumber(n)) return false;
		return calculateMSDivisors(n).size() == 2;
	}

	public static List<Integer> calculateDivisors(int n) {
		List<Integer> ds = new ArrayList<Integer>();
		for (int i = 1; i <= n / 2; i++) {
			if (n % i == 0) ds.add(i);
		}
		ds.add(n);
		return ds;
	} 

	public static List<Integer> calculateMSDivisors(int n) {
		List<Integer> msds = new ArrayList<Integer>();
		Iterator it = calculateDivisors(n).iterator();
		while (it.hasNext()) {
			int d = Integer.parseInt(it.next().toString());
			if (isMSNumber(d)) msds.add(d);
		}
		return msds;
	}

	public static List<Integer> calculateMSPF(int n) {
		List<Integer> mspfs = new ArrayList<Integer>();
		Iterator it = calculateMSDivisors(n).iterator();
		while (it.hasNext()) {
			int msd = Integer.parseInt(it.next().toString());
			if (isMSPrime(msd)) mspfs.add(msd);
		}
		return mspfs;
	}
}

Measured memory_bytes: 33296
import java.util.Scanner;

public class Main {
  static int selectionSort(int[] a, int n) {
    int sw = 0;
    for (int i = 0; i < n; i++) {
      int minj = i;
      for (int j = i; j < n; j++) 
        if (a[j] < a[minj]) 
          minj = j;
      int t = a[i];
      a[i] = a[minj];
      a[minj] = t;
      if (minj != i) sw++;
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = selectionSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
}

Measured memory_bytes: 26184
#include<bits/stdc++.h>
#define x 100000
using namespace std;
int main()
{
	int n[x],a[x],i,b[x];
	cin>>n[x];
	for(i=1;i<=n[x];i++)
	{
		cin>>a[i];
		b[a[i]]=i;
	}
	for(i=1;i<=n[x];i++){
		cout<<b[i]<<" ";
	}
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);

    int n;

    cin >> n;

    int result = 0;

    for1n(a, n){
        if (a % 3 != 0 && a % 5 != 0) {
            result += a;
        }
    }

    cout << result;

    return 0;
}


Measured memory_bytes: 3648
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[][] points = new int[n+1][3];
		for(int i=1;i<=n;i++){
		    points[i][0] =scn.nextInt();
		    points[i][1] =scn.nextInt();
		    points[i][2] =scn.nextInt();
		}
		// System.out.println(maxHappiness(1,points,-1));
		int[][] memo = new int[n+1][3];
		System.out.println(maxHappiness_dp(1,points));

	}


    public static int maxHappiness_dp(int day, int[][] points) {
		int len = points.length;
		int[][] dp = new int[len][3];
		for (int cday = len - 1; cday > 0; cday--) {
			for (int ca = 0; ca < 3; ca++) {

				if (cday == points.length - 1) {
					dp[cday][ca] = points[cday][ca];
					continue;
				}

				int ans = Integer.MIN_VALUE;
				for (int i = 0; i < 3; i++) {
					if (i != ca) {
						int ch = points[cday][ca] + dp[cday + 1][i];
						//maxHappiness_memoized(day + 1, points, i, memo);
						ans = Math.max(ans, ch);
					}
				}

				dp[cday][ca] = ans;
			}
		}
		return Math.max(dp[1][0], Math.max(dp[1][1], dp[1][2]));
	}
	
}


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


int main(void){
    char s[4];
    scanf("%s", s);
    if(strcmp("AAA", s) == 0 || strcmp("BBB", s) == 0){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 128
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
#define int long long
using namespace std;

const ll N = 1e6 + 100, OO = 1e6 + 10, M = 1e9 + 7, lg = 22;
typedef pair <int, int> pii;
int x[N];
int b[N];

int32_t main() {
	int n;
	cin >> n;
	n = n * n * n;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
out = [ "AGC", "ACG", "GAC"]
from functools import *

def check(s):
    for i in range(4):
        t = list(s)
        if i >= 1:
            t[i - 1], t[i] = t[i], t[i - 1]
        if "".join(t).count('AGC') >= 1:
            return False
    return True

@lru_cache(None)
def dfs(n, s):
    if n == N:
        return 1
    res = 0
    for c in "ACGT":
        if not check(s + c):
            continue
        res += dfs(n + 1, s[1:] + c) % MOD
    return res

print(dfs(0, "TTT") % MOD)
    



Measured memory_bytes: 10776
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias AB = Tuple!(long, "a", long, "b");

AB[10^^5] ABS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        auto ab = readln.split.to!(long[]);
        ABS[i] = AB(ab[0], ab[1]);
    }
    sort!"a.a < b.a"(ABS[0..N]);

    long r;
    foreach (ab; ABS[0..N]) {
        if (ab.b >= M) {
            r += ab.a * M;
            break;
        } else {
            M -= ab.b;
            r += ab.a * ab.b;
        }
    }
    writeln(r);
}

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

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> cnt(100000);
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    cnt.at(a-1)+=b;
  }
  long long ans;
  long long temp=0;
  for(int i=0; i<100000; i++){
    temp+=cnt.at(i);
    if(temp>=K){
      ans=i+1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3, greater<int>());

    cout << a[0] - a[1] + a[1] - a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include 	<ext/pb_ds/assoc_container.hpp> 
#include 	<ext/pb_ds/tree_policy.hpp> 
#include 	<iostream>
#include 	<queue>
#include 	<tuple>
#include 	<vector>
#include	<bits/stdc++.h>
#include	<algorithm>
#include 	<cmath>
#include 	<map>
#include 	<string>
#include 	<iomanip> 
#include 	<ctype.h>
#define 	ll  long long int
#define		read(a) long long int a; cin>>a;
#define 	readstr(s) string s; cin>>s;
#define 	readc(c) char c; cin>>c;
#define 	readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define 	loop(i,a,b) for(ll i=a;i<b;i++)
#define 	rloop(i,a,b) for(ll i=a;i>b;i--)
#define 	loopchar() for(char c='a';c<='z';c++)
#define 	printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define		printv(v) for (int i: v) cout << i << " "; cout << endl;
#define 	loopitr(vec) for(auto itr=vec.begin();itr!=vec.end();itr++)
#define 	ff first
#define 	ss second
#define 	readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define 	all(a) a.begin(), a.end()
#define 	yes cout <<"YES"<<endl;
#define 	no cout <<"NO"<<endl;
#define 	sc(x) cout << (#x) << " is " << (x) << endl;
#define 	fast ios_base::sync_with_stdio(false);cin.tie(0);
#define 	pb(p) push_back(p)
#define 	mp make_pair
#define 	fsort(vec) sort(vec.begin(),vec.end())
#define 	rsort(vec) sort(vec.begin(),vec.end(),compare)
#define 	Endl endl
#define 	ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define 	roundoff std::cout << std::setprecision(15)
#define 	inf 9223372036854775807
#define 	infn -9223372036854775807
#define 	pi 3.14159265358979323846
const 		int mod = 1e9+7; 
#define 	intsize ll size = trunc(log10(num)) + 1
#define 	REVERSE(vec) reverse(vec.begin(),vec.end())
using 		namespace __gnu_pbds; 
using 		namespace std;

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

//code start from here 

int main() {
	fast;
	read(x)
	ll sum=100;
	ll a=100;
	ll t=0;
	while(a<x){
		a = a*1.01;
		t++;
	}
	cout<<t;
	return 0;
}

//ends here

Measured memory_bytes: 3648
import sys
n, p = map(int, input().split())

if n == 1:
    print(p)
    sys.exit()
# 素因数分解
ls = {}
for i in range(2, int(p**0.5) + 1):
    while p % i == 0:
        ls[i] = ls.get(i, 0) + 1
        p //= i
if p > 1:
    ls[p] = 1
ans = 1

for key, value in ls.items():
    while value >= n:
        ans *= key
        value -= n
print(ans)

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

int main(){
	int n;
	scanf("%d", &n);
	int len[n];
	for(int i=0; i<n; i++){
		scanf("%d", &len[i]);
	}
	
	int sum=0, max=0;
	for(int i=0; i<n; i++){
		sum+=len[i];
		if(max<len[i]) max=len[i];
	}
	
	if(max < (sum-max)){
		printf("Yes");
	}
	else{
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 128
// At Corder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <algorithm>
#include <iostream>
using namespace std;
#include <vector>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using p = pair<int, int>;//<key,value>

int main()
{
int s,w;
cin>>s>>w;
if(s>w){
	cout<<"safe"<<endl;}
if(s<=w){
	cout<<"unsafe"<<endl;}
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント:
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3620
a,b=map(int, input().split())

if a == b:
    print(a*2)
elif (abs(a-b) == 1):
    print(a+b)
elif (abs(a-b) >= 2):
    if (a>b):
        print(a*2-1)
    else:
        print(b*2-1)



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 998244353;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/



int main() {
    cin >> n;
    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
 
using namespace std;
 
int main(){
int n;cin>>n;
int up=0, low=1001;
for(int i=0;i<n;i++){
int t;cin>>t;
up=max(up,t);
low=min(low,t);
}
cout<<up-low<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int A,B,Q;
    vector<ll> s,t;
    ll a;
    ll x[100000];
    cin>>A>>B>>Q;
    rep(i,A) {
        cin>>a;
        s.push_back(a);
    }
    rep(i,B) {
        cin>>a;
        t.push_back(a);
    }
    rep(i,Q) cin>>x[i];
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    ll min_val;
    int pos;
    ll s1,s2,t1,t2;
    rep(i,Q){
        min_val=100000000000;
        auto itr1=lower_bound(s.begin(),s.end(),x[i]);
        auto itr2=lower_bound(t.begin(),t.end(),x[i]);
        s1=0;s2=0;t1=0;t2=0;
        if(itr1!=s.end()) s1=*itr1-x[i];
        if(itr2!=t.end()) t1=*itr2-x[i];
        if(itr1!=s.begin()) {
            --itr1;
            s2=x[i]-*itr1;
        }
        if(itr2!=t.begin()) {
            --itr2;
            t2=x[i]-*itr2;
        }
        if(s1!=0 && t1!=0) min_val=min(min_val,max(s1,t1));
        if(s2!=0 && t2!=0) min_val=min(min_val,max(s2,t2));
        if(s1!=0 && t2!=0) min_val=min(min_val,s1+t2+min(s1,t2));
        if(t1!=0 && s2!=0) min_val=min(min_val,t1+s2+min(t1,s2));
        cout<<min_val<<endl;
    }    
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	getline(cin,s);
	// while(cin>>s != 0)
		// cout<<s[0];
	stringstream ss(s);
	string t;
	while(ss>>t)
		cout<<t[0];
	// cout<<s[0];
	// for(int i =1;i <s.length();i++)
	// 	if(s[i]==' ')
	// 		cout<<s[i+1];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int n, k; cin >> n >> k;
    int a[n]; rep(i,n) cin >> a[i];

    int ans = (n - 1) / (k - 1);
    if ((n - 1) % (k - 1) != 0) ++ans;

    out(ans);




    return 0;
}









Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int n;
  int a[100010];
  scanf("%d",&n);
  int i;
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  int count = 0;
  int j;
  for(i=1;i<=n;i++){
    j = a[i];
    if(a[j]==i){
      count++;
    }
  }

  printf("%d\n",count/2);

  return 0;
}


Measured memory_bytes: 512
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int a,b,c,k,ans;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>a>>b>>c>>k;
    int kk = k;
    if(a>=kk) ans = k;
    else{
        kk -= a;
        if(b>=kk) ans = a;
        else{
            kk -= b;
            ans = a-kk;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

vi S[6];
string expr;

vi calc(vi a,vi b,char op)
{
	vi ret(a.size()+b.size());
	vi::iterator it;
	switch(op)
	{
	case 'u':
		it=set_union(all(a),all(b),ret.begin()); break;
	case 'i':
		it=set_intersection(all(a),all(b),ret.begin()); break;
	case 'd':
		it=set_difference(all(a),all(b),ret.begin()); break;
	case 's':
		it=set_symmetric_difference(all(a),all(b),ret.begin()); break;
	}
	ret.erase(it,ret.end());
	return ret;
}

vi eval(int s,int t)
{
	int d=0,p=t-1; char c;
	for(;p>s;p--)
	{
		c=expr[p];
		if(c=='(')d++;
		if(c==')')d--;
		if(d==0&&(c=='u'||c=='i'||c=='d'||c=='s'))break;
	}
	if(p==s)
	{
		if(expr[s]=='(')return eval(s+1,t-1);
		if(expr[s]=='c')return calc(S[5],eval(s+1,t),'d');
		return S[expr[s]-'A'];
	}
	return calc(eval(s,p),eval(p+1,t),c);
}

int main()
{
	char c; int n;
	while(cin>>c>>n)
	{
		rep(i,6)S[i].clear();
		do
		{
			rep(i,n)
			{
				int t; cin>>t;
				S[c-'A'].pb(t);
				S[5].pb(t);
			}
		}while(cin>>c>>n,c!='R');
		
		rep(i,6)
			sort(all(S[i])),S[i].erase(unique(all(S[i])),S[i].end());
		cin>>expr;
		
		vi ans=eval(0,expr.size());
		if(ans.empty())cout<<"NULL"<<endl;
		else rp(i,ans)cout<<ans[i]<<(i==ans.size()-1?"\n":" ");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#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 repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<50;
const int INF = 1<<30;
const double PI=acos(-1);
pair<ll, ll> func(int at, vector<pair<ll, bool>> &hash, vector<vector<pair<int, ll>>>& path,ll pos)
{
	pair<ll,ll>res=mp(pos,pos);//min,max
	pair<ll,ll>bef;
	if(hash[at].S==false){
		hash[at].S=true;
		for(auto itr=path[at].begin();itr!=path[at].end();itr++){
			if(hash[itr->F].F==INFLL){
				hash[itr->F].F=pos+(itr->S);
			}
			else if (hash[itr->F].F != pos + (itr->S))
			{
				res=mp(-INFLL,INFLL);
			}
			bef=func((itr->F),hash,path,pos+(itr->S));
			chmin(res.F,bef.F);
			chmax(res.S, bef.S);
		}
	}
	return res;
}
 int main()
{
	int n,m;
	bool ans=true;
	cin >>n>>m;
	vector<vector<pair<int,ll>>>path(n);
	int l,r;
	ll d;
	vector<pair<ll,bool>> hash(n,mp(INFLL,false));
	rep(i,m){
		cin>>l>>r>>d;
		l--;
		r--;
		if(l> r){
			swap(l,r);
			d*=-1LL;
		}
		path[l].emplace_back(r,d);
		path[r].emplace_back(l,-d);
	}
	pair<ll,ll>res;
	rep(i,n){
		if(hash[i].S==false){
			res=func(i,hash,path,0LL);
			if(abs(res.F-res.S)>1000000000){
				ans=false;
			}
		}
	}

	cout<<solve(ans)<<endl;
}

Measured memory_bytes: 19072
#include <cstdio>
#include <map>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

//------------------------------------------------------------------------------
const int UF_SIZE = 200000;

struct UF {
  int par[UF_SIZE];
  int rnk[UF_SIZE];
  void init(int n) {
    REP(i, n) {
      par[i] = i;
      rnk[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

//------------------------------------------------------------------------------
const int K_MAX = 100000;
const int L_MAX = 100000;

typedef pair<int, int> P;

int N, K, L;
int p[K_MAX];
int q[K_MAX];
int r[L_MAX];
int s[L_MAX];

UF road;
UF rail;
map<P, int> cnts;

void solve() {
  road.init(N);
  REP(i, K) road.unite(p[i] - 1, q[i] - 1);

  rail.init(N);
  REP(i, L) rail.unite(r[i] - 1, s[i] - 1);

  REP(i, N) {
    cnts[P(road.find(i), rail.find(i))]++;
  }
  REP(i, N) printf("%d%c",
    cnts[P(road.find(i), rail.find(i))],
    i + 1 == N ? '\n' : ' '
  );
}

void input() {
  scanf("%d%d%d", &N, &K, &L);
  REP(i, K) scanf("%d%d", p + i, q + i);
  REP(i, L) scanf("%d%d", r + i, s + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main() {
	int n, k;
	int a[1 << 25];
	cin >> n >> k;
	int p = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	n -= k;
	k--;
	int ans = 1;
	while (n > 0) {
		n -= k;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2304
/*
 * ID: ITP1_9_A
 * Problem: finding the word
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    char target[10 + 1];
    char word[1000 + 1];

    scanf("%s", target);

    int count = 0;
    while (1) {
        scanf("%s", word);
        if (strcmp(word, "END_OF_TEXT") == 0)
            break;

        for (int i = 0; word[i]; i++)
            word[i] = tolower(word[i]);

        if (strcmp(word, target) == 0)
            count++;
    }
    printf("%d\n", count);

    return 0;
}



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

int main() {
    int N;
    cin >> N;
    int K, P;
    for (int i=0; i<N; ++i) {
        cin >> K >> P;
        cout << (K % P == 0 ? P : K % P) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define rep(i, ne) for (int i = 0; i < ne; ++i)

struct UnionFind {
  //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
  //そうでなければ親のid
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

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

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

int N, M;
vector<P> s;

void input() {
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    s.emplace_back(a - 1, b - 1);
  }
}

void solve() {

  UnionFind uf(N);

  for (auto p : s) {
    uf.unite(p.first, p.second);
  }

  int ans = 0;
  rep(i, N) { ans = max(ans, uf.size(i)); }

  cout << ans << endl;
}

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

// 写経
// 公式解説
// https://atcoder.jp/contests/abc177/editorial/90

Measured memory_bytes: 5544
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

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


int main() {
    int n, k;
    cin >> n >> k;
    int ub = (n - 1) * (n - 2) / 2;
    if (k > ub) cout << "-1" << endl;
    else {
        vector<P> ans;
        rep(i, n-1) ans.push_back(P(i+1,n));
        
        vector<P> edges;
        rep(i, n-1)rep(j, i) edges.push_back(P(i+1, j+1));
        
        int add = ub - k;
        rep(i, add) ans.push_back(edges[i]);

        cout << ans.size() << endl;
        rep(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;   
    }
    return 0;
}

Measured memory_bytes: 384
use proconio::input;
use std::collections::HashMap;

const MOD:i64 = 1e9 as i64 + 7;
fn main() {
    input! {
        n:usize,
        ab:[(i64,i64);n],
    };
    let ab:Vec<(i64,i64)> = ab.into_iter().filter(|&(a,b)| a!=0 || b!=0 ).collect();
    let zcnt = (n-ab.len()) as i64;
    let ab:Vec<(i64,i64)> = ab.into_iter().map(|(a,b)|{
        let g = num::integer::gcd(a,b);
        (a/g,b/g)
    }).collect();

    let mut pow2 = vec![1i64;n+1];
    for i in 0..n {
        pow2[i+1] = pow2[i]*2%MOD;
    }

    let mut dict = HashMap::new();
    ab.iter().for_each(|&x|{
        let count = dict.entry(x).or_insert(0);
        *count+=1;
    });
    
    let mut get_pararell = |a:i64,b:i64| {
        let mut res = 0;
        if let Some(v) = dict.get(&(a,b)) {
            res+=v;
            dict.remove(&(a,b));
        }
        if let Some(v) = dict.get(&(-a,-b)) {
            res+=v;
            dict.remove(&(-a,-b));
        }
        res
    };

    let mut ans = 1;
    for &(a,b) in &ab {
        let sum0 = get_pararell(a,b);
        let sum1 = get_pararell(b,-a);
        let sum = (pow2[sum0]+pow2[sum1]-1)%MOD;
        ans = ans*sum%MOD;
    }

    ans+=zcnt-1;
    ans = (ans%MOD+MOD)%MOD;
    println!("{}",ans);

}

Measured memory_bytes: 26932
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())

primes = [0]*100
def prime_factorize(n):
    while n % 2 == 0:
        primes[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            primes[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        primes[n] += 1

for i in range(1, N+1):
    prime_factorize(i)

up2 = 0
up4 = 0
up24 = 0
up14 = 0
up74 = 0
for i, p in enumerate(primes):
    if p>=2:
        up2 += 1
    if p>=4:
        up4 += 1
    if p>=24:
        up24 += 1
    if p>=14:
        up14 += 1
    if p>=74:
        up74 += 1

ans = 0
if up4>=2:
    ans += (up2-2)*(up4*(up4-1)//2)
if up24>=1:
    ans += (up2-1)*up24
if up14>=1:
    ans += (up4-1)*up14
if up74>=1:
    ans += up74

print(ans)
    
    


Measured memory_bytes: 62132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const ll INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int g[15][15];

int main(){
    int n;
    cin >> n;
    rep(i,n) rep(j,n) g[i][j] = -1;
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    }

    int ans = 0;
    
    rep(i,1<<n){
        vector<int> x(n);
        rep(j,n) if(i>>j & 1) x[j] = 1;
        bool ok = true;
        rep(j,n){
            if(x[j]){
                rep(k,n){
                    if(g[j][k]==-1)continue;
                    if(g[j][k]!=x[k])ok = false;
                }
            }
        }
        if(ok) ans = max(ans,__builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for(int i=0;i<2;i++){
      int rest = N %10;
      N = N / 10;
      if(rest == 9){
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<PP> v(2*m);
  int gr = 1;
  int group[m+1];
  CLR(group);
  FOR(i,0,m){
    int a, b;
    cin >> a >> b;
    v[i] = PP(P(a, 1), i);
    v[i+m] = PP(P(b, -1), i);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  bool up = false;
  FOR(i,0,2*m){
    if(v[i].first.second==1){
      group[v[i].second] = gr;
      if(!up){
        up = true;
        ans++;
      }
    } else {
      if(group[v[i].second] == gr){
        up = false;
        gr++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3072
N = int(input())
A = list(map(int, input().split()))

cnt = 0

DP = [0] * (N + 1)

for i in range(N):
    DP[i + 1] = DP [i] + A[i]

dic = {}

for i in DP:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

for i in dic.values():
    cnt += (i * (i - 1)) // 2

print(cnt)

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

void printVec(std::vector<int> &vec)
{
    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it)
    {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
}

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

    vector<int> list(n);
    rep(i, n)
    {
        cin >> list[i];
    }

    int ans = 0;

    if (n == 1 || n == 2)
    {
        cout << ans << endl;
        return 0;
    }

    rep(i, n - 2)
    {
        for (int j = i + 1; j < n - 1; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                if (list[i] + list[j] > list[k] && list[j] + list[k] > list[i] && list[i] + list[k] > list[j] && (list[i] != list[j] && list[i] != list[k] && list[j] != list[k]))
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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

const int INF = 1e9;
const int MAX_C = 100;

int main()
{
	int D, N;
	cin >> D >> N;
	vector<int> T(D), A(N), B(N), C(N);
	for (int i = 0; i < D; i++) {
		cin >> T[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}
	vector<vector<int>> dp(D, vector<int>(MAX_C + 1, -INF));
	for (int i = 0; i < N; i++) {
		if (A[i] <= T[0] && T[0] <= B[i]) {
			dp[0][C[i]] = 0;
		}
	}
	for (int i = 1; i < D; i++) {
		for (int j = 0; j < N; j++) {
			if (A[j] <= T[i] && T[i] <= B[j]) {
				for (int k = 0; k <= MAX_C; k++) {
					dp[i][C[j]] = max(dp[i][C[j]], dp[i - 1][k] + abs(k - C[j]));
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= MAX_C; i++) {
		res = max(res, dp[D - 1][i]);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3236
from collections import deque
from copy import deepcopy

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
UF = UnionFind(N+1)
direct_connect = [0]*(N+1)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a, b)
  direct_connect[a] += 1
  direct_connect[b] += 1
for _ in range(K):
  a, b = map(int, input().split())
  if UF.same(a, b):
    direct_connect[a] += 1
    direct_connect[b] += 1
print(" ".join([str(UF.size(i)-direct_connect[i]-1) for i in range(1, N+1)]))

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

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


Measured memory_bytes: 3596
S = input()
L = len(S)
Ans = 'No'
if L % 2 != 0:
  print(Ans)
else:
  for i in range(L//2):
    if S[(i+1)*2-2] == 'h' and S[(i+1)*2-1] == 'i':
      Ans = 'Yes'
    else:
      Ans = 'No'      
  print(Ans)

  

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	static int lastInd(String str,char ch1,char ch2) {
		int n = 0;
		for(int i=str.length()-1;i>0;i--) {		//()内は無視
			char c = str.charAt(i);
			if(c=='(')
				n++;
			if(c==')')
				n--;
			if((ch1==c||ch2==c) && n==0)
				return i;
		}
		return -1;
	}
	

	
	static int parse(String str) {
		int a = str.length();
		int n = 0;
		int g = 0;
		if(str.startsWith("(") && str.endsWith(")")) {				//(で始まり)で終わる
			if(!str.substring(1, a-1).contains("("))				//間に()がなければsubstr
				return parse(str.substring(1, str.length()-1));
			for(int i=0;i<str.length()-1;i++) {
				if(str.charAt(i)=='(') {
					n++;
					g++;
				}
				if(str.charAt(i)==')') n--;
				if(g!=0 && n==0) {
					break;
				}
				if(i==str.length()-2 && n-1==0) {
					return parse(str.substring(1, str.length()-1));
				}
			}
		}
		
		int ind = lastInd(str,'+','-');
		if(ind!=-1) {
			if(str.charAt(ind)=='+')
				return parse(str.substring(0, ind)) + parse(str.substring(ind+1));
			return parse(str.substring(0, ind))  - parse(str.substring(ind+1));
		}
				
		ind = lastInd(str,'*','/');					
		if(ind!=-1){
			if(str.charAt(ind)=='*')
				return parse(str.substring(0, ind)) * parse(str.substring(ind+1));
			return parse(str.substring(0, ind)) / parse(str.substring(ind+1));
		}
		
		return Integer.parseInt(str);
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		while(a--!=0) {
			String str = sc.next();
			System.out.println(parse(str.substring(0,str.length()-1)));
		}
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<double> x;
  for (int i = 0; i < n; i++) {
    double tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  double ans = 999999999;

  for (double i = 1; i <= 100; i++) {
    double sum = 0;

    for (int j = 0; j < n; j++) {
      sum += pow(x[j] - i, 2.0);
    }

    if (sum < ans) {
      ans = sum;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    int x = 0;
    for (int y = 1; y < N; y++) {
      if (abs(sum - a[y] * N) < abs(sum - a[x] * N)) {
        x = y;
      }
    }
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val ar = (1 to 5).map(_ => sc.nextInt).sorted
  val k = sc.nextInt

  if (math.abs(ar(0) - ar(4)) <= k) {
    println("Yay!")
  } else {
    println(":(")
  }
}


Measured memory_bytes: 27212
from collections import defaultdict as de
n,q=map(int,input().split())
s=[[]for i in range(n+1)]
a=de(int)
for i in range(n-1):
    o,b=map(int,input().split())
    s[o].append(b)
    s[b].append(o)
for i in range(q):
    p,x=map(int,input().split())
    a[p]=a[p]+x
t=[0]*(n+1)
g=[[1,0,0]]
while g:
    w=[]
    for i in g:
        t[i[0]]=i[1]+a[i[0]]
        for j in s[i[0]]:
            if j!=i[2]:
                w.append([j,t[i[0]],i[0]])
    else:
        g=w
print(*t[1:])


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

int main()
{
	int a, b, c, d,count=0,x=0;
	cin >> a >> b >> c >> d;
	if (a > d)
	{
		cout << d;
	}
	else if ((a + b) >= d)
	{
		cout << a;
	}
	else
	{
		cout << a - (d - (a + b));
	}
	



}

	
	



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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;

void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

typedef pair<int, int> P;

const int N = 1e6+5;
string s,t = "Yes";
int n,result;
int a,b;

int main () {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> a >> b;
  if(a*500 < b) t = "No";

  cout << t << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long ans = -(1LL << 60);
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608