akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
#define square(x) (x)*(x)
// ????????±?????£???????????¬????????????????????£???
// ??????????????°????±?????????¨????????¬????????????????±??????£?????????.
// ????????¬????????????????????£???????????????????????????????????????.


int main(){
	int n;
	cin >> n;
	vector<pair<double,double> > x(3);
	vector<double> d(3),r(3);
	pair<double,double> ans;
	double R;
	rep(j,n){
		rep(i,3){
			cin >> x[i].fi >> x[i].se;
		}
		d[0] = square(x[2].fi-x[1].fi) + square(x[2].se-x[1].se);
		d[1] = square(x[2].fi-x[0].fi) + square(x[2].se-x[0].se);
		d[2] = square(x[0].fi-x[1].fi) + square(x[0].se-x[1].se);
		r[0] = d[0]*(d[1]+d[2]-d[0]);
		r[1] = d[1]*(d[2]+d[0]-d[1]);
		r[2] = d[2]*(d[0]+d[1]-d[2]);
		R = r[0]+r[1]+r[2];
		ans.fi = (r[0]*x[0].fi+r[1]*x[1].fi+r[2]*x[2].fi)/R;
		ans.se = (r[0]*x[0].se+r[1]*x[1].se+r[2]*x[2].se)/R;
		R = square(x[0].fi-ans.fi) + square(x[0].se-ans.se);
		printf("%.3f %.3f %.3f\n",ans.fi,ans.se, sqrt(R));
	}
}

Measured memory_bytes: 3052
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,c=0,n,i;
  char s[1005];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a==b){
     c++;
      if(c>=3){
       printf("Yes");
        return 0;
      }
    }else{
     c=0; 
    }
  }
  
  printf("No");
  return 0;
}







Measured memory_bytes: 2168
#include <stdio.h>

