akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#include<queue>
#define sqr(x) (x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
int n,m,i,j,x,y,z,ans;
map<int,vector<pair<pair<int,int>,int> > > bi[100005];
map<int,int> dis[100005];
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,m)
	{
		scanf("%d%d%d",&x,&y,&z);
		bi[x][z].push_back(make_pair(make_pair(y,z),0));
		bi[x][z].push_back(make_pair(make_pair(x,0),0));
		bi[x][0].push_back(make_pair(make_pair(x,z),1));
		bi[y][z].push_back(make_pair(make_pair(x,z),0));
		bi[y][z].push_back(make_pair(make_pair(y,0),0));
		bi[y][0].push_back(make_pair(make_pair(y,z),1));
		dis[x][z]=dis[y][z]=0x22222222;
	}
	fz1(i,n) dis[i][0]=0x22222222;
	dis[1][0]=0;
	priority_queue<pair<int,pair<int,int> > > pq;
	pq.push(make_pair(0,make_pair(1,0)));
	while (!pq.empty())
	{
		x=pq.top().second.first,y=pq.top().second.second;
		pq.pop();
		ff(bi[x][y],it)
		{
			int nx=it->first.first,ny=it->first.second,nz=dis[x][y]+it->second;
			if (dis[nx][ny]>nz)
			{
				dis[nx][ny]=nz;
				pq.push(make_pair(-nz,make_pair(nx,ny)));
			}
		}
	}
	if (dis[n][0]>=0x22222222) puts("-1"); else printf("%d\n",dis[n][0]);
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int H, W;
char S[2001][2001];
int dp1[2001][2001], dp2[2001][2001];
int main(void){
    cin >> H >> W;
    REP(i,H) scanf("%s", S[i+1]+1);

    for(int h=1;h<=H;h++) for(int w=1;w<=W;w++){
        if(S[h][w] == '.') dp1[h][w] = dp1[h][w-1] + 1;
        if(S[h][w] == '#'){
            for(int i=1;i<dp1[h][w-1];i++) dp1[h][w-1-i] = dp1[h][w-1];
        }else if(w == W){
            for(int i=1;i<dp1[h][w];i++) dp1[h][w-i] = dp1[h][w];
        }
    }

    for(int w=1;w<=W;w++) for(int h=1;h<=H;h++){
        if(S[h][w] == '.') dp2[h][w] = dp2[h-1][w] + 1;
        if(S[h][w] == '#'){
            for(int i=1;i<dp2[h-1][w];i++) dp2[h-1-i][w] = dp2[h-1][w];
        }else if(h == H){
            for(int i=1;i<dp2[h][w];i++) dp2[h-i][w] = dp2[h][w];
        }
    }

    int res = 0;
    for(int h=1;h<=H;h++) for(int w=1;w<=W;w++){
        res = max(res, dp1[h][w]+dp2[h][w]-1);    
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a; i<=b; i++){
    if(i%k == 0){
      cout<<"OK";
      return 0;
    }
    
  }
cout << "NG";
return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
奇閉路がないので二部グラフ
まずは最大の二部グラフを作る．
左右それぞれのグループ内の頂点同士を結ぶ辺がない．
この時点でスケールの小さい同問題に帰着，グループ内で二部グラフを作れば良い．
ただ，これを素直にやると構築が面倒そう．

レベルの最大値の最小値はN<=2^mなる最小のm
つまりNの二進数表記での桁数

レベル1 : 000..111...
レベル2 : 00..11..00..11..
みたいに分けるか．
これ，二進数で各bitが異なる頂点とつなげば良い．すでにあるならば無視
"""
def main():
    mod=10**9+7
    N=I()
    M=2**(N-1).bit_length()
    
    ans=[[-1]*N for _ in range(N)]
    
    for k in range(M):#二進数の桁数
        for i in range(N):
            for j in range(i+1,N):
                if (i>>k &1)^(j>>k &1):#iとjのkbit目が違うならば
                    if ans[i][j]==-1:
                        ans[i][j]=k+1
                        
    for i in range(N):
        print(' '.join(map(str, ans[i][i+1:])))
    
    

main()


Measured memory_bytes: 75916
package main

import (
	"fmt"
)

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	
	min := 1000000
	max := -1000000
	sum := 0
	for i := 0; i < n; i++ {
		var a int
		if _, err := fmt.Scan(&a); err != nil {
			panic(err)
		}

		if a < min {
			min = a
		}
		if a > max {
			max = a
		}
		sum += a
	}

	fmt.Printf("%d %d %d\n", min, max, sum)
}



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

using namespace std;

int main()
{
    int w,h,n;
    cin >> w >> h >> n;

    int p,q;
    p = q = 0;
    int x,y,a;

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

        if(a == 1 && p < x)
            p = x;
        else if(a == 2 && w > x)
            w = x;
        else if(a == 3 && q < y)
            q = y;
        else if(a == 4 && h > y)
            h = y;
    }

    if(p >= w || q >= h)
        cout << 0 << endl;
    else
        cout << (w-p)*(h-q) << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n, m; cin >> n >> m;
    int s[m], c[m];
    rep(i, m) cin >> s[i] >> c[i];

    int ans = -1;
    rep(i, 1000){
        // 文字列にした方がチェックしやすい
        string tmp = to_string(i);
        if(tmp.length() != n) continue;
        bool flag = true;
        // s[i]の桁がc[i]じゃなければあてはまらない
        rep(j, m){
            if(tmp[s[j] - 1] - '0' != c[j]) flag = false;
        }
        // 小さい値から判定しているのでminは不要
        if(flag){
            ans = i;
            break;
        }
    }
    OP(ans);
}



Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long int
ll num[500000],cnt[500000]= {0};
long long int bigmod(long long int a,long long int b,long long int p)
{
    long long int val,ret;
    //printf("b=%lld\n",b);


    if(b==0)
    {
        return 1;
    }
    if(b%2==1)
    {
        ret= ((a*bigmod(a,b-1,p))%p);
        //printf("ret1=%lld\n",ret);

    }
    else
    {
        val=bigmod(a,b/2,p);
        ret= ((val *val)%p);
        //printf("ret2=%lld\n",ret);


    }
    return ret;
}

int main()
{

    ll n,i,j,k,flag=1,cnt1=1,res,res1;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&num[i]);
    }
    if(n%2==0)
    {
        for(i=1; i<n; i+=2)
            cnt[i]=2;
    }
    else
    {
        cnt[0]=1;
        for(i=2; i<n; i+=2)
            cnt[i]=2;

    }
    sort(num,num+n);
    flag=1;

    if(n%2==0)
    {

        for(i=1; i<n; i++)
        {
            if(num[i]==num[i-1])
            {
                cnt1++;
                if(cnt[num[i]]!=cnt1)
                {
                    flag=0;
                    break;
                }

            }
            else(cnt1=1);

        }
    }
    else
    {


        for(i=1; i<n; i++)
        {
            if(num[0]!=0)
            {
                flag=0;
                //printf("f1 %lld\n",flag);
                break;

            }



            if(num[i]==0)
            {
                flag=0;
                //printf("f2 %lld\n",flag);
                break;
            }
            if(num[i]==num[i-1])
            {
                cnt1++;
                //printf("cnt %lld\n",cnt1);
                 //printf("num %lld\n",num[i]);

                //printf("arr %lld\n",cnt[num[i]]);
                if(cnt[num[i]]!=cnt1)
                {
                    flag=0;
                    //printf("f3 %lld\n",flag);
                    break;
                }

            }
            else{cnt1=1;}

        }


    }


    if(flag==1)
    {


        k=n/2;
        res=bigmod(2,k,1000000007);
        printf("%lld\n",res);

    }
    else
    {
        printf("0\n");
    }



    return 0;
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5+5, INF = 0x3f3f3f3f3f3f3f3f;

ll N, arr[MAXN], ps[MAXN];

ll sum(int a, int b) {
	return ps[b]-ps[a-1];
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> arr[i], ps[i] = ps[i-1]+arr[i];
	
	ll ans = INF;
	int l = 1, r = 3;
	for (int i = 2; i <= N-2; i++) {
		while (abs(sum(1, l)-sum(l+1, i)) > abs(sum(1, l+1)-sum(l+2, i))) l++;
		while (abs(sum(i+1, r)-sum(r+1, N)) > abs(sum(i+1, r+1)-sum(r+2, N))) r++;
		ll mnm = min(min(sum(1, l), sum(l+1, i)), min(sum(i+1, r), sum(r+1, N)));
		ll mks = max(max(sum(1, l), sum(l+1, i)), max(sum(i+1, r), sum(r+1, N)));
		ans = min(ans, mks-mnm);
	}
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    if(n>=30)cout<<"Yes\n";
    else cout<<"No\n";   
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3644
/*
RAone00
Rohit sharma
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef vector < vector < ll > > matrix;
typedef vector < ll > vll;

#define pb push_back
#define debug(x) cout << (#x) << " is " << (x) << endl
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int main() {
    fast_io();
    int a;
    cin >> a;
    string s;
    cin >> s;
    if (a >= 3200) {
      cout << s << "\n";
    } else {
      cout << "red\n";
    }
    return 0;
}


Measured memory_bytes: 256
x = int(input())
n_list = []
for i in range(1000):
    n_list.append(i**5)
for i in range(1000):
    for j in range(1000):
        if n_list[i] - n_list[j] == x:
            print(i, j)
            exit()
        if n_list[i] + n_list[j] == x:
            print(i, j*(-1))
            exit()

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

main() {
  string S,T;
  cin >> S >> T;
  for(int i=0; i<S.size(); i++){
    if(S == T){
      cout << "Yes";
      return 0;
    }
    S= S.back()+S.substr(0,S.size()-1);
  }
  cout << "No";
  return 0;
}  
    

Measured memory_bytes: 256
n,T=map(int,input().split())
t=list(map(int,input().split()))
ans=0
#合計時間
s=0
tmp=0
#お湯が出始める時間 
for i in range(1,n):
    if tmp+T > t[i]:
    #延長
        tmp=t[i]
    #延長された分のスタート時間
    else:
    #一旦切れる
        ans=ans+(tmp+T-s)
        tmp=t[i]
        s=tmp
        #スタート時間の更新
ans=ans+(tmp+T-s)
print(ans)

Measured memory_bytes: 26832
#include <iostream> 
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>

#define mp make_pair
#define s second
#define f first
#define ll long long
using namespace std;
const ll MAX = 100002;
ll dp[100003], ans;
bool b[100003];

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

	int n, m;
	cin >> n >> m;
	
	for (int i=1; i<MAX; i++)
		dp[i] = 10e12;
	
	b[0] = 1;
	for (int i=0; i<n; i++) {
		ll weight, value; 
		cin >> weight >> value;
		for (int j=MAX-1; j>=0; j--) {
			if (b[j-value] == 1 and dp[j-value] + weight <= m) {
				b[j] = 1;
				dp[j] = min(dp[j], dp[j-value] + weight);
				ans = max(int(ans), j);
			}
		}
	}
	
	cout << ans;
return 0;	
}




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

void solve() {
	// エラトステネスのふるい
	vector<int> is_prime(MAX, 1);
	is_prime[0] = 0; is_prime[1] = 0;
	for (int i = 2; i < MAX; i++) {
		if (!is_prime[i]) continue;
		for (int j = i * 2; j < MAX; j += i) is_prime[j] = 0;
	}

	// 2017-likeかどうか
	vector<int> a(MAX, 0);
	for (int i = 0; i < MAX; i++) {
		if (i % 2 == 0) continue;
		if (is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
	}

	// 累積和
	vector<int> s(MAX + 1, 0);
	for (int i = 0; i < MAX; i++) s[i + 1] = s[i] + a[i];

	int Q; cin >> Q;
	rep(q, Q) {
		int l, r;
		scanf("%d%d", &l, &r);
		r++;
		printf("%d\n", s[r] - s[l]);
	}
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];

//木の直径（未完成）
plglg visit(int p, int v) {
    plglg ans(0, v);
    int n = G[v].size();
    for(int i = 0; i < n; i++){
        edge e = G[v][i];
        if (e.to != p) {
            plglg a = visit(v, e.to);
            a.first += e.cost;
            if (ans.first < a.first) {
                ans = a;
            }
        }
    }
    return ans;
}

pii farthest;

ll diameter() {
    plglg r = visit(-1, 0);
    plglg t = visit(-1, r.second);
    farthest.first = r.second;
    farthest.second = t.second;
    return t.first;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        edge e1;
        e1.to = t;
        e1.cost = w;
        G[s].push_back(e1);
        edge e2;
        e2.to = s;
        e2.cost = w;
        G[t].push_back(e2);
    }
    ll ans = diameter();
    cout << ans << endl;
}



Measured memory_bytes: 37496
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).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 INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int N;
string S[305];
int main(){
	cin>>N;
	rep(i,N)cin>>S[i];
	int ans=0;
	for(int c=-(N-1);c<=N-1;c++){
		bool pos=true;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				int ni=(i+c+N)%N;
				int nj=(j-c+N)%N;
				if(S[i][j]!=S[nj][ni])pos=false;
			}
		}
		if(pos){
			//cout<<c<<endl;
			ans+=N-abs(c);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

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

    if(R < 1200) {
        cout << "ABC" << endl;
    } else if(R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, p[15], i, max = 1, ans = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		if (max < p[i])max = p[i];
	}

	for (i = 0; i < n; i++)ans += p[i];
	printf("%d", ans - max / 2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vector<vector<P>> G;
vl ans;

void dfs(ll v, ll p = -1, ll c = 0) {
    // 行きの処理はこのへんに書く
    ll num = 1;
    for(auto z : G[v]) {
        ll u = z.first;
        ll id = z.second;
        if(u == p) {
            continue;
        }
        if(num == c) {
            num++;
        }
        ans[id] = num;
        num++;
        dfs(u, v, ans[id]);
        // 帰りの処理はこのへんに書く
    }
}

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

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(make_pair(b, i));
        G[b].pb(make_pair(a, i));
    }

    ll K = 0;
    rep(v, n) {
        chmax(K, (ll)G[v].size());
    }
    out(K);

    const ll root = 0;
    ans.resize(n-1);
    dfs(root);

    rep(v, n-1) {
        out(ans[v]);
    }

    re0;
}

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

import java.util.*;
import java.io.*;

public class Main {
    private static boolean bsearch(int arr[], int l, int r, int k){
        if(l>r){
            return false;
        }
        int mid = (l+r)/2;
        if(arr[mid]<k){
            return bsearch(arr, mid+1, r, k);
        }
        if(arr[mid]==k){
            return true;
        }
        return bsearch(arr, l, mid-1, k);
    }
	public static void main (String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int i= 1;
	    int ans = Integer.MAX_VALUE;
	    while(true){
	        if(i>n/2){
	            break;
	        }
	        String o = i+"";
	        String o1 = (n-i)+"";
	        int a = 0;
	        for(int ii=0;ii<o.length();ii++){
	            a+=o.charAt(ii)-'0';
	        }
	        for(int ij=0;ij<o1.length();ij++){
	            a+=o1.charAt(ij)-'0';
	        }
	        ans= Math.min(ans,a);
	        i++;
	    }
	    System.out.println(ans);
	}
}

Measured memory_bytes: 26800
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	f = 0
	for i in 1:3500
		for j in 1:3500
			if 4*i*j-n*i-n*j>0
				if (n*i*j)%(4*i*j-n*i-n*j)==0
					println(i, " ", j, " ", div(n*i*j,4*i*j-n*i-n*j))
					f = 1
					break
				end
			end
		end
		if f == 1
			break
		end
	end
end

main()

Measured memory_bytes: 166008
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll k,ans=1;

    cin >> k;

    if(k%2==0){
        cout << -1 << endl;
        return 0;
    }

    map<ll,ll> mod_list;    //循環検知
    ll seven = 7;
    while(seven<k){
        seven = seven*10+7;
        ans++;
    }

    ll mod = seven%k;
    while(mod != 0){
        mod = seven%k;
        //print("*",mod,seven);
        if(mod_list.count(mod)>0){
            break;
        }
        mod_list[mod] = 1;
        seven = mod*10+7;
        
        //print("#",mod,seven);
        if(mod != 0)
            ans++;
    }
    if(mod != 0)
        ans = -1;
    
    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 66100
#!/usr/bin/env python3

def solve(s,t):

  s = (sorted(s))
  t = (sorted(t,reverse=True))

  return s < t



def main():
  S = input()
  T = input()
  print("Yes" if solve(S,T) else "No")
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9104
c11,c12,c13=map(int,input().split())
c21,c22,c23=map(int,input().split())
c31,c32,c33=map(int,input().split())
if (c11-c12==c21-c22==c31-c32 and c12-c13==c22-c23==c32-c33 \
and c13-c11==c23-c21==c33-c31 and c11-c21==c12-c22==c13-c23 \
and c21-c31==c22-c32==c23-c33 and c31-c11==c32-c12==c33-c13) :
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	min := sum(0, xs)
	for i := 1; i <= 100; i++ {
		tmp := sum(i, xs)
		if min > tmp {
			min = tmp
		}
	}

	fmt.Print(min)
}

func sum(p int, xs []int) int {
	var s int
	for _, x := range xs {
		tmp := x - p
		s += tmp * tmp
	}
	return s
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PII> v(N);
  rep(i,N) cin >> v[i].first;
  rep(i,N) cin >> v[i].second;

  vector<int> w(N);
  vector<int> z(N);
  vector<int> forward(N,0);

  int ans = MAX_I;
  rep(S,1<<N){
    int count = 0;
    rep(i,N){
      int x = v[i].first;
      forward[i] = 0;
      if(S>>i&1){
        ++forward[i];
        x = v[i].second;
        ++count;
      }
      w[i] = x;
      z[i] = x;
    }
    if(count%2)continue;

    sort(all(z));
    vector<int> y(N,-1);
    vector<bool> used(N,false);
    rep(i,N){
      rep(j,N){
        if(z[i] != w[j] || used[j] || (i+j+forward[j])%2 != 0)continue;
        y[i] = j;
        used[j] = true;
        break;
      }
    }

    bool sat = true;
    rep(i,N)if(!used[i]) sat = false;
    if(!sat)continue;

    count = 0;
    rep(i,N) repp(j,i+1,N) if(y[i] > y[j]) ++count;
    ans = min(ans,count);
  }

  if(ans == MAX_I)ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# coding:utf-8
a, b, c, k = map(int, input().split())
point = 0

if k <= a:
    point += k
elif k > a and (k - a) <= b:
    point += a
elif k > a and (k - a) > b:
    point = a + (-1) * (k - a - b)

print(point)


Measured memory_bytes: 9176
inp = input()
inp = input()
 
def mp(nums):
  if 0 in nums:
    print(0)
    return
  n = 1
  limit = 10**18
  for num in nums:
    n *=num
    if n > limit:
      print(-1)
      return
  print(n)
 
mp([int(x) for x in inp.split(" ")])

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

int main ()
{
    int N{};
    cin >> N;
    
    string Si[N];
    for (int i{}; i<N; i++) 
        {
            cin >> Si[i];
        }
    int C[4] {0,0,0,0};
    for (auto i : Si) 
        {
            if (i == "AC")
                C[0] += 1;
            if (i == "WA")
                C[1] += 1;
            if (i == "TLE")
                C[2] += 1;
            if (i == "RE")
                C[3] += 1;
        }
    cout << "AC x " << C[0] << endl;
    cout << "WA x " << C[1] << endl;
    cout << "TLE x " << C[2] << endl;
    cout << "RE x " << C[3] << endl;
        
	return 0;
}


Measured memory_bytes: 5480
N = int(input())
S = [input() for i in range(N)]
nameDict = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
List = []
result = 0

# 入力された文字に対する辞書の生成
for i in range(0, N):
    if S[i][0] in nameDict.keys():
        nameDict[S[i][0]] += 1

for i in nameDict.values():
    List.append(i)

for i in range(0, 3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            result += List[i]*List[j]*List[k]
print(result)

Measured memory_bytes: 9752
from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    global N
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0
distant = floyd_warshall(distant)
# warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(int(ans))


Measured memory_bytes: 16808
#include<iostream>

int main(void){
    std::string s;
    std::cin >> s;
    if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A'){
	std::cout << "No" << std::endl;
    }else if(s[0] == 'B' && s[1] == 'B' && s[2] == 'B'){
	std::cout << "No" << std::endl;
    }else{
	std::cout << "Yes" << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3584
implicit none
integer :: n
integer,allocatable :: a(:)
integer :: i,j,m,s
integer,allocatable :: ball(:)

read *,n
allocate(a(n))
read *,(a(i),i=1,n)

allocate(ball(n))
ball(:) = 0

do i = n, 1, -1
   s = 0
   do j = 2*i, n, i
      s = xor(s,ball(j))
   enddo
   ball(i) = xor(s,a(i))
enddo

m = sum(ball)

write(*,'(i0)') m
if (m > 0) then
   s = 0
   do i = 1, n
      if (ball(i) == 1) then
         if (s == 0) then
            s = 1
         else
            write(*,'(a)',advance='no') ' '
         endif
         write(*,'(i0)',advance='no') i
      endif
   enddo
   write(*,'(a)') ''
endif
end

Measured memory_bytes: 2816
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;

void solve(){

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

    ll x;
    cin >> x;
    for (int a=-118;a<120;a++){
        for (int b=-119;b<129;b++){
            if (pow(a,5)-pow(b,5)==x){
                cout << a << " " << b;
                return 0;
            }
        }

    }








    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
 
int main() {
	string s;
	cin >> s;
	int len = s.size();
	vector<int> v(len);
	for (int i = 0; i < len; ++i) {
		v[i] = (int)(s[i] -'0');
	}

	ll res = 0;
	for (int i = 0; i < (1<<(len - 1)); ++i) {
		ll tmp = 0;
		for (int j = len - 2; j >= 0; --j) {
			tmp += v[len - 2 - j];
			if ((i>>j) & 1) { 
				res += tmp;
				tmp = 0;
			} else { 
				tmp *= 10;
			}
		}
		tmp += v[len - 1];
		res += tmp;
	}

	cout << res << endl;


	return 0;
}


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

int main(){
  int e,ans;
  while(1){
    cin>>e;
    if(!e)break;
    ans=(1e9);
    for(int z=0;z*z*z<=e;z++){
      int Z=z*z*z;
      for(int y=0;y*y<=e-Z;y++){
	int Y=y*y;
	int X=e-Y-Z;
	if(X+Y+Z!=e)continue;
	ans=min(ans,X+y+z);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int N, a;
    vector<int> vs;
    vector<int> frq(200005);

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a);
        frq[a]++;
        vs.push_back(a);
    }

    long long ans = 0;
    for (int i = 1; i <= N; i++)
        ans += ((ll)frq[i] * (ll)(frq[i] - 1LL)) / 2LL;

    for (int i = 1; i <= N; i++) {
        int k = vs[i - 1];
        long long x = (frq[k] * (frq[k] - 1)) / 2;
        long long y = ((frq[k] - 2) * (frq[k] - 1)) / 2;
        printf("%lld\n", ans - x + y);
    }

    return 0;
}

Measured memory_bytes: 4212
#include <stdio.h>

int main(void)
{
	int S, h, m, s;

	scanf("%d", &S);

	h = S / 3600;

	m = (S % 3600) / 60;

	s = (S % 3600) % 60;

	printf("%d:%d:%d\n", h, m, s);
}


Measured memory_bytes: 2128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next()); 
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N-1];

    for (int i=0; i < N; i++) {
        A[i] = Integer.parseInt(sc.next()); 
    }
    for (int i=0; i < N; i++) {
        B[i] = Integer.parseInt(sc.next()); 
    }
    for (int i=0; i < N - 1; i++) {
        C[i] = Integer.parseInt(sc.next()); 
    }
    int sum = 0;
    for(int i=0; i < N; i++){
        sum += B[A[i]-1];
        if(i>=1&&i<N){
            if(A[i] - A[i-1] ==1){
                sum += C[A[i-1]-1];
            }
        }
    }

    System.out.println(sum);
}
  
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int zero=0,one=0;
    rep(i,s.length()){
        if(s[i]=='0'){
            zero++;
        }
        else{
            one++;
        }
    }
    int min1=min(zero,one);
    cout<<min1*2<<endl;
}

Measured memory_bytes: 512
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var diff,h,w,s;

console.log(main());
function main(){
  h = o.a(), w = o.a();
  s = o.r(h,1);
  var ans = 0;
  for(var y = 0; y < h; y++)for(var x = 0; x < w; x++){
    if(s[y][x] === "."){
      solve(y,x);
      for(var i = 0; i < h; i++)for(var j = 0; j < w; j++){
        if(ans < diff[i][j])ans = diff[i][j];
      }
    }
  }
  return ans;
}

function solve(y,x){
  diff = xArray(-1,h,w);
  diff[y][x] = 0;
  var q = [y,x];
  var d = 1;
  while(q.length){
    var qq = [];
    while(q.length){
      x = q.pop(), y = q.pop();
      if(x && diff[y][x-1] === -1 && s[y][x-1] === "."){
        diff[y][x-1] = d;
        qq.push(y,x-1);
      }
      if(x < w-1 && diff[y][x+1] === -1 && s[y][x+1] === "."){
        diff[y][x+1] = d;
        qq.push(y,x+1);
      }
      if(y && diff[y-1][x] === -1 && s[y-1][x] === "."){
        diff[y-1][x] = d;
        qq.push(y-1,x);
      }
      if(y < h-1&& diff[y+1][x] === -1 && s[y+1][x] === "."){
        diff[y+1][x] = d;
        qq.push(y+1,x);
      }
    }
    d++;
    q = qq;
  }
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n; cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) ans += i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
N, X = map(int, input().split())
burger  = [1] * N
patty = [1] * N
for i in range(1, N):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level-1] + 1 < x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int h,w;
int a[500][500],b[500][500],c[500][500];
int main(){
	cin>>h>>w;
	FOR(i,0,h) FOR(j,0,w){
		char c; cin>>c;
		a[i][j]=(c=='#');
	}
	FOR(i,0,h){
		FOR(j,0,w){
			if(i%2) b[i][j]=1;
			else c[i][j]=1;
		}
	}
	FOR(i,0,h){
		b[i][0]=1;
		b[i][w-1]=0;
		c[i][0]=0;
		c[i][w-1]=1;
	}
	FOR(i,0,h){
		FOR(j,0,w){
			b[i][j]|=a[i][j];
			c[i][j]|=a[i][j];
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			cout<<(b[i][j]?"#":".");
		}
		cout<<endl;
	}
	cout<<endl;
	FOR(i,0,h){
		FOR(j,0,w){
			cout<<(c[i][j]?"#":".");
		}
		cout<<endl;
	}
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    IO
    ll N,M;
    cin>>N>>M;
    ll H[N+5];
    for(ll i=1;i<=N;i++)
    cin>>H[i];
    vector <ll> G[N+5];
    ll p,q;
    for(ll i=1;i<=M;i++)
    {
        cin>>p>>q;
        G[p].push_back(q);
        G[q].push_back(p);
    }
    ll ans=0;
    for(ll i=1;i<=N;i++)
    {
        ll aa=0;
        for(ll j=0;j<G[i].size();j++)
        {
            if(H[G[i][j]]>=H[i])
            aa=1;
        }
        if(aa==0){
        ans++;
        // cout<<i<<' ';
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10212
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	string s;
	cin >> s;

	int n = s.length(), i, j, k;
	bool ans = true;

	if (n % 2 == 1) ans = false;
	else for (i = 0; i < n; i++) {
		if ((i % 2 == 0) && (s[i] != 'h')) ans = false;
		if ((i % 2 == 1) && (s[i] != 'i')) ans = false;
	}

	if (ans) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include <algorithm>
#include <functional>

using namespace std;

int main (void){
    int N,A,B;
    cin >> N >> A >> B;
    if(N*A > B) cout << B << endl;
    else cout << N*A << endl;

    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    //  b\a  0  1  2
    //   0   0  1  2
    //   1   1  2  0
    //   2   2  0  1
    return (a+b)%3;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
int Seg_query(int a,int b,int k,int l,int r){
    //外からはSeg_query(a,b,0,0,n)で呼ぶ
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}


signed main(void){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  
    string S,T;
    int Q;
    int A[114514],B[114514],C[114514],D[114514];
    int G[114514],H[114514];
    
    cin >> S >> T;
    cin >> Q;
    REP(i,Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;C[i]--;D[i]--;
    }
    
    //Aを1、Bを2、O(=AB)を0と扱う
    
    //Sをセグる
    Seg_init(S.size());
    REP(i,S.size()){
        Seg_update(i,(S[i]=='A'?1:2));
    }
    REP(i,Q){
        G[i]=Seg_query(A[i],B[i]+1,0,0,n);
    }
    
    //Tをセグる
    Seg_init(T.size());
    REP(i,T.size()){
        Seg_update(i,(T[i]=='A'?1:2));
    }
    REP(i,Q){
        H[i]=Seg_query(C[i],D[i]+1,0,0,n);
    }
    
    //REP(i,Q){cout << G[i] MM H[i] << endl;}
    
    REP(i,Q){
        if(G[i]==H[i]){
            cout << "YES" << '\n';
        }else{
            cout << "NO" << '\n';
        }
    }
    
    return 0;
}



Measured memory_bytes: 10320
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

char s[200005];

int cnt[256];

ll ans;

int n;

void solve() {                   
	scanf("%s", s);

	for (n = 0; s[n]; ++n);

	for (int i = 0; i < n; ++i) {
		++cnt[s[i]];
	}

	ans = n * (n - 1ll) / 2 + 1;

	for (int i = 0; i < n; ++i) {
		ans -= --cnt[s[i]];                
	}	
    
    printf("%lld\n", ans);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main(void){
    int N,M,K,a;
    cin>>N>>M;
    VI A(N),ans(M);
    rep(i,N){
        cin>>K;
        rep(j,K){
            cin>>a;
            ans[a-1]++;
        }
    }
    int cnt=0;
    rep(i,M){
        if(ans[i]==N){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
	public static void main(String[] args)throws Exception
	{
		Scanner scan=new Scanner(System.in);
		
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		
		if(a>b&&a>c)
		{
			if(b>c)
			{
				System.out.println(c+" "+b+" "+a);
			}
			else if(b<c)
			{
				System.out.println(b+" "+c+" "+a);
			}
			else if(b==c)
			{
				System.out.println(b+" "+c+" "+a);
			}
		}
		else if(b>a&&b>c)
		{
			if(a>c)
			{
				System.out.println(c+" "+a+" "+b);
			}
			else if(a<c)
			{
				System.out.println(a+" "+c+" "+b);
			}
			else if(a==c)
			{
				System.out.println(a+" "+c+" "+b);
			}
			
		}
		else if(c>a&&c>b)
		{	
			if(a>b)
			{
				System.out.println(b+" "+a+" "+c);
			}
			else if(a<b)
			{
				System.out.println(a+" "+b+" "+c);
			}
			else if(a==b)
			{
				System.out.println(a+" "+b+" "+c);
			}

		}
	}
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{   
    gearup;
    int n,m,r; cin >> n >> m >> r;
    vl R(r);
    rep(i,r)cin >> R[i],R[i]--;
    sort(all(R));

    vector<vector<ll> > dp(n+1,vector<ll>(n+1,INF));
    for(int i=0;i<n;i++){
        dp[i][i] = 0;
    }
    for(int i=0;i<m;i++){
        ll a,b,t; cin >> a >> b >> t;
        a--;b--;
        dp[a][b] = t;
        dp[b][a] = t;
    }

    //ワーシャルフロイド法
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                chmin(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }

    ll res = L_INF;
    do{
        ll now = 0;
        rep(i,r-1){
            now += dp[R[i]][R[i+1]];
        }
        res = min(res,now);
    }while(next_permutation(all(R)));
    out(res);
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	long x[n],ans;
	int i,j;
	for(i=0;i<n;i++)scanf("%ld",&x[i]);
	for(i=0;i<=n-k;i++){
		if(i==0)ans=abs(x[i])+abs(x[i+k-1]-x[i]);
		if(ans>abs(x[i])+abs(x[i+k-1]-x[i]))ans=abs(x[i])+abs(x[i+k-1]-x[i]);
		if(ans>abs(x[i+k-1])+abs(x[i+k-1]-x[i]))ans=abs(x[i+k-1])+abs(x[i+k-1]-x[i]);
	}
	printf("%ld\n",ans);
	//for(i=0;i<n;i++)printf("%ld,",x[i]);
	return 0;
}

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

int main() {
	int N, A, B, P;
	cin >> N >> A >> B;
	vector<int> vec(3);
	for (int i = 0; i < N; i++) {
		cin >> P;
		if (P <= A) {
			vec.at(0)++;
		}
		else if (A + 1 <= P && P <= B) {
			vec.at(1)++;
		}
		else {
			vec.at(2)++;
		}
	}
		sort(vec.begin(), vec.end());
		cout << vec.at(0) << endl;
}


Measured memory_bytes: 3532
def main():
    from functools import lru_cache
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(100000000)

    n,u,v=map(int,input().split())
    u-=1
    v-=1
    tree=[[] for i in range(n)]
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1
        b-=1
        tree[a].append(b)
        tree[b].append(a)
    
    depth=[0]*n
    depth[v]=0
    def dfs(i,before=-1):
        for e in tree[i]:
            if e!=before:
                depth[e]=depth[i]+1
                dfs(e,i)
    dfs(v)
    #print(depth)
    
    max_depth=[-1]*n
    max_depth[v]=0   
    @lru_cache(maxsize=None)
    def dfs2(i,before=-1):
        t=-1
        for e in tree[i]:
            if e!=before:
                t=max(t,dfs2(e,i))
        if t!=-1:
            max_depth[i]=t
            return max_depth[i]
        else:
            max_depth[i]=depth[i]
            return max_depth[i]
            
    dfs2(v)   
    #print(max_depth)
    
    lim=depth[u]
    i,key=u,u
    while i!=v:
        if 2*depth[i]>lim and max_depth[key] < max_depth[i]:
            key=i
            
        for e in tree[i]:
            if depth[e]<depth[i]:
                i=e
                break
                
    print(max_depth[key]-1) 
if __name__=='__main__':
    main()



Measured memory_bytes: 282428
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    s = abs(first) // abs(last)
    t = abs(first) % abs(last)
    ans = 2 * s
    if t != 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import sys

N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

t_max = [0] * N
t_min = [1] * N
tmp = -1
for i in range(N):
    t = T[i]
    if t > tmp:
        t_max[i] = t
        t_min[i] = t
    elif t == tmp:
        t_max[i] = t
    else:
        print(0)
        sys.exit(0)
    tmp = t

a_max = [0] * N
a_min = [1] * N
tmp = -1
for i in range(N-1, -1, -1):
    a = A[i]
    if a > tmp:
        a_max[i] = a
        a_min[i] = a
    elif a == tmp:
        a_max[i] = a
    else:
        print(0)
        sys.exit(0)
    tmp = a

answer = 1
for i in range(N):
    tmp = min(t_max[i], a_max[i]) - max(t_min[i], a_min[i])
    if tmp < 0:
        print(0)
        sys.exit(0)
    answer *= tmp + 1
    answer %= MOD

print(answer)


Measured memory_bytes: 83940