akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# input
num = str(input())
list = list(num)
list = [int(i) for i in list]

counter = 0
for ii in range(1, len(list)):
    if list[ii - 1] == list[ii]:
        list[ii] = (list[ii] + 1) % 2
        counter += 1

print(counter)


Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
 
int main(void) {
	string s; cin >> s;
	long long int sum = 0;
	int i;
	int a = s.size() - 1;
 
	for (i = a; i >= 0; i--) {
		if (s[i] == 'B') {
			sum += a - i;
			a--;
		}
	}
 
 
 
	cout << sum << endl;
 
	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a + b >= 10)
            System.out.println("error");
        else
            System.out.println(a + b);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int arr[100005];
int n;
int dp[100005];
long long go(int i){
    if(i == n-1)
        return 0;
  	if(i >= n)
      return 1000000;
  int &ans = dp[i];
  if(ans!=-1)
    return ans;

  ans = min(abs(arr[i] - arr[i+1]) + go(i+1) , abs(arr[i] - arr[i+2]) + go(i+2));
  return ans;
}

int main(){
    //auto start = high_resolution_clock::now();
    for(int i = 0 ; i <= 100005 ; i++){
        dp[i] = -1;
    }
	cin >> n;
  	for(int i = 0 ; i < n ; i++)	cin >> arr[i];

  	cout<<go(0)<<"\n";



  	//auto stop = high_resolution_clock::now();

  	//auto duration = duration_cast<milliseconds>(stop - start);
  	//cout<<duration.count();
}


Measured memory_bytes: 2560
N=int(input())
A=list(map(int,input().split()))
h=0
for i in range(1,N):
  if A[i-1]<=A[i]:
    h+=0
  if A[i-1]>A[i]:
    h+=A[i-1]-A[i]
    A[i]=A[i-1]
print(h)

Measured memory_bytes: 32232
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	map<string , string> mp;
	mp["Sunny"]="Cloudy";mp["Cloudy"]="Rainy";mp["Rainy"]="Sunny";
	string str;
	cin>> str ;
	cout<<mp[str]<<endl;

	return 0;
}

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

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

	string sa, sb;
	for (int i = 0; i < b; i++) {
		sa += to_string(a);
	}
	for (int i = 0; i < a; i++) {
		sb += to_string(b);
	}

	vector<string> vec;
	vec.push_back(sa);
	vec.push_back(sb);

	sort(vec.begin(),vec.end());

	cout << vec[0] << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int *data;
    int a,i,key,j;

scanf("%d\n",&a);

data = (int *)malloc(a * sizeof(int ));

for(i=0;i<a;i++) scanf("%d",&data[i]);


for(j=1;j<=a;j++)
{
     for(i=0;i<a;i++) 
    {
    printf("%d",data[i]);
    if(i != a-1) printf(" ");
    } 
    printf("\n");   
    
    if(j != a)
    {
       key = data[j];
       i = j - 1;
       while(i >= 0 && data[i] >key)
         {
          data[i+1] = data[i];
          i--;
          }
        data[i+1] = key;
    }
 
}

free(data);
return 0;
}


Measured memory_bytes: 2068
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
map<string, ll> dp[101];
int main() {
	int N;
	cin >> N;
	dp[0][""] = 1;
	char ch[5] = "ACGT";
	for (int i = 0; i < N; i++) {
		for (auto p : dp[i]) {
			for (int j = 0; j < 4; j++) {
				string t = p.first + string(1, ch[j]);
				if (t.size() > 4) t.erase(t.begin());
				if (t.find("AGC") != string::npos || t.find("GAC") != string::npos || t.find("ACG") != string::npos) continue;
				if (t.size() <= 3) {
					(dp[i + 1][t] += p.second) %= MOD;
					continue;
				}
				if (t[0] == 'A'&&t[2] == 'G'&&t[3] == 'C') continue;
				if (t[0] == 'A'&&t[1] == 'G'&&t[3] == 'C') continue;
				(dp[i + 1][t] += p.second) %= MOD;
			}
		}
	}
	ll ans = 0;
	for (auto p : dp[N]) {
		(ans += p.second) %= MOD;
	}
	cout << ans << endl;
}


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

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}

