akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"


using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(10)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void Pvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Ps(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}

ll  n, m, r, l, k, h, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;

void INIT() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << DOUBLE;
}

int main() {
	INIT();
	cin >> s;
	vvll dp(s.size()+1, vll(13,0));
	dp[0][0] = 1;
	rep(i, s.size()) {
		if (s[i] == '?') {
			//cout << i << endl;
			rep(j, 13) {
				rep(k, 10) {
					//cout << (10 * j + k) % 13;
					dp[i + 1][(10 * j + k) % 13] += dp[i][j];
				}
				//cout << endl;
			}
		}
		else {
			rep(j, 13) dp[i + 1][(10 * j + (s[i] - '0')) % 13] += dp[i][j];
		}
		rep(j, 13) dp[i + 1][j] %= mod;
	}
	//Pvvll(dp);
	cout << dp[s.size()][5] % mod << endl;
	return 0;
}

Measured memory_bytes: 13648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n;cin>>n;
  int p[n];rep(i,n)cin>>p[i];
  multiset<int> mst;
  mst.insert(0);mst.insert(0);
  mst.insert(n+1);mst.insert(n+1);
  map<int,int> MAP;
  rep(i,n){
    MAP[p[i]]=i+1;
  }
  ll l0[n+1],l1[n+1],r0[n+1],r1[n+1];
  for(int i=n;i>0;--i){
    int idx=MAP[i];
    auto it=mst.lower_bound(idx);
    r0[i]=*it;r1[i]=*(++it);
    --it;
    l0[i]=*(--it);l1[i]=*(--it);
    mst.insert(idx);
  }
  ll ans=0;
  rep(i,1,n+1){
    ll tmp=0;
    tmp+=1ll*(l0[i]-l1[i])*(r0[i]-MAP[i]);
    tmp+=1ll*(r1[i]-r0[i])*(MAP[i]-l0[i]);
    ans+=tmp*i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  rep(i,5){
    int tmp;
    cin >> tmp;
    if(tmp == 0){
      cout << i + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

static const int MAX = 100;

int main () {
        int i, j, n, A[MAX], min, idx, temp, c = 0;

        cin >> n;
        for (i = 0; i < n; i++)
                cin >> A[i];

        for (i = 0; i < n; i++) {
                min = A[i];
                idx = i;
                for (j = i + 1; j < n; j++) {
                        if (min > A[j]) {
                                min = A[j];
                                idx = j;
                        }
                }
                if (i != idx) {
                        temp = A[i];
                        A[i] = A[idx];
                        A[idx] = temp;
                        c++;
                }
        }

        cout << A[0];
        for (i = 1; i < n; i++)
                cout << ' ' << A[i];
        cout << endl;

        cout << c << endl;

        return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// using u128 = __uint128_t;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
// typedef vector<vi> vvll;
// typedef pair<ll,ll> ii;
// typedef vector<ii> vii;
// typedef vector<vector<pair<ll,ll>>> vvii;
// typedef long double ld;
// typedef vector<long double> vld;
// typedef vector<vector<long double>> vvld;
typedef vector<bool> vbl;
// typedef vector<vector<bool>> vvbl;
#define pb push_back
#define rep(x, n) for(int x = 0 ; x < n ; x++)
// #define rep1(x, n) for(int x = 1 ; x < n ; x++)
// #define rrep(x, n) for(int x = n ; x >= 0 ; x--)
// #define all(c) (c).begin() , (c).end()
// typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll MOD = 1e9 + 7;
vvi g;
ll n;
vbl visited;
vll f1, f2;

inline void dfs(int node, int parent=-1)
{
    for (auto child : g[node])
    {
        if (child == parent)
            continue;
        if (!visited[child])
            dfs(child, node);
        visited[child] = true;
        f1[node] = (f1[node] * (f1[child] + f2[child]) % MOD) % MOD;
        f2[node] = (f2[node] * f1[child]) % MOD;
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    cin >> n;
    g.resize(n);
    visited.resize(n, false);
    f1.resize(n, 1);
    f2.resize(n, 1);
    ll a, b;
    rep(i,n - 1)        cin >> a >> b, a--, b--, g[a].pb(b), g[b].pb(a);
    dfs(0);
    cout << (f1[0] + f2[0]) % MOD << '\n';
    return 0;
}

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

using namespace std;
const int maxn=500005;
char str[maxn];
char str1[maxn];
int Next[maxn];
void getNext()
{
   Next[0]=-1;
   int k=-1,j=0;
   while(str[j]!='\0')
   {
        while(k!=-1&&str[k]!= str[j])
            k=Next[k];
        ++j;++k;
        Next[j]=k;
   }
   int l=strlen(str);
//   for(int i=0;i<=l;i++)
//    printf("%d ",Next[i]);
//   printf("\n");
}
bool flag[maxn];
int main()
{
    scanf("%s",str);
    getNext();
    int l=strlen(str);
    int s=l-Next[l];
    //printf("%d %d\n",l,s);
    if(s==l||l%s!=0){
        printf("1\n1\n");return 0;
    }
    if(s==1){
        printf("%d\n1\n",l);return 0;
    }



    for(int i=1;i<=l;i++)
    {
        int t1=i-Next[i];
        if(t1==i||i%t1!=0){
            continue;
        }
        flag[i]=1;
    }



    for(int i=0;i<l/2;i++)
    {
        swap(str[i],str[l-1-i]);
    }
    getNext();
    for(int i=1;i<=l;i++)
    {
        int t1=i-Next[i];
        if(t1==i||i%t1!=0){
            continue;
        }
        flag[l-i]=1;
    }

    int ans=0;
    for(int i=1;i<l;i++)
        if(flag[i]==0) ans++;

    printf("2\n%d\n",ans);
    return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int n;
int c[100000];
int f[100000];
long long d[100000];
vector <pair<int, int>> v[100000];
vector <int> w;
map <pair<int, int>, int> mp;

int dfs(int x, int y, int z) {
    int i;
    
    c[x] = z;
    
    for (i = 0; i < v[x].size(); i++) {
        int nx = v[x][i].first;
        
        if (c[nx] == z) {
            w.push_back(nx);
            w.push_back(x);
            return 1;
        } else if (c[nx] == 0) {
            int p = dfs(nx, x, 3 - z);
            
            if (p == 1) {
                w.push_back(x);
                return 1;
            }
        }
    }
    
    return 0;
}

void dfs2(int x, int y) {
    int i;
    
    f[x] = 1;
    
    for (i = 0; i < v[x].size(); i++) {
        int nx = v[x][i].first;
        int nd = v[x][i].second - d[x];
        
        if (f[nx] == 0) {
            d[nx] = nd;
            dfs2(nx, x);
        }
    }
}

bool check() {
    int i, j;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < v[i].size(); j++) {
            int x = i, y = v[i][j].first, z = v[i][j].second;
            
            if (d[x] + d[y] != z) return false;
        }
    }
    
    return true;
}

int main() {
    int m, i;
    long long ans = 0;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < m; i++) {
        int x, y, s;
        
        scanf("%d %d %d", &x, &y, &s);
        
        x--;
        y--;
        
        v[x].push_back(make_pair(y, s));
        v[y].push_back(make_pair(x, s));
        mp[make_pair(x, y)] = mp[make_pair(y, x)] = s;
    }
    
    if (dfs(0, -1, 1) == 0) {
        long long m1 = 1e18, m2 = 1e18;
        
        dfs2(0, -1);
        
        for (i = 0; i < n; i++) {
            if (c[i] == 1) {
                m1 = min(m1, d[i]);
            } else {
                m2 = min(m2, d[i]);
            }
        }
        
        m2 -= 1 - m1;
        
        if (check()) ans = max(0LL, m2);
    } else {
        int p, x, y;
        
        for (i = 1; i < w.size(); i++) {
            if (w[i] == w[0]) break;
        }
        
        p = i;
        
        for (i = 2; i < p; i += 2) {
            int x = w[i], y = w[i - 1], z = w[i - 2];
            
            d[x] = d[z] - mp[make_pair(y, z)] + mp[make_pair(x, y)];
        }
        
        x = w[0], y = w[p - 1];
        
        if ((mp[make_pair(x, y)] - d[y]) % 2 == 0) {
            d[x] = (mp[make_pair(x, y)] - d[y]) / 2;
            
            dfs2(x, -1);
            
            for (i = 0; i < n; i++) {
                if (d[i] <= 0) break;
            }
            
            if (i == n && check()) ans = 1;
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int S;
int po[111];

signed main(){
    po[0]=1;
    for(int i=1;i<111;i++)po[i]=po[i-1]*10;

    cin>>S;

    int ans=0;
    for(int i=1;i<=7;i++){
        for(int j=i;j<=7;j++){
            int tmp=0;
            for(int k=i;k<=j;k++)tmp+=k*9*po[k-1];
            if(tmp>S)continue;
            int lim;
            if(i==1)lim=0;
            else lim=9*po[i-2]-1;
            for(int k=0;k<=lim;k++){
                int r=S-tmp-k*(i-1);
                if(r<0||r%(j+1)||r/(j+1)>=9*po[j])continue;
                ans++;
            }
        }
    }

    for(int i=1;i<=7;i++){
        for(int j=1;j<9*po[i-1];j++){
            int r=S-i*j;
            if(r<=0||r%(i+1)||r/(i+1)>=9*po[i])continue;
            ans++;
        }
    }

    ans%=mod;
    for(int i=1;i*i<=S;i++){
        if(S%i)continue;
        int tmp=S/i;
        if(!(i<=7&&tmp>=9*po[i-1]))add(ans,(9*mpow(10,i-1)-tmp+1+mod)%mod);


        int j=S/i;
        if(i==j)continue;
        tmp=S/j;
        if(!(j<=7&&tmp>=9*po[j-1]))add(ans,(9*mpow(10,j-1)-tmp+1+mod)%mod);
    }

    /*
    for(int i=8;i<123;i++){
        for(int j=1;i*j<S;j++){
            int r=S-i*j;
            if(r%(i+1))continue;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
    */

    int l=0,r=0;
    for(int i=S-1;i>=8;i--){
        while(S-i*l>=l)l++;
        while(S-i*(r+1)>0)r++;
        if(l<=r)ans+=r-l+1;
    }
    cout<<ans%mod<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

ll f(ll x) {
  ll y = 1;
  for (ll i = 1; i <= x; i++) {
    y *= i;
    y %= MOD;
  }
  return y;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  ll N,K; cin >> N >> K;
  vector<ll> ans(K+1);
  for (int i = 1; i <= K; i++) {
    if (N-K-i+1 >= 0) {
      ll child = f(K-1) * f(N-K+1) % MOD;
      ll mom = f(K-i) * f(i-1) % MOD;
      mom = mom * f(N-K-i+1) % MOD;
      mom = mom * f(i) % MOD;
      mom = modinv(mom,MOD);
      ans[i] = child * mom % MOD;
    } else ans[i] = 0;
  }
  
  for (int i = 1; i <= K; i++) cout << ans[i] << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,d,i,j,l,g=0;
	char a[300][300];
	scanf("%d %d %d",&n,&m,&d);
	for(i=0;i<n;i++){
		scanf("%s",a[i]);
	}
	if(n>=1 && n<=100 && m>=1 && m<=100 && d>=1 && d<=100){
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				l=0;
				while(l<=d-1){
					if(a[i+l][j]=='.' && l!=d-1){
						l++;
					}
					else if(a[i+l][j]=='.' && l==d-1){
						g+=1;
						l++;
					}
					else{
						l=100;
					}
				}
				l=0;
				while(l<=d-1){
					if(a[i][j+l]=='.' && l!=d-1){
						l++;
					}
					else if(a[i][j+l]=='.' && l==d-1){
						g+=1;
						l++;
					}
					else{
						l=100;
					}
				}
			}
		}
		printf("%d\n",g);
	}
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  S += '0';
  int ans = 0;
  for (int i = 0; i + 1 < S.size(); i++) {
    int n  = S.at(i) - '0';
    ans += min(n, 10 - n);
    if (n >= 6 || n == 5 && S.at(i + 1) >= '5') S.at(i + 1)++;
  }
  ans += S.back() - '0';
  cout << ans << "\n";
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int n;
        cin>>n;
        if(n==0){
            break;
        }
        int w[310];
        for(int i=0;i<n;i++){
            cin>>w[i];
        }
        int dp[310][310];
        int dp2[310][310];
        //dp[i][j] range(i,j)
        //0<=i<=j<=n
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                dp[i][j]=0;
                dp2[i][j]=0;
            }
        }
        for(int a=0;a<=n;a++){
            for(int b=0;b+a<=n;b++){
                int i,j;
                i=b;j=b+a;
                if (a==0){
                    dp[i][j]=1;
                }
                for(int k=i;k<=j;k++){
                    if (dp[i][k]==1 && dp[k][j]==1){
                        dp[i][j]=1;
                    }
                }
                if(dp[i][j]==1){
                    if (i-2>=0 && abs(w[i-2]-w[i-1])<=1){
                        dp[i-2][j]=1;
                    }
                    if (j+2<=n && abs(w[j]-w[j+1])<=1){
                        dp[i][j+2]=1;
                    }
                    if (i-1>=0 && j+1<=n && abs(w[i-1]-w[j])<=1){
                        dp[i-1][j+1]=1;
                    }
                }
                //cout<<dp[i][j]<<" ";
            }
            //cout<<endl;
        }
        for(int a=0;a<=n;a++){
            for(int b=0;b+a<=n;b++){
                int i,j;
                i=b;j=b+a;
                if (dp[i][j]==1){
                    dp2[i][j]=j-i;
                }
                for(int k=i;k<=j;k++){
                    dp2[i][j]=max(dp2[i][j],dp2[i][k]+dp2[k][j]);
                }
                //cout<<dp2[i][j]<<" ";
            }
            //cout<<endl;
        }
        cout<<dp2[0][n]<<endl;
    }
}



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

const int MAX = 10000000;
const int mod = 1000000007;

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

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

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

long long modpow(int x, int r)
{
    if (r == 0)
    {
        return 1;
    }
    else if (r % 2 == 0)
    {
        long long tmp = modpow(x, r / 2);
        return tmp % mod * tmp % mod;
    }
    else
    {
        return x % mod * modpow(x, r - 1) % mod;
    }
}

int main()
{
    COMinit();
    long long K;
    string S;
    cin >> K >> S;
    long long L = S.length() + K;
    long long N = S.length();
    long long ans = 0;
    for (long long i = N; i <= L; i++)
    {
        //S_N以降の文字数
        long long p = L - i;
        ans += COM(L - p - 1, N - 1) % mod * modpow(25, K - p) % mod * modpow(26, p) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 239620
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in); 
		
		int a, b;
		String op;
		
		for(;;){
			a = scan.nextInt();
			op = scan.next();
			b = scan.nextInt();
			
			if(op.equals("+")){
				System.out.println(a + b);
			}else if(op.equals("-")){
				System.out.println(a - b);
			}else if(op.equals("/")){
				System.out.println(a / b);
			}else if(op.equals("*")){
				System.out.println(a * b);
			}else if(op.equals("?")){
				break;
			}
		}
	}

}

Measured memory_bytes: 26368
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i <=999; i++)
	{
		int tmp = i;
		int c = 0;
		for (int j = n - 1; j >= 0; j--)
		{
			if (tmp % 10 == s[j] - '0')
			{
				c++;
				tmp /= 10;
			}
			if (c == 3)
			{
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    boolean hasYellow = false;
    int N = sc.nextInt();
    for (int i = 0; i < N; i++) {
      if (sc.next().equals("Y")) {
        hasYellow = true;
        break;
      }
    }
    System.out.println(hasYellow ? "Four" : "Three");
  }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> m(H * W);
  vector<int> s(H * W, 0);
  for (int i = 0; i < H * W; ++i) cin >> m[i];
  for (int i = H * W - 1; i >= 0; --i) {
    int right_score = 1000;
    int down_score = 1000;
    char right_color = '.';
    char down_color = '.';
    if ((i + 1) % W != 0) {
      right_score = s[i + 1];
      right_color = m[i + 1];
    }
    if (i + 1 <= W * (H - 1)) {
      down_score = s[i + W];
      down_color = m[i + W];
    }
    int min_score = min(right_score, down_score);
    char min_color = '.';
    if (right_score == down_score) {
      if (right_color == '#' || down_color == '#') min_color = '#';
    } else if (right_score < down_score && right_color == '#'){
      min_color = '#';
    } else if (down_score < right_score && down_color == '#') {
      min_color = '#';
    }
    if (min_score == 1000) min_score = 0;
    s[i] = min_score;
    if (m[i] == '#' && min_color == '.') {
      s[i] += 1;
    }
  }
  cout << s[0] << endl;
}

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

struct Point{
  int x,y;
  Point operator + (const Point p)const{
    return (Point){x+p.x,y+p.y};
  }
  Point operator - (const Point p)const{
    return (Point){x-p.x,y-p.y};
  }
};

struct Segment{
  Point p,v;
};

int dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}

