akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;
 
const ll N=100009;
ll n,u,vv,w;
vector<ll>v[N],ww[N];
bool vis[N];
ll ans[N];
void dfs(ll i)
{
    vis[i]=1;
    for(ll j=0;j<v[i].size();j++)
    {
        u=v[i][j];
        w=ww[i][j];
        if(!vis[u])
        {
            if(w&1)
            {
                ans[u]=!ans[i];
            }
            else
            {
                ans[u]=ans[i];
            }
            dfs(u);
        }
    }
}
int main()
{
    ll i,j;
    cin >>n;
    for(i=1;i<n;i++)
    {
        cin >> u >> vv >> w;
        v[u].pb(vv);
        v[vv].pb(u);
        ww[u].pb(w);
        ww[vv].pb(w);
    }
    dfs(1);
    for(i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 17796
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


struct Sieve {//
	int n;
	vector<int> f, primes;
	Sieve(int N ): n(N), f(N + 1) {//コンスタクタでNまでの素数列挙 以下に現れるxはN以下
		f[0] = f[1] = -1;//factorList()のため
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.emplace_back(i);
			f[i] = i;//素数は自分を保持
			for (ll j = i * i; j <= n; j += i) {  //例えばi==7の時、7*5等は先に５の方で試してるから7*7以降、つまりi*i以降を試していけばいい
				if (!f[j]) f[j] = i;//何かしらが代入されていない時は、f[j]の約数であるiを代入
			}
		}
	}

	bool isPrime(int x) { return (f[x] == x);}//印が素数自身ならば素数

	vector<int> factors(int x) {//素因数リスト　重複あり ex)100==2*2*5*5
		vector<int> res;
		while (x != 1) {
			res.emplace_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	set<int> factorList(int x) {//素因数の集合　ex)100..(2,5)
		set<int> res;
		while (x != 1) {
			res.insert(f[x]);
			x /= f[x];
		}
		return res;
	}

	vector<pair<ll, int>> factor(int x) {
		vector<int> fl = factors(x); //ex)100...{2,2,5,5}
		if (fl.size() == 0) return {};
		vector<pair<ll, int>> res(1, PII(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			} else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};



/*.....................DEFINE FUNCTIONS ......................*/



map< ll, ll > prime_factor(ll n) {
	map< ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1; //素数だった時の
	return ret;
}

/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__

	ll A, B;
	cin >> A >> B;

	ll g=gcd(A,B);

	map<ll,ll> anslist=prime_factor(g);

	cout<<anslist.size()+1<<endl;


	




	return 0;
}


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

int main() {
  long long A, B;
  cin >> A >> B;
  A--;
  long long aa = (A % 4 == 1 || A % 4 == 2) ? 1 : 0;
  long long bb = (B % 4 == 1 || B % 4 == 2) ? 1 : 0;
  for (long long i = 2; i <= 2 * A; i = i << 1) {
	  long long ma = A % (i * 2);
	  if (ma >= i && ma % 2 == 0) {
		  aa += i;
		}
	}
  for (long long i = 2; i <= 2 * B; i = i << 1) {
	  long long mb = B % (i * 2);
	  if (mb >= i && mb % 2 == 0) {
		  bb += i;
		}
	}
  long long ans = aa ^ bb;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,k;

	cin>>n>>k;

	int total=0;
	rep(i,n){
		int h;
		cin>>h;
		if(h>=k)total++;
	}
	cout<<total<<endl;

	return 0;
}


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


int N;
double arr[3005];
double dp[3005][3005];
double solve(int pos,int val)
{
    double &ret=dp[pos][val];
    if(ret!=-1.0)return ret;
    if(val>=(N+1)/2)return 1;
    if(pos==N)return 0;
    ret=0;
    ret+=solve(pos+1,val+1)*arr[pos];
    ret+=solve(pos+1,val)*(1-arr[pos]);
    return ret;


}

int main()
{
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>arr[i];
    for(int i=0;i<3005;i++)
        for(int j=0;j<3005;j++)
            dp[i][j]=-1.0;
    cout<<fixed<<setprecision(12)<<solve(0,0);
}


Measured memory_bytes: 71040
import java.util

object Main {
  def main(args: Array[String]): Unit = {
    val in = io.Source.fromInputStream(System.in).getLines()
    val N = in.next().toInt
    val A = in.next().split(' ') map (_.toInt)
    val B = in.next().split(' ') map (_.toInt)
    val C = in.next().split(' ') map (_.toInt)
    System.out.println(solve(N, A, B, C))
  }

  def solve(N: Int, A: Array[Int], B: Array[Int], C: Array[Int]): Long = {
    util.Arrays.sort(A)
    util.Arrays.sort(C)

    var r: Long = 0
    for {
      i <- B.indices
      ai = upperBound(A, B(i) - 1)
      ci = lowerBound(C, B(i) + 1)
      if ai != -1 && ci != -1
    } {
      r += upperBound(A, B(i) - 1).toLong * (N - lowerBound(C, B(i) + 1)).toLong
    }
    r
  }

  def lowerBound(a: Array[Int], x: Int): Int = {
    def step(from: Int, to: Int): Int = {
      if (from == to) from
      else {
        val i = from + (to - from) / 2
        if (x <= a(i)) step(from, i)
        else step(i + 1, to)
      }
    }
    step(0, a.length)
  }

  def upperBound(a: Array[Int], x: Int): Int = {
    def step(from: Int, to: Int): Int = {
      if (from == to) from
      else {
        val i = from + (to - from) / 2
        if (x < a(i)) step(from, i)
        else step(i + 1, to)
      }
    }
    step(0, a.length)
  }
}


Measured memory_bytes: 78688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        char[] S = sc.next().toCharArray();
        int r = 0;
        for (int i = 0; i < N - 2; i++) {
            if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') r++;
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 21844
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    char X, Y;
    scan(X, Y);
    long a = X - Y;
    if (a == 0)
    {
        writeln("=");
        return;
    }
    if (a < 0)
    {
        writeln("<");
    }
    else
    {
        writeln(">");
    }
}


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

int c[4][4],s,tmp;

int main(){
	for(int i=1;i<=3;++i)
		for(int j=1;j<=3;++j)
			cin>>c[i][j];
	s=c[1][1]+c[2][2]+c[3][3];
	tmp=c[1][1]+c[2][3]+c[3][2];
	if(tmp!=s) {printf("No"); return 0;}
	tmp=c[1][2]+c[2][1]+c[3][3];
	if(tmp!=s) {printf("No"); return 0;}
	tmp=c[1][2]+c[2][3]+c[3][1];
	if(tmp!=s) {printf("No"); return 0;}
	tmp=c[1][3]+c[2][1]+c[3][2];
	if(tmp!=s) {printf("No"); return 0;}
	tmp=c[1][3]+c[2][2]+c[3][1];
	if(tmp!=s) {printf("No"); return 0;}
	printf("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};
 
int N;
string s;
 
signed main(){
  cin>>N;
  map<char,int>mp;
  for(int t=0;t<N;t++){
    cin>>s;
    mp[s[0]]++;
  }
 
  int ans=mp['M']*(mp['A']*(mp['R']+mp['C']+mp['H'])+mp['R']*(mp['C']+mp['H'])+mp['C']*mp['H']);
      ans+=mp['A']*(mp['R']*(mp['C']+mp['H'])+mp['C']*mp['H']);
      ans+=mp['R']*mp['C']*mp['H'];
 
  cout<<ans<<"\n";
  return 0;
}

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

using ll = long long;

const int MOD = 1e9 + 7;

int powmod(int a, int b) {
	int r = 1;
	while (b) {
		if (b & 1) {
			r = ll(r) * a % MOD;
		}
		a = ll(a) * a % MOD;
		b /= 2;
	}
	return r;
}

const int MAXQ = 16;
int N, Q;
int adj[MAXQ];

vector<pair<int, int>> extra[MAXQ];
int coeff[1 << MAXQ];
int dp[2][1 << MAXQ];

const int i9 = powmod(9, MOD - 2);

int main() {
	vector<pair<int, int>> pts = {{0, 0}};
	scanf("%d %d", &N, &Q); Q++;
	for (int i = 1; i < Q; i++) {
		int l, r; scanf("%d %d", &l, &r); l--;
		pts.emplace_back(l, i);
		pts.emplace_back(r, i);
	}

	sort(pts.begin(), pts.end());
	int ans = powmod(10, N - pts.back().first);

	for (size_t i = 0; i + 1 < pts.size(); i++) {
		int x = pts[i].second;
		int y = pts[i + 1].second;
		if (pts[i].first == pts[i + 1].first) {
			adj[x] |= 1 << y;
			adj[y] |= 1 << x;
		} else {
			int base = ll(i9) * (powmod(10, pts[i + 1].first - pts[i].first) - 1) % MOD;
			ans = ll(ans) * base % MOD;
			base = ll(base + 1) * powmod(base, MOD - 2) % MOD;
			extra[x].emplace_back(y, base);
		}
	}

	for (int m = 0; m < (1 << Q); m++) {
		coeff[m] = 1;
		for (int i = 0; i < Q; i++) {
			if (!(m & (1 << i))) continue;
			if ((adj[i] & m) != adj[i]) {
				coeff[m] = 0;
				break;
			}
			for (auto p : extra[i]) {
				if (m & (1 << p.first)) {
					coeff[m] = ll(p.second) * coeff[m] % MOD;
				}
			}
		}
	}

	int cur = 0, nxt = 1;
	dp[0][0] = 1;
	for (int x = 0; x < 9; x++, swap(cur, nxt)) {
		memset(dp[nxt], 0, sizeof(int) * (1 << Q));
		
		for (int m = 0; m < (1 << Q); m++) {
			int cm = (1 << Q) - 1 - m;
			for (int s = cm; ; s = (s - 1) & cm) {
				if ((s & 1) || x) {
					dp[nxt][s | m] += ll(dp[cur][m]) * coeff[s] % MOD;
					if (dp[nxt][s | m] >= MOD) {
						dp[nxt][s | m] -= MOD;
					}
				}
				if (s == 0) break;
			}
		}
	}
	ans = ll(ans) * dp[cur][(1 << Q) - 1] % MOD;

	printf("%d\n", ans);

	return 0;
}


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

void calculate(int const n);
void show_table(const vector<int> table, const int n);

int main()
{
	int n = 0;

	while(true) {
		cin >> n;
		if(n==0) break;
		calculate(n);
	}

	return 0;
}

void calculate(int const n)
{
	int row_n = n+1;
	vector<int> table((row_n)*(row_n),0);

	// 表への入力
	for(int i=1;i<=row_n*n;i++) {
		if(i%row_n==0) ;			//  結果が入るところはスキップ
		else
			cin >> table[i-1];
	}

	// 右側の和の計算 
	for(int i=n;i<=(row_n)*(row_n);i+=(row_n))
		for(int j=1;j<=n;j++)
			table[i] += table[i-j];

	// 下側の和の計算
	int count = 0;
	int j = 0;
	for(int i=0;i<n;i++) {
		count = 0;
		j = i;
		while(true) {
			table[(row_n)*n+i] += table[j];
			j += (row_n);
			count++;
			if(count==n) break;
		}
	}
	// 右下の和の計算
	for(int i=n;i<(row_n)*n;i+=(row_n))
		table[(row_n)*(row_n)-1] += table[i];

	show_table(table,n);
}

void show_table(const vector<int> table,const int n)
{
	int row_n = n+1;
	for(int i=0;i<(row_n)*(row_n);i+=(row_n)) {
		for(int j=i;j<i+row_n;j++)
			cout << setw(5) << table[j];
		cout << endl;
	}
}

Measured memory_bytes: 1220
#include<stdio.h>
int main()
{
  int t,i,n,k,h[101],nb,or,mxnb,mxor;
  scanf("%d",&t);
  for(i=0;i<t;i++){
    scanf("%d",&n);
    mxnb=0;
    mxor=0;
    nb=0;
    or=0;
    for(k=0;k<n;k++){
      scanf("%d",&h[k]);
      if(h[k]>h[k-1]&&k!=0)nb=h[k]-h[k-1];
      else if(h[k]<h[k-1]&&k!=0)or=h[k-1]-h[k];
      if(mxnb<nb)mxnb=nb;
      if(mxor<or)mxor=or;
    }
    printf("%d %d\n",mxnb,mxor);
  }
  return 0;
}

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

int main(){
	long long N;
	cin>>N;
	string S;
	long long c0=0,c1=0,c2=0,c3=0;
	for(int i=0;i<N;i++){
		cin>>S;
		if(S=="AC"){
			c0++;
			}else if(S=="WA"){
				c1++;
			}else if(S=="TLE"){
				c2++;
			}else if(S=="RE"){
				c3++;
			}
	}
	cout<<"AC x "<<c0<<endl;
	cout<<"WA x "<<c1<<endl;
	cout<<"TLE x "<<c2<<endl;
	cout<<"RE x "<<c3<<endl;
}

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

int main(void){
    int N; cin >> N;
    
    vector<int> A(N+1);
    rep(i,N+1) cin >> A[i];

    vector<int> B(N);
    rep(i,N) cin >> B[i];

    long long int cnt = 0L;
    rep(i,N){
        int tmp;
        if(A[i] > 0){
            tmp = min(A[i], B[i]);
            //cerr << 'A' << i << tmp << endl;
            cnt += tmp;
            B[i] -= tmp;
        }

        if(B[i] > 0){
            tmp = min(A[i+1], B[i]);
            //cerr << 'B' << i << tmp << endl;
            cnt += tmp;
            A[i+1] -= tmp;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int maxl = 0;
  int res = 0;
  rep(i, n) {
    int l;
    cin >> l;
    res += l;
    maxl = max(maxl, l);
  }
  
  if (maxl < (res-maxl) ) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define rep(i,n,k) for(int i=n;i<k;i++)
#define int unsigned long long
#define F first 
#define S second
#define P make_pair 


signed main(void){
 
    
    int n,m,q,p,r,ans,t;
    string s;
    vector<int> v;
    ans=0;
    cin>>n>>m;
    cout<<min(n,min(n%m,m-n%m))<<endl;
  
}


Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let (t, a): (f64, f64) = parse_line().unwrap();
    let h: Vec<f64> = parse_line().unwrap();
    let mut diff = std::f64::MAX;
    let mut ans = 0;

    for i in 0..n {
        let d = (t - h[i] * 0.006 - a).abs();
        if d < diff {
            diff = d;
            ans = i + 1;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define get dlafkjsdlfajks

const int M = 500100;
const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

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

int fact[M];

void pre() {
  fact[0] = 1;
  for (int i = 1; i < M; ++i) {
    fact[i] = mul(i, fact[i - 1]);
  }
}

int bin(int x, int to) {
  int y = 1;
  while (to) {
    if (to & 1)
      y = mul(x, y);
    x = mul(x, x);
    to >>= 1;
  }
  return y;
}

int inv(int x) {
  //assert(x != 0);
  return bin(x, mod - 2);
}

int f[M];
int n, p[M], sm[M];
bool u[M];

void addf(int at, int what) {
  for (int i = at; i < M; i |= (i + 1))
    f[i] += what;
}

int get(int r) {
  int ans = 0;
  for (int i = r - 1; i >= 0; i = (i & (i + 1)) - 1)
    ans += f[i];
  return ans;
}

int get(int l, int r) {
  return get(r) - get(l);
}

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];

    if (p[i] != -1) {
      u[p[i]] = true;
    }
  }
}

void kill() {
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (!u[i]) {
      sm[i] = 1;
      ++cnt;
    }

  for (int i = 1; i <= n; ++i)
    sm[i] += sm[i - 1];

  int ans = 0;
  int ma = 0;
  int i2 = (mod + 1) / 2;
  int sum = 0;

  for (int i = n - 1; i >= 0; --i) {
    int bon = 0;

    if (p[i] == -1) {
      bon = add(bon, mul(ma, i2));
      bon = add(bon, mul(sum, inv(cnt)));
      ++ma;
    } else {
      bon = add(bon, mul(mul(ma, sm[p[i]]), inv(cnt)));
      bon = add(bon, get(-1, p[i]));
      addf(p[i], 1);
      sum = add(sum, cnt - sm[p[i]]);
    }

    int rest = n - 1 - i;
    ans = add(ans, mul(bon, fact[rest]));
  }

  ans = add(ans, 1);
  ans = mul(ans, fact[cnt]);
  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  pre();
  read();
  kill();
}


Measured memory_bytes: 8704
using System;
using System.Linq;

namespace B___Good_Distance
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_D = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = N_D[0], D = N_D[1];
            var Xij = new int[N].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
            var cnt = 0;

            for (int i = 0; i < N; i++)
                for (int ii = i + 1; ii < N; ii++)
                {
                    var sum = 0;
                    for (int j = 0; j < D; j++)
                        sum += (int)Math.Pow(Xij[ii][j] - Xij[i][j], 2);

                    if ((int)Math.Sqrt(sum) == Math.Sqrt(sum)) cnt++;
                }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13524
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		Scanner sc = new Scanner(System.in);

		Set<Integer> hs =new HashSet<>();
		int N=sc.nextInt();
		int K = sc.nextInt();
		
		for (int i = 0; i < K; i++) {
			int d = sc.nextInt();
			for(int j = 0; j < d; j++) {
				hs.add(sc.nextInt());
			}
		}
		System.out.println(N - hs.size());
	}
}

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

int main (){
	int n ,q, a,k=0;
	cin>>n;
	vector<int> A;
	for(int i = 0;i<n;i++){
		cin>>a;
		A.push_back(a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>a;
		for(int j=0;j<n;j++){
			if(A[j]==a) {k++;break;}
		}
	}
	cout<<k<<endl;;
	return 0;
}


Measured memory_bytes: 3232
N=int(input())
div = []
ans = 0
for i in range(1,int(pow(N,0.5)+3)):
    if N%i==0:
        div.append(i)
        div.append(N//i)
div = list(set(div))
for i in map(lambda x:x-1,div):
    if i != 0 and N%i==N//i:
        ans += i
print(ans)

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

constexpr ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(a, b, dummy1, dummy2);
}


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int maxA = 0;
  for (int i = 0; i < N; i++) maxA = max(maxA, A.at(i));
  if (maxA < K) {
    cout << "IMPOSSIBLE\n";
    return 0;
  }
  int g = A.at(0);
  for (int i = 1; i < N; i++) g = gcd(g, A.at(i));
  if (K % g == 0) {
    cout << "POSSIBLE\n";
  }else {
    cout << "IMPOSSIBLE\n";
  }

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}
int dp[401];


int main(){
	int n, m; cin >> n >> m;
	vector<vector<int> > edge(n, vector<int>(n, 0));
	FOR(i, m){
		int s, t, d; cin >> s >> t >> d;
		edge[s][t] = d;
	}

	vector<int> s;
	s.push_back(0);
	while (1){
		vector<int> c;
		FOR(i, s.size()){
			FOR(j, n){
				if (edge[s[i]][j]){
					if (dp[j] < dp[s[i]] + edge[s[i]][j]){
						dp[j] = dp[s[i]] + edge[s[i]][j];
						c.push_back(j);
					}
				}
			}
		}
		
		s = c;

		if (!s.size()) break;
	}

	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1788
def c_many_requirements():
    from itertools import combinations_with_replacement
    N, M, Q = [int(i) for i in input().split()]
    Queries = [[int(i) for i in input().split()] for j in range(Q)]

    ans = 0
    for sequence in combinations_with_replacement(range(1, M + 1), N):
        score = 0
        for a, b, c, d in Queries:
            a, b = a - 1, b - 1
            if sequence[b] - sequence[a] == c:
                score += d
        ans = max(ans, score)
    return ans

print(c_many_requirements())

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

const int NMX = 8;

int n,m;
vector<int> to[NMX];
int dfs(int v, vector<bool> visited) {
    bool all_visited = true;
    rep(i, n) {
        if (!visited[i]) all_visited = false;
    }
    if (all_visited) {
        return 1;
    }

    int ret = 0;
    for (int u : to[v]) {
        if (visited[u]) continue;
        visited[u] = true;
        ret += dfs(u, visited);
        visited[u] = false;
    }
    return ret;
}

int main()
{
    cin >> n >> m;
    rep(i,m) {
        int a,b;
        cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<bool> vs(n, false);
    vs[0] = true;
    int ans = dfs(0, vs);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

char u[4] = { 'N','S','W','E' };
bool b[4];
int main() {
	string s; cin >> s;
	REP(i, s.size()) {
		REP(j, 4) {
			if (s[i] == u[j])b[j] = true;
		}
	}
	cout << (b[0] == b[1] and b[2] == b[3] ? "Yes" : "No") << endl;
}



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

int main(){
    while (true)
    {
        string s;
        cin >> s;
        if(s == "-") break;
        int m;
        cin >> m;
        for(int i = 0; i < m; i++){
            int h; 
            cin >> h;
            s = s.substr(h) + s.substr(0, h);
        }
        cout << s << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
/*    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;       */
using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define ld long double
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define print(x) cerr << #x << " is " << x << endl;
//      typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;
    ll a[n], f[n];
    f(0, n) cin >> a[i];
    f(0, n) cin >> f[i];
    sort(a, a + n);
    sort(f, f + n);
    ll l = 0, r = 1000000000000, ans = -1;
    while (l <= r)
    {
        ll mid = l + r >> 1, x = 0;
        f(0, n)
        {
            if (a[i] * f[n - 1 - i] <= mid)
                continue;
            ll y = mid / f[n - i - 1];
            x += a[i] - y;
        }
        if (x <= k)
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    string N;
    cin >> N;
    int f = 0;
    for(auto c : N)
        f += c - '0';
    istringstream iss(N);
    int x;
    iss >> x;
    if(x % f == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    ll ns = S.size(), nt = T.size();
    ll s_idx = 0;
    set<ll> st[26];
    map<ll, ll> mp;
    rep(i,0,ns){
        ll t = S[i] - 'a';
        mp[t]++;
        st[t].insert(i);
    }
    rep(i,0,nt){
        ll t = T[i] - 'a';
        if(mp[t] == 0){
            print(-1);
            return 0;
        }
    }
    ll ans = 0;
    rep(i,0,nt){
        ll t = T[i] - 'a';
        auto iter = st[t].lower_bound(s_idx);
        if(iter == st[t].end()){
            ans += ns - s_idx;
            s_idx = 0;
            auto iter2 = st[t].lower_bound(0);
            ll v = *iter2;
            ans += v+1;
            s_idx = v+1;
        }else{
            ll v = *iter;
            ans += v+1 - s_idx;
            s_idx = v+1;
        }

    }
    print(ans);

    
}

Measured memory_bytes: 5200
#include <stdio.h>
int D;
int c[26];
int l[367][26];
int s[366][26];
int t[366];
int m, p, q, d, k;
int md[100000];
int mq[100000];
int ans;
int main() {
	scanf("%d", &D);
	for (int i = 0; i < 26; i++) {
		scanf("%d", c + i);
	}
	for (int i = 1; i <= D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", s[i] + j);
		}
	}
	for (int i = 1; i <= D; i++) {
		scanf("%d", t + i);
		t[i]--;
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", md + i, mq + i);
		mq[i]--;
	}
	for (int i = 1; i <= D; i++) {
		ans += s[i][t[i]];
		for (int j = 0; j < 26; j++) {
			l[i][j] = l[i - 1][j] + 1;
		}
		l[i][t[i]] = 0;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * l[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		q = mq[i];
		d = md[i];
		p = t[d];
		t[d] = q;
		ans -= s[d][p];
		ans += s[d][q];
		k = d;
		while (l[k][q] && k <= D) {
			ans -= c[q] * (k - d - l[k][q]);
			l[k][q] = k - d;
			k++;
		}
		k = d;
		do {
			ans -= c[p] * (l[k - 1][p] + 1 - l[k][p]);
			l[k][p] = l[k - 1][p] + 1;
			k++;
		} while (l[k][p] && k <= D);
		printf("%d\n", ans);
	}
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long h;
    cin >> h;
    long long ans = 1, cnt = 1;
    while(h > 1){
    	h /= 2;
    	cnt *= 2;
    	ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;

    while(1){
        cin >> n;
        if(n == 0){break;}
        double* s;
        s = new double[n];
        for(int i = 0; i < n; i++){
            cin >> s[i];
        }
        double sum = 0.0;
        double ave;
        for(int i = 0; i < n; i++){
             sum += s[i];
        }
        ave = sum / n;

        double sum2 = 0;
        double std;
        for(int i = 0; i < n; i++){
             sum2 += pow(s[i] - ave, 2);
        }
        
        std = sqrt(sum2 / n);
        printf("%.10f\n", std);
        delete [] s;
    }
    
    return 0;
}



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

int main(){
  int a, b;
  cin >> a >> b;

  string s;
  rep(i, max(a, b)){
    s += to_string(min(a,b));
  }

  cout << s << endl;

}


Measured memory_bytes: 256
//Created Time:2020年01月05日 星期日 18时54分37秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 100005

using namespace std;

int n;
int a[N];

bool cmp(int x, int y){
	return x > y;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	sort(a + 1, a + 1 + n, cmp);
	int pos = 1;
	while(a[pos + 1] >= pos + 1) ++pos;
	int p = pos;
	while(a[p + 1] == pos) ++p;
	if((a[pos] - pos) & 1 || (p - pos) & 1) puts("First");
	else puts("Second");
    //	cout << a[pos] << ' ' << pos << endl;
    return 0;
}


Measured memory_bytes: 640
// finish date: 2018/12/15

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;
    int N = s.length();
    int st = N;
    //最初のFの処理
    
    rep(i, N) {
        if (s[i] == 'F') x--;
        else {
            st = i + 1;
            break;
        }
    }
    vi X, Y;
    int sign = 1;
    int cnt = 0;

    //XとYの移動距離をリストに
    FOR(i, st, N) {
        if (s[i] == 'F') cnt++;
        if (i == N - 1 || s[i] == 'T') {
            if (sign == 1) Y.push_back(cnt);
            else X.push_back(cnt);
            sign *= -1;
            cnt = 0;
        }
    }

    vvb isReachedX(X.size() + 1, vb(16001, false)), isReachedY(Y.size() + 1, vb(16001, false));
    isReachedX[0][8000] = true;
    isReachedY[0][8000] = true;
    FOR(i, 1, isReachedX.size()) {
        rep(j, isReachedX[0].size()) {
            if (isReachedX[i - 1][j] == true) {
                isReachedX[i][j + X[i - 1]] = true;
                isReachedX[i][j - X[i - 1]] = true;
            }
        }
    }

    FOR(i, 1, isReachedY.size()) {
        rep(j, isReachedY[0].size()) {
            if (isReachedY[i - 1][j] == true) {
                isReachedY[i][j + Y[i - 1]] = true;
                isReachedY[i][j - Y[i - 1]] = true;
            }
        }
    }
    
    
    if (x + 8000>=0 && y+8000>0 &&isReachedX[isReachedX.size() - 1][x + 8000] && isReachedY[isReachedY.size() - 1][y + 8000]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define ll long long
int N=INT_MAX;
ll INF1=1e9 + 5;
ll INF2=1e18L + 5;
map<int ,int>my;
double dp[3009];

int main(){
    int n;
    cin>>n;
    double head;
    dp[0]=1;
    for(int i=1;i<=n;i++){
        cin>>head;
        for(int j=i;j>=0;j--){
            if(j!=0)
            dp[j]=dp[j]*((double)(1-head)) + dp[j-1]*head;
            else{
                dp[j]*=(1-head);
            }
        }
    }
    double ans=0;
    /*for(int i=n;i>=0;i--){
        cout<<dp[i]<<" ";
    }cout<<endl;*/
    //cout<<dp[2]<<endl;
    for(int i=0;i<=n/2;i++){
        ans+=dp[n-i];
    }

    cout<<setprecision(10)<<ans;
    //cout<<"YEs";
    return 0;
}


Measured memory_bytes: 256
import math
 
A,B,H,M = map(int,input().split())
angh = H*30+M*0.5
angm = M*6
ang = abs(angh - angm)%360
C = (A**2+B**2-2*A*B*math.cos(math.radians(ang)))**0.5
 
print(C)

Measured memory_bytes: 9504
n=io.read("*n","*l")
a={}
for i=1,3*n do
    a[i]=io.read("*n")
end
table.sort(a)

total=0
for i=3*n,2,-2 do
    if i<=n then
        break
    end
    total=total+a[i-1]
end
print(total)

Measured memory_bytes: 8568
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

int dp[101][4];
int dp2[101][4];

signed main() {
    string s;
    int k;
    cin >> s >> k;

    dp[0][0] = 1;

    rep(i, s.size()) {
        int d = s[i] - '0';
        if (i == 0) {
            dp[1][0] = 1;
            dp[1][1] = d - 1;
            dp2[1][1] = 1; 
        } else {
            if (d == 0) {
                rep(j, 4) {
                    if (j + 1 <= 3) dp[i + 1][j + 1] += dp[i][j] * 9;
                    dp[i + 1][j] += dp[i][j];
                    dp2[i + 1][j] += dp2[i][j];
                }
            } else {
                rep(j, 3) {
                    dp[i + 1][j + 1] += dp[i][j] * 9 + dp2[i][j] * (d - 1) + dp2[i][j + 1];
                    dp2[i + 1][j + 1] += dp2[i][j];
                }
                rep(j, 4) {
                    dp[i + 1][j] += dp[i][j];
                }
            }
        }
    }

    cout << dp[s.size()][k] + dp2[s.size()][k];

    return 0;
}


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

int main() {
    ll n,m;
    cin>>n>>m;
    if (n>m)
        swap(n,m);
    ll ans;
    if (n==1) {
        if (m==1)
            ans=1;
        else
            ans=m-2;
    } else
        ans=(n-2)*(m-2);
    cout<<ans<<endl;
    return 0;
}

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

const int N = 110;

char s[N], t[N];

int main(){
	int n;
	scanf("%d%s%s", &n, s, t);
	for (int i = 0; i <= n; ++ i){
		bool flag = true;
		for (int j = i; j < n; ++ j){
			if (s[j] != t[j - i]){
				flag = false;
				break;
			}
		}
		if (flag){
			printf("%d\n", n + i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int H, N, P;
	cin >> H >> N;
	P = 0;
	for(int i=1; i<=N;i++) {
		int tmp;
		cin >> tmp;
		P += tmp;
	}
	if(H<=P) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	return 0;
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	vector<pair<ll,ll> > vp;
	vector<ll> v1,v2,v3;
	rep(i,0,n){
		ll a;
		cin>>a;
		if(a>0)v1.pb(a);
		else if(a<0)v2.pb(a);
		else v3.pb(a);
	}
	ll a;
	if(v1.sz==0&&v2.sz==0){
		cout << 0 << endl;
		rep(i,0,n-1){
			cout << 0 << " " << 0 << endl;
		}
		return 0;
	}
	else if(v2.sz==0&&v3.sz>0){
		ll sum = 0;
		rep(i,0,v1.sz){
			sum += v1[i];
		}
		cout << sum << endl;
		rep(i,0,v3.sz-1){
			cout << 0 << " " << 0 << endl;
		}
		a = 0;
		rep(i,0,v1.sz-1){
			cout << a << " " << v1[i] << endl;
			a -= v1[i];
		}
		cout << v1[v1.sz-1] << " " << a << endl;
		return 0;
	}
	else if(v2.sz==0&&v1.sz==1){
		a = v1[0];
	}
	else if(v2.sz==0){
		sort(all(v1));
		a = v1[0];
		rep(i,1,v1.sz-1){
			vp.pb(mp(a,v1[i]));
			a = a-v1[i];
		}
		vp.pb(mp(v1[v1.sz-1],a));
		a = v1[v1.sz-1]-a;
	}
	else if(v1.sz==0&&v3.sz>0){
		ll sum = 0;
		rep(i,0,v2.sz){
			sum -= v2[i];
		}
		cout << sum << endl;
		rep(i,0,v3.sz-1){
			cout << 0 << " " << 0 << endl;
		}
		a = 0;
		rep(i,0,v2.sz){
			cout << a << " " << v2[i] << endl;
			a -= v2[i];
		}
		return 0;
	}
	else if(v1.sz==0&&v2.sz==1){
		cout << -v2[0] << endl;
		cout << 0 << " " << v2[0] << endl;
		rep(i,0,v3.sz-1){
			cout << -v2[0] << " " << 0 << endl;
		}
		return 0;
	}
	else if(v1.sz==0){
		sort(all(v2));
		reverse(all(v2));
		a = v2[0];
		rep(i,1,v2.sz){
			vp.pb(mp(a,v2[i]));
			a = a-v2[i];
		}		
	}
	else if(v1.sz==1){
		a = v1[0];
		rep(i,0,v2.sz){
			vp.pb(mp(a,v2[i]));
			a = a-v2[i];
		}
	}
	else{
		a = v2[0];
		rep(i,0,v1.sz-1){
			vp.pb(mp(a,v1[i]));
			a = a-v1[i];
		}
		vp.pb(mp(v1[v1.sz-1],a));
		a = v1[v1.sz-1]-a;
		rep(i,1,v2.sz){
			vp.pb(mp(a,v2[i]));
			a = a-v2[i];			
		}
	}
	rep(i,0,v3.sz){
		vp.pb(mp(a,v3[i]));
		a = a-v3[i];
	}
	ll ans = vp[vp.sz-1].fi-vp[vp.sz-1].se;
	cout << ans << endl;
	rep(i,0,vp.sz){
		cout << vp[i].fi << " " << vp[i].se << endl;
	}
	return 0;
}

Measured memory_bytes: 5232
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
typedef long long ll;
using namespace std;

int r, g, b;
const int INF = 10e8;
void atozstring(){
	string s;
	cin >> s;
	int res = s.size();
	int p = 0;
	while (s[p++] != 'A')
		res--;
	int t = s.size() - 1;
	while (s[t--] != 'Z')
		res--;
	cout << res << endl;
}

int main() {
	atozstring();
	return 0;
}



Measured memory_bytes: 640
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n, k = MII()
    aa = MII()
    g = ft.reduce(gcd, aa)
    m = max(aa)
    if k <= m and k%g==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

if __name__ == '__main__':
    main()

Measured memory_bytes: 14584
#include<stdio.h>
int main(){
  long long i,c=1,M=1e9+7,d[100010][3]={};
  char s[100010];
  scanf("%s",s);
  for(i=0;s[i];i++){
    d[i+1][0]=d[i][0];
    d[i+1][1]=d[i][1];
    d[i+1][2]=d[i][2];
    if(s[i]=='A')d[i+1][0]=(d[i+1][0]+c      )%M;
    if(s[i]=='B')d[i+1][1]=(d[i+1][1]+d[i][0])%M;
    if(s[i]=='C')d[i+1][2]=(d[i+1][2]+d[i][1])%M;
    if(s[i]=='?'){
      d[i+1][0]=(d[i+1][0]*3+c      )%M;
      d[i+1][1]=(d[i+1][1]*3+d[i][0])%M;
      d[i+1][2]=(d[i+1][2]*3+d[i][1])%M;
      c=(c*3)%M;
    }

      
    //if(s[i]=='A'||s[i]=='?')d[i+1][0]+=(+1      )%M;
    //if(s[i]=='B'||s[i]=='?')d[i+1][1]+=(d[i][0]+d[i][1]*3)%M;
    //if(s[i]=='C'||s[i]=='?')d[i+1][2]+=(d[i][1]+d[i][2]*3)%M;
  }
  printf("%lld\n",d[i][2]);
  //for(i=1;s[i-1];i++)printf("%lld %lld %lld\n",d[i][0],d[i][1],d[i][2]);
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    for(char i='a';i<='z';i++){
        int k=0;
        for(int j=0;j<26;j++){
            if(S[j]==i){
                k++;
            }
        }
        if(k==0){
            cout<<S<<i<<endl; return 0;
        }
    }
    char max=S[25],min='z';
    for(int i=24;i>=0;i--){
        if(S[i]>max){
            max=S[i];
        }else{
            for(int j=0;j<i;j++){
                cout<<S[j];
            }
            for(int j=i+1;j<26;j++){
                if(S[i]<S[j]&&S[j]<min){
                    min=S[j];
                }
            }
            cout<<min<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    
}


Measured memory_bytes: 256
N, A, B, C = gets.split.map(&:to_i)
L = N.times.map { gets.to_i }

def calc_cost(v, list, c = 0)
  cost = c

  c1 = list.map { |i| (v - i).abs }.min + cost
  n = list.size

  c2 = if n > 1
         min_diff = Float::INFINITY
         min_pair = []

         [*0..(n-1)].combination(2) do |i, j|
           a = list[i]
           b = list[j]
           diff = (v - (a + b)).abs

           if min_diff > diff
             min_diff = diff
             min_pair = [i, j]
           end
         end

         nl = [list[min_pair[0]] + list[min_pair[1]]]

         list.each_with_index do |v, i|
           next if min_pair.include?(i)
           nl << v
         end

         calc_cost(v, nl, c + 10)
       else
         Float::INFINITY
       end

  [c1, c2].min
end

ans = Float::INFINITY

[*1..3].repeated_permutation(N) do |list|
  next if list.uniq.size <= 2

  listA = list.map.with_index { |c, i| c == 1 ? L[i] : nil }.compact
  listB = list.map.with_index { |c, i| c == 2 ? L[i] : nil }.compact
  listC = list.map.with_index { |c, i| c == 3 ? L[i] : nil }.compact

  costA = calc_cost(A, listA)
  costB = calc_cost(B, listB)
  costC = calc_cost(C, listC)
  cost = costA + costB + costC

  if ans > cost
    ans = cost
  end
end

puts ans


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = Integer.parseInt(sc.next());
			long[] arr = new long[n + 1];
			for (int i = 2; i <= n; i++) {
				int j = 1;
				int tmp = i * j;
				while (tmp <= n) {
					arr[tmp] += 1;
					j++;
					tmp = i * j;
				}
			}
			long ans = 0;
			for (int i = 1; i <= n; i++) {
				ans += i * (arr[i] + 1);
			}
			System.out.print(ans);
		}
	}
}

Measured memory_bytes: 116568