akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 3e3 + 7;
const int mod = 1e9 + 7;

int n, dp[N][N];
string s;

void add(int& x, int y)
{
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
}

void Enter()
{
    cin >> n >> s;
    for(int i = 1 ; i <= n ; ++i) dp[1][i] = 1;
    s = "  " + s;
    for(int i = 2 ; i <= n ; ++i)
    {
        for(int j = 1 ; j <= i ; ++j)
        {
            if(s[i] == '>')add(dp[i][j],dp[i - 1][i - 1] - dp[i - 1][j - 1]);
            else add(dp[i][j],dp[i-1][j-1]);
            add(dp[i][j],dp[i][j-1]);
        }
    }
    cout << (dp[n][n] % mod + mod) % mod;
}

void Solve()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


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

struct card{char suit,value;};

void BubbleSort(struct card A[],int n){
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i; j--){
            if(A[j].value < A[j-1].value){
                card t = A[j]; A[j] = A[j-1]; A[j-1] = t; 
            }
        }
    }
}

void SelectionSort(struct card A[], int n){
    for(int i = 0; i < n; i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(A[j].value < A[minj].value) minj = j;
        }
        card t = A[i]; A[i] = A[minj]; A[minj] = t;
    }
}

void print(struct card A[], int n){
    for(int i = 0; i < n; i++){
        cout << A[i].suit << A[i].value;
        if(i != n-1) cout << " ";
        else cout << endl;
    }
}

bool isStable(struct card C1[], struct card C2[],int n){
    for(int i = 0; i < n; i++){
        if(C1[i].suit != C2[i].suit) return false; 
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    card C1[100],C2[100];
    
    for(int i = 0; i < n; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    
    for(int i = 0; i < n; i++) C2[i] = C1[i];
    
    BubbleSort(C1,n);
    print(C1,n);
    cout << "Stable" << endl;
    SelectionSort(C2,n);
    print(C2,n);
    if(!isStable(C1,C2,n)) cout << "Not stable" << endl;
    else cout << "Stable" << endl;
    
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int upcmpii(const void *a, const void *b){
    return (*(int*)a == *(int*)b ? 0 : (*(int*)a > *(int*)b ? 1 : -1));
}
void sort_ui(int *a, int n){ qsort(a, n, sizeof(int), upcmpii); }

int main(){
    int n; scanf("%d",&n);
    int a[101];
    rep(i,n) scanf("%d",a+i);
    sort_ui(a,n);
    int ans = 0, tmp = -1;
    rep(i,n) {
        ans += a[i];
        if(tmp == -1 && a[i]%10 != 0) tmp = a[i];
    }
    if(ans%10 == 0){
        if(tmp == -1) ans = 0;
        else ans -= tmp;
    }
    printf("%d",ans);
}

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

		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		if( K<=A ){
			System.out.println((A-K)+" "+B);
		}else{
			if( K-A>B ){
				System.out.println(0+" "+0);
			}else{
				System.out.println(0+" "+(B-(K-A)));
			}
		}
	}
}


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

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

fn main(){
    use std::collections::BTreeSet;
    let n = read();
    let a: BTreeSet<u32> = (0..n).map(|_| read()).collect();
    println!("{}", a.len());
}

Measured memory_bytes: 4352
fun main(args: Array<String>) {
    readLine()!!
    val s = readLine()!!
    val ecnt = s.count { it == 'E' }
    var e = 0
    var w = 0
    var ans = Int.MAX_VALUE
    for (c in s) {
        val x = w
        if (c == 'E') e++ else w++
        ans = Math.min(ans, x + ecnt - e)
    }
    println(ans)
}


Measured memory_bytes: 36632
//dhruv
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
const int inf = 1e18 + 5;
 
template<typename T>
T binpow(T a,T b,T modi){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a)%modi;
		}
		b /= 2;
		(a *= a) %= modi;
	}
	return res;
}
 
 
template<typename T>
T binpow(T a,T b){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a);
		}
		b /= 2;
		a *= a;
	}
	return res;
}
 
template<typename T>
T add(T a,T b){
	return (a + b)%mod;
}
template<typename T>
T sub(T a,T b){
	return add(a,mod - b);
}
template<typename T>
T mul(T a,T b){
	return (a*b)%mod;
}
template<typename T>
T inv(T a){
	return binpow(a,mod - 2,mod);
}

int make_int(string s){
	int x = 0;
	reverse(s.begin(),s.end());
	string tmp = s;
	for(int i = 0;i < s.length(); ++i){
		x *= 10;
		x += (int)(tmp.back() - '0');
		tmp.pop_back();
	}
	return x;
}
 
string make_string(int s){
	string x;
	while(s){
		x.push_back(char(s%10 + '0'));
		s /= 10;
	}
	reverse(x.begin(),x.end());
	return x;
}