int cross(Point a,Point b){
  return a.x*b.y-b.x*a.y;
}

bool isParallel(Point a,Point b){
  return (0==cross(a,b));
}

int abs(int a){return max(a,-a);}
bool eq(Point a,Point b){
  return (a.x==b.x&&a.y==b.y);
}
bool eq(Segment a,Segment b){
  if(eq(a.v,b.v)&&eq(a.p,b.p))return true;
  if(eq(a.p,b.p+b.v)&&eq(a.p+a.v,b.p))return true;
  return false;
}

bool onSegment(Segment s,Point p){
  Point q=p-s.p;
  if(eq(s.p,p)||eq(s.p+s.v,p))return false;
  if(!isParallel(s.v,q))return false;
  if(dot(s.v,q)<=0)return false;
  Point Q=p-(s.p+s.v);
  if(dot(s.p-s.p-s.v,Q)<=0)return false;
  return true;  
}



int n;
int c;
map<string,int> mp;
vector<Segment> G[10];
int g[10][10];

bool calc(int a,int b){
  for(int i=0;i<(int)G[a].size();i++){
    Segment si=G[a][i];
    for(int j=0;j<(int)G[b].size();j++){
      Segment sj=G[b][j];
      if(!isParallel(si.v,sj.v))continue;
      if(eq(si,sj))return true;

      if(onSegment(si,sj.p))return true;
      if(onSegment(si,sj.p+sj.v))return true;
      if(onSegment(sj,si.p))return true;
      if(onSegment(sj,si.p+si.v))return true;
    }
  }
  return false;
}

