akhauriyash/Code-Regression huggingface dataset:
// Problem : C - One Quadrillion and One Dalmatians
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    string ans;
    while(n){
        n--;
        int z = n%26;
        n /= 26;
        ans += (z+'a');
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,n;
    cin>>h>>n;
    int sum=0;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>=h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <queue>
#include <utility>
#include <functional>
#include <sstream>
using namespace std;
#define ll long long
 
int main(void){
    ll n, m;
    cin >> n >> m;
    if(n==m)
        cout << "Yes" << endl;
    else if(n > m)
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int H,W,tate,yoko;
	for(;;){
		scanf("%d %d",&H,&W);if(H==0&&W==0){break;}
	for(tate=1;tate<=H;tate++){
		for(yoko=1;yoko<=W;yoko++){
				if(tate%2==0&&yoko%2==0||tate%2!=0&&yoko%2!=0){printf("#");
				}else{printf(".");}
			
			
		}printf("\n");
		}printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
X, Y = [int(x) for x in input().split()]
flag = True

if not 2*X <= Y <= 4*X:
  flag = False
if not 0 <= (Y-2*X)/2 <= X:
  flag = False
if (Y-2*X)/2.0 != int((Y-2*X)/2):
  flag = False
  
if flag:
  print('Yes')
else:
  print('No')
  


Measured memory_bytes: 9184
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jcg
 */

#include <iostream>

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

class CAlchemist
{
public:
    void solve(std::istream& in, std::ostream& out)
    {
        int n;
        in >> n;

        std::vector<long double> a(n);
        for (auto &x : a) in >> x;
        std::sort(a.rbegin(), a.rend());

        while (a.size() > 1)
        {
            long double x = (a.end()[-1] + a.end()[-2]) / 2;
            a.pop_back(); a.pop_back();
            a.push_back(x);
            std::inplace_merge(a.begin(), prev(a.end()), a.end(), std::greater<long double>());
        }
        out << std::fixed << std::setprecision(20) << a[0] << '\n';
    }
};


int main()
{
    std::ios_base::sync_with_stdio(0);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    in.tie(0);
    CAlchemist solver;
    solver.solve(in, out);
    return 0;
}


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

int main() {
	int n;

	while (1){
		cin >> n;
		if (!n) break;

		string f;

		int a = 0, b = 0, c = 1, d = 1;
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			cin >> f;

			if (f == "lu") {
				a = 1, c = 0;
			}
			if (f == "ru") {
				b = 1, d = 0;
			}
			if (f == "ld") {
				a = 0, c = 1;
			}
			if (f == "rd") {
				b = 0, d = 1;
			}

			if (ans % 2 == 0 && a == 1 && b == 1) { //床から台
				ans += 1;
			}
			if (ans % 2 == 1 && c == 1 && d == 1) { //台から床
				ans += 1;
			}
		}
		cout << ans << endl;
	}
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<pair<ll, ll> > x(n);
    vector<pair<ll, ll> > y(m);
    for(int i = 0; i < n; i++){
        ll a, b; cin >> a >> b;
        x[i] = make_pair(a, b);
    }
    for(int i = 0; i < m; i++){
        ll c, d; cin >> c >> d;
        y[i] = make_pair(c, d);
    }

    for(int i = 0; i < n; i++){
        ll dis = 1LL << 60, num = 0;
        for(int j = 0; j < m; j++){
            ll nx = abs(x[i].first - y[j].first);
            ll ny = abs(x[i].second - y[j].second);
            if(nx + ny < dis){
                dis = nx + ny;
                num = j + 1;
            }
        }
        cout << num << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a, b;
   cin >> a >> b;
   cout << (a < b ? string(b, '0' + a) : string(a, '0' + b)) << endl;
   ;
   return 0;
}


Measured memory_bytes: 384
import java.util.*;


public class Main {
    static void solve() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == '1') count++;
        }

        System.out.println(count);
    }

    public static void main(String[] args) {
        solve();
    }
}


Measured memory_bytes: 21844
H, W = map(int, input().split())
H, W = max(H, W), min(H, W)


