akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define mod 1000000007
#define inf 999999999999999ll
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,l;
    cin>>n>>m>>l;
    //vector <vii> adj(n,vii ());
    
    vv dist(n,vi(n,inf));
    for(ll i=0;i<n;i++)
        dist[i][i]=0;
    for(ll i=0;i<m;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        dist[a][b]=dist[b][a]=c;
    }

	for(ll k=0;k<n;k++)
	{
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
			{
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	vv d(n,vi(n,inf));
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(dist[i][j]<=l)
				d[i][j]=1;
		}
	}
	
	for(ll k=0;k<n;k++)
	{
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
    ll q;
    cin>>q;
    
    while(q--)
    {
        ll s,t;
        cin>>s>>t;
        s--;
        t--;
        if(d[s][t]>=inf)
        {
            cout<<-1<<endl;
            continue;
        }
    	cout<<d[s][t]-1<<endl;
    }
}


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

int main() {
	int h, w;
	cin >> h >> w;
	string s[50];
	for (int i = 0;i < h;i++)cin >> s[i];
	int dx[8] = { 0,1,1,1,0,-1,-1,-1 };
	int dy[8] = { 1,1,0,-1,-1,-1,0,1 };
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (s[i][j] == '#') {
				cout << s[i][j];
				continue;
			}
			int num = 0;
			for (int k = 0;k < 8;k++) {
				int ni = i + dy[k];
				int nj = j + dx[k];
				if (ni < 0 || ni >= h)continue;
				if (nj < 0 || nj >= w)continue;
				if (s[ni][nj] == '#')num++;;
			}
			cout << num;
		}
		cout << endl;
	}
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	int a, b;
	cin >> a >> b;
	cout << max(0, a - b - b) << endl;
	

}




Measured memory_bytes: 768
n = int(input())
numberlist = [int(x) for x in input().split()]

score = 0
score +=numberlist[0]

for i in range(n-1):
  if i == n-2:
    score +=numberlist[i]
  else:
    score +=numberlist[i] if numberlist[i] < numberlist[i+1] else numberlist[i+1]
print(score)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

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

  if(n == 100) n++;

  cout << n*(int)pow(100, d) << endl;;

  return 0;
}


Measured memory_bytes: 512
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
l = [[0]*W for i in range(H)]
r = [[0]*W for i in range(H)]
d = [[0]*W for i in range(H)]
u = [[0]*W for i in range(H)]

for h in range(H):
    if s[h][0] == ".": l[h][0] = 1
    for w in range(1,W):
        if s[h][w] == ".": l[h][w] = l[h][w-1] + 1
    if s[h][W-1] == ".": r[h][W-1] = 1
    for w in range(1,W):
        if s[h][W-1-w] == ".": r[h][W-1-w] = r[h][W-w] + 1

for w in range(W):
    if s[0][w] == ".": d[0][w] = 1
    for h in range(1,H):
        if s[h][w] == ".": d[h][w] = d[h-1][w] + 1
    if s[H-1][w] == ".": u[H-1][w] = 1
    for h in range(1,H):
        if s[H-1-h][w] == ".": u[H-1-h][w] = u[H-h][w] + 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, l[h][w]+r[h][w]+u[h][w]+d[h][w]-3)

print(ans)


Measured memory_bytes: 309640
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_N=300001;