void init(){
  c=0;
  mp.clear();  
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      g[i][j]=0;
  for(int i=0;i<10;i++)G[i].clear();
}

int main(){
  int id;
  int px,py;
  string str;
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      cin>>str;
      if(mp.count(str)==0)mp[str]=id=c++;
      else id=mp[str];
      vector<Point> t;
      while(1){
        cin>>px;
        if(px==-1)break;
        cin>>py;
        t.push_back((Point){px,py});
      }
      int size=t.size();
      for(int j=0;j<size;j++)
        G[id].push_back((Segment){t[j],t[(j+1)%size]-t[j]});
    }
    
    for(int i=0;i+1<c;i++){
      for(int j=i+1;j<c;j++){
        bool flg=calc(i,j);
        if(flg)g[i][j]=g[j][i]=1;
      }
    }

    
    vector<int> e;
    for(int i=0;i<(1<<c);i++){
      bool flg=true;
      for(int j=0;j<c;j++){
        if(i>>j&1){}else continue;
        for(int k=0;k<c;k++){
          if(i>>k&1){}else continue;
          if(g[j][k])flg=false;
        }
      }
      if(flg)e.push_back(i);
    }
    
    int dp[(1<<c)];
    fill(dp,dp+(1<<c),1e8);
    dp[0]=0;
    for(int S=0;S<(1<<c);S++){
      if(dp[S]==1e8)continue;
      for(int i=0;i<(int)e.size();i++){
        int T=e[i];
        dp[S|T]=min(dp[S|T],dp[S]+1);
      }
    }
    cout<<dp[(1<<c)-1]<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1268
