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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP (i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector <vector<int>>;
using vvll = vector <vector<ll>>;

#define inf(T) (numeric_limits<T>::max() / 2)
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int n; cin >> n;
        if (n == 0) break;

        vi a(n);
        REP(i, n) cin >> a[i];
        sort(all(a));

        int ans = inf(int);
        REP(i, n-1) chmin(ans, a[i+1] - a[i]);

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3168
import math
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
before=math.fabs(t-h[0]*0.006-a)
num=1
for i in range(n-1):
  diff=before-math.fabs(t-h[i+1]*0.006-a)
  if diff>0:
    before=math.fabs(t-h[i+1]*0.006-a)
    num=i+2
print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};

int w, h, res;
int m[100][100];
pii g;

void dfs(pii, int, int, pii);

int main(void){
    while(cin >> w >> h, w){
        pii s;

        rep(y, h) rep(x, w){
            cin >> m[y][x];
            if(m[y][x] == 2) s = mp(x, y), m[y][x] = 0;
            if(m[y][x] == 3) g = mp(x, y);
        }

        res = INF;
        dfs(s, 0, 0, mp(0, 0));
        if(res == INF) res = -1;

        cout << res << endl;
    }

    return 0;
}

void dfs(pii p, int n, int d, pii dxy){
    if(p.X < 0 || w <= p.X ||
       p.Y < 0 || h <= p.Y) return;
    if(n == 11) return;

    if(p == g){ res = min(n, res); return; }

    if(d != 0){
        if(m[p.Y][p.X] == 1){
            if(d == 1) return;
            else{
                m[p.Y][p.X] = 0;
                dfs(mp(p.X - dxy.X, p.Y - dxy.Y), n, 0, dxy);
                m[p.Y][p.X] = 1;
            }
        }
        else dfs(mp(p.X + dxy.X, p.Y + dxy.Y), n, d + 1, dxy);
    }
    else rep(i, 4) dfs(mp(p.X + dx[i], p.Y + dy[i]), n + 1, 1, mp(dx[i], dy[i]));
}

Measured memory_bytes: 1180
import heapq
N = int(input())
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
heapq.heapify(cumsum)
before = 10 ** 10
count = 0
ans = 0
while cumsum:
    now = heapq.heappop(cumsum)
    count += before == now
    if not (before == now and cumsum):
        ans += count * (count + 1) // 2
        count = 0
    before = now
print(ans)


Measured memory_bytes: 25852
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 10 ** 18
for i in range(1 << n):
    c = []
    for j in range(n):
        if i >> j & 1 == 0:
            c.append(a[j])
        else:
            c.append(b[j])
    d = sorted(c)

    ind = {}
    for j, k in enumerate(d):
        if (j % 2, k) not in ind:
            ind[(j % 2, k)] = j

    e = []
    ok = True
    for j, k in enumerate(c):
        j = ((i >> j & 1) + j) % 2
        if (j, k) not in ind:
            ok = False
            break
        l = ind[(j, k)]
        if l >= n or d[l] != k:
            ok = False
            break
        e.append(l)
        ind[(j, k)] += 2

    if ok:
        count = 0
        for _ in range(n):
            for j in range(n - 1):
                if e[j] > e[j + 1]:
                    count += 1
                    e[j], e[j + 1] = e[j + 1], e[j]
        ans = min(ans, count)
if ans == 10 ** 18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 52524
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

signed main() {
    int n, x, t;
    cin >> n >> x >>t;

    if (n % x == 0) {
        cout << t * n / x;
    } else {
        cout << t * (n / x + 1);
    }

    return 0;
}


Measured memory_bytes: 3188
from sys import stdin
n=int(stdin.readline().rstrip())
#print(n)
dic={}
for i in range(n):
    s=stdin.readline().rstrip()
    if s in dic.keys():
        dic[s] +=1
    else:
        dic[s]=1
#print(dic)
#print(dic.keys())
sup=0
suc=[]
for (i,number) in dic.items():
    if number>sup:
        suc=[]
        sup=number
        suc.append(i)
    elif number==sup:
        suc.append(i)
for k in (sorted(suc)):
    print(k)

