akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
char in[110];
int e[110000];
int f[110000];
int v[110000];
int y[110000];
pair<int,int> t[110000];
pair<int,int> s[110000];
int main(){
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d),a){
		map<string,int>m;
		for(int i=0;i<a;i++){
			scanf("%s%d",in,e+i);
			string tmp=in;
			m[tmp]=i;
			v[i]=0;
		}
		int now=0;
		for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
			y[(*it).second]=now++;
		}
		for(int i=0;i<b;i++){
			scanf("%s",in);
			string tmp=in;
			f[i]=m[tmp];
			v[f[i]]=1;
		}
		int sz=0;
		for(int i=0;i<a;i++){
			if(!v[i])s[sz++]=make_pair(-e[i],y[i]);
		}
		std::sort(s,s+sz);
		for(int i=0;i<b;i++)t[i]=make_pair(-e[f[i]],y[f[i]]);
		std::sort(t,t+b);
		int L=0;
		int R=min(b,c)+1;
		while(L+1<R){
			int M=(L+R)/2;
			int rem=c-M;
			if(c-M>=sz){
				L=M;continue;
			}
			long long pr=0;
			for(int i=0;i<M;i++){
				int tmp=t[i].first-s[rem].first;
				if(t[i].second>s[rem].second)tmp++;
				pr+=max(0,tmp);
			}
		//	printf("%d: %lld\n",M,pr);
			if(pr<=d)L=M;
			else R=M;
		}
		printf("%d\n",L);
	}
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }


/**
 *  最長共通接頭辞(LCP: Longest Common Prefix)を導出する
 *  NOTE: Z-Algorithm 計算量O(|S|)
 */
class LCPCulculator {
public:
    LCPCulculator() = default;
    explicit LCPCulculator(const string& S) :
        S_(S) { createTable(); }
    ~LCPCulculator() { }

    const string& getString() const { return S_; }
    const std::vector<int>& getTable() const { return table_; }
    const size_t& getMaxVal() const { return max_val_; }

    void run(const string& S) { S_ = S; createTable(); }

private:
    std::string      S_;
    std::vector<int> table_;
    size_t           max_val_;

    void createTable() {
        table_    = std::vector<int>(S_.size(), 0);
        table_[0] = S_.size();
        max_val_  = 0;
        size_t i = 1, j = 0, k = 0;
        while(i < S_.size()) {
            while(i + j < S_.size() && S_[j] == S_[i + j]) j++;
            table_[i] = j;
            max_val_  = max(max_val_, min(j, i));
            if(j == 0) { i++; continue; }
            k = 1;
            while(i + k < S_.size() && k + table_[k] < j) {
                table_[i + k] = table_[k];
                k++;
            }
            i += k; j -= k;
        }
    }
};

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

    int N;
    std::cin >> N;
    string S;
    std::cin >> S;

    int ans = 0;
    LCPCulculator lcp;
    for(int i = 0; i < N - 1; i++) {
        lcp.run(S.substr(i));
        chmax(ans, (int)lcp.getMaxVal());
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ans = "";

        String s = sc.nextLine();
        String rep = s.replaceAll("hi", "");
        if (rep.equals("")) ans = "Yes";
        else ans = "No";

        System.out.println(ans);
    }
}

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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
	string str;
	cin>>str;
	ll k = str.size();
    rep(i,0,str.size()-1){
        if(str[i]!=str[i+1]){
            k = min(k,ll(max(ll(i+1),ll(str.size()-1-i))));
        }
    }
    cout<<k<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define S 1000001
#define M 1000000007
#define newline cout<<"\n";
#define error  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
lli arr[S];
int main()
{lli h,i=1,count=1;
cin>>h;
if(h==1)
cout<<"1";
else
{
    while(h!=1)
    {
        h=h/2;
        count=count+(i*2);
        i=i*2;
    }
    cout<<count;
    //1099511627775
}
}


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