random_device rd;
mt19937 g(rd());

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

const int N = 100;

vi fact;

void factorial(){
	fact.resize(N);
	fact[0] = 1,fact[1] = 1;
	fro(i,2,N){
		fact[i] = (fact[i - 1]*i)%mod;
	}
}

int nCr(int n,int r){
	return (mul(fact[n],inv(mul(fact[r],fact[n - r]))));
}

int nPr(int n,int r){
	return(mul(nCr(n,r),fact[r]));
}

// Linear Seive


int lp[N + 1];
vector<int> pr;
void ls(){
	for(int i = 2;i <= N; ++i){
		// means prime
		if(lp[i] == 0){
			lp[i] = i;
			pr.push_back(i);
		}
		for(int j = 0;j < pr.size() && pr[j] <= lp[i] && i*pr[j] <= N; j++){
			lp[i*pr[j]] = pr[j];
		}
	}
}


// getting the prime factorisation

vector<int> getfc(int n){
	vi factors;
	while(n != 1){
		int x = lp[n];
		factors.push_back(x);
		while(n%x == 0){
			n /= x;
		}
	}
	return factors;
}

int gcd(int a,int b){
	while(b){
		a %= b;
		swap(a,b);
	}	
	return a;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	// shuffle(all(a),g);
	int x,n;
	cin >> x >> n;
	vi a(n);
	map<int,bool> done;
	ffor(i,n){
		cin >> a[i];
		done[a[i]] = true;
	}
	// just bf all distances
	int res = inf;
	int ans;
	for(int i = -100;i <= 300; ++i){
		if(abs(i - x) < res && !done[i]){
			res = abs(i - x);
			ans = i;
		}
	}

	cout << ans;
	return 0;
}	

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<unordered_map>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  if(y>=x){
    cout<<"unsafe";
  }else{
    cout<<"safe";
  }
  return 0;
}

