akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

	ll sum = 0;
	for (int i = 0; i < N.size(); i++)
	{
		sum += (N[i] - '0');
	}
	if (stoi(N) % sum == 0)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import fractions

N = int(input())
A = [int(i) for i in input().split()]
L = [0] * (N+1)
R = [0] * (N+1)
M = 1

for i in range(N):
  L[i+1] = fractions.gcd(L[i], A[i])
  R[N-i-1] = fractions.gcd(R[N-i], A[N-i-1])
  
if N == 2:
   print(max(A))
else:
  for i in range(N):
    M = max(M, fractions.gcd(L[i], R[i+1]))
  print(M)

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
V hash1(200000);
V hash2(200000);
int main(){
    int n,m;cin>>n>>m;
    bool flag=false;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(a==1)hash1[b]=1;
        if(b==n)hash2[a]=1;
    }
    rep(i,n){
        if(hash1[i]&&hash1[i]==hash2[i])flag=true;
    }
    cout<<(flag?"POSSIBLE":"IMPOSSIBLE")<<endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int n, m;
int a[35];

int main(void)
{
	cin >> n >> m;
	for(int i = 1; i<= n; i++){
		int k, b;
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> b;
			a[b]++;
		}
	}
	int ans = 0;
	for(int i = 1; i<= m; i++) if(a[i] == n) ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

b = []
if n%2 == 1:
    for i in a[n-1:0:-2]:
        b.append("{0}".format(i))
    b.append(str(a[0]))
    for i in a[1:n:2]:
        b.append("{0}".format(i))

if n%2 == 0:
    for i in a[n-1:0:-2]:
        b.append("{0}".format(i))
    for i in a[0:n:2]:
        b.append("{0}".format(i))

print(' '.join(b))


Measured memory_bytes: 36628
n = gets.to_i
all = Array.new(n) {gets.split(" ").map(&:to_i)}
# 頂点の高さを定めるための、たかさ１以上の基準点(stx,sty)を見つける
for i in 0..n-1 do
    if all[i][2] != 0
        stx = all[i][0]
        sty = all[i][1]
        sth = all[i][2]
        break
    end
end


for px in 0..100 do
    for py in 0..100 do
#頂点（px,py）の高さphを定める
        ph = sth + (stx - px).abs + (sty - py).abs 
        for i in 0 .. n-1 do
#(xi,yi,hi)のときあってるかどうかたしかめる
            xi = all[i][0]
            yi = all[i][1]
            hi = all[i][2]
            if hi != 0
                if ph - hi != (xi - px).abs + (yi - py).abs
                    # ふせいごうがあったら次のループ
                    break
                end
            else
                if ph > hi + (xi - px).abs + (yi - py).abs
                    # ふせいごうがあったら次のループ
                    break
                end
            end
            if i == n-1
                # 不整合がなければしゅつりょくして終了
                puts "#{px} #{py} #{ph}"
                exit
            end
        end
    end
end


Measured memory_bytes: 3836
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int h, w;

int f(int a, int b){
    
    a %= 2 * w;
    while(a > 0){
        
        if((a + b) % 2 == 0){
            // 左へ
            if(b == 0){
                a--;
                continue;
            }else{
                int val = min(a, b);
                a -= val;
                b -= val;
            }
        }else{
            // 右へ
            if(b == w - 1){
                a--;
                continue;
            }else{
                int val = min(a, w - 1 - b);
                a -= val;
                b += val;
            }
        }
    }
    
    return b;
}

signed main(){
    
    int n; cin >> h >> w >> n;
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        p[i].first = a - 1;
        p[i].second = b - 1;
    }

    sort(p.begin(), p.end());

    vector<int> m(w);
    for(int i = 0; i < w; i++) m[i] = i;

    for(int i = 0; i < n; i++){
        int u = f(p[i].first, p[i].second);
        int v = f(p[i].first, p[i].second + 1);
        
        swap(m[u], m[v]);
    }
    
    vector<int> ans(w);
    for(int i = 0; i < w; i++){
        ans[m[f(h, i)]] = i + 1;
    }

    for(int i = 0; i < w; i++) cout << ans[i] << endl;

    return 0;
}




Measured memory_bytes: 9072
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double dist(int n,int x[],int y[],double p){
	int i;
	double sum=0;
	for(i=0;i<n;i++){
		sum += pow(abs(x[i]-y[i]),p);
	}
	return pow(sum,1/p);
}

double dist_inf(int n,int x[],int y[]){
	int i;
	double max=abs(x[0]-y[0]);
	for(i=0;i<n;i++){
		if(max<abs(x[i]-y[i]))max=abs(x[i]-y[i]);
	}
	return max;
}
int main(){
	int i,n,x[100],y[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&y[i]);
	}
	printf("%f\n",dist(n,x,y,1));
	printf("%f\n",dist(n,x,y,2));
	printf("%f\n",dist(n,x,y,3));
	printf("%f\n",dist_inf(n,x,y));
	return 0;
}