void solve()
{
	ll mod = 1e9 + 7;
	ll n,k;
	cin>>n>>k;
	// ll dp[n+2] = {};
	// dp[0] = 1;
	ll ans = 0;
	ll c = n+1-k;
	for (ll i = k; i < n+2; ++i)
	{
		ll l = i*(i-1)/2;
		ll r = (n+1)*(n)/2 - (n+1-i)*(n-i)/2;
		ans = (ans + r-l+1)%mod;
	}
	cout<<ans<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector<ll> *gr;
ll m=1e9+7;
ll dp[100002][2];
ll solve(ll src,ll col,ll par)
{
	if(dp[src][col]!=-1)
	return dp[src][col];
	dp[src][col]=1;
	for(int i=0;i<gr[src].size();i++)
	{
		ll j=gr[src][i];
		if(j!=par)
		{
			if(col==0)
			{
				dp[src][col]=(dp[src][col]%m * (solve(j,0,src)+solve(j,1,src))%m)%m;
			}
			else if(col==1)
			{
				dp[src][col]=(dp[src][col]%m * solve(j,0,src)%m)%m;
			}
		}
	}
	return dp[src][col];
}
int main()
{
	for(int i=0;i<100002;i++)for(int j=0;j<2;j++)dp[i][j]=-1;
	cin>>n;
	gr=new vector<ll>[n+1];
	ll x,y;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	ll ans=(solve(1,0,0)+solve(1,1,0))%m;
	cout<<ans;
}

Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[] num = new int[3];
		
		num[0]=s.nextInt();
		num[1]=s.nextInt();
		num[2]=s.nextInt();
		int temp;
		if(num[0]>=1 && num[0]<=10000 && num[1]>=1 && num[1]<=10000 && num[2]>=1 && num[2]<=10000) {
		for(int i = 0;i<num.length;i++) {
			for(int j = 1;j<num.length-i;j++) {
				if(num[j-1]>num[j]) {
					temp=num[j-1];
					num[j-1]=num[j];
					num[j]=temp;
				}
			}
		}
		
		System.out.print(num[0]);
		System.out.print(" ");
		System.out.print(num[1]);
		System.out.print(" ");
		System.out.println(num[2]);

	}
	}

}

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

#define PI 2 * acos(0.0)
#define DEGtoRAD(X) (X*PI)/180.0
#define EPS 1e-06