def hhcut(H, W):
    ans = 10**10
    for i in range(1, H-1):
        S1 = i*W

        h = H-i  # 残りの高さ
        if h % 2 == 0:
            S2 = S3 = h*W//2
        else:
            S2 = (h+1)//2*W
            S3 = (h-1)//2*W

        ans = min(ans, max(S1, S2, S3)-min(S1, S2, S3))
    return ans


def vhcut(H, W):
    ans = 10**10
    for i in range(1, H):
        S1 = i*W

        h = H-i  # 残りの高さ
        if W % 2 == 0:
            S2 = S3 = h*W//2
        else:
            S2 = (W+1)//2*h
            S3 = (W-1)//2*h

        ans = min(ans, max(S1, S2, S3)-min(S1, S2, S3))
    return ans


if W == 1:
    print(hhcut(H, W))
elif W == 2:
    print(min(hhcut(H, W), vhcut(W, H), vhcut(H, W)))
else:
    print(min(hhcut(H, W), hhcut(W, H), vhcut(W, H), vhcut(H, W)))


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

int c[26];
int go[26][100000];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin>>s>>t;
	long long int ans=0;
	memset(go,-1,sizeof go);
	memset(c,-1,sizeof c);
	for(int i=s.size()-1;i>=0;i--)
		c[s[i]-'a']=i+s.size();
	for(int i=s.size()-1;i>=0;i--){
		for(int j=0;j<26;j++)
			go[j][i]=c[j];
		c[s[i]-'a']=i;
	}
	int x;
	x=c[t[0]-'a'];
	ans=x+1;
	if(x==-1){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<t.size();i++){
		if(go[t[i]-'a'][x]==-1){
			cout<<-1<<endl;
			return 0;
		}
		ans+=go[t[i]-'a'][x]-x;
		x=go[t[i]-'a'][x]%s.size();
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10704
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        if (b - a + 1 >= k * 2) {
            for (int i = a; i < a + k; i++) {
                System.out.println(i);
            }
            for (int i = b - k + 1; i <= b; i++) {
                System.out.println(i);
            }
        } else {
            for (int i = a; i <= b; i++) {
                System.out.println(i);
            }
        }
    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#define lson pos<<1
#define rson pos<<1|1
#define ll long long
using namespace std;
const int maxn=60;
char a[2][maxn];
const int mod=1e9+7;
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",a[0]);
    scanf("%s",a[1]);
    ll t=1,s=0;
    for(int j=0; j<n; j++)
    {
        if(a[0][j+1]==a[0][j])
        {
            j++;
            if(s==0)
            {
                t=t*6%mod;
                s=2;
            }
            else if(s==1)
            {
                t=t*2%mod;
                s=2;
            }
            else if(s==2){
                t=t*3%mod;
                s=2;
            }
        }
        else
        {
            if(s==0)
            {
                t=t*3%mod;
                s=1;
            }
            else if(s==2)
            {
                t=t;
                s=1;
            }
            else if(s==1)
            {
                t=t*2%mod;
            }
        }
    }
    printf("%lld\n",t%mod);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[(int)1e6+5];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&arr[i]);
	}
	sort(arr,arr+n);
	ll ans=1;
	bool exist=true;
	for(int i=1;i<n;i++){
		if(arr[i]!=arr[i-1]){
			exist=true;
			ans++;
		}
		
		else{
			if(exist==1){
				ans--;
			}
			
			else{
				ans++;
			}
			exist^=1;
			
		}
	}
	
	printf("%lld\n",ans);
	
	
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n,k;cin>>n>>k;
    while(k--)
	{
		 int x;
		 cin>>x;
		 if(n>0)
		 n-=x;
	}
	if(n<=0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll mi=1LL<<60;
	cin>>A>>B>>C;
	
	mi=min(mi,B*C*((A-A/2)-A/2));
	mi=min(mi,A*C*((B-B/2)-B/2));
	mi=min(mi,A*B*((C-C/2)-C/2));
	
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int r,c;
    int s[1000][1000]={};
    cin>>r>>c;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            s[i][c]=s[i][c]+s[i][j];
        }
        s[r][c]=s[r][c]+s[i][c];
    }
    for(int j=0;j<c;j++){
        for(int i=0;i<r;i++){
            s[r][j]=s[r][j]+s[i][j];
        }
    }
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j==c){
                cout<<s[i][j];
            }
            else{
                cout<<s[i][j]<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 6988
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
int main(void){
  int a,b,sa;
  scanf("%d%d",&a,&b);
  sa=b-a;
  int t1,i,sum=0;
  for(i=1;i<sa;i++){
    sum+=i;
  }
  printf("%d",sum-a);
  return 0;
}

Measured memory_bytes: 128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN3(n,a,b);
  OUT(min(n*a,b));
}

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

