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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define mod 1000000007

ll solve(vector<vector<char> >mat,ll n,ll w)
{

    ll dp[n][w];
    dp[0][0]=1;
    int col=1;

    while(col <w && mat[0][col]=='.' )
    {
        dp[0][col]=1;
        col++;
    }

    while(col<w)
    {
        dp[0][col]=0;
        col++;
    }

    int row=1;

    while(row<n && mat[row][0]=='.' )
    {
        dp[row][0]=1;
        row++;

    }



    while(row<n)
    {
        dp[row][0]=0;
        row++;
    }


    for(int i=1;i<n;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(mat[i][j]=='.')
            {
                dp[i][j]=(dp[i][j-1]%mod+ dp[i-1][j]%mod)%mod;

            }
            else
                dp[i][j]=0;

        }

    }

    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<w;j++)
            cout<<dp[i][j]<<" ";
        cout<<"\n";
    }*/

    return dp[n-1][w-1];

}

int main()
{
	FASTIO;
	ll n,w;
	 cin>>n>>w;

	 vector<vector<char> >mat(n,vector<char>(w));

	 for(int i=0;i<n;i++)
        for(int j=0;j<w;j++)
            cin>>mat[i][j];

     ll ans=solve(mat,n,w);
	 cout<<ans%mod<<"\n";
	return 0;
}













Measured memory_bytes: 10112
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 200002
int dp[26][MAX_N]={};
bool d[MAX_N]={};
int pa[MAX_N];
vector<edge> G[MAX_N];
P1 cost[MAX_N]={};
vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que;
ll a[100005]={};
ll b[100005]={};
int main() {
	int n;
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	ll t=0;
	rrep(i,n){
		ll k=a[i]+t;
		if(k==0)continue;
		t+=(b[i]-k%b[i])%b[i];
//		cout<<t<<endl;
	}

	cout<<t<<endl;
	return 0;
}





Measured memory_bytes: 18688
//https://atcoder.jp/contests/dp/tasks/dp_g

#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;
//const ll INF = 1e18L + 5;
const int INF = 1e9 + 5;


enum class  Color {
	NOT_VISITED, PROCESING, VISITED
};

int dfs( int v, vector<Color> & seen, map<int, vector<int>> & G, unordered_map<int, int> & memo) {
	if(seen[v] == Color::VISITED) return memo[v];

	assert(seen[v] != Color::PROCESING);

	seen[v] = Color::PROCESING;

	int maxLenSeen = 0;
	for(auto u : G[v]) {
		maxLenSeen = max(maxLenSeen, dfs(u, seen, G, memo) + 1);
	}

	seen[v] = Color::VISITED;
	memo[v] = maxLenSeen;
	return maxLenSeen;
}

int solveLongestPath() {
	int v, m; cin >> v >> m;

	map<int, vector<int>> G;
	for(auto i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
	}


	unordered_map<int, int> memo;
	vector<Color> seen(v + 1, Color::NOT_VISITED);
	int maxLen = 0;
	for(auto i = 1; i <= v; ++i) {
		if(seen[i] == Color::NOT_VISITED) {
			maxLen = max(maxLen, dfs(i, seen, G, memo));
		}
	}


	// for(auto i = 1; i <= v; ++i) {
	// 	cout << " i: " << i << " - > ";
	// 	switch(seen[v]) {
	// 		case Color::NOT_VISITED : cout << " NOT_VISITED"; break;
	// 		case Color::PROCESING : cout << " PROCESING"; break;
	// 		case Color::VISITED : cout << " VISITED"; break;
	// 	}
	// 	cout << " memo : " << memo[i] ;
	// 	cout <<endl;
	// }
	return maxLen;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	auto ret = solveLongestPath();
	cout << ret << endl;
	return 0;
}




Measured memory_bytes: 20516
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

int main(){
    int p,q,r;
    cin >> p >> q >>r;
    int a = max(p,max(q,r));
    cout << p+q+r-a;
}

Measured memory_bytes: 256
#include <iostream>

/* 切り上げ */
void round_up(int *num, const int round_num)
{
    int fraction;  // 端数
    int tmp;
    
    tmp = *num;
    fraction = tmp % round_num;
    
    tmp /= round_num;
    if (fraction != 0){
        tmp++;
    }
    *num = tmp * round_num;
}