int main(){
    int m, n, v;
    while(1){
        cin >> m;
        if(m == 0)  break;

        double first = 0, second = 0;

        int rest = 360;
        for(int i = 0; i < m-1; i++){
            cin >> v;
            first += sin(DEGtoRAD(v));
            rest -= v;
        }
        first += sin(DEGtoRAD(rest));

        cin >> n;
        rest = 360;
        for(int i = 0; i < n-1; i++){
            cin >> v;
            second += sin(DEGtoRAD(v));
            rest -= v;
        }
        second += sin(DEGtoRAD(rest));

        if(first - second > EPS)        cout << 1 << endl;
        else if(first - second < -EPS)  cout << 2 << endl;
        else                            cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3312
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long n,a[200],i,j,total=0,min=2000000000;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(j=1;j<=a[n];j++)
    {
        total=0;
        for(i=1;i<=n;i++)
        {
            total+=((j-a[i])*(j-a[i]));
        }
        if(total<min)
        {
            min=total;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 3640
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int ctoi(char c) {
  if('0'<=c && c <= '9') return c-'0';
  return 0;
}

int main(){
  int K=0;
  cin >> K;
  cout << (K/2)*(K-(K/2)) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll P=1000000007,n, m;std::cin >> n >> m;
  vll a(n), b(m);re(i, n) std::cin >> a[i]; re(i, m) std::cin >> b[i];
  vvl dp = vv(n+1, m+1, 0, ll);

  vll s(m+1, 0), t(m+1, 0);
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(a[i-1]!=b[j-1]) continue;
      dp[i][j] = (s[j-1] + 1)%P;
    }
    for(int j=0;j<=m;j++) t[j] = (t[j] + dp[i][j])%P;
    for(int j=1;j<=m;j++) s[j] = (s[j-1] + t[j])%P;
  }
  ll ans = 0;
  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans = (ans+dp[i][j])%P;
  std::cout << (ans+1)%P << '\n';
  return 0;
}


Measured memory_bytes: 31616
s = input()
N = len(s)
K = int(input())
L = []
for i in range(N):
	for j in range(5):
		if i + j < N:
			L.append(s[i:i + j + 1])

L = sorted(L)

sub = ""
x = 0
for i in L:
	if sub != i:
		sub = i
		x += 1
	
	if x == K:
		print(sub)
		break

	


Measured memory_bytes: 4596
#include<stdio.h>
#define MAX 100
#define INF 100000

int matrix[MAX][MAX];
int dis[MAX];
int color[MAX];
int n,tail,head;
int que[MAX];

void enqueue(int v) {
  
  que[tail++] = v;
  if (tail == MAX) tail = 0;
  
}

int dequeue() {
  
  int res = que[head];
  head++;
  if (head == MAX) head = 0;
  return res;
  
}

void bfs(int u){
  int i,v;
  enqueue(u);
  for(i=0; i<n; i++) dis[i] = INF;
  dis[u] = 0;
  
  while(tail != head){
    int j;
    v = dequeue();
    for(j=0; j<n; j++){
      if(matrix[v][j] == 0) continue;
      if(dis[j] != INF) continue;
      dis[j] = dis[v]+1;
      enqueue(j);
    }
  }
  
  for(i=0; i<n; i++){
    printf("%d ",i+1);
    if(dis[i] == INF) printf("%d\n",-1);
    else printf("%d\n",dis[i]);
  }
}

int main(){
  int i,j;
  
  scanf("%d",&n);
  
  tail=head=0;
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)
      matrix[i][j]=0;
  }
  
  for(i=0;i<n;i++){
    int u,k;
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      int peak;
      scanf("%d",&peak);
      peak--;
      matrix[u][peak]=1;
    }
  }
  
  bfs(0);
  
  return 0;
  
}




Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pi 3.14
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<long long,int> pli;
typedef pair<int,long long> pil;
const int INF=1000000007;
const int MOD=1000000007;
const int nmax=201234;

int a,b,c,d;

int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a==c)
        puts("0");
    else
        puts("1");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	ll n;
	cin >> n;
	vector<ll> a(n),b(n);
	vector<ll> s(n + 1, 0);
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
		s[i + 1] = s[i] + a[i];
	}
	reverse(all(b));
	vector<ll> c(n + 1), d(n + 1);
	c[0] = 0;
	REP(i, n) {
		if (a[i] == 0) {
			c[i + 1] = min(0ll, c[i] + 2);
		} else if (a[i] % 2 == 0) {
			c[i + 1] = min(0ll, c[i] - a[i]);
		} else {
			c[i+1] = min(0ll, c[i] - a[i] + 1);
		}
	}
	d[0] = 0;
	REP(i, n) {
		if (b[i] == 0) {
			d[i + 1] = min(0ll, d[i] + 2);
		} else if (b[i] % 2 == 0) {
			d[i + 1] = min(0ll, d[i] - b[i]);
		} else {
			d[i + 1] = min(0ll, d[i] - b[i] + 1);
		}
	}
	vector<ll> d2(n + 1);
	d2[0] = 0;
	REP(i, n) {
		vector<ll> tmp = { 0 };
		tmp.push_back(d[i + 1]);
		if (b[i] % 2 == 0) {
			tmp.push_back(d2[i] - b[i] + 1);
		} else {
			tmp.push_back(d2[i] - b[i]);
		}
		d2[i + 1] = *min_element(all(tmp));
	}
	reverse(all(d));
	reverse(all(d2));
	ll res = LLONG_MAX;
	REP(i, n + 1) {
		ll temp = s[n] + c[i] + d2[i];
		chmin(res, temp);
	}
	put(res);
	return 0;
}


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

