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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  string s;cin>>s;
  rep(i,s.size()){
    if(s[i]!=',')cout<<s[i];
    else cout<<' ';
  }
  cout<<endl;
}





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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;


lli h,w,k;
vector<vector<vector<lli>>> dp;
lli y[] = {1, 1, 2, 3, 5, 8, 13, 21};
lli mod = 1000000007;


int main(){
  cin >> h >> w >> k;
  dp = vector<vector<vector<lli>>>(h+1,vector<vector<lli>>(w, vector<lli>(w)));
  dp[0][0][0] = 1;
  for(lli i = 0;i < h;i++){
    for(lli j = 0;j < w;j++){
      for(lli l = 0;l < w;l++){
        if(l-1 >= 0) dp[i+1][j][l-1] += dp[i][j][l]*y[l-1]*y[w-l-1];
        dp[i+1][j][l] += dp[i][j][l]*y[l]*y[w-l-1];
        if(l+1 < w) dp[i+1][j][l+1] += dp[i][j][l]*y[l]*y[w-l-2];
      }
    }
    for(lli j = 0;j < w;j++){
      for(lli l = 0;l < w;l++){
        dp[i+1][j][l] %= mod;
      }
    }
  }
  cout << dp[h][0][k-1] << endl;
}


Measured memory_bytes: 384
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int64_t a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + 2 * sqrtl(a * b) < c ? "Yes" : "No") << endl;
}


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