import sys
x, n = list(map(int, input().split()))
if(n == 0):
  print(x)
  sys.exit()

p = list(map(int, input().split()))
i = 1
if x in p:
  while 1:
    if (x - i) in p:
      if (x + i) in p:
        i += 1
      else:
        print(x + i)
        sys.exit()
    else:
      print(x - i)
      sys.exit()
else:
  print(x)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int arr[3];
    int k;
    cin >> arr[0] >> arr[1] >> arr[2] >> k;
    sort(arr, arr + 3);
    cout << arr[0] + arr[1] + (1 << k) * arr[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int m,n,p,q,r,x;
  while(cin>>n>>m>>p&&n+m+p){
    q=0;
    for(i=0;i<n;i++){
      cin>>x;
      q+=x;
      if(i+1==m)
	r=x;
    }
    if(r)
      cout<<q*(100-p)/r<<endl;
    else
      cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

int a, b;
int d;
bool check[105] = {};
void solve()
{
    cin >> a >> b;
    for (int i = 0; i < b; i++)
    {
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int sn;
            cin >> sn;
            check[sn] = true;
        }
    }
    int ans = 0;
    for (int i = 1; i <= a; i++)
    {
        if (check[i] == false)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3652
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    const int MOD = 1000000007;
    public void Slove()
    {
        var n = int.Parse(Console.ReadLine());
        var maxIndex = -1;
        var max = 0;
        var max2 = 0;
        var data = Enumerable.Range(0, n )
            .Select(x => Console.ReadLine())
            .Select(int.Parse)
            .ToArray();
        foreach(var i in data.Select((x, index) => index))
        {
            if(data[i] >= max)
            {
                max2 = max;
                max = data[i];
                maxIndex = i;
            }
            else if(data[i] > max2)
                max2 = data[i];

        }
        foreach (var i in data.Select((x, index) => index))
        {
            Console.WriteLine(i == maxIndex ? max2 : max);
        }
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 19284
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv)
{
	string str, str2;
	cin >> str;
	str += str;
	cin >> str2;

	if(str.find(str2) != string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;

typedef pair<char[11], int> ps;

int main()
{
	queue<ps> Q;
	int n, q, st = 0;
	scanf("%d %d", &n, &q);

	ps p;
	while (n--) {
		scanf("%s %d", p.first, &p.second);
		Q.push(p);
	}

	while (!Q.empty()) {
		ps t = Q.front();
		Q.pop();
		if (t.second <= q) {
			st += t.second;
			printf("%s %d\n", t.first, st);
		} else {
			st += q;
			t.second -= q;
			Q.push(t);
		}
	}
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> a(n), b(n);
    for (auto&& aa : a) {
        cin >> aa;
    }
    for (auto&& bb : b) {
        cin >> bb;
    }

    unordered_set<int64_t> q;
    for (auto i : irange(0L, n)) {
        auto prev = (i - 1 + n) % n;
        auto next = (i + 1) % n;
        if (b[i] - (b[prev] + b[next]) >= a[i]) {
            q.insert(i);
        }
    }

    int64_t ans = 0;
    while (!q.empty()) {
        auto idx = *q.begin();
        q.erase(idx);

        auto prev = (idx - 1 + n) % n;
        auto next = (idx + 1) % n;

        auto tmp = (b[idx] - a[idx]) / (b[prev] + b[next]);
        ans += tmp;
        b[idx] -= (b[prev] + b[next]) * tmp;

        auto prev2 = (prev - 1 + n) % n;
        if (b[prev] - (b[prev2] + b[idx]) >= a[prev]) {
            q.insert(prev);
        }

        auto next2 = (next + 1) % n;
        if (b[next] - (b[idx] + b[next2]) >= a[next]) {
            q.insert(next);
        }
    }

    if (a == b) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 7460
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] H = new int[N];
    boolean[] ii = new boolean[N];
    int[] A = new int[M];
    int[] B = new int[M];
    for(int i = 0; i<N;i++){
      H[i] = sc.nextInt();
      ii[i] = true;
    }
    for(int i = 0; i<M;i++){
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    for(int i = 0; i<M;i++){
      if(H[A[i]-1] == H[B[i]-1]){
        ii[B[i]-1] = false;
        ii[A[i]-1] = false;
      }else if(H[A[i]-1] > H[B[i]-1]){
        ii[B[i]-1] = false;
      }else{
        ii[A[i]-1] = false;
      }
    }
    int count = 0;
    for(int i=0;i<N;i++){
      // System.out.println(ii[i]);  
      if(ii[i]==true){

        count++;
      }
    }
    System.out.println(count);  
  }
}





Measured memory_bytes: 61072
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int dp[100001];
vector<int> a[100001];
int getans(int v)
{
	if(dp[v]!=-1)
	{
		return dp[v];
	}
	int ans=0;
	for(int child:a[v])
	{
			ans=max(ans,1+getans(child));
	}
	return dp[v]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,-1,sizeof(dp));
int n,m;
cin>>n>>m;
int x,y;
for(int i=1;i<=m;i++)
{
	cin>>x>>y;
	a[x].pb(y);
}
int ans=0;
for(int i=1;i<=n;i++)
{
		ans=max(ans,getans(i));
}
cout<<ans<<endl;
}





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

const int INF = 2e9;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<int> dp(h+1, INF);
  dp[0] = 0;
  rep(i, h) rep(j, n) {
    int to = min(i + a[j], h);
    dp[to] = min(dp[to], dp[i] + b[j]);
  }
  cout << dp[h] << endl;
  return 0;
}

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

using namespace std;

int main() {

    int A, B, T;
    cin >> A >> B >> T;

    double t = T + 0.5;
    int tmp = A;
    int b = 0;
    while (tmp < t) {
        tmp += A;
        b += B;
    }
    cout << b << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1e9+7;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗 1*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*n乗 2*/ll modpow(ll x,ll n,ll m){ll ans=x,tmp=x,t1=1;i=1; while(i<n){if(i*2<n){ans*=ans;ans%=m;i*=2;}else{t1=1;tmp=x;while(t1*2<n-i){tmp*=tmp;tmp%=m;t1*=2;}ans*=tmp;ans%=m;i+=t1;}}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x){ans*=(x-i);ans%=mod;}return ans;}
/*nCr*/ll ncr(ll n,ll r){ll ans=1,l=2;rep(i,0,min(n-r,r)){ans*=(n-i);ans%=mod;while(ans%l==0&&l<=min(r,n-r)){ans/=l;l++;}}return ans;}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}//素数の時true
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n; 
 cin>>n;
 vector<ll>a;
 ll b;
 rep(i,0,n){
  cin>>b;
  push(a,b);
 }
 sort(all(a));
 ll p=distance(all(a));
 ll sum=abs(a[p-1]-a[0]);
 ll mx=abs(a[p-1]-a[0]);
 rep(i,1,n){
  sum+=abs(a[i]-a[i-1]);
  mx=max(mx,abs(a[i]-a[i-1]));
 }
 pr(sum-mx);
return 0;}

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

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

  vector<string> s(n);
  map<string, int> p;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    p[s[i]]++;
  }

  cout << "AC x " << p["AC"] << endl;
  cout << "WA x " << p["WA"] << endl;
  cout << "TLE x " << p["TLE"] << endl;
  cout << "RE x " << p["RE"] << endl;
}

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

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

    vector<long> vec(N + 1);
    vec.at(0) = 2;
    vec.at(1) = 1;

    for (int i = 2; i < N + 1; i++)
        vec.at(i) = vec.at(i - 1) + vec.at(i - 2);

    cout << vec.at(N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> C(H);
	for (auto& x : C) cin >> x;
	int res = 0;
	for (int i = 0; i < (1<<H); ++ i) {
		for (int j = 0; j < (1<<W); ++ j) {
			int c = 0;
			for (int ii = 0; ii < H; ++ ii) if ((i>>ii)&1) {
				for (int jj = 0; jj < W; ++ jj) if ((j>>jj)&1) {
					if (C[ii][jj] == '#') ++ c;
				}
			}
			if (c == K) ++ res;
		}
	}
	cout << res << endl;
}


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