int main() {
  string s, t;
  cin >> s;
  
  t = s.at(0);
  int ans = 1, i;
  
  for(i = 1; i < s.size(); i++){
    if(t.size() == 2){
      t = s.at(i);
      ans++;
    }
    else if(s.at(i) != t.at(0)){
      t = s.at(i);
      ans++;
    }
    else{
      if(i == s.size() - 1) break;
      else{
        t = s.at(i);
        t += s.at(i + 1);
        ans++;
        i++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    vector<vector<char>> v(a,vector<char>(b));
    for(int i=0;i<a;i++){
        string aaaa; cin >> aaaa;
        for(int j=0;j<b;j++){
            v[i][j] = aaaa[j];
        }
    }
    int cnt = 0;
    int ans = 0;
   for(int i=0;i<(1<<a);i++){
       for(int j=0;j<(1<<b);j++){
           bitset<10> A(i);
           bitset<10> B(j);
           for(int k=0;k<a;k++){
               for(int l=0;l<b;l++){
                   if(A[k] == 0 and B[l] == 0){
                       if(v[k][l] == '#')cnt++;
                   }
               }
           }
           if(cnt == c)ans++;
           cnt = 0;
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int A,B;
	cin >> A >> B;
	
	if(max(A,B)<=8){
		cout << "Yay!" << endl;
	}
	else{
		cout << ":(" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int N, p, cnt = 0;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> p;
        if (p != i) cnt++;
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

map<int,int> prime(ll n){  
    map<int,int> mp;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n!=1)mp[n]++;
    return mp;
}

int main(){
    ll a,b;cin >> a >> b;
    map<int,int> mp = prime(__gcd(a,b));
    cout << mp.size() + 1 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, k;
    cin >> n >> k;
    int arr[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int j = 0;
    deque<int> cycle;
    unordered_map<int, int> table;
    int cur = 1;
    while (table.find(cur) == table.end())
    {
        table[cur] = 1;
        cycle.push_back(cur);
        cur = arr[cur];
    }
    j = cycle.size();
    if (j - k > 0)
    {
        cout << cycle[k] << "\n";
        return 0;
    }
    else
        k -= j;
    while (cycle.front() != cur)
        cycle.pop_front();
    k = k % cycle.size();
    cout << cycle[k] << "\n";
    return 0;
}

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

ll solve() {
    ll N, U, V, a, b;
    cin >> N >> U >> V;
    U--, V--;
    vector<vector<int>> G(N);
    for ( int i = 0; i < N-1; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if ( U == V ) return 0;
    vector<ll> dt(N), da(N);

    function<void(int,int,vector<ll>&)> dfs = [&](int v, int p, vector<ll>& d) {
        if ( p == -1 ) {
            d[v] = 0;
        } else {
            d[v] = d[p] + 1;
        }
        for ( int u : G[v] ) {
            if ( u == p ) continue;
            dfs( u, v, d);
        }
    };

    dfs(U, -1, dt);
    dfs(V, -1, da);

    ll m = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( dt[i] < da[i] ) {
            m = max(m, da[i]);
        }
    }
    if ( m > 0 ) m--;

    return m;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f[3030][3030],n,a[3030],t;
int main()
{
	cin>>n;
	if(n%2)
		t=1;
	else
		t=-1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		f[i][i]=t*a[i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			if((i+1+n)%2)
				f[j][j+i]=min(f[j+1][j+i]-a[j],f[j][j+i-1]-a[j+i]);
			else
				f[j][j+i]=max(f[j+1][j+i]+a[j],f[j][j+i-1]+a[j+i]);
		//	cout<<j<<' '<<j+i<<' '<<f[j][j+i]<<endl;
		}
	}
	cout<<f[1][n]<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    Vl dm(k);
    for (int i = 0; i < q; i++) {
        ll n, x, m;
        cin >> n >> x >> m;
        ll out = 0;
        ll a_last = x % m;
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m;
            ll tmp;
            if (j <= (n - 1) % k - 1)
                tmp = (n - 1) / k + 1;
            else
                tmp = (n - 1) / k;
            a_last += dm[j] * tmp;
            if (dm[j] == 0) out += tmp;
        }
        out += a_last / m;
        cout << n - 1 - out << "\n";
    }

    return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string a, b, c;
   cin >> a >> b >> c;
   vector<char> va, vb, vc;
   for(int i = a.size() - 1; i >= 0; i--)
      va.push_back(a[i]);
   for(int i = b.size() - 1; i >= 0; i--)
      vb.push_back(b[i]);
   for(int i = c.size() - 1; i >= 0; i--)
      vc.push_back(c[i]);
   char ch = 'a';

   while(1)
   {
      if(ch == 'a')
      {
         if(va.empty())
         {
            cout << "A" << nl;
            return 0;
         }
         ch = va.back();
         va.pop_back();
      }
      if(ch == 'b')
      {
         if(vb.empty())
         {
            cout << "B" << nl;
            return 0;
         }
         ch = vb.back();
         vb.pop_back();
      }
      if(ch == 'c')
      {
         if(vc.empty())
         {
            cout << "C" << nl;
            return 0;
         }
         ch = vc.back();
         vc.pop_back();
      }


   }





	return 0;
}


Measured memory_bytes: 3584
def getdata():

    array_result = []
    
    array_result.append(input().split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = Fa;se
    finally:

        return array_result

arr_data = getdata()

n = int(arr_data[0][0])

arr = [int(arr_data[1][x]) for x in range(n)]
arr01 = [v for v in arr if v % 4 == 0]
arr02 = [v for v in arr if v % 4 != 0 and v % 2 == 0]

print("Yes" if len(arr) // 2 <= len(arr01) + len(arr02) //2 else "No")

    


Measured memory_bytes: 15020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a <= 8 && b <= 8) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}

	}
}


Measured memory_bytes: 21716
#include <stdio.h>

int main(){
  int n, i, j = 0;
  int prime[10001];
  for(i = 2; i <= 10000; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= 10000; i++) {
    if(prime[i]) {
      for(j = 2 * i; j <= 10000; j += i) {
        prime[j] = 0;
      }
    }
  }
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i=n ; i >= 5 ; i--){
      if(prime[i] && prime[i-2]) break;
    }
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 1804
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;
const double EPS=1e-9;

struct Choco{
	int nut;
	double S;
};

int n,m,w,h,thre;
Choco ch[30000];

int solve(){
	int nut=0,ans=INF;
	double S=0;
	for(int i=0,j=0;i<m;i++){
		for(;j<i;j++){
			S+=ch[j].S;
			nut+=ch[j].nut;
		}

		for(;j<m;j++){
			if(w*h-thre+EPS<S) break;
			ans=min(ans,n-nut);
			S+=ch[j].S;
			nut+=ch[j].nut;
		}
		if(w*h-thre+EPS>S) ans=min(ans,n-nut);

		S-=ch[i].S;
		nut-=ch[i].nut;
	}

	return ans;
}

int main(){
	for(;scanf("%d%d%d%d%d",&n,&m,&w,&h,&thre),n;){
		static int l[30001],r[30001];
		l[0]=r[0]=0;
		rep(i,m) scanf("%d%d",l+i+1,r+i+1);

		rep(i,m){
			ch[i].S=((l[i+1]-l[i])+(r[i+1]-r[i]))/2.0*w;
			ch[i].nut=0;
		}
		rep(i,n){
			double cx,cy; scanf("%lf%lf",&cx,&cy);

			int lo=0,hi=m+1;
			while(lo<hi){
				int mi=(lo+hi+1)/2;
				if((w-cx)*l[mi]+cx*r[mi]<w*cy) lo=mi; else hi=mi-1;
			}
			ch[lo].nut++;
		}

		printf("%d\n",solve());
	}

	return 0;
}

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

//前処理は O(n)、毎回の二項係数計算は O(1)

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			res[i]++;
			n /= i;
		}
	}
	if (n != 1)res[n]++;//nは素数
	return res;
}


int main() {
	// 前処理
	COMinit();
	int n, m;
	cin >> n >> m;
	map<int, int>mp = prime_factor(m);
	long long ans = 1;
	for (auto i: mp) {
			ans *= COM(n + i.second - 1, i.second);
			ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(N);
  if(N % 2 == 0) out(N / 2- 1);
  else out(N / 2);
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int N,A[100000];
bool check;
int main(){
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
  }
  sort(A,A+N);
  if(N==1){
    if(A[0]==0){
      cout<<1<<endl;
    }else{
      cout<<0<<endl;
    }
    return 0;
  }else if(N==2){
    if(A[0]==1&&A[1]==1){
      cout<<2<<endl;
    }else{
      cout<<0<<endl;
    }
    return 0;
  }
  if(N%2==1){
    if(A[0]!=0||A[1]==0){
      check=true;
    }else{
      int i=1,j=2;
      while(i<N){
        if(A[i]!=j||A[i+1]!=j){
          check=true;
          break;
        }else{
          i+=2;
          j+=2;
        }
      }
    }
  }else{
    int i=0,j=1;
    while(i<N){
      if(A[i]!=j||A[i+1]!=j){
        check=true;
        break;
      }else{
        i+=2;
        j+=2;
      }
    }
  }
  if(check){
    cout<<0<<endl;
  }else{
    long long X=1;
    FOR(i,0,N/2){
      (X*=2)%=INF;
    }
    cout<<X<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    int h,w;
    char a[100][100];
    //入力
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",a[i]);
    }
    
    for(int i=0;i<h;i++){
        int flag=0;
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){flag=1;}
        }
        if(!flag){
            for(int l=i;l<h-1;l++){
                for(int j=0;j<w;j++){
                  a[l][j]=a[l+1][j];
                }
            }
        h--;
        i--;
        }
    }
    for(int i=0;i<w;i++){
        int flag=0;
        for(int j=0;j<h;j++){
            if(a[j][i]=='#'){flag=1;}
        }
        if(!flag){
            for(int l=i;l<w-1;l++){
                for(int j=0;j<h;j++){
                  a[j][l]=a[j][l+1];
                }
            }
        i--;    
        w--;
        }
    }

    //出力
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%c",a[i][j]);
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>
#define MAX_N 100000

using namespace std;

typedef long long ll;
int n;
string s[MAX_N];
unordered_map<string, int> um;

void solve()
{
    ll res = 0, tmp;
    for (int i = 0; i < n; i++)
    {
        sort(s[i].begin(), s[i].end());
        if (um.count(s[i]))
        {
            tmp = um.at(s[i]) + 1;
            um[s[i]] = tmp;
            res += tmp;
        }
        else
        {
            um.emplace(s[i], 0);
        }
    }

    cout << res << endl;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    solve();
}


Measured memory_bytes: 17700
#include <stdio.h>
#include <string.h>
#define PRI(x) printf(x); puts("");
#define PRIF(x,v1,v2) printf(x,v1,v2); puts("");
#define FOR(x,n) for(int i=(x);i<(n);i++)
int main(void){
    // Your code here!
    int num;
    scanf("%d",&num);
    char words[num];
    scanf("%s",words);
    int flag=0;
    int ans=0;
    FOR(0,num){
        if(flag==2){
            if(words[i]=='C'){
                ++ans;
                flag=0;
            }else{
                flag=0;
            }
        }
        if(flag==1){
            if(words[i]=='B') {
                flag=2;
            }else{
                flag=0;
            }
        }
        if(words[i] == 'A') flag=1;
    }
    PRIF("%i",ans,ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int A,Z;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      A=i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='Z'){
      Z=i;
      break;
    }
  }
  int ans=Z-A+1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    cout<<"Cloudy\n";
    if(s=="Cloudy")
    cout<<"Rainy\n";
    if(s=="Rainy")
    cout<<"Sunny\n";
}