Measured memory_bytes: 696
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

  if (s.at(0) != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  string str = s.substr(2, s.size() - 3);

  int cnt = 0;
  int tmp = 2;
  for (int i = 0; i < str.size(); ++i) {
    if (str.at(i) == 'C') {
      cnt++;
      tmp += i;
    }
  }
  if (cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); ++i) {
    if (i == 0 || i == tmp) {
      continue;
    }
    if (s.at(i) >= 'A' && s.at(i) <= 'Z') {
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {
  def play(s:String) = {
    val r = (0 until s.length).foldLeft((0,0)){ (x,y) =>
      if(s(y)=='A') (x._1+1,x._2) else (x._1,x._2+1)
    }
    r._1 + " " + r._2
  }

  def main(args:Array[String]) = {
    var s1 = "0"
    while({s1=readLine.trim;s1} != "0") {
      val s2 = readLine.trim
      val s3 = readLine.trim
      println(play(s1.drop(1)+s2(0)))
      println(play(s2.drop(1)+s3(0)))
      val a = s3.drop(1).count(_=='A')
      val b = s3.drop(1).count(_=='B')
      val c = if(a>b) 'A' else 'B'
      println(play(s3.drop(1)+c))
    }
  }

}

Measured memory_bytes: 43852
#include <stdio.h>

int main()
{
	int r, c;
	int mat[101][101] = {0};

	scanf("%d %d", &r, &c);
	for(int i = 0; i < r; ++i)
	{
		for(int j = 0; j < c; ++j)
		{
			scanf("%d", &mat[i][j]);
			mat[r][j] += mat[i][j];
			mat[i][c] += mat[i][j];
			mat[r][c] += mat[i][j];
		}
	}

	for(int i = 0; i <= r; ++i)
	{
		for(int j = 0; j < c; ++j)
		{
			printf("%d ", mat[i][j]);
		}
		printf("%d\n", mat[i][c]);
	}
	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

// mod付きコンビネーション
const int MAX = 1100000;
const int MOD = 1000000007;

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

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

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

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<Int> d(n - 1);
    for (Int i = 0; i < n - 1; i++) {
        d[i] = a[i + 1] - a[i];
    }
    COMinit();
    vector<Int> b(n + 1, 0);
    for (Int i = 1; i <= n; i++) {
        b[i] = inv[i];
    }
    for (Int i = 0; i < n; i++) {
        b[i + 1] += b[i];
        b[i + 1] %= mod;
    }
    Int res = 0;
    for (Int i = 0; i < n - 1; i++) {
        res += d[i] * b[i + 1] % mod;
        res %= mod;
    }
    dump(res * fac[n - 1] % mod);
    return 0;
}

Measured memory_bytes: 28416
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int calcDpTable(int i, int j, int ** dpTable, const int *p) {
	int minValue = INT_MAX; 
	for (int k = i; k < j; ++k) {
		minValue = min(dpTable[i][k - i] + dpTable[k + 1][j - k - 1] + p[i] * p[k + 1] * p[j + 1], minValue);
	}
	//dpTable[0][0] = 1;
	return minValue;
}

int minNumOfMultiplications(const int *p, int n) {
	int **dpTable = new int*[n];
	for (int i = 0; i < n; ++i) {
		dpTable[i] = new int[n - i];
		dpTable[i][0] = 0;
	}

	int d = 1;
	for (int to = n - 2; to >= 0; --to) {
		for (int i = 0; i <= to; ++i) {
			int j = i + d;
			dpTable[i][j - i] = calcDpTable(i, j, dpTable, p);
		}
		++d;
	}
	int ret = dpTable[0][n - 1];
	
	for (int i = 0; i < n; ++i) {
		delete[] dpTable[i];
	}
	delete[] dpTable;

	return ret;
}

int main() {
	int n;
	cin >> n;
	int *p = new int[n + 1];
	for (int i = 0; i < n; ++i) {
		cin >> p[i] >> p[i + 1];
	}
	cout << minNumOfMultiplications(p, n) << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1<<29)
using namespace std;
const int N=505;
char s[N];
int n,cnt[N];
ll ans;
int a[N][N],sum[N][N];
int l[N][N],r[N][N];
int tl[N][N],tr[N][N];
void recalc(int i){
	For(j,1,n) sum[i][j]=sum[i][j-1]+a[i][j];
}
int S(int i,int l,int r){
	return sum[i][r]-sum[i][l-1];
}
int main(){
	scanf("%d",&n);
	For(i,1,n){
		scanf("%s",s+1);
		For(j,1,n) a[i][j]=(s[j]=='#'?0:s[j]-48);
		recalc(i);
	}
	For(i,1,n) For(j,1,n)
		l[i][j]=n+1,r[i][j]=0;
	Rep(x,n,1){
		For(i,x,n) For(j,1,n)
			tl[i][j]=n+1,tr[i][j]=0;
		For(y,x,n)
			if (y==x){
				Rep(j,n,1) if(a[x][j]){
					tl[y][j]=j;
					tr[y][j]=max(j,j==n?0:tr[y][j+1]);
					ans+=a[y][j]*S(y,tl[y][j]+1,tr[y][j]);
				}
			}
			else{
				Rep(j,n,1) if (a[x][j]){
					tl[y][j]=min(l[y][j],j==n?n+1:tl[y][j+1]);
					tr[y][j]=max(r[y][j],j==n?0:tr[y][j+1]);
				}
				For(j,1,n) cnt[j]=0;
				For(j,1,n) if (tl[y][j]<=tr[y][j]){
					++cnt[tl[y][j]];
					--cnt[tr[y][j]+1];
				}
				bool flag=0;
				For(j,1,n){
					cnt[j]+=cnt[j-1];
					if (!cnt[j]&&a[y][j])
						a[y][j]=0,flag=1;
				}
				if (flag) recalc(y);
				For(j,1,n)
					if (tl[y][j]<=tr[y][j])
						ans+=a[x][j]*S(y,tl[y][j],tr[y][j]);
			}
		For(i,x,n) For(j,1,n)
			l[i][j]=tl[i][j],r[i][j]=tr[i][j];
	}
	printf("%lld",ans);
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int mx = max({a,b,c});
    if((3 * mx) %2 == (a + b + c) %2) {
        cout  << (3 * mx - a- b- c)/2 << endl;
    } else
        cout  << 1 + (3 * mx+1 - a- b- c)/2 << endl;

    return 0;
}


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

using namespace std;

int solve(string s, int k){
    if(s == "")
        return 0;

    if(k==1){
        return (s.length()- 1) * 9 + (s[0] - '0');
    }

    int ans = 0, len = s.length();
    if(k==2){
        if(len>=3)
            ans += (len-1) * (len-2) / 2 * 81;
        if(len>=2)
            ans += (s[0] - '1') * (len - 1) * 9;
    }
    if(k==3){
        if(len>=4)
            ans += (len-1) * (len-2) * (len-3) / 6 * 729;
        if(len >= 3)
            ans += (s[0] - '1') * (len-1) * (len-2) / 2 * 81;
    }

    int p = 1;
    while(p<len && s[p] == '0'){
        p++;
    }

    ans += solve(s.substr(p), k-1);

    return ans;
}

int main(){
    string s;
    int k, ans = 0;
    cin >>s>>k;

    cout <<solve(s, k);
}


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

int main(){
    string s; cin >> s;
    int ans = 0 , cnt = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'A'|| s[i] ==  'C'|| s[i] == 'G' || s[i] == 'T' ){
            cnt++;
        }
        else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    ans = max(ans,cnt);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MOD (10000)
int t[104][6],r[104];
int main(void){
    int n,k;
    int i;
    int a,b;
    int ans;

    scanf("%d%d",&n,&k);
    while(k--){
        scanf("%d%d",&a,&b);
        r[a]=b;
    }

    if(r[1]!=0) t[1][(r[1]-1)*2]=1;
    else t[1][0]=t[1][2]=t[1][4]=1;


    for(i=2;i<=n;i++){
        if(r[i]==0||r[i]==1){
            t[i][0]=(t[i-1][2]+t[i-1][3]+t[i-1][4]+t[i-1][5])%MOD;
            t[i][1]=t[i-1][0];
        }
        if(r[i]==0||r[i]==2){
            t[i][2]=(t[i-1][0]+t[i-1][1]+t[i-1][4]+t[i-1][5])%MOD;
            t[i][3]=t[i-1][2];
        }
        if(r[i]==0||r[i]==3){
            t[i][4]=(t[i-1][0]+t[i-1][1]+t[i-1][2]+t[i-1][3])%MOD;
            t[i][5]=t[i-1][4];
        }
    }

    ans=0;
    ans=(t[n][0]+t[n][1]+t[n][2]+t[n][3]+t[n][4]+t[n][5])%MOD;
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define N 200005
    #define fs first
    #define sc second
    #define UNIVISITED 0
    #define EXPLORED 1
    #define VISITED 2

    using namespace std;
    typedef  long long int ll;
    typedef pair<ll,ll> ii;
    typedef vector <ii> vii;
    typedef vector <ll> vi;
   

   


    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
ll n,a,b,sum,ans=0;

cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
  ll pp=i;
  sum=0;
  while(pp>0)
  {
    sum+=pp%10;
    pp/=10;
  }
  if(sum>=a && sum<=b)
    ans+=i;
}

cout<<ans<<endl;




    return 0;


    }

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

using namespace std;

int n;
double a,b,ans;

int main(){
	for(cin>>n>>a>>b;n;n--){
		ans+=a+b*(2*n-1)/2;
		a+=(a+2.5*b)/n,b+=2*b/n;
	}
	printf("%.15lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<bool> D(10, true);
  rep(i, K) {
    int d;
    cin >> d;
    D[d] = false;
  }

  int Ans = N;
  for (; Ans < 10 * N; Ans++) {
    int chk = Ans;
    while (chk) {
      if (D[chk % 10] == false) break;
      chk /= 10;
    }
    if (chk == 0) {
      break;
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;



string t="AGCT";

int main(){
    int N;cin >> N;
    LL dp[N+1][4][4][4];
    memset(dp,0,sizeof(dp));
    dp[0][3][3][3] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                for (int s = 0; s < 4; s++) {
                    for (int l = 0; l < 4; l++) {
                        if(k==0&&s==1&&l==2) continue;
                        else if(k==0&&s==2&&l==1) continue;
                        else if(k==1&&s==0&&l==2) continue;
                        else if(j==0&&k==1&&l==2) continue;
                        else if(j==0&&s==1&&l==2) continue;
                        dp[i+1][k][s][l] = (dp[i+1][k][s][l] + dp[i][j][k][s])%mod;
                    }
                }
            }
        }
    }
    LL ans = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                ans = (ans+dp[N][i][j][k])%mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static Map<Integer, int[]> map = new HashMap<Integer, int[]>();
    static Map<Integer, Boolean> visited = new HashMap<Integer, Boolean>();
    static List<Integer> que = new ArrayList<Integer>();
    static List<Integer> tmpQue = new ArrayList<Integer>();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
		
		//set map
        for (int i = 0; i < n; i++){
            String[] s = br.readLine().split(" ");
            int u = Integer.parseInt(s[0]);
            int k = Integer.parseInt(s[1]);
            int[] a = new int[k];
            for (int j = 0; j < k; j++){
                a[j] = Integer.parseInt(s[j + 2]);
            }
            map.put(u, a);
            visited.put(u, false);
        }
        //steps array of each node
        int[] d = new int[n + 1];
        for (int i = 0; i < n + 1; i++){
            d[i] = -1;
        }
        //bfs
        int v = 1;
        que.add(v);
        visited.put(1, true);
        int step = 0;
        d[v] = step;
        step++;
        while (que.size() > 0){
            v = que.remove(0);
            //add the next Vertices to the que
            try{
				if (map.get(v) == null){
					;
                }else{
                    int[] nextArr = map.get(v);
                    for (int j = 0; j < nextArr.length; j++){
                        if (visited.get(nextArr[j])){
                            ;
                        }else{
                            tmpQue.add(nextArr[j]);
                            visited.put(nextArr[j], true);
                            d[nextArr[j]] = step;
                        }
                    }
                }
				// after all next siblings are added...
				if (que.size() == 0){
					step++;
					for (int i = 0; i < tmpQue.size(); i++){
						que.add(tmpQue.get(i));
					}
					tmpQue.clear();
				}
            }catch (NullPointerException e){
                e.printStackTrace();
            }
        }
        //show the result
        for (int i = 1; i < n + 1; i++){
            System.out.println(i + " " + d[i]);
        }
    }    
}

Measured memory_bytes: 18960
#[macro_use]
mod utils {
    macro_rules! input {
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($next:expr) => {};
        ($iter:expr, ) => {};
 
        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }
    macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };
        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };
        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}