using namespace std;

struct object
{
    int weight, value;

    object(){};

    int operator <(const object &O)
    {
        if(value == O.value)
        {
            return (weight < O.weight);
        }

        return (value > O.value);
    }
};

const int MAX_N = 1e3 + 5, MAX_VALUE = 55, oo = 1e9;
int minimum_weight[MAX_N][MAX_VALUE];

int main()
{
    int no_of_objects, capacity;
    cin >> no_of_objects >> capacity;

    vector <object> O(no_of_objects + 1);
    for(int i = 1; i <= no_of_objects; i++)
    {
        cin >> O[i].weight >> O[i].value;
    }

    long long total_value = 0;
    for(int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;
    }

    int answer = 0;
    vector <long long> minimum_weight(total_value + 1, -1);
    total_value = 0;
    minimum_weight[0] = 0;

    for(int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;

        for(int v = total_value; v >= O[i].value; v--)
        {
            if(minimum_weight[v - O[i].value] != -1)
            {
                long long weight_required = minimum_weight[v - O[i].value] + O[i].weight;

                if(weight_required <= capacity)
                {
                    answer = max(answer, v);
                }

                if(minimum_weight[v] == -1 || minimum_weight[v] > weight_required)
                {
                    minimum_weight[v] = weight_required;
                }
            }
        }
    }

    cout << answer;

    return 0;
}


