akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main(){
    std::string s;
    std::cin >> s;
    
    char num[4];
    num[0]=s[0];
    int temp=0;
    for(int i=1;i<s.size();i++){
        if(num[0]!=s[i]){
            num[1]=s[i];
            temp=i;
            break;
        }
    }
    int sum0=1;
    for(int i=1;i<s.size();i++){
        if(num[0]==s[i]){
            sum0++;
        }
    }
    int sum1=1;
    for(int i=0;i<s.size();i++){
        if(num[1]==s[i]){
            sum1++;
        }
        if(i==temp-1){
            i++;
        }
    }
    
    if(sum0==2&&sum1==2){
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();
    let mut ans = 0;
    for i in 1..n+1 {
        let mut v = i;
        let mut sum = 0;
        while v > 0 {
            sum += v % 10;
            v /= 10;
        }
        if a <= sum && sum <= b { ans += i; }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 2e5 + 111;
        
using namespace std;          

int n, a[maxn];
map <int, int> ma1, ma2;

void solve(){
	cin >> n;

	for (int i = 1; i <= n; i++){
		cin >> a[i];
		ma1[a[i] + i]++;
		ma2[i - a[i]]++;
	}

	int ans = 0;

	for (int i = 1; i <= n; i++){
		//cout << ma2[a[i] + i] << " " << ma1[i - a[i]] << endl;
		ans += ma1[i - a[i]] + ma2[a[i] + i];
		ma1[a[i] + i]--;
		ma2[i - a[i]]--;
	}

	cout << ans;
}   
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;

    //cin >> q;

    while (q--){
        solve();
    }
}

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

#define F first
#define S second
#define ll long long
#define pb push_back
#define ld long double
#define map mp

using namespace std ;

const int MAXN = 555 ;

int cntx[MAXN] , cnty[MAXN] , cnt ;

bool map[MAXN][MAXN] ;



int32_t main()
{
	ios::sync_with_stdio(0) ; cin.tie(0) ;
	int n ;
	cin >> n ;
	for(int i = 0 ; i < n ; i ++ ) for(int j = 0 ; j < n ; j ++ )
	{
		char ch ;
		cin >> ch ;
		map[i][j] = (ch=='#'?1:0) ;
		cntx[i] += map[i][j] ;
		cnty[j] += map[i][j] ;
		cnt += map[i][j] ;
	}
	if(!cnt) return cout << -1 << '\n' , 0 ;
	if(cnt==n*n) return cout << 0 << '\n' , 0 ;
	int N = n ;
	for(int i = 0 ; i < n ; i ++ )
		N -= (cnty[i]==n) ;
	int mn = n ;
	for(int i = 0 ; i < n ; i ++ )
	{
		if(cnty[i]) mn = min(mn,n-cntx[i]) ;
	}
	for(int i = 0 ; i < n ; i ++ ) 
	{
		if(cntx[i]) mn = min(mn,n-cntx[i]+1) ; 
	}
	cout << mn + N << '\n' ;
}

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

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

using ll = long long;
using namespace std;

int main(){
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n){ cin >> a[i]; b[i] = a[i]; }
    sort(all(b));
    ll count = 0;
    rep(i,n){
        ll k = lower_bound(all(b),a[i]) - b.begin();
        if((k-i)%2 != 0) count++;
    }
    cout << count/2 << endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int ,int> P;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

int main(){
	ll n,m;
	cin>>n>>m;
	if(2*n>=m) cout<<m/2<<endl;
	else cout<<n+(m-2*n)/4<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    ll sum=0;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    sort(all(a));
    if(n%2){
        if(sum%2){
            cout<<"First"<<endl;
        }else{
            cout<<"Second"<<endl;
        }
    }else{
        if(a[0]%2)cout<<"First"<<endl;
        else if(sum%2)cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    }
}


Measured memory_bytes: 4356
h, n = gets.split.map(&:to_i)
ab = n.times.map{gets.chomp.split(" ").map(&:to_i)}.sort_by{|a,b|a}.reverse
dp = Array.new(h+1, 0)


(0..h+1).each do |j|
	dp[j] = ab.map{|m|
		if m[0] >= j
			m[1]
		else
			dp[j - m[0]] + m[1]
		end
    }.min
end

puts dp[h]

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

before = sum(A)

for  n in range(N):
    t = min(A[n],B[n])
    A[n] -= t
    B[n] -= t
    A[n+1] -= min(A[n+1],B[n])
    
after = sum(A)
print(before-after)


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

map<char, long long> memo;

int main(){
	string S;
	cin >> S;
	for(int i = 0; i < S.size(); i++){
		memo[S[i]]++;
	}

	long long ans =  S.size() * (S.size() - 1)/2 + 1;

	for(auto me: memo){
		ans -=  me.second * (me.second - 1)/2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;


int main(){

    int n,q;
    cin >> n >> q;

    queue<int> num_que;
    queue<string> str_que;

    int num;
    string str;

    for(int i=0; i<n; i++){
        cin >> str >> num;
        num_que.push(num);
        str_que.push(str);
    }

    int totalTime = 0;

    while(!num_que.empty()){
        str = str_que.front();
        num = num_que.front();
        if(num>q){
            num = num - q;
            num_que.pop();
            str_que.pop();
            num_que.push(num);
            str_que.push(str);
            totalTime += q;
        }else{
            totalTime += num;
            cout << str_que.front() << " " << totalTime << endl;
            str_que.pop();
            num_que.pop();
        }
    }


    return 0;
}



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

int N;
int r[60],t[60];

bool flagr[60],flagt[60];//true????????????

int ansa[60],ansb[60],ansc[60],ansd[60];

int main(){

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

	for(int i=0;i<N;i++){
		flagr[i]=false;
		flagt[i]=false;
	}

	for(int i=0;i<N;i++){
		if(r[i]%100==0){
			flagr[i]=true;
		}
		if(t[i]%30==0){
			flagt[i]=true;
		}
	}

	for(int i=0;i<N;i++){
		if(flagr[i]&&flagt[i]){
			ansa[i]=(r[i]/100)+((t[i]/30)*5);
		}
		if(flagr[i]&&!flagt[i]){
			ansa[i]=(r[i]/100)+(((t[i]-(t[i]%30))/30)*5);
			ansb[i]=ansa[i]+5;
		}
		if(!flagr[i]&&flagt[i]){
			ansa[i]=((r[i]-(r[i]%100))/100)+((t[i]/30)*5);
			ansb[i]=ansa[i]+1;
		}
		if(!flagr[i]&&!flagt[i]){
			ansa[i]=((r[i]-(r[i]%100))/100)+(((t[i]-(t[i]%30))/30)*5);
			ansb[i]=ansa[i]+1;
			ansc[i]=ansa[i]+5;
			ansd[i]=ansa[i]+6;
		}
	}

	for(int i=0;i<N;i++){
		if(flagr[i]&&flagt[i]){
			cout<<ansa[i]<<"\n";
		}
		if((flagr[i]&&!flagt[i])||(!flagr[i]&&flagt[i])){
			cout<<ansa[i]<<" "<<ansb[i]<<"\n";
		}
		if(!flagr[i]&&!flagt[i]){
			cout<<ansa[i]<<" "<<ansb[i]<<" "<<ansc[i]<<" "<<ansd[i]<<"\n";
		}
	}

}

Measured memory_bytes: 3036
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 100010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int x[maxn],y[maxn];
struct edge{
	int to,nxt;
}e[2*maxn];
int fir[maxn];
int n,m,tot;
inline void add_edge(int x,int y){e[tot].to=y; e[tot].nxt=fir[x]; fir[x]=tot++;}
int dfs(int now,int fa,int dep)
{
	int cur=(dep>m/2);
	for(int i=fir[now];~i;i=e[i].nxt)
		if(e[i].to!=fa)cur+=dfs(e[i].to,now,dep+1);
	return cur;
}
int main()
{
	n=read(); m=read();
	memset(fir,255,sizeof(fir)); tot=0;
	for(int i=1;i<n;i++){
		x[i]=read(); y[i]=read();
		add_edge(x[i],y[i]); add_edge(y[i],x[i]);
	}
	int ans=inf;
	if(m&1){
		for(int i=1;i<n;i++)
			ans=std::min(ans,dfs(x[i],y[i],0)+dfs(y[i],x[i],0));
	}
	else{
		for(int i=1;i<=n;i++)
			ans=std::min(ans,dfs(i,-1,0));
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
#define mod 1000000007
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    int a[M];
    vector<int> dp(N+1,0);
    for(int i=0;i<M;i++){
        cin >> a[i];
        dp[a[i]] = -1;
    }
    int count = 1;
    for(int i=0;i<=N;i++){
        if(dp[i]!=-1){
            dp[i] += count;
            count++;
            if(count==2){
                break;
            }
        }
    }
    for(int i=0;i<=N;i++){
        if(dp[i]!=-1){
            if(dp[i-1]!=-1 && i-1 >= 0){
                dp[i] = (dp[i] + dp[i-1])%mod;
            }
            if(dp[i-2]!=-1 && i-2 >= 0){
                dp[i] = (dp[i] + dp[i-2])%mod;
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
<?php
  function to_d($e) {
    return (double)$e;
  }
  $n = fgets(STDIN);
  for($i=0; $i<(double)$n; $i++) {
    $line = fgets(STDIN);
    $a = explode(" ", $line);
    $a = array_map("to_d", $a);
    $a1 = 2*($a[2]-$a[0]);
    $a2 = 2*($a[4]-$a[0]);
    $b1 = 2*($a[3]-$a[1]);
    $b2 = 2*($a[5]-$a[1]);
    $c1 = $a[0]*$a[0]-$a[2]*$a[2]+$a[1]*$a[1]-$a[3]*$a[3];
    $c2 = $a[0]*$a[0]-$a[4]*$a[4]+$a[1]*$a[1]-$a[5]*$a[5];
    $xp = ($b1*$c2-$b2*$c1)/($a1*$b2-$a2*$b1);
    $yp = ($c1*$a2-$c2*$a1)/($a1*$b2-$a2*$b1);
    $r  = sqrt(($xp-$a[0])*($xp-$a[0])+($yp-$a[1])*($yp-$a[1]));
    printf("%.3f %.3f %.3f\n", $xp, $yp, $r);
  }

Measured memory_bytes: 15432
#include <cstdio>

using namespace std;

int main()
{
    while( 1 )
    {
        int n, a, more_than_2 = 0, not_zero = 0;
        scanf( "%d\n", &n );
        if( n == 0 ) break;
        for( int i = 0; i < n; i++ )
        {
            scanf( "%d ", &a );
            if( a >= 2 )
            {
                more_than_2++;
            }
            if( a > 0 )
            {
                not_zero++;
            }
        }
        if( more_than_2 == 0 )
        {
            printf( "NA\n" );
        }
        else
        {
            printf( "%d\n", not_zero + 1 );
        }
    }
    return 0;
}


Measured memory_bytes: 2736
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  string a[h];
  for(int i=0;i<h;i++) cin >> a[i];
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(j==0) cout << "#";
      else if(j==w+1)cout << "#" << endl;
      else if(i==0||i==h+1) cout << "#";
      else {
        cout << a[i-1];   
        j=w;
      }
    }
  }
}

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

int main(){
  string S;
  cin >> S;
  if(S[0] == 'R' && S[1] == 'R' && S[2] == 'R')cout << 3;
  else if(S[0] == 'R' && S[1] == 'R')cout << 2;
  else if(S[1] == 'R' && S[2] == 'R')cout << 2;
  else if(S[0] == 'R')cout << 1;
  else if(S[1] == 'R')cout << 1;
  else if(S[2] == 'R')cout << 1;
  else cout << 0;
  
  
  
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string s;
    ll k;
    cin >> s >> k;
    int nr = 0;
    while (nr < s.size() && s[nr] == '1')
        ++nr;
    --nr;
    if (k - 1 <= nr)
        cout << "1";
    else
        cout << s[nr + 1];
    return 0;
}


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

int main()
{
  ll A, V, B, W, T; cin >> A >> V >> B >> W >> T;
  if (V <= W) {
    cout << "NO" << endl;
    return 0;
  }

  ll pos = abs(B - A);
  ll adv = (V-W)*T;

  if (pos <= adv) {
    cout << "YES" << endl;
    return 0;
  };
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int a[n];
  for(int i(0);i<n;i++){
    cin>>a[i];
  }
  for(int i(n-1);i>0;i--){
    for(int j(n-1);j>n-1-i;j--){
      if(a[j-1]<a[j]){
        int t;
        t=a[j-1];
        a[j-1]=a[j];
        a[j]=t;
      }
    }
  }
  int al(0),bo(0);
  for(int i(0);i<n;i++){
    if(i%2==0)al+=a[i];
    else bo+=a[i];
  }
  cout<<al-bo<<endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

double DP[550][550] = {};

int main(){
	
	int N, M;
	cin >> N >> M;
	
	long long int a[1000];
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= M; j++){
			DP[i][j] = -INF;
		}
	}
	DP[0][0] = 0;
	
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++){
			long long int S = 0;
			for(int k = 1; k <= i; k++){
				S += a[i - k];
				DP[i][j] = max(DP[i][j], DP[i - k][j - 1] + S / (double)k);
			}
		}
	}
	
	printf("%.10f\n", DP[N][M]);
	
	return 0;
}



Measured memory_bytes: 5376
N = int(input())
h = list(map(int, input().split()))
dp = [0]*N
dp[0], dp[1] = 0, abs(h[1] - h[0])
for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]),dp[i-1] + abs(h[i]-h[i-1]))
print(dp[N-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0){
            break;
        }
        else{
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if((i+j)%2==0){
                        cout<<'#';
                    }
                    else{
                        cout<<".";
                    }
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1000000007;
int n,m,a;
int dp[100001];
bool f[100001];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(f,true,sizeof(f));
	cin>>n>>m;
	for (int i=0;i<m;++i) cin>>a,f[a]=false;
	if (f[1]==true) dp[1]=1;
	if (f[2]==true && f[1]==true) dp[2]=2;
	else if (f[2]==true) dp[2]=1;
	for (int i=3;i<=n;++i)
	{
		if (f[i]==true)
			dp[i]=(dp[i-1]+dp[i-2])%mod;
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 768
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static char S[100001];

int main(void) {
    size_t N, K;

    scanf("%zu %zu\n%s", &N, &K, S);

    size_t stPos = 0;
    size_t transCount = (S[0] == '0' ? 1 : 0);
    size_t size = 1;
    size_t maxSize = 0;

    while (stPos + size <= N) {
        if (maxSize < size) {
            maxSize = size;
        }

        if (S[stPos + size] != S[stPos + size - 1]) {
            if (S[stPos + size] == '0') {
                if (transCount < K) {
                    transCount++;

                    if (maxSize < size) {
                        maxSize = size;
                    }
                }
                else {
                    while (S[stPos] == '1') {
                        stPos++;
                        size--;
                    }
                    while (S[stPos] == '0') {
                        stPos++;
                        size--;
                    }
                }
            }
        }

        size++;
    }

    printf("%zu\n", maxSize);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){
  int N,X;
  cin>>N>>X;

  ll minm=INF;
  int ans=0;
  rep(i,N){
    ll m; cin>>m;
    X-=m;
    ++ans;
    mini(minm,m);
  }
  while(X>=minm){
    X-=minm;
    ++ans;
  }

  cout<< ans<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
}

Measured memory_bytes: 23892
N, M = map(int, input().split())
road = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    road[a].append(b)
    road[b].append(a)

for a in road:
    print(len(a))


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

class Main{
	
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		StringTokenizer st = new StringTokenizer(line," ");
		
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int count=0;
		
		for(int i=a; i<=b; i++){
			if(c%i == 0){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24408
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
        string[] line = Console.ReadLine().Split(' ');
        int H = int.Parse(line[0]);
        int W = int.Parse(line[1]);
    
        string[,] map = new string[H+2,W+2];
        int chk = 0;
        bool can = true;

        for(int hi = 0 ; hi < H+1 ; hi++){
            for(int wi = 1 ; wi < W+1 ; wi++){
                map[hi,wi] = ".";
            }
        }

        for(int hi = 0 ; hi < H ; hi++){
            char[] c = Console.ReadLine().ToCharArray();
            for(int wi = 0 ; wi < W ; wi++){
                map[hi+1, wi+1] = c[wi].ToString();
            }
        }

        for(int hi = 1 ; hi < H+1 ; hi++){
            for(int wi = 1 ; wi < W+1 ; wi++){
                if(map[hi,wi]=="#"){
                    chk = check(map, hi, wi);
                } else {
                    chk = 1;
                }
                if(chk == -1) can = false;
            }
        }

        if(can){
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }
	}                   

    public static int check(string[,] map, int cH , int cW){
        int cnt = 0;
        if(map[cH-1,cW] == ".") cnt++;
        if(map[cH+1,cW] == ".") cnt++;
        if(map[cH,cW-1] == ".") cnt++;
        if(map[cH,cW+1] == ".") cnt++;
        
        if(cnt == 4){
            return -1;
        } else {
            return 1;
        }
    }                                                                                                                                                    
}

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


int main() {
    int N;
  cin >> N;
    vector<double> A(N);

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    double Sum = 0;
    
    for(int i = 0; i < N; i++){
        Sum += 1/A.at(i);
    }

    cout << fixed << setprecision(12);
    cout << 1 / Sum << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    int w = 1 + d * 2;
    if (n % w == 0) {
        cout << n / w << endl;
    } else {
        cout << n / w + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

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

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

int main(){

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

    int cnt = 0;
    for(int i=0; i<N; ++i){
        for(int j=i+1; j<N; ++j){
            for(int k=j+1; k<N; ++k){
                if(L[i] + L[j] > L[k] && 
                L[i] + L[k] > L[j] &&
                L[j] + L[k] > L[i] && 
                L[i] != L[j] &&
                L[j] != L[k] &&
                L[i] != L[k]){
                    cnt++;
                }
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    while(1){
        string s;
        cin >> s;
        if(s == "-")break;

        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            int h;
            cin >> h;
            s = s.substr(h,s.size()-h)+s.substr(0,h);
        }
        cout << s << endl;


    }



}


Measured memory_bytes: 3156
#include<iostream>
using namespace std;
int a,b,c;
int n;
int ans;
int main(){
	cin>>a>>b>>c;
	for(int i=1;i<=a;i++){
		cin>>n;
		if(n<b||n>=c)ans++;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()

favorite_number = 753
min_number = int(s)*100
#print(len(s))

for i in range(0, len(s)-2):
    num = int(s[i] + s[i+1] + s[i+2])
    if(abs(favorite_number-num) < min_number):
        min_number = abs(favorite_number-num)

print(min_number)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main(){
  char s[100000];  //100000
  scanf("%s", s);
  int len = strlen(s);
  int core[len], num[len];
  int i = 0;
  int r = 0;
  int l = 0;
  while(i < len){
    r = 0;
    while(s[i] == 'R'){
      core[i] = 0;
      r++;
      i++;
    }
    core[i - 1] = r;
    int ix = i;
    //core[i] = 1;
    i++;
    l = 0;
    while(s[i] == 'L'){
      core[i] = 0;
      l++;
      i++;
    }
    core[ix] = l + 1;
  }
  /*
  for(int i = 0; i < len; i++){
    num[i] = 1;
  }
  */
  /*
  for(int i = 0; i < len; i++){
    int p = i;
    while(!core[p]){
      p += 2;
      if(s[i] == 'L'){
        p -= 4;
      }
    }
    num[p]++;
  }
  */
/*
  for(int i = 0; i < len; i++){
    printf("%d ", core[i]);
  }
  printf("\n");
*/
  for(int i = 0; i < len; i++){
    if(!core[i]){
      num[i] = 0;
    }else{
      if(s[i] == 'R'){
        num[i] = (core[i] - 1) / 2 + (core[i + 1] - 1) / 2 + (core[i + 1] - 1) % 2 + 1;
      }
      if(s[i] == 'L'){
        num[i] = (core[i - 1] - 1) / 2 + (core[i] - 1) / 2 + (core[i - 1] - 1) % 2 + 1;
      }
    }
  }

  for(int i = 0; i < len; i++){
    printf("%d ", num[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D,E,ans=0;
main(){
  cin>>A>>B>>C>>D>>E;
  if(A>0){
    ans=(B-A)*E;
  }else if(A==0){
    ans=D+B*E;
  }else{
    ans=abs(A)*C+D+B*E;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3088
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    int L=0,R,T,B=0,N;
    cin>>R>>T>>N;
    REP(i,N) {
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1) {
            L=max(L,x);
        }
        else if(a==2) {
            R=min(R,x);
        }
        else if(a==3) {
            B=max(B,y);
        }
        else {
            T=min(T,y);
        }
    }
    if(L>R || B>T) cout<<0<<endl;
    else cout<<(R-L)*(T-B)<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    a,b=map(int, input().split())
    if a==0 and b==0:
        break
    else:
        for  i in range(a):
                if i==0 or i==(a-1):
                    print("#"*b)
                else:
                    print("#"+"."*(b-2)+"#")
    print("")


Measured memory_bytes: 5608
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		out(nd() / nd());
	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int abcount(String str) {
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if ("AB".equals(str.substring(i, i + "AB".length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 37552
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    rep (i, s.size()) {
        cout << s[i];
        if (i + 1 < s.size() || s.size() == t.size()) cout << t[i];
    }
    cout << "\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    string s;
    int a;

    while (cin >> s)
    {
        if (s == "-")
            break;
        cin >> a;
        rep(i, a)
        {
            int t;
            cin >> t;
            s = s.substr(t) + s.substr(0, t);
        }
        cout << s << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
N,K = map(int, input().split())

A = list( map(int, input().split()) )	# 1 2 3 4 5 ...

from itertools import accumulate

for _ in range(K):
  B=[0]*N
  for i,d in enumerate(A):
    l = max(0, i-d)
    r = i+d+1

    B[l]+=1
    if r<N: B[r]-=1

  A = list(accumulate(B))
  if A.count(N)==N: break
  # p("A=",A)
  # p("B=",B)

print(*A)


Measured memory_bytes: 179648
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/10/ITP1_10_A

#include <iostream>
#include <cmath>
#include <cstdio>

int main()
{
    double x1 = 0., x2 = 0., y1 = 0., y2 = 0.;
    double dist;

    std::cin >> x1 >> y1 >> x2 >> y2;
    dist = sqrt(pow(x1 - x2, 2.) + pow(y1 - y2, 2.));
    printf("%.5lf\n", dist);
}


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

int main() {
  int A,B,C,K;
  cin >>A>>B>>C>>K;
  for(int i=0;i<K;i++){
    if(A>=B){
      B*=2;
    }
    else if(B>=C){
      C*=2;
    }
    else {
      break;
    }
  }
  if(A<B&&B<C){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N;
long long int A[200005];

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	long long int ans = 0;
	long long int val = A[1];

	for (int i = 2; i <= N; i++) {
		if (A[i] < val) { ans += val-A[i]; }
		val = max(val, A[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i += 2) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ll n, t;
    cin >> n >> t;
    ll ans = 0, b = 0;
    REP(i, n){
        ll a;
        cin >> a;
        ans += min(a - b, t);
        b = a;
    }
    ans += t;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var ny = IO.RSInt;
            for (int i = 0; i <= ny[0]; i++)
            {
                for (int j = 0; j + i <= ny[0]; j++)
                {
                    if (-(10000 * i + 5000 * j - ny[1]) % 1000 == 0 && -(10000 * i + 5000 * j - ny[1]) / 1000 == ny[0] - i - j)
                    {
                        WriteLine(i + " " + j + " " + -(10000 * i + 5000 * j - ny[1]) / 1000);
                        return;
                    }
                }
            }
            WriteLine("-1 -1 -1");
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> U(N-1), V(N-1);
    for ( int i = 0; i < N-1; i++ ) {
        cin >> U[i] >> V[i];
        U[i]--, V[i]--;
    }
    ll s1 = N*(N+1)*(N+2)/6;
    ll s2 = 0;
    for ( int i = 0; i < N-1; i++ ) {
        ll u = U[i], v = V[i];
        if ( u > v ) swap(u,v);
        s2 += (u+1) * (N-v);
    }
    ll ans = s1 - s2;
    return ans;
}

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

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


int main() {

    int h, w, k;

    cin >> h >> w >> k;

    vector<vector<int>> cakes(h, vector<int>(w, -1));
    int count = 1;

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            char ch;
            cin >> ch;

            if(ch != '.')
                cakes[i][j] = count++;

        }

    }

    /*
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(j)
                cout << " ";
            cout << cakes[i][j];
        }
        cout << endl;
    }
    cout << endl;
    */

    vector<int> hCount(h, 0);

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j)
            if(cakes[i][j] != -1)        
                hCount[i]++;
    }

    for(int j = 0; j < w; ++j) {
        int i = 0;

        while(i < h && cakes[i][j] == -1)
            i++;
    
        if(i == h)
            continue;

        int first_i = i;
        int sValue = cakes[i][j];

        while(--i != -1)
            cakes[i][j] = sValue;


        for(i = first_i + 1; i < h; ++i) {
            if(cakes[i][j] == -1)
                cakes[i][j] = cakes[i - 1][j];
        }

    }

    int first_j;
    int j = 0;

    while(j < w && cakes[0][j] == -1)
        j++;
    
    

    first_j = j;

    if(j != w) {
        while(--j != -1) {
            for(int i = 0; i < h; ++i)
                cakes[i][j] = cakes[i][j + 1];
        }
    }

    for(j = first_j + 1; j < w; ++j) {
        if(cakes[0][j] != -1)
            continue;

        for(int i = 0; i < h; ++i)
            cakes[i][j] = cakes[i][j - 1];


    }
    

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(j)
                cout << " ";
            cout << cakes[i][j];
        }
        cout << endl;
    }

    return 0;

}

Measured memory_bytes: 3968
import math
# K = int(input())
# ans = 0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         for k in range(1,K+1):
#             ans+=math.gcd(i,math.gcd(j,k)) 
# print(ans)           


ans = 0
K = int(input())
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = math.gcd(i,j)
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a = dp[i][j]
            ans += dp[a][k]
print(ans)


Measured memory_bytes: 70772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    ll rem = N % 10;
    if (rem == 0 || rem == 1 || rem == 6 || rem == 8) cout << "pon" << endl;
    if (rem == 2 || rem == 4 || rem == 5 || rem == 7 || rem == 9) cout << "hon" << endl;
    if (rem == 3) cout << "bon" << endl;
}

Measured memory_bytes: 3596
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 998244353
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,s = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0]*(s+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
  for si in range(s+1):
    dp[i+1][si] += dp[i][si]*2
    dp[i+1][si] %= mod
    if not 0 <= si+A[i] < s+1:continue
    dp[i+1][si+A[i]] += dp[i][si]
    dp[i+1][si+A[i]] %= mod
# print(*dp,sep = "\n")
print(dp[n][s])

Measured memory_bytes: 139792
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}



int main(){
    IOS;
    make2(ll,x,n);
    makevec(ll,vec,n);
    unordered_map <ll,ll> umap;
    fr(i,n) umap[vec[i]]=1;
    ll i=0;
    while(true){
        if(!umap[x-i]) {cout<<x-i<<endl; return 0;}
        if(!umap[x+i]) {cout<<x+i<<endl; return 0;}
        i++;
    }


    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin >> n >> m;
    int a[n],b[n],c[m],d[m];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<m;i++){
        cin >> c[i] >> d[i];
    }
    for(int i=0;i<n;i++){
        int x = a[i];
        int y = b[i];
        int dis=INT_MAX;
        int kyori = 0;
        for(int i=0;i<m;i++){
            int v = abs(x-c[i]) + abs(y-d[i]);
            if(dis > v){
                dis = v;
                kyori = i;
            }
        }
        cout << kyori + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>

using namespace std;

int main()
{
  long N, M;
  cin >> N >> M;
  if (2 * N > M) {
    cout << M / 2 << endl;
  } else {
    long x = (M - 2 * N) / 4;
    while (true) {
      if (2 * (N + x) > M - 2 * x) break;
      ++x;
    }
    cout << N + x - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
   
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
   
int n, M[MAX][MAX];
   
int prim() {
   int a, min;
   int d[MAX], p[MAX], color[MAX];
    
   for ( int i = 0; i < n; i++) {
      d[i] = INFTY;
      p[i] = -1;
      color[i] = WHITE;
   }
   
   d[0] = 0;
   
   while ( 1 ) {
      min = INFTY;
      a = -1;
   
      for ( int i = 0; i < n; i++ ) {
         if ( min > d[i] && color[i] != BLACK ) {
            a = i;
            min = d[i];
         }
      }
   
      if ( a == -1 ) break;
      color[a] = BLACK;
      for ( int v = 0; v < n; v++ ) {
         if ( color[v] != BLACK && M[a][v] != INFTY ) {
            if ( d[v] > M[a][v] ) {
               d[v] = M[a][v];
               p[v] = a;
               color[v] = GRAY;
            }
         }
      }
   }
   
   int sum = 0;
   for ( int i = 0; i < n; i++ ) {
      if ( p[i] != -1 ) sum = sum + M[i][p[i]];
   }
    
   return sum;
}
   
int main() {
   cin >> n;
   
   for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) { 
         int e; cin >> e;
         M[i][j] = (e == -1) ? INFTY : e;
      }
   }
   
   cout << prim() << endl;
   
   return 0;
}

Measured memory_bytes: 3064
N, T = list(map(int, input().split()))
ans = -1
for i in range(N):
    c, t = list(map(int, input().split()))
    if t<=T:
        if ans==-1:
            ans = c
        elif c<ans:
            ans = c 

if ans==-1:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 3060