akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
int main(){
	fastio;
	ll n;
	cin>>n;
	if(n%2==1){
		cout<<0<<"\n";
		return 0;
	}
	ll sum = 0;
	sum += n/10;
	n /= 10;
	
	while(n>0){
		sum += n/5;
		n /= 5;
	}
	
	cout<<sum<<"\n";	
}

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

const long long MOD = 1LL << 32;

long long shl(int w) {
    return (1LL << w);
}


long long to_int(string hex) {
    long long ret = 0;
    for (int j = 0; j < hex.size(); ++j) {
        ret <<= 4LL;
        if ('0' <= hex[j] && hex[j] <= '9') {
            ret += hex[j] - '0';
        } else if ('a' <= hex[j] && hex[j] <= 'f') {
            ret += hex[j] - 'a' + 10;
        } else {
            assert(false);
        }
    }
    return ret;
}

string to_hex(long long bin) {
    string ret = "";
    bool leading_zero = true;

    long long shw = 28;
    for (int j = 0; j < 8; ++j, shw -= 4) {
        long long dig = (bin / (1LL << shw)) % 16LL;
        if (leading_zero && dig == 0) continue;
        leading_zero = false;
        if (0 <= dig && dig <= 9) {
            ret += (dig + '0');
        } else if (10 <= dig && dig <= 15) {
            ret += (dig - 10 + 'a');
        } else {
            assert(false);
        }
    }

    if (ret == "") return "0";
    return ret;
}

int main() {
    int S;
    cin >> S;
    for (int j = 0; j < S; ++j) {
        string chunks[9];
        int num[9];
        for (int k = 0; k < 9; ++k) {
            cin >> chunks[k];
            num[k] = to_int(chunks[k]);
        }

        long long K = 0;
        long long mask = 1;

        for (int b = 0; b < 32; ++b) {
            long long s = 0;
            
            for (int k = 0; k < 8; ++k) {
                s += (num[k] & (mask | shl(b+1))) ^ (K & mask);
            }
            s %= 1LL << (b+1);

            K |= (s & shl(b)) ^ (num[8] & shl(b));

            mask |= shl(b+1);
        }

        cout << to_hex(K) << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int>p;
p box[100001];
int main(void)
{
	int n,a,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		box[i].first=a;
		box[i].second=i;
	}
	sort(box+1,box+n+1);
	for(i=1;i<=n;i++){
		if(i!=1){
			printf(" ");
		}
		printf("%d",box[i].second);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
N,A,B,C,D=map(int,input().split())
S=input()

c1=S[B-2:D+1].count('...')
c2=S[A-1:D].count('##')

if c2>=1:
    print('No')
    exit()
else:
    pass

if C>D and c1==0:
    print('No')
    exit()
else:
    pass


print('Yes')


Measured memory_bytes: 9448
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0] * (M + 1) for _ in range(N + 1)]

for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        if s == t:
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % MOD
        else:
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD

print((dp[N][M] + 1) % MOD)


Measured memory_bytes: 72668
#include "bits/stdc++.h"
    using namespace std;
     
    #define DEBUG(x) cout<<#x<<": "<<x<<endl;
    #define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
    typedef long long ll;
    #define vi vector<int>
    #define vl vector<ll>
    #define vii vector< vector<int> >
    #define vll vector< vector<ll> >
    #define vs vector<string>
    #define pii pair<int,int>
    #define pis pair<int,string>
    #define psi pair<string,int>
    const int inf=1000000001;
    const ll INF=1e16;
    #define MOD 1000000007
    #define mod 1000000009
    #define pi 3.14159265358979323846
    #define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
    int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
     
    int main() {
    	ll k, i;
    	cin >> k;
    	int n = 50;
    	ll x = k / 50, y = k % 50;
    	vl a(n);
    	for (i = 0; i < n; i++) {
    		if (i < y) {
    			a[i] = (n - 1) + x + n - (y - 1);
    		}
    		else {
    			a[i] = (n - 1) + x - y;
    		}
    	}
    	cout << n << endl;
    	for (i = 0; i < n; i++) {
    		cout << a[i] << " ";
    	}
    	cout << endl;
    }

Measured memory_bytes: 256
// 8/2 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    if (X >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);

int A,B,C,D;
cin >> A>>B>>C>>D;

while (A>0 && C>0){
    C=C-B;
    if (C<=0){
        cout << "Yes";
        break;
    }
    A=A-D;
    if (A<=0){
        cout << "No";
        break;
    }   
}

	
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;

    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll b[m];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<m;i++) cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    reverse(a,a+n);
    reverse(b,b+m);

    ll valid=0;

    for(i=1;i<n;i++){
        if(a[i]==a[i-1]) valid=1;
    }
    for(i=1;i<m;i++){
        if(b[i]==b[i-1]) valid=1;
    }

    if(a[0]!=n*m||b[0]!=n*m) valid=1;
    
    if(valid==1){
        cout<<0<<endl;
        return 0;
    }

    ll aused[n];
    ll bused[m];

    for(i=0;i<m;i++) bused[i]=0;
    for(i=0;i<n;i++) aused[i]=0;

    ll pa=0,pb=0;
    ll ans=1;
    ll space=1;


    for(ll num=n*m;num>=1;num--){

        ll fa=0,fb=0;

        if(pa<n-1&&a[pa+1]>=num) {
            pa++;
            space+=pb+1;
            fa=1;
        }
        if(pb<m-1&&b[pb+1]>=num) {
            pb++;
            space+=pa+1;
            fb=1;
        }

        if(fa==0&&fb==0){
            ans*=space;
            ans%=Mod;
            space--;
        }
        else if(fa==0){
            ans*=pa+1;
            ans%=Mod;
            space--;
        }
        else if(fb==0){
            ans*=pb+1;
            ans%=Mod;
            space--;
        }
        else {
            space--;
        }


    }

    cout<<ans<<endl;
    return 0;

    


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a;
	string b;
	cin>>a>>b;
	long long c=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
	//cout<<c<<" ";
	c=a*c/100;
	cout<<c;
	return 0;
 } 