int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  if((B-A)%2 == 0){cout << (B-A)/2 << endl;}else{
    if(A-1 <= N-B){cout << A+(B-A)/2 << endl;}else{
    cout <<N-B+1+(B-A)/2 << endl;}
  } 
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	ll rainSum = accumulate(begin(a), end(a), 0LL);

	vector<ll> dp(n);
	ll tmp = 0;
	for (int i = 1; i < n; i+=2) {
		tmp += a[i];
	}
	dp[0] = rainSum - 2LL*tmp;

	for (int i = 1; i < n; i++) {
		dp[i] = 2LL * a[i - 1] - dp[i - 1];
	}

	for (int i = 0; i < (int)dp.size(); i++) {
		if (i) cout << " ";
		cout << dp[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int n,m; cin >> n >> m;
    for(int i = 0; i < n; i++){
        if(i)cout << " ";
        if(i<n/2+1)cout << 0;
        else cout << m;
    }
    cout << endl;
}



Measured memory_bytes: 3104
x = str(input())
if x == "0 2 3 4 5":
    print(1)
elif x == "1 0 3 4 5":
    print(2)
elif x == "1 2 0 4 5":
    print(3)
elif x == "1 2 3 0 5":
    print(4)
else:
    print(5)
    

Measured memory_bytes: 8964
#include <iostream>
#include <vector>

using namespace std;

int main() {
 	int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; ++i) {
    	cin >> b[i];  
    }
    int temp;
    int ans = 0;
    int a;
    for (int i = 0; i < n; ++i) {
        temp = c;
        for (int j = 0; j < m; ++j) {
        	cin >> a;
            temp += a * b[j];            
        }
        if (temp > 0)
        	++ans;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int W,H,x,y,r;
	scanf("%d %d",&W,&H);
	scanf("%d %d %d",&x,&y,&r);
	if(W>0&&W<=100&&H>0&&H<=100&&r>0&&r<=100){
		if(x>=-100&&x<=100&&y>=-100&&y<=100){
			if(W>=x+r&&0<=x-r&&H>=y+r&&0<=y-r) printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2128
import math

def digits(n):
    if n == 0:
        return 0
    return digits(n/10) + 1

N = int(raw_input())
ans = digits(N)
for d in range(2, int(math.sqrt(N))+1):
    if d*d > N:
        break
    if N % d == 0:
        temp = max(digits(d), digits(N/d))
        if temp < ans:
            ans = temp
print ans


Measured memory_bytes: 5764
BASE =  1000000007

if __name__ == '__main__':
    N, M = [int(i) for i in input().split()]
    not_available = []
    for i in range(M):
        not_available.append(int(input()))
    x = 0
    y = 1
    predicted_next = 1
    is_available = [True] * N
    for idx in not_available:
        is_available[idx - 1] = False

    for flag in is_available:
        if flag:
            z = x + y
            x = y
            y = z
        else:
            x = y
            y = 0

    print(y % BASE)

Measured memory_bytes: 7824
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 998244353;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
char str[MAXN];
int st[MAXN], en[MAXN];
int cnt[3];

int main() {
	int n; ni(n);
	for (int i = 0; i <= n; i++) st[i] = INF;
	scanf("%s", str);
	pair<char,int> a = mp('R',0), b = mp('R',0);
	ll ans = 1, x = n;
	for (int i = 0; i < 3*n; i++) {
		if (b.se > 0 && str[i] == b.fi) {
			ans = (ans * (ll)b.se) % MOD;
			b.se--;
		} else if (a.se > 0 && a.fi != str[i]) {
			ans = (ans * (ll)a.se) % MOD;
			a.se--;
			b.fi = 'R';
			if (a.fi == 'R' || str[i] == 'R') {
				b.fi = 'G';
				if (a.fi == 'G' || str[i] == 'G')
					b.fi = 'B';
			}
			b.se++;
		} else {
			ans = (ans * x) % MOD;
			x--;
			a.se++;
			a.fi = str[i];
		}
	}
	while (x);
	prl(ans);
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;

	cin >> n >> m;

	int a, b;


	vector<vector<int>> arr(m+1);

	  for(int i=0;i<n;i++)
	{
		cin >> a >> b;

		if (a <= m)
		{
			arr[a].pb(b);
		}
	}

	priority_queue<int>pq;

	int k = 0;

	for (int i = 1; i <= m; i++)
	{
		for (auto j : arr[i])

			pq.push(j);

		if (!pq.empty())
		{

			k += pq.top();
			pq.pop();
		}


	}


	cout << k << endl;


}

Measured memory_bytes: 8456
#include <stdio.h>
int a[4][3][10];

int main(void){
    int b,f,r,v,i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        a[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                printf(" %d",a[i][j][k]);
            }
            printf("\n");
        }
        if(i==3)break;
        for(int l=0;l<20;l++){
            printf("#");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2712
#include<stdio.h>
int main(void)
{
    int a,b,c,d[10],i;
    a=0;
    b=0;
    c=0;
    for(i=0;i<10;i++)
    {
        scanf("%d",&d[i]);
        if(d[i]>=a)
        {
            c=b;
            b=a;
            a=d[i];
        }
        else if(d[i]>=b)
        {
            c=b;
            b=d[i];
        }
        else if(d[i]>=c)
        {
            c=d[i];
        }
    }

    printf("%d\n%d\n%d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct edge {int to;int cost;};
const int M_N=300;
int L;
vector<edge> G[M_N+1];
P d[M_N+1][M_N+1];

void dijkstra(int s){
    priority_queue<pair<P,int> ,vector<pair<P,int>>,greater<pair<P,int>>> que;
    que.push({{0,-L},s});
    while(!que.empty()){
        pair<P,int> p=que.top();que.pop();
        int v=p.second;
        int t=-p.first.second;
        int l=p.first.first;
        if(d[s][v].first<l) continue;
        else if(d[s][v].first==l&&d[s][v].second>t) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(e.cost>t){
                if(d[s][e.to].fs>l+1||(d[s][e.to].fs==l+1&&d[s][e.to].sc<L-e.cost)){
                    d[s][e.to] = mp(l+1,L-e.cost);
                    que.push({{l+1,-(L-e.cost)},e.to});
                }
            }
            else{
                if(d[s][e.to].fs>l||(d[s][e.to].fs==l&&d[s][e.to].sc<t-e.cost)){
                    d[s][e.to] = mp(l,t-e.cost);
                    que.push({{l,-(t-e.cost)},e.to});
                }
            }
        }
    }
}




int main(){
    int n,m;cin >> n >> m >> L;
    for (int i = 0; i < m; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int c;cin >> c;
        if(c>L) continue;
        G[x].pb({y,c});
        G[y].pb({x,c});
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = mp(INF,INF);
        }
    }
    for (int i = 0; i < n; i++) {
        dijkstra(i);
    }
    int q;cin >> q;
    for (int i = 0; i < q; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int ans = d[x][y].fs;
        if(ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}


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

using d = pair<long long, long long>;

int main(){
  long long n, m;
  cin >> n >> m;
  priority_queue<d, vector<d>, greater<d>> drink;
  for(int i = 0; i < n; ++i){
    d x;
    cin >> x.first >> x.second;
    drink.push(x);
  }
  
  long long ans = 0;
  long long cnt = 0;
  while(1){
    d x = drink.top();
    drink.pop();
    long long k = cnt + x.second;
    if(k >= m){
      ans +=(m - cnt) * x.first;
      break;
    }
    
    cnt += x.second;
    ans += x.first * x.second;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include <fstream>

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    long long x,k,d;
    cin>>x>>k>>d;
    x=abs(x);

    long long come_to_point=x/d;
    if(come_to_point>=k)
        cout<<x-(k*d);
    else
    {
        k-=come_to_point;
        x-=(come_to_point*d);
        if(k%2==0)
        cout<<x;
        else
        {
            cout<<abs(x-d);
        }
        
    }
    

    return 0;
}

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

typedef long long ll;
queue<ll> que;
int main(){
    //freopen("in.txt","r",stdin);
    for(int i=1; i<10; i++) que.push(i);
    int k;
    cin>>k;
    for(int i=1; i<=k; i++){
        ll x = que.front();
        que.pop();
        if(i == k){
            printf("%lld\n", x);
            break;
        }
        if((x % 10) != 0) que.push(x * 10 + (x % 10) - 1);
        que.push(x * 10  + (x % 10));
        if((x % 10) != 9) que.push(x * 10 + (x % 10) + 1);
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  string S;
  ll K;
  cin>>S>>K;
  ll _1=0;
  FORi(S.size()){
    if(S[i]!='1'){
      break;
    }
    _1++;
  }
  if(_1>=K){
    cout<<1<<endl;
  }else{
    cout<<S[_1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#define mod 1000000007
#define pb push_back
using namespace std;
int main(){
	int n,k,apl,ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x==1)apl=i;
	}
	int left = apl - 1;
	int right = n - apl;
	ans += left/(k-1); left= left%(k-1);
	ans += right/(k-1); right= right%(k-1);
	int su = left+right;
	while(su>0){ su=su-(k-1); ans++;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
g=[[] for i in range(n)]
for i in range(n-1):
	u,v=map(lambda x:int(x)-1,input().split())
	g[u]+=[v]
	g[v]+=[u]
while sum([len(g[i]) for i in range(n)])>0:
	for i in range(n):
		if len(g[i])==1:
			u=g[i][0]
			g[i].remove(u)
			g[u].remove(i)
			for v in g[u]:
				g[v].remove(u)
				if len(g[v])==0:
					print("First")
					exit()
			g[u]=[]
print("Second")

Measured memory_bytes: 94240
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    ll x = min(B-1, N);
    //cout << A*(x/B) << endl;
    cout << (A*x)/B << endl;

    return 0;
}


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

bool inside(int y, int x) {
  return 0 <= y && y < 8 && 0 <= x && x < 8;
}

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

  for (int Case = 1; Case <= n; ++Case) {
    bool b[10][10];
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        scanf("%1d", &b[i][j]);
      }
    }

    queue<pair<int, int>> q;
    int x, y;
    int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

    cin >> x >> y;
    q.push(make_pair(x - 1, y - 1));

    while (!q.empty()) {
      x = q.front().first;
      y = q.front().second;
      q.pop();

      if (!b[y][x]) continue;
      b[y][x] = false;

      for (int k = 1; k <= 3; ++k) {
        for (int i = 0; i < 4; ++i) {
          int nx = x + k * dx[i];
          int ny = y + k * dy[i];
          if (inside(ny, nx) && b[ny][nx]) {
            q.push(make_pair(nx, ny));
          }
        }
      }
    }

    cout << "Data " << Case << ":" << endl;
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cout << b[i][j] << (j + 1 == 8 ? "\n" : "");
      }
    }
  }
}

Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int N=100100,MOD=1000000007;
ll fact[N];
int n,m;
void initialize()
{
	scanf("%d%d",&n,&m);
	if(n>m)std::swap(n,m);
	fact[0]=1;
	for(int i=1;i<=m;i++)
		fact[i]=fact[i-1]*i%MOD;
}
int main()
{
	initialize();
	if(m-n>1)printf("0\n");
	else 
	{
		if(n==m)printf("%lld\n",fact[n]*fact[n]%MOD*2%MOD);
		else printf("%lld\n",fact[n]*fact[m]%MOD);
	}
	return 0;
}


Measured memory_bytes: 1024
// ABC150B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>

#include <string>
using namespace std;
int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < S.length()-2; i++)
	{
		if (S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C')
		{
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long sum[200001] = {};

int main() {
    int N; cin >> N;
    vector<int> C(N);
    for(int i=0; i<N; ++i) cin >> C[i];
    C.erase(unique(begin(C), end(C)), end(C));

    const long long MOD = 1000000007;
    sum[C[0]] = 1;
    for(int i=1; i<C.size(); ++i) {
        sum[C[i]] = (sum[C[i]] + sum[C[i - 1]]) % MOD;
    }
    cout << sum[*rbegin(C)] << endl;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        while(true){
            String a = sc.next();
            if(a.equals("0")) break;
            
            int sum = 0;
            for(int i=0; i< a.length(); i++){
                sum += Integer.parseInt(String.valueOf(a.charAt(i)));
            }
            System.out.println(sum);
        }
    }

}



Measured memory_bytes: 26620
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

struct UnionFind {
  vi par, count;

  UnionFind(int N) : par(N), count(N, 1){
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int root(int x){
    if(par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }

  int unite(int x, int y){
    if(root(x) == root(y)) return 0;
    if(size(x) < size(y)){
      count.at(root(y)) += count.at(root(x));
      par.at(root(x)) = root(y);
    }
    else{
      count.at(root(x)) += count.at(root(y));
      par.at(root(y)) = root(x);
    }
    return 1;
  }

  bool same(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return count.at(root(x));
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vvll A(M, vll(0));
  for(int i = 0; i < N; i++){
    ll K;
    cin >> K;
    for(int j = 0; j < K; j++){
      ll L;
      cin >> L;
      L--;
      A.at(L).push_back(i);
    }
  }
  UnionFind uf(N);
  for(int i = 0; i < M; i++){
    for(int j = 0; j < sz(A.at(i)); j++){
      uf.unite(A.at(i).at(0), A.at(i).at(j));
    }
  }
  if(uf.size(0) == N) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 4736
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] L = new int[2 * N];
        for (int i = 0; i < 2 * N; i++)
        {
            L[i] = cin.nextInt();
        }
        Array.Sort(L);
        int sum = 0;
        for (int i = 0; i < 2 * N; i += 2)
        {
            sum += Math.Min(L[i], L[i + 1]);
        }
        Console.WriteLine(sum);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e3+5;
const ll M = 1e9+7;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int _;
pair<ll,int> P[maxn];
ll dp[maxn][maxn];
int main()
{
    fastio();
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>P[i].first;
        P[i].second = i;
    }
    sort(P+1,P+n+1);
    reverse(P+1,P+n+1);
    for(int i=1;i<=n;i++)
    {
        dp[i][0] = dp[i-1][0]+P[i].first*abs(P[i].second-(n-i+1));
        dp[i][i] = dp[i-1][i-1]+P[i].first*abs(P[i].second-i);
        for(int j=1;j<i;j++)
        {
            int x = n-(i-1-j);
            dp[i][j] = max(dp[i][j],dp[i-1][j]+P[i].first*abs(P[i].second-x));
            dp[i][j] = max(dp[i][j],dp[i-1][j-1]+P[i].first*abs(P[i].second-j));
        }
    }
    ll ans = 0;
    for(int i=0;i<=n;i++) ans = max(ans,dp[n][i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26296
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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 (a > b) { a = b; return true; } return false; }

int cnt = 0;

// merge sort
template <class It>
void merge(It l, It m, It r) {
	vector<int> tmp(r - l);
	It it = tmp.begin(), it1 = l, it2 = m;
	while (it1 != m && it2 != r) {
		cnt++;
		if (*it1 < *it2)
			*it++ = *it1++;
		else
			*it++ = *it2++;
	}
	while (it1 != m) {
		cnt++; *it++ = *it1++;
	}
	while (it2 != r) {
		cnt++; *it++ = *it2++;
	}
	move(tmp.begin(), tmp.end(), l);
};

template <class It>
void merge_sort(It l, It r) {
	if (r - l <= 1)return;
	It m = l + (r - l) / 2;
	merge_sort(l, m);
	merge_sort(m, r);
	merge(l, m, r);
}
// end merge sort

signed main() {
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	merge_sort(v.begin(), v.end());
	cout << v[0]; rep(i, 1, v.size()) { cout << " " << v[i]; } cout << endl;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7716
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
$sum = $n*($n-1)/2;
for($i = 0; $i < $m; $i++){
    $data[] =  explode(" ", trim(fgets(STDIN)));
}
$data = array_reverse($data);

$uft = new UFT($n);
$sum = ($n * ($n-1)) / 2;
foreach($data as $row){
    $history[] = $sum;
    $s1 = $uft->size($row[0]);
    $s2 = $uft->size($row[1]);
    $uft->unite($row[0], $row[1]);
    $s3 = $uft->size($row[0]);
    if($s1 != $s3){
        $sum -= $s1 * $s2;
    }
}
echo implode("\n", array_reverse($history));

class UFT{
    public $parent;
    public $size;
    public $rank;
    public function __construct($size){
        for($i = 1; $i <= $size; $i++){
            $this->size[$i] = 1;
            $this->rank[$i] = 1;
            $this->parent[$i] = 0;
        }
    }
    public function dump(){
        o("--------------");
        o($this->parent);
        o($this->size);
        o($this->rank);
    }
    public function getRoot($i){
        if($this->parent[$i] == 0){
            return $i;
        }else{
            return $this->getRoot($this->parent[$i]);
        }
    }
    public function unite($i, $j){
        $rootI = $this->getRoot($j);
        $rootJ = $this->getRoot($i);
        if($rootJ == $rootI)return false;//元から同じグループ
        if($this->rank[$rootI] > $this->rank[$rootJ])list($rootI, $rootJ) = [$rootJ, $rootI];//Rank(J)>Rank(I)に揃えておく
        $this->parent[$rootI] = $rootJ;
        if($this->rank[$rootI] == $this->rank[$rootJ]){
            $this->rank[$rootJ]++;
        }
        $this->size[$rootJ]+=$this->size[$rootI];
        $this->size[$rootI] = '*';//不要な情報となるので潰す/デバッグ出力向けに*を入れている
        $this->rank[$rootI] = '*';//同上
    }
    public function size($i){return $this->size[$this->getRoot($i)];}
    public function isUnion($i, $j){return $this->getRoot($i) == $this->getRoot($j);}
}

Measured memory_bytes: 72684
n = gets.to_i
graph = Array.new(n){ Array.new(n, 0) }

n.times do
    u, k, *adj = gets.split.map(&:to_i)
    k.times do |i|
      graph[u-1][adj[i]-1] = 1
    end
end
graph.each do |i|
  puts i.join(' ')
end

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

struct Problem {

    void Solve() {
        UL N; cin >> N; N++;
        UL K; cin >> K;
        const ULL M = 1000000007;
        ULL ans = 0;
        for (UL i = K; i <= N; i++) {
            ULL tmp = ULL(N) * (N + 1) / 2;
            tmp -= ULL(N - i) * (N - i + 1) / 2;
            tmp -= ULL(i) * (i + 1) / 2;
            tmp++;
            ans += tmp; ans %= M;
        }
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
B = [a - i for i, a in enumerate(A, 1)]
sorted_B = sorted(B)
b = sorted_B[N // 2]
ans = 0
for i, a in enumerate(A, 1):
    ans += abs(a - (b + i))
print(ans)


Measured memory_bytes: 101460
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;
int main(){
int a, b;
cin >> a >> b;
if(a+b < 10){
    cout << a+b << endl;
}
else{
    cout << "error" << endl;
}
}


Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T=int> using order_statistics = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

long long dp[105][100005];
int w[105], v[105];

int main(int argc, char* argv[]) {
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    int n, W;
    cin >> n >> W;
    for (int i = 1;i <= n;++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1;i <= n;++i) {
        for (int j = 1;j <= W;++j) {
            if (j - w[i] >= 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n),f(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>f[i];
	
	sort(a.begin(),a.end());
	sort(f.rbegin(),f.rend());
	// for(auto t: a)
	// 	cout<<t<<" ";
	// cout<<endl;
	// for(auto t:f)
	// 	cout<<t<<" ";
	// cout<<endl;
	ll low=0,high=1e18;
	while(low<high)
	{
		ll mid=(low+high)>>1;
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			if(mid<a[i]*f[i])
				cnt+=a[i]-mid/f[i];
		}
		// cout<<mid<<" "<<cnt<<endl;
		if(cnt<=k)
			high=mid;
		else
			low=mid+1;
	}
	cout<<low<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=55;
const ll mod=1e9+7;
ll fac[N],inv[N],f[N][N],n;
ll C(ll n,ll m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	n=read();
	fac[0]=1;for(ll i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(ll i=2;i<=n;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(ll i=1;i<=n;i++)inv[i]=inv[i-1]*inv[i]%mod;
	f[1][0]=f[1][1]=n;
	for(ll i=1;i<=n;i++)for(ll j=1;j<=n-i;j++)for(ll k=0;k<=j;k++){
		if((j-k)&1)continue;ll re=(j-k)/2;
		for(ll d=0;d<=j;d++)f[i+j][abs(re-d)]=(f[i+j][abs(re-d)]+f[i][k]*C(n-i,j)%mod*C(j,d)%mod)%mod;
	}return cout<<f[n][0],signed();
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <array>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template<typename T>
#define _HT template<typename H,typename... T>
_T _DEF(T,in,int c){T n{};int m{1};while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
_T _SCAN(T &n){int c{gcu()};return c==EOF?false:(n=in<T>(c),true);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
_OUT(string s){for(char c:s)pcu(c);}
#endif
_OUT(const char *s){while(*s)pcu(*s++);}
_T _OUT(T n){static char b[20];char *p{b};T m=n<0?pcu('-'),-1:1;if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{int e,b{0},s{1};range(int _b,int _e,int _s):e(_e),b(_b),s(_s){}range(int _b,int _e):e(_e),b(_b){}range(int _e):e(_e){}
	struct it{int v,s;it(int _v,int _s):v(_v),s(_s){}operator int()const{return v;}operator int&(){return v;}int operator*()const{return v;}it& operator++(){v+=s;return *this;}};
	it begin(){return{b, s};}it end(){return{e,s};}};

int main() {
	const array<const array<int, 4>, 2> l {1, 1, 3, 1, 0, 2, 0, 2};
	string s;
	for (int n, m; (n = in());) {
		scan(m, s);
		int r {}, t {}, i {};
		for (char c: s) {
			i = l[c == 'O'][i];
			if (i < 2)
				t = 0;
			else if (i == 3 && ++t >= n)
				r++;
		}
		outl(r);
	}
}


Measured memory_bytes: 3268
import java.util.*;
 
public class  Main{
	public static void main(String args[]){
	  Scanner sc = new Scanner(System.in);
  	  String s = sc.next();
      String t = sc.next();
      Integer a = Integer.parseInt(sc.next());
      Integer b = Integer.parseInt(sc.next());
      String u = sc.next();
      
      if(s.equals(u)) System.out.println((a-1)+" "+b);
      else System.out.println(a+" "+(b-1));
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
const int IINF = (1 << 30);

const ll MOD = 1e9 + 7;

ll mpow(int base, int n)
{
    if (n == 0)
    {
        return 1;
    }
    ll prev = mpow(base, n / 2);
    if (n % 2 == 0)
    {
        return (prev * prev) % MOD;
    }
    else
    {
        return (prev * prev * base) % MOD;
    }
}

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    vector<vector<ll>> dp(s.size() + 1, vector<ll>(3, 0)); //0:"A" 1:"A"
    dp[0][0] = 1;
    ll ans = 0;
    ll cur = 0;
    rep(i, s.size())
    {
        dp[i + 1] = dp[i];
        if (s[i] == 'A')
        {
            dp[i + 1][1] += mpow(3, cur); //dp[i][0];
        }
        else if (s[i] == 'B')
        {
            dp[i + 1][2] += dp[i][1];
        }
        else if (s[i] == 'C')
        {
            dp[i + 1][0] += dp[i][2];
            ans += dp[i][2];
        }
        else if (s[i] == '?')
        {
            dp[i + 1][1] += mpow(3, cur);
            dp[i + 1][2] += dp[i][1];
            dp[i + 1][0] += dp[i][2];

            dp[i + 1][0] += 2 * dp[i][0];
            dp[i + 1][1] += 2 * dp[i][1];
            dp[i + 1][2] += 2 * dp[i][2];

            ans += 2 * ans;
            ans += dp[i][2];
            cur++;
        }
        dp[i + 1][0] %= MOD;
        dp[i + 1][1] %= MOD;
        dp[i + 1][2] %= MOD;
        //cerr << dp[i + 1][0] << " " << dp[i + 1][1] << " " << dp[i + 1][2] << " " << ans << endl;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    long long h;
    scanf("%lld",&h);
    long long a = h;
    long long cnt = 1;
    while (a != 1)
    {
        a /= 2;
        cnt++;
    }
    long long ans = powl(2,cnt);
    printf("%lld",ans - 1);
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static int dp[];
    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)throws IOException {
        FastReader fr = new FastReader();
        int n=fr.nextInt();
        int m=fr.nextInt();
        HashMap<Integer,ArrayList<Integer>> hm=new HashMap<>();
        for(int i=0;i<m;i++)
        {
            int k=fr.nextInt();
            int v=fr.nextInt();
            if(hm.containsKey(k))
            {
                ArrayList<Integer> t=hm.get(k);
                t.add(v);
                hm.put(k,t);}
            else {
                ArrayList<Integer> t=new ArrayList<>();
                t.add(v);
                hm.put(k,t);
            }
        }
        dp=new int[n+1];
        Arrays.fill(dp,-1);
        int max=-1;
        for(int i:hm.keySet())
            max=Math.max(max,dfs(hm,i));
        System.out.println(max);

    }
    public static int dfs(HashMap<Integer,ArrayList<Integer>> hm,int v)
    {
        int max=0;
        if(dp[v]!=-1)
            return dp[v];
        if(hm.containsKey(v)){
            for(int i=0;i<hm.get(v).size();i++)
            {
                max=Math.max(max,1+dfs(hm,hm.get(v).get(i)));
            }
        }

        return dp[v]= max;
    }




}


Measured memory_bytes: 76968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;

main(){
    int n;cin>>n;
    string temp;
    int a[4]={0};
    for(int i=0;i<n;i++){
        cin>>temp;
        if(temp == "AC") a[0]++;
        else if(temp == "WA") a[1]++;
        else if(temp == "TLE") a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<"\n";
    cout<<"WA x "<<a[1]<<"\n";
    cout<<"TLE x "<<a[2]<<"\n";
    cout<<"RE x "<<a[3]<<"\n";
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
int main()
{
    int s,a,b,c,d;
    scanf("%d",&s);
    d=s%10;s/=10;
    c=s%10;s/=10;
    b=s%10;s/=10;
    a=s%10;
    if(a+b+c+d==7)
        {printf("%d+%d+%d+%d=7\n",a,b,c,d);return 0;}
    if(a+b+c-d==7)
        {printf("%d+%d+%d-%d=7\n",a,b,c,d);return 0;}
    if(a+b-c+d==7)
        {printf("%d+%d-%d+%d=7\n",a,b,c,d);return 0;}
    if(a+b-c-d==7)
        {printf("%d+%d-%d-%d=7\n",a,b,c,d);return 0;}
    if(a-b+c+d==7)
        {printf("%d-%d+%d+%d=7\n",a,b,c,d);return 0;}
    if(a-b+c-d==7)
        {printf("%d-%d+%d-%d=7\n",a,b,c,d);return 0;}
    if(a-b-c+d==7)
        {printf("%d-%d-%d+%d=7\n",a,b,c,d);return 0;}
    if(a-b-c-d==7)
       {
           printf("%d-%d-%d-%d=7\n",a,b,c,d);
    return 0;
       }
}


Measured memory_bytes: 128
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,s,t,flg;
	scanf("%d %d %d %d",&h,&w,&s,&t);
	flg=1;
	if((s-1)%2==0 && (h-s)%2==0)	{
		if((t-1)%2==1 && (w-t)%2==1)	flg=0;
	}
	if((t-1)%2==0 && (w-t)%2==0)	{
		if((s-1)%2==1 && (h-s)%2==1)	flg=0;
	}	
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
char s[30005];
bool dp[1005][4];
int main(){
    int n;
    scanf("%d%s", &n, s+1);   
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        s[i] -= '0';
        for(int j=999;j>=0;j--){
            for(int k=2;k>=0;k--){
                if(dp[j][k]){
                    dp[j*10+s[i]][k+1] = 1;
                }
            }
        }
    }
    int ans = 0;
    for(int i=0;i<1000;i++) ans += dp[i][3];
    printf("%d\n", ans);
}

Measured memory_bytes: 3828
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, A: "List[int]"):
    mm = lambda x: mod(x, M)
    A = [0] + A
    c = Counter(map(mm, accumulate(map(mm, A))))

    ret = 0
    for v in c.values():
        ret += v * (v - 1) // 2
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, M, A)
    print(result)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int K; cin >> K;
    VI dist(K,INF);
    deque<P> deq; deq.emplace_back(1,0);
    while(!deq.empty()){
        P p = deq.front(); deq.pop_front();
        if(dist[p.first]<INF) continue;
        int v = p.first, cost = p.second;
        dist[v] = cost;
        deq.emplace_front((v*10)%K,cost); deq.emplace_back((v+1)%K,cost+1);
    }
    int ans = dist[0]+1;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
string x,y;
int lena,lenb;
int main(){
    getline(cin,x),getline(cin,y);
    sort(x.begin(),x.end());
    sort(y.begin(),y.end(),greater<char>());
    if(x<y)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

int main(){
    long double A,B,H,M,h,m;
    cin >> A >> B >> H >> M;
    m = 6*M;
    h = 30*H + 0.5*M;

    cout << setprecision(20) << sqrt(A*A + B*B - 2*A*B*cos(M_PI*abs(h-m)/180)) << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    long long A, B, N;
    cin >> A >> B >> N;
    long long x = min(B-1, N);
    cout << (A*x)/B - A*(x/B) << endl;
}

















Measured memory_bytes: 3636
#include<stdio.h>

void trace(int A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionSort(/* arguments */ int A[], int N) {
  int j, i, v;
  for ( i = 1; i < N; i++ ) {
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v) {
      A[j +1] = A[j];
      j--;
    }
    A[j +1] = v;
    trace(A, N);
  }
}

int main() {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) scanf("%d", &A[i] );

  trace(A, N);
  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 2096
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    long long int N;

    cin >> N;

    if (N % 2 == 1)
    {
        cout << "0" << endl;
        return 0;
    }

    long long int i = 1;
    long long int count = 0;

    while (pow(5, i) * 2 <= N)
    {
        long long int r = pow(5, i) * 2;
        count += N / r;
        i++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int X; cin >> X;
    int ans = 0;
    if (X == 1) {
        cout << "1";
        exit(0);
    }
    rep(i, 1, 32) {
        rep(j, 2, X) {
            int v = pow(i, j);
            if (v <= X) ans = max(ans, v);
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
    while (1){
    int m, n = 0;
    bool member[101][101] = {{false}}; // who knows who

    cin >> n;
    if (n == 0) break;
    for (int i = 1; i <= n; i++){
	cin >> m;
	for (int j = 1; j <= m; j++){
	    int tmp;
	    cin >> tmp;
	    member[i][tmp] = true;
	}
    }

    int k;
    cin >> k;
    int ohno[101] = {false};
    for (int i = 0; i < k; i++){
	int tmp;
	cin >> tmp;
	ohno[tmp] = true;
    }
    int many = 0;

    bool theOne = true;
    int mem = 0;
    for (int j = 1; j <= n; j++){
	theOne = true;
	for (int i = 1; i <= n; i++){ // member
	    if (ohno[i]){
		if (!member[j][i]) theOne = false;
	    }
	}
	if (theOne){
	    many++;
	    mem = j;
	}
    }
    
    if (many == 1) cout << mem << endl;
    else cout << -1 << endl;
    }
}
    

Measured memory_bytes: 876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string t;
    cin >> t;
    rep(i,sz(t)){
        if(t[i]=='?'){
            t[i] = 'D';
        }
    }
    print(t);
}


Measured memory_bytes: 3760