Measured memory_bytes: 3572
// 2020/08/17 Tazoe

#include <iostream>
using namespace std;

// 最大公約数（ユークリッドの互除法）
int gcd(int a, int b)
{
	if(b==0)
		return a;

	return gcd(b, a%b);
}


int main()
{
	int x, y;
	cin >> x >> y;

	int g = gcd(x, y);

	// (横方向の交点数)+(縦方向の交点数)-(重なる交点数)
	cout << (x+1)+(y+1)-(g+1) << endl;

	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int h, w;
string s[505], a[505], b[505];

signed main() {
	cin >> h >> w;
	rep(i,h) {
		cin >> s[i];
		a[i] = b[i] = s[i];
	}
	rep(i,h) {
		a[i][0] = b[i][w-1] = '#';
		reps(j,1,w-1) (i%2 ? a : b)[i][j] = '#';
	}
	rep(i,h) cout << a[i] << endl;
	cout << endl;
	rep(i,h) cout << b[i] << endl;
}

Measured memory_bytes: 1536
import sys
A,B,C = map(int,input().split())
if not ( 1 <= A <= 100 and 1 <= B <= 100 and 1 <= C <= 100 ): sys.exit()
if not ( isinstance(A,int) and isinstance(B,int) and isinstance(C,int) ): sys.exit()

print(( A * B ) // 2)

Measured memory_bytes: 8976
import math
N,D = map(int,input().split())
xys = []
for i in range(N):
    x, y = map(int, input().split())
    xys.append([x,y])
c = 0
for x, y in xys:
  t = math.sqrt(x ** 2 + y ** 2)
  if t <= D:
      c += 1
print(c)

Measured memory_bytes: 39284
#include <bits/stdc++.h>
using namespace std;
vector<int>tr[2333];

int n,k;
int vis[2333];
int sum,maxx;
int ss[2333],fa[2333];
void dfs(int u,int cnt){
        vis[u]=1;
        if(k%2==0){
                if(cnt>k/2) return ;
                else{
                        for(int i=0; i<tr[u].size(); i++){
                                int temp=tr[u][i];
                                if(!vis[temp]){
                                        if(cnt<=k/2){
                                                sum+=1;
                                                dfs(temp,cnt+1);
                                        }
                                }
                        }
                }
        }
        else{
                if(cnt>k/2+1) return ;
                else{
                        for(int i=0; i<tr[u].size(); i++){
                                int temp=tr[u][i];
                                if(!vis[temp]){
                                        if(cnt==k/2+1){
                                                if(cnt!=1){
                                                        int len=tr[u].size()-1;
                                                        ss[u]=len;
                                                        //maxx=max(maxx,len);
                                                }
                                                else{
                                                        if(tr[u].size()>=1)
                                                                maxx=max(maxx,1);
                                                }
                                        }
                                        else{
                                                sum++;
                                                dfs(temp,cnt+1);
                                                ss[u]+=ss[temp];
                                        }
                                }
                        }
                }
        }
}
int main(){
        cin>>n>>k;
        for(int i=1; i<n; i++){
                int u,v;
                cin>>u>>v;
                tr[u].push_back(v);
                tr[v].push_back(u);
        }
        int ans=0;
        for(int i=1; i<=n; i++){
                sum=1;
                memset(vis,0,sizeof(vis));
                memset(ss,0,sizeof(ss));
                maxx=0;
                dfs(i,1);
//cout<<maxx<<endl;
                if(k%2){
                        sum+=maxx;
                        if(!maxx){
                                for(int j=0;j<tr[i].size();j++){
                                        int temp=tr[i][j];
                                        maxx=max(ss[temp],maxx);
                                }
                                sum+=maxx;
                        }
                }
                ans=max(ans,sum);
//cout<<i<<" "<<ans<<endl;
        }
        cout<<n-ans;
        return 0;
}


Measured memory_bytes: 512
input = raw_input
n = int(input())

x_list = map(int, input().split(" "))

x_sum = sum(x_list)
x_ave = float(x_sum) / n

import math
m1 = int(math.ceil(x_ave))
m2 = int(math.floor(x_ave))
out1 = sum([(x-m1)**2 for x in x_list])
out2 = sum([(x-m2)**2 for x in x_list])
out = min(out1, out2)
print(out)

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

using namespace std;

long long INF=1e15;

int solve(int x,int y,int z){
    int res=0;
    res+=195*(x-1);
    res+=5*((x-1)/3);// x年1月1日までの日数
    if(x%3==0){
        res+=(y-1)*20;
    }
    else{
        for(int i=1;i<y;i++){
            if(i%2==0)res+=19;
            else res+=20;
        }
    }// x年y月1日までの日数
    res+=z-1;

    return res;
}

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

    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        int y,m,d;
        cin>>y>>m>>d;
        cout<<solve(1000,1,1)-solve(y,m,d)<<endl;
    }
}


