akhauriyash/Code-Regression huggingface dataset:
while True:
 a,op,b=map(str,input().split())
 if op=='+':
   print(int(a)+int(b))
 elif op=='-':
   print(int(a)-int(b))
 elif op=='*':
   print(int(a)*int(b))
 elif op=='/':
   print(int(a)//int(b))
 elif op=='?':
   break


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
long long sum = 1;
int f, n;
int main() {
    cin >> n;
   
    for (int i = 0; i <n; i++) {
        cin >> a[i];
        if (a[i]==0) f=1;
    }
    if (f==1) {
        cout<< 0<<endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] <= 1000000000000000000 / sum) {
            sum *= a[i];
        } else {
            cout<<-1<<endl;
            return 0;
        }
    }
    cout << sum<<endl;
    return 0; 
}

Measured memory_bytes: 4316
#include <iostream>
using namespace std;
int inf= 1000000001;
long long int knapsack(int arr[][2],int n,int w)
{
    int maxSize = n*1000;
    long long int dp[n][maxSize+1];
    for(int i=0;i<=maxSize;i++)
    {
        dp[0][i]=inf;
    }
    dp[0][0]=0;
    dp[0][arr[0][1]]=arr[0][0];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=maxSize;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(arr[i][1]>j)
            {
                continue;
            }
            dp[i][j] = min(dp[i][j],arr[i][0]+dp[i-1][j-arr[i][1]]);
        }
    }
    long long int ans = 0;
    for(int x=0;x<=maxSize;x++)
    {
        if(dp[n-1][x]<=w)
        {
            ans = x;
        }
    }
    return ans;
}
int main()
{
    int n,w;
    cin>>n>>w;
    int arr[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
    }
    cout<<knapsack(arr,n,w)<<endl;
    return 0;
}


Measured memory_bytes: 78336
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = {'s':R, 'p':S, 'r':P}
T = input()

ans = 0
a = []
for i, t in enumerate(T):
  if i < K:
    ans += d[t]
    a.append(t)
  else:
    if t == a[i-K]:
      a.append('a')
    else:
      ans += d[t]
      a.append(t)

print(ans)

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

int main () {
        string s, t;
        int a, b;
        cin >> s >> t >> a >> b;
        string u; cin >> u;
        if (u == s) a--;
        if (u == t) b--;
        cout << a << " " << b << endl;
        return 0;
}

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

bool convert(char c) {
  return (c == 'H') ? 1 : 0;
}

int main() {
  char a, b;
  cin >> a >> b;
  char ans = convert(a) ^ convert(b) ? 'D' : 'H';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#memo roiti 899204
def rm_s(h):
    seth=set(h)
    for hai in seth:
        if set([hai,hai+1,hai+2])<=seth:
            if len(h)==3:
                return 1
            h1=h[:]
            for i in range(3):
                h1.remove(hai+i)
            return is_hora(h1)
    else:
        return 0

def rm_k(h):
    for hai in set(h):
        if h.count(hai)>=3:
            if len(h)==3:
                return 1
            h1=h[:]
            for i in range(3):
                h1.remove(hai)
            return is_hora(h1)
    else:
        return 0

def is_hora(h):
    return rm_k(h) or rm_s(h)

while 1:
    try:
        h=map(int,raw_input())
        ans=[]
        for a in range(1,10):
            if h.count(a)<=3:
                h1=h[:]+[a]
                for d in set(h1):
                    if 2<= h1.count(d):
                        h1=h[:]+[a]
                        h1.remove(d)
                        h1.remove(d)
                        if is_hora(h1):
                            ans.append(a)
                            break
        print ' '.join(map(str, sorted(ans))) if len(ans)>0 else 0
    except:
        break

Measured memory_bytes: 6368
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
int val[100001];
int wt[100001];
int val1[10000001];
int val2[10000001];
int val3[10000001];
int val4[10000001];
int val5[10000001];
int val6[10000001];
int val7[10000001];
int val8[10000001];
int val9[10000001];
int val10[10000001];

int knapsck(int n, int w){
    int dp[2][w+1];
    for (int i=0; i<=n; i++){
        for (int j = 0; j <= w; j++){
            // Base Case ...
            if(i==0 || j == 0){
                dp[i%2][j] = 0ll; 
                continue;
            }
            if(wt[i-1]>j)
                dp[i%2][j] = dp[(i-1+2)%2][j];
            else{
                dp[i%2][j] = max( 
                                dp[ (i-1+2)%2 ][j] , 
                                val[i-1] + dp[ (i-1+2)%2 ][ j - wt[i-1] ] );
            }
        }
    }
    return dp[n%2][w]; 
}

signed main() {
    int n, w;

    cin >> n >> w;
    for (int i=0;i<n; i++)
        cin >> wt[i] >> val[i];
    cout<<knapsck(n, w);
     
    return 0;
}

Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
static const int MAX_N = 10000;
static const int MAX_H = 100;
static const int MAX_W = 100;

int H, W;
int N;
int a[MAX_N];

int c[MAX_H][MAX_W];

void solve(){
	int index_ci = 0, index_cj = 0;
	for(int i = 0; i < N; i++){
		for(int j = 1; j <= a[i]; j++){
			c[index_ci][index_cj] = i + 1;
			if(index_ci % 2 == 0 && index_cj == W - 1) index_ci++;
			else if(index_ci % 2 == 1 && index_cj == 0) index_ci++;
			else if(index_ci % 2 == 0) index_cj++;
			else if(index_ci % 2 == 1) index_cj--;
		}
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			printf("%d", c[i][j]);
			if(j == W - 1) printf("\n");
			else printf(" ");
		}
	}
}