vector<vector<int>> edges(200010);
vector<int> nodes(200010, 0);
vector<bool> visited(200010, false);

int main(){
  int N, Q;
  
  cin >> N >> Q;
  for(int i=0; i<N-1; i++){
    int a, b; cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  for(int i=0; i<Q; i++){
    int p, x; cin >> p >> x;
    nodes[p] += x;
  }

  queue<int> que; que.push(1);
  while(!que.empty()){
    int c = que.front(); int cx = nodes[c];
    visited[c] = true; que.pop();
    for(int i=0; i<edges[c].size(); i++){
      if(!visited[edges[c][i]]){
        que.push(edges[c][i]);
        nodes[edges[c][i]] += cx;
      }
    }
  }


  for(int i=1; i<=N; i++){
    cout << nodes[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 15604
#include <iostream>
#include <numeric>

using namespace std;
using ll = long long;

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

  int s{};
  for (int i = 1; i <= a; ++i) {
    for (int j = 1; j <= a; ++j) {
      for (int k = 1; k <= a; ++k) {
        s += gcd(gcd(i, j), k);
      }
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3600
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut line = line.split_whitespace();
    let r = line.next().unwrap().parse::<usize>().unwrap();
    let g = line.next().unwrap().parse::<usize>().unwrap();
    let b = line.next().unwrap().parse::<usize>().unwrap();

    let n = r * 100usize + g * 10usize + b;
    if n % 4 == 0 {
        println!("YES");
    }
    else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
a=[list(map(int,input().split())) for _ in range(3)]
tf=[[0]*3 for _ in  range(3)]
n=int(input())
b=[]
for i in range(n):
  s=int(input())
  b.append(s)
for i in  b:
  for j in range(3):
    for k in range(3):
      if i==a[j][k]:
        tf[j][k]=1
for i in range(3):
  if tf[i]==[1,1,1]:
    print('Yes')
    exit()
  if [row[i] for row in tf]==[1,1,1]:
    print('Yes')
    exit()
if [tf[i][i] for i in range(3)]==[1,1,1]:
  print('Yes')
elif [tf[i][2-i] for i in range(3)]==[1,1,1]:
  print('Yes')
else:
  print('No')

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

int n,k;

int main()
{
	cin >> n >> k;
	int a = n / k;
	int b = n % k;
	int res = 0;
	if(b != 0) {
		res = 1;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	unsigned long long a, b, x;
	cin >> a >> b >> x;
	if (a == 0) {
		cout << b/x + 1 << endl;
	}
	else cout << (b / x + 1) - ((a - 1) / x + 1) << endl;
}


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

namespace ProgrammingContest_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = Enumerable.Range(-100, 201)
                                .Select(i => A.Select(x => (x - i) * (x - i)).Sum())
                                .Min();

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 2904
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll N;
    cin>>N;
    
    vector<ll> t(5);
    REP(i,5){
       cin>>t[i]; 
    }
    sort(ALL(t));
    
    cout<<((N+t[0]-1)/t[0])+4;
    
    return 0;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();
		int cnt = 0;
		for (int i = 0; i < n - 2; ++i){
			String tmp = s.substring(i, i + 3);
			if(tmp.equals("ABC"))
			++cnt;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

#define int long long

using namespace std;

int INF = 1e16 + 7;

void solve() {
    double n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        ans += d >= sqrt(x * x + y * y);
    }
    cout << ans;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3164
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

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


int N, M;

double val(vector<int> v){
	int n = v.size();
	sort(v.begin(), v.end());
	double med = (n & 1) ? v[n / 2] :(v[n / 2] + v[n + 1])/2;
	double avg = 0;
	for (auto& i : v){
		avg += i;
	}
	avg /= n;
	return abs(avg - med);
}

int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin >> N >> M;
	int k = N / 2 + 1;
	for (int i = 0; i < k; i++)
	{
		cout << (!i) + " " << 0;
	}
	for (int i = 0; i < N-k; i++)
	{
		cout << " " << M;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (b-a == c-b)cout << "YES";
    else cout << "NO";
    return 0;
}

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

n,m = map(int,input().split())
uf = UnionFind(n)
cnt = 0
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)
for i in uf.parents:
    if i < 0:
        cnt += 1
    
print(cnt - 1)

Measured memory_bytes: 10796
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
ll pre[MAX];
ll n,m,ans;
ll x[MAX],y[MAX],sum[MAX];
vector<ll>v;
ll Find(ll x)
{
    return pre[x]==x?x:pre[x]=Find(pre[x]);
}
int main()
{
    for(ll i=0;i<MAX;i++) pre[i]=i;
    for(ll i=0;i<MAX;i++) sum[i]=1;

    scanf("%lld%lld",&n,&m);
    for(ll i=1;i<=m;i++)
        scanf("%lld%lld",&x[i],&y[i]);

    for(ll i=m;i>=1;i--)
    {
        v.push_back(1LL*n*(n-1)/2-ans);

        ll fx=Find(x[i]);
        ll fy=Find(y[i]);

        if(fx!=fy)
        {
            ans+=1LL*sum[fx]*sum[fy];
            pre[fx]=fy;
            sum[fy]+=sum[fx];
        }
    }
    for(ll i=v.size()-1;i>=0;i--)
        printf("%lld\n",v[i]);

    return 0;
}


Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#include <math.h> /* M_PI */
int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2 * 60 + m2 - (h1 * 60 + m1) - k;
}


Measured memory_bytes: 3636
import numpy as np
h_w_list = [int(i) for i in input().split()]

if h_w_list[0] == 1 or h_w_list[1] ==1:
    print(1)

elif h_w_list[0]*h_w_list[1] % 2 == 0:    
    print(int(h_w_list[0]*h_w_list[1]/2))

else:
    print(int(np.ceil(h_w_list[0]*h_w_list[1]/2)))

Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;

ll solve(ll i,ll n){
  ll cnt=0;
  while(n>0){
    cnt+=n%i;
    n=n/i;
  }
  return cnt;
}

int main(){
  ll i,j;
  ll n,s;
  cin>>n>>s;
  for(i=2;i*i<=n;i++){
    if(solve(i,n)==s) {
      cout<<i<<endl;
      return 0;
    } 
  }
  ll ans=INF;
  for(i=1;i*i<=n;i++){
    ll q=s-i;
    ll r=n-q;
    if(q>=0&&r>=0&&r%i==0&&i<r/i&&q<r/i){
      ans=min(ans,r/i);
    }
  }
  if(n==s) ans=min(n+1,ans);
  if(ans<INF) cout<<ans<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
  // 1から順に足して行き、その数を除いた約数の和を引く(重複に注意）
  int N, K;
  cin >> N >> K;
  mint ans = 0;
  vector<int> reset(K+1);
  for (int i = 1; i <= K; i++) {
    int x = i - reset[i];
    ans += mint(K/i).pow(N) * (mint)x;
    for (int j = i; j <= K; j += i) {
      reset[j] += x;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 159772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const ll INF = 1LL<<60;

vector<vector<int>> v;

void dfs(int n, int m, int t=1, vector<int> vv=vector<int>())
{
  if (vv.size() >= n) {
    v.push_back(vv);
    return;
  }
  vv.push_back(t);
  for (int i=t; i<=m; i++) {
    dfs(n, m, i, vv);
  }

}

int main()
{
  int n, m, q; cin>>n>>m>>q;
  vector<int> a(q);
  vector<int> b(q);
  vector<int> c(q);
  vector<int> d(q);
  rep(i, q) {
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--; b[i]--;
  }
  dfs(n, m);

  int ans = 0;
  for (auto vv:v) {
    int tmp = 0;
    rep(i, q) {
      if (vv[b[i]]-vv[a[i]] == c[i]) tmp += d[i];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9872
use bigint;
($A,$B,$C,$D)=glob<>;
sub gcd{my($a,$b)=@_;$b?gcd($b,$a%$b):$a}
sub f{
	my$I=0+pop;
	$L=$C/gcd($C,$D)*$D;
	$I-($I/$C)-($I/$D)+($I/$L)
}
print f($B)- f($A-1)



Measured memory_bytes: 5120
n,q=map(int,input().split())
cnt=[0]*(n+1) #答えのリスト
lst=[[] for _ in range(n+1)] #連結リスト

for i in range(n-1):
    a,b=map(int,input().split())
    lst[a].append(b)
    lst[b].append(a)

for i in range(q):
    a,val=map(int,input().split())
    cnt[a]+=val

stack=[1]
visited=[None]*(n+1)
visited[1]=1
while stack:
    item=stack.pop()
    for i in lst[item]:
        if visited[i]==1:
            continue
        visited[i]=1
        stack.append(i)
        cnt[i]+=cnt[item]

print(" ".join(map(str,cnt[1:])))

Measured memory_bytes: 148528
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int s = in(), c = in();
    int ans = 0;
    if(2 * s >= c) cout << c / 2 << endl;
    else{
        ans += s;
        c -= 2 * s;
        ans += c / 4;
        cout << ans << endl;
    }
}

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

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const int maxn = 1e5 + 9;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x;
    cin >> x;
    int ans = x / __gcd(x, 360);
    ans = 360 * ans / x;
    cout << ans;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int n,m,Q,u[100010],d[100010],t=0,c[100010],Link[100010],color[100010][15];
vector <int> edge[100010];
struct dsa
{
	int v,nex;
}e[200010];
void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;}
void dfs(int now,int dis,int col)
{
	if (dis==-1) return;
	if (color[now][dis]) return;
	color[now][dis]=col;
	for (int i=0;i<edge[now].size();i++) 
	  dfs(edge[now][i],dis-1,col);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) {
		int xx,yy;
		scanf("%d%d",&xx,&yy);
		edge[xx].push_back(yy);
		edge[yy].push_back(xx);
	}
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++)
	  scanf("%d%d%d",&u[i],&d[i],&c[i]);
	for (int i=1;i<=n;i++)	edge[i].push_back(i);
	for (int i=Q;i;i--)
	  dfs(u[i],d[i],c[i]);
	for (int i=1;i<=n;i++)
	  cout<<color[i][0]<<endl;
}
	

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

int main(){
    int n;
    int d1[100],d2[100];
    int cun = 0;
    int ans = 0;

    cin >> n;
    for(int i = 0;i < n; i++){
        cin >> d1[i] >> d2[i];
    }
    for(int i = 0;i < n ;i++){
        if(d1[i] == d2[i]){
           cun++;
           if (cun >= 3){
               ans = cun;
               break;
           }
        }else{
           if(ans < cun) ans = cun;
           cun = 0;
        }
    }
    if (ans >= 3){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

return 0;
}

Measured memory_bytes: 3640
IN = gets.chomp

(0..(1 << 3) - 1).each do |bit|
  tmp = IN.clone
  (0..2).each do |i|
    if (bit >> i) & 1 == 1
      tmp.insert(3 - i, '+')
    else
      tmp.insert(3 - i, '-')
    end
  end
  if eval(tmp) == 7
    puts tmp + '=7'
    break
  end
end

Measured memory_bytes: 14384
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn hash(s: &Vec<char>) -> u64 {
    let r = 27;
    let mut ans = 0;
    for c in s.iter() {
        ans = r * ans + (*c as u64 + 1 - 'a' as u64);
    }
    ans
}

fn run() {
    input! {
        n: usize,
        s: chars,
    }
    let mut map = std::collections::HashMap::new();
    for i in 0..(1 << n) {
        let mut a = vec![];
        let mut b = vec![];
        for j in (0..n).rev() {
            if ((i >> j) & 1) == 1 {
                a.push(s[n + j]);
            } else {
                b.push(s[n + j]);
            }
        }
        let h = (hash(&a), hash(&b));
        let po = map.entry(h).or_insert(0);
        *po += 1;
    }
    let mut ans: u64 = 0;
    for i in 0..(1 << n) {
        let mut a = vec![];
        let mut b = vec![];
        for j in 0..n {
            if ((i >> j) & 1) == 1 {
                a.push(s[j]);
            } else {
                b.push(s[j]);
            }
        }
        let h = (hash(&a), hash(&b));
        match map.get(&h) {
            Some(&v) => ans += v,
            _ => (),
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 28744
N=int(input())
L=list(map(int, input().split()))
count=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            L2=[L[i],L[j],L[k]]
            L2.sort()
            if L2[0]+L2[1]>L2[2] and L2[0] != L2[1] and L2[1] != L2[2] and L2[2] != L2[0]:
                count+=1
                
print(count)

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

    using namespace std;

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        set<string>s;
        for(int i=0;i<n;i++){
            string str;
            cin>>str;
            s.insert(str);
        }
        cout<<s.size();
        return 0;
    }


Measured memory_bytes: 19220
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

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

    map <int,int, greater<int>> m1;
    int n=nxt();
    int k=power(2,n,1e8);
    for(int i=0;i<k;i++)
    {
        int x=nxt();
        m1[x]+=1;
    }
    //cout<<"came 2\n";
    multiset <int> s;
    s.insert(m1.begin()->first);
    m1.begin()->second-=1;
    if(m1.begin()->second==0)
        m1.erase(m1.begin());
    bool f=1;
    for(int i=1;i<=n;i++)
    {vector <int> v;
        //cout<<"came\n";
        for(auto it=s.begin();it!=s.end();it++)
        {
            int x=*it;
            auto it2=m1.upper_bound(x);
            if(it2==m1.end())
            {//cout<<x<<endl;
                f=0;
                break;
            }
            //cout<<x<<" "<<it2->first<<endl;
            it2->second-=1;
            v.push_back(it2->first);
            if(it2->second==0)
                m1.erase(it2);
        }
        //cout<<"new set: ";
        //for(auto it=s.begin();it!=s.end();it++)
           // cout<<*it<<" ";
        //cout<<endl;
    for(int j=0;j<v.size();j++)
        s.insert(v[j]);

        if(!f)
            break;
    }

    if(!f)
        cout<<"No\n";
    else
        cout<<"Yes\n";

    
    
    return 0;   
}


 
 


Measured memory_bytes: 13304
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}


int main(){
    int N;
    cin >> N;
    long long X[N];
    long long num_max=0;
    for(int i=0;i<N;++i){
        cin >> X[i];
        num_max=max(X[i],num_max);
    }
    long long num=10000000000,tmp=0;;
    for(int i=0;i<=num_max;++i){
        tmp=0;
        for(int j=0;j<N;++j){
            tmp+=pow(abs((X[j]-i)),2);
        }
        num=min(tmp,num);
    }
    cout << num;
    }


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

signed main(){
	string a, b, c;
	cin >> a >> b >> c;
	cout << string({char(a.front() - 32)}) + string({char(b.front() - 32)}) + string({char(c.front() - 32)}) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

string ans;

void ps(int n,char a){
    for(int i=0;i<n;i++) ans+=a;
    return;
}

int sumd(int n){
    int res=0;
    while(n>0){
        res=n%10;
        n/=10;
    }
    return res;
}

int main(){
    int n;cin>>n;
    int a[n];
    rep(i,0,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    int sa=0,sb=0;
    rep(i,0,n){
        if(i%2==0) sa+=a[i];
        else sb+=a[i];
    }
    cout<<(sa-sb)<<endl;
}    

Measured memory_bytes: 632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    int n, A;
    cin >> n >> A;
    ll dp[n * A + 55][n + 5][n + 5];
    int x[n];
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < n * A; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                dp[i + x[k]][j + 1][k + 1] += dp[i][j][k];
                dp[i][j][k + 1] += dp[i][j][k];
            }
        }
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += dp[A * i][i][n];
    }
    cout << sum << endl;
}


Measured memory_bytes: 60544
from enum import Enum
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
line = input()
num_query = int(input())
 
for loop in range(num_query):
 
    input_str = list(input().split())
 
    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]
 
    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]
 
    else: #print
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()


Measured memory_bytes: 6448
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

// 最大積載量 P の k 台のトラックで何個の荷物を積めるか？
int check(llong P) {
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    llong s = 0;
    while( s + T[i] <= P) {
      s += T[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

int solve() {
  llong left = 0;
  llong right = 100000 * 10000;  // 荷物の個数 x 1個当たりの最大重量
  llong mid;
  while ( right - left > 1 ) {
    mid = (left + right) / 2;
    int v = check(mid);  // mid == P を決めて何個積めるかチェック
    if ( v >= n ) right = mid;
    else left = mid;
  }

  return right;
}

int main() {
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) cin >> T[i];
  llong ans = solve();
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    
    if (!a && !b) {
        cout << 1 << endl;
    } else if (!a) {
        cout << b / x + 1 << endl;
    } else {
        cout << b / x - (a - 1) / x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	
	while (n > 0)
	{
		n /= 10;
		
		count++;
	}
	return count;
}
int digit(int n)
{
	
	int ans=0;
	while (n > 0)
	{
		ans+=n%10;
		n /= 10;
		
		
	}
	return ans;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n;
	cin>>n;
	int ans=1e9;
	FOR(i,1,n){
		ans=min(ans,digit(i)+digit(n-i));
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;







int main(void){
	long X,Y,Z;
	cin >> X ;
	cin >> Y;
	cin >> Z;
	
	int ans = 0;
	
	for(int i = 0; (i*(Y+Z)+Z) <= X; i++){
		ans = i;
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AlgoStudy
{
  class Program
  {    
    static void Main(string[] args)
    {
      int i = 1;
      string s;

      while (true)
      {
        s = Console.ReadLine();
        if (s.Equals("0")) break;

        Console.WriteLine("Case {0}: {1}", i++, s);
      }

    }
  }
}

Measured memory_bytes: 9264
#include <bits/stdc++.h>
#define int long long
using namespace std;

int N,A,B;
vector<int> h;
const int MAX=INT_MAX;

int func(int K){
	int sum=0;
	for(int i=0;i<N;i++)sum+=max(0LL,(h[i]-B*K+A-B-1)/(A-B));
	return sum;
}



signed main(){
	cin>>N>>A>>B;
	h.assign(N,0);
	for(int i=0;i<N;i++)cin>>h[i];
	int start=0,end=MAX;
	while(llabs(start-end)>1){
		int mid=(end+start)/2;
		if(func(mid)>mid)start=mid;
		else end=mid;
	}
	cout<<end<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Affine Cipher
 */
public class Main {

	static final char[][] hints = {{'t', 'h', 'i', 's'}, {'t', 'h', 'a', 't'}};

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = parseInt(br.readLine());

		for (int i = 0; i < n; i++) {
			String s = br.readLine();
			int[] c = cipher(s);
			char[] d = new char['z' + 1];
			for (char j = 'a'; j <= 'z'; j++) {
				d[((c[0] * (j - 'a') + c[1]) % 26) + 'a'] = j;
			}
			StringBuilder sb = new StringBuilder();
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(j) == ' ') {
					sb.append(' ');
				} else {
					sb.append(d[s.charAt(j)]);
				}
			}
			System.out.println(sb.toString());
		}
	}

	static int[] cipher(String s) {

		int[] ret = new int[2];

		StringTokenizer st = new StringTokenizer(s);

		while (st.hasMoreTokens()) {

			String w = st.nextToken();

			if (w.length() == 4) {

				char[] hint = (w.charAt(0) != w.charAt(3) ? hints[0] : hints[1]);

				for (int a = 0; a < 26; a++) {
					if (a % 2 != 0 && a % 13 != 0) {
						for (int b = 0; b < 26; b++) {
							StringBuilder h = new StringBuilder();
							for (int i = 0; i < hint.length; i++) {
								h.append((char) (((a * (hint[i] - 'a') + b) % 26) + 'a'));
							}
							if (w.equals(h.toString())) {
								ret[0] = a;
								ret[1] = b;
								return ret;
							}
						}
					}
				}

			}
		}

		return ret;
	}
}

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

int main()
{
  int n, m, a, b;
  int ans = 0;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  vector<int> way[n];
  rep(i, m) {
    cin >> a >> b;
    a--; b--;
    way[a].push_back(b);
    way[b].push_back(a);
  }

  rep(i, n) {
    bool maxflg = true;
    for (int j : way[i]) {
      if (h[i] <= h[j]) {
        maxflg = false;
        break;
      }
    }
    if (maxflg) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8740
#include<bits/stdc++.h>
using namespace std;
#define DB(x){if(DEBUG)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(LL i=(0);i<(b);++i)
#define FOR(i,a,b)for(LL i=(a);i<=(b);++i)
#define FORD(i,a,b)for(LL i=(a);i>=(b);--i)
#define ALL(x) (x).begin(),(x).end()
#define VV vector
template<typename X,typename Y>void MAX(X&a,Y b){a=(a>=b?a:b);}
template<typename X,typename Y>void MIN(X&a,Y b){a=(a<=b?a:b);}
typedef long long LL;typedef long double LD;
int DEBUG=0,MULTI=0,GCJ=0;

struct solver_t;solver_t *solver;
struct solver_t {

  struct fus_t {
    VV<int> PAR;
    fus_t(int N) {
      PAR.resize(N);
      REP (i, N) PAR[i] = i;
    }

    int parent(int x) {
      if (x == PAR[x]) return x;
      return PAR[x] = parent(PAR[x]);
    }

    void join(int L, int R) {
      PAR[parent(L)] = parent(R);
    }
  };

  void test() {
    fus_t fus(6);
    fus.join(0,1);
    fus.join(3,5);
    fus.join(1,3);
    FOR (i, 0, 5) DB(i<<" "<<fus.parent(i));

  }

  void solve() {
    int N, M;
    cin >> N >> M;
    VV <LL> A(N);
    REP (i, N) cin >> A[i];

    fus_t fus(N);

    REP (m,M) {
      int a, b;cin>>a>>b;
      fus.join(a, b);
    }

    int groups = 0;
    REP (i, N) if (fus.parent(i) == i) groups++;
    VV< VV<LL> > VALS(N);
    REP (i, N) VALS[fus.parent(i)].push_back( A[i] );

    vector<LL> Q;
    LL res = 0;
    if (groups == 1) {
      cout << 0 << "\n";
      return;
    }
    REP (i, N) if (VALS[i].size() ) {
      sort( ALL(VALS[i]) );
      REP (j, min( (int)VALS[i].size(), groups - 1) ) {
        if (j == 0) {
          res += VALS[i][j];
          continue;
        }
        Q.push_back(VALS[i][j]);
      }
    }
    if ((int)Q.size() < (groups - 2)) {
      cout << "Impossible\n";
      return;
    }
    else {
      sort( ALL(Q) );
      REP (i, (groups - 2)) {
        res += Q[i];
      }
      cout << res << "\n";
    }
  }
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  FOR(i,1,argc-1)for(int j=0;argv[i][j];j++)if(argv[i][j]=='.')freopen(argv[i],"r",stdin);
  FOR(i,1,argc-1)if(argv[i]==string("q"))DEBUG=1<<30;
  FOR(i,1,argc-1)if(argv[i]==string("gen")){(solver=new solver_t())->gen();exit(0);}
  FOR(i,1,argc-1)if(argv[i]==string("brute")){(solver=new solver_t())->brute();exit(0);}
  ios::sync_with_stdio(false),cin.tie(0);
  cout.setf(ios::fixed),cout.precision(10);int t;if(MULTI||GCJ)cin>>t;else t=1;
  FOR(i,1,t){if(DEBUG)cerr<<__LINE__<<" "<<i<<endl;if(GCJ)cout<<"Case #"<<i<<": ";
    solver = new solver_t();
    solver->test();
    solver->solve();
  }return 0;
}


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

int main(){
	int N,A,B;
  	scanf("%d %d %d",&N,&A,&B);
  	int plan1,plan2;
  	plan1 = N*A;
  	plan2 = B;
  	if (plan1 < plan2) printf("%d\n", plan1);
  	else printf("%d\n", plan2);
  	return 0;
  
}

Measured memory_bytes: 128
object Main extends App {
  /* 標準入力を読む */
  val stdinChar = io.StdIn.readLine

  /* 対になる文字列を返す
  * A->T
  * T->A
  * C->G
  * G->C
  * */
  val map: Map[Char,String] = Map('A'->"T",'T'->"A",'C'->"G",'G'->"C")

  println(map(stdinChar.head))
}

Measured memory_bytes: 27064
from collections import deque
def bfs(start, goal, g, n, visited):
    visited1 = [False]*(n+1)
    visited2 = [False]*(n+1)
    q = deque([start])
    visited[start] = 0
    while q:
        curr_node = q.popleft()
        if curr_node == goal: 
            return
        for next1_node in g[curr_node]:
            if visited1[next1_node]: continue
            visited1[next1_node] = True
            for next2_node in g[next1_node]:
                if visited2[next2_node]: continue
                visited2[next2_node] = True
                for next3_node in g[next2_node]:
                    if visited[next3_node] >= 0: continue
                    visited[next3_node] = visited[curr_node] + 1
                    q.append(next3_node)



def main():
    n,m = map(int, input().split())
    g = [ [] for _ in range(n+1)]

    for _ in range(m):
        u, v = map(int, input().split())
        g[u].append(v)

    s,t = map(int, input().split())
    

    visited = [-1]*(n+1)
    visited[0] = 0

    bfs(s, t, g, n, visited)
    print(visited[t])

if __name__ == "__main__":
    main()

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll N; cin >> N;
    map<ll, ll> len;
    vector<ll> ok;
    rep(i, N) {
        ll temp; cin >> temp;
        len[temp]++;
        if (len[temp] == 2) {
            ok.push_back(temp);
            len[temp] = 0;
        }
    }
    
    // ll bigger = -1;
    // ll smaller = -1;
    
    // for (auto itr = len.rbegin(); itr != len.rend(); itr++) {
        
    // }

    sort(ok.begin(), ok.end());
    ll bigger = ok[ok.size() -  1];
    ll smaller = ok[ok.size() - 2];
    ll ans = bigger * smaller;
    if (ok.size() <= 1) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;

int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

string alpha="abcdefghijklmnopqrstuvwxyz";

string s;



int main(){
	cin>>s;
	Rep(i,s.size()){
		Rep(j,alpha.size()){
			if(s[i]==alpha[j]){
				alpha.erase(alpha.begin()+j);
			}
		}
	}
	if(alpha.size()){
		cout<<alpha[0]<<endl;
	}
	else cout<<"None"<<endl;
	
	return 0;
}



Measured memory_bytes: 512