/* 借金額 */
int debt(const int amount, const int weeks)
{
    int ret;
    int round_num = 1000;  // 切り上げる基準の数
    
    ret = amount;
    for (int i = 0; i < weeks; i++){
        ret *= 1.05;  // 利子計算
        round_up(&ret, round_num);
    }
    
    return ret;
}

int main()
{
    int n;
    
    std::cin >> n;
    
    std::cout << debt(100000, n) << std::endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>

using namespace std;

int top, S[101];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top = 0;
  string s;
  while (cin >> s){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(s.c_str()));
    }
  }

  cout << pop() << endl;

  return 0;
}



Measured memory_bytes: 3164
x, y = input().split()
dic = {"1": "A", "2": "C", "3": "A", "4": "B", "5": "A",
       "6": "B", "7": "A", "8": "A", "9": "B", "10": "A", "11": "B", "12": "A"}
if dic[x] == dic[y]:
    print("Yes")
else:
    print("No")


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

const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
const int MAX_N = 27;
int H, W;
string g[MAX_N];
int dist[MAX_N][MAX_N][MAX_N][MAX_N];

void solve()
{
    memset(dist,0x3f,sizeof(dist));
	int ans = 0;
	for(int i=0;i<H;++i)for(int j=0;j<W;++j)if(g[i][j]=='.'){
		dist[i][j][i][j]=0;
		for(int k=0;k<4;++k){
		    int nx=i+dx[k], ny=j+dy[k];
		    if(nx>=0&&nx<H&&ny>=0&&ny<W&&g[nx][ny]=='.') dist[i][j][nx][ny]=dist[nx][ny][i][j]=1;
		}
	}
	for(int kx=0;kx<H;++kx)for(int ky=0;ky<W;++ky)
	for(int x=0;x<H;++x)for(int y=0;y<W;++y)if(g[x][y]=='.')
	for(int a=0;a<H;++a)for(int b=0;b<W;++b)if(g[a][b]=='.'){
	    dist[x][y][a][b]=min(dist[x][y][a][b],dist[x][y][kx][ky]+dist[kx][ky][a][b]);
	}
	for(int x=0;x<H;++x)for(int y=0;y<W;++y)if(g[x][y]=='.')
	for(int a=0;a<H;++a)for(int b=0;b<W;++b)if(g[a][b]=='.'){
	    ans=max(ans,dist[x][y][a][b]);
	}
	cout << ans << '\n';
}

int main()
{
	cin >> H >> W;
	for(int i=0;i<H;++i) cin >> g[i];
	solve();
	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int selectionSort(int[], int);
int main(){
  int i, N, con;
  int A[100];

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

  printf("%d",A[0]);
  for( i = 1 ; i < N ; i++ ){
    printf(" %d",A[i]);
  }
  printf("\n%d\n",con);
  return 0;
}

int selectionSort(int A[], int N){
  int i, j, con=0, minj, tmp;
  for( i = 0 ; i < N ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if( A[j] < A[minj] ) minj = j;
    }
    if( i != minj ) con++;
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
  }
  return con;
}