Measured memory_bytes: 3632
N,H=map(int,input().split())
# a=[];b=[]
s=[]
for i in range(N):
    # ai,bi=map(int,input().split())
    # a.append(ai);b.append(bi)
    s.append(tuple(map(int,input().split())))

s.sort(reverse=True)
a=s[0][0]
b=sorted([t[1] for t in s if t[1]>a],reverse=True)
'''
print(s)
print(a)
print(b)
'''
ans=0
for bi in b:
    H-=bi
    ans+=1
    if H<=0:
        break

if H>0:
    ans+=(H+a-1)//a

print(ans)

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

int main(){
    long long L,R;
    cin >> L >> R;
    int Lmod = L%2019, Rmod = R%2019;
    if(Rmod <= Lmod || R-L >= 2019) cout << 0 << endl;
    else{
        int ans = 2019;
        for(long long i = L;i < R;++i){
            for(long long j = i+1;j < R+1;++j){
                int imod = i%2019;
                int jmod = j%2019;
                ans = min(ans,(imod*jmod)%2019);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
long long a[100010],b[100010],c[100010];
int main()
{
    long long  n,i,j,sum=0;
    scanf("%lld",&n);
    for(i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    for(i=0; i<n; ++i)
        scanf("%lld",&b[i]);
    for(i=0; i<n; ++i)
        scanf("%lld",&c[i]);
        sort(a,a+n);
        sort(b,b+n);
        sort(c,c+n);
        for(i=0;i<n;++i)
        {long long ans;
            long long l=0,r=n-1,mid;
            while(r>=l)
            {
                mid=(r+l)/2;
                if(a[mid]>=b[i])
                {
                    r=mid-1;
                }
                else if(a[mid]<b[i])
                {
                    l=mid+1;
                }
            }
            ans=r+1;
            l=0,r=n-1,mid;
            while(r>=l)
            {
                mid=(r+l)/2;
                if(c[mid]>b[i])
                {
                    r=mid-1;
                }
                else if(c[mid]<=b[i])
                {
                    l=mid+1;
                }
            }
            ans*=(n-l);
            sum+=ans;
        }
        printf("%lld\n",sum);
    return 0;
}


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

bool dp[1010][5010];
int p[1010],x[1010],a[1010],ans = 0;
vector<int> ch[1010];

void solve(int i){
	int j,k,sum = 0;
	if(ch[i].size()==0){
		a[i] = 0;
	}
	for(j=0;j<ch[i].size();j++){
		solve(ch[i][j]);
	}
	for(j=0;j<ch[i].size();j++){
		sum += x[ch[i][j]]+a[ch[i][j]];
	}
	for(j=0;j<=ch[i].size();j++){
		for(k=0;k<=x[i];k++){
			dp[j][k] = false;
		}
	}
	dp[0][0] = true;
	for(j=0;j<ch[i].size();j++){
		for(k=x[i];k>=0;k--){
			if(dp[j][k]){
				if(k+a[ch[i][j]]<=x[i]){
					dp[j+1][k+a[ch[i][j]]] = true;
				}
				if(k+x[ch[i][j]]<=x[i]){
					dp[j+1][k+x[ch[i][j]]] = true;
				}
			}
		}
	}
	a[i] = -1;
	for(k=x[i];k>=0;k--){
		if(dp[ch[i].size()][k]){
			a[i] = sum - k;
			break;
		}
	}
	if(a[i]==-1){
		ans = -1;
	}
}
	
	
int main(){
	int i,n;
	cin >> n;
	for(i=2;i<=n;i++){
		cin >> p[i];
		ch[p[i]].push_back(i);
	}
	for(i=1;i<=n;i++){
		cin >> x[i];
	}
	
	solve(1);
	/*for(i=1;i<=n;i++){
		cout << a[i] << endl;
	}
	for(i=0;i<=ch[1].size();i++){
		for(int j=0;j<=x[1];j++){
			if(dp[i][j]){
				cout << i << " " << j << endl;
			}
		}
	}*/
	if(ans==-1){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << "POSSIBLE" << endl;
	}
}


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

int main()
{
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int time = 60 * (h2 - h1) + (m2 - m1);
    cout << time - k << endl;
    return 0;
}

Measured memory_bytes: 3636
from collections import Counter


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 factorization(n):
    arr = Counter()
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if len(arr.keys()) == 0 and n != 1:
        arr[n] = 1

    return arr


N, M = map(int, input().split())
modFacts, invs = prepare(N + 100)
primes = factorization(M)

ans = 1
for p in list(primes.keys()):
    q = primes[p]
    ans *= modFacts[q + N - 1] * invs[q] * invs[N - 1]
    ans %= MOD

print(ans)


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

int main(){
    int n; cin>>n;
    vector<int> s;

    for(int i=0; i<n; i++){
        int v; cin>>v;
        s.push_back(v);
    }

    int m,count=0; cin>>m;

    for(int i=0; i<m; i++){
        int t; cin>>t;
        if( *lower_bound(s.begin(),s.end(),t) == t) count++;
    }

    cout<<count<<endl;

    return 0;
}


Measured memory_bytes: 3464
#include <stdio.h>

int main(){
  int  n;
  double m;
  scanf("%d",&n);
  
  float ans;
  if(n%2==1){
    m=(n+1)/2;
    ans=m/n;
  }else{
    ans=0.5;
  }
  printf("%lf",ans);
  return 0;
}



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

using ll=long long;
using ld=long double;

void solve(){
	int n,d,cnt=0;
	cin>>n>>d;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		if(sqrt((x*x)+(y*y))<=d){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3696
import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F)[::-1]

left = -1
right = 10 ** 18

while left + 1 < right:
  mid = (left + right) // 2
  tmp = 0
  for i in range(N):
    a, f = A[i], F[i]
    if a * f > mid:
      tmp += -(-(a * f - mid) // f)
  if tmp <= K:
    right = mid
  else:
    left = mid
    
print(right)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int N,numbers[100],sum=0;
	cin>>N;
	REP(i,N){
		cin>>numbers[i];
		sum+=numbers[i];
	}
	SORT(numbers,N);

	if(sum%10!=0) printf("%d\n",sum);
	else{
		REP(i,N+1){
			if(i==N) printf("0\n");
			else if(numbers[i]%10!=0){
				printf("%d\n",sum-numbers[i]);
				break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
list1 = list(map(int,input().split()))
list2 = list(map(int,input().split()))
list3 = list(map(int,input().split()))
N=int(input())
i=0
list4=[]

rlist1=[]
rlist2=[]
rlist3=[]

while(i<N) :
  a = int(input())
  list4.append(a)
  i+=1

j=0

while(j<len(list4)):
  if(list1.count(list4[j])!=0):
    rlist1.append(list1.index(list4[j]))
  j+=1

k=0
while(k<len(list4)):
  if(list2.count(list4[k])!=0):
    rlist2.append(list2.index(list4[k]))
  k+=1

l=0
while(l<len(list4)):
  if(list3.count(list4[l])!=0):
    rlist3.append(list3.index(list4[l]))
  l+=1

result="No"

rlist1.sort()
rlist2.sort()
rlist3.sort()

if(len(rlist1)==3):
  result="Yes"

if(len(rlist2)==3):
  result="Yes"

if(len(rlist3)==3):
  result="Yes"

if(rlist1.count(0)!=0 and rlist2.count(0)!=0 and rlist3.count(0)!=0):
  result="Yes"

if(rlist1.count(1)!=0 and rlist2.count(1)!=0 and rlist3.count(1)!=0):
  result="Yes"

if(rlist1.count(2)!=0 and rlist2.count(2)!=0 and rlist3.count(2)!=0):
  result="Yes"

if(rlist1.count(0)!=0 and rlist2.count(1)!=0 and rlist3.count(2)!=0):
  result="Yes"

if(rlist1.count(2)!=0 and rlist2.count(1)!=0 and rlist3.count(0)!=0):
  result="Yes"

print(result)

Measured memory_bytes: 3192
ary = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
while n > 0:
    num = int(input())
    if num == a1[0]:
        ary[0][0] = 1
    if num == a1[1]:
        ary[0][1] = 1
    if num == a1[2]:
        ary[0][2] = 1
    if num == a2[0]:
        ary[1][0] = 1
    if num == a2[1]:
        ary[1][1] = 1
    if num == a2[2]:
        ary[1][2] = 1
    if num == a3[0]:
        ary[2][0] = 1
    if num == a3[1]:
        ary[2][1] = 1
    if num == a3[2]:
        ary[2][2] = 1
    n = n - 1
if (ary[0][0] == 1 and ary[0][1] == 1 and ary[0][2] == 1) or\
   (ary[1][0] == 1 and ary[1][1] == 1 and ary[1][2] == 1) or\
   (ary[2][0] == 1 and ary[2][1] == 1 and ary[2][2] == 1) or\
   (ary[0][0] == 1 and ary[1][0] == 1 and ary[2][0] == 1) or\
   (ary[0][1] == 1 and ary[1][1] == 1 and ary[2][1] == 1) or\
   (ary[0][2] == 1 and ary[1][2] == 1 and ary[2][2] == 1) or\
   (ary[0][0] == 1 and ary[1][1] == 1 and ary[2][2] == 1) or\
   (ary[0][2] == 1 and ary[1][1] == 1 and ary[2][0] == 1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<iostream>
#include<stack>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define ll long long
#define MST(vis,x) memset(vis,x,sizeof(vis))
#define maxn 200010
#define maxm 1010
#define INF 0x3f3f3f3f
int s1[maxn];
int s2[maxn];
int main()
{
    int n,m,x,y;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        MST(s1,-1);
        MST(s2,-1);
        for(int a=1;a<=m;a++)
        {
            scanf("%d%d",&x,&y);
            if(x>y)swap(x,y);
            if(x==1)s1[y]=1;
            if(y==n)s2[x]=1;
        }
        int judge=0;
        for(int a=2;a<=n-1;a++)
        {
            if(s1[a]!=-1&&s2[a]!=-1)
            {
                judge=1;
                break;
            }
        }
        if(judge==1)printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;

int main(void){
    int s;
    cin >> s;
    int a = s/100;
    int b = s%100;
    string ans;
    if(a == 0 && b >= 13){
        ans = "NA";
    }else if(b == 0 && a >= 13){
        ans = "NA";
    }else if(a == 0 && b == 0){
        ans = "NA";
    }else if(a >= 13 && b >= 13){
        ans = "NA";
    }else if(a >= 13 && b <= 12){
        ans = "YYMM";
    }else if(b >= 13 && a <= 12){
        ans = "MMYY";
    }else if(a <= 12 && b <= 12 && a != 0 && b != 0){
        ans = "AMBIGUOUS";
    }else if(a <= 12 && b <= 12 && a !=0 && b == 0){
        ans = "MMYY";
    }else if(a <= 12 && b <= 12 && a ==0 && b != 0){
        ans = "YYMM";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B) {
    cout << C << endl;
  }
  else if (B == C) {
    cout << A << endl;
  }
  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))

    for xx, yy, hh in points:
        if hh > 0:
            break
    for cx in range(101):
        for cy in range(101):
            f = True
            H = hh + abs(xx - cx) + abs(yy - cy)
            for x, y, h in points:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    f = False
                    break
            if f is True:
                print(cx, cy, H)
                return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
typedef int key;

int main(){
	int r,c,n;
	scanf("%d%d%d",&r,&c,&n);
	unordered_map<key,vector<pair<key,long long>>>m;
	for(;n;n--){
		int s1,s2,d;
		scanf("%d%d%d",&s1,&s2,&d);
		m[s1].emplace_back(s2+r,d);
		m[s2+r].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		long long a=-1LL<<61,b=1LL<<61;
		auto s=m.begin()->first;
		vector<pair<key,long long>>st={{s,0}};
		unordered_map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			memo[cur]=d;
			if(cur<=r)a=max(a,d);
			else b=min(b,d);
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return 0;
				}
			}
		}
		if(a>b){
			puts("No");
			return 0;
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}

Measured memory_bytes: 17864
import sys
input = sys.stdin.readline

def main():
	N,K=map(int,input().split())
	A=list(map(int,input().split()))
	if (N-1)%(K-1):
		print((N-1)//(K-1)+1)
	else:
		print((N-1)//(K-1))
if __name__=='__main__':
	main()

Measured memory_bytes: 13876
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    a = []
    for i in range(n):
        a.append(list(map(int, readline().split())))

    ans = INF
    for _ in range(m):
        cnt = [0] * (m + 1)
        for i in range(n):
            cnt[a[i][0]] += 1
        max_cnt = max(cnt)
        ans = min(ans, max_cnt)
        max_num = cnt.index(max_cnt)
        for i in range(n):
            a[i].remove(max_num)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74816
#include <stdio.h>

void swap(int *x,int *y);

int main(){
  int p,q,r;
  int *pp,*pq,*pr;
  pp = &p;
  pq = &q;
  pr = &r;
  scanf("%d %d %d",&p,&q,&r);

  if(p>q){swap(&p,&q);}
  if(q>r){swap(&q,&r);}

  printf("%d\n",p+q);

  return 0;
}

void swap(int *x,int *y){
  int temp;
  temp = *y;
  *y = *x;
  *x = temp;
}

        


Measured memory_bytes: 128
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
using namespace std;

int h[100002];
int dp[100002];

int main() {
  int n, k;

  while (cin >> n >> k) {
    for (int i = 0; i < n; i++) {
      cin >> h[i];
      dp[i] = INT_MAX;
    }

    dp[0] = 0;

    for (int i = 0; i < n; i++) {
      if (dp[i] == INT_MAX) continue;
      for (int j = 1; j <= k; j++) {
        if (i + j < n) {
          dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
      }
    }

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


Measured memory_bytes: 1024
n = int(input())

tmp = 0
cnt = 0
ans = 1

for i in range(1,n+1):
    s = i
    cnt = 0
    while True:
        if s % 2 == 0:
            cnt += 1
            s /= 2
        else:
            break
    if tmp < cnt:
        tmp = cnt
        ans = i

print(ans)

Measured memory_bytes: 3060
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    auto m = map<string, int>();
    for (auto i = 0; i < n; ++i) {
        auto s = string{};
        cin >> s;
        m[s]++;
    }
    /*
AC x 3
WA x 1
TLE x 2
RE x 0
    */

    string name[] = {"AC", "WA", "TLE", "RE"};
    for (auto s : name) {
        cout << s << " x " << m[s] << "\n";
    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int max_count = 0;
  
  map<char, bool> pre;
  int wh_count = 0;
  rep(i, N){
    pre[s[i]] = true;
  }
  for (auto p : pre) wh_count++;
  rep(i, N){
    string s1, s2;
    int count = 0;
    s1 = s.substr(0,i);
    s2 = s.substr(i);
    map<char, bool> A;
    map<char, bool> B;
    rep(j, s1.size()){
      A[s1[j]] = true;
    }
    
    for (auto p : A) count++;
    
    rep(k, s2.size()){
      B[s2[k]] = true;
    }
    
    for (auto p : B) count++;
    
    max_count = max(max_count, count - wh_count);
  }
  
  cout << max_count << endl;
      
}

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

using namespace std;

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

	int ans;
	if (c >= b){
		ans = b + min(c, a+b+1);
	}
	else{
		ans = b + c;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1,gtest=1;
//	cin>>test;
	while(test--)
	{
		int n,m,g;
		cin>>n>>m;
		g=(n-1)/2;
		int a[g],b[g];
		int j=g+1;
		int e=0,o=0;
		FOR(i,0,g)
		{
			if(i%2==0)
			{
				a[i]=e+1;
				b[i]=g-e+1;
				e++;
			}
			else
			{
				a[i]=o+1+j;
				b[i]=g-o+j;	
				o++;
			}
//			cout<<a[i]<<' '<<b[i]<<'\n';
		}
		FOR(i,0,m)
		cout<<a[i]<<' '<<b[i]<<'\n';
		
	}
	return 0;
}


Measured memory_bytes: 4260
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

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();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//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())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const LL MOD =1000000009;
int zz;
LL pe[66][5625];

inline void mulmatmat(LL *l, LL *r, LL *ans){
	REP(i,zz){
		FOR(j,i,zz){
			REP(k,zz){
				ans[i*75+j] = (ans[i*75+j]+l[i*75+k]*r[k*75+j])%MOD;
			}
			ans[j*75+i] = ans[i*75+j];
		}
	}
}

inline VLL mulmatvec(LL *l, VLL r){
	VLL ans(zz,0LL);
	REP(i,zz){
		REP(j,zz){
			ans[i]+=l[i*75+j]*r[j];
			ans[i]%=MOD;
		}
	}
	return ans;
}

inline void mulmatvec(LL k, VLL &r){
	int i=0;
	while(k){
		if(k&1)r=mulmatvec(pe[i], r);
		k>>=1;
		i++;
	}
}

int main(){
	int t=1;
	LL h,nb;
	while(scanf("%d%lld%lld",&zz,&h,&nb),zz){
		map<LL, VI> bar;
		VLL bary;
		memset(pe,0,sizeof(pe));
		REP(i,zz)FOR(j,max(0,i-1),min(zz,i+2))pe[0][i*75+j]=1LL;
		REP(i,65)mulmatmat(pe[i],pe[i],pe[i+1]);
		REP(i,nb){
			LL bx,by;
			scanf("%lld%lld",&bx,&by);
			bar[by].PB(bx);
			bary.PB(by);
		}
		bary.PB(h);
		SORT(bary);
		LL cur=1;
		VLL vec(zz,0);
		vec[0]=1LL;
		REP(i,bary.size()){
			LL p=bary[i]-cur;
			cur = bary[i];
			mulmatvec(p,vec);
			REP(j,bar[cur].size())vec[bar[cur][j]-1]=0LL;
		}
		printf("Case %d: %lld\n", t++, vec[zz-1]);
	}
	return 0;
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

int solve(map<vector<vector<bool>>, int>& memo, const vector<vector<bool>> &v, const set<int>& s) {
  if (v.size() <= 1) return 0;
  if (memo.find(v) != end(memo)) return memo[v];
  int res = 11;
  for (int i:s) {
    vector<vector<bool>> a, b;
    for (const auto& bs:v) {
      if (bs[i]) a.push_back(bs);
      else b.push_back(bs);
    }
    if (a.empty() || b.empty()) continue;
    set<int> ns = s;
    ns.erase(i);
    int score = max(solve(memo, a, ns), solve(memo, b, ns)) + 1;
    res = min(res, score);
  }
  memo[v] = res;
  return res;
}

int main() {
  while(1) {
    int m,n;
    cin>>m>>n;
    if(!m) break;
    vector<vector<bool>> vo(n, vector<bool>(m));
    REP(i,n) {
      string str;
      cin>>str;
      REP(j,m) vo[i][j] = str[j] == '1';
    }
    set<int> s;
    REP(i,m) s.insert(i);
    map<vector<vector<bool>>, int> memo;
    int res = solve(memo, vo, s);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 13460
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include  <algorithm>
typedef long long ll;
using namespace std;
const int maxn=101000;
int n,k;
int num[maxn];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&num[i]);
    int pos=lower_bound(num+1,num+n+1,0)-num;
    if(n==1){
        printf("%d\n",abs(num[1]));
    }else if(num[n]<=0){
        printf("%d\n",abs(num[n-k+1])); //n n-k+1
    }else if(num[1]>=0){
        printf("%d\n",num[k]);
    }else{
        int ans=5e8+1000;
        int f=min(k,n-pos+1);
        for(int i=0;i<=f;i++){
            int j=k-i,ff=pos-1;
            if(ff<j) continue;//pos<j+1;pos>=j+1
            ans=min(ans,abs(i==0?0:num[pos+i-1])+2*abs(j==0?0:num[pos-j]));
            ans=min(ans,2*abs(i==0?0:num[pos+i-1])+abs(j==0?0:num[pos-j]));
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

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

const int N = 1e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;

int main(int argc, char **args){
    ll k, n;
    cin >> k >> n;
    vector<ll>a(n);
    for(int i = 0; i < n; i++){
        scanf("%lld", &a[i]);
    }
    sort(a.begin(), a.end());
    ll mx = 0;
    for(int i = 1; i < n; i++){
        mx = max(mx, a[i] - a[i - 1]);
    }
    mx = max(mx, abs(k-a[n - 1]+a[0]));
    if(n == 1) puts("0");
    else cout <<k - mx <<"\n";
return 0;

}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//n種類の商品
		int m=sc.nextInt();		//人気商品n個
		int a=0;
		
		ArrayList<Integer>array=new ArrayList<>();
		for(int i=0;i<n;i++) {
			int b=sc.nextInt();	
			array.add(b);
			a=a+b;		//総投票数計算
		}
		
		int c=(a+4*m-1)/(4*m);
		int count=0;
		
		
		
		for(int i:array) {
			if(i>=c) {
				count++;
			}
		}
		
		if(count>=m) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
			}
		
		sc.close();
	}

}

Measured memory_bytes: 27084
import java.util.Scanner;
 
public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++){
            a[i] = stdIn.nextInt();
        }

        int[] b = new int[n+1];
        for(int i=n; i>=1; i--){
            int multipleSum = a[i];
            for(int j=2; i*j<=n; j++){
                multipleSum += b[i*j];
            }

            b[i] = multipleSum % 2;
        }

        int sum = 0;
        for(int i=1; i<=n; i++){
            sum += b[i];
        }
        System.out.println(sum);
        for(int i=1; i<=n; i++){
            if(b[i] == 1)
                System.out.print(i + " ");
        }
    }
}


Measured memory_bytes: 61616
import Control.Monad
import Data.Function
import Text.Read
import Text.ParserCombinators.ReadPrec

import qualified Data.ByteString.Char8 as B

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

main :: IO ()
main = do
  s <- B.getLine
  t <- B.getLine
  print $ solve s t

solve :: B.ByteString -> B.ByteString -> Int
solve = length . filter (== True) `dot` B.zipWith (/=)


Measured memory_bytes: 5856
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int N;
vector<long long> A;
vector<long long> sum;

int main() {
    cin >> N;
    A.resize(N); sum.resize(N+1); sum[0] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum[i+1] = sum[i] + A[i];
    
    long long res = 1LL<<60;
    for (int i = 0; i <= N; ++i) {
        // P < Q となる最大の切れ目を求める: 二分探索を終えた時の left_low
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        long long P = sum[low], Q = sum[i] - sum[low]; // 候補1
        long long P2 = sum[high], Q2 = sum[i] - sum[high]; // 候補2
        long long left_min = min(P, Q), left_max = max(P, Q);
        if (abs(P2-Q2) < abs(P-Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);
        
        // R < S となる最大の切れ目を求める
        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }
        long long R = sum[low] - sum[i], S = sum[N] - sum[low]; // 候補1
        long long R2 = sum[high] - sum[i], S2 = sum[N] - sum[high]; // 候補2
        long long right_min = min(R, S), right_max = max(R, S);
        if (abs(R2-S2) < abs(R-S)) right_min = min(R2, S2), right_max = max(R2, S2);
        
        // 真ん中の切れ目が i であるときの暫定解
        long long tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
}


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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

const int N = 1e6 + 4;
int cnt[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int r;
	for(int i=1; i<n; i++) {
		cin>>r;
		cnt[r]++;
	}
	for(int i=1; i<=n; i++)
		cout<<cnt[i]<<"\n";
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 10000000000
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

#define int ll
#define endl '\n'

int lcm(int x, int y) {
	if(x==inf) return inf;
	int g = __gcd(x,y);
	x/=g;
	if(log10(x)+log10(y)>10) return inf;
	x*=y;
	if(x>1000000000) return inf;
	return x;
}

signed main() {
	fast;

	int n,m;
	cin>>n>>m;
	vector<int> a(n);

	int l = 1;

	for(int i=0;i<n;i++) {
		cin>>a[i];
		a[i]/=2;
		l = lcm(l,a[i]);
	}

	for(int i=0;i<n;i++) {
		int temp = l/a[i];
		if(temp%2==0) {
			cout<<0;
			return 0;
		}
	}

	cout<<m/l-(m/(2*l));
}

Measured memory_bytes: 1024
loop {
    n = gets.to_i
    break if n == 0
    a = (1..n).map{ gets.split.map(&:to_i) }
    format = "%5d" * (n+1) + "\n"
    a.map!{|row| row + [row.inject(:+)]}
    a = a.transpose
    a.map!{|row| row + [row.inject(:+)]}
    a = a.transpose
    a.each{|row| printf(format, *row)}
}

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

int main() { 
  string n;
  cin >> n;
 
if (n == "Sunny")
  cout << "Cloudy" << endl; 
else if (n == "Cloudy")
  cout << "Rainy" << endl;
else
  cout << "Sunny" << endl;


    
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0)
    {
        cout<<1<<endl;
    }
    else if(b==0)
    {
        cout<<2<<endl;
    }
     else if(c==0)
    {
        cout<<3<<endl;
    }
     else if(d==0)
    {
        cout<<4<<endl;
    }
    else if(e==0)
    {
        cout<<5<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n,m,k;
    in(n,m,k);
    if(k%m==0||k%n==0){
        yn(1);
        return 0;
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*m+j*n-2*i*j==k){
                ans=1;
                goto skip;
            }
        }
    }
    skip:
    yn(ans);
}

Measured memory_bytes: 3764
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	int a[1010]={};
	int b[1010]={};
	int c[1010]={};
	int mat[110][110]={};
	
	for(int i=0;i<110;i++)
		for(int j=0;j<110;j++)
			if(i!=j)
				mat[i][j]=1e7;
	
	cin >> N >> M;
	for(int i=0;i<M;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		mat[a[i]][b[i]]=min(mat[a[i]][b[i]],c[i]);
		mat[b[i]][a[i]]=min(mat[b[i]][a[i]],c[i]);
	}
	
	for(int k=0;k<N;k++)
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
			
	int ans=0;
	for(int i=0;i<M;i++)
	{
		if(mat[a[i]][b[i]]!=c[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

        int suma = n * y;
        int sumb = n-y;
        int sumd = n +y;

        System.out.println(Math.max(Math.max(suma,sumb),sumd));

    }
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
	int i,j,k;
	int n;
	int x;
	int ans;
	
	for(;scanf("%d %d",&n,&x),n!=0||x!=0;){
		ans = 0;
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				for(k=j+1;k<=n;k++){
					if((i+j+k) == x){
						ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1001;
int n,x;
int a[N];
int main(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int i;
	for(i=1;a[i]<=x&&i<=n;x-=a[i],i++);
	if(i==n+1&&x) printf("%d",n-1);
	else printf("%d",i-1);
	return 0;
}

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

int main(){
	int n;
	string str;
	vector<string> st1;
	vector<int> st2;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string tmp_s;
		int tmp_i;
		cin >> tmp_s >> tmp_i;
		st1.push_back(tmp_s);
		st2.push_back(tmp_i);
	}
	cin >> str;

	bool flag = false;
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if(flag) {
			ans += st2[i];
		}
		if(st1[i] == str) flag = true;
		
	}

	cout << ans << endl;
}

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  complex<int> one(x1, y1);
  complex<int> two(x2, y2);
  complex<int> r(0, 1);

  complex<int> vec = two - one;

  int x3, y3, x4, y4;

  vec = vec * r;

  x3 = real(vec) + x2;
  y3 = imag(vec) + y2;

  vec = vec * r;

  x4 = real(vec) + x3;
  y4 = imag(vec) + y3;

  cout << x3 << endl;
  cout << y3 << endl;
  cout << x4 << endl;
  cout << y4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
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;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long N, std::vector<long long> a)
{
    int ans = 0;
    int cnt = 0;
    int tmp = 0;
    for (int i = 0; i < N; i++)
    {
        if (tmp != a[i])
        {
            ans += cnt / 2;
            tmp = a[i];
            cnt = 1;
        }
        else
        {
            cnt++;
        }
    }
    ans += cnt / 2;
    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
s = [input() for i in range(2)] 
li1 = list(map(int, s[0].split()))
li2 = list(map(int, s[1].split()))
N = li1[0]
K = li1[1]

li2.sort()
wa = 0
for i in range(K):
    wa = wa + li2[i]
print(wa)

Measured memory_bytes: 9264
#include <iostream>
using namespace std;
long long gcd(long long n, long long m){
    if(n%m==0) return m;
    else return gcd(m,n%m);
}
int main(void){
    long long a,b,c,d,x,y;
    cin >> a >> b >> c >> d;
    a--;
    x = b-b/c-b/d+b/(c*d/gcd(c,d));
    y = a-a/c-a/d+a/(c*d/gcd(c,d));
    cout << x-y;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e9;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

vector<pair<int,int>> permutation;
long double ans = 0;
long double cnt = 0;
void search(vector<pair<int, int>> cities, int n, vector<bool> chosen) {
    if (permutation.size() == n) {
        for (int i = 0; i < n-1; i++) {
            ans += sqrt(((permutation[i].first - permutation[i + 1].first) * (permutation[i].first - permutation[i + 1].first)) + ((permutation[i].second - permutation[i + 1].second) * (permutation[i].second - permutation[i + 1].second)));
        }
        cnt++;
    }
    else {
        for (int i = 0; i < n; i++) {
            if (chosen[i]) continue;
            chosen[i] = true;
            permutation.push_back(cities[i]);
            search(cities, n, chosen);
            chosen[i] = false;
            permutation.pop_back();
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> cities(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        cities[i] = { x, y };
    }
    vector<bool> chosen(n);
    search(cities, n, chosen);
    long double average = ans / cnt;
    printf("%Lf", average);
    return 0;
}

Measured memory_bytes: 3796
import math
def trial_division(n):
    primeN = n
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return primeN
    else:
        factor.append(n)
        if factor[-1]==1:
            factor.remove(1)
        return factor
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
#for i in range(100):
#N = i + 1

N = I()

#print(N)
if N >= 82:
    print("No")
    exit()
elif N == 70 or N == 80 or N == 60:
    print("No")
    exit()
ans = [1]

ans = trial_division(N)
if type(ans) is int:
    if ans >= 10:
        print("No")
    else:
        print("Yes")
elif max(ans) >= 10:
    print("No")
elif 5 in ans and ans.count(5) >= 2 and len(ans) >= 3:
    print("No")
elif 7 in ans:
    if ans.count(7) >= 2 and len(ans) >= 3:
        print("No")
    elif len(ans) >= 4:
        if 3 in ans:
            print("No")
        else:
            print("Yes")
    else:
        print("Yes")
elif len(ans) >= 6 and ans.count(3) >= 1:
    print("No")

else:
    print("Yes")

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,c,d;
    while(scanf("%d%d%d",&a,&b,&c)==3)
    {
        if(a<b && b<c)
            printf("Yes\n");
        else
          printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 2100
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    int N;
    ll p = 1;
    ll m = 1000000000000000000;
    ll A[100005];
    cin >> N;
    for (int i = 0; i < N; i++) {
        
        cin >> A[i];
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N; i++) {
        if (A[i] > m / p) {
            cout << -1 << endl;
            return 0;
        }
        p *= A[i];
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 4408