fn main() {
    input! {
        n: u64,
        m: usize,
        mut a: [u64; n]
    }
    let mut sum = 0;
    let mut flg = true;
    sum = a.iter().sum();
    a.sort();
    a.reverse();
    for i in 0..m{
        if a[i] < (sum + (4*m-1) as u64)/(4*m) as u64 {
            flg = false
        }
    }
    if flg{
        println!("Yes");
    }else{
        println!("No");
    }
}

Measured memory_bytes: 4352
// 2020/08/24
// Step

#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  long long a, tmp=0, sum=0, n;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    if(tmp>a){
      sum += tmp - a;
    } else {
      tmp = a;
    }
  }

  cout << sum;

}


Measured memory_bytes: 3512
#include<iostream>
#include<tuple>
#include<algorithm>
#include<vector>
using namespace std;

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

  vector<tuple<int, int, int>> wsvs(N);
  for(int i = 0; i < N; i++){
    int w, s, v;
    cin >> w >> s >> v;
    wsvs[i] = make_tuple(w, s, v);
  }
  sort(wsvs.begin(), wsvs.end(), [](tuple<int, int, int> a, tuple<int, int, int>b){return get<0>(a) + get<1>(a) < get<0>(b) + get<1>(b);});

  // dp[n][W] := with item[0: n) and the sum of weight <= W, you can get dp[n][W] values
  // dp[0][0] = 0
  // dp[n][W] = max(dp[n - 1][W], dp[n][W - 1]);
  // if s[n - 1] >= W - w[n - 1] then dp[n][W] = max(dp[n][W], dp[n - 1][W - w[n - 1]] + v[n - 1])
  const int w_sum_max = 2e4;
  vector<vector<long long>> dp(N + 1, vector<long long>(w_sum_max + 1, 0));
  for(int n = 0; n <= N; n++){
    dp[n][0] = 0;
  }
  for(int n = 1; n <= N; n++){
    for(int w_sum = 1; w_sum <= w_sum_max; w_sum++){
      int w, s, v;
      tie(w, s, v) = wsvs[n - 1];
      dp[n][w_sum] = max(dp[n - 1][w_sum], dp[n][w_sum - 1]);
      if(s >= w_sum - w && w_sum - w >= 0){
        dp[n][w_sum] = max(dp[n][w_sum], dp[n - 1][w_sum - w] + v);
      }
    }
  }

  cout << dp[N][w_sum_max] << endl;

}