Measured memory_bytes: 2140
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    int V, E;
    cin>>V>>E;
    vector<vector<pair<int, int> > > edge(V);
    int s, t, w;
    for(int i=0;i<E;++i){
        cin>>s>>t>>w;
        edge[s].push_back(make_pair(t, w));
        edge[t].push_back(make_pair(s, w));
    }
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, 0));
    pair<int, int> state;
    int dot, cost;
    int DP[V];
    for(int i=0;i<V;++i){
        DP[i] = -1;
    }
    while(!que.empty()){
        state = que.top();que.pop();
        dot = state.se;
        cost = state.fi;
        if(DP[dot]!=-1) continue;
        DP[dot] = cost;
        for(int i=0;i<edge[dot].size();++i){
            if(DP[edge[dot][i].fi]!=-1) continue;
            que.push(make_pair(edge[dot][i].se, edge[dot][i].fi));
        }
    }
    int ans = 0;
    for(int i=0;i<V;++i){
        ans += DP[i];
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 6816
#include <stdio.h>
int main(void){
	int x,y,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0) break;

		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


V<string> split(const string& s, char c) {
  V<string> res;
  stringstream ss(s);
  string t;
  while (getline(ss, t, c)) {
    res.push_back(t);
  }
  return res;
}

VV<> convert(const string& s) {
  VV<> res;
  for (const auto& e : split(s, '/')) {
    V<> curr;
    for (char c : e) {
      if (c == 'b') {
        curr.push_back(1);
      } else {
        while (c-- > '0') curr.push_back(0);
      }
    }
    res.push_back(curr);
  }
  return res;
}

string invert(const VV<>& a) {
  int h = a.size();
  string res;
  for (int i = 0; i < h; ++i) {
    if (i) res += '/';
    int w = a[i].size();
    int t = 0;
    for (int j = 0; j < w; ++j) {
      if (a[i][j]) {
        res += 'b';
      } else {
        ++t;
        if (j == w - 1 or a[i][j + 1]) {
          res += '0' + t;
          t = 0;
        }
      }
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    string s; cin >> s;
    if (s == "#") break;
    auto a = convert(s);
    for (int _ = 0; _ < 2; ++_) {
      int i, j; cin >> i >> j, --i, --j;
      a[i][j] ^= 1;
    }
    s = invert(a);
    cout << s << '\n';
  }
}


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

using namespace std;

const int M = 1e5 + 10;
int n, a[M];

inline int gcd(int a, int b) {
	if(b == 0) return a;
	else return gcd(b, a%b);
}

inline bool go() {
	bool all1 = 1;
	int cnt = 0;
	for (int i=1; i<=n; ++i) {
		all1 &= (a[i] == 1);
		if(a[i] == 1) continue;
		cnt += (a[i]%2 == 0);
	}
	if(all1) return 0;
	if(cnt&1) return 1;
	else {
		if(n - cnt != 1) return 0;
		else {
			for (int i=1; i<=n; ++i) if(a[i] != 1 && (a[i]&1)) --a[i];
			int t = -1;
			for (int i=2; i<=n; ++i) 
				if(a[i] != 1) {
					if(t == -1) t = a[i];
					else t = gcd(t, a[i]);
				}
			for (int i=1; i<=n; ++i) if(a[i] != 1) a[i] /= t;
			return go() ^ 1;
		}
	}
}

int main() {
	cin >> n;
	for (int i=1; i<=n; ++i) cin >> a[i];	
	cout << (go() ? "First" : "Second");
	return 0;
}
			

Measured memory_bytes: 640
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n;
        ll a[200005],b[200005];
        ll i,j,k,l,m;
        cin>>n;
        priority_queue<pair<ll,ll>> pq;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            pq.push({b[i],i});
        }
        ll ans=0;
        while(!pq.empty())
        {
            pair<ll,ll> p=pq.top();
            pq.pop();
            if(p.F<a[p.S])
            {
                cout<<-1;
                return 0;
            }
            if(p.F==a[p.S])
            {
                continue;
            }
            // ans++;
            ll i=p.S;
            ll pre=(i-1+n)%n;
            ll nex=(i+1)%n;
            ll y=(b[i]-max(b[pre],b[nex])+b[pre]+b[nex]-1)/(b[pre]+b[nex]);
            // cout<<(b[i]-max(b[pre],b[nex])+b[pre]+b[nex]-1)<<" "<<y<<endl;
            y=min(y,(b[i]-a[i])/(b[pre]+b[nex]));
            if(y==0)
            {
                cout<<-1;
                return 0;
            }
            // cout<<i<<" "<<b[i]<<" "<<y<<endl;
            ans=ans+y;
            b[i]=b[i]-y*(b[nex]+b[pre]);
            pq.push({b[i],i});
            // break;
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 9584
import math


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [10**9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break

        dp[i] = min(
            dp[i],
            dp[i - j] + abs(h[i] - h[i - j])
        )

print(dp[-1])


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

int main()
{
    ll n;
    cin >> n;
    ll ans=0;
    ll five=10;
    if(n%2==1){
        ans=0;
    }else{
        while(n>=five){
            ans+=n/five;
            five*=5;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        System.out.println(judge(x));
    }
    static long judge(long x){
        long r = (x/11)*2;
        x%=11;
        if(x>6){
            r+=2;
        }else if(x>0){
            r+=1;
        }
        return r;
    }
}

Measured memory_bytes: 9812
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = T
tmp = 0

for i in range(1, N):
    if t[i] - t[i - 1] <= T:
        ans += t[i] - t[i - 1]
    else:
        ans += T
        tmp = t[i]

print(ans)


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    int n;
    cin>>n;
    int c1=0,c2=0,c3=0,c4=0;

    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
            c1++;
        else if(s=="WA")
            c2++;
        else if(s=="TLE")
            c3++;
        else if(s=="RE")
            c4++;
    }
    cout<<"AC x "<<c1<<"\n";
    cout<<"WA x "<<c2<<"\n";
    cout<<"TLE x "<<c3<<"\n";
    cout<<"RE x "<<c4<<"\n";


}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
	int N;
  	char S[50];
  	int count=0;
  	int i;
  	scanf("%d",&N);
  	scanf(" %c",&S[0]);
  	for(i=1;i<N;i++){
      scanf("%c",&S[i]);
  	}
  	for(i=0;i<=N-3;i++){
    	if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
        	count++;
        }
    }
  	printf("%d\n",count);
  	return 0;
}


