akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 200011
#define mod 1000000007

struct ball {
    int col;
    ll dim;
    int id;
};

int n, i, j, min_col, pos;
ll X, Y;
ball B[maxN], rez[maxN];
vector<int> list[maxN];

vector<ball> base, rest;
ball last;

bool us[maxN];
vector<int> cols;

ll fact[maxN];
ll inv_fact[maxN];
ll ans, aux;

ll poww(ll a, ll b) {
    ll ans = 1;

    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

void pre() {
    int i;

    fact[0] = 1;
    for (i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[n] = poww(fact[n], mod - 2);
    for (i = n - 1; i >= 1; i--)
        inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % mod;
    inv_fact[0] = 1;
}


void dfs(int node) {
    us[node] = true;
    cols.pb(rez[node].col);
    for (auto to : list[node])
        if (!us[to])
            dfs(to);
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d%lld%lld", &n, &X, &Y);
    pre();
    for (i = 1; i <= n; i++) scanf("%d%lld", &B[i].col, &B[i].dim), B[i].id = i, rez[i] = B[i];

    sort(B + 1, B + n + 1, [](const ball& a, const ball& b)->bool const {
        return mp(a.col, a.dim) < mp(b.col, b.dim);
    });

    for (i = 1; i <= n; i = j) {
        for (j = i; j <= n; j++) {
            if (B[i].col != B[j].col) break;
            if (B[i].dim + B[j].dim <= X) {
                list[B[i].id].pb(B[j].id);
                list[B[j].id].pb(B[i].id);
            }
        }
    }

    sort(B + 1, B + n + 1, [](const ball& a, const ball& b)->bool const {
        return a.dim < b.dim;
    });

    min_col = B[1].col;
    for (i = 1; i <= n; i++) {
        if (B[i].col == min_col)
            base.pb(B[i]);
        else
            rest.pb(B[i]);
    }

    reverse(base.begin(), base.end());
    pos = 0;

    for (auto act : base) {
        if (pos != 0) {
            list[act.id].pb(last.id);
            list[last.id].pb(act.id);
        }
        last = act;

        while (pos < rest.size()) {
            if (act.dim + rest[pos].dim > Y) break;
            list[act.id].pb(rest[pos].id);
            list[rest[pos].id].pb(act.id);
            pos++;
        }
    }

    ans = 1;
    for (int node = 1; node <= n; node++) {
        if (us[node]) continue;
        cols.clear();

        dfs(node);
        aux = fact[cols.size()];

        sort(cols.begin(), cols.end());
        for (i = 0; i < cols.size(); i = j) {
            for (j = i; j < cols.size(); j++)
                if (cols[i] != cols[j])
                    break;

            aux = (aux * inv_fact[j - i]) % mod;
        }

        ans = (ans * aux) % mod;
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 31856
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

const int MAX_N = 40;

ll v[MAX_N];
ll w[MAX_N];
vector<pl> x,y;

void func(int si,int ti,vector<pl> &x){
  int size=ti-si;
  rep(i,1<<size){
    pl p=pl(0,0);
    rep(j,size){
      if(i&(1<<j)){
        p.first+=w[si+j];
        p.second+=v[si+j];
      }
    }
    x.push_back(p);
  }
}
  
int main(){
  ll N,W;
  cin>>N>>W;
  rep(i,N){
  	cin>>v[i]>>w[i];
  }
  func(0,N/2,x);
  sort(x.begin(),x.end());
  func(N/2,N,y);
  sort(y.begin(),y.end());
    
  ll target=0,maxm=-(1LL<<60),ans=0;
    
  for(int i=x.size()-1;i>=0;i--){
    while(target<y.size() && x[i].first+y[target].first <=W ){
      maxm=max(maxm,y[target].second);
      target++;
    }
    ans=max(ans,maxm+x[i].second);
  }
  
  cout<<ans<<endl;
  return 0;
}

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

#define MAX 1299709

int main(void){
  // エラトステネスの篩
  vector<bool>  eratos(MAX+2, true);
  eratos[0] = eratos[1] = false;
  for(size_t i = 2; i * i <= eratos.size(); i++){
    if(eratos[i]){
      for(size_t j = 2; i * j <= eratos.size(); j++){
        eratos[i * j] = false;
      }
    }
  }
  eratos[eratos.size() - 1] = true;

  // PrimGapを全て計算
  vector<int>  ans(MAX+2, -1);
  size_t s = 2, t = 2;
  while(t != eratos.size() - 1){
    s = t;
    for(++t; !eratos[t]; ++t);    
    ans[s] = 0;
    for(size_t i = s + 1; i < t; i++){
      ans[i] = t - s;
    }
  }

  // 出力
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }
    cout << ans[n] << endl;
  }
  return 0;
}



Measured memory_bytes: 7876
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>1
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 20000+5
#define P pair<int,int>//first最短路径second顶点编号
using namespace std;
int N,M;
struct edge
{
    int to,dis,cost;
    edge(int to,int dis,int cost):to(to),dis(dis),cost(cost) {}
};
vector<edge>G[Maxn];//G[i] 从i到G[i].to的距离为dis，花费的钱为cost
int d[Maxn][Maxn];//d[i][j]从i到j的最短距离
int sum[Maxn];//sum[i]，起点到i之间所需要的花费的钱
void Dijk(int s)
{
    priority_queue<P,vector<P>,greater<P> >q;//按first从小到大出队
    for(int i=0; i<=N; i++)
        d[s][i]=INF;
    d[s][s]=0;
    q.push(P(0,s));
    while(!q.empty())
    {
        P p=q.top();
        q.pop();
        int v=p.second;//点v
        if(d[s][v]<p.first)
            continue;
        for(int i=0; i<G[v].size(); i++)
        {
            edge e=G[v][i];//枚举与v相邻的点
            if(d[s][e.to]>=d[s][v]+e.dis)
            {
                if(d[s][e.to]==d[s][v]+e.dis)//距离相等，比较谁花费的钱少
                    sum[e.to]=min(sum[e.to],e.cost);
                else//若d[s][e.to]>d[s][v]+e.dis，相求出最短距离，再求出最短距离所需要的钱
                    sum[e.to]=e.cost;
                d[s][e.to]=d[s][v]+e.dis;
                q.push(P(d[s][e.to],e.to));
            }
        }
    }
}
int main()
{
    IOS;
    while(cin>>N>>M,N+M)
    {
        MEM(sum,0);
        for(int i=1; i<=N; i++)
            G[i].clear();
        for(int i=0; i<M; i++)
        {
            int u,v,d,c;
            cin>>u>>v>>d>>c;
            G[u].push_back(edge(v,d,c));
            G[v].push_back(edge(u,d,c));
        }
        Dijk(1);//城市1到各个城市的最短距离
        int ans=0;
        for(int i=2; i<=N; i++)
            ans+=sum[i];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 5476
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::map<std::string, intmax_t> map;
  for (size_t i = 0; i < N; ++i) {
    char buf[16];
    scanf("%s", buf);
    std::string s = buf;
    std::sort(s.begin(), s.end());
    ++map[s];
  }

  intmax_t res = 0;
  for (auto const& p: map) {
    res += (p.second * (p.second-1)) / 2;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 11136
import math
from itertools import permutations


def get_distance(a,b):
    d = math.sqrt((a[1] - b[1]) ** 2 + (a[0] - b[0]) ** 2)
    return d

N = int(input())
mati = [list(map(int, input().split())) for _ in range(N)]
total = 0

for v in permutations(mati,N):
    for i in range(N-1):
        total += get_distance(v[i+1], v[i])
print(total/math.factorial(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    long long int N;
    cin >>N;
    long long int M[N+1],S[N];
    for(long long int i=0;i<N+1;i++){
    cin >> M[i];
    }
    sort(M,M+(N+1));
    for(long long int i=0;i<N;i++){
        S[i]=(M[i+1]-M[i]);
    }
    for(long long int i=0;i<N-1;i++){
       S[i+1]= __gcd(S[i],S[i+1]);
    }
    if(N==1)cout <<M[N]-M[N-1];else cout <<S[N-1];
 }



Measured memory_bytes: 1792
s = list(map(int,list(input())))
def search(i,current,signs):
    if i == 4:
        if current == 7:
            return signs
        else: return []
    return search(i+1,current+s[i],signs+['+']) + search(i+1,current-s[i],signs+['-'])
signs = search(1,s[0],[])
for i in range(4):
    if i == 3:
        print(s[i], end='')
    else:
        print(s[i], end='')
        print(signs[i], end='')
print('=7')

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

typedef long long ll;
ll n, a, s, c;
map<ll, ll> m;
int main()
{
	cin >> n;
	m[0] = 1;
	while (n--) {
		scanf("%lld", &a);
		s += a;
		c += m[s];
		m[s]++;
	}
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 12800
#include<stdio.h>
#include<math.h>
int main()
{
    unsigned long long  x,y,z,ans;
    scanf("%llu%llu%llu",&x,&y,&z);
    ans=x/(y+z);
    if(x<(ans*(y+z))+z)ans--;
    printf("%llu\n",ans);
                return 0;
}




Measured memory_bytes: 1704
#include<stdio.h>
int min(int a,int b){return a>b?b:a;}
int max(int a,int b){return a>b?a:b;}
int main()
{
	int A,B,C,D,P;
	scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
	return !printf("%d\n",min(A*P,B+(max(0,(P-C))*D)));
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    int n, k;
    while (cin >> n >> k) {
        if ((n + 1) / 2 >= k) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,h,mx,ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>h;
        if(i==1){mx = h;ans++;}
        else{
            if(h>=mx){mx = h;ans++;}
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update>
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*d,a*c,b*c,b*d}) << nl;
    return 0;
}

Measured memory_bytes: 3648
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
mod = 10**9 + 7
ans = 1

if n == k:
    for x in a:
        ans *= x
        ans %= mod
    print(ans)
    exit()

b = []
c = []
for x in a:
    if 0 <= x:
        b += [x]
    else:
        c += [x]

if len(b) == 0 and k % 2 == 1:
    c.reverse()
    for i in range(k):
        ans *= c[i]
        ans %= mod
    print(ans)
    exit()

b.reverse()
bi = 0
ci = 0
bl = len(b)
cl = len(c)
if k % 2 == 1:
    ans *= b[0]
    bi += 1
    k -= 1
while k > 0:
    if bl-1 <= bi:
        ans *= c[ci] * c[ci+1]
        ans %= mod
        ci += 2
    elif cl-1 <= ci:
        ans *= b[bi] * b[bi + 1]
        ans %= mod
        bi += 2
    else:
        if b[bi] * b[bi + 1] < c[ci] * c[ci + 1]:
            ans *= c[ci] * c[ci + 1]
            ans %= mod
            ci += 2
        else:
            ans *= b[bi] * b[bi + 1]
            ans %= mod
            bi += 2
    k -= 2
print(ans)

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

c=[int(input()) for i in range(a)]

minbox = min(c)
flag = 0

for i in c:
    b = b - i
    flag += 1


while True:
    if b < minbox:
        break
    else:
        b = b - minbox
        flag += 1
        continue
    break
print(flag)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

N = int(input().strip())
W_list=[int(i) for i in input().rstrip().split()]
#-----
ans=100*100
for i in range(1,len(W_list)):
    diff = abs( sum(W_list[:i]) - sum(W_list[i:]) )
    ans = min(ans, diff)
    
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <tuple>
using namespace std;

int main(){

    int a, b, c; cin >> a >> b >> c;

    if(c <= b + a){
        cout << b + c;
    }
    else if(c > b + a){
        cout << 2*b + a + 1;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100][101],b[102][102];

int main(){
  int h,w;
  cin >> h >> w;
  for(int i=0; i<h; i++)
   cin >> a[i];
  
  for(int i=0;i<h+2;i++)
    for(int j=0; j<w+2; j++)
      b[i][j] = '#' ;
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      b[i+1][j+1] = a[i][j];

  
  for(int i =0; i<h+2; i++){
    for(int j=0; j<w+2; j++)
      cout << b[i][j];
    cout << endl;
  }
    

}

Measured memory_bytes: 3576
#include "bits/stdc++.h"
 
using namespace std;
 
int main() {
    string S;
    cin >> S;
    bool ok = S[0] == 'A';
    int cnt = 0;
    for (int i = 1; i < S.size(); i++) {
        if (i < 2 || i + 1 == S.size()) ok &= !!islower(S[i]);
        else if (S[i] == 'C') cnt++;
        else ok &= !!islower(S[i]);
    }
    ok &= cnt == 1;
    cout << (ok ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
// Created by new_sm
//
#include<bits/stdc++.h>
#define int long long
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int h,w,m;
cin>>h>>w>>m;
mii mp,mp1;
set<pii>st; 
while(m--)
{
    int row,col;
    cin>>row>>col;
    mp[row]++;
    mp1[col]++;
   st.insert({row,col});
}
int max1=0,max2=0;
for(auto &x:mp)
{
   max1=max(max1,x.second);

}
for(auto &x:mp1)
max2=max(max2,x.second);
vi row;
for(auto &x:mp)
{
    if(x.second==max1)
    row.pb(x.first);
}
vi col;
for(auto &x:mp1)
{
    if(x.second==max2)
    col.pb(x.first);
}
for(auto &x:row)
{
    for(auto &y:col)
    {
        if(st.find({x,y})!=st.end())
        continue;
        else
        {
            cout<<max1+max2;
            return ;
        }
        
    }
}
cout<<max1+max2-1;
}
signed main()
{
//code
fastio
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}

Measured memory_bytes: 67824
// <B.cpp> - Sat Apr  1 19:59:54 2017
// This file is created by XuYike's black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don't know what this program is.

#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
#define next NEXT
template<typename T>
inline void gg(T &res){
    res=0;T fh=1;char ch=getchar();
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    if(ch=='-')fh=-1,ch=getchar();
    while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
    res*=fh;
}
inline int gi(){int x;gg(x);return x;}
inline lol gl(){lol x;gg(x);return x;}
const int MAXN=100010;
const int MAXM=200010;
const int INF=1e9;
int bt,b[MAXN],next[MAXM],to[MAXM];
inline void add(int x,int y){
    next[++bt]=b[x];b[x]=bt;to[bt]=y;
    next[++bt]=b[y];b[y]=bt;to[bt]=x;
}
int f[12][MAXN],c[MAXN];
int main(){
    int n=gi(),m=gi();
    for(int i=1;i<=m;i++)add(gi(),gi());
    int q=gi();
    for(int i=1;i<=q;i++){
        int v=gi(),d=gi();c[i]=gi();
        f[d][v]=max(f[d][v],i);
    }
    for(int j=9;j>=0;j--)
        for(int i=1;i<=n;i++){
            f[j][i]=max(f[j][i],f[j+1][i]);
            for(int k=b[i];k;k=next[k])f[j][i]=max(f[j][i],f[j+1][to[k]]);
        }
    for(int i=1;i<=n;i++)printf("%d\n",c[f[0][i]]);
    return 0;
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long int
#define pb push_back
#define sx 200007
int main()
{
//    vector<pair<int,int> v;
    int maxi=0;
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
            cnt++;
        else
        {
            maxi=max(cnt,maxi);
            cnt=0;
        }
    }
    maxi=max(maxi,cnt);
    if(maxi>=3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

int n;
int a[100001],b[100001],c[100001];
int fa[100001],fb[100001],fc[100001];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(int i=1;i<=n;i++){
		fa[i]=a[i]+max(fb[i-1],fc[i-1]);
		fb[i]=b[i]+max(fa[i-1],fc[i-1]);
		fc[i]=c[i]+max(fb[i-1],fa[i-1]);
	}
	printf("%d",max(fa[n],max(fb[n],fc[n])));
	return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll N;
V v;

ll check(ll x){
    ll sum = 0;
    rep(i, N){
        if(v[i] <= x * 2 || v[i] <= sum * 2){
            sum += v[i];
        }
        else return 0;
    }
    return 1;
}

int main(){

    cin >> N;
    rep(i, N){
        ll a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    ll ok = N - 1, ng = -1;
    while(ng + 1 < ok){
        ll mid = (ng + ok) / 2;
        if(check(v[mid]))ok = mid;
        else ng = mid;
    }
    cout << N - ok << endl;
    
    return 0;
}

Measured memory_bytes: 1400
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());
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n - 1];

        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < n - 1; i++) {
            c[i] = Integer.parseInt(sc.next());
        }

        int prev = -1;
        int ret = 0;
        for (int an : a) {
            ret += b[an - 1];
            if (prev == an - 1) {
                ret += c[prev - 1];
            }
            prev = an;
        }

        System.out.println(ret);

    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi b(n,0), num(n,0);
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC"){
            if(b[p])continue;
            b[p] = 1;
        }else{
            if(b[p])continue;
            num[p]++;
        }
    }
    int cnt = 0;
    int ans = 0;
    rep(i,n)if(b[i]){
        cnt++;
        ans += num[i];
    }
    cout << cnt << " " << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
int main(){
  int x,k;
  int i;
 
  scanf("%d %d", &k, &x);
 
  for(i = x - k + 1;i < k + x - 1;i++){
    if(i >= -1000000 && 1000000 >= i) printf("%d ",i);
  }
 
  if(i >= -1000000 && 1000000 >= i) printf("%d\n", i);
 
  return 0;
}

Measured memory_bytes: 128
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val n = sc.nextInt()
        val d = sc.nextInt()
        val x = sc.nextInt()
        val a = Array(n) { sc.nextInt() }

        var ans = x
        for (i in 0 until d) {
            for(j in 0 until n){
                if(i%a[j]==0){
                    ans++
                }
            }
        }

        println(ans)
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 31384
line = STDIN.gets.split(" ")
size = Array.new(3) { |i| i = line[i].to_i}
matrixA = []
matrixB = []
matrixC = []

# matrixA
for i in 0..size[0] - 1 do
  line = STDIN.gets.split(" ")
  for j in 0..size[1] - 1 do
    # puts "i = #{i}, j = #{j}"
    line[j] = line[j].to_i
  end
  matrixA << line
  # print matrix
end
# print matrixA, "\n"

# matrixB
for i in 0..size[1] - 1 do
  line = STDIN.gets.split(" ")
  for j in 0..size[2] - 1 do
    # puts "i = #{i}, j = #{j}"
    line[j] = line[j].to_i
  end
  matrixB << line
  # print matrix
end
# print matrixB, "\n"

# calc
for i in 0..size[0] - 1 do
  line = []
  for j in 0..size[2] - 1 do
    sum = 0
    for k in 0..size[1] - 1 do
      # puts "i = #{i}, j = #{j}, k = #{k}"
      sum += matrixA[i][k] * matrixB[k][j]
    end
    # puts "sum = #{sum}"
    line << sum
  end
  puts line.join(" ")
end

Measured memory_bytes: 6228
N, K, Q = map(int, input().split(" "))

Points = [0] * N
for i in range(Q):
    RightAnserMan = int(input()) - 1
    Points[RightAnserMan] = Points[RightAnserMan] + 1

Points = map(lambda x: K - (Q - x), Points)

for point in Points:
    if point > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4680
str = gets.chomp.to_s
ori = Marshal.load(Marshal.dump(str))
words = ["dream","dreamer","erase","eraser"].permutation(4).to_a
#p words,words.size

result = []
i = 0
while i < words.size
  #p str,ori
  str = ori.dup
  j = 0
  while j < words[i].size
    #p "i:#{i}, j:#{j}, words[#{i}][#{j}]:#{words[i][j]} str:#{str}"
    if str.include?(words[i][j])
      str = str.gsub!(words[i][j],"")
    end
    j += 1
  end
  result << str
  i += 1
end

if result.include?("")
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 7164
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n,k = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
item = []
for key,value in c.items():
    item.append([value,key])
item.sort()
cnt = len(item)
i = 0
ans = 0
while True:
    if cnt <= k:
        break
    ans += item[i][0]
    i+=1
    cnt -= 1
print(ans)


Measured memory_bytes: 44960
#include<cstdio>
int main() {
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a==b){
		printf("a == b\n");
	}else if(a>b){
		printf("a > b\n");
	}
	return 0;
}


Measured memory_bytes: 2588
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <sstream>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

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

int main() {
    ios::sync_with_stdio(false);

    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    a *= ib;
    cout << a / 100 << endl;
    return 0;
}


Measured memory_bytes: 3220
implicit none
INTEGER(4) :: n,i,ans,k
REAL(8),ALLOCATABLE,DIMENSION(:) :: a

ans = 0
k = 0

READ(5,*) n
ALLOCATE(a(n))
READ(5,*) (a(i),i=1,n)

call heapsort(n,a)

do i=n,1,-1
    if(MOD(n-i,2)==0)then
        ans = ans+a(i)
    else
        ans = ans-a(i)
    endif
enddo

WRITE(6,"(i0)") ans

end

!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    INTEGER(4),INTENT(IN) :: n
    DOUBLE PRECISION,INTENT(INOUT) :: array(1:n)

    INTEGER(4) :: i,k,j,l
    DOUBLE PRECISION :: t

    if(n.le.0)then
        WRITE(6,*)"Error, at heapsort"; stop
    endif

    if(n.eq.1)return
        l=n/2+1
        k=n
        do while(k.ne.1)
            if(l.gt.1)then
                l = l-1
                t = array(l)
            else
                t=array(k)
                array(k) = array(l)
                k = k-1
                if(k.eq.1)then
                    array(1) = t
                    exit
                endif
            endif
            i = l
            j = l+l
            do while(j.le.k)
                if(j.lt.k)then
                    if(array(j).lt.array(j+1))j=j+1
                endif
                if(t.lt.array(j))then
                    array(i)=array(j)
                    i=j
                    j=j+j
                else
                    j=k+1
                endif
            enddo
            array(i)=t
    enddo
    RETURN
end subroutine


Measured memory_bytes: 768
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if abs(a-b)>k or abs(a-c)>k or abs(a-d)>k or abs(a-e)>k or abs(b-c)>k or abs(b-d)>k or abs(b-e)>k or abs(c-d)>k or abs(c-e)>k or abs(d-e)>k:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
D, G = map(int, input().split())

score_map = {}
for i in range(D):
    score_map[i] = list(map(int, input().split()))

result_list = []
for bit in range(1 << D):
    sum = 0
    result = 0
    not_used = D
    for i in range(D):
        if 1 & bit >> i:
            sum += score_map[i][1] + 100 * (i + 1) * score_map[i][0]
            result += score_map[i][0]
        else:
            not_used = i

    if not_used != D:
        for p in range(score_map[not_used][0]):
            if sum + (not_used + 1) * 100 * p >= G:
                result_list.append(result + p)

    else:
        if sum >= G:
            result_list.append(result)

print(min(result_list))


Measured memory_bytes: 7084
#include <iostream>

using namespace std;

int main(){
    long long int a,b,c,k;
    cin >> a >> b >> c >> k;
    if (b - a > 1000000000000000000 || b - a  < -1000000000000000000){
        cout << "Unfair" << endl;

    }else{
        if(k%2==1){
            cout << b - a << endl;
        }else{
            cout << a-b << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<int,int>
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const int MAXN=500005,Mo=1000000007;
const double eps=1e-8,INF=1e20,PI=3.141592653589793238462;
int n,a[10][10],b[MAXN];
struct list{
	int l,lt[MAXN],nt[MAXN],x[MAXN];
	void clear(){ l=0; memset(lt,0,sizeof(lt)); }
	void addedge(int a,int b){ l++; nt[l]=lt[a]; lt[a]=l; x[l]=b; }
}E;
int check(int x,int y,int z,int w,int m) {
	return a[a[a[a[a[0][x]][y]][z]][w]][m];
}
int main(){
	FOR(i,0,9)
		FOR(j,0,9) a[i][j]=read();
	int flag,ans=0;
	FOR(i,0,9999) {
		flag=0;
		int x=i/1000,y=i/100%10,z=i/10%10,w=i%10;
		//cout<<x<<' '<<y<<' '<<z<<' '<<w<<endl;
		int m=a[a[a[a[0][x]][y]][z]][w];
		if (check(x,y,z,w,m)!=0) cout<<"lxsb"<<endl;
		if (x!=y&&check(y,x,z,w,m)==0) flag=1;
		if (y!=z&&check(x,z,y,w,m)==0) flag=1;
		if (w!=z&&check(x,y,w,z,m)==0) flag=1;
		if (m!=w&&check(x,y,z,m,w)==0) flag=1;
		FOR(j,0,9) {
			if (j!=x&&check(j,y,z,w,m)==0) { flag=1; break; }
			if (j!=y&&check(x,j,z,w,m)==0) { flag=1; break; }
			if (j!=z&&check(x,y,j,w,m)==0) { flag=1; break; }
			if (j!=w&&check(x,y,z,j,m)==0) { flag=1; break; }
			if (j!=m&&check(x,y,z,w,j)==0) { flag=1; break; }
		}
		if (flag) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

/*
0 1 2 3 4 5 6 7 8 9
9 0 1 2 3 4 5 6 7 8
8 9 0 1 2 3 4 5 6 7
7 8 9 0 1 2 3 4 5 6
6 7 8 9 0 1 2 3 4 5
5 6 7 8 9 0 1 2 3 4
4 5 6 7 8 9 0 1 2 3
3 4 5 6 7 8 9 0 1 2
2 3 4 5 6 7 8 9 0 1
1 2 3 4 5 6 7 8 9 0

*/

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

int main(void) {
  ios::sync_with_stdio(false);
  int64_t X;
  cin >> X;
  int64_t yen = 100;
  int year = 0;
  while (yen < X) {
    yen = yen * 1.01;
    year++;
  }
  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

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

		int sum = 0;
		for (int i = 0; i < s.length(); i++) {
			sum += Integer.valueOf(Character.toString(s.charAt(i)));
		}

		if (sum % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}

Measured memory_bytes: 49800
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    int x, y;
    cin >> x >> y;
    for (int turtle = 0; turtle <= 100; turtle++) {
        for (int crane = 0; crane <= 100; crane++) {
            if ((turtle + crane == x) && (turtle * 4 + crane * 2 == y)) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
t = []
for i in range(n):
    for j in range(n):
        if not i == j:
            t.append([s[i][0] - s[j][0], s[i][1] - s[j][1]])
ans = n
for i in range(pow(n, 2) - n):
    cnt = 0
    for j in range(pow(n, 2) - n):
        if t[i][0] == t[j][0] and t[i][1] == t[j][1]:
            cnt += 1
    ans = min(ans, n - cnt)
print(ans)

Measured memory_bytes: 3444
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main() {

	int a, b;
	cin >> a >> b;
	if (a > b && b != 1)
		cout << "Alice" << endl;
	else if (b > a && a != 1)
		cout << "Bob" << endl;
	else if (a == 1 && b != 1)
		cout << "Alice" << endl;
	else if (b == 1 && a != 1)
		cout << "Bob" << endl;
	else if (a == b)
		cout << "Draw" << endl;

    return 0;
}



Measured memory_bytes: 3540
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,t,i,ans = 0;
    cin >> n >> t;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a.at(i);
    for(i=0;i<n-1;i++){
        ans += min(t,a.at(i+1)-a.at(i));
    }
    ans += t;
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, K; cin >> N >> K;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> s; // 訪れた頂点をメモ
  vector<int> ord(N + 1, -1); // ある頂点が何回目の移動時に訪れたか？
  // ↑+1しておかないと配列外参照する
  int c = 1, l = 0; // 周期
  {
    int v = 1; // スタート
    while(ord[v] == -1) { // すでに訪れた頂点かどうか
      ord[v] = s.size();
      s.push_back(v); // 訪れた頂点をメモ
      v = A[v - 1];
    }
    c = s.size() - ord[v]; // 周期
    l = ord[v]; // しっぽ
  }
  if(K < l) cout << s[K] << endl;
  else {
    K -= l;
    K %= c;
    cout << s[l + K] << endl;
  }
}

Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int n;
   cin>>n;
   int l,r;
   int ans = 0;
   for(int i = 0; i<n; i++){
       cin>>l>>r;
       ans = ans + (r-l+1);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    input = stdin.readline

    n = int(input())
    a = [[int(i) for i in input().split()] for _ in range(n)]

    ans = 0
    tf = [[True] * n for _ in range(n)]
    # Warshall-Floyd algorithm
    for k in range(n):
        for i in range(n-1):
            if i == k:
                continue
            for j in range(i, n):
                if j == k:
                    continue
                elif a[i][j] > a[i][k] + a[k][j]:
                    print(-1)
                    exit()
                elif a[i][j] == a[i][k] + a[k][j] and tf[i][j]:
                    ans -= a[i][j]
                    tf[i][j] = False
    
    ans += sum([sum(i) for i in a]) // 2
    print(ans)

main()

Measured memory_bytes: 70396
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int getValue(map<int,map<int,int>>& m, int a, int b){
	if(m.count(a)){
		if(m[a].count(b)){
			return m[a][b];
		}
	}
	return -1;
}

const int gmax_n = 80000;

int par[gmax_n]; //親
int depth[gmax_n];//木の深さ

void init(int n){
	rep(i,n){
		par[i] = i;
		depth[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(depth[x] < depth[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

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

void connect(map<int,map<int,int>>& m, int n, int p, int x, int y, int c){
	rep(i,4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		int np = getValue(m, nx, ny);
		if(np == -1) continue;
		if(np == p + n){
			unite(p, np + n);
			unite(p + n, np);
		}else{
			unite(p, np);
			unite(p + n, np + n);
		}
	}

	p += n;
	rep(i,4){
		int nx = x + dx[i] + (c == 'x' ? 1 : 0);
		int ny = y + dy[i] + (c == 'y' ? 1 : 0);
		int np = getValue(m, nx, ny);
		if(np == -1) continue;
		if(np != p - n){
			unite(p, np);
			unite(p + n, np + n);
		}
	}
}

bool f(int n){
	rep(i,n){
		if(same(i, i + n)) return false;
	}
	return true;
}

int main(){
	int n;
	while(cin >> n,n){
		init(n * 4);
		vector<int> x(n), y(n);
		vector<char> c(n);
		rep(i,n){
			cin >> x[i] >> y[i] >> c[i];
		}

		map<int,map<int,int>> ma;
		rep(i,n){
			ma[x[i]][y[i]] = i;
			if(c[i] == 'x') ma[x[i] + 1][y[i]] = i + n;
			else ma[x[i]][y[i] + 1] = i + n;
		}

		rep(i,n){
			connect(ma, n, i, x[i], y[i], c[i]);
		}
		cout << (f(n) ? "Yes" : "No") << endl;
	}
}



Measured memory_bytes: 8164
import sys
for line in sys.stdin.readlines():
    a, b, c, d, e, f=map(float,line.split())
    k=(a*e)-(b*d)
    xval=(c*e)-(b*f)
    yval=(a*f)-(c*d)
    g=xval/k
    h=yval/k
    if(xval==0):
        g=0
    if(yval==0):
        h=0
    print("%.3f %.3f"%(g,h))

Measured memory_bytes: 7376
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define REP(i,a,b) for(int i=a;i<(b);++i)
using namespace std;
typedef long long ll;

int a[8][8];

int h,w;
int check(int i, int j){
  int ret=0;
  // cout << "i,j"<<i <<","<<j<<endl;
  if(i==h-1 && j==w-1)
    return 1;
  if(i < h-1 && a[i+1][j])
    ret += check(i+1,j);
  if(j < w-1 && a[i][j+1])
    ret += check(i,j+1);
  return ret;
}

int main()
{
  int cnt=0;
  cin >> h >> w;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char ch;
      cin >> ch;
      if(ch == '#'){
	a[i][j]=1;
	cnt++;
      }
      else
	a[i][j]=0;
      //cout << a[i][j];
    }
    cout <<endl;
  }
  if(cnt!= h+w-1){
    cout <<"Impossible"<<endl;
    return 0;
  }
  if(check(0,0))
    cout << "Possible"<<endl;
  else
    cout <<"Impossible"<<endl;
}


Measured memory_bytes: 764
MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


def f(i, j):
    Fij = modFacts[i + j]
    Ii = invs[i]
    Ij = invs[j]
    rst = (Fij * Ii * Ij) % MOD
    return rst


def g(r1, r2, y):
    rst = 0
    for x in range(r1, r2 + 1):
        rst += f(x + 1, y)
        rst %= MOD
    return rst


r1, c1, r2, c2 = map(int, input().split())
modFacts, invs = prepare(max(r1, c1, r2, c2) * 2 + 1)


ans = g(r1, r2, c2) - g(r1, r2, c1 - 1)


print(ans % MOD)


Measured memory_bytes: 71916
#include<iostream>
using namespace std;
int main(void)
{
	int n,a;
	cin>>n>>a;
	while(1){
		if(n<500) break;
		n=n-500;
	}
	if(n<=a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    int res = 1;
    for (int i = 1; i < N; i++)
    {
        if (S.at(i) != S.at(i - 1))
            res++;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long a, b, v, w, t;
	long dist, speed;

	cin >> a >> v;
	cin >> b >> w;
	cin >> t;

	dist = abs(a - b);
	speed = v - w;
	if (speed <= 0) {
		cout << "NO" << endl;
		return 0;
	}

	long taiho = t * speed;

	if (taiho >= dist) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod=1e9+7;

int ans=0;
int power(int x, unsigned int y, int p)  
{  
  if(x==0)
    return 1;
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

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

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n,m,k;
  cin>>n>>m>>k;
  int f=0;
  for(int i=1;i<=n;i++)
  {
    int z=(n-i);
    f+=(z*(z+1))/2;
    z=i-1;
    f+=(z*(z+1))/2;
    f%=mod;    
  }
  f*=((m*m))%mod;
  f%=mod;
  int t=0;
  for(int i=1;i<=m;i++)
  {
    int z=(m-i);
    t+=(z*(z+1))/2;
    z=i-1;
    t+=(z*(z+1))/2;
    t%=mod;    
  }
  t*=((n*n))%mod;
  t%=mod;
  f+=t;
  f%=mod;
  f*=power(2,mod-2,mod);
  f%=mod;
  for(int i=0;i<k-2;i++)
  {
    f*=(n*m-2-i)%mod;
    f%=mod;
    f*=power(i+1,mod-2,mod);
    f%=mod;
  }
  cout<<f;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			Point3 p[]=new Point3[3];
			for(int i=0;i<3;i++) {
				p[i]=new Point3(in.nextDouble(), in. nextDouble());
				if(p[0].x==0&&p[0].y==0)
					return;
			}
			Point3 c=new Point3(in.nextDouble(), in.nextDouble());
			double r=in.nextDouble();
			boolean judge=false;
			if(ccw(p[0],c,p[1])==1&&ccw(p[1],c,p[2])==1&&ccw(p[2],c,p[0])==1
					||ccw(p[0],c,p[1])==-1&&ccw(p[1],c,p[2])==-1&&ccw(p[2],c,p[0])==-1)
				judge=true;

			double rd1=pointDistance(p[0], c);
			double rd2=pointDistance(p[1], c);
			double rd3=pointDistance(p[2], c);
			//円の中心と辺の距離
			double d1=Point3.lp_dis(c.x, c.y, p[0].x, p[0].y, p[1].x, p[1].y);
			double d2=Point3.lp_dis(c.x, c.y, p[1].x, p[1].y, p[2].x, p[2].y);
			double d3=Point3.lp_dis(c.x, c.y, p[2].x, p[2].y, p[0].x, p[0].y);

			if(judge)//円の中心が三角形内
			{

				if(r>=rd1&&r>=rd2&&r>=rd3)
					System.out.println("b");
				else if(r<=d1&&r<=d2&&r<=d3)
					System.out.println("a");
				else System.out.println("c");
			}
			else//円の中心が三角形外(接する含む)
			{
				if(r>=rd1&&r>=rd2&&r>=rd3)
					System.out.println("b");
				else if(r<d1&&r<d2&&r<d3)
					System.out.println("d");
				else System.out.println("c");
			}
		}
	}
	static double ccw(Point3 p1,Point3 p2,Point3 p3)
	{
		Point3 a=new Point3(p2.x-p1.x, p2.y-p1.y);
		Point3 b=new Point3(p3.x-p1.x, p3.y-p1.y);
		if(crossProduct(a, b)>0) return 1;//counter clockwise
		if(crossProduct(a, b)<0) return -1;//clockwise
		else return 0;
	}
	//外積
	static double crossProduct(Point3 a,Point3 b)
	{
		return a.x*b.y-a.y*b.x;
	}
	static double pointDistance(Point3 p1, Point3 p2)
	{
		return Math.hypot(p1.x-p2.x, p1.y-p2.y); 
	}
}

class Point3
{
	double x;
	double y;
	Point3(double x,double y)
	{
		this.x=x;
		this.y=y;
	}
	
	//point to line dis
	static double lp_dis(double px,double py,double x1,double y1,double x2,double y2)
	{
		double dx=x2-x1,dy=y2-y1;
		double a=dx*dx+dy*dy,b=dx*(x1-px)+dy*(y1-py);
		double t=-b/a;
		if(t<0) t=0;
		if(t>1) t=1;
		double tx=x1+dx*t;
		double ty=y1+dy*t;
		return Math.hypot(px-tx, py-ty);
	}	
}

Measured memory_bytes: 21400
using System;
public class Hello{
    public static void Main()
    {
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        int sum = 0;
        int num = N;
        while(num > 0)
        {
            int dig = num % 10;
            sum += dig;
            num = num / 10;
        }
        if(N % sum == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092