int main(void){
    int n;
    int p[51];
    int i;
    int bad = 0;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        scanf("%d", &p[i]);
    }
    
    for(i = 1; i <= n; i++){
        if(p[i] != i){
            bad++;
        }
    }
    
    if(bad == 0 || bad == 2){
        puts("YES");
    }else{
        puts("NO");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
const long INF=1000000000000000;
const long MOD=1000000007;

int main() {
    long A,B;
    cin>>A>>B;
    if(A%3!=0 && B%3!=0 && (A+B)%3!=0) cout<<"Impossible"<<endl;
    else cout<<"Possible"<<endl;
}

Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=700;

int n,m;
double f[N],INF=1e18;
double p[N];

vector<int> g[N];
int main(){
    scanf("%d%d",&n,&m);
    FOR(i,1,m){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].pb(v);
    }
    f[n]=0;
    ROF(u,n-1,1){
        int c=g[u].size();
        double sum=0;
        for(int v:g[u]) sum+=f[v];
        f[u]=sum/c+1;
    }
    double ans=f[1];
    p[1]=1;
    FOR(u,1,n-1){
        int c=g[u].size();
        for(int v:g[u]){
            p[v]+=p[u]/c;
        }
    }
    FOR(u,1,n-1){
        int c=g[u].size();
        if(c==1)continue;
        double sum=(f[u]-1)*c;
        for(int v:g[u]){
            double e=(sum-f[v])/(c-1)+1;
            ans=min(ans,f[1]+(e-f[u])*p[u]);
        }
    }
    printf("%.10lf",ans);
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main() {
	int A, B;
	int C, D;
	cin >> A >> B >> C >> D;
	int left = A + B;
	int right = C + D;
	if (left > right) {
		cout << "Left";
	}
	else if (right > left) {
		cout << "Right";
	}
	else {
		cout << "Balanced";
	}
}

Measured memory_bytes: 256
from collections import deque

base = 10007
mod1 = int(1e9 + 7)
mod2 = int(1e9 + 9)


class RollingHash:
    def __init__(self, s):
        self.s = s
        self.len = len(s)
        self.mod1_table = [pow(base, i, mod1) for i in range(self.len + 2)]
        self.mod2_table = [pow(base, i, mod2) for i in range(self.len + 2)]
        self.inv1_table = [pow(self.mod1_table[i], mod1 - 2, mod1) for i in range(self.len + 2)]
        self.inv2_table = [pow(self.mod2_table[i], mod2 - 2, mod2) for i in range(self.len + 2)]
        self.elm_1 = [0]
        self.elm_2 = [0]
        for i in range(self.len):
            val_1 = self.elm_1[-1] + self.mod1_table[len(self.elm_1)] * ord(s[i])
            val_2 = self.elm_2[-1] + self.mod2_table[len(self.elm_2)] * ord(s[i])
            self.elm_1.append(val_1 % mod1)
            self.elm_2.append(val_2 % mod2)
    
    def get(self, l, r):
        val_1 = (self.elm_1[r] - self.elm_1[l]) * self.inv1_table[l] % mod1
        val_2 = (self.elm_2[r] - self.elm_2[l]) * self.inv2_table[l] % mod2
        return val_1, val_2


def check(s, val):
    que = deque()
    se = set()
    for i in range(s.len - val + 1):
        res = s.get(i, i + val)
        if res in se:
            return True
        que.append(res)
        if len(que) == val:
            se.add(que.popleft())
    
    return False


def main():
    n = int(input())
    s = input()
    rh = RollingHash(s)
    
    
    ok = 0
    ng = n
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(rh, mid):
            ok = mid
        else:
            ng = mid
    
    print(ok)


if __name__ == '__main__':
    main()

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

int main()
{
  string s;

  cin >> s;

  for(int i = 0;i < s.length();i++){
    if(s.at(i) == '?'){
     s.at(i) = 'D';
    }
  }
  cout << s << endl;
}

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

int main() {
  int i,j,n,t,a,min=10000000000;
  int h[1010];
  int b[1010];
  cin>>n>>t>>a;
  for(i=0;i<n;i++){
    cin>>h[i];
    b[i]=t*1000-h[i]*6-a*1000;
    if(b[i]<0){
      b[i]=b[i]*(-1);
    }
    if(min>b[i]){
      min=b[i];
      j=i;
    }
  }
  j++;
  cout<<j<<endl;
}




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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    string s;
    cin>>s;
    int n=s.size();
    // VVi dp(n+1,Vi(2,INF));
    // dp[0][0]=0;
    // dp[0][1]=2;

    // REP(i,0,n){
    //     if(s[i]=='0'){
    //         dp[i+1][0]=dp[i][0];
    //         dp[i+1][1]=dp[i][1];
    //         continue;
    //     }
    //     chmin(dp[i+1][0],dp[i][0]+ctoi(s[i]));
    //     chmin(dp[i+1][0],dp[i][1]+ctoi(s[i]));
    //     chmin(dp[i+1][1],dp[i][1]+(10-ctoi(s[i]))-1);
    //     chmin(dp[i+1][1],dp[i][0]+ctoi(s[i])+2);
    //     chmin(dp[i+1][1],dp[i][1]+ctoi(s[i])+2);
    // }
    // vvout(dp);

    while(s[s.size()-1]=='0'){
        s.pop_back();
    }
    reverse(ALL(s));
    n=s.size();
    VVi dp(n,Vi(2,INF));
    dp[0][0]=ctoi(s[0]);
    dp[0][1]=11-ctoi(s[0]);
    REP(i,1,n){
        // if(s[i]=='0'){
        //     dp[i][0]=dp[i-1][0];
        //     dp[i][1]=dp[i-1][1];
        //     continue;
        // }
        chmin(dp[i][0],dp[i-1][0]+ctoi(s[i]));
        if(s[i]!='9') chmin(dp[i][0],dp[i-1][1]+ctoi(s[i]));
        chmin(dp[i][1],dp[i-1][0]+11-ctoi(s[i]));
        chmin(dp[i][1],dp[i-1][1]+9-ctoi(s[i]));
    }
//   vvout(dp);
//    cout<<dp[n-1][0]<<" "<<dp[n-1][1]<<endl;
     cout<<min(dp[n-1][0],dp[n-1][1])<<endl;
    return 0;
}