Measured memory_bytes: 32988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());

		int cost0 = 0, costN = 0, Ai;

		for (int i = 0; i < M; i++) {
			Ai = Integer.parseInt(sc.next());
			if (Ai < X) {
				cost0++;
			} else {
				costN++;
			}
		}

		if (cost0 < costN) {
			System.out.println(cost0);
		} else {
			System.out.println(costN);
		}

	}

}

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

string s;

int dp[10009][100][2],p,d;


int dfs(int idx,int z,bool tight=true){
  if(idx==s.size())return !z;
  int &res=dp[idx][z][tight];
  if(~res)return res;
  res=0;
  int x=s[idx]-'0';
  int r=(tight?x:9);
  for(int i=0;i<=r;i++){
    res+=dfs(idx+1,(z+i)%d,tight&&i==r);
    res%=1000000007;
  }
  return res;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin>>s>>d;
  cout<<(dfs(0,0)-1+1000000007)%1000000007<<endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    vector<char> ans;
    rep(i, s.size()){
        char aa = s[i];
        rep(j, 26){
            if(s[i] == a[j]){
                ans.push_back(a[j+n]);
            }
        }
    }
    rep(i, s.size()){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

ll bit_size(ll a){
    for(int i=0;i<63;i++){
        if(1<<i >= a){return i;}
    }
    return 63;
}

//1-index
template<typename T>
class BIT{
private:
    vector<T> bit;
    ll size;
    
public:
    BIT(vector<T> t){
        size=bit_size(t.size());
        bit.resize((1<<size)+1);
        for(int i=1;i<=t.size();i++){
            change(i,t[i-1]);
        }
    }
    
    BIT(ll s){
        size=bit_size(s);
        bit.resize((1<<size)+1);
    }
    
    BIT(ll s,T a){
        size=bit_size(s);
        bit.resize((1<<size)+1,a);
    }
    
    void add(ll where,T a){
        while(where<bit.size()){
            bit[where]+=a;
            where+=where&-where;
        }
    }
    
    //[1,r]
    T sum(ll r){
        T ret=0;
        while(r>0){
            ret+=bit[r];
            r=r&(r-1);
        }
        return ret;
    }
    
    //[l,r]
    T sum(ll l,ll r){
        T ret=sum(r);
        ret-=sum(l-1);
        return ret;
    }
};

vector<ll> a;

ll J;

bool judge(ll number){
    vector<ll> k(a.size(),0);
    ll count=0;
    for(int i=0;i<a.size();i++){
        if(a[i]>=number){k[i]=1;}
        if(a[i]<number){k[i]=-1;}
    }
    const ll C=110000;
    k[0]+=C;
    for(int i=1;i<k.size();i++){
        k[i]+=k[i-1];
    }
    BIT<ll> bit(2*C);
    bit.add(C,1);
    //for(int i=0;i<k.size();i++){
        //cout<<k[i]<<" ";
    //}
    //cout<<endl;
    for(int i=0;i<k.size();i++){
        count+=bit.sum(k[i]);
        //cout<<a[i]<<" "<<bit.sum(k[i])<<endl;
        bit.add(k[i],1);
    }
    //cout<<number<<" "<<J<<" "<<count<<endl;
    return count>=J;
}



int main(){
    ll n;
    cin>>n;
    vector<ll> A;
    J=n*(n+1)/2;
    J=(J+1)/2;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
        A.push_back(b);
    }
    sort(A.begin(),A.end());
    ll L=0;
    ll R=A.size();
    while(R-L>1){
        ll mid=L+(R-L)/2;
        if(judge(A[mid])){L=mid;}
        else{R=mid;}
    }
    ll ans=L;
    for(ll i=R-1;i>=L;i--){
        if(judge(A[i])==true){ans=i; break;}
    }
    //cout<<ans<<endl;
    cout<<A[ans]<<endl;
    
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? 0 : 1) << "\n";
}
int gauss_jordan(vector<vector<int>> &A) {
    int m = A.size(), n = A[0].size();
    int rank = 0;
    for (int col = 0; col < n; ++col) {
        // ピボットを探す
        int pivot = -1;
        int ma = 0;
        for (int row = rank; row < m; ++row) {
            if (abs(A[row][col]) > ma) {
                ma = abs(A[row][col]);
                pivot = row;
            }
        }
        // ピボットがなかったら次の列へ
        if (pivot == -1) continue;

        // まずは行を swap
        swap(A[pivot], A[rank]);

        // ピボットの値を 1 にする
        //auto fac = A[rank][col];
        //for (int col2 = 0; col2 < n; ++col2) A[rank][col2] /= fac;

        // ピボットのある列の値がすべて 0 になるように掃き出す
        for (int row = 0; row < m; ++row) {
            if (row != rank && abs(A[row][col]) > 0) {
                for (int col2 = 0; col2 < n; ++col2) {
                    A[row][col2] = A[row][col2] ^ (A[rank][col2]);
                }
            }
        }
        ++rank;
    }
    for (int row = 0; row < m; ++row) {
        for(int row2 = row+1; row2<m; ++row2) {
            REP(k, n) {
                if(A[row2][k] == 1) {
                    if(A[row][k] == 1) {
                        for (int col2 = 0; col2 < n; ++col2) {
                            A[row][col2] = A[row][col2] ^ (A[row2][col2]);
                        }
                    }
                    break;
                } 
            }
        }
    }
    return rank;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    REP(t, T) {
        int N;
        cin >> N;
        vector<lint> A(N);
        REP(i, N) cin >> A[i];
        string S;
        cin >> S;
        set<lint, greater<lint>> st;
        bool flg = true;
        IREP(i, N) {
            for(lint x : st) A[i] = min(A[i], A[i]^x);
            if(S[i] == '0') {
                if(A[i] > 0) st.insert(A[i]);
            } else {
                if(A[i] > 0) {
                    flg = false;
                    break;
                }
            }
        }
        yes(flg);  
    }
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        OUT:for (long i = 1; i <= 3500; i++) {
            for (long j = 1; j <= 3500; j++) {
                long k = Math.round((double)(n*i*j)/(double)(4*i*j-n*i-n*j));
                if(k>0&&4*i*j*k==n*(i*j+j*k+k*i)){
                    System.out.printf("%d %d %d",i,j,k);
                    break OUT;
                }
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,y,z,money,s;
int main() {
	cin>>a>>b>>c>>money;
	for(x=0;x<=a;x++){
		for(y=0;y<=b;y++){
			for(z=0;z<=c;z++){
				if(x*500+y*100+z*50==money)
				++s;
			}
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,ans=1;
  scanf("%d/n",&N);
  char S[100002];
  scanf("%s",S);
  for(int i=1;i<N;i++)
    if(S[i]!=S[i-1]) ans++;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1828
#include<stdio.h>

int main(){
	int dice[6],q,i;
	char c;

	for(i=0;i<6;i++){
	scanf("%d",&dice[i]);
	}

	scanf("%d",&q);
	for(i=0;i<q;i++){
	int x,y;
	scanf("%d %d",&x,&y);
	if((x==dice[5] && y==dice[4])||(x==dice[4] && y==dice[0])||(x==dice[0] && y==dice[1])||(x==dice[1] && y==dice[5])){
		printf("%d\n",dice[2]);
	}else if((x==dice[0] && y==dice[2])||(x==dice[2] && y==dice[5])||(x==dice[5] && y==dice[3])||(x==dice[3] && y==dice[0])){
		printf("%d\n",dice[4]);
	}else if((x==dice[5] && y==dice[1])||(x==dice[1] && y==dice[0])||(x==dice[0] && y==dice[4])||(x==dice[4] && y==dice[5])){
		printf("%d\n",dice[3]);
	}else if((x==dice[0] && y==dice[3])||(x==dice[3] && y==dice[5])||(x==dice[5] && y==dice[2])||(x==dice[2] && y==dice[0])){
	printf("%d\n",dice[1]);
	}else if((x==dice[2] && y==dice[1])||(x==dice[1] && y==dice[3])||(x==dice[3] && y==dice[4])||(x==dice[4] && y==dice[2])){
		printf("%d\n",dice[5]);
	}else{
		printf("%d\n",dice[0]);
	}
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

void solve() {
	int n; cin >> n;
	vector<int> w(n);
	rep(i, n) {
		cin >> w[i];
	}
	int ans = mod;
	rep1(i, n - 1) {
		int le = 0, ri = 0;
		rep(j, n) {
			if (j <= i)le += w[j];
			else ri += w[j];
		}
		ans = min(ans, abs(ri - le));
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    string s; cin>>s;
    ll cnt = 0;
    char tmp = 'a';
    for(char c : s){
        if(tmp != c){
            cnt++;
            tmp = c;
        }
    }
    OUT(cnt-1);
}

Measured memory_bytes: 512
def resolve():
    # エラトステネスのふるい
    def make_primes_table(n):
        if n < 2:
            return [False]*n
        is_prime = [True]*n
        is_prime[0] = False
        is_prime[1] = False
        for i in range(2, int(n**0.5)):
            if is_prime[i]:
                for j in range(i**2, n, i):
                    is_prime[j] = False
        return is_prime

    MAX_N = 10**5+1
    primes_table = make_primes_table(MAX_N)
    cnt = [0]*MAX_N
    for i in range(2, MAX_N):
        if primes_table[i] and primes_table[(i+1)//2]:
            cnt[i] += 1

    for i in range(1, MAX_N):
        cnt[i] += cnt[i-1]

    Q = int(input())
    for _ in range(Q):
        l, r = map(int, input().split())
        print(cnt[r] - cnt[l-1])

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 8948
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int n,c=0;
    n=in.nextInt();
    while(n>=1)
    {
      n=n-2;
      c=c+1;
    }
    System.out.println(c);
  }
}

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

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

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;

    cin >> S;
    int result = 0;
    long count = S.size()-1L;
    for(long i=0; i<count; i++) {
        if (S[i] != S[i+1]) {
            result++;
        }
    }

    cout << result;

    return 0;
}


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

class Solution
{
    static void Main()
    {
        var s = Console.ReadLine().Select(c => new HashSet<char>() { c}).ToArray();

        int count = 0;
        while (!s.First().Any(c => s.All(set => set.Contains(c))))
        {
            s = s.Zip(s.Skip(1), (a, b) => new HashSet<char>(a.Union(b))).ToArray();
            count++;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 15828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct State{
    int y,x,d;
};

const int N = 32;
const ll INF = LLONG_MAX/3;
ll dp[N][N][N*N];

const int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};

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

    rep(i,N)rep(j,N)rep(k,N*N) dp[i][j][k] = INF;

    auto IN = [&](int y, int x, int d){
        return 0<=y && y<h && 0<=x && x<w && d<N*N;
    };

    dp[0][0][0]=0;
    queue<State> que;
    que.push({0,0,0});
    while(!que.empty()){
        State s = que.front();
        que.pop();

        rep(i,4){
            int ny = s.y+dy[i], nx = s.x+dx[i], nd = s.d+1;
            if(!IN(ny,nx,nd)) continue;

            ll add = (2*s.d+1)*a[ny][nx];
            ll v = dp[s.y][s.x][s.d]+add;
            if(dp[ny][nx][nd] > v){
                dp[ny][nx][nd] = v;
                que.push({ny,nx,nd});
            }
        }
    }

    ll ans = INF;
    rep(i,N*N) ans = min(ans, dp[h-1][w-1][i]);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 11364
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<unordered_map>
#define mod 1000000007
using namespace std;
#define LL long long int 
#define MAXN   1000001 
LL spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (LL i=2; i<MAXN; i++) 
        spf[i] = i;
    for (LL i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (LL i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (LL j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}
bool repetition(LL x, map <LL,bool> &check) 
{
    map<LL,bool> factors;
    while (x != 1) 
    {  
        factors [ spf[x] ]=true;
        x = x / spf[x]; 
    }
    for(auto it:factors)
    {
        if(check[it.first]==true)
        {
            return true;
        }
        check[it.first]=true;

    }
    return false; 
} 
int main() 
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sieve();
    LL N;
    cin >> N;
    vector<LL> arr(N);
    for(auto &it:arr)
    {
        cin>>it;
    }
    map<LL,bool> check;
    bool ok=true;
    for(auto it:arr)
    {
        if(repetition(it,check)==true)
        {
            ok=false;
            break;
        }
    }
    if(ok==true)
    {
        cout<<"pairwise coprime";
    }
    else
    {
        LL gcd=arr[0];
        for(LL i=1;i<N;i++)
        {
            gcd=__gcd(gcd,arr[i]);
        }
        if(gcd==1)
        {
            cout<<"setwise coprime";
        }
        else
        {
            cout<<"not coprime";
        }
    }
}
 
 

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    vector<int32> h(n);
    REP(i,n)cin >> h[i];
    sort(ALL(h));
    int64 ans = 0;
    REP(i,n-k){
        ans += h[i];
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int maisu = n / 1000 + 1;
  int otsuri = maisu * 1000 - n;
  if(otsuri == 1000){
    otsuri = 0;
  }
  cout << otsuri << endl;
}

Measured memory_bytes: 3636
iN,iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)

aMaxD = [0]
iMin = aA[0]
iV = 0

def checkMax(aMaxD,iMaxD):
    if aMaxD[0] < iMaxD:
        aMaxD = [iMaxD]
    elif aMaxD[0] == iMaxD:
        aMaxD.append(iMaxD)
    return aMaxD

for i in range(1,iL):
    iB = aA[i-1]
    iN = aA[i]
    if iB - iN > 0:
        if iV >= 0:
            aMaxD = checkMax(aMaxD,iB-iMin)
        iV = -1
    elif iB - iN < 0:
        if iV <= 0:
            iMin = min(iB,iMin)
        iV = 1
aMaxD = checkMax(aMaxD,aA[-1] - iMin)
print( len(aMaxD) )


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

using namespace std;
#define int long long

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 1; i < n; i++) {
    if(a[i] < a[i-1]) {
      ans += a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  cout<<ans << '\n';
  return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int h, w;
int j = 0;
    while(j == 0){
        cin >> h >> w;
    if(h == 0 && w == 0){
        break;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << "#";
            if(j == w - 1)
            cout << endl;
        }
    }
    cout << endl;
}
}




Measured memory_bytes: 3088
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int d, n ;
    cin >> d >> n ;
  
    int tmp = 1 ;
    for(int i=1;i<=d;i++){
      if(d==0)break ;
      tmp *= 100 ;
    }
  if(n==100)n = 101 ;
    
    cout << tmp*n << endl ;
      
    return 0;
}


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

lst = []
i = N
while i > 0:
    for j in range(min(i, M), 0, -1):
        if S[i - j] == '0':
            lst.append(j)
            i -= j
            break
    else:
        print(-1)
        exit()
print(' '.join(map(str, reversed(lst))))


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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
}

/**
*/


Measured memory_bytes: 256
#abc085c
import sys

n,y=map(int,raw_input().split())
for a in xrange(n+1):
 for b in xrange(n+1):
  if y==10000*a+5000*b+1000*(n-a-b) and n-a-b>=0:
   print a,b,n-a-b
   sys.exit()
print '-1 -1 -1'


Measured memory_bytes: 2568
n = int(input())
a = list(map(int, input().split()))
ans = []
a_sum = sum(a)//2
a2 = a + a
l = [0 for i in range(2*n)]
for i in range(2*n):
    if i == 0:
        l[i] = 0
    elif i == 1:
        l[i] = a2[0]
    else:
        l[i] = l[i-2] + a2[i-1]
for i in range(n):
    ans.append(2*(a_sum - l[i+n-1] + l[i]))
print(" ".join(map(str, ans)))

Measured memory_bytes: 30424
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;


int main(void) {
    Int x, y;
    cin >> x >> y;
    if (x % y == 0) {
        cout << -1 << endl;
    } else {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
'use strict'
function main(input) {
  input = input.trim().split('\n')
  input.shift()
  let count = []
  let aMap = new Map
  input = input
    .map(c => {
      let arr = c.split(' ').map(w => w - 0)
      if (count[arr[0]] === undefined) count[arr[0]] = []
      count[arr[0]].push(arr[1])
      aMap.set(arr[1], '')
    })
  count.forEach((v, i) => {
    v.sort((a, b) => a - b)
    v.forEach((y, j) => {
      let id = ('000000' + i).slice(-6)
      id += ('000000' + (j+1)).slice(-6)
      aMap.set(y, id)
    })
  })
  aMap.forEach(v => console.log(v))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 76068
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp
{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x)
{
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue()
{
  P x=Q[head];
  head = (head+1)%LEN;
  return x;

}

int min(int a,int b)
{
  return a<b?a:b;
}
int main()
{
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++)
    {
      scanf("%s", Q[i].name);
      scanf("%d", &Q[i].t);
    }
  head=1;
  tail=n+1;
  
  while(head != tail)
    {
      u = dequeue();
      c = min(q,u.t);
      u.t -= c;
      elaps += c;
      if(u.t>0) enqueue(u);
      else
	{
	  printf("%s %d\n",u.name,elaps);
	}
    }
  return 0;
}



Measured memory_bytes: 11848
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ll long long
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

vector<vector<ll> > dp;
int N, W;
vector<ll> w, v;

ll calc(int i, int j) {
	if(i == N) return 0;
	if(dp[i][j] >= 0) return dp[i][j];
	if(j - w[i] >= 0) return dp[i][j] = max(calc(i+1, j), calc(i+1, j-w[i]) + v[i]);
	return dp[i][j] = calc(i+1, j);
}

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

	cin >> N >> W;
	w.resize(N);
	v.resize(N);
	REP(i, N) cin >> w.at(i) >> v.at(i);
	
	dp = vector<vector<ll> >(N, vector<ll>(W+1, -1));
	dp[0][0] = 0;
	cout << calc(0, W) << endl;
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hoge(ll i){
    if(i==1){
        return 1;
    }
    return hoge(i/2)*2+1;
}

int main(){
    ll n;cin>>n;
    cout<<hoge(n)<<endl;
    
    return 0;
}


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

int INF = 100000000;

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

  int ans = INF;
  for (int i = 1; i < n; i++) {
    int id0, id1, id2, id3, id4, id5;
    int j, jd0, jd1, jd2, jd3, jd4, jd5;

    id0 = i % 10;
    id1 = i / 10 % 10;
    id2 = i / 100 % 10;
    id3 = i / 1000 % 10;
    id4 = i / 10000 % 10;
    id5 = i / 100000;

    j = n - i;
    jd0 = j % 10;
    jd1 = j / 10 % 10;
    jd2 = j / 100 % 10;
    jd3 = j / 1000 % 10;
    jd4 = j / 10000 % 10;
    jd5 = j / 100000;

    int sum = id0 + id1 + id2 + id3 + id4 + id5 + jd0 + jd1 + jd2 + jd3 + jd4 + jd5;
    if (sum < ans) ans = sum;
  }

  cout << ans << endl;

  return 0;
}


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

dp = [float('inf')] * (n + 1)
dp[0] = 0

for i in range(1, n + 1):
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9
print(dp[-1])


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

using namespace std;


int main(void){
int n;
int arr[200001];
cin >> n;
for(int i=1;i<=n;i++)
    cin >> arr[i];
int l=1;
int r=1;
int cur=arr[1];
long long result=0;
while(1){
if(r==n || (cur^arr[r+1])!=cur+arr[r+1]){
    result+=(long long)(r-l+1);
    if(l==n)
        break;
    else if(l==r){
        l++;
        r++;
        cur=arr[r];
    }
    else{
        l++;
        cur^=arr[l-1];
    }
}
else{
    r++;
    cur^=arr[r];
}


}
cout << result;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
// #include <priority_queue>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

const int maxn = 102;

int n;
int x[maxn], y[maxn], h[maxn];

int main() {

	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i] >> h[i];
	
	for (int cx = 0; cx <= 100; ++cx)
	{
		for (int cy = 0; cy <= 100; ++cy)
		{
			bool flag = true;
			int curH = -1;
			
			for (int i = 0; i < n; ++i)
			{
				if (h[i] != 0) {
					curH = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
					break;
				}
			}

			if (curH >= 1) {
				for (int i = 0; i < n; ++i)
				{
					int dist = abs(cx - x[i]) + abs(cy - y[i]);
					if (h[i] != max(curH - dist, 0)) {
						flag = false;
						break;
					}
				}
			}

			if (flag && curH >= 1) {
				cout << cx << " " << cy << " " << curH << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
void fun(vector<int> &a, int n){
    vector<int> b(n);
    for(int i=0; i<a.size(); i++){
        int l = max(0ll, i - a[i]);
        int r = min(i+a[i], n-1);
        b[l]++;
        if( r+1 < n) b[r+1]--;
    }
    for(int i=1; i<n; i++) b[i] += b[i-1];
    for(int i=0; i<n; i++) a[i] =  b[i];
}
int32_t main()
{
    
    int n, k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    
    for(int i=0; i<min(k, 100ll); i++){
        fun(a,n);
    }
    for(int i=0; i<n; i++) cout<<a[i]<<" ";
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,m,i=0,j,h,a;
    string s;
    cin >> a >> s;
    h=s.size();
    if(a<3200)
    {
        cout << "red" << endl;
    }
    else
    {
        cout << s << endl;
    }
    
    return 0;

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

template<typename T>
class UnionFind {
    vector<T> parent;
    vector<T> rank;
public:
    UnionFind(T n) {
        init(n);
    }

    void init(T n) {
        parent.clear();
        rank.clear();
        for(int i=0; i<n; i++){
            parent.emplace_back(i);
            rank.emplace_back(0);
        }
    }

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

    void unite(T x, T y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(rank[x] < rank[y]){
            parent[x] = y;
        } else {
            parent[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(T x, T y){
        return find(x) == find(y);
    }
};

const int MX = 1e5+5;
int n,m;
vi p;
UnionFind<int> uf(MX);
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;

    p.resize(n);

    REP(i,n) {
        cin>>p[i];
        p[i]--;
    }

    REP(i,m) {
        int a,b;
        cin>>a>>b;
        a--; b--;
        uf.unite(a,b);
    }

    int ans = 0;
    REP(i,n){
        if(p[i]==i){
            ans++;
            continue;
        }

        if(uf.same(i,p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long

signed main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int ans = 0;
	map<string, int> mp;
	for (int msk = 0; msk < (1 << N); ++msk) {
		string red, blue;
		for (int i = 0; i < N; ++i) {
			if (msk & (1 << i))
				red += S[i];
			else
				blue += S[i];
		}
		++mp[red+' '+string(blue.rbegin(), blue.rend())];
	}
	for (int msk = 0; msk < (1 << N); ++msk) {
		string red, blue;
		for (int i = 0; i < N; ++i) {
			if (msk & (1 << i))
				red += S[N+i];
			else
				blue += S[N+i];
		}
		ans += mp[string(blue.rbegin(), blue.rend())+' '+red];
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int x, y, a, b, c;

int va[N_MAX];
int vb[N_MAX];
int vc[N_MAX];

multiset <int> s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x >> y >> a >> b >> c;
    for(int i = 1; i <= a; i++)
        cin >> va[i];
    for(int i = 1; i <= b; i++)
        cin >> vb[i];
    for(int i = 1; i <= c; i++)
        cin >> vc[i];
    sort(va + 1, va + a + 1);
    sort(vb + 1, vb + b + 1);
    sort(vc + 1, vc + c + 1);
    reverse(va + 1, va + a + 1);
    reverse(vb + 1, vb + b + 1);
    reverse(vc + 1, vc + c + 1);
    for(int i = 1; i <= x; i++)
        s.insert(va[i]);
    for(int i = 1; i <= y; i++)
        s.insert(vb[i]);
    for(int i = 1; i <= c; i++)
    {
        if(vc[i] > *s.begin())
        {
            s.erase(s.begin());
            s.insert(vc[i]);
        }
    }
    ll ans = 0;
    for(auto it = s.begin(); it != s.end(); it++)
        ans += *it;
    cout << ans << "\n";
    return 0;
}


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

int main(){
int K,N;
cin >> K >> N;
int A[N];
for(int i=0; i<N; i++){
    cin >> A[i];
}
int max = A[1] - A[0];
for(int j=1; j<N-1; j++){
    if((A[j+1]-A[j]) > max){
        max =  A[j+1]-A[j];
    }
}
if((K-A[N-1]+A[0]) > max){
    max = K-A[N-1]+A[0];
}
cout << K-max;
return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int digsum = 0;
        int len = Integer.toString(n).length();
        for (int i = 1; i <= len; i++) {
            int num = (int) Math.pow(10, i);
            digsum += n % num / (num / 10);
        }

        boolean judge = n % digsum == 0;
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23508
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=4e5+5;
typedef long long ll;
int n,k;
char s[N];
int num[N];
int st;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
        num[i]=s[i]-'A';
    st=num[1];
    int p=1;
    int cnt=0;//p表示删到哪里了，cnt是操作次数
    while(k--){
        if(st==0){//这是第一个是A的情况
            st^=1;
            num[p]^=1;
        }
        else{
            p++;
            cnt++;
            st=num[p];
            st^=(cnt&1);
        }
        if(p>n)
            break;
    }
    if(p<=n){
        for(int i=p;i<=n;i++)
            putchar('A'+(num[i]^(cnt&1)));
        int t=p-1,c=(cnt-1)&1;
        while(t--){
            putchar('A'+c);
            c^=1;
        }
    }
    else{
        if((cnt-1)&1)//BABA
            for(int i=1;i<=n;i++)
                putchar('A'+(i&1));
        else{//ABAB
            putchar('A'+(k&1));
            for(int i=1;i<n;i++)
                putchar('A'+(i&1));
        }
    }
}

Measured memory_bytes: 1280
n=int(input())
B=list(map(int,input().split()))
A=[]
while B:
    for i,b in enumerate(B[::-1]):
        idx=len(B)-i
        if b==idx:
            A.append(b)
            B.pop(idx-1)
            break
    else:
        break
if B:
    print(-1)
else:
    for a in A[::-1]:
        print(a)

Measured memory_bytes: 38768
#include<bits/stdc++.h>
    using namespace std;
    #define inp(k)           ll k;cin>>k;
    #define in2(n,k)       ll n, k; cin>>n;cin>>k;
    #define in3(n,k,r)       ll n, k,r; cin>>n;cin>>k;cin>>r;
    #define ll long long
    #define dl double
    #define ch char
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define rf(i,a,b) for(ll i=a-1;i>=b;i--)
    #define Godspeed                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define vpl vector< pair<ll,ll> >
    #define vpi vector< pair<int,int> >
    #define vi vector<int>
    #define vl vector<ll>
    #define vdl vector<dl>
    #define vch vector<char>
    #define pll pair<ll,ll>
    #define pb push_back
    #define mp make_pair
    #define fr first
    #define se second
    #define PI 3.14159265
    /*vl v[10005];
    ll cnt=0;
    ll a[51][51]={0};
    bool visited[10005]={0};
    void dfs(ll u)
    {
        visited[u]=1;
        f(i,0,v[u].size())
        {
            ll f=v[u][i];
            if(!visited[f])
            {
                dfs(f);
            }
        }
    }*/
    #define nos 1000000007;
    void solve()
    {
        inp(n);dl p[n+1];f(i,1,n+1)cin>>p[i];
        dl dp[n+1][n+1];f(i,0,n+1){f(j,0,n+1)dp[i][j]=0.0;}dp[0][0]=1.0;
        f(i,1,n+1)
        {
            f(j,0,i+1)
            {
                if(j==0)dp[i][j]=dp[i-1][j]*(1.0-p[i]);
                else
                {
                    dp[i][j]=dp[i-1][j]*(1.0-p[i])+dp[i-1][j-1]*p[i];
                }
            }
        }
        dl ans=0.0;
        f(i,(n+1)/2,n+1)
        {
            ans+=dp[n][i];
        }
        cout<<fixed<<setprecision(10)<<ans;
    }

    int32_t main(void)
    {
        Godspeed;
        int q;
        q=1;
        //cin>>q;
        while (q--)
        {
            solve();cout<<endl;
        }
        return 0;
    }


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

int main() {
  string s;
  cin >> s;
  int flag = 1;
  int ans = 0;
  s.erase(s.size() - 1);

  while (flag) {
    int n = s.size();
    string t = s.substr(0, n / 2);
    string u = s.substr(n / 2, n);
    if (t == u) {
      flag = 0;
      ans = s.size();
    }
    s.erase(n - 1);
  }
  cout << ans;
}


Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, p, a[100000];
int main() {
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++) cin >> a[i], a[i] = (a[i] - p + n) % n; p = 0;
	sort(a, a + m);
	int ret = min(a[m - 1], n - a[0]);
	for (int i = 0; i < m - 1; i++) ret = min(ret, min(a[i] * 2 + n - a[i + 1], a[i] + (n - a[i + 1]) * 2));
	cout << ret * 100 << endl;
	return 0;
}

Measured memory_bytes: 3160
N=int(input())
ans = 0
for x in range(1,N+1):
    if x%2 == 0:
        continue
    divider = 0
    for i in range(1,x+1):
        if x%i == 0:
            divider += 1
    if divider == 8:
        ans += 1
print(ans)

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

int n, c, mx, s, e, t, v[35][100005], cnt[100005];
int main()
{
	int i;
	cin >> n >> c;
	while (n--) {
		scanf ("%d %d %d", &s, &e, &t);
		for (i = s; i <= e; i++) {
			if (!v[t][i]) {
				v[t][i] = 1;
				cnt[i]++;
				mx = max(mx, cnt[i]);
			}
		}
	}
	cout << mx;
    return 0;
}


Measured memory_bytes: 12416