using namespace std;

int main()
{
	char s[101];
	cin >> s;
	
	int i = 0;
	bool p = true;
	while (s[i] != '\0') {
		if (s[i++] == 'L') {
			p = false;
			break;
		}
		if (s[i] == '\0')
			break;
		else if (s[i++] == 'R') {
			p = false;
			break;
		}
	}
	
	switch(p) {
	 case true: cout << "Yes"; break;
	 case false: cout << "No"; break;
	}
}

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

using namespace std;

#define ll long long
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cmax(a,b)		a = max (a, b)
#define cmin(a,b)		a = min (a, b)

const int MAXN = 2e5 + 5;
const int oo = 0x3f3f3f3f;

int N, M, a[MAXN], mark[MAXN], ans = 0, cnt[MAXN];

void inc(int o){
	cnt[o]++;
	if (o - cnt[o] + 1 >= 1) {
		mark[o - cnt[o] + 1]++;
		if (mark[o - cnt[o] + 1] == 1) ans--;
	}
}

void dec(int o){
	if (o - cnt[o] + 1 >= 1) {
		mark[o - cnt[o] + 1]--;
		if (mark[o - cnt[o] + 1] == 0) ans++;
	}
	cnt[o]--;
}

int main(){
	scanf("%d%d", &N, &M);
	up (i, 1, N) scanf("%d", &a[i]);
	ans = N;
	up (i, 1, N) inc(a[i]);
	while (M--) {
		int x, y;
		scanf("%d %d", &x, &y);
		dec(a[x]);
		inc(a[x] = y);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3712
N=int(input())
hyx=[list(map(int,input().split()))[::-1]for _ in range(N)]
R=range(101)
for X in R:
    for Y in R:
        h,y,x=max(hyx)
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,y,x in hyx):
            print(X,Y,H)

Measured memory_bytes: 9100
N = int(input())
X = list(map(int, input().split()))


def variance(x):
    avg = sum(X) // len(X)
    return (avg - x) ** 2


def main(X):
    tot = 0
    tot2 = 0
    for x in X:
        tot += variance(x)
        tot2 += variance(x - 1)
    return min(tot, tot2)


ans = main(X)
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
X = int(input())

Y = 1 # A-B
flg = 0

while flg==0:
  if X%Y==0 and (Y**4-X//Y)%5==0:
    Z1 = Y*Y
    Z0 = (Y**4-X//Y)//5
    A = 1
    B = A-Y
    while True:
      if (A*B)**2+Z1*A*B == -Z0:
        print(A,B)
        flg = 1
        break
      elif B>0 and (A*B)**2+Z1*A*B > -Z0:
        break
      A += 1
      B += 1
  Y += 1

Measured memory_bytes: 9200
main = do
  nIn <- getLine
  s <- getLine
  let
    n = head $ map read $ words nIn :: Int
    count c ls ret
      | ls == [] = ret
      | head ls == c = count c (tail ls) (ret+1)
      | otherwise = count c (tail ls) ret
    -- cnt1 : left b to w , cnt2 : right w to b
    fun s cnt1 cnt2 ret
      | s == [] = min (cnt1+cnt2) ret
      | head s == '#' = fun (tail s) (cnt1+1) cnt2 (min (cnt1+cnt2) ret)
      | head s == '.' = fun (tail s) cnt1 (cnt2-1) (min (cnt1+cnt2) ret)
    in
    putStrLn $ show $ fun s 0 (count '.' s 0) n


Measured memory_bytes: 13948
#include<stdio.h>
int main()
{
    int n,k,x,y;
    scanf("%d\n%d\n%d\n%d",&n,&k,&x,&y);
    if(n<=k)
    {
        printf("%d\n",n*x);
    }
    else
    {
    printf("%d\n",(k*x)+((n-k)*y));
    }
} 

Measured memory_bytes: 2132
#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>;

int main(){
    int x, t;
    cin >> x >> t;
    cout << max(x - t, 0) << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
    cin >> n >> s;
    int cnt = 0;
    for(int i = 0; i < 1000; ++i) {
        string check;
        if(i < 10) {
            check = "00";
            string indata = to_string(i);
            check += indata;
        }else if(i < 100) {
            check = "0";
            string indata = to_string(i);
            check += indata;
        }else {
            check = to_string(i);
        }

        int chidx = 0;
        for(int j = 0; j < n; ++j) {
            if(check.at(chidx) == s.at(j)) chidx++;
            if(chidx == 3) {
                cnt++;
                break;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>

const int MOD = (int)1e9 + 7;

bool is_prime(int n)
{
    for (int i = 2; i * i <= n; ++ i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int count(int p, int n)
{
    int result = 0;
    while (n) {
        result += n /= p;
    }
    return result;
}

int main()
{
    int n;
    while (scanf("%d", &n) == 1) {
        int result = 1;
        for (int p = 2; p <= n; ++ p) {
            if (is_prime(p)) {
                result = (long long)result * (1 + count(p, n)) % MOD;
            }
        }
        printf("%d\n", result);
    }
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;
import java.util.LinkedList;


public class Main {
	static int n;
	static int[][] a;
	static int[] d;
	static int[] f;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		n = sc.nextInt();
		a = new int[n][n];
		d = new int[n];

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				a[u - 1][sc.nextInt() - 1] = 1;
			}
			
			d[i] = -1;
		}

		LinkedList<Integer> q = new LinkedList<Integer>();
		q.add(1);
		d[1 - 1] = 0;

		for (; !q.isEmpty(); ) {
			int u = q.remove();
			for (int i = 0; i < n; i++) {
				if (a[u - 1][i] != 0) {
					if (d[i] == -1) {
						q.add(i + 1);
						d[i] = d[u - 1] + 1;
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			pr.print(i + 1);
			pr.print(" ");
			pr.print(d[i]);
			pr.println("");
		}

		pr.close();
		sc.close();
	}
	
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;
		
		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}
		
		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}
			
			return st.sval;
		}
		
		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}
			
			return (int)st.nval;
		}

		void close() {
		}
	}
	
	private static class Printer {
		PrintStream out;
		StringBuffer strbuf;
		int bufSize;
		final String CR;

		Printer(PrintStream out) {
			this.out = out;
			strbuf = new StringBuffer();
			bufSize = 64 * 1024;
			CR = System.getProperty("line.separator");
		}

		void println(String str) {
			strbuf.append(str);
			strbuf.append(CR);
			checkStringBuffer();
		}

		void print(String str) {
			strbuf.append(str);
			checkStringBuffer();
		}

		void println(int n) {
			strbuf.append(n);
			strbuf.append(CR);
			checkStringBuffer();
		}

		void print(int n) {
			strbuf.append(n);
			checkStringBuffer();
		}

		void print(char c) {
			strbuf.append(c);
			checkStringBuffer();
		}

		void printArray(int[] array) {
			for (int i = 0; i < array.length; i++) {
				checkStringBuffer();
				strbuf.append(array[i]);
				strbuf.append(" ");
			}
			strbuf.delete(strbuf.length() - 1, strbuf.length());
			strbuf.append(CR);
		}

		void close() {
			flashStringBuffer();
		}
		
		private void flashStringBuffer() {
			if (strbuf.length() > 0) {
				out.print(strbuf);
				strbuf.setLength(0);
			}
		}
		
		private void checkStringBuffer() {
			if (strbuf.length() > bufSize) {
				out.print(strbuf);
				strbuf.setLength(0);
			}
		}
	}
}

Measured memory_bytes: 16920
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <numeric>
#include <climits>
#include <deque>
#include <random>
#include <functional>
#include <unordered_map>
#define rep(i,n) for(int i=0;i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
#define MAX_N 100005
int par[MAX_N];
int ran[MAX_N];

void init(int n){
    rep(i,n){
        par[i] = i;
        ran[i] = 0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    
    if(ran[x] < ran[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(ran[x] == ran[y]) ran[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}
vector<int>g[100005];
int main(){
    int n,m;
    cin >> n >> m;
    int k;
    init(n);
    rep(i,n){
        cin >> k;
        int l;
        rep(j,k){
            cin >> l;
            l--;
            g[l].push_back(i);
        }
    }
    rep(i,m){
        if(g[i].size()>=2)rep(j,g[i].size()-1){
            //cout << g[i][j] << " ";
            //cout << g[i][j] << " "<< g[i][j+1] << endl;
            unite(g[i][j],g[i][j+1]);
        }
        //cout << endl;
    }
    int same = find(0);
    rep(i,n){
        if(same != find(i)){
            cout <<"NO" << endl;
            return 0;
        }
    }
    cout <<"YES" << endl;
}

Measured memory_bytes: 4864
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }


    let mut map = HashMap::new();
    let mut a_num = 1;
    for numb in a.iter() {
        let count = map.entry(*numb).or_insert(0);
        *count += 1;
        a_num += 1;
    }

    for j in 1..a_num+1 {
        match map.get(&j) {
            Some(ans) => { println!("{:?}", ans) },
            None => { println!("{:?}", 0) },
        }
    }
}

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

//input
string s, t;

//dp table
long long dp[3010][3010] = {0};

int main() {
    cin >> s >> t;

    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    
    while (i > 0 && j > 0)
    {
        if (dp[i][j] == dp[i-1][j]) {
            --i;
        }

        else if (dp[i][j] == dp[i][j-1]) {
            --j;
        }

        else {
            res = s[i-1] + res;
            --i; --j;
        }

    }

    cout << res << endl;
}


Measured memory_bytes: 70784
<?php
$a = fgets(STDIN);
$ts = explode(" ",trim(fgets(STDIN)));
$sum = 1;
$max = 10**18;
$flg = false;
for ($i=0;$i<intval($a);$i++){
  if($ts[$i] == 0){
    echo '0';
    return;
  }
  $sum *= $ts[$i];
}
if($sum > $max){
  $flg = true;
  $sum = 1;
}else{
  $flg = false;
}
 
if($flg){
  echo '-1';
  exit;
}
 
echo $sum;

Measured memory_bytes: 25552
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
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;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗を1000000007で割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= 1000000007;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= 1000000007;
	}
	return tmp;
}

int main() {
	llint a, b;
	cin >> a >> b;
	cout << power(a, b) << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  string s[n]; int t[n];
  rep(i,n) cin >> s[i] >> t[i];
  string x;
  cin >> x;
  int ans = 0;
  bool f = false;
  rep(i,n) {
    if(f) ans += t[i];
    if(s[i] == x) f = true;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

vector<LL> loc[128];
string s,t;
int main() {
	cin >> s >> t;
	for(int i=0;i<s.size();i++){
		loc[(int)s[i]].push_back(i);
	}
	LL n=s.size();
	LL pos=0;
	LL p2=0;
	for(auto c:t){
		int v=(int)c;
		if(loc[v].size()==0){
			pos=-1;
			break;
		}
		auto it=lower_bound(loc[v].begin(),loc[v].end(),p2);
		if(it==loc[v].end()){
			pos+=n-p2+loc[v][0]+1;
		}
		else{
			pos+=*it-p2+1;
		}
		p2=pos%n;
	}
	cout << pos  << endl;


	return 0;
}



Measured memory_bytes: 1656
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 105;
int n, m, k, P, dp[MAXN][MAXN][MAXN][2];
int binom[MAXN][MAXN], coef[MAXN][MAXN][MAXN][2];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
int main()
{
	scanf("%d%d%d%d", &n, &m, &k, &P);
	dp[1][0][0][0] = 1;
	for (int i = 0; i <= max(n, m); i++) {
		binom[i][0] = 1;
		for (int j = 1; j <= i; j++)
			binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % P;
	}
	for (int t = 1; t <= k; t++)
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			int tmp = (power(t, m - i) - power(t - 1, m - i) + P) % P;
			tmp = 1ll * tmp * power(k - t + 1, i) % P;
			coef[t][i][j][0] = power(tmp, j);
		}
	}
	for (int t = 1; t <= k; t++)
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			int tmp = (power(k - t + 1, i) - power(k - t, i) + P) % P;
			tmp = 1ll * tmp * power(t, n - i) % P;
			coef[t][i][j][1] = power(tmp, j);
		}
	}
	for (int t = 1; t <= k; t++) {
		for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++) {
			int tmp = dp[t][i][j][0];
			for (int k = 0; i + k <= n; k++)
				update(dp[t][i + k][j][1], 1ll * tmp * binom[n - i][k] % P * coef[t][j][k][0] % P);
			tmp = dp[t][i][j][1];
			for (int k = 0; j + k <= m; k++)
				update(dp[t + 1][i][j + k][0], 1ll * tmp * binom[m - j][k] % P * coef[t][i][k][1] % P);
		}
	}
	printf("%d\n", dp[k + 1][n][m][0]);
}


Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        sum=sum+i;
    }
    cout<<sum;
}