Measured memory_bytes: 1024
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    H, W = in_nn()

    if H % 3 == 0 or W % 3 == 0:
        print(0)
        exit()

    ans = 10 ** 9 + 7

    if H > 3:
        ans = min(ans, W)

    if W > 3:
        ans = min(ans, H)

    for i in range(-3, 2):
        i = H // 3 + i
        for j in range(-3, 2):
            j = W // 2 + j
            if 0 < i < H and 0 < j < W:
                a1 = i * W
                a2 = (H - i) * j
                a3 = (H - i) * (W - j)
                ans = min(ans, max(a1, a2, a3) - min(a1, a2, a3))

    for i in range(-3, 2):
        i = H // 2 + i
        for j in range(-3, 2):
            j = W // 3 + j
            if 0 < i < H and 0 < j < W:
                a1 = j * H
                a2 = (W - j) * i
                a3 = (W - j) * (H - i)
                ans = min(ans, max(a1, a2, a3) - min(a1, a2, a3))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
loop do
  n = gets.chomp.to_i
  row_count = gets.chomp.to_i

  break if n == 0 && row_count == 0

  pairs = row_count.times.map { gets.chomp.split(' ') }

  friends, others, foaf = [], [], []

  pairs.each do |pair|
    if pair[0] == '1'
      friends << pair[1] 
    else
      others << pair
    end
  end

  others.each do |pair|
      foaf << pair[1] if friends.include?(pair[0])
      foaf << pair[0] if friends.include?(pair[1])
  end

  puts (friends | foaf).size