int main(){
  int N;
  ll K;
  cin >> N >> K ;
  vector<P> v;
  rep(i,N){
    int a,b;
    cin >> a >> b;
    v.pb({a,b});
  }
  sort(ALL(v));
  ll next=1;
  int ans;
  rep(i,N){
    next+=v[i].second;
    //cout << next << endl;
    if(next>K){
      ans=v[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int N,i;
	while(cin>>N>>i)
	{
		cout<<N-i+1<<endl;	
	} 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,c,d;
  cin>>a>>b>>c>>d;
  long long int x=a*c,y=a*d,z=b*c,l=b*d;
  cout<<max(x,max(y,max(z,l)));
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
struct edge {int u,v,cost;};
int par[100001],Rank[100001];
edge es[200002];
int N;
bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

void init_union_find(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    Rank[i]=0;
  }
}

int find(int x){
  if(par[x]==x)return x;
  else return x=find(par[x]);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return ;
  if(Rank[x]<Rank[y]){
    par[x]=y;
  }
  else{
    par[y]=x;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}
bool same(int x,int y){
  return find(x) == find(y);
}
int main(){
  cin >> N;
  vector<pair<int ,int> > p(N),p2(N);
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    p[i]=make_pair(x,i);
    p2[i]=make_pair(y,i);
  }
  sort(p.begin(),p.end());
  sort(p2.begin(),p2.end());

  for(int i=0;i<N-1;i++){
    es[i].u=p[i].second;
    es[i].v=p[i+1].second;
    es[i].cost=p[i+1].first-p[i].first;
   
  }

   for(int i=0;i<N-1;i++){
    es[N-1+i].u=p2[i].second;
    es[N-1+i].v=p2[i+1].second;
    es[N-1+i].cost=p2[i+1].first-p2[i].first;
  
  }
   sort(es,es+2*(N-1),comp);
   //for(int i=0;i<2*(N-1);i++)  printf("%d %d %d\n",es[i].u,es[i].v,es[i].cost);
   init_union_find(N);
   ll res=0;
   for(int i=0;i<2*(N-1);i++){
     edge e=es[i];
     if(!same(e.u,e.v)){
       unite(e.u,e.v);
       res+=e.cost;
     }
   }
   cout << res << endl;
  return 0; 
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();scan.nextLine();
        String[] str = new String[n];
        for(int i = 0; i < n; i++) {
            str[i] = scan.nextLine();
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if (i != j && str[i].equals(str[j])) {
                    System.out.println("No");
                    return;
                }
            }
        }
        for(int i = 0; i < n-1; i++) {
            if (str[i].charAt(str[i].length()-1) != str[i+1].charAt(0)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#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>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n,m;
  cin>>n>>m;
  vector<double> l(n),a(n),b(n);
  rep(i,n)cin>>l[i]>>a[i]>>b[i];
  double ans=0;
  rep(i,1<<n){
    vi t;
    rep(j,n)if(i&(1<<j))t.push_back(j);
    double tmp=0;
    if(t.size()!=m)continue;
    rep(j,t.size())loop(k,j+1,t.size()){
      tmp+=(l[t[j]]-l[t[k]])*(l[t[j]]-l[t[k]]);
      tmp+=(a[t[j]]-a[t[k]])*(a[t[j]]-a[t[k]]);
      tmp+=(b[t[j]]-b[t[k]])*(b[t[j]]-b[t[k]]);
    }
    ans=max(ans,tmp);
  }
  cout<<shosu(10)<<ans<<endl;
}

Measured memory_bytes: 3296
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//contest
//sentence
//s e nte n ce
//7*4 + 5
//
// c ontest
int main() {
	string s, t;
	cin >> s >> t;
	vector<vector<int>> pos(26,vector<int>());
	for (int i = 0; i < s.size(); i++) {
		pos[s[i] - 'a'].push_back(i+1);
	}
	int fpos = -1;
	ll ans = 0;
	for (int i = 0; i < t.size(); i++) {
		auto a = upper_bound(pos[t[i]-'a'].begin(), pos[t[i]-'a'].end(), fpos);
		if (fpos == -1 && a == pos[t[i]-'a'].end()) {
			cout << -1 << endl;
			return 0;
		}
		else {
			if (a == pos[t[i]-'a'].end()) {
				fpos = -1;
				ans += s.size();
				a = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), fpos);
				if (a == pos[t[i] - 'a'].end()) {
					cout << -1 << endl;
					return 0;
				}
				fpos = *a;
			}
			else {
				fpos = *a;
			}
			if (i == t.size() - 1) {
				ans += fpos;
			}
		}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#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 FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
long long digits(long long num) {
    long long digit = num;
    int       d_sum = 0;
    while (digit > 0) {
        ++d_sum;
        digit /= 10;
    }
    return d_sum;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long N;
    cin >> N;
    long long ans = INF;
    for (long long A = 1; A < sqrt(N) + 1; ++A) {
        if (N % A == 0) { ans = min(ans, max(digits(A), digits(N / A))); }
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    int cnt=0;
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(l[k]<(l[i]+l[j])){
                    //cout << l[i] << " " << l[j] << " " << l[k]  <<endl;
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  static int words[] = new int[3];

  /** カウント */
  private static int COUNT_5, COUNT_7;

  /**
   * メインメソッド
   *
   * @param args 引数
   */
  public static void main(String[] args) {
    setData();
    calc();

    System.out.println(COUNT_5 == 2 && COUNT_7 == 1 ? "YES" : "NO");
  }

  /** 初期値設定 */
  private static void setData() {
    Scanner sc = new Scanner(System.in);
    words[0] = sc.nextInt();
    words[1] = sc.nextInt();
    words[2] = sc.nextInt();
  }

  /** 計算メソッド */
  private static void calc() {
    for (int word : words) {
      if (word == 5) {
        COUNT_5++;
      } else if (word == 7) {
        COUNT_7++;
      }
    }
  }
}

Measured memory_bytes: 19796
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int N;
	cin >> N;

	int arr[2000];
	for (int i = 0; i < N; ++i) cin >> arr[i];

	sort(arr, arr + N);

	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			ans += lower_bound(arr, arr + N, arr[i] + arr[j]) - arr - j - 1;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Data[] list = new Data[n*2];
			for(int i = 0; i < n; i++) {
				int m = sc.nextInt();
				long a = sc.nextLong();
				long b = sc.nextLong();
				list[i*2] = new Data(m,a);
				list[i*2+1] = new Data(-m,b);
			}
			
			Arrays.sort(list,new MyComp());
			for(int i = 0; i < n*2-1; i++) {
				if(list[i].a == list[i+1].a) {
					list[i+1].m += list[i].m;
					list[i].m = 0;
				}
			}
			
			int sum = 0;
			boolean flg = false;
			for(int i = 0; i < n*2; i++) {
				sum += list[i].m;
				if(sum > 150) {
					flg = true;
					break;
				}
			}
			if(flg) {
				System.out.println("NG");
			}
			else {
				System.out.println("OK");
			}
		}
	}
	
	static class Data {
		int m;
		long a;
		Data(int c, long d) {
			m = c;
			a = d;
		}
	}
	
	static class MyComp implements Comparator<Data> {

		@Override
		public int compare(Data o1, Data o2) {
			if(o1.a > o2.a) {
				return 1;
			}
			else if(o1.a < o2.a){
				return -1;
			}
			return 0;
		}
		
	}
	
		
}

Measured memory_bytes: 60456
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
char s[N],t[N];
vector<int> pos[30];
int main()
{
  scanf("%s",s);
  scanf("%s",t);
  int n=strlen(s),m=strlen(t),l=0;
  LL ans=0;
  for(int i=0;i<n;++i) pos[s[i]-'a'].push_back(i+1);
  for(int i=0;i<m;++i)
  {
    int x =t[i]-'a';
    int r = upper_bound(pos[x].begin(),pos[x].end(),l)-pos[x].begin();
    if(pos[x].empty())
    {
      ans=-1;
      break;
    }
    else 
    {
       if(r==pos[x].size())
       {
         ans+=(n-l+pos[x][0]);
         l=pos[x][0];
       }
       else
       {
         ans+=(pos[x][r]-l);
         l=pos[x][r];
       }
       
    }
  }
  printf("%lld",ans);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> white(N+1), black(N+1);
  for(int i=1; i<N+1; i++) {
    white[i] = white[i-1];
    black[i] = black[i-1];
    if(S[i-1] == '.')
      white[i]++;
    else
      black[i]++;
  }
  int ans = N+1;
  for(int i=0; i<N+1; i++) {
    ans = min(ans, black[i]+(white[N]-white[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
from collections import defaultdict
t = 1
def change(s):
    s_ = [[[s[z][y][x] for x in range(7)] for y in range(7)] for z in range(7)]
    for z in range(1,6):
        for y in range(1,6):
            for x in range(1,6):
                su = -s[z][y][x]
                for i in range(z-1,z+2):
                    for j in range(y-1,y+2):
                        for k in range(x-1,x+2):
                            su += s[i][j][k]
                if not s[z][y][x]:
                    if fa[su]:
                        s_[z][y][x] = 1
                else:
                    if not fb[su]:
                        s_[z][y][x] = 0
    return s_

while 1:
    n = int(input())
    if n == 0:
        break
    if t != 1:
        print()
    s = [[[0]*7 for i in range(7)]]
    for i in range(5):
        s.append([[0]*7]+[[0]+[int(x) for x in input()]+[0] for j in range(5)]+[[0]*7])
        input()
    s.append([[0]*7 for i in range(7)])
    a = [int(x) for x in input().split()[1:]]
    b = [int(x) for x in input().split()[1:]]
    fa = defaultdict(lambda : 0)
    fb = defaultdict(lambda : 0)
    for i in a:
        fa[i] = 1
    for i in b:
        fb[i] = 1
    for i in range(n):
        s = change(s)
    print("Case",str(t)+":")
    for z in range(1,6):
        for y in range(1,6):
            for x in range(1,6):
                print(s[z][y][x],end = "")
            print()
        if z < 5:
            print()
    t += 1



Measured memory_bytes: 6032
import numpy as np
import bisect

def prime_number(num):  
  if num == 0 or num == 1:
    return False
  
  if num > 2 and num % 2 == 0:
    return False  
  
  for i in range(3, int(np.sqrt(num)+1)):
    if num % i == 0:
      return False
  
  return True

def check(num):
  if prime_number(num) and prime_number((num+1)//2):
    return True
    
  return False
    
checked = [i for i in range(10**5+1) if check(i)]

# r_list = [sum(checked[:(i+1)]) for i in range(10**5+1)]

# print(checked)

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(bisect.bisect_right(checked, r) - bisect.bisect_left(checked, l))

Measured memory_bytes: 14648
A,B = map(str,input().split())
cnt = 0
for i in range(int(A),int(B)+1):
    l = list(str(i))
    flag = True
    n = len(l)
    for j in range(n//2):
        if l[j] != l[n-j-1]:
            flag = False
    
    if flag:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int min(int a,int b, int c){
  if(a<=b&&a<=c) return a;
  else if (b<=a && b<=c) return b;
  else return c;
}
int main(){
  int n;
  cin >>n;
  int a[210];
  for(int i=0;i<n;i++)
  cin >>a[i];
  int ans=0;
  int count=n;
  while(count==n){
    count = 0;
  for(int i=0 ; i<n ;i++){
    if(a[i]%2==0) count++;
    a[i]/=2;
  }
  if(count==n) ans++;
}
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ms[12]={0,31,59,90,120,151,181,212,243,273,304,334},g[5]={144000,7200,360,20,1};

void ymbk(int *b) {
	int i,k;
	long long d,a;
	a=b[0]-1;
	d=a*365+a/4-a/100+a/400; a++;
	if (b[1]>2 && ((a % 4==0 && a % 100!=0) || a % 400==0)) d++;
	d=(d+ms[b[1]-1]+b[2]-734858) % 1872000;
	for (i=0;i<5;i++) {
		k=d/g[i];
		cout << k; if (i!=4) cout << '.';
		d-=k*g[i];
	}
	cout << endl;
  }
void bkym(int *b) {
	  int i,e,c,y,m,d,h;
	  for (i=d=0;i<5;i++) d+=g[i]*b[i];
	  d+=734858;
	  for (y=d/366; y<=d/365; y++) {
		  e=y*365+y/4-y/100+y/400;
		  if (e+1>d) break;
	  }
	  d-=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400;
	  for (m=1,c=h=0;m<12;m++) {
	  if (m>1 && ((y % 4==0 && y % 100!=0) || y % 400==0)) c=1;
	  if (d>h && d<=ms[m]+c) break;
	  h=ms[m]+c;
     }
      d-=h;
      cout << y << '.' << m << '.' << d << endl;
  } 
  
int main() {
  int i,a,s,b[5];
  char c[50];
  while(true) {
  cin >> c; a=0; s=0;
  if (c[0]=='#') break;
  for (i=0;c[i]!='\0';i++,s*=10) {
	  if (c[i]!='.') s+=c[i]-'0';
	  if (c[i+1]=='.' || c[i+1]=='\0') { b[a++]=s; s=0; }
      }
   if (a==3) ymbk(b); else bkym(b);
   }
return 0;
} 

Measured memory_bytes: 1144
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//Quest of Merchant
public class Main{

	int N, M, W, T, INF = 1<<23;
	
	int[] w, p, x, y;
	int[][] item, adj;
	
	int[][] dist;
	int[] bestTime, bestSell;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt(); M = sc.nextInt(); W = sc.nextInt(); T = sc.nextInt();
		Map<String, Integer> ref = new HashMap<String, Integer>();
		w = new int[M];
		p = new int[M];
		for(int i=0;i<M;i++){
			ref.put(sc.next(), i);
			w[i] = sc.nextInt();
			p[i] = sc.nextInt();
		}
		x = new int[N+1];
		y = new int[N+1];
		item = new int[N+1][M];
		for(int i=0;i<N;i++){
			Arrays.fill(item[i], INF);
			int L = sc.nextInt();
			x[i] = sc.nextInt(); y[i] = sc.nextInt();
			while(L--!=0){
				int id = ref.get(sc.next());
				item[i][id] = sc.nextInt();
			}
		}
		adj = new int[N+1][N+1];
		for(int i=0;i<=N;i++)for(int j=i+1;j<=N;j++)adj[i][j] = adj[j][i] = Math.abs(x[i]-x[j])+Math.abs(y[i]-y[j]);
		dist = new int[1<<N][N];
		for(int S=1;S<1<<N;S++)for(int last=0;last<N;last++)if(((S>>last)&1)>0){
			int ns = S-(1<<last);
			if(ns==0)dist[S][last] = adj[last][N];
			else{
				int min = INF;
				for(int j=0;j<N;j++)if(((ns>>j)&1)>0)min = Math.min(min, dist[ns][j]+adj[j][last]);
				dist[S][last] = min;
			}
		}
		bestTime = new int[1<<N];
		for(int S=1;S<1<<N;S++){
			int min = INF;
			for(int i=0;i<N;i++)if(((S>>i)&1)>0)min = Math.min(min, dist[S][i]+adj[i][N]);
			bestTime[S] = min;
		}
		bestSell = new int[1<<N];
		int[] c = new int[M];
		int[] ws = new int[W+1];
		for(int V=1;V<1<<N;V++){
			Arrays.fill(c, INF);
			Arrays.fill(ws, 0);
			for(int i=0;i<N;i++)if(((V>>i)&1)>0)for(int j=0;j<M;j++)c[j]=Math.min(c[j], item[i][j]);
			for(int j=0;j<M;j++)c[j] = Math.max(0, p[j]-c[j]);
			for(int k=1;k<=W;k++)for(int j=0;j<M;j++)if(w[j]<=k)ws[k] = Math.max(ws[k], ws[k-w[j]]+c[j]);
			bestSell[V] = ws[W];
		}
		long[] dp = new long[T+1];
		for(int t=1;t<=T;t++){
			dp[t] = dp[t-1];
			for(int V=1;V<1<<N;V++){
				if(bestTime[V]<=t)dp[t] = Math.max(dp[t], dp[t-bestTime[V]] + bestSell[V]);
			}
		}
		System.out.println(dp[T]);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}




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

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout_single(const T& value) {
  std::cout << value;
}
void write_to_cout_single(bool value) { std::cout << (value ? "Yes" : "No"); }
template <typename T>
void write_to_cout(const T& value) {
  write_to_cout_single(value);
  std::cout << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout_single(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, n, m);
  V<int> a(n);
  cin >> a;
  sort(all(a));
  wt(a[n - m] * 4 * m >= accumulate(all(a), 0));
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    vl x(3);
    rep(i, 3) {
        cin >> x[i];
    }
    sort(all(x));
    out(x[0] + x[1]);
    re0;
}

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

using namespace std;

struct Bitset {
  vector<unsigned long long> a;
  Bitset() {}
  Bitset(const vector<unsigned long long>& a) : a(a) {}

  Bitset f(const Bitset &o) {
    vector<unsigned long long> vec(max(o.a.size(), a.size()));
    for (int i = 0; i < vec.size(); i++) {
      unsigned long long x = 0, y = 0;
      if (i < a.size()) x = a[i];
      if (i < o.a.size()) y = o.a[i];
      vec[i] = (x | y);
    }
    return Bitset(vec);
  }

  int count() {
    int ret = 0;
    for (auto x : a) {
      ret += __builtin_popcountll(x);
    }
    return ret;
  }

  void reset() {
    for (auto& x : a) {
      x = 0;
    }
  }

  void set(int v) {
    int p = v / 64;
    while (a.size() <= p) a.push_back(0);
    a[p] |= (1ULL << (v % 64));
  }
}a[2][501][10];
int b[505][505];

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  vector<int> c(11);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0, now = 0; i < n; i++, now ^= 1) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= 9; k++) {
        a[now][j][k].reset();
      }
    }
    string s;
    cin >> s;
    for (int j = 1; j <= n; j++) {
      if (s[j - 1] == '#') continue;
      int v = s[j - 1] - '0';
      for (int k = 1; k <= 9; k++) {
        a[now][j][k] = a[now][j - 1][k].f(a[now ^ 1][j][k]);
        ans += a[now][j][k].count() * k * v;
      }
      a[now][j][v].set(c[v]++);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 33792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

//Nayeem Shahriar Joy,Applied Physics And Electronic Engineering,University of Rajshahi.

unsigned long long int phie( long long int n)

{
    int result =n;
    for(int p=2;p*p<=n;++p)
    {
        if(n%p==0)
        {
            while(n%p==0)
            {
                n=n/p;
            }
            result=result-(result/p);
        }
    }
    if(n>1)
    {
        result=result-(result/n);
    }
    return result;
}

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

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1001;
const ll INF=1LL<<60;

vector<pair<int,ll>> S[MAX];
ll dis[MAX];
int N;

bool bell(int u){
    for(int i=0;i<N;i++){
        dis[i]=INF;
    }
    dis[u]=0;

    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<S[i].size();j++){
                int a=S[i][j].first;
                ll b=S[i][j].second;
                if(dis[i]!=INF&&dis[a]>dis[i]+b){
                    dis[a]=dis[i]+b;
                    if(k==N-1) return true;
                }
            }
        }
    }

    return false;

}

int main(){
    
    int E,r;cin>>N>>E>>r;
    for(int i=0;i<E;i++){
        int a,b;
        ll c;cin>>a>>b>>c;
        S[a].push_back(make_pair(b,c));
    }

    if(bell(r)) cout<<"NEGATIVE CYCLE"<<endl;
    else{
        for(int i=0;i<N;i++){
            if(dis[i]!=INF) cout<<dis[i]<<endl;
            else cout<<"INF"<<endl;
        }
    }
}




Measured memory_bytes: 3156
function main(input) {
  const [x, n] = input[0].trim().split(" ").map(i => parseInt(i));
  if(n!==0){
    const p = input[1].trim().split(" ").map(i => parseInt(i));

    let i=0;
    while(true){
      if(!p.includes(x-i)){
        console.log(x-i);
        break;
      }
      if(!p.includes(x+i)){
        console.log(x+i);
        break;
      }
      i++;
    }
  }else{
    console.log(x);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 29656
import numpy as np
def bin_search(left, right, check):
    while left + 1 < right:
        middle = (left + right) >> 1
        if check(middle):
            right = middle
        else:
            left = middle
    return right

def check(m):
    return np.maximum(A - m // F, Z).sum() <= K

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
F = np.array(input().split(), dtype=np.int32)
Z = np.zeros((N,), dtype=np.int32)
A.sort()
F = F[np.argsort(-F)]

print(bin_search(-1, 10 ** 12, check))

Measured memory_bytes: 36480
#include <iostream>
using namespace std;
 
int main(){
  
  bool takakachi=false;
  bool aokachi=false;
  
  int A,B,C,D;
  do{
  cin>>A>>B>>C>>D;
  }while(A<1||A>100||B<1||B>100||C<1||C>100||D<1||D>100);
  do{
    C=C-B;
      if(C<=0){
        takakachi=true;
    continue;}
    A=A-D;
      if(A<=0){
        aokachi=true;
        continue;
      }
   
  }while((!takakachi)&&(!aokachi));
  if(takakachi)cout<<"Yes"<<endl;
  if(aokachi)cout<<"No"<<endl;
   
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		long sum = 0, ans = 0, ans2 = 0;
		for(int i = 0 ; i < n ; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum <= 0) {
				ans += 1 - sum;
				sum = 1;
			} else if(i % 2 == 1 && sum >= 0) {
				ans += sum + 1;
				sum = -1;
			}
		}
		sum = 0;
		for(int i = 0 ; i < n ; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum >= 0) {
				ans2 += sum + 1;
				sum = -1;
			} else if(i % 2 == 1 && sum <= 0) {
				ans2 += 1 - sum;
				sum = 1;
			}
		}
		System.out.println(Math.min(ans, ans2));
	}
}


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

int main() { 
  int N, A, B;
  cin >> N >> A >> B;
  int c = 0;

  if(N*A<B){
    c = N * A;


  }
  else{
    c = B;
  }
  cout << c << endl;
}

Measured memory_bytes: 3604
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete


main = do
    [a, b] <- map (map (readInt . takeWhile (/=','))) . splitWhen (=="") . lines <$> getContents
    let counts = map (applyTuple (head, length)) $ group $ sort (a ++ b)
    mapM_ putStrLn $ map (applyBin (((++) .) (++" ")) (show . fst) (show . snd)) $ filter (flip elem b . fst) $ filter (flip elem a . fst) counts

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int n,d;
	cin>>n>>d;
	if(n%(2*d+1)==0)cout<<n/(2*d+1);
	else cout<<n/(2*d+1)+1;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
    val n = io.StdIn.readInt
    val as = io.StdIn.readLine.split(" ").map(_.toInt)

    val targets = rec1(1, Map.empty)
    def rec1(index: Int, map: Map[Int, Int]): Map[Int, Int] = {
        if (n < index) map
        else {
            rec1(index+1, map+(index -> as(index-1)))
        }
    }

    val result = targets.count { case (k,v) => targets(v) == k }
    println(result/2)
}

Measured memory_bytes: 66892
a, b, c = gets.chomp.split.map(&:to_i)

rad_c = Float(c) / 180 * Math::PI
s = 0.5 * a * b * Math.sin(rad_c)
puts format("%.6f", s)

c = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(rad_c))
puts format("%.6f", a + b + c)

h = 2 * s / a
puts format("%.6f", h)



Measured memory_bytes: 6944
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private int N;
  private int A;
  private int[] x;

  private int X;

  private void solve(Scanner sc, PrintWriter out) {
    N = sc.nextInt();
    A = sc.nextInt();
    sc.nextLine();
    x = new int[N];

    X = A;

    for (int i = 0; i < N; ++i) {
      x[i] = sc.nextInt();
      if (x[i] > X) {
        X = x[i];
      }
    }

    long[][][] dp = new long[N + 1][N + 1][N * X + 1];
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= N; ++k) {
        for (int s = 0; s <= N * X; ++s) {
          if (j == 0 && k == 0 && s == 0) {
            dp[j][k][s] = 1;
          } else if (j >= 1 && s < x[j - 1]) {
            dp[j][k][s] = dp[j - 1][k][s];
          } else if (j >= 1 && k >= 1 && s >= x[j - 1]) {
            dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
          } else {
            dp[j][k][s] = 0;
          }
        }
      }
    }
    long sum = 0;
    for (int k = 1; k <= N; ++k) {
      sum += dp[N][k][k * A];
    }
    out.println(sum);
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 65308
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define REP(countName, end) for (ll countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)
#define REV(countName, end) for (ll countName = end - 1; countName >= 0; countName--)
int main(void)
{
    int n;
    cin >> n;
    int m = 1;
    for (int i = 2; i < n; i++)
    {
        for (int k = 2; pow(i, k) <= n; k++)
        {
            m = std::max(m, (int)pow(i, k));
        }
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 384
/*
гонфлад
*/
#pragma ARCENIY_KIRILLOV_UVIDEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;



main(){
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    int ce = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == 'A') ce++;
        else{
            if (s[i] == 'B' && s[i+1] == 'C'){
                ans += ce;
                i++;
            }else ce = 0;
        }
    }
    cout << ans;



}


Measured memory_bytes: 640
#/usr/bin/python3
n = int(input())
list_a = list(map(int, input().split()))
result = 1
if 0 in list_a:
        print(0)
        exit()
  
for i in range(n):
    result *= int(list_a[i])
    if result > 10**18:
        print("-1")
        exit()
print(result)

Measured memory_bytes: 21476
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, ans = 1;
    cin >> N;
    vector<string> S(N);
    
    rep(j, N) {
        cin >> S.at(j);       
    }
    sort(S.begin(), S.end());
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) ans++;
    }
    
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 9600
import java.awt.Polygon;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	public void run() throws Exception
	{
		Scanner file = new Scanner(System.in);
		int a = file.nextInt();
		int b = file.nextInt();
		int ans = a+a-1;
		ans = Math.max(ans, b+b-1);
		ans = Math.max(ans, a + b);
		System.out.println(ans);
	}
}


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree< long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void erase ( ordered_set &s, long long val )
{
    auto it = s.upper_bound(val);

    if ( it == s.begin() && val == *s.begin() )
        s.erase ( s.upper_bound(val) );
    else
        s.erase ( s.upper_bound(val) );
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


int main()
{
    su;
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0;
    else
        cout<<1000-(n%1000);
    cout<<nl;
    return 0;
}


Measured memory_bytes: 3648
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for a in B:
    for j in range(3):
        for k in range(3):
            if A[j][k] == a:
                A[j][k] = 0

# print(A)

for i in range(3):
    if sum(A[i]) == 0:
        print("Yes")
        exit()

for i in range(3):
    if A[0][i]+A[1][i]+A[2][i] == 0:
        print("Yes")
        exit()

if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    print("Yes")
    exit()

print("No")


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

int main() {
  int h, n, s = 0;
  cin >> h >> n;
  rep(i, n){
    int a;
    cin >> a;
    s += a;
  }
  if(s < h) cout << "No" << endl;
  else cout << "Yes" << endl;
}


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

int n;
double dp[3000][3000] ;

double a[3000] = {0.0};
double f(int h,  int i) {

	if (h == 0 ) return 1;
	if (i == n + 1) return 0;
	if (dp[i][h] > -0.9)
		return dp[i][h];

	return dp[i][h] = a[i] * f(h - 1,  i + 1) + (1 - a[i]) * f(h,  i + 1);
}

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

	memset(dp, -1, sizeof dp);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int k = ( n + 1) / 2 ;
	double ans = 0;
	// for (int i = k; i <= n; i++) {
	// 	ans +=
	// }
	//cout <<
	cout << fixed << setprecision(10) << f(k,  1);
	return 0;
}