Measured memory_bytes: 3676
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0

n=I()
a=LI()
s=set()
for i in a:
    s.add(i)

if len(s)==n:
    k=0
else:
    k=1
print(YN[k])

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

using namespace std;

int main(){
    int N= 0;
    //cout <<"N = ";
    cin >> N;
    vector<double> v;
    for(int i = 0; i < N; ++i ){
        double t = 0;
        cin >> t;
        v.push_back(t);
    }
    sort(v.begin(),v.end());
    double sum = 0;
    for(int i = 0; i < v.size(); ){
        sum = (v[i] +v[i+1])*0.5;
        v.push_back(sum);
        v.erase(v.begin()+i);
        v.erase(v.begin()+i);
        sort(v.begin(),v.end());
    }
    cout <<v[0] <<endl;
    return 0;
}





Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ARoundUpTheMean {
public:
	void solve(istream& in, ostream& out) {
        double a, b; in >> a >> b;
        out << ceil((a + b) / 2) << endl;
	}
};

int main() {
	ARoundUpTheMean solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fint register int
#define p 479853
#define h 5001
#define int long long
using namespace std;
int a[p];
signed main()
{
	int n;
	cin>>n;
	for(fint i=1;i<=n;i++)
	cin>>a[i];
	int ans=0;
	for(fint i=1;i<=n;i++)
	for(fint j=i;j<=n;j++)
	for(fint k=j;k<=n;k++)
	if(i!=j&&j!=k&&i!=k&&a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j]&&a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
	ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3612
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

#[fastout]
fn main() {
  input! {
    h : usize, w : usize, k : usize,
  };
  input! {
    c : [Chars; h],
  };

  let mut res = 0usize;
  for rows in 0..(1 << h) {
    for cols in 0..(1 << w) {
      let mut cnt = 0;
      for i in 0..h {
        if rows & (1 << i) != 0 {
          continue;
        }
        
        for j in 0..w {
          if cols & (1 << j) != 0 {
            continue;
          }
          
          if c[i][j] == '#' {
            cnt += 1;
          }
        }
      }

      if cnt == k {
        res += 1;
      }
    }
  }
  
  println!("{}", res);
}

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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 1e9 + 7;
const int MX = (int)2e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

void pre(){
}	

void solve(){
	ll x, k, d;
	cin >> x >> k >> d;
	ll dist = abs(x);

	ll res = 9e18;

	// if(k == 1)
	// 	res = abs(dist - d);
	// else{
		// if(k % 2 == 0)
		// 	res = min(res, dist); // maybe this is okay?
		ll steps_to_origin = min(k, dist / d);
		ll rem = k - steps_to_origin;
		if(rem & 1)
			res = abs(dist - (steps_to_origin + 1) * d); // try taking one more step, now u should cross the origin to the other side
		else
			res = abs(dist - steps_to_origin * d);
	// }
	
	cout << res << "\n";
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": \n";
		solve();
	}

	return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	bool ans = true;
	if (s[0] != 'A')ans = false;
	int c = 0;
	for (int i = 2; i < s.size() - 1; i++)
	{
		if (s[i] == 'C')c++;
	}
	if (c != 1)ans = false;
	loop(i, s.size())
	{
		if (s[i] != 'A'&&s[i] != 'C'&&s[i] && !((s[i] >= 'a') && (s[i] <= 'z')))ans = false;
	}
	cout << (ans ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
N,X=map(int,input().split())

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

x=[]
for _ in input().split():
    x.append(int(_))

dist=[abs(x[0]-X)]
for i in range(len(x)-1):
    dist.append(abs(x[i+1]-x[i]))

if len(dist)>1:
    D=gcd(dist[0],dist[1])
    for i in range(len(dist)):
        D=gcd(D,dist[i])
else:
    D=dist[0]

print(D)

Measured memory_bytes: 14228
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> d(n);
	std::vector<i64> a(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &d[i]);

		a[d[i]]++;
	}
	if(d[0] != 0 or a[0] != 1) {
		printf("0\n");
		return 0;
	}

	for(int i = 1; i < n; i++) {
		if(!a[i]) continue;
		if(!a[i - 1]) {
			printf("0\n");
			return 0;
		}
	}

	i64 ans = 1;
	const int MOD = 998244353;
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < a[i]; j++) (ans *= a[i - 1]) %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    double m = (double)sum / n;

    int index = 0;
    double d = 10000;
    for (int i = 0; i < n; i++) {
        if (abs(m - a.at(i)) < d) {
            index = i;
            d = abs(m - a.at(i));
        }
    }

    cout << index << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, a;
    cin >> n >> a;
    vs64 x(n);
    s64 max_x = 0;
    rep (i, n)
    {
        cin >> x[i];
        max_x = max(max_x, x[i]);
    }

    s64 dp[n + 1][n + 1][n * max_x + 1];
    rep (i, n + 1) rep (j, n + 1) rep (k, n * max_x + 1) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep (i, n)
    {
        rep (j, n + 1)
        {
            rep (k, n * max_x + 1)
            {
                if (j > 0 && k - x[i] >= 0)
                {
                    dp[i + 1][j][k] += dp[i][j][k] + dp[i][j - 1][k - x[i]];
                }
                else
                {
                    dp[i + 1][j][k] += dp[i][j][k];
                }
            }
        }
    }

    s64 ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n * max_x; ++j)
        {
            if (j % i == 0 && j / i == a)
            {
                ans += dp[n][i][j];
            }
        }
    }

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



Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  LL n, z, w;
  cin >> n >> z >> w;
  vector<LL> a(n);
  rep(i, n) cin >> a[i];

  if (n == 1) {
    cout << abs(a[0] - w) << endl;
  } else {
    cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
#define nl (next_num<lint>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
lint solve(lint l,lint r){
	if(l>r){
		return 0;
	}
	if(l==r){
		return 1;
	}
	lint hi=1;
	for(;hi<=(l^r);hi<<=1);
	hi--;
	l&=hi,r&=hi;
	hi++;
	hi>>=1;
	assert(r&hi);
	assert((l&hi)==0);
	lint a=r^hi,b=l;
	lint ans=(hi-1)-b+1;//0 | 1
	lint hi2=1;
	for(;hi2<=a;hi2<<=1);
	ans+=min(hi2,b);//1 | 1
	ans+=solve(b,hi-1);//0 | 0
	return ans;
}
int main(){
	lint l=nl,r=nl;
	printf("%lld\n",solve(l,r));
	return 0;
}

Measured memory_bytes: 256
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0: break
    for j in range(h):
        for i in range(w):
            if (i + j)%2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7004
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (signed long long int i = (signed long long int)(k); i < (signed long long int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define loop(n) rep(looping, n);
#define rREP(i, k, n) for (signed long long int i = (signed long long int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end())
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::max;
using std::abs;
using std::next_permutation;
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
using LL = signed long long int;
using VL = V<LL>;
using VVL = V<VL>;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f; //1061109567
const LL LLINF = 0x3f3f3f3f3f3f3f3fLL; //4557430888798830399
const double PI = M_PI;
template<class T,class U>inline LL min(T a, U b){return std::min((LL)a, (LL)b);}
template<class T,class U>inline LL max(T a, U b){return std::max((LL)a, (LL)b);}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});os<<"}\n";
    }
}

void Main(){
    cill(n);
    cill(k);
    VL vl(n);
    vcin(vl);
    SORT(vl);
    LL ans=0;
    rep(i, k){
        ans+=vl[i];
    }
    co(ans);
}


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int result = 0;
        if (s.indexOf("RRR") > -1) {
            result = 3;
        } else if (s.indexOf("RR") > -1) {
            result = 2;
        } else if (s.indexOf("R") > -1) {
            result = 1;
        }
        System.out.println(result);

    }
}

Measured memory_bytes: 35544