end

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

using namespace std;

typedef long long ll;

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

    int n; cin >> n;
    int weight; cin >> weight;
    
    vector<ll> w(n), v(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    ll max_value = 0;
    vector<ll> dp(weight + 1, 0);
    
    for (int i = 0; i < n; i++) {
        for (int curr_weight = weight - w[i]; curr_weight >= 0; curr_weight--) {
            dp[curr_weight + w[i]] = max (dp[curr_weight + w[i]], dp[curr_weight] + v[i]);
            if (dp[curr_weight + w[i]] > max_value) max_value = dp[curr_weight + w[i]];
        }
    }

    cout << max_value << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
	int h,w,n;
	cin >> h >> w >> n;
	int che = max(h,w);
	ll ans = n/che;
	if(n%che!=0)ans++;
	cout << ans << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::string s; std::cin >> s;
  auto solve = [&] (int k) {
    auto d = 0, m = 0; auto pairs = 0LL, ret = 0LL;
    rep(r, 1, n + 1) {
      auto l = r - k;
      if (s.at(r - 1) == 'D')
        { d++; }
      if (s.at(r - 1) == 'M')
        { m++; pairs += d; }
      if (0 < l && s.at(l - 1) == 'D')
        { d--; pairs -= m; }
      if (0 < l && s.at(l - 1) == 'M')
        { m--; }
      if (s.at(r - 1) == 'C')
        { ret += pairs; }
      // debug(d, m, pairs);
    }
    return ret;
  };
  int q; std::cin >> q;
  loop(q) {
    int k; std::cin >> k;
    std::cout << solve(k) << std::endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef pair<int, pair<int,int> > pipii;

const int INF = 1e7;
vector<pipii> road[10001];
bool visit[10001];
pii minCost[10001];
int dist[10001];

int main() {
	int n, m;
	while(cin >> n >> m, n) {
		memset(visit, 0, sizeof(visit));
		memset(dist, 0, sizeof(dist));
		rep(i, n+1) {
			road[i].clear();
			minCost[i] = pii(INF, INF);
		}
		rep(i, m) {
			int u, v, d, c;
			cin >> u >> v >> d >> c;
			road[u].push_back(pipii(v, pii(d, c)));
			road[v].push_back(pipii(u, pii(d, c)));
		}
		visit[1] = true;
		rep(i, road[1].size()) {
			minCost[ road[1][i].first ] = road[1][i].second;
		}
		int res = 0;
		while(1) {
			int p = -1;
			for(int i=1; i<=n; i++) {
				if( !visit[i] ) {
					if( p==-1 || minCost[i] < minCost[p] ) {
						p = i;
					}
				}
			}
			if(p==-1) break;
			visit[p] = true;
			res += minCost[p].second;
			rep(i, road[p].size()) {
				if( visit[ road[p][i].first ] ) continue;
				minCost[ road[p][i].first ] = min(minCost[ road[p][i].first ], pii(road[p][i].second.first + minCost[p].first, road[p][i].second.second) );
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
"use strict";
function Main(input) {
  input = input.split("\n");
  let line0 = input[0].split(" ");
  let N = parseInt(line0[0]);
  let K = parseInt(line0[1]);
  function pow3(k) {
    return k * k * k;
  }
  if (K % 2 === 0) {
    console.log(pow3(Math.floor(N / K)) + pow3(Math.floor((N + K / 2) / K)));
  } else {
    console.log(pow3(Math.floor(N / K)));
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

const int MAXN=1000010;

int cnt=0,G[100];

void Insertion_Sort(int s,int t,int n,int* A)
{
	for(int i=s+t;i<n;i+=t)
	{
		int key=A[i],j=i-t;
		while(j>=0&&A[j]>key)
		{
			A[j+t]=A[j];
			j-=t;
			cnt++;
		}
		if(A[j+t]!=key)
		{
			A[j+t]=key;
			//cnt++;
		}
	}
}

int main()
{
	for(int i=0;(G[i]=G[i-1]*3+1)<=MAXN;i++);
	static int n,A[MAXN];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]);
	int t;
	for(t=0;G[t]<=n;t++);
	printf("%d\n",t);
	for(int i=t-1;i>=0;i--)
		printf("%d%c",G[i],i==0?'\n':' ');
	for(int i=t-1;i>=0;i--)
		for(int j=0;j<G[i];j++)
			Insertion_Sort(j,G[i],n,A); 
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)
		printf("%d\n",A[i]);
	return 0;
}

Measured memory_bytes: 7092
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
using namespace std;

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

const int INF = 1e9;
int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

int main() {
  int a, b, rv = 0, rm, t, ans = 0;
  cin >> a >> b;
  for(; a <= b; a++) {
    t = a;
    while(t!=0) {
      rm = t % 10;
      rv = rv * 10 + rm;
      t /= 10;
    }
    if(a == rv) ans++;
    rv = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# 2019/09/15
# AtCoder Beginner Contest 141 - B

# Input
s = input()
yflg = True

# Check
for i in range(len(s)):
    # Case Odd(0-idx)
    if i % 2 == 0:
        if s[i] == "L":
            yflg = False
    # Case Even(0-idx)
    else:
        if s[i] == "R":
            yflg = False

if yflg == True:
    ans = "Yes"
else:
    ans = "No"

# Output
print(ans)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
string s;
int t[26];
int main(void){
    cin>>s;
    for(int i=0;i<4;i++){
        t[s[i]-'A']++;
    }
    for(int i=0;i<26;i++){
        if(t[i]!=2&&t[i]!=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){//
    int x, y, w, h, r;
    cin >> w >> h >> x >> y >> r;
    if ((0 <= (x-r))&&((x-r) <= w)&&(0<=(x+r))&&((x+r)<=w)&&(0<=(y-r))&&((y-r)<=h)&&(0<=(y+r))&&((y+r)<=h)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main(){
	int k, s;
	cin >> k >> s;
	int sum = 0;
	for(int i = 0; i<= k ;i++){
		for(int j = 0; j <= k; j++){
			if(i+j <= s){
				if(s-(i+j) <= k){
					sum++;
				}
			}
		}
	}
	cout << sum;
	return 0;
} 

Measured memory_bytes: 3644