Measured memory_bytes: 1736
#三井住友信託銀行プログラミングコンテスト2019-D
N = int(input())
S = input()
ans = 0

possible_pass = [str(i).zfill(3) for i in range(1000)]

for password in possible_pass:
    try:
        first_num = S.index(password[0])
        S_second = S[first_num+1:]
        second_num = S_second.index(password[1])
        S_third = S_second[second_num+1:]
        third_num = S_third.index(password[2])
        ans += 1
    except:
        continue
    
print(ans)

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

int main() {
  int N, K;
  cin >> N >> K;
  int x;
  int r=1;
  for (int j=0; j<N; j++) {
    r *= 2;
  }
  int min=(r);
  
  for (int i=0; i<(r); i++) {
    int y=i, c=1;
    
    for (int j=0; j<N; j++) {
      x = (y%2);
      y = (y/2);
      
      if (x == 0) {
        c *= 2;
      }
      
      else if (x == 1) {
        c += K;
      }
      
    }
    
    if (min > c) {
      min = c;
    }
    
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void)
{
    int a,b,k,i,tmp;
    scanf("%d%d%d",&a,&b,&k);
    for(i=a;i<a+k;i++){
        printf("%d\n",i);
        if(i==b) return 0;
    }   
    tmp=i;
    for(i=(b-k+1);i<=b;i++){
        if(i<tmp) i=tmp;
        printf("%d\n",i);
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int cnt[26] = {};
	bool f = 0;
	for (int i = 0; i < s.size(); i++)cnt[s[i] - 'a']++;
	for (int i = 0; i < 26; i++)if (cnt[i] > 1)f = 1;
	if (f)cout << "no" << endl;
	else cout << "yes" << endl;
	return 0;
}

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


int main(){
  int a[7],b[7];
  for(int i=0;i<7;i++){
    cin>>a[i]>>b[i];
    a[i]=a[i]-b[i];
  }
  for(int i=0;i<7;i++){
      cout<<a[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092
from collections import defaultdict
import bisect


n, k = map(int, input().split())
A = list(map(int, input().split()))

S = [0] * (n + 1)
for i in range(1, n + 1):
    S[i] = S[i - 1] + A[i - 1]

T = [0] * (n + 1)
for i in range(1, n + 1):
    T[i] = (S[i] - i) % k

# print(S)
# print(T)
size = defaultdict(list)
for i in range(0, n + 1):
    size[T[i]].append(i)

# print(size)
ans = 0
for i in range(0, n + 1):
    # [index_i, index_j)
    # T[i][index_i] >= i
    # T[i][index_j] < (i + k) because T[i][index_j + 1] >= (i + k)
    index_i = bisect.bisect_left(size[T[i]], i)
    index_j = bisect.bisect_left(size[T[i]], i + k) - 1
    # print(index_i, index_j)
    ans += (index_j - index_i)

print(ans)


Measured memory_bytes: 71816
import math
 
n, k = list(map(int, input().split()))
 
ans = 0
 
"i点の時、k点以上になるためにはlog2(k/i)回連続で表を出す必要がある"
for i in range (1, n + 1):
  if i < k:
    omote = math.ceil(math.log(k/i, 2))
    ans += (1/2) **(omote)
  else :
    ans += 1
print(ans/n)

Measured memory_bytes: 3060
#include<stdio.h>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> P;
bool used[102][102];
bool ew[102][102];
int dx1[6]={0,-1,0,1,1,1};//奇数
int dx2[6]={-1,-1,-1,0,1,0};//偶数
int dy[6]={-1,0,1,1,0,-1};
int ans;
int w,h;
queue<P> que;
void bfs(){
	int i;
	used[0][0]=true;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		int x=p.first;
		int y=p.second;
		for(i=0;i<6;i++){
			int nx,ny;
			if(y%2==0)nx=x+dx2[i];
			else nx=x+dx1[i];
			ny=y+dy[i];
			if(nx<0||nx>w+1||ny<0||ny>h+1)continue;
			if(ew[ny][nx])ans++;
			else if(!used[ny][nx]){
				used[ny][nx]=true;
				que.push(P(nx,ny));
			}
		}
	}
}
int main(){
	int i,j;
	scanf("%d %d",&w,&h);
	for(i=0;i<h+2;i++)for(j=0;j<w+2;j++){
		used[i][j]=false;
		ew[i][j]=false;
	}
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		int x;
		scanf("%d",&x);
		if(x==1)ew[i+1][j+1]=true;
	}
	ans=0;
	bfs();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1076
#include <iostream>
#include <vector>
#include <climits>

int main(){
    int size;
    std::cin >> size;
    std::vector<int> v(size);
    for (int i = 0; i < size; i++){
        std::cin >> v[i];
    }
    int q;
    std::cin >> q;
    while(q--){
        int com, a, b;
        std::cin >> com >> a >> b;
        int min = INT_MAX;
        int max = -INT_MAX;
        for (int i = a; i < b; i++){
            if (com == 0){
                if (v[i] < min) min = v[i];
            }
            else {
                if (v[i] > max) max = v[i];
            }
        }
        if (com == 0) std::cout << min << std::endl;
        if (com == 1) std::cout << max << std::endl;
    }
}


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

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<double>> x(n, vector<double>(d));
    rep(i,n)rep(j,d) cin >> x[i][j];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            double dist = 0;
            rep(k,d) {
                dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            dist = sqrt(dist);
            int idist = (int)dist;
            if (dist == (double)idist) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=40005;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a,b;
	cin>>a>>b;
	for(int i=1;i<=1e6;i++)
	{
		int oof1=i*(8);
		oof1/=100;
		int oof2=i*10;
		oof2/=100;
		if(a==oof1&&b==oof2)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
}
// 0.08*x = a
// 
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int INF=(1<<29);
  int v,e,s,t,d,g[20][20],i,j,k,dp[(1<<16)][20];
  scanf("%d %d\n",&v,&e);
  for(i=0;i<v;i++){
    for(j=0;j<v;j++){
      g[i][j]=-1;
    }
  }
  for(i=0;i<e;i++){
    scanf("%d %d %d\n",&s,&t,&d);
    g[s][t]=d;
  }
  for(i=0;i<(1<<v);i++){
    for(j=0;j<v;j++){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  for(i=0;i<(1<<v);i++){
    for(j=0;j<v;j++){
      for(k=0;k<v;k++){
        if(g[j][k]!=-1 && (i&(1<<k))==0){
          dp[i|(1<<k)][k]=min(dp[i][j]+g[j][k],dp[i|(1<<k)][k]);
        }
      }
    }
  }
  if(dp[(1<<v)-1][0]==INF){
    printf("-1\n");
  }
  else{
    printf("%d\n",dp[(1<<v)-1][0]);
  }
  return 0;
}


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

int main() {
  int a;
  cin >> a ;
  int s1, s2, s3;
  s1=a/100;
  s2=a/10-10*s1;
  s3=a-100*s1-10*s2;
  cout << s1+s2+s3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
//#include <file>
using namespace std;

double speed(double time){
    return 9.8*time;
}
double height(double time){
    return 4.9*time*time;
}
double time(double speed){
    return speed/9.8;
}
int floor1(double height1){
    return static_cast<int>((height1+5)/5+0.5);
}

int main (int argc, char const* argv[]){
    double minspeed;
    double reachedTime;
    double heigh;
    
    while(cin >> minspeed){
        reachedTime = time(minspeed);
        heigh = height(reachedTime);
        //cout << floor1(heigh)<< endl;
        for(int i=0;i<100000;i++){
            if(heigh<=5*i-5){
                cout << i << endl;
                break;
            }
        }
    }
    
    return 0;
}

/*
    m/s
*/

Measured memory_bytes: 1224
import java.util.*;
public class Main {
	static int mod = (int)1e9+7;	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		for(int i=0;i<N;i++)A[i]=sc.nextLong();
		sc.close();

		long ans = 0;
		for(int i=0;i<61;i++) {
			int cnt = 0;
			for(int j=0;j<N;j++) {
				if(((A[j]>>i)&1)==1) cnt++;
			}
			ans += (long)cnt * (((long)(N-cnt) * (((long)1<<i)%mod)%mod)%mod);
			ans %= mod;	
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 98892
import sys
input = sys.stdin.readline

A, B, C = [int(x) for x in input().split()]

# Ax = By + C
# ⇄ Ax - By = C
# を満たすx, yが存在する
# CがGCD(A, B)の倍数であることが条件

# 最大公約数をユークリッドの互除法で求める
def GCD_by_euclid(x, y):
    if y == 0:
        return x
    else:
        return GCD_by_euclid(y, x % y)

gcd = GCD_by_euclid(A, B)
if C % gcd == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 61896
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void max_self(ll& a, ll b){
  a = max(a,b);
}
int main(){
	ll n, w; cin>>n>>w;
  	vector<ll> val(n), weight(n);
  	for(int i = 0 ; i < n; i++)
      cin>>weight[i]>>val[i];
	vector<ll> dp(w+1);
  	
  	for(int i = 0 ; i < n; i++)
      for(ll w_so_far = w -weight[i] ; w_so_far >=0 ; w_so_far--)
        	max_self(dp[w_so_far+weight[i]], dp[w_so_far]+val[i]);
  
	cout<<*max_element(dp.begin(),dp.end())<<endl;
  	return 0;
}

Measured memory_bytes: 4032
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, a, b;
	cin>>n>>a>>b;
	vector<ll> v(n);
	rep(i, n) cin>>v[i];
	cout<<(n>1?max(abs(b-v[n-1]), abs(v[n-2]-v[n-1])):abs(b-v[n-1]))<<endl;
	return 0;
}


Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/20
// Problem:Where's Snuke? ? a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1;

int main()
{
  CIN(H, W);
  string str;
  REP(hi, H) {
    REP(wi, W) {
      cin >> str;
      if (str == "snuke") printf("%c%d\n", wi + 65, hi + 1);
    }
  }

  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
    auto N = readln.split[0].to!ulong;
    auto A = readln.split.to!(ulong[]);
    N = A.length;
    auto grps = sort(A.dup).group;
    size_t[ulong] nums;
    
    //grps.array.writeln;
    
    foreach (tup; grps) {
        nums[tup[0]] = tup[1];
    }
    //nums.writeln; 
    
    ulong all_num = grps.map!(a => a[1] * (a[1]-1)).sum / 2;
    ulong all_num_true = nums.values.dup.map!(a => a*(a-1)).sum / 2;
    
    int[] re; re.length = N;
    if (
        all_num != all_num_true || (
            equal( sort(grps.map!(a => a[1]).array), sort(nums.values) ) &&
            !equal( sort(grps.map!(a => a[1] * (a[1]-1)).array), sort(nums.values.map!(a => a * (a-1)).array) )
        )
    ) {
        if (all_num_true > all_num) re[N+1] = 1;  // RE
        else if (all_num_true < all_num) writeln("aaa");   // WA
        else while (true) { writeln("tle"); }    // TLE
    }
    
    foreach (k; 0 .. N) {
        writeln( all_num_true - (nums[A[k]] - 1) );
    }
}



Measured memory_bytes: 26896
N = int(input())
H = list(map(int, input().split()))

max_val = 0

index = 0
while(index < len(H) - 1):
    index_boolean = index
    tmp = 0
    while (index_boolean < len(H) - 1):
        if (H[index + 1] <= H[index]):
            tmp += 1
            index += 1
            index_boolean += 1
        else:
            index_boolean = len(H)
            index += 1

    if (tmp > max_val):
        max_val = tmp

print(max_val)

Measured memory_bytes: 14380
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2; 
  if (m1 != m2) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


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

min_back1 = abs(hi[1] - hi[0])
min_back2 = 0

answer = min_back1

for i in range(2,n):
    back1 = abs(hi[i]-hi[i-1]) + min_back1
    back2 = abs(hi[i]-hi[i-2]) + min_back2

    answer = min(back1, back2)
    min_back2 = min_back1
    min_back1 = answer

print(answer)

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;


int main() {
    string s, t;
    bool ans = true;
    cin >> s >> t;
    map<char, char> mp1, mp2;
    rep(i, s.size()){
        if(mp1[s[i]] && mp1[s[i]] != t[i])ans = false;
        if(mp2[t[i]] && mp2[t[i]] != s[i])ans = false;
        mp1[s[i]] = t[i];
        mp2[t[i]] = s[i];
    }
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 776
#include <stdio.h>
#include <string.h>

int mf[16][16];

int bomb(int x, int y)
{
	int i;

	mf[y][x] = 0;
	for (i = -3; i <= 3; i++){
		if (mf[y][x + i]){
			mf[y][x + i] = 0;
			bomb(x + i, y);
		}
		if (mf[y + i][x]){
			mf[y + i][x] = 0;
			bomb(x, y + i);
		}
	}
	return (0);
}

int main(void)
{
	int n, i;
	int x, y;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		memset(mf, 0, sizeof(mf));
		for (y = 0; y < 8; y++){
			char s[16];
			scanf(" %s", s);
			for (x = 0; x < 8; x++){
				mf[y + 3][x + 3] = s[x] - '0';
			}
		}

		scanf("%d %d", &x, &y);
		bomb(x + 2, y + 2);
		
		printf("Data %d:\n", i + 1);
		for (y = 3; y < 11; y++){
			for (x = 3; x < 11; x++){
				printf("%d", mf[y][x]);
			}
			puts("");
		}
	}
	return (0);
}

Measured memory_bytes: 608
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp[55][55][2505];
int n,a,x[55];
int main(){
	cin >> n >> a;
	for(int i=1;i<=n;i++){
		cin >> x[i];
	}
	dp[0][0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int q=n;q>=0;q--){
			for(int r=2500;r>=0;r--){
				dp[i][q][r] = dp[i-1][q][r];
				if(q && r>=x[i]){
					dp[i][q][r] += dp[i-1][q-1][r-x[i]];
				}
			}
		}
	}
	ll ret = 0;
	for(int i=1;i<=n;i++) ret += dp[n][i][i*a];
	cout << ret << endl;
}

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

int main() {

  int N;
  cin >> N;

  string tmp;
  map<string, int> m;
  int max = 0;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    m[tmp]++;
    if(m[tmp] > max){
      max = m[tmp];
    }
  }

  for(auto iter = m.begin(); iter != m.end(); iter++){
    if(iter->second == max){
      cout << iter->first << endl;
    }
  }
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int (i)=(j); i<(k);++(i))

int main(){
    int N,M,in;
    cin>>N>>M;
    vector<vector<char>> A(N,vector<char>(N)),B(M,vector<char>(M));
    FOR(i,0,N){FOR(j,0,N){cin>>A[i][j];}}
    FOR(i,0,M){FOR(j,0,M){cin>>B[i][j];}}

    FOR(i,0,N-M+1){
        FOR(j,0,N-M+1){
            in=1;
            FOR(k,0,M){
                FOR(l,0,M){
                    if(A[k+i][l+j] != B[k][l]){in = 0;}
                }
            }
            if(in){cout<<"Yes\n";return 0;}
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 256
// AOJ 1172

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX (123456 * 2)

vector <int> prime;
bool p[MAX];

void make_prime(void)
{
	fill(p, p + MAX, true);
	p[0] = p[1] = false;
	for (int i = 4; i < MAX; i += 2){
		p[i] = false;
	}
	prime.push_back(2);
	for (int i = 3; i < MAX; i += 2){
		if (p[i]){
			prime.push_back(i);
			for (int j = i+i; j < MAX; j += i){
				p[j] = false;
			}
		}
	}
	
	return;
}

int main(void)
{
	make_prime();
	int n;
	while (cin >> n, n){
		int ret = 0;
		for (int i = 0; prime[i] <= (2 * n); i++){
			if (n < prime[i]){
				ret++;
			}
		}
		cout << ret << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1584
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using Point = pair<int, int>;
const int INF = (int)1e9;

int main(void){
    string S;
    cin >> S;

    for(int i = 0; i < (1<<3); i++){
        int sum = S[0] - '0';
        for(int j = 0; j < 3; j++){
            if(i & (1<<j)) sum += S[j + 1] - '0';
            else sum -= S[j + 1] - '0';
        }

        if(sum == 7){
            cout << S[0];
            for(int j = 0; j < 3; j++){
                if(i & (1<<j)) cout << '+';
                else cout << '-';

                cout << S[j + 1];
            }
            cout << "=7\n";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define FOR(i,n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

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

int main(){
	int n,x;
	cin >> n >> x;
	int arr[n];
	FOR(i,n) cin >> arr[i];
	int ans=0,temp=0;
	for(int i(0);i<n;++i){
		if(temp<=x){
			temp+=arr[i];
			ans++;
		}
		else break;
	}
	if(temp<=x){
		ans++;
	}	
	cout << ans;
}

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






int main(){
    ll q;
    cin>>q;
    while(q--){
        ll fd=E,mx=-1,mx2=-1;
        string s,t;
        cin>>s>>t;
        if(s==t){cout<<0<<endl; continue;}
        for(int i=0;i<s.size();i++){
            if(s[i]!=t[i]){fd=min(fd,(ll)i);}
            if(s[i]=='1'){mx=max(mx,(ll)i);}
            if(t[i]=='1'){mx2=max(mx2,(ll)i);}
        }
        cout<<abs(fd-mx)+abs(mx2-fd)<<endl;
    }
    
    
    
    return 0;
}



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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define fi first
#define se second



int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    
    ll a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a*b));
    
    return 0;
}


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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

int main() {
    lld K, A, B;
    cin >> K;
    cin >> A >> B;
    for(lld i = A; i <= B; i++) {
        if(i % K == 0) {
            cout << "OK" << endl;
            exit(0);
        }
    }
    cout << "NG" << endl;
    return 0;
}

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



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

    if( a >= 3200 ) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const unordered_map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
int main()
{
       speed;
       int a,b;
       cin>>a>>b;
       cout<<a*b;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
#define endl '\n'
const double PI = 3.141592653589793238460;
  void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
    #endif
}
int main()
{
   
  c_p_c();

  ll a;cin>>a;
  cout<<a+a*a+a*a*a;
 
 
 
 
 





  



  

  return 0;
}


Measured memory_bytes: 3628
let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let build_max_heap (t : int array) h =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= h && t.(l) > t.(i) then l else i in
    let m = if r <= h && t.(r) > t.(m) then r else m in
    if m <> i then begin
      let tmp = t.(i) in t.(i) <- t.(m); t.(m) <- tmp;
      max_heapify m
    end
  and doit i =
    if i > 0 then (max_heapify i; doit (i - 1))
  in doit (parent h)

let () =
  let h = read_int () in
  let t = Array.make (h + 1) 0 in
  let rec read i =
    if i <= h then (t.(i) <- Scanf.scanf "%d " (fun i -> i); read (i + 1))
  in read 1;
  build_max_heap t h;
  let rec doit i =
    if i <= h then (print_string " "; print_int t.(i); doit (i + 1))
  in doit 1;
  print_newline ()

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

using namespace std;

typedef long long ll;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  cin >> a;

  vector<vector<int>> dp(h, vector<int>(w));
  dp[0][0] = 1;
  // dp[i+1][j] += dp[i][j] if dp[i+1][j] == "."
  // dp[i][j+1] += dp[i][j] if dp[i][j+1] == "."
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (i+1<h && a[i+1][j] == '.') {
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] %= 1000000007;
      }
      if (j+1<w && a[i][j+1] == '.') {
        dp[i][j+1] += dp[i][j];
        dp[i][j+1] %= 1000000007;
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	cin>>n>>k;
	set<int>s[110];
	for(int i=1;i<=k;i++){
		int num;
		cin>>num;
		while(num--){
			int f;
			cin>>f;
			s[f].insert(i);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(s[i].size()==0) ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 4048
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Harshad Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int f = 0;
  for (int m = n; m; m /= 10) f += m % 10;

  if (n % f == 0) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define pf push_front
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int n,k;
  cin>>n>>k;
  vector<pair<int,int> > p(n);
 
  rep(i,n){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(a,b);
  }
  sort(p.begin(),p.end());
  int sum=0;
  rep(i,n){
    sum+=p[i].second;
    if(sum>=k){
      cout<<p[i].first<<endl;
      break;
    }
    
  }

  return 0;
}




Measured memory_bytes: 1792
#include<iostream>
#include <cstdio>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

////Nayeem Shahriar Joy,Applied Physics &Electronic Engineering,University of Rajshahi.

int main()

{
   for(int i=1;i<=9;i++)
   {
       for(int j=1;j<=9;j++)
       {
           cout<<i<<"x"<<j<<"="<<i*j<<endl;
       }
   }
   return 0;
}

Measured memory_bytes: 3092