Measured memory_bytes: 74380
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

double pow(double x){
    return x*x;
}
int main() {
    int N,D;
    cin >> N >> D;
    int count = 0;
    vector<vector<int>> data(N, vector<int>(D));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
         cin >> data[i][j];
        }
    }
    
    for(int l=0;l<N;l++){
        for(int i=l+1;i<N;i++){
            int diff = 0;
            for(int j=0;j<D;j++){
                int tmp = abs(data[l][j] - data[i][j]);
                diff += pow(tmp);
            }
            if((int)sqrt(diff) * (int)sqrt(diff) == diff) count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B, C, D;

string printop(int n) {
  if (n == 1) {
    return "+";
  } else {
    return "-";
  }
}

int main() {
  string S;
  cin >> S;
  A = S[0] - '0';
  B = S[1] - '0';
  C = S[2] - '0';
  D = S[3] - '0';

  for (int i = -1; i <= 1; i += 2) {
    for (int j = -1; j <= 1; j += 2) {
      for (int k = -1; k <= 1; k += 2) {
        int sum = A + i * B + j * C + k * D;
        if (sum == 7) {
          cout << A << printop(i) << B << printop(j) << C << printop(k) << D
               << "=7" << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 3652
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if(sc.nextInt() == 1) System.out.println("Hello World");
        else System.out.println(sc.nextInt() + sc.nextInt());
    }




}




Measured memory_bytes: 23892
A,B,C = list(map(int,input().split()))
count = 0
while A%2==0 and B%2==0 and C%2==0:
	_A = A//2
	_B = B//2
	_C = C//2
	A = _B + _C
	B = _A + _C
	C = _A + _B
	if A == B and B == C:
		print(-1)
		quit()
	count += 1
print(count)

Measured memory_bytes: 3064
W, H, N = gets.split.map(&:to_i)
left, right, bottom, top = [0, W, 0, H]
 
while gets
  x, y, a = $_.split.map(&:to_i)
 
  if a == 1
    left = [left, x].max
  elsif a == 2
    right = [right, x].min
  elsif a == 3
    bottom = [bottom, y].max
  elsif a == 4
    top = [top, y].min
  end
end
 
p [right - left, 0].max * [top - bottom, 0].max

Measured memory_bytes: 1788
#include <stdio.h>

int main(void){
    int count, number, i;
    long max = -1000000, min = 1000000, sum = 0;
    scanf("%d", &count);
    for(i = 0; i < count; i++){
        scanf("%d", &number);
        if(number > max){max = number;}
        if(number < min){min = number;}
        sum = sum + number;
    }
    printf("%ld %ld %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i) 

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int a, b, c, cnt;
    cin>>a>>b>>c;
    cnt = 0;
    rep(i, b - a + 1) {
        if (c % (a + i) == 0) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3112
function solve()
    n = parse(Int, readline())
    a = [parse(Int, x) for x in split(readline())]

    z = [(a[i], i) for i=1:n]
    sort!(z, rev=true)

    dp = zeros(Int, (n+1, n+1))
    for s=1:n, i=0:s
        li = i
        ri = s-i
        l = if li > 0
            dp[li, ri+1] + z[s][1] * abs(li - z[s][2])
        else
            0
        end
        r = if ri > 0
            dp[li+1, ri] + z[s][1] * abs((n-ri+1) - z[s][2])
        else
            0
        end
        dp[li+1, ri+1] = max(l, r)
    end
    maximum([dp[i+1, n-i+1] for i=0:n])
end

println(solve())


Measured memory_bytes: 217032
#include<stdio.h>
#include<math.h>
int main(){
int n,k;
  scanf("%d%d",&n,&k);
  double p[n];
  for(int i=0;i<n;i++){
    	p[i]=0;
  }
  double ans=0;
  for(int i=0;i<n;i++){
	int score=i+1;	
    int count=0;
    while(score<=k-1){
      score=score*2;
      count++;
    }
    //printf("%dの目　%d回必要\n",i+1,count);
    double bunbo=n*pow(2,count);
    //printf("%.lf\n",bunbo);
    ans+=1/bunbo;
  }
  printf("%.10lf",ans);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n ;
    set<char> s;
    for (int i = 0; i < n; ++i) {
        char a;
        cin >> a;
        s.insert(a);
    }
    if(s.size() == 4) cout << "Four";
    else cout << "Three";
    cout << endl;

    return 0;
}


Measured memory_bytes: 384