int main(){
	scanf("%d %d", &H, &W);
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>

using namespace std;

int main() {

    int n;
    string s, t;
    int len_s, len_t;
    int i, j, k, ans;
    
    cin>>n;
    cin>>s>>t;

    len_t = 0;
    j = n+n;
    k=n;
    /*if(strcmp(s,t)==0)
        cout<<n;
    elseif*/{
        
        for(i=0; i<n; i++){
            
            if(( s.substr(i,n).compare( t.substr(0,n-i)) == 0)){
                cout<<k<<"\n";
                len_t=1;
                break;  
            }
            k++;
        }
        if(len_t==0)
            cout<<j;
    }
    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<P> p(N);
    rep(i, N) {
        ll x, y;
        cin >> x >> y;
        p[i] = P(x,y);
    }
    vector<ll> x(N);
    vector<ll> y(N);
    rep(i, N) {
        x[i] = p[i].first;
        y[i] = p[i].second;
    }
    sort(all(x));
    sort(all(y));
    ll mi = INF;
    rep(i, N) {
        rep(j, N) {
            rep(s, N) {
                rep(t, N) {
                    if (x[i] <= x[j] && y[s] <= y[t]) {
                        ll cnt = 0;
                    for(P tmp : p) {
                        if (x[i] <= tmp.first && tmp.first <= x[j] && y[s] <= tmp.second && tmp.second <= y[t]) {
                            cnt++;
                        }
                        if (cnt >= K) {
                            mi = min(mi, (x[j] - x[i]) * (y[t] - y[s]));
                        }
                    }
                    }
                    
                }
            }
        }
    }
    print(mi);
    return 0;
}

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

int main() {
  long a;
  double b;
  long tb;
  
  cin >> a >> b;
  tb = stoi(to_string(b).substr(0,1) + to_string(b).substr(2,2));
  
  long result = a * tb / 100;
  
  cout << result << endl;
}

  

Measured memory_bytes: 3816
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

ll g[334][334];
ll h[334][334];

int main(int argc, char const *argv[]) {
    int n,m,l;
    cin>>n>>m>>l;
    rep(i,334) rep(j,334) g[i][j] = h[i][j] = LINF;
    rep(i,334) g[i][i] = h[i][i] = 0;
    rep(i,m) {
        ll a,b,c; cin>>a>>b>>c;
        --a,--b;
        if (c > l) continue;
        g[a][b] = g[b][a] = c;
    }

    rep(k,n) {
        rep(i,n) {
            rep(j,n) chmin(g[i][j], g[i][k]+g[k][j]);
        }
    }

    rep(i,n) {
        rep(j,n) {
            if (i==j) continue;
            if (g[i][j] <= l) h[i][j] = 1;
            else h[i][j] = g[i][j];
        }
    }

    rep(k,n) {
        rep(i,n) {
            rep(j,n) chmin(h[i][j], h[i][k]+h[k][j]);
        }
    }

    int q; cin>>q;
    rep(i,q) {
        int s,t; cin>>s>>t;
        --s,--t;
        if (h[s][t] == LINF) {
            cout << -1 << endl;
            continue;
        }
        else {
            cout << h[s][t]-1 << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <math.h>

double area(double a,double b, double c);

int main(){
	int i,n = 0;
	double x[20];
	double y[20];
	double a,b,c,s = 0;
	
	while(scanf("%lf,%lf",&x[n],&y[n])!=EOF){
		n++;
	}
	for(i=1;i<n-1;i++){
		a = sqrt( (x[0]-x[i])*(x[0]-x[i]) + (y[0]-y[i])*(y[0]-y[i]) );
		b = sqrt( (x[0]-x[i+1])*(x[0]-x[i+1]) + (y[0]-y[i+1])*(y[0]-y[i+1]) );
		c = sqrt( (x[i+1]-x[i])*(x[i+1]-x[i]) + (y[i+1]-y[i])*(y[i+1]-y[i]) );
		s += area(a,b,c);
	}
	
	printf("%f\n",s);
	
	return 0;
}

double area(double a,double b, double c){
	double z = (a+b+c)/2;
	return sqrt(z*(z-a)*(z-b)*(z-c));
}

Measured memory_bytes: 652
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int N, K;
   cin >> N >> K;
   int h[N];
   for (int i = 0; i < N; i++) {
      cin >> h[i];
   }
   int dp[N];
   dp[0] = 0;
   dp[1] = dp[0] + abs(h[1] - h[0]);
   for (int i = 2; i < N; i++) {
      int min = -1;
      for (int j = 1; j <= K; j++) {
         if (i - j >= 0) {
            int tmp = dp[i - j] + abs(h[i] - h[i - j]);
            if (j == 1 || tmp < min) min = tmp;
         }
      }
      if (min != -1) dp[i] = min;
   }
   cout << dp[N - 1] << endl;
   return 0;
}


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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = 0;
  ll n = B - A;
  if (n == 1) {
    ans = min(N - A, B - 1);
  } else if (n % 2 == 0) {
    ans = n / 2;
  } else {
    ll p = (A - 1) * 2 + 1;
    ll q = (N - B) * 2 + 1;
    ll a = p + (n - p) / 2;
    ll b = q + (n - q) / 2;
    ans = min(a, b);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>


/**------------ SUB ROUTIONE -------------*/
/**------------ SUB ROUTIONE -------------*/
int main()
{
	int i,k,wk;
	char inp[96];
	int dt[10];

	int work[10];

	/**--init --**/

	/**--input--**/
	for (i=0 ; i<10 ; i++) {
		gets(inp);
		sscanf(inp,"%d",&(dt[i]));
	}

	/**-- CALC --**/
	memcpy(work,dt,sizeof(work));
	for (i=0 ; i<9 ; i++) {
		for (k=0 ; k<9 ; k++) {
			if (work[k] > work[k+1]) {
				wk = work[k];
				work[k] = work[k+1];
				work[k+1] = wk;
			}
		}
	}

	for (i=9 ; i>6 ; i--) {
		printf("%d\n",work[i]);
	}
	return 0;
}

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

LL t,n,m,ans;
string a,b="CODEFESTIVAL2016";

int main()
{
	LL i,j,k,l;
	cin>>a;
	for(i=0;i<16;i++)ans+=a[i]!=b[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int H=stdIn.nextInt();
		int W=stdIn.nextInt();
		int h=stdIn.nextInt();
		int w=stdIn.nextInt();
		System.out.println(H*W-(W*h+H*w-h*w));
	}

}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.1415926535897932384626

int main()
{
  int n;
  cin >> n;
  int k = n % 10;
  if (k == 3)
  {
    cout << "bon" << endl;
  }
  else if (k == 0 || k == 1 || k == 6 || k == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<string.h>
char S[100001];

int main() {
    scanf(" %s", S);
    int n = strlen(S);
    int h = (int) ((n + 1) / 2);
    int t = h;
    while(t >= 1 && S[t - 1] == S[h - 1] && S[n - t] == S[h - 1]) t--;
    printf("%d\n", n - t);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
ll n;
ll ans=0;
int main(){
	scanf("%lld",&n);
	ll u=1;
	while(u<=n){
		ll v=n/(n/u);
		if(n%(n/u)==0&&n/v<v-1&&v-1>=u){
			ans+=v-1;
		}
		u=v+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(void){char o;int a,b;scanf("%d%c%c%d",&a,&o,&o,&b);while(o!='?'){if(o=='+'){a=a+b;}if(o=='-'){a=a-b;}if(o=='*'){a=a*b;}if(o=='/'){a=a/b;}printf("%d\n",a);scanf("%d%c%c%d",&a,&o,&o,&b);}return(0);}


Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>
#include <map>
#include <string>

using namespace std;
 
int main(void){
	
	int P[3];
	
	cin >> P[0] >> P[1] >> P[2];
	
	sort(P, P+3);
	
	cout << P[0]+P[1];
	
	return 0;
}

Measured memory_bytes: 256
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
 //    #endif
    
    string s,t;
    cin >> s;
    cin >>t;
    rep(i,s.length())
    {
    	char temp=s[0];
    	s=s.substr(1,s.length()-1)+temp;
    	if(s==t)
    	{
    		cout << "Yes\n";
    		return 0;
    	}
    }
    cout << "No\n";
	
	return 0;
}



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

#define MAX_NUM 1000000000000000000
int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);

	long long result = 1;
	bool flag_over = false;

	for (int i = 0; i < N; i++)
	{
		long long A;
		scanf("%lld", &A);
		if (A == 0)
		{
			cout << "0";
			return 0;
		}

		if (MAX_NUM / result < A)
		{
			result = 1;
			flag_over = true;
		}
		result *= A;
	}
	if (flag_over)
	{
		cout << -1;
	}
	else
	{
		cout << result;
	}

	return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N];

int main()
{
   int t,d,x;
   cin>>d>>t>>x;
   if(t*x>=d)
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;

int N;
//int64_t L,Lk1,Lk2;
VVI data(12, VI(12,0));

void dfs(int k,int64_t &L,int64_t &Lk1,int64_t &Lk2) {
    if(N==1) {
        L=1;
        return;
    }else if(k==N) {
        L=Lk1+Lk2;
        return;
    }
    
    if(k==0) Lk1=2;
    else if(k==1) Lk2=1;
    else {
        L=Lk1+Lk2;
        Lk1=Lk2;
        Lk2=L;
    }
    dfs(k+1,L,Lk1,Lk2);
}

int main() {
  cin >> N;
  int64_t L,Lk1,Lk2;
  dfs(0,L,Lk1,Lk2);
  cout << L << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main(){
  int W,H,N;
  cin>>W>>H>>N;
  int w0,w1,h0,h1;
  w0=0;
  w1=W;
  h0=0;
  h1=H;
 
  REP(i,N){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1)w0=max(x,w0);
    else if(a==2)w1=min(x,w1);
    else if(a==3)h0=max(y,h0);
    else h1=min(y,h1);
  }
  cout<<max(0,(w1-w0))*max(0,(h1-h0))<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;

int main()
{
	ll x,k,d;cin>>x>>k>>d;
	if(x<0) x=-x;
	ll yu=x-(x/d)*d,y=x/d;
	if(y>k) cout<<x-k*d;
	else{
		if(k%2==y%2) cout<<yu;
		else{
			ll x1=yu-d,x2=yu+d;
			x1=abs(x1),x2=abs(x2);
			cout<<min(x1,x2);
		}
	} 
	return 0;	
} 

Measured memory_bytes: 3180
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    int X=0,Y=0,Z=0;
    X = count(S.cbegin(), S.cend(), '1');
    Y = count(S.cbegin(), S.cend(), '0');
    Z = max(X,Y) - min(X,Y);
    cout << X + Y - Z << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()




using namespace std;



int main(){
  int K,A,B; cin>>K>>A>>B;
  for(int i=A;i<=B;i++){
    if(i % K == 0){ cout<<"OK"<<endl;return 0;}

  }
  cout<<"NG"<<endl;





  return 0;
}

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

typedef long long ijt;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define rep(i,n) for(int i = 0;i < n;i++)

int N,Q;
int main(void){
   cin >> N >> Q;
   set<int> P;
   vector<pair<int,pair<int,int>>> E;
   for(int i = 0;i < N;i++){
      int s,t,x;cin >> s >> t >> x;
      E.pb(mp(s - x,mp(-1,x)));
      E.pb(mp(t - x - 1,mp(1,x)));
   }
   for(int i = 0;i < Q;i++){
      int d;cin >> d;
      E.pb(mp(d,mp(0,0)));
   }
   
   sort(all(E));
   //for(auto i : E)cout << i.ff << " " << i.ss.ff << " " << i.ss.ss << endl;
   for(int i = 0;i < E.size();i++){
      auto e = E[i];
      int command = e.second.first;
      int posi = e.second.second;
      if(command == -1){
         P.insert(posi);
      }else if(command == 1){
         P.erase(posi);
      }else{
         if(!P.empty())cout << *P.begin() << endl;
         else cout << -1 << endl;
      }
   }
   return 0;
}

Measured memory_bytes: 17768
import math
n = int(input().rstrip())
sqrt_n = math.sqrt(n)
possible_a = math.ceil(sqrt_n)

def b(n,a):
    for i in range(a,0,-1):
        if n%i==0:
            return i,int(n/i) #a,b
            
def f(a,b):
    return max(len(str(a)),len(str(b)))

a,b = b(n,possible_a)
print(f(a,b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define fastcin ios_base::sync_with_stdio(false)

typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int v[100007];
int main (void) {
  	fastcin;
  	int n;
  	int a, maxim, maxscore = -1;
  	int answ;
  	cin >> n;
  	for(int i=0;i<n;i++){
  		cin >> a >> maxim;
  		if(a > maxscore){
  			maxscore = a;
  			answ = maxim;
  		}
  	}
  	cout << maxscore + answ << endl;

  
	return 0;
  		
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string str1,str2;
    cin>>str1>>str2;
    char charray1[3], charray2[3];
    str1.copy(charray1, 3);
    str2.copy(charray2,3);
    if (charray1[0]==charray2[2] && charray1[1]==charray2[1] && charray1[2]==charray2[0])
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(x,n) for(auto& (x) : n)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
typedef pair<int,pint> P;

vint calc(int a){
    vint kari;
    reps(i,1,pow(a,0.5)+1){
        if(a%i==0){
            kari.pb(i);
            kari.pb(a/i);
        }
    }
    return kari;

}

int main(){
    int n;
    cin>>n;
    vint a(n);
    rep(i,n)cin>>a[i];
    vint a1cal=calc(a[0]);
    vint a2cal=calc(a[1]);
    int nummax=0;
    forin(x,a1cal){
        int check=0;
        rep(i,n){
            if(a[i]%x>=1){
                check++;
                if(check>1)break;
            }
        }
        if(check<=1){
            chmax(nummax,x);
        }
    }
    forin(x,a2cal){
        int check=0;
        rep(i,n){
            if(a[i]%x>=1){
                check++;
                if(check>1)break;
            }
        }
        if(check<=1){
            chmax(nummax,x);
        }
    }
    cout<<nummax<<endl;


}

Measured memory_bytes: 640
double x,y,r,X,Y,R;main(n){for(scanf("%d",&n);n--;printf("%d\n",x+R<r?2:x+r<R?-2:x<=r+R))scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&r,&X,&Y,&R),x=hypot(X-x,Y-y);}

Measured memory_bytes: 652
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  string s;
  vector<int> ans;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'&&ans.size()!=0) ans.pop_back();
    else if(s[i]=='0') ans.push_back(0);
    else if(s[i]=='1') ans.push_back(1);
    else continue;
  }
  for(int i=0;i<ans.size();i++){
  cout<<ans[i];
  }
  return 0;
}


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

int main() {
  string x;
  long long N;
  cin >> x;
  N=size(x);
  if (x.at(N-1)=='s') {
    cout << x+"es" << endl;
  }
  if (x.at(N-1)!='s') {
    cout << x+'s' << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
  cout << n*n*n <<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b, c, ab;
	cin >> a >> b >> c;
	ab = a * b;
	if (ab < c) {
		cout << ab;
	}
	else if (c < ab) {
		cout << c << endl;
	}
	else cout << c;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
const long long MOD = 1000000007;
long long N, O, pow3[61];
std::map < long long, long long > ans[61];
long long F(long long n, int w)
{
	if (w == -1)
		return 1;
	if (n >= (4LL << w) - 2)
		return pow3[w + 1];
	auto it = ans[w].find(n);
	if (it != ans[w].end())
		return it -> second;
	long long r = 0;
	for (long long i = 0; i <= 2 && i <= n >> w; i++)
		r += F(n - (i << w), w - 1);
	return ans[w][n] = r % MOD;
}
int main()
{
	scanf("%lld", &N);
	pow3[0] = 1;
	for (int i = 1; i <= 60; i++)
		pow3[i] = pow3[i - 1] * 3 % MOD;
	printf("%lld\n", F(N, 60));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   set<ll> s;
    int a,b,c;
  cin>>a>>b>>c;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  
  if(s.size()==2)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;





}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()


int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> p(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    ll ans = 0;
    ll _min = p[0];
    for (ll i = 0; i < n; i++)
    {
        if (p[i] <= _min)
        {
            ans++;
        }
        _min = min(_min, p[i]);
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mN = 1e5;

ull t, n, dp[mN][3];

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

  cin>>n;
  int arr[n][3];
  for(int i = 0; i < n; ++i) for(int j = 0; j < 3; ++j) cin>>arr[i][j];

  for(int i = 0; i < n; ++i) dp[0][i] = arr[0][i];

  for(int i = 0; i < n - 1; ++i){
    dp[i + 1][0] = arr[i + 1][0] + max(dp[i][1], dp[i][2]);
    dp[i + 1][1] = arr[i + 1][1] + max(dp[i][0], dp[i][2]);
    dp[i + 1][2] = arr[i + 1][2] + max(dp[i][0], dp[i][1]);
  }
  ull ans = dp[n - 1][0];
  for(int i = 1; i < 3; ++i) ans = max(dp[n - 1][i], ans);
  cout<<ans<<"\n";
}


Measured memory_bytes: 7068
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <iomanip>
using namespace std;
int main(){
	long long n,k;
	vector<long long> a,f;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		a.push_back(A);
	}
	for(int i=0;i<n;i++){
		int F;
		cin>>F;
		f.push_back(F);
	}
	sort(a.begin(),a.end());
	sort(f.begin(),f.end());
	long long l=0,r=2e18;
	while(l!=r){
		long long m=(l+r)/2;
		long long cnt=0;
		vector<long long> am;
		for(int i=0;i<n;i++){
			am.push_back(m/f[i]);
		}
		sort(am.begin(),am.end());
		for(int i=0;i<n;i++){
			if(a[i]>am[i]){
				cnt+=(a[i]-am[i]);
			}
		}
		if(cnt<=k){
			r=m;
		}else{
			l=m+1;
		}
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 7572
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define int long long
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 5, MOD1 = 1e9 + 7, MOD2 = 998244353;
const lint INF = 1e18;

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

Measured memory_bytes: 3588
unittest
{
	assert( [ "4", "1 4 2", "2", "1 1 -8", "2" ].parse.expand.solve == "4 2\n1 -3" );
	assert( [ "4", "1 -1000000000 1000000000", "1 -1000000000 1000000000", "1 -1000000000 1000000000", "2" ].parse.expand.solve == "-1000000000 3000000000" );
	
	assert( [ "4", "1 -4 2", "2", "1 -1 -8", "2" ].parse.expand.solve == "-4 2\n-4 -3" );		// 追加ケース
}



import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto qss = new long[][ n ];
	foreach( ref qs; qss )
	{
		input.popFront;
		qs = input.front.split.to!( long[] );
	}
	return tuple( qss );
}

auto solve( long[][] qss )
{
	string[] anss;
	auto c  = 0L;
	auto x  = 0L;
	auto lt = 0L;
	auto lq = heapify( new long[ 10L ^^ 5 + 10 ], 0 );
	auto rt = 0L;
	auto rq = heapify!( ( x, y ) => y < x )( new long[ 10L ^^ 5 + 10 ], 0 );
	auto bt = 0L;
	foreach( qs; qss )
	{
		final switch( qs[ 0 ] )
		{
			case 1:
				// 左右のキューの長さが一致するようにaを追加（全体の個数が奇数の場合は左に寄せる）
				c++;
				if( qs[ 1 ] <= x )
				{
					lt += qs[ 1 ];
					lq.insert( qs[ 1 ] );
					if( lq.length != rq.length + c % 2 )
					{
						rt += lq.front;
						rq.insert( lq.front );
						lt -= lq.front;
						lq.popFront();
					}
				}
				else
				{
					rt += qs[ 1 ];
					rq.insert( qs[ 1 ] );
					if( lq.length != rq.length + c % 2 )
					{
						lt += rq.front;
						lq.insert( rq.front );
						rt -= rq.front;
						rq.popFront();
					}
				}
				
				// 中央値をxとして使う（全体の個数が奇数の場合は左に寄せる）
				x = lq.front;
				bt += qs[ 2 ];
				break;
			
			case 2:
				// 左右のキューの合計が x == 0 のときの答えなので、xに合わせてずらす
				auto ltx = ( x * ( lq.length.signed - 1 ) ) - ( lt - x );
				auto rtx = rt - ( x * rq.length.signed );
				anss ~= format( "%s %s", x, ltx + rtx + bt );
				break;
		}
	}
	return anss.join( "\n" );
}


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

#define  __  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define  int  long long
#define  endl  '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
//______________________


int32_t main()
{ 
  __
 
  
  int k, x;
  cin >> k >> x;

  for(int i = max((int)-1e6, x - k + 1); i <= min((int)1e6, x + k - 1); i++)
    cout << i << ' ';

 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int CheckPrime(int n);
int main(void)
{
	static int IsPrime[1000000];
	int i, n, ans;

	for(i=0; i<=999999; i++)
		IsPrime[i]=-1;

	while(scanf("%d",&n)!=EOF)
	{
		ans = 0;
		for(i=2; i<=n; i++)
		{
			if(IsPrime[i] == -1)
				IsPrime[i] = CheckPrime(i);
			
			if(IsPrime[i])
				ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

int CheckPrime(int n)
{
	int i;
	if(n <= 1)return 0;
	if(n == 2)return 1;
	if(n%2==0)return 0;

	for(i=3; i*i<=n; i++)
		if(n%i == 0)return 0;

	return 1;
}

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


void solve(long long T, long long X){
	printf("%.10Lf\n",T/(long double)(X));
	
}

int main(){
    long long T;
    scanf("%lld",&T);
    long long X;
    scanf("%lld",&X);
    solve(T, X);
    return 0;
}


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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i])  {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  prime.erase(remove(prime.begin(), prime.end(), 0), prime.end());
  return prime;
}

int main() {
  int n;
  vector<int> prime;
  prime = sieve(1000000);

  while(cin >> n) {
    int count=0;

    for(vector<int>::iterator it=prime.begin(); it!=prime.end(); it++) {
      if(*it>n) break;
      count++;
    }
    cout << count <<endl;
  }
  return 0; 
}


Measured memory_bytes: 5164
N = int(input())
T = list(map(int, input().split()))
M = int(input())
PX = [list(map(int, input().split())) for i in range(M)]

for i in range(M):
    time = 0
    ls = PX[i]
    for j in range(N):
        if ls[0] == j+1:
            time += ls[1]
        else:
            time += T[j]
    print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


void testcase(){
	int n,a[200005];
	unordered_map<int,int> freq;
	ll sum = 0;
	cin >> n;
	for(int i{0};i < n;i++){
		cin >> a[i];
		freq[a[i]]++;
		sum += (ll)a[i];
	}
	int q;
	cin >> q;
	while(q--){
		ll b,c;
		cin >> b >> c;
		if(freq.find((int)b) != freq.end()){
			sum -= b * (ll)freq[b];
			sum += c * (ll)freq[b];
			freq[c] += freq[b];
			freq[b] = 0;
		}
		cout << sum << "\n";
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 7272
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
)
 

func main(){
  a := 0
  for i := 1; ; i++{
    fmt.Scan(&a)
    if a == 0{
      break
    }else{
      fmt.Printf("Case %d: %d\n",i,a)
    }
  }
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


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

int main(){
  int N,T;
  cin >> N >> T;

  int c[N];
  int t[N];
  for(int i =0; i<N; i++){
    cin >> c[i] >> t[i];
  }

  int ans=1001;
  int num=0;
  for(int i=0; i<N; i++){
    if(t[i]<=T){
    ans=min(ans,c[i]);
    }
  }
   
  if(ans==1001) cout << "TLE"<<endl;
    else cout << ans << endl;
}
  


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

int n, m, f, t;
stack<int> top;
vector<int> cnt;
vector<vector<int>> g;
bitset<100019> vis(0);
void dfs(int v) {
	vis.set(v);
	for(auto& i : g[v])
		if(!vis.test(i))
			dfs(i);
	top.push(v);
}

int main() {
	cin >> n >> m;
	g.resize(n + 1);
	cnt.resize(n + 1, 0);
	for(int i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].push_back(t);
	}

	for(int i = 1; i <= n; i++)
		if(!vis.test(i))
			dfs(i);

	vector<int> tsort;
	while(!top.empty()) {
		tsort.push_back(top.top());
		top.pop();
	}

	for(auto& i : tsort)
		for(auto& j : g[i])
			cnt[j] = max(cnt[j], cnt[i] + 1);
	cout << *max_element(cnt.begin(), cnt.end());
	return 0;
}


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

using namespace std;

int main()
{
	int N;
	int d[100];
	cin>> N;
	for(int i=0;i<N;i++)cin>> d[i];

	int ret=1;
	sort(d,d+N);
	for(int i=1;i<N;i++)
	{
		if(d[i]!=d[i-1])ret++;
	}
	cout<< ret<< endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int n, m;
const int MAX = 10;
vi to[MAX];

int main () {
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  vi v;
  rep(i,n-1) {
    v.push_back(i+1);
  }
  /*for (auto x : v) {
    cout << x << " " ;
  }
  cout << endl;*/

  int ans = 0;
  do {
    rep(i,n-1) {
      if (find(ALL(to[v[i]]),v[i+1])==to[v[i]].end()) break;
      if (i == n-2) ans++;
    }
  } while (next_permutation(ALL(v)));

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main(){
    string n;
    cin >> n;
    for (int i = 0; i < 3; i++){
        if (n[i] == '1'){
            n[i] = '9';
        }else{
            n[i] = '1';
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class AtCoder_154_D
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] sum = new int[1001];
        sum[0] = 0;
        for (int i = 1; i < sum.Length; i++)
        {
            sum[i] = sum[i - 1] + i;
        }

        double[] exp = new double[1001];
        exp[0] = 0f;
        for (int i = 1; i < exp.Length; i++)
        {
            exp[i] = (double)sum[i] / i;
        }

        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = line1[0];
        int k = line1[1];
        double[] line2 = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x))
            .Select(x => exp[x])
            .ToArray();

        double prev = 0f;
        for (int i = 0; i < k; i++)
        {
            prev += line2[i];
        }
        double max = prev;

        for (int i = 1; i < n - k + 1; i++)
        {
            prev = prev - line2[i - 1] + line2[i + k - 1];
            if (max < prev)
            {
                max = prev;
            }
        }

        Console.WriteLine(max);
    }
}


Measured memory_bytes: 34012
import java.io.*
import java.util.*

// 500A + 100B +  50C = X
fun solve(A: Int, B: Int, C: Int, X: Int){
    var ans = 0
    for (a in 0..A){
        for (b in 0..B){
            for (c in 0..C){
                if (500*a + 100*b + 50*c == X){
                    ans++
                }
            }
        }
    }
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    val C = sc.next().toInt()
    val X = sc.next().toInt()
    solve(A, B, C, X)
}



Measured memory_bytes: 31400
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    int now_min = INF;

    rep(i, N) {
        if (A[i] < now_min) {
            ans++;
            now_min = A[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import heapq
from collections import defaultdict

N=int(input())
V=defaultdict(set)
for i in range(N-1):
  a,b,c=map(int,input().split())
  V[a-1].add((b-1,c))
  V[b-1].add((a-1,c))

Q,K=map(int,input().split())

def dijkstra(n,v):
  d=[float('inf')]*n
  d[v]=0
  
  hq=[(0,v)]
  
  while hq:
    u = heapq.heappop(hq)[1]
    for nv,c in V[u]:
      if d[nv]>d[u]+c:
        d[nv]=d[u]+c
        heapq.heappush(hq,(d[u]+c,nv))
        
  return d

ans=dijkstra(N,K-1)

for i in range(Q):
  a,b=map(int,input().split())
  print(ans[a-1]+ans[b-1])

Measured memory_bytes: 73368
#include<stdio.h>


int main(void){
    int m,f,r;

    while(1){
        scanf("%d %d %d",&m, &f, &r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }else if(m == -1 || f == -1){
            printf("F\n");
        }else if(m + f >= 80){
            printf("A\n");
        }else if(m + f >= 65){
            printf("B\n");
        }else if(m + f >= 50 || r >= 50){
            printf("C\n");
        }else if(m + f >= 30){
            printf("D\n");
        }else{
            printf("F\n");
        }

    }

    return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
int main(void){
    int i,j,p=1,tmp,a[12]={};
    //int k;
    for(i=0;i<12;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<11;i++){
        for(j=0;j<11-i;j++){
            if(a[j]>a[j+1]){
                tmp=a[j];
                a[j]=a[j+1];
                a[j+1]=tmp;
            }
            //for(k=0;k<12;k++){
            //    printf("%d",a[k]);
            //}
            //puts("");
        }
    }
    
    for(i=0;i<3;i++){
        if(a[i]!=a[i+1])p=0;
    }
    i++;
    for(;i<7;i++){
        if(a[i]!=a[i+1])p=0;
    }
    i++;
    for(;i<11;i++){
        if(a[i]!=a[i+1])p=0;
    }
    
    if(p==1)printf("yes\n");
    else printf("no\n");
    
    return 0;
}

Measured memory_bytes: 580