Measured memory_bytes: 160640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        char head = s.charAt(0);
        char foot = s.charAt(s.length() - 1);
        String result = "" + head + (s.length() - 2) + foot;

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


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

 int main(){
        char s[4];
        int a=0;
        cin >> s[0] >> s[1] >> s[2] >> s[3];
        if (s[0] == '+')a++;
        else if (s[0] == '-')a=a-1;
        if (s[1] == '+')a++;
        else if (s[1] == '-')a=a-1;
        if (s[2] == '+')a++;
        else if (s[2] == '-')a=a-1;
        if (s[3] == '+')a++;
        else if (s[3] == '-')a=a-1;
        cout << a << endl;

        return 0;
    }
   


Measured memory_bytes: 256
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    a, b = map(int, input().split())
    if 2 * b >= a:
        print(0)
    else:
        print(a - 2*b)


    
            
    

    

    

if __name__ == '__main__':
    main()


Measured memory_bytes: 69868
#結局これもパターン全列挙(2パターン)か。
#判別しようと無駄な努力をしてしまった。
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    def buildDiff(bF):
        iC = 0
        iS = 0
        for a in aA:
            iS += a
            if bF:
                if iS >= 0:
                    iC += iS + 1
                    iS = -1
                bF = 0
            else:
                if iS <= 0:
                    iC += -1 * iS + 1
                    iS = 1
                bF = 1
        return iC
    print(min(buildDiff(1),buildDiff(0)))