Measured memory_bytes: 3080
import java.io.*;
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner f = new Scanner(System.in);
        int[] arr = new int[5];
        for(int i=0;i<5;i++){
            arr[i] = f.nextInt();
        }
        int ans = 0;
        for(int i=0;i<5;i++){
            if(arr[i] == 0){
                ans = i + 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35580
program c

integer :: n,a(10000),ans=0

read(*,*) n
read(*,*) (a(i),i=1,n)

do i=1,n
	do while (mod(a(i),2)==0)
		a(i) = a(i) / 2
		ans = ans + 1
	enddo
enddo

write(*,*) ans

end program

Measured memory_bytes: 800
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    cout<<pow(n,3)<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>

int a[1005],b,c[1005];

int main(){
	int i,j,n,m;
	
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)scanf("%d",&a[i]),c[i]=0;
	for(i=0;i<m;i++){
		scanf("%d",&b);
		for(j=0;j<n;j++)if(a[j]<=b)break;
		c[j]++;
	}
	j=0;
	for(i=0;i<n;i++)if(c[i]>c[j])j=i;
	printf("%d\n",j+1);
	
	return 0;
}

Measured memory_bytes: 604
def bit_dp(N, Adj):
    dp = [[0]*N for i in range(1 << N)]
    # dp({0], 0) = 1 と初期化する
    dp[1][0] = 1

    for S in range(1 << N):
        for v in range(N):
            # v が S に含まれていないときはパスする
            if (S & (1 << v)) == 0:
                continue

            # sub = S - {v}
            sub = S ^ (1 << v)

            for u in range(N):
                # sub に u が含まれており、かつ u と v が辺で結ばれている
                if (sub & (1 << u)) and (Adj[u][v]):
                    dp[S][v] += dp[sub][u]

    ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))
    return ans