Measured memory_bytes: 3604
N_List = sorted(list(map(int,input().split())))
cnt = 0
if N_List[0] + 2 <= N_List[2]:
    cnt += (N_List[2] - N_List[0])//2
    N_List[0] += ((N_List[2] - N_List[0])//2) * 2

if N_List[1] + 2 <= N_List[2]:
    cnt += (N_List[2] - N_List[1])//2
    N_List[1] += ((N_List[2] - N_List[1])//2) * 2

if N_List.count(max(N_List)) == 2:
    cnt += 2
elif N_List.count(max(N_List)) == 1:
    cnt += 1
else:
    cnt += 0
print(cnt)

Measured memory_bytes: 9140
n = int(input())
a = list(map(int,input().split()))
cnt = 0
target = 1
if 1 not in a:
    print(-1)
else:
    for i in range(len(a)):
        if a[i] == target:
            a[i] = '_'
            target += 1
        
    result = [x for x in a if x != '_']

    print(len(result))

Measured memory_bytes: 26268
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll modexp(ll x, ll y, ll mod) {
	ll ans = 1;
	while(y) {
		if(y & 1) {
			ans = (ans * x) % mod;
		}
		x = (x * x) % mod;
		y /= 2;
	}
	return ans;
}
ll freq[10001];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    freq[0] = 1;
    ll n, p, i, ans = 0;
    cin>>n>>p;
    string s;
    cin>>s;
    if(p == 2 || p == 5) {
    	for(i = 0; i < s.length(); i++) {
    		ll t = s[i] - '0';
    		if(t % p == 0) {
    			ans += i + 1;
    		}
    	}	
    }
    else {
	    reverse(all(s));
	    ll prev = 0, cur;
	    for(i = 0; i < s.length(); i++) {
	    	cur = (prev + ((s[i] - '0') * modexp(10, i, p))%p)%p;
	    	freq[cur]++;
	    	prev = cur;
	    }
	    for(i = 0; i < 10001; i++) {
	    	ans += (freq[i] * (freq[i] - 1)) / 2;
	    }
	}
    cout<<ans<<'\n';
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int n;
int a[100001];
int b[100001];


int main(){
    cin >> n;
    rep(i,n){
        int idx = i+1;
        cin >> a[idx];
        b[a[idx]] = idx;
    }
    rep(i,n) cout << b[i+1] << " " ;
    cout << endl;


return 0;
}

Measured memory_bytes: 4344
#define F(p,n,m)(p*(f-d)*(n-e)>p*(m-d)*(g-e)&&p*(d-h)*(n-i)>p*(m-h)*(e-i))
main(z){float d,e,f,g,h,i,m,n,M,N,p,q;for(scanf("%d",&z);z--;puts((F(p,n,m)^F(q,N,M))?"OK":"NG"))scanf("%f%f%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n,&M,&N),p=(h-f)*(n-g)-(m-f)*(i-g),q=(h-f)*(N-g)-(M-f)*(i-g);}

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <math.h>
#include <set>
#include <fstream>
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;
	}
	return 0;
}

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

const int MX=100010,INF=1001001001,mod=1e9+7;
int dp[MX];
bool ng[MX];

int main(){
    int n,m;
    cin>>n>>m;
    set<int>se;
    rep(i,m){
        int a; cin>>a;
        ng[a]=true;
    }
    rep(i,MX)dp[i]=0;
    dp[0]=1;
    if(!ng[1])dp[1]=1;
    for(int i=2; i<=n; ++i){
        if(!ng[i-1])dp[i]+=dp[i-1];
        if(!ng[i-2])dp[i]+=dp[i-2];
        dp[i]%=mod;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 4100
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

vector<int>v[2007];
int dist[2007];
vector<int>ans[2007];
void solve() {
    int n;
    cin >> n;
    memset(ans,0,sizeof(dist));
    int x,y;
    cin >>x >>y;
    x--;y--;
    for(int i=1;i<n;i++) {
        v[i].pb(i-1);
        v[i-1].pb(i);
    }
    v[x].pb(y);
    v[y].pb(x);
   
    
    for(int src=0;src<n-1;src++) {
        memset(dist,0,sizeof(dist));
        queue<int>q;
        dist[src]=0;
        q.push(src);
        while(!q.empty()){
            int x = q.front();
            q.pop();
            for(int i=0;i<v[x].size();i++) {
                int node = v[x][i];
                if(dist[node]==0){
                    dist[node] = dist[x]+1;
                    q.push(node);
                }
            }

        }

        for(int i=0;i<=n-1;i++) {
            ans[src].pb(dist[i]);
        }
        
    }
    unordered_map<int, int>m;
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) {
            m[ans[i][j]]++;
        }
    }
    for(int i=1;i<=n-1;i++){
        cout << m[i] <<endl;
    }

}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int max1(int l1,int l2,int l3)
{
	if(l1>l2)
	{
		if(l1>l3)
			return l1;
		 else
		 	return l3;
	}
	else
	{
		if(l2>l3)
			return l2;
		else
			return l3;
	}
 }
int dp[3][100005];
int val[100005][3];
int fun(int choice,int l,int n)
{
	if(l>=n)
		return 0;
	if(dp[choice][l]!=-1)
		return dp[choice][l];
	if(choice==0)
		return dp[choice][l]=max(fun(1,l+1,n),fun(2,l+1,n))+val[l][choice];
	if(choice==1)
		return dp[choice][l]=max(fun(0,l+1,n),fun(2,l+1,n))+val[l][choice];
	if(choice==2)
		return dp[choice][l]=max(fun(1,l+1,n),fun(0,l+1,n))+val[l][choice];
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++)
{
	for(int j=0;j<3;j++)
cin>>val[i][j];
}
for(int i=0;i<3;i++)
{
   for(int j=0;j<100005;j++)
      dp[i][j]=-1;
}
int l1=fun(0,0,n);
int l2=fun(1,0,n);
int l3=fun(2,0,n);
int ans=max1(l1,l2,l3);
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 7296
#include<cstdio>

using namespace std;

int date[12];

int main()
{
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&date[0],&date[1],&date[2],&date[3],&date[4],&date[5],&date[6],&date[7],&date[8],&date[9],&date[10],&date[11])!=EOF)
	{
		int line=0;//合計の距離
		for(int i=0;i<10;i++)line+=date[i];
		double d = line*date[10];
		d/=(date[10]+date[11]);
		int k=0;
		for(int i=0;i<10;i++)
		{
			k+=date[i];
			if(d<=k)
			{
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 0
N = int(input())
S={}
for i in range(N):
    k=input()
    if(k not in S):
        S[k]=1
    else:
        S[k]+=1
#print(S)
T=sorted(S.items(),key=lambda x:x[1],reverse=True)
#print(T)
for i in range(len(T)):
    l=T[0][1]
    if(l>T[i][1]):
        T=T[0:i]
        break
#T=T[0:s]
T=sorted(T,key=lambda x:x[0])
for i in range(len(T)):
    print(T[i][0])


Measured memory_bytes: 48216
strings = input()
def s_to_k(s):
    k = []
    l = [0]
    s = s + "0"
    for i in range(1,len(s)):
        if s[i] != s[i-1]:
            l += [i]
            k += [l[-1]-l[-2]]
    return [k,l]

b = s_to_k(strings)
num = []
for i in range(0,len(b[0]),2):
    x = b[0][i]
    y = b[0][i+1]
    if y > x:
        d = y-x
        if max(x,y)%2 == 0:
            num += [y-d//2,x+d//2]
        else:
            num += [x+d//2,y-d//2]
    else:
        d = x-y
        if max(x,y)%2 == 0:
            num += [y+d//2,x-d//2]
        else:
            num += [x-d//2,y+d//2]

a = [0]*len(strings)
p = 0
for j in b[1][1:-1][::2]:
    a[j-1] = num[p]
    a[j] = num[p+1]
    p += 2

print(' '.join(map(str,a)))

Measured memory_bytes: 16620
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

double dp[301][301][301];

double solve(int* a, int  n, int one, int two, int three) {

	if (one == 0 and two == 0 and three == 0)
		return 0;

	if (dp[one][two][three] != -1)
		return dp[one][two][three];

	double ans = (double)n / (double)(one + two + three);
	if (one)
		ans += (double)one / (double)(one + two + three) * solve(a, n, one - 1, two, three);
	if (two)
		ans += (double)two / (double)(one + two + three) * solve(a, n, one + 1, two - 1, three);
	if (three)
		ans += (double)three / (double)(one + two + three) * solve(a, n, one, two + 1, three - 1);
	dp[one][two][three] = ans;
	return ans;
}

int main() {

	int n;
	cin >> n;
	int a[n];
	int one = 0, two = 0, three = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] == 1)
			one++;
		if (a[i] == 2)
			two++;
		if (a[i] == 3)
			three++;
	}
	for (int i = 0; i < 301; ++i)
		for (int j = 0; j < 301; ++j)
			for (int k = 0; k < 301; ++k)
				dp[i][j][k] = -1;
	// memset(dp, 0, sizeof(dp));
	cout << setprecision(14) << solve(a, n, one, two, three);

	return 0;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

int A, B;

int main() {
	cin >> A >> B;
	cout << max(0, A - 2 * B) << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void){
    int d,n;
    scanf("%d %d",&d,&n);
    
    int i;
    int a=1;
    
    for(i=0;i<d;i++){
        a*=100;
    }
    if(n!=100){
        printf("%d\n",a*n);
    }else{
        printf("%d\n",a*(n+1));
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;
double b[110],ans,sum;
int a[110];
int n,ansi;
int main()
{
    int i,j;
    scanf("%d",&n);
    for (i=0;i<n;i++)
        scanf("%d",&a[i]);
    sum=0;
    for (i=0;i<n;i++)
        sum+=a[i];
    double k=sum*1.0/(n*1.0);
    for (i=0;i<n;i++)
        b[i]=fabs(a[i]-k);
    ans=b[0];
    ansi=0;
    for (i=1;i<n;i++)
    if (b[i]<ans)
    {
        ans=b[i];
        ansi=i;
    }
    printf("%d\n",ansi);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  string S;
  cin >> S;
  int N = S.size();
  for (auto i = 0; i < N-1; ++i) {
    if (S[i] == S[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  for (auto i = 0; i < N-2; ++i) {
    if (S[i] == S[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define MAXN 100005
using namespace std;

int N, K, A[MAXN];

int main() {
    scanf("%d%d",&N,&K);
    for (int i=1;i<=N;++i) scanf("%d", &A[i]);
    int ans = 0;
    if (N <= K) ans = 1;
    else {
        N -= K;
        K--;
        ans = 1 + (N + K-1) / K;
    }
    printf("%d\n",ans);
}












Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Text;

class Solve{
    
    string s;
    int n;
    int[] x;
    long k;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        string ans;
        getinput();
        StringBuilder sb = new StringBuilder(n);
        for(int i=0;i<n;i++){
            if(i == n-1){
                sb.Append((char)(('a'+((k+26-x[i])%26)))+"");
            }
            else{
                if(x[i]<=k){
                    sb.Append("a");
                    k -= x[i];
                }
                else{
                    sb.Append(s[i]+"");
                }
            }
        }
        ans = sb.ToString();
        Console.WriteLine(ans);
    }
    void getinput(){
        s = Console.ReadLine();
        n = s.Length;
        x = new int[n];
        for(int i=0;i<n;i++){
            if(s[i] == 'a')
                x[i] = 0;
            else
                x[i] = 'z'-s[i]+1;
        }
        k = Int64.Parse(Console.ReadLine());
    }    
}

Measured memory_bytes: 8024
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0){
      return false;
    }
  }
  return true;
}

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

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

  vector<bool> ok(n, true);
  rep(i, 0, m){
    if(h[a[i]] <= h[b[i]]) ok[a[i]] = false;
    if(h[a[i]] >= h[b[i]]) ok[b[i]] = false;
  }

  ll ans = 0;
  rep(i, 0, n){
    if(ok[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int N;
    cin >> N;
    vector<int> a(N+1);
    for(int i = 1; i <= N;i++){
        cin >> a[i];
    }
    
    vector<int> ans;
    vector<int> b(N+1,0);
    for(int i = N; i >= 1;i--){
        int sum = 0;
        for(int j = i;j <= N;j +=i){
            sum += b[j];
        }
        if((sum+a[i])%2 == 1){
            b[i]++;
            ans.push_back(i);
        }
    }
    
    reverse(ans.begin(),ans.end());
    
    cout<< ans.size()<<endl;
    for(auto x:ans)cout << x <<" ";
    
    
    
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 12;
const ll inf = 1e9+7;


int main() {
	fastio;
	ll n,ans=0,ans2=0;
	string s;
	cin>>n>>s;
	f(i,0,n){
		if(s[i]=='W') ans++;
	}
	af(i,n-1,n-ans){
		if(s[i]=='R') ans2++;
	}
	cout<<ans2;
	return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>

int main(void)
{
	int n;

	scanf("%d", &n);
	for (; n > 0; n--){
		int a, b, c;

		scanf("%d %d %d", &a, &b, &c);

		if (a > b && a > c){
			int buf = a;
			a = c;
			c = buf;
		}
		if (b > a && b > c){
			int buf = b;
			b = c;
			c = buf;
		}

		if (a * a + b * b == c * c){
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
}


Measured memory_bytes: 580
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[300000];
ll cou[30];
ll com2(ll n){
    if(n < 2)
        return 0;

    ll m = n - 1;

    if(n % 2)
        m /= 2;
    else
        n /= 2;
    return n * m;
}
int main(){
    cin >> s;

    ll n = strlen(s);

    REP(i,30){
        cou[i] = 0;
    }
    REP(i,n){
        cou[s[i] - 'a']++;
    }
    ll ans = 1 + com2(n);

    REP(i,30)
        ans -= com2(cou[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;

int main(void) {
	int tmp, i = 0,j, can = 1, can2 = 0;
	string S, T, D[4] = { "dream","dreamer","erase","eraser" };
	cin >> S;

	reverse(S.begin(), S.end());
	rep(i, 4) {
		reverse(D[i].begin(), D[i].end());
	}

	while( i < S.size()) {
		can2 = 0;
		rep(j, 4) {
			if (S.compare(i, D[j].size(), D[j]) == 0) {
				can2 = 1;
				i += D[j].size();
				
			}
		}
		if (can2 == 0) {
			can = false;
			break;
		}
	}

	if (can == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
function Main(input){
	input = input.split("\n");
  var a = input[0].split(" ");
  var b = ("" + a[0] + "" +  a[1])*1;
  for(var i = 3; i < 317; i++){
  	if(i * i == b){
    	return "Yes";
    }
    if(i * i > b){
    	return "No";
    }
  }
  return "No";
}

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


Measured memory_bytes: 7372
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
 
int main(){
    string a;
    cin >> a;
    int b=0;
    while(b < a.size()){
        cout << a[b];
        b +=2;
    }
    
    cout << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

/*
Range Sum Query by FenwickTree(Binary Indexed Tree)

total number: n
queries:
    1. add(i, val): bit[i] += val 
    2. sum(n): sum(bit[0] + ... + bit[n-1])
time complexity: O(log n)
space complexity: O(N)

Self-balancing binary search tree or Segment Tree can do the same, it takes longer to program and complexity also increases.

Thanks: http://hos.ac/slides/20140319_bit.pdf
    
used in ARC031 C, indeednow finalB E, DSL2B(AOJ), ARC033 C, yukicoder No.59
*/

template<typename T> struct RangeSumQuery {
  int N;
  vector<T> dat;

  RangeSumQuery(int N) : N(N) {
    assert(N > 0);
    dat.resize(N, 0);
  }

  void add(int k, T val) {
    assert(0 <= k && k < N);
    for (int x = k; x < N; x |= x + 1) {
      dat[x] += val;
    }
  }

  // [0, k)
  T sum(int k) {
    assert(k >= 0);
    T ret = 0;
    for (int x = k - 1; x >= 0; x = (x & (x + 1)) - 1) {
      ret += dat[x];
    }
    return ret;
  }
  // [l, r)
  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= N);
    return sum(r) - sum(l);
  }

  T index(int k) {
    assert(0 <= k && k < N);
    return sum(k+1) - sum(k);
  }
};

P idx[200010];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  REP(i, N) {
    int a;
    cin >> a;
    idx[i] = P(a, i);
  }
  RangeSumQuery<int> fwt(N);
  REP(i, N) fwt.add(i, 1);
  sort(idx, idx + N);

  ll ans = 0;
  for (P p : idx) {
    ans += fwt.sum(p.second);
    fwt.add(p.second, -1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3372
#include <stdio.h>
int dp[100005][4];
int dif(int a, int b)
{
    if(a>=b)return a-b;
    return b-a;
}
int max(int a, int b)
{
    if(a<=b)return b;
    return a;
}
int main(void) {
	// your code goes here
	int n,i,k,j,x,y,z;
	scanf("%d",&n);
	scanf("%d%d%d",&x,&y,&z);
	dp[1][1] = x;
	dp[1][2]= y;
	dp[1][3] =  z;
	for(i=2;i<=n;i++)
	{
	    scanf("%d%d%d",&x,&y,&z);
	    dp[i][1] = max(max(dp[i-1][2],dp[i-1][3]), max(dp[i-2][1],max(dp[i-2][2],dp[i-2][3])))+x;
	    dp[i][2] = max(max(dp[i-1][1],dp[i-1][3]), max(dp[i-2][1],max(dp[i-2][2],dp[i-2][3])))+y;
	    dp[i][3] = max(max(dp[i-1][2],dp[i-1][1]), max(dp[i-2][1],max(dp[i-2][2],dp[i-2][3])))+z;
	}
	printf("%d\n",max(dp[n][1],max(dp[n][2],dp[n][3])));
	return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
int main(void){
int v[100][100];
int i,r,n,t,sum=0;
int b[100];
scanf("%d %d",&i,&r);
for(n=0;n<i;n++){
for(t=0;t<r;t++){
scanf("%d",&v[n][t]);
}
}
for(n=0;n<r;n++){
scanf("%d",&b[n]);
}
for(n=0;n<i;n++){
for(t=0;t<r;t++){
sum+=b[t]*v[n][t];
}
printf("%d\n",sum);
sum=0;
}
return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int n, m, x, right = 0, left = 0;
    cin >> n >> m >> x;
    for (int i = 0; i < m; i++){
        int a;
        cin >> a;
        if (a > x){
            right++;
        } else {
            left++;
        }
    }
    cout << min(right, left) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

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

  std::set<char> s;
  for (int i = 0; i < N; ++i) {
    char S;
    std::cin >> S;
    s.insert(S);
  }
  if (s.size() == 3) {
    std::cout << "Three" << std::endl;
  } else {
    std::cout << "Four" << std::endl;
  }
}

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

int main() {
  int m = 2019;
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());

  ll ans = 0;
  int x = 1, tot = 0;
  vector<int> cnt(m);
  cnt.at(0) = 1;
  rep(i, n) {
    tot += (s.at(i) - '0') * x;
    tot %= m;
    ans += cnt.at(tot);
    cnt.at(tot)++;
    x = (x * 10) % m;
  }

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

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define endl "\n";
#define ll long long 
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define satyam ios_base::sync_with_stdio(false);
#define mishra cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
	satyam mishra
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
	  ll n,w;cin>>n>>w;
	  ll arr[n+1][w+1];
	  memset(arr,0,sizeof(arr));
	  vector<ll>weight,value;
	  ll weigh,val;
	  ll nn=n;
	  while(nn--)
	  {
	  	cin>>weigh>>val;
	  	weight.pb(weigh);value.pb(val);
	  }
	  for(int i=1;i<=n;i++)
	  {
	  	for(int j=1;j<=w;j++)
	  	{
	  		if(weight[i-1]<=j)
	  		{
	  			arr[i][j]=max(value[i-1]+arr[i-1][j-weight[i-1]],arr[i-1][j]);
	  			//cout<<value[i-1]+arr[i-1][j-weight[i-1]]<<" ";
	  		}
	  		else
	  		{
	  			arr[i][j]=arr[i-1][j];
	  		}
	  		
	  	}
	  	//cout<<endl;
	  }
	  cout<<arr[n][w];
	}
}

Measured memory_bytes: 79232
#include <stdio.h>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

double len[40][40];
int lim[40][40];

double mini[40][40][40];

int main(){
  for(;;){
    int n,m;
    int s,g;
    int i,j,k,l;

    scanf("%d%d",&n,&m);
    if(n==0 && m==0)return 0;
    scanf("%d%d",&s,&g);
    s--;g--;
    for(i=0;i<n;i++)for(j=0;j<n;j++)lim[i][j]=-1;
    for(i=0;i<m;i++){
      int p,q;
      double d;
      int c;
      scanf("%d%d",&p,&q);
      scanf("%lf%d",&d,&c);
      p--;q--;
      len[p][q]=len[q][p]=d;
      lim[p][q]=lim[q][p]=c;
    }
    for(k=0;k<=30;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)mini[k][i][j]=1e9;
    multimap<double, pair<int, pair<int,int> > > que;
    que.insert(make_pair(0.0,make_pair(0,make_pair(s,s))));
    mini[0][s][s]=0;
    double ans=-1;int count=0;
    for(;!que.empty();){count++;
      pair<double, pair<int, pair<int,int> > > h=*(que.begin());
      que.erase(que.begin());
      double cost=h.first;
      int v=h.second.first;
      int prev=h.second.second.first;
      int now=h.second.second.second;

      if(v==1 && now==g){
	ans=cost;
	break;
      }
      
      for(i=0;i<n;i++){
	if(i!=prev && len[now][i]>=0){
	  int newv;
	  for(newv=v-1;newv<=v+1;newv++){
	    if(newv<=0 || newv>lim[now][i])continue;
	    //que ni ireru
	    double ncost=cost+(double)len[now][i]/newv;
	    int nprev=now;
	    int nnow=i;
	    if(mini[newv][nprev][nnow]>ncost){
	      mini[newv][nprev][nnow]=ncost;
	      que.insert(make_pair(ncost,make_pair(newv,make_pair(nprev,nnow))));
	    }
	  }
	}
      }
  	}//printf("count: %d\n",count);
    if(ans>=0)printf("%.10f\n",ans);
    else printf("unreachable\n");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int R,G,B,N;
long long ans = 0;
void dfs(int r,int g,int b,long long sum){
	if(sum==N){
		ans++;
		return;
	}
	if(sum>N)return;
	dfs(r+1,g,b,sum+R);
	dfs(r,g+1,b,sum+G);
	dfs(r,g,b+1,sum+B);
}
int main(void){
	
	cin >> R >> G >> B >> N;
	for(int r=0;r<=3000;r++){
		for(int g=0;g<=3000;g++){
			int temp = r*R + g*G;
			if(temp>N)continue;
			if((temp-N)%B==0)ans++;
		}
	}
	cout << ans << endl;
}

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

int main(){
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; ++i){
		cin >> S[i];
	}

	sort(S.begin(), S.end());
	for (int i = 0; i < N; ++i){
		cout << S[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int l;
  cin >> l;
  cout << fixed << setprecision(12);
  double s = l / 3.0;
  cout << s * s * s;
}

Measured memory_bytes: 256
n = int(input())
qplusmod = 0
i = 1
ans = n+1
for i in range(1,int(n)):
#  print(n,i)
  if n % i == 0:
    q = n / i
    qplusmod = q + i
#    print(n,i,qplusmod)
    if qplusmod < ans:
      ans = int(qplusmod)
  if i > n/i:
#    print(i)
    break
print(int(ans - 2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9e18
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll gcdsum(int n){
    int sum = 0;
    reps(i, n){
        reps(j, n){
            reps(k, n){
                sum += __gcd(i, __gcd(j, k));
            }
        }
    }
    return sum;
}

int main(){
    int n;
    cin >> n;
    cout << gcdsum(n) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<ll> x(n),y(n);
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	vector<ll> u(n),v(n);
	for(int i = 0; i < n; i++){
		u[i] = x[i] + y[i];
		v[i] = x[i]-y[i];
	}
	for(int i = 0; i < n; i++){
		if(abs(u[i]%2) != abs(u[0] %2)){
			cout << -1 << endl;
			return 0;
		}
	}

	int m = 31;
	vector<ll> d(m+1);
	for(int i = 0; i <= m; i++){
		d[i] = pow(2,m-i);
	}
	if(u[0] %2 == 0){
		d.push_back(1);
	}

	vector<ll> arm;
	vector<string> ans(n);
	for(int i = 0; i < n; i++){
		ll uu = 0,vv = 0;
		//cout << u[i] << " " << v[i] << endl;
		for(int j = 0; j < d.size(); j++){
			if(uu<u[i]){
				uu += d[j];
				if(vv<v[i]){
					vv += d[j];
					ans[i] += 'R';
				}else{
					vv -= d[j];
					ans[i] += 'U';
				}
			}else{
				 uu -= d[j];
				 if(vv<v[i]){
					vv += d[j];
					ans[i] += 'D';
				}else{
					vv -= d[j];
					ans[i] += 'L';
				}
			}
			//cout << uu << " " << vv << endl;
		}

		if(uu != u[i] || vv != v[i]){
			cout << -1 << endl;
			return 0;
		}
		// printf("\n");
	}


	cout << d.size() << endl;
	for(int i = 0; i < d.size(); i++){
		cout << d[i] << (i!=d.size()-1?" ":"\n");
	}
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
/*
Q回Dijkstraは間に合わない
なら1回で済ます方法を考える
Kを経由しての距離ということは
x-K-yとなるがクエリごとにKは変わらない
Kを始点としてDijkstraをかければ良い
K〜x K〜yの距離を足して終わりです。
*/

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
    ll N,Q,K;
    vector<edge> G[100010];
    ll d[100010];
    ll ans=0;
//辺がたかだかN-1本なので、
void dijkstra(int s){
    std::priority_queue<P,vector<P>,std::greater<P>> que;
    std::fill(d,d+N,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
 
        P p =que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<(signed)G[v].size();i++){
            edge e =G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
 
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N-1){
        int a,b,c;
        DEB(i)END
        cin>>a>>b>>c;
        edge e;
        e.to=b-1;e.cost=c;
        G[a-1].push_back(e);
        e.to=a-1;
        G[b-1].push_back(e);
    }
    cin>>Q>>K;
    DEB(Q)DEB(K)END
    dijkstra(K-1);
    REP(i,Q){
        DEB(i)
        int a,b;
        cin>>a>>b;
        cout<<d[a-1]+d[b-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 8820
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
int count=1;
string s;
cin>>s;
int n=s.size();
sort(s.begin(),s.end());
for(int i=1;i<n;i++)
{
if(s[i]==s[i-1]) count++;
else if(count%2!=0)
{
cout<<"No"<<endl;
return 0;
}
else count=1;
}
if(s[n-1]!=s[n-2])
{
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(t>s)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<string> s(n);
  int i;
  vector<int> temp;
  for(i=0;i<n;i++){
    cin >> s[i];
    cin >> p[i];
  }
  int ans= 0;
  int tmp = 0;
  int j;
  int k;
  string a = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  for(i=0;i<n;i++){
      a = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
      ans= 0;
      tmp =0;
    for(j=0;j<n;j++){
      loop:
      for(k=0;k<temp.size();k++){
        if(temp[k] == j && j != n-1){
          j++;
          goto loop;
        }else if(temp[k] == j && j == n-1){
          goto end;
        }
      }
      if(s[j]  < a){
        ans = j;
        tmp = p[j];
        a = s[j];
      }else if(s[j] == a && tmp < p[j]){
        ans = j;
        tmp = p[j];
        a = s[j];
      }
    }
    end:
    cout << ans + 1 << endl;
    temp.push_back(ans);
  }    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[1050][1050];
char a[1050],b[1050];

int main()
{
    while(~scanf("%s%s",a,b))
    {
        int m = strlen(a), n = strlen(b);
        for(int i=0;i<=m;i++) dp[i][0] = i;
        for(int i=0;i<=n;i++) dp[0][i] = i;
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
                dp[i][j] = min(dp[i-1][j] + 1,min( dp[i][j-1] + 1, ( a[i-1]==b[j-1] ? dp[i-1][j-1] : dp[i-1][j-1] + 1 ) ));
        printf("%d\n",dp[m][n]);
    }
    return 0;
}

Measured memory_bytes: 5080
#include <stdio.h>

int main(){
int n,t,i;
scanf("%d %d",&n,&t);
int a[n],b[n];
int low = 1001;
for(i = 0;i < n;i++){
scanf("%d %d",&a[n],&b[n]);
if(b[n] <= t && low > a[n])
	low = a[n];
}
if(low == 1001)
	printf("TLE");
else
	printf("%d",low);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/
int n;
vector<vector<int> > a;
vector<vector<int> > dp;
ll recur(int i, int j){
    //cout<<i<<" "<<j<<endl;
    if(i==n-1)
        return a[i][j];
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll x = a[i][j], m= 0;
    for(int k=0;k<3;k++){
        if(k!=j)
            m = max(m, recur(i+1, k));
    }
    x += m;
    dp[i][j] = x;
    return x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++)
    {
        a[i].resize(3);
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp.resize(n);
    for(int i=0;i<n;i++){
        dp[i].resize(3);
        for(int j=0;j<3;j++)
            dp[i][j]=-1;
    }
    int a1 = recur(0, 0), a2 = recur(0, 1), a3 = recur(0, 2);

    cout<<max(a1, max(a2, a3))<<endl;
    return 0;
}


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

int main() {
  ll k , x ;
  ll mins = -1000000;
  ll maxs =  1000000;
  cin >> k >>  x;
  vector<ll> ans;
  ans.push_back(x);
  for(int i = 1; i<k; i++) {
    if(x+i<maxs){
      ans.push_back(i+x);
    }
  }
  for(int i = 1; i<k; i++) {
    if(x-i>mins){
      ans.push_back(x-i);
    }
  }
  sort(ans.begin(), ans.end());
  rep(i,ans.size()){
    if(i<ans.size()-1)
      cout << ans[i] << " " ;
    if(i==ans.size()-1)
      cout << ans[i] << endl;
  }
  return 0;
}


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

main(){
	int n,a ;
	while( cin >> n , n ){
		int c[10] = {} ;
		for( int i=0 ; i<n ; i++ ){
			cin >> a ;
			c[a]++ ;
		}
		for( int i=0 ; i<10 ; i++ ){
			if( !c[i] ) cout << "-" << endl ;
			else {
				for( int j=0 ; j<c[i] ; j++ ) cout << "*" ;
				cout << endl ;
			}
		}
	}
}

Measured memory_bytes: 1152