解()


Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
 
main()
{
  int n;
  int c[501];
  int s[501];
  int f[501];
  int t[501];
  
  cin >> n;
  for(int i=0;i<n-1;i++)
    cin >> c[i] >> s[i] >> f[i];
 
  for(int i=0;i<n;i++){
    int ans=0;
    for(int j=i;j<n-1;j++){
      if(ans<s[j])
        ans+=s[j]-ans;
      if(ans%f[j]!=0){
        int k;
        for(k=1;f[j]*k<ans;k++);
        ans+=(f[j]*k)-ans;
      }
      ans+=c[j];
    }
    cout << ans << endl;
  }
  
  return (0);
}

Measured memory_bytes: 256
import bisect

n, q = map(int,input().split())
a = list(map(int,input().split()))
a.reverse()
 
cums = [0]*(n+1)
cume = [0]*(n+1)
for i in range(n):
  cums[i+1] = cums[i] + a[i]
  cume[i+1] = cume[i] + a[i]*(1 - i%2)

bo = list()
sc = list()
for i in range(1,(n+1)//2):
    b = (a[i] + a[2*i])//2 + 1
    bo.append(b)
    s = cums[i] + cume[-1] - cume[2*i]
    sc.append(s)
sc.append(cums[(n+1)//2])

bo.reverse()
sc.reverse()
 
for _ in range(q):
    i = bisect.bisect(bo, int(input()))
    print(sc[i])

Measured memory_bytes: 23456
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N,tmp;
  cin >> X >> N;
  if(N==0){
    cout << X << endl;
    return 0;
  }
  map<int,int> mp;
  for(int i=0;i<N;i++){
    cin >> tmp;
    mp[tmp] = 1;
  }
  for(int i=0;i<100000000;i++){
    // if(X-i<1) continue;
    if(mp[X-i]==0){
      cout << X-i << endl;
      return 0;
    }
    // if(X+i>N) continue;
    if(mp[X+i]==0){
      cout << X+i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int memo[100010][3];


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n+1);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;

    vector<vector<int>> ans(n+1, vector<int>(3, -1));
    queue<pair<int, int>> que;
    que.emplace(s, 0);
    ans[s][0] = 0;
    while (!que.empty()) {
        int v, d;
        tie(v, d) = que.front(); que.pop();
        for (auto &u: g[v]) {
            if (ans[u][(d+1)%3] != -1) continue;
            ans[u][(d+1)%3] = d+1;
            que.emplace(u, d+1);
        }
    }

    if (ans[t][0] == -1) {
        cout << -1 << endl;
    } else {
        cout << ans[t][0]/3 << endl;
    }

    return 0;
}


Measured memory_bytes: 11136
using System;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var K = NK[1];
            var input = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToList();
            input = input.OrderByDescending(s => s).ToList();
            var sum = Enumerable.Range(0, K).Select(x => input[x]).Sum();
            Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 13396
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner in  = new Scanner(System.in);
    //行の読み込み
    String ring = in.nextLine();
    ring += ring;
    String str  = in.nextLine();
    if(ring.contains(str)){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 26276
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int main(){
	int n;
	int data[21];
	while(cin>>n,n){
		int ret = INT_MAX;
		rep(i,n)cin>>data[i];
		rep(i,(1<<n)/2+1){
			int a=0,b=0;
			for(int j=0; j<n; j++){
				if( i&(1<<j) ){
					a += data[j];
				}else{
					b += data[j];
				}
			}
			ret = min(ret, abs(a-b));
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 868
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 c = sc.nextInt();
	int k = sc.nextInt();
	boolean isCan = false;
	for (int i=0; i<=k; i++) {
	    if (a<b*(int)Math.pow(2,i) && b*(int)Math.pow(2,i)<c*(int)Math.pow(2,k-i))
		isCan = true;
	}
	if (isCan) System.out.print("Yes");
	else { System.out.print("No"); }
    }
}


Measured memory_bytes: 35648
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		long N=sc.nextLong();
		long M=sc.nextLong();

		long ans=Math.min(N,M/2);

		M-=ans*2;

		ans+=M/4;

		System.out.println(ans);

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

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

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

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

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

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;



int main(){
ll n,m; cin>>n>>m;
ll res=0;

if(n>=m/2) res=m/2;
else res=(n+m/2)/2;
cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+10 , OO = 0x3f3f3f3f ;
//const int mod = 1000000007;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int heights[N] , n , k;
int mem[N];

int goo(int idx){ ///// 4
                  ///// 10 30 40 20
	if(idx > n) return OO;
	if(idx == n-1) return 0;
	int& ret = mem[idx];
	if(~ret) return ret;
	ret = OO;
	for(int i = 1 ; i <= k ; ++i)
		ret = min(ret , goo(idx+i) + abs(heights[idx] - heights[idx+i]));
	return ret; 
}


int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin >> n >> k;
	for(int i = 0 ; i < n ; ++i)
		cin >> heights[i];

	clr(mem , -1);
	cout << goo(0) << "\n";



    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int hsz = 1e7 + 39, mod = 1e9 + 7;
int n, k, ans;

struct hash_table {
    int sz, hd[hsz + 5], nxt[hsz + 5], key[hsz + 5], val[hsz + 5];
    
    void inline ins(int id, int w) {
        int hid = id % hsz;
        for (int i = hd[hid]; i; i = nxt[i]) {
            if (id == key[i])  return;
        }
        ++sz;
        key[sz] = id;
        val[sz] = w;
        nxt[sz] = hd[hid];
        hd[hid] = sz;
    }
    
    int inline qry(int id) {
        int hid = id % hsz;
        for (int i = hd[hid]; i; i = nxt[i]) {
            if (id == key[i])  return val[i];
        }
        return -1;
    }
};
hash_table dat;

int inline qpow(int a, int p) {
    int res = 1;
    for (; p; p >>= 1) {
        if (p & 1) {
            res = (num) res * a % mod;
        }
        a = (num) a * a % mod;
    }
    return res;
}

void inline upd(int &a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    if (a < 0) {
        a += mod;
    }
}

int solve(int a) {
    int res = dat.qry(a);
    if (res != -1)  return res;
    if (a == 1) {
        res = k % mod;
        dat.ins(1, res);
        return res;
    }
    res = 0;
    for (int b = 1; b * b <= a; ++b) {
        if (a % b)  continue;
        int bb = a / b;
        upd(res, -solve(b));
        if (b != bb && bb != a) {
            upd(res, -solve(bb));
        }
    }
    upd(res, qpow(k, (a - 1) / 2 + 1));
    dat.ins(a, res);
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    solve(n);
    cont (i, dat.sz) {
        int a = dat.key[i], cnt = dat.val[i], cur = (num) a * cnt % mod;
        upd(ans, (a & 1) ? cur : (num) cur * qpow(2, mod - 2) % mod);
    }
    cout << ans << ln;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

struct edge {
  int u, v, w;
  edge() {}
  edge(int u, int v, int w):
    u(u), v(v), w(w) {}
};

void chmin(int &a, int b) {
  if (a > b) a = b;
}

void solve() {
  int n, m;
  cin >> n >> m;
  vector<edge> edges;
  vector<vector<int>> dist(n + 1, vector<int>(n + 1, 2e9));
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    dist[u][v] = dist[v][u] = w;
    edges.push_back(edge(u, v, w));
  }
  for (int k = 1; k <= n; k++)
  for (int i = 1; i <= n; i++)
  for (int j = 1; j <= n; j++) {
    chmin(dist[i][j], dist[i][k] + dist[k][j]);
  }
  int ans = 0;
  for (auto &i : edges) {
    if (dist[i.u][i.v] < i.w) ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int b[200][200], d[200][200], t, n, sx, sy,
    dx[] = {-1, -1, 0, 0, 1, 1}, dy[] = {0, -1, 1, -1, 0, 1};

signed main(void) {
  while (true) {
    cin >> t >> n;
    if(!t && !n) break;
    REP(i, 200) REP(j, 200) {
      b[i][j] = 0;
      d[i][j] = INF;
    }
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      b[y + 100][x + 100] = -1;
    }
    cin >> sx >> sy;

    queue<VI> que;
    que.push({sx, sy, 0});
    d[sy + 100][sx + 100] = 0;

    while (que.size()) {
      VI p = que.front();
      que.pop();
      if (p[2] == t)
        continue;
      REP(i, 6) {
        int nx = p[0] + dx[i], ny = p[1] + dy[i];
        if (abs(nx) <= 100 && abs(ny) <= 100 && !b[ny + 100][nx + 100] &&
            d[ny + 100][nx + 100] == INF) {
          que.push({nx, ny, p[2] + 1});
          d[ny + 100][nx + 100] = d[p[1] + 100][p[0] + 100] + 1;
        }
      }
    }

    int ret = 0;
    REP(i, 200) REP(j, 200) {
      if (d[i][j] <= t)
        ret++;
    }

    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 3476
#include <iostream>
using namespace std;
int sum;
int main(){
        int n,a;
        int dig;
        cin >> n;
        a=n;
        while(n) {
                dig=n%10;
                sum+=dig;
                n=n/10;
        }
        if((a%sum)==0) {
                cout << "Yes" <<endl;
        }
        else{
                cout << "No" <<endl;
        }
        return 0;
}


Measured memory_bytes: 256
N = int(input())
S = str(input())
sumL = [0]*N
sumL[0] = S[1:].count('E')
left = 0
right = 0
for i in range(1,N):
  if S[i-1] == 'W':
    left = 1
  else:
    left = 0
  if S[i] == 'E':
    right = 1
  else:
    right = 0
  sumL[i] = sumL[i-1] + left - right
sumL.sort()
print(sumL[0])

Measured memory_bytes: 16632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(int i=a; i<b; i++)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n, m, l;
	cin>>n>>m>>l;
	vector<vll> dp(n+1, vll(n+1, 1e16));
	loop(i, 1, n+1){
		loop(j, 1, n+1){
			if(i == j)
				dp[i][j] = 0;
		}
	}
	loop(i, 0, m){
		lli c1, c2, c3;
		cin>>c1>>c2>>c3;
		dp[c1][c2] = c3;
		dp[c2][c1] = c3;
	}
	loop(k, 1, n+1){
		loop(i, 1, n+1){
			loop(j, 1, n+1)
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
		}
	}
	vector<vll> old_dp = dp;
	loop(i, 1, n+1){
		loop(j, 1, n+1){
			if(old_dp[i][j] <= l)
				dp[i][j] = 1;
			else
				dp[i][j] = 1e16;
			if(i == j)
				dp[i][j] = 0;
		}
	}
	loop(k, 1, n+1){
		loop(i, 1, n+1){
			loop(j, 1, n+1)
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
		}	
	}
	lli q;
	cin>>q;
	while(q>0){
		q--;
		lli c1, c2;
		cin>>c1>>c2;
		if(dp[c1][c2] >= 1e16)
			cout<<-1<<"\n";
		else
			cout<<dp[c1][c2]-1<<"\n";
	}
	return 0;
}
int main(){
	fastio;
	lli t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}


Measured memory_bytes: 2048
n,m = (int(i) for i in input().split())
x,y,dp = [[] for i in range(n)],[],[[0,-1] for i in range(n)]
for i in range(m):
	a,b = (int(i)-1 for i in input().split())
	x[a].append(b)
	x[b].append(a)
q = int(input())
for i in range(q):
	v,d,c = (int(i) for i in input().split())
	y.append((v-1,d,c))
def f(v,d,c):
	z,z2 = dp[v]
	if d>z2:
		if z: dp[v] = z,d
		else: dp[v] = c,d
		if d:
			for i in x[v]: f(i,d-1,c)
for i,j,k in y[::-1]: f(i,j,k)
for i in dp: print(i[0])

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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

const int Maxn=2e5+10;

int n;
ll a[Maxn];
ll cnt[Maxn];
ll ans[Maxn];

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	cnt[a[i]]++;
	}
	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		ans[i]=cnt[i]*(cnt[i]-1LL)/2LL;
		sum+=ans[i];
	}
	for(int i=0;i<n;i++)
	{
		cout<<sum-cnt[a[i]]+1LL<<endl;
	}
    /* end code */
	return 0;
}

Measured memory_bytes: 6912
n,k=map(int,input().split())
s=input()
ans=0
bef=s[0]
cnt=0
s2_l=[s[0]]
for i in range(n):
    if bef==s[i]:
        cnt+=1
    else:
        ans+=(cnt-1)
        cnt=1
        bef=s[i]
        s2_l.append(bef)
    if i==n-1:
        ans+=(cnt-1)
s2="".join(s2_l)
n2=len(s2)
if n2==1:
    print(ans)
    exit()
if s2[0]==s2[n2-1]:
    print(ans+min(k,s2.count(s2[1]))*2)
else:
    if k>=n2//2:
        print(ans+n2-1)
    else:
        print(ans+k*2)
    


Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  vector<int> P(N);
  
  for(int i = 0;i < N;++i){
    cin >> P[i];
  }
  
  int num = 1;
  
  int num2 = 1e9;
  
  if(N == 1){
    cout << 1 << endl;
  }
  else{
    for(int i = 1;i < N;++i){
      num2 = min(P[i - 1],num2);
        if(P[i] < num2){
          num++;
        }
    }
    cout << num << endl;
  }
  
          
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define MAX_V 500001
#define INF 1000000000000000009
typedef pair<ll, ll> p;
std::vector<ll> mincost(MAX_V,INF),used(MAX_V,0);
std::vector<ll> pre(MAX_V, -1);
priority_queue<p, std::vector<p>, greater<p> > que;
struct edge{ll to, cost;};
std::vector<std::vector<edge> > G(MAX_V);
void prim(){
  mincost[1]=0;
  que.push(make_pair(0, 1));
  while(!que.empty()){
    p p_now=que.top();que.pop();
    if(p_now.first > mincost[p_now.second]) continue;
    used[p_now.second]=1;
    for(int i=0;i<G[p_now.second].size();i++){
      int to = G[p_now.second][i].to;
      if(used[to]==0&&mincost[to]>G[p_now.second][i].cost){
        pre[to] = p_now.second;
        mincost[to]=G[p_now.second][i].cost;
        que.push(make_pair(mincost[to],to));
      }
    }
  }
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vvl d = vv(n, 2, 0, ll);
  multiset<vll> a, b;
  re(i, n) {
    std::cin >> d[i][0] >> d[i][1];
    a.insert(vll{d[i][0], i+1});
    b.insert(vll{d[i][1], i+1});
  }

  for(auto itr=a.begin();itr!=a.end();itr++){
    auto i = itr;
    if(i!=a.begin()){
      i--;
      G[(*i)[1]].push_back(edge{(*itr)[1], (*itr)[0] - (*i)[0]});
      G[(*itr)[1]].push_back(edge{(*i)[1], (*itr)[0] - (*i)[0]});
      i++;
    }
    i++;
    if(i!=a.end()){
      G[(*i)[1]].push_back(edge{(*itr)[1], (*i)[0] - (*itr)[0]});
      G[(*itr)[1]].push_back(edge{(*i)[1], (*i)[0] - (*itr)[0]});
    }
  }
  for(auto itr=b.begin();itr!=b.end();itr++){
    auto i = itr;
    if(i!=b.begin()){
      i--;
      G[(*i)[1]].push_back(edge{(*itr)[1], (*itr)[0] - (*i)[0]});
      G[(*itr)[1]].push_back(edge{(*i)[1], (*itr)[0] - (*i)[0]});
      i++;
    }
    i++;
    if(i!=b.end()){
      G[(*i)[1]].push_back(edge{(*itr)[1], (*i)[0] - (*itr)[0]});
      G[(*itr)[1]].push_back(edge{(*i)[1], (*i)[0] - (*itr)[0]});
    }
  }
  prim();
  ll ans = 0;
  for(int i=1;i<=n;i++){
    ans += mincost[i];
    //std::cout << mincost[i] << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 66412