Measured memory_bytes: 55940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N, sum;
    cin >> N;
    for(int i=0;i<=25;i++){
        for(int j=0;j<=14;j++){
            sum = 4*i +7*j;
            if(N==sum){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
N = int(input())
S, T = map(str, input().split())

S = list(S)
T = list(T)
ANS = []

for i in range(N):
    ANS.append(S[i])
    ANS.append(T[i])
    
ANS = ''.join(ANS) 
    
    
print(ANS)

Measured memory_bytes: 61700
N, A, B = map(int, input().split())

def solve2 (N, A, B):
    return A + (B - A - 1) // 2
    

def solve (N, A, B):
    if A == B:
        return 0
    diff = abs(A - B)
    if diff % 2 == 0:
        return diff // 2
    

    ans1 = solve2(N, A, B)
    ans2 = solve2(N, N - A + 1, N - B + 1)
    return min(ans1, ans2)

print(solve(N, A, B))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pi pair<int,int>
#define mk make_pair
#define f(i,n) for(int i=1;i<=n;i++)
#define fo(i,a,n) for(int i=a;i<n;i++)
#define fr(i,a,n) for(int i=a;i>=n;i--)
#define ll long long
#define li long
#define N 1000000
using namespace std;

vector<li> adj(3005);
ll dp[3002][3002][2];

ll dq(int l , int r,int ind)
{
    if(l>r)
        return 0;
    if(dp[l][r][ind]==-1)
    {
        if(ind==0)
        {
            ll left=adj[l]+dq(l+1,r,1);
            ll right=adj[r]+dq(l,r-1,1);
            dp[l][r][ind]=max(left,right);
        }
        else
        {
            ll left=dq(l+1,r,0)-adj[l];
            ll right=dq(l,r-1,0)-adj[r];
            dp[l][r][ind]=min(left,right);
        }
    }
    return dp[l][r][ind];

}



int main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    cin>>n;
    f(i,n)
        cin>>adj[i];
    ll ans=dq(1,n,0);
    cout<<ans;

}


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

int a[2000002] = {};
int b[2000002] = {};
int cnt[10002] = {};

int main(){

  int n;

  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    cnt[a[i]]++;
  }
  for(int i = 1; i <= 10000; i++) cnt[i] += cnt[i-1];
  for(int i = 1; i <= n; i++) b[cnt[a[i]]--] = a[i];
  for(int i = 1; i <= n; i++){
    cout << b[i] << (i != n ? " " : "\n");
  }
  return 0;
}


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

int main()
{
    ll n , w , t;
    cin >> n >> w >> t;
    ll ara[n+10] ;
    for(int i=1; i<=n; i++)
    {
        cin >> ara[i] ;
    }
    ll sum = 0;
    for(int i=2; i<=n; i++)
    {
        ll dis = ara[i] - ara[i-1] ;
        sum += min(dis*w,t);
    }
    cout << sum << endl;
}


Measured memory_bytes: 4272
import fractions

N, X = [int(n) for n in input().split()]
x = sorted([abs(int(n) - X) for n in input().split()])

if len(x) > 1:
  gcd = fractions.gcd(x[0], x[1])
  for i in x:
    gcd = fractions.gcd(gcd, i)
else:
  gcd = x[0]
print(gcd)

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

using namespace std;

int main(){
  int q,a,b;
  string str,order,s;

  cin >> str >> q;
  while(q--){
    cin >> order >> a >> b;
    if(order == "replace"){
      cin >> s;
      for(int i = a ; i <= b ; i++){
        str[i] = s[i-a];
      }
    }else if(order == "reverse"){
      int p = b;
      string tmp = str;
      for(int i = a ; i <= b ; i++){
        tmp[i] = str[p--];
      }
      str = tmp;
    }else{
      for(int i = a ; i <= b ; i++){
        cout << str[i];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1216
N = int(input())
S = input()

i = 0
j = 1
res = 0
while j < N:
    sub = S[i:j]
    main = S[j:]
    if sub in main:
        j += 1
        res = max(res, len(sub))
    else:
        i += 1
    if i == j:
        i += 1
        j += 2
print(res)

Measured memory_bytes: 3188
#include<iostream>
 
using namespace std;
 
int main(){
    int n,i,k;
    long long all,count = 0;
    cin>>n;
    long long a[n+1],num[n+1] = {0};
    for(i=1;i<=n;i++){
        cin>>a[i];
        num[a[i]]++;
    }
    for(i=1;i<=n;i++){
        if(num[i]>1) count += num[i]*(num[i]-1)/2;
    }
    all = count;
    for(k=1;k<=n;k++){
        count = all;
        count -= num[a[k]] - 1;
        cout<<count<<endl;
    }
}

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

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

    int n;
    cin>>n;
    long long ans = 0;
    for (int i=1; i<=n; i++){
        for (int j=i; j<=n; j+=i){
            ans += j;
        }
    }
    cout<<ans<<endl;
    return 0 ;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    int a, b;
    cin>>a>>b;
    int c=a+b;
    if(c>=10)cout<<"error"<<endl;
    else cout<<c<<endl;
}


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

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

int main(void){
    string s;
    cin >> s;
    ll ans, cnt = 1;
    while(1){
        string s1="", s2="";
        if( (s.length()-cnt) %2==0){
            for(int i=0;i<(s.length()-cnt)/2;i++){
                s1 += s[i];
            }
            for(int i=(s.length()-cnt)/2;i<s.length()-cnt;i++){
                s2 += s[i];
            }
            if(s1 == s2){
                ans = s.length()-cnt;
                break;
            }
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a;
  a.push_back(3);
  a.push_back(5);
  a.push_back(7);
  queue<int>q;
  q.push(5);q.push(7);
  int i=3;
  while(i<1e8){
    int x=i*10+3;
    int y=i*10+5;
    int z=i*10+7;
    a.push_back(x);
    a.push_back(y);
    a.push_back(z);
    q.push(x);q.push(y);q.push(z);
    i=q.front();
    q.pop();
  }
  int ans=0;
  
  rep(i,a.size()){
    if(a.at(i)<=n){
      string s=to_string(a.at(i));
      bool ex=true;
      vector<bool>d(3);
      rep(k,s.size()){
        if(s.at(k)=='3'){
          d.at(0)=true;
        }
        if(s.at(k)=='5'){
          d.at(1)=true;
        }
        if(s.at(k)=='7'){
          d.at(2)=true;
        }
      }
      rep(l,3){
        if(!d.at(l)){
          ex=false;
        }
      }
      if(ex){
        ans++;
      }
    }
    else{
      break;
    }
  } 
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

#include <algorithm>
#include <cmath>
#include <functional>

#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <list>

#define ll long long int

using namespace std;

int main(int argc, char const* argv[]) {

    vector<int> times(5);

    bool flag = true;

    int min_margin = 9;
    int ans = 0;

    for (int i = 0; i != 5; ++i) {
        cin >> times[i];
    }

    for (int i = 0; i != 5; ++i) {
        int margin = times[i] % 10;
        if (margin != 0) {
            flag = false;
            if (margin < min_margin) {
                min_margin = margin;
            }
        }
    }
    if (flag) {
        for (int i = 0; i != 5; ++i) {
            ans += times[i];
        }
    } else {
        for (int i = 0; i != 5; ++i) {
            if (times[i] % 10 == 0) {
                ans += times[i];
            } else {
                ans += (times[i] / 10) * 10;
                ans += 10;
            }

        }
        ans += min_margin - 10;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k=0,s,sa,sb;
	cin>>n>>m;
	s=n;
	int a[m],b[m]={};
	for(int i=0;i<m;i++){
		cin>>a[i]>>sb;
		if(s>a[i]){
			s=a[i];
			sa=i;
		}
		if(n>a[i]){
			b[i]=n-a[i];
			k+=b[i];
		}
	}
	cout<<k-b[sa]<<endl;
}


Measured memory_bytes: 3092
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

int a,b,c,x,y;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> a>>b>> c >> x >> y;
	if(2*c >= a+b) {
		cout << a*x+b*y << endl;
	} else {
		if (x < y) {
			cout << x*2*c+(y-x)*min(b,2*c) << endl;
		} else if(x==y) {
			cout << x*2*c << endl;
		} else {
			cout << y*2*c+(x-y)*min(a,2*c) << endl;
		}
	}
}

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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

double pi = acos(-1);

double toRadian(double degree){
    return (pi / 180 ) * degree;
}

void solve() {
    double a , b , h , m;
    cin>>a>>b>>h>>m;
    double h1 = toRadian(30 * h + 0.5 * m);
    double m1 = toRadian(6 * m);
    double x1 = a * sin(h1) , y1 = a * cos(h1);
    double x2 = b * sin(m1) , y2 = b * cos(m1);
    double t = (sqrtl(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1- y2)));
    printf("%0.9f" , t);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	int n;
	cin >> n;
	vector<vi> gr(n);
	rep(i,1,n){
		int a,b;
		cin >> a >> b;
		gr[a-1].push_back(b-1);
		gr[b-1].push_back(a-1);
	}
	vi d1(n), d2(n);
	function<void(int,int,vi&)> dfs = [&](int v, int par, vi &d){
		trav(u, gr[v]) if(u != par){
			d[u] = d[v] + 1;
			dfs(u,v,d);
		}
	};
	dfs(0,-1,d1);
	dfs(n-1,-1,d2);
	int dif = 0;
	rep(i,0,n){
		if(d2[i]<d1[i]) ++dif;
		else --dif;
	}
	if(dif >= 0) puts("Snuke");
	else puts("Fennec");
}

Measured memory_bytes: 15872
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

long long const MOD = 1000000007;
long long const MAX = 100005;
long long mod_m(long long x, long long y) {
	return x * y % MOD;
}
long long mod_p(long long x, long long y) {
	return (x + y) % MOD;
}

//ax+by = (gcd of x and y)となるようにa,bを変更する
long long extgcd(long long x, long long y, long long &a, long long &b) {
	if (y == 0) {
		a = 1; b = 0;
		return x;
	}
	else {
		long long q = x / y; long long r = x % y;
		long long s;
		long long d = extgcd(y, r, s, a);
		b = s - a * q;
		return d;
	}
}

long long mod_inverse(long long x) {
	x %= MOD;
	long long a, b;
	a = b = 0;
	if (extgcd(x, MOD, a, b) != 1) {
		return -1;
	}
	else {
		return (MOD + a % MOD) % MOD;
	}
}

long long mod_fact[MAX];
long long mod_inv_fact[MAX];

void prep_fact(long long n) {
	mod_fact[0] = 1;
	for (long long i = 1; i <= n; i++) {
		mod_fact[i] = (mod_fact[i - 1] * i) % MOD;
	}
}
void prep_inv(long long n) {
	for (long long i = 0; i <= n; i++) {
		mod_inv_fact[i] = mod_inverse(mod_fact[i]);
	}
}

long long nCr(long long n, long long r) {
	if (r > n || r < 0) {
		return 0;
	}
	return (((mod_fact[n] * mod_inv_fact[r]) % MOD)*mod_inv_fact[n - r]) % MOD;
}

ll pos[MAX];

int main() {
	prep_fact(MAX - 1);
	prep_inv(MAX - 1);
	ll n;
	cin >> n;
	REP(i, 1, n) {
		pos[i] = -1;
	}
	ll v1, v2;
	REP(i, 1, n + 1) {
		ll t;
		cin >> t;
		if (pos[t] == -1) { pos[t] = i; }
		else {
			v1 = pos[t];
			v2 = i;
		}
	}
	ll p, q, r;
	p = v1 - 1;
	q = v2 - v1 - 1;
	r = n - v2 + 1;
	REP(k, 1, n + 1) {
		ll ans = nCr(n + 1, k);
		ll doub = nCr(p + r, k - 1);
		ans = (ans - doub + MOD) % MOD;
		cout << ans << endl;
	}
}

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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
// Template END

int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}

const int mxn = (int)1e5 ;
signed main(){
    int n ; cin >> n ;
    int sum = 0, x ;
    vector<int> cnt( mxn + 1, 0 ) ;
    for( int i = 0 ; i < n ; i++ ) {
        cin >> x ;
        sum += x ;
        cnt[x]++ ;
    }
    int q, l, r ;
    cin >> q ;
    for( int i = 0 ; i < q ; i++ ){
        cin >> l >> r ;
        int f = cnt[l] ;
        cnt[l] = 0 ;
        cnt[r] += f ;
        sum -= f * l ;
        sum += f * r ;
        cout << sum << endl ;
    }
    return 0 ;   
}          

Measured memory_bytes: 4044
main = do
    [n,y] <- map read . words <$> getLine
    let (a,b,c) = head $ [(a,b,rest) |
                            a <- [0..n],
                            b <- [0..n-a],
                            let rest = n-a-b,
                            rest >= 0,
                            10000*a+5000*b+1000*rest==y] ++ [(-1,-1,-1)]
    putStr $ show a ++ " "
    putStr $ show b ++ " "
    putStrLn $ show c 

Measured memory_bytes: 892
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    n_odd, n_even = 0, 0
    for c in counter.values():
        if c % 2 == 0:
            n_even += 1
        else:
            n_odd += 1
    print(n_odd + (n_even // 2) * 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18656
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  vi v(3);
  rep(i, 3) cin >> v[i];
  sort(all(v));

  int ans = v[0]*v[1] / 2;
  pr(ans);

  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++)

int main() {
  int n;cin>>n;
  vector<long> an(n);
  rep(i,n) cin>>an[i];
  sort(an.begin(), an.end());
  reverse(an.begin(), an.end());
  
  long a=0,b=0;
  rep(i,n-1) {
    if (an[i]==an[i+1]) {
      if (a==0) {
        a=an[i];
        i++;
      } else if (b==0) {
        b=an[i];
        long s=a*b;
        cout << s;
        return 0;
      }
    }
  }
  long s=a*b;
  cout << s;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;cin>>s;
    if(s[1]=='B')cout<<"ARC";
    else cout<<"ABC";
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e3 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		int K = in.nextInt();
		long dp[] = new long[K + 1];
		dp[0] = 1;
		for (int i = 0; i < N; i++) {
			int upto = in.nextInt();
			long sum[] = new long[K + 1];
			for (int used = K; used >= 0; used--) {
				long temp = dp[used];
				int L = used + 1;
				int R = used + Math.min(upto, K - used);
				if (L <= R) {
					sum[L] += temp;
					if (sum[L] >= mod) {
						sum[L] -= mod;
					}
					if (R + 1 <= K) {
						sum[R + 1] -= temp;
						if (sum[R + 1] < 0) {
							sum[R + 1] += mod;
						}
					}
				}
			}
			long pref = 0;
			for (int j = 0; j <= K; j++) {
				pref += sum[j];
				if (pref >= mod) {
					pref -= mod;
				}
				dp[j] += pref;
				if (dp[j] >= mod) {
					dp[j] -= mod;
				}
			}

		}
		pw.println(dp[K]);

//		for (int i = 0; i < N; i++) {
//			pw.println(Arrays.toString(dp[i]));
//		}
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 44552
using System;

namespace PrintRectangle
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			while (true) {
				string[] tmp = Console.ReadLine ().Split (" ".ToCharArray ());
				int height, Wide;

				height = int.Parse (tmp [0]);
				Wide = int.Parse (tmp [1]);
				if (height == 0 && Wide == 0)
					break;

				for (int i = 1; i <= height; i++) {
					for (int j = 1; j <= Wide; j++) {
						Console.Write ((i == 1 || i == height ||j == 1||j==Wide)? "#":".");
					}
					Console.Write ("\n");
				}
				Console.Write ("\n");
			}
		}
	}
}

Measured memory_bytes: 5276
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
li = []
ans = []
Min_sa = 9999999999
for i in range(-200,201):
    if i not in p:
        li.append(i)
for i in li:
     Min_sa = min(Min_sa,abs(x-i))
for i in li:
    if abs(x-i) == Min_sa:
        ans.append(i)
print(min(ans))

Measured memory_bytes: 62068
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> x;
	for(int i=0;i!=n;++i){
		int temp;
		cin>>temp;
		x.push_back(temp);
	}
	if(n&1){
		for(int i=n-1;i>=0;i-=2)
			cout<<x[i]<<' ';
		for(int i=1;i<=n-2;i+=2)
			cout<<x[i]<<' ';
	}
	else{
		for(int i=n-1;i>=1;i-=2)
			cout<<x[i]<<' ';
		for(int i=0;i<=n-2;i+=2)
			cout<<x[i]<<' ';
	}
}



Measured memory_bytes: 3060
package main 

import (
        "fmt"
)

func main () {
        var a, b, c, d  int
        z := 0
        
        fmt.Scan(&a, &b)

        for i :=0 ; i < a ; i++{
                fmt.Scan(&c, &d)
                if  d <= b {
                        if z == 0 {
                                z = c
                        } else if c  < z   {
                                z = c
                        }
                }
        }

        if z == 0{
                fmt.Println("TLE")
        } else if z != 0{
                fmt.Println(z)
        }
}


Measured memory_bytes: 512
/*input
2
*/


// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

#define fast_cin() ios_base::sync_with_stdio(false)
#define pb push_back
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug1(x) cerr << x << endl;
#define debug2(x,y) cerr << x << " " << y << endl;
#define debug3(x,y,z) cerr << x << " " << y << " " << z << endl;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define FORR(i, a, b) for (ll i=a; i>=(b); i--)
ll INF = 2000000000000000001;
double EPS = 1e-9;
ll nextll(){ll inp; cin>>inp; return inp;}
string nextStr(){string inp; cin>>inp; return inp;}
double nextDouble(){double inp; cin>>inp; return inp;}
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int k;
	cin>>k;
	int ans=0;
	FOR(i,1,k+1) ans+=ceil((double)(k-i)/(double)2);
	cout<<ans<<endl;
	return 0;
}

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

// #define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vin(v,n) copy_n(istream_iterator<int>(cin),n,back_inserter(v));
#define all(v) v.begin(),v.end()
#define INF 2000000000
#define MOD 1000000007
#define ll long long 
#define vi vector<int>
#define ii pair<int,int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define f1(i,a,b) for(int i = a;i<b;i++)
#define f2(i,a,b) for(int i = a;i<=b;i++)

using namespace std;

int32_t main() 
{
	IOS;
   int n, m;
   cin >> n >> m;
   vector<vector<char> > grid(n+1, vector<char>(m+1, '#'));

   f2(i,1,n)
      f2(j,1,m)
         cin >> grid[i][j];
      
	vector<vi> dp(n+1, vi(m+1, 0));
   f2(j,1,m)
   {
      if(grid[1][j]!='#')
         dp[1][j] = 1;
      else
         break;
      
   }

   f2(i,1,n)
   {
      if(grid[i][1]!='#')
         dp[i][1] = 1;
      else 
         break;
   }

   f2(i,2,n)
      f2(j,2,m)
         if(grid[i][j]=='#')
            dp[i][j] = 0;
         else
            dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;

   cout << dp[n][m]; 
}


Measured memory_bytes: 5248
#include <iostream>
#include <math.h>

using namespace std;

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

        if (n == 0) break;

        double m = 0;
        int s[n];
        for (int i = 0; i < n; i++) {
            cin >> s[i];
            m += s[i];
        }
        m /= n;

        double a = 0;
        for (int i = 0; i < n; i++) {
            a += pow(s[i] - m, 2);
        }
        a /= n;
        
        cout << fixed << sqrt(a) << endl;
    }
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main(){
    int N; cin >> N;
    double ans = 0;
    for(int i=0; i<N; i++){
        double x; cin >> x;
        string u; cin >> u;
        if(u=="BTC") ans += x*380000;
        else ans += x;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
public class A{
  public static void Main(string[] args){
    string[] inputs = Console.ReadLine().Split(' ');
    var num1 = int.Parse(inputs[0]);
    var num2 = int.Parse(inputs[1]);
    Console.WriteLine(num1 % num2 == 0 ? "0" : "1");
    Console.ReadLine();
  }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef struct RMQandRAQ {
  i64 *add;
  i64 *max;
  i32 bit;
  i32 size;
} RMQandRAQ;

RMQandRAQ* new_RMQandRAQ (const i32 n) {
  i32 k = 0;
  while ((1 << k) < n) ++k;
  RMQandRAQ *s = (RMQandRAQ *) calloc (1, sizeof (RMQandRAQ));
  s->add = (i64 *) calloc (2 << k, sizeof (i64));
  s->max = (i64 *) calloc (2 << k, sizeof (i64));
  s->bit = k;
  s->size = 1 << k;
  return s;
}

static inline i64 max (i64 a, i64 b) {
  return a > b ? a : b;
}

static inline i64 eval (RMQandRAQ *s, i32 k) {
  return s->add[k] + s->max[k];
}

void propagate (RMQandRAQ *s, i32 x) {
  x += s->size;
  for (i32 bit = s->bit; bit > 0; bit--) {
    i32 k = x >> bit;
    s->add[2 * k] += s->add[k];
    s->add[2 * k + 1] += s->add[k];
    s->add[k] = 0;
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void save (RMQandRAQ *s, i32 x) {
  for (i32 k = (x + s->size) >> 1; k >= 1; k >>= 1) {
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void add (RMQandRAQ *s, i32 l, i32 r, i64 v) {
  for (i32 x = l + s->size, y = r + s->size; x < y; x >>= 1, y >>= 1) {
    if (x & 1) s->add[x++] += v;
    if (y & 1) s->add[--y] += v;
  }
  save (s, l);
  save (s, r - 1);
}

i64 find (RMQandRAQ *s, i32 l, i32 r) {
  //propagate (s, l);
  //propagate (s, r - 1);
  i64 ans = 0;
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max (ans, eval (s, l++));
    if (r & 1) ans = max (ans, eval (s, --r));
  }
  return ans;
}

typedef struct node {
  i32 l, v, next;
} node;

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  node *a = (node *) calloc (m + 1, sizeof (node));
  i32 *start = (i32 *) calloc (n + 1, sizeof (node));
  for (i32 i = 1; i <= m; ++i) {
    i32 l = read_int();
    i32 r = read_int();
    i32 v = read_int();
    a[i] = (node) {l, v, start[r]};
    start[r] = i;
  }
  RMQandRAQ *s = new_RMQandRAQ (n + 1);
  for (i32 i = 1; i <= n; ++i) {
    i64 v = find (s, 0, i);
    add (s, i, i + 1, v);
    for (i32 p = start[i]; p; p = a[p].next) {
      add (s, a[p].l, i + 1, a[p].v);
    }
  }
  print_int (find (s, 0, n + 1));
  putchar ('\n');
}

int main (void) {
  run();
  return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;

int N;
vi arr;

ll calc(bool isPos) {
    int curSum = 0;
    ll curMoves = 0;
    F0R(i, N) {
        if (isPos) {
            curMoves += (arr[i] > -curSum) ? 0 : 1 - curSum - arr[i];
            curSum = (arr[i] > -curSum) ? (curSum + arr[i]) : 1; 
        } else {
            curMoves += (-arr[i] > curSum) ? 0 : curSum + 1 + arr[i];
            curSum = (-arr[i] > curSum) ? (curSum + arr[i]) : -1;
        }
        isPos = !isPos;
    }
    return curMoves;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N; arr.resize(N);
    F0R(i, N) cin >> arr[i];
    cout << min(calc(true), calc(false)) << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int h,s,m,S,p,q;
    scanf("%d",&S);
    h=S/3600;
    p=S%3600;
    m=p/60;
    q=p%60;
    s=q;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2040
def examB(mod):
    N = I(); C = [I() for _ in range(N)]
    dp = [0]*(N); dp[0] = 1
    cur = [0]*(max(C)+1); cur[C[0]] =1
    for i in range(1,N):
        if C[i]==C[i-1]:
            dp[i] = dp[i-1]
        else:
            dp[i] = cur[C[i]] + dp[i-1]
            dp[i] %=mod
            cur[C[i]] = dp[i]
#    print(dp)
    ans = dp[-1]%mod
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB(mod)


Measured memory_bytes: 54492
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int X,N;
  cin >> X >> N;
  if(N!=0){
  std::vector<int> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
  }
  std::vector<int> w;
  w.push_back(0);

  for(int i=1;i<101;i++){
    bool check = false;
    for(int j=0;j<N;j++){
      if(v.at(j)==i){
        check = true;
        break;
      }
    }
    if(!check){
      w.push_back(i);
    }
  }
    w.push_back(101);

  int left=0;
  int right=w.size()-1;
  int mid;
  bool kak =false;

  for(int k=0;k<9;k++){
    mid=(left+right)/2;
    if(X==w.at(mid)){kak = true;break;}
    if(X>w.at(mid))left=mid;
    else if(X<w.at(mid))right=mid;
  }

  if(kak){
    cout << X << endl;
  }else if(abs(w.at(left)-X)<=abs(w.at(right)-X)){
    cout << w.at(left) << endl;
  }else{
    cout << w.at(right) << endl;
  }
  
  }else{
    cout << X << endl;
  }



}




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

i=1
cnt = 0 
while(i<=n):
	if i < 10 or (i >= 100 and i < 1000) or (i>=10000 and i<100000) :
		cnt+=1
		i+=1
	elif n == 100000:
		cnt  = 90909
		break
	elif len(str(i)) > 1:
		if i < 100:
			i = 100

		elif i >999 and i< 10000:
			i = 10000
	
print(cnt)



Measured memory_bytes: 38640
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;

void solve(){
	int n ;
	cin >> n ;
	for(int i = 1 ; i <= 9 ; i++){
		if(n%i == 0){
			int v = n/i ;
			if(v > 0 && v < 10){
				cout << "Yes\n" ;
				return ;
			}
		}
	}
	cout << "No" << endl ;
}

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

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll A, B;
   char op;
   cin >> A >> op >> B;
   if (op == '+') cout << A + B << endl;
   else cout << A - B << endl;
   return 0;
}


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

void dfs(int vertex, unordered_map<int, vector<int>> &m, vector<bool>& visited, vector<int>& count, int hop){
    if(visited[vertex]) return ;
    visited[vertex] = true;
    count[vertex] = min(hop, count[vertex]);
    if(vertex == 1) return;
    for(int i=0;i<m[vertex].size();i++){
        if(!visited[m[vertex][i]]){
            dfs(m[vertex][i], m, visited, count, hop+1);
        }
    }
    return ;
}

int main(){
    int n;
    cin>>n;
    vector<int> arr(n,0);
    for(int i=0;i<n;i++)cin>>arr[i];

    unordered_map<int, vector<int>> m;
    for(int i=0;i<n;i++){
        m[i].push_back(arr[i]-1);
    }
    vector<bool> visited(n,false);
    vector<int> count(n,INT_MAX);
    dfs(0, m, visited, count, 0);
    if(visited[1]) cout<<count[1]<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 20536
#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n][3];
    for (int i=0; i<n; i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    int dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for (int i=1; i<n; i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
    }
    int ans=max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    cout<<ans<<endl;
}

Measured memory_bytes: 2560