def main():
    N, M = map(int, input().split())
    Adj = [[0]*N for i in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        Adj[a-1][b-1] = 1
        Adj[b-1][a-1] = 1

    ans = bit_dp(N, Adj)

    print(ans)


if __name__ == '__main__':
    main()


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


ll const mod = 1e9+7;
int main() {
  ll N,H,use,cnt=0;
  cin >> N >> H;
  vector<ll> a(N),b(N);
  rep(i,N) cin >> a[i] >> b[i];
  use = *max_element(a.begin(),a.end());
  sort(b.rbegin(),b.rend());
  for (auto i:b) {
    if (i>use) {
      cnt++;
      H-=i;
      if (H<=0)break;
    }
    else {
      break;
    }
  }
  if (H>0) cnt += (H+use-1)/use;
  cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

class Union_Find_Tree{
	public:
	vi Par,Rank;
	Union_Find_Tree(int n){
		Par=Rank=vi(n);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		if(Rank[x]<Rank[y]) Par[x]=y;
		else{
			Par[y]=x;
			if(Rank[x]==Rank[y]) Rank[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

class Graph{
	private:
	int V;
	vvp List;
	vip e;
	vb used;
	void Rec(int v,int M,vl& d){
		used[v]=1;
		d[v]=M;
		for(int i=0;i<List[v].size();i++){
			int u=List[v][i].first,c=List[v][i].second;
			if(!used[u]) Rec(u,max(M,c),d);
		}
	}
	public:
	Graph(int v){
		V=v;
		List=vvp(v);
	}
	void add_edge(int s,int t,int c){
		List[s].push_back({t,c});
		List[t].push_back({s,c});
		e.push_back({c,{s,t}});
	}
	vvl func(){
		vvl d(V,vl(V));
		for(int i=0;i<V;i++){
			used=vb(V,0);
			Rec(i,0,d[i]);
		}
		return d;
	}
	void solve(){
		Union_Find_Tree uft(V);
		Graph G(V);
		ll cost=0;
		sort(e.begin(),e.end());
		for(int i=0;i<e.size();i++){
			ll c=e[i].first,s=e[i].second.first,t=e[i].second.second;
			if(!uft.Same(s,t)){
				uft.Unite(s,t);
				G.add_edge(s,t,c);
				cost+=c;
			}
		}
		vvl d=G.func();
		int q;
		cin>>q;
		for(int i=0;i<q;i++){
			int s,t;
			cin>>s>>t;
			cout<<cost-d[s-1][t-1]<<endl;
		}
	}
};

int n,m;

int main(){
	cin>>n>>m;
	Graph g(n);
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		g.add_edge(a-1,b-1,c);
	}
	g.solve();
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll K, std::vector<ll> p) {
  sort(all(p));
  ll sum = 0;
  rep(i, K) { sum += p.at(i); }

  cout << sum << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}


Measured memory_bytes: 3720
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc168_b
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000



int main() {
    int k;
    string s;
    cin >> k >> s;
    if((int)size(s) <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
}


Measured memory_bytes: 3632