akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int gcd(int a,int b)
{
  if(b>a) 
    {
      swap(a,b);
      gcd(a,b);
    }
  if(b==0) return a;
  else if(b==1) return b;
  int p=a/b;
  a-=p*b;
  return gcd(b,a);
}

int main(int argc,char const* argv[])
{
  int p,q,k;
  cin >>p >> q;
  k=gcd(p,q);
  p/=k;
  q/=k;
  int q_=q;
  vector<P> ans;
  for(int i=2;i<=sqrt(q);i++)
    {
      if(q_%i==0)
	{
	  P pa=make_pair(i,1);
	  q_ /=i;
	  while(q_%i ==0)
	    {
	      pa.second++;
	      q_ /=i;
	    }
	  ans.push_back(pa);
	}
    }
  if(q_ > 1) ans.push_back(P(q_,1));

  int a=1;
  for(int i=0;i<(int) ans.size();i++)
    {
      a*=ans[i].first;
    }
	  
    cout << a << endl;
  return 0;
}



Measured memory_bytes: 3120
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q, ans2;
P p[ohara];
ll fuku[ohara];

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

  cin >> n;
  rep(i, n) {
    cin >> a[i];
    p[i] = m_p(a[i], i);
  }
  sort(p, p + n);
  ans = p[n / 2 - 1].fi;
  ans2 = p[n / 2].fi;

  rep(i, n) {
    if (p[i].fi < ans) {
      fuku[p[i].se] = ans2;
    } else if (p[i].fi == ans) {
      fuku[p[i].se] = ans2;
    } else if (p[i].fi == ans2) {
      fuku[p[i].se] = ans;
    } else {
      fuku[p[i].se] = ans;
    }
  }
  rep(i, n) Cout(fuku[i]);
  return 0;
}

Measured memory_bytes: 13952
n,k,q = map(int,input().split())
li = [k-q for i in range(n)]
for i in range(q):
  a = int(input())
  li[a-1] += 1
for i in range(n):
  if li[i] > 0:
    print("Yes")
  else:
    print("No")
    

Measured memory_bytes: 7848
import heapq
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
hq=[]
tmp=0
ans=0
for i in range(1,m+1):
  while tmp<n and AB[tmp][0]<=i:
      heapq.heappush(hq,-AB[tmp][1])
      tmp+=1
  if hq:
      ans-=heapq.heappop(hq)
print(ans)


Measured memory_bytes: 72664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int men, point, solve;
	cin >> men >> point >> solve;
	VE ansr(solve);
	REP(i, solve) {
		cin >> ansr[i];
	}
	VE get_point(men,0);
	REP(i, solve) {
		get_point[ansr[i] - 1]++;
	}
	REP(i, men) {
		if (point - solve + get_point[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=LINF*5,a,b,c,d,cmp,cmpp,m,h,w,x[51],y[51],sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll xmi,xma,ymi,yma;

//-------------------------↓↓↓↓↓↓------------------------

bool judge(ll i){
    if(xmi<=x[i]&&xma>=x[i]&&ymi<=y[i]&&yma>=y[i])return true;
    else return false;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>k;
    rep(i,n)cin>>x[i]>>y[i];
    rep(i,n){
        rep(j,n){
            rep(kk,n){
                rep(l,n){
                    xmi=min(x[i],x[j]);
                    xma=max(x[i],x[j]);
                    ymi=min(y[kk],y[l]);
                    yma=max(y[kk],y[l]);
                    cnt=0;
                    rep(ser,n){
                        if(judge(ser))cnt++;
                    }
                    if(cnt>=k){
                        if(ans==114154)ans=(xma-xmi)*(yma-ymi);
                        else ans=min(ans,(xma-xmi)*(yma-ymi));
                    }
                }
            }
        }
    }
    Cout(ans);
    return 0;
}


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

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

    int d1[n];
    int d2[n];

    for(int i=0; i<n; i++){
        cin >> d1[i] >> d2[i]; 
    }

    int count = 0;

    for(int i=0; i<n; i++){
        if(d1[i] == d2[i]){
            count++;
            if(count == 3){
                break;
            } 
        }
        else{
            count = 0;
        }
    }

    if(count < 3){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 200000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int n;
long long merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int i,j,k;
    long long cnt=0;

    for(i=0;i<n1;i++)L[i]=A[left+i];
    for(i=0;i<n2;i++)R[i]=A[mid+i];
    L[n1]=SENTINEL;
    R[n2]=SENTINEL;
    i=0;
    j=0;
    for(k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
        }
        else{
            A[k]=R[j];
            j++;
            cnt+=n1-i;
        }
    }
    return cnt;
}

long long mergesort(int A[],int n,int left,int right){
    long long v1,v2,v3;
    if(left+1<right){
        int mid=(left+right)/2;
        v1=mergesort(A,n,left,mid);
        v2=mergesort(A,n,mid,right);
        v3=merge(A,n,left,mid,right);
        return v1+v2+v3;
    }
    else return 0;
}


int main(void){
    scanf("%d",&n);
    int a[MAX];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    long long ans=mergesort(a,n,0,n);
    printf("%lld\n",ans);
    

    return 0;
}


Measured memory_bytes: 3304
n = int(input())
h = [int(x) for x in input().split()]
inf = 10**9+7

dp_list = [inf]*(n)

for i in range(n):
  if i == 0:
    dp_list[i] = 0
  elif i == 1:
    dp_list[i] = abs(h[1]-h[0])
  else:
    dp_list[i] = min([dp_list[i-1]+abs(h[i]-h[i-1]), dp_list[i-2]+abs(h[i]-h[i-2])])


print(dp_list[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
string str;
void solve()
{
    int i,len=str.length(),xtag=0;
    vector < int > tag(26,0);
    for (i=0;i<len;i++)
        tag[str[i]-'a']++;
    for (i=0;i<26;i++)
        if (tag[i]>1) {xtag=1;break;}
    if (xtag) cout<<"no";
    else cout<<"yes";
    cout<<endl;
}
int main()
{
    while(cin>>str)
        solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    sort(all(a));
    reverse(all(a));
    ll ans=a[0];
    
    int cnt=1;
    int id=1;
    rep(i,n-2){
        if(cnt==1){
            ans+=a[id];
            cnt++;
        }
        else{
            ans+=a[id];
            cnt=1;
            id++;
        }
    }

    cout<<ans<<endl;
}



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

#define STRING(str) #str

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	scc_graph scc = scc_graph(N);
	for (int i=0;i<M;i++) {
		int a, b;
		cin >> a >> b;
		scc.add_edge(a, b);
	}
	vector<vector<int>> vec = scc.scc();
	cout << vec.size() << endl;
	for (int i=0;i<vec.size();i++) {
		cout << vec[i].size() << " ";
		for (int j=0;j<vec[i].size();j++) {
			cout << vec[i][j];
			if (j != vec[i].size()-1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 40080
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int n; cin >> n;
  if(n == 1){
    cout << "Hello World\n";
  }
  else{
    int a, b; cin >> a >> b;
    cout << a + b << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
S = input()
op = len(S) - 1
res = 0
for i in range(2 ** op):
    string = ""
    bag = []
    for j in range(op):
        if (i >> j) & 1 == 1:
            bag.append("+")
        else:
            bag.append("")
    for s, b in zip(S, bag + [""]):
        string = string + s + b
    res += eval(string)
print(res)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
  int i,j,n,m,sum;
  
  int a[100][100],b[100],c[100];
  scanf("%d %d",&n,&m);
 
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);
 
  for(i=0;i<m;i++)
    scanf("%d",&c[i]);

  for(i=0;i<n;i++){
     for(j=0;j<m;j++)
      sum+=a[i][j]*c[j];
       printf("%d\n",sum);
       sum=0;
  }
  return 0;
}




Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <set>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    string ans = "";
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (ans.size() != 0 && s.at(i) == 'B'){
                ans.pop_back();
        }
        else if (s.at(i) != 'B') {
                ans += s.at(i);
            }
        }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    map<int,int> m;
    int n,x;
    cin>>n;
    for (int i=1;i<n;++i)
    {
        cin>>x;
        ++m[x];
    }
    for (int i=1;i<=n;++i)
    {
        cout<<m[i]<<"\n";
    }
    return 0;
}

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

int dp[502][2][10][500][3], m;
char S[2][550];
inline int solve(int o) {
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	int i;
	for (i = 0; S[o][i]; i++)rep(j, 2)rep(k, 10)rep(l, m)rep(d, 3) {
		if (dp[i][j][k][l][d] == 0)continue;
		int s, g, p = S[o][i] - '0';
		if (d == 1)s = k + 1, g = (j ? 9 : p);
		else if (d == 2)s = 0, g = (j ? k - 1 : min(k - 1, p));
		else s = 0, g = (j ? 9 : p);
		for (int x = s; x <= g; x++) {
			if (x&&k == x)continue;
			int y;
			if (d == 1)y = 2;
			else if (d == 2)y = 1;
			else {
				if (k == 0)y = 0;
				else if (x < k)y = 1;
				else y = 2;
			}
			(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %= MOD;
		}
	}
	int sum = 0;
	rep(k, 2)rep(j, 10)rep(t, 3) {
		if (!k && !o)continue;
		(sum += dp[i][k][j][0][t]) %= MOD;
	}
	return sum;
}
int main() {
	scanf("%s%s%d", S[0], S[1], &m);
	printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}

Measured memory_bytes: 62012
#include <bits/stdc++.h>
using namespace std;
typedef long double LD; 
typedef long long ll; 
#define int ll 
#define ff(i,a,b) for (int i = a; i < b; i++) 
#define bf(i,a,b) for (int i = a; i >= b; i--) 
#define all(v) v.begin(),v.end() 
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first 
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound   
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define intmx INT_MAX 
#define intmi INT_MIN
const int MOD=1e9+7;
int mod(int x){
    return ((x%MOD + MOD)%MOD);
}
int add(int a,int b){
    return mod(mod(a)+mod(b));
}
int mul(int a,int b){
    return mod(mod(a)*mod(b));
}
void solve(){
   int n;
   cin>>n;
   int a[n];
   
   ff(i,0,n){
       cin>>a[i];
   }
   int maxh=a[0];
   int sum=0;
   ff(i,1,n){
       if(a[i]<maxh){
           sum+=maxh-a[i];
       }
       else{
           maxh=a[i];
       }
   }
   cout<<sum<<endl;
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5084
from itertools import combinations_with_replacement as cwr

n, m = map(int, input().split())
c_lst = list(map(int, input().split()))
for t in cwr((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), n):
    out = ""
    cost = 0
    for n in t:
        cost += c_lst[n]
        out += str(n)
    if cost <= m:
        print(out)
        break
else:
    print("NA")


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

const int MOD = 1000000007;
const ll INF = 1LL<<60;

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

    vector<int> a(N, 0);

    rep(i,K){
        int d;
        cin >> d;
        rep(j,d){
            int A;
            cin >> A;
            a[--A]++;
        }
    }

    ll ans = 0;
    for(auto ai:a){
        if (ai == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
def dfs(i,total,s=""):
    if i == 3:
        if total == 7:
            return s
        else:
            return False

    s += "+"
    ans = dfs(i+1, total+l[i+1], s)
    if ans:
        return ans

    s = s[:-1]
    s += "-"
    ans = dfs(i+1, total-l[i+1], s)
    if ans:
        return ans


l = list(map(int,input()))
operation = dfs(0,l[0])
result = ""

for i in range(3):
    result += str(l[i]) + operation[i]
print(result + str(l[3]) + "=7")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	string s1 = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[300005] = {};
	ll y[300005] = {};
	ll y2[302][302] = {};
	cin >> a;
	cin >> b;
	if (b <= a)
	{

		for (int i = 0; i < a; i++)
		{
			s += '0' + b;
		}
		cout << s << endl;
	}
	else
	{

		for (int i = 0; i < b; i++)
		{
			s1 += '0' + a;
		}
		cout << s1 << endl;

	}

	//cout << ans << endl;



	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n,m,l;
  ll dp[309][309];

  cin>>n>>m>>l;
  rep(i,n){
    rep(j,n){
      if(i==j)dp[i][j]=0;
      else dp[i][j]=lINF;
    }
  }
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    dp[a][b]=dp[b][a]=c;
  }

  rep(k,n){
    rep(i,n){
      rep(j,n){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
      }
    }
  }

  ll dp2[309][309];
  rep(i,n){
    rep(j,n){
      if(dp[i][j]<=l)dp2[i][j]=1;
      else dp2[i][j]=lINF;
    }
  }

  rep(k,n){
    rep(i,n){
      rep(j,n){
        dp2[i][j]=min(dp2[i][j],dp2[i][k]+dp2[k][j]);
      }
    }
  }

  int q;
  cin>>q;
  rep(i,q){
    ll s,t,ans;
    cin>>s>>t;
    s--;t--;
    if(dp2[s][t]==lINF){
      ans=-1;
    }
    else{
      ans=dp2[s][t]-1;
    }
    cout<<ans<<endl;
  }

  return(0);

}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    int d,t,s;
    cin>>d>>t>>s;
    if(d>t*s)cout<<"No";
    else cout<<"Yes";
    return 0;
}



Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string s;
int n,bit[26][543210];

void update(int k, int p, int v){
	while(p<=n){
		bit[k][p] += v;
		p += (p&(-p));
	}
}

int query(int k, int p){
	int v = 0;
	while(p){
		v += bit[k][p];
		p -= (p&(-p));
	}
	return v;
}

int main(void){
	int q,t,i,j,l,r,ans;
	char c;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		s[i] -= 'a';
		update(s[i],i+1,1);
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> t;
		if(t>1){
			cin >> l >> r; --l;
			ans = 0;
			for(j=0; j<26; ++j){
				if(query(j,r)-query(j,l)){
					++ans;
				}
			}
			cout << ans << endl;
		}else{
			cin >> j >> c;
			c -= 'a';
			update(s[j-1],j,-1);
			update(c,j,1);
			s[j-1] = c;
		}
	}
	return 0;
}


Measured memory_bytes: 55812
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, m, xc, yc, x[100], y[100], maxx=-1000, miny=1000;

	cin >> n >> m >> xc >> yc;

	for (int i = 0; i < n; i++) {
		cin >> x[i];
		maxx = max(maxx, x[i]);

	}

	for (int i = 0; i < m; i++) {
		cin >> y[i];
		miny = min(miny, y[i]);
	}

	maxx = max(maxx, xc); 
	miny = min(miny, yc);

	if (miny > maxx)cout << "No War\n";
	else cout << "War\n";

	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

// ab[i + 10000] : aの始点を0としたときのbの始点がiである場合
bool ab[20000], bc[20000], ac[20000];

bool check(char c, char d){
    return (c == '?' || d == '?' || c == d);
}

signed main(){
    string a, b, c;
    cin >> a >> b >> c;
    int A = a.length(), B = b.length(), C = c.length();
    REP(i, A) REP(j, B) if(!check(a[i], b[j])) ab[i - j + 10000] = true;
    REP(i, A) REP(j, C) if(!check(a[i], c[j])) ac[i - j + 10000] = true;
    REP(i, B) REP(j, C) if(!check(b[i], c[j])) bc[i - j + 10000] = true;

    const int M = 2000;
    int ans = 3 * M;
    // 始点 a : 0, b : i, c : j
    for(int i = -2 * M; i <= 2 * M; i++){
        for(int j = -2 * M; j <= 2 * M; j++){
            if(!ab[i + 10000] && !ac[j + 10000] && !bc[j - i + 10000]){
                int L = min(0, min(i, j));
                int R = max(A, max(B + i, C + j));
                ans = min(ans, R - L);
            }
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A,B,C = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)

dpA,dpB,dpC = [0]*n,[0]*n,[0]*n
dpA[0],dpB[0],dpC[0] = A[0],B[0],C[0]

for i in range(1,n):
    dpA[i] = max(dpB[i-1],dpC[i-1])+A[i]
    dpB[i] = max(dpA[i-1],dpC[i-1])+B[i]
    dpC[i] = max(dpB[i-1],dpA[i-1])+C[i]

print(max(dpA[-1],dpB[-1],dpC[-1]))

Measured memory_bytes: 32620
#include <iostream>
#include <string.h>
using  std::endl;
using  std::cin;
using  std::cout;

#define MAX_PAT_NUM 1000000007

uint64_t getBridgePatternNum(int32_t colNum)
{
    if (colNum <= 0) {
        return 0;
    } else if (colNum == 1) {
        return 1;
    } else if (colNum == 2) {
        return 2;
    } else {
        return getBridgePatternNum(colNum-1) + getBridgePatternNum(colNum-2);
    }
}

int main(void)
{
    uint32_t h,w,k;
    cin >> h >> w >> k;

    uint64_t patternVec[w] = {};
    patternVec[0] = 1;
    
    for (uint32_t i = 0; i < h; ++i) {
        uint64_t prePatternVec[w] = {};
        memcpy(prePatternVec, patternVec, sizeof(prePatternVec));
        memset(patternVec, 0, sizeof(patternVec));
        for (int32_t j = 0; j < w; ++j) {
            int32_t preCol[3] = {j, j+1, j-1};
            for (uint32_t n = 0; n < 3; ++n) {
                if (0 <= preCol[n] && preCol[n] < w) {
                    int32_t leftColNum = ((j < preCol[n]) ? j : preCol[n]);
                    int32_t rightColNum = w - ((j > preCol[n]) ? j : preCol[n]) - 1;
                    uint64_t leftBridgePatNum = getBridgePatternNum(leftColNum);
                    uint64_t rightBridgePatNum = getBridgePatternNum(rightColNum);
                    patternVec[j] += (prePatternVec[preCol[n]] 
                                        * (leftBridgePatNum != 0 ? leftBridgePatNum : 1)
                                        * (rightBridgePatNum != 0 ? rightBridgePatNum : 1)
                                        );
                    patternVec[j] = patternVec[j] % MAX_PAT_NUM;
                }
            }
        }
    }
    
    cout << patternVec[k-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[200100];

ll solve() {
    ll x = 0, y = 0;
    for (int i = 0; i < n; i++) y += a[i];
    ll res = 1e16;
    for (int i = 0; i < n-1; i++) {
        x += a[i];
        y -= a[i];
        res = min(res, abs(x - y));
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

Int n;
vector<Int> G[200001];
Int a[200001];
Int d[200001];
Int dp[200001];
bool visited[200001];

void dfs(Int x) {
    visited[x] = true;
    Int index = lower_bound(dp, dp + n, a[x]) - dp;
    Int pre = dp[index];
    dp[index] = a[x];
    d[x] = lower_bound(dp, dp + n, INF) - dp;
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (not visited[to]) {
            dfs(to);
        }
    }
    dp[index] = pre;
}

int main() {
    cin >> n;
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    for (Int i = 0; i < (Int)n - 1; i++) {
        Int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    fill(dp, dp + n, INF);
    dfs(0);
    for (Int i = 0; i < (Int)n; i++) {
        print(d[i]);
    }
    return 0;
}

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

int main(){
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    ll A = min(min(Q*4, H*2), S);
    cout << min(A*N, N/2*D+(N%2)*A) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define L 5005

using namespace std;

int N, M;
int m1[L*(L+1)/2] = {0}, m2[L*(L+1)/2] = {0};
int P(int y, int x) {
	++y;
	return y*(y+1)/2 + x;
}
void Print() {
	for (int y = 0; y < N+1; ++y) {
		for (int x = 0; x <= y+1; ++x) {
			cout << m1[P(y, x)] << " ";
		}
		cout << endl;
	}
}
int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int y, x, l; cin >> y >> x >> l; --x, --y, ++l;
		++m1[P(y, x)], --m1[P(y+l, x)], --m1[P(y+1, x+1)], ++m1[P(y+l+1, x+1)];
		--m1[P(y, x+1)], ++m1[P(y+l, x+l+1)], ++m1[P(y+1, x+1)], --m1[P(y+l+1, x+l+1)];
	}
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x <= y+1; ++x) {
			m1[P(y+1, x+1)] += m1[P(y, x)];
		}
	}
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x <= y+1; ++x) {
			m1[P(y+1, x)] += m1[P(y, x)];
		}
	}
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x <= y+1; ++x) {
			m1[P(y, x+1)] += m1[P(y, x)];
		}
	}
	int ans = 0;
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x <= y; ++x) {
			if (m1[P(y, x)] > 0) ++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 51900
// https://atcoder.jp/contests/aising2019/tasks/aising2019_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

struct UnionFind {
  struct Node {
    ll parent;
    ll size;
  };
  vector<Node> tree;

  UnionFind(ll size) : tree(size) {
    for (ll i = 0; i < size; i++) {
      tree[i].parent = i;
      tree[i].size = 1;
    }
  }

  ll find(ll x) {
    while (tree[x].parent != x) {
      ll p = tree[x].parent;
      tree[x].parent = tree[p].parent;
      x = p;
    }
    return x;
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree[x].size < tree[y].size) swap(x, y);
    tree[y].parent = x;
    tree[x].size += tree[y].size;
  }

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

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vi dx = {0, 0, 1, -1};
  vi dy = {1, -1, 0, 0};
  UnionFind uf(h*w);
  rep(i, h) rep(j, w) rep(k, 4) {
    int ni = i+dx[k];
    int nj = j+dy[k];
    if (0 <= ni && ni < h && 0 <= nj && nj < w && s[i][j] != s[ni][nj]) {
      uf.unite(i*w + j, ni*w + nj);
    }
  }

  vector<ll> black(h*w, 0), white(h*w, 0);
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') black[uf.find(i*w + j)]++;
    else white[uf.find(i*w + j)]++;
  }

  ll ans = 0;
  rep(i, h*w) {
    ans += black[i] * white[i];
  }
  cout << ans << endl;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int ans=n/1000;
	if(n%1000==0){
		cout<<0;
	}
	else{
		cout<<(1000*(ans+1)-n);
	}
	return 0;
}

Measured memory_bytes: 3592
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final int VALUE = 0;
		final int TYPE = 1;

		Map<String, Double> rateMap = new HashMap<>();
		rateMap.put("JPY", 1.0);
		rateMap.put("BTC", 380000.0);

		Scanner sc = new Scanner(System.in);
		sc.nextLine();

		double sum = 0;
		while (sc.hasNext()) {
			String[] input = sc.nextLine().split(" ");
			double value = Double.valueOf(input[VALUE]);
			double rate = rateMap.get(input[TYPE]);
			sum = sum + value * rate;
		}
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int N=100010,Mod=998244353;
const double pi=acos(-1.0);
typedef long long int ll;
typedef pair<int,int> pii;
int main()
{
  int a,b;
  cin>>a>>b;
  cout<<max(a*b,max(a-b,a+b))<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(br.readLine());
        Set<String> Dictionary = new HashSet<String>();
        String tmp = new String();
        String[] input = new String[2];
        StringBuilder ans = new StringBuilder(); 
        
        for(int i = 0; i < n; i++){
            input = br.readLine().split(" ");
            //System.out.println(input[0] + " " + input[1]);
            if(input[0].equals("insert")){
                Dictionary.add(input[1]);
            }else if(input[0].equals("find")){
                if(Dictionary.contains(input[1])){
                    ans.append("yes\n");
                }else{
                    ans.append("no\n");
                }
            }else{
                System.err.println("error");
            }
        }
        System.out.print(ans.toString());
       
    }
}


Measured memory_bytes: 196816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
ll f(ll a,ll b){
	if(b==0)return 1;
	if(b%2==0){
		ll t=f(a,b/2);
		return t*t;
	}
	return a*f(a,b-1);
}

signed main(){
	int k; cin>>k;
	int t; cin>>t;
	vi a(t);
	rep(i,0,t)cin>>a[i];
	sort(all(a));
	ll x=a[t-1]-1;
	rep(i,0,t-1){
		x-=a[i];
	}
	cout<<max((ll)0,x)<<endl;
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n, m;
  cin >> n >> m;
  vi num(m);
  rep (i, n) {
    int k;
    cin >> k;
    rep (j, k) {
      int a;
      cin >> a;
      a--;
      num[a]++;
    }
  }
  int ans = 0;
  rep (i, m) {
    if (num[i] == n) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def o_divisors(n):
    L = [i for i in range(1, int(n**0.5)+5) if n%i == 0]
    L += [n//i for i in L]
    L = sorted(list(set(L)))
    return [l for l in L if n//l % 2]
    
N = int(input())
T = input()
P = 998244353
bt = int(T, 2)
c = 0
ans = 0
L = []
for k in o_divisors(N):
    tt = T[:k]
    tt_ = tt.replace("0", "2").replace("1", "0").replace("2", "1")
    ttf = tt + (tt_ + tt) * ((N//k-1)//2)
    aa = int(tt, 2) + (int(ttf, 2) <= bt)
    for l, cc in L:
        if k % l == 0:
            aa -= cc
    L.append((k, aa))
    c += aa
    ans += k*2*aa
        
ans = (ans + 2 * N * (bt - c + 1)) % P
print(ans)


Measured memory_bytes: 4596
#include <cstdio>
#include <cstring>
const int mo = 1e9+7;
const int MAXN = 5002;
int F[2][MAXN];
int main()
{
	int N, K, i, j, p;
	char str[MAXN];
	scanf("%d%s", &N, str);
	K = strlen(str);
	F[0][0] = 1;
	for(i=1; i<=N; ++i)
	{
		p = i&1;
		F[p][0] = (F[p^1][0] + 2*F[p^1][1]%mo) % mo;
		for(j=1; j<=N; ++j)
			F[p][j] = (F[p^1][j-1] + 2*F[p^1][j+1]%mo) % mo;
	}
	printf("%d\n", F[p][K]);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::string S; std::cin >> S;
  std::map<char, int> m;

  for (char c : S) {
    auto it = m.find(c);
    if (it != m.end()) {
      m[c]++;
    } else {
      m.insert(std::make_pair(c, 1));
    }
  }

  LL count = 1;
  for (auto pair : m) {
    count *= static_cast<LL>(pair.second + 1);
    count %= kMod;
  }
  --count;
  std::cout << count % kMod << std::endl;
}


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

using namespace std;


int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int a,b;
    cin >> a >> b;
    if (a>b)
        swap(a,b);
    int c=a+b;

    if (c%2==1)
    {
        cout << "IMPOSSIBLE";
        return 0;
    }

    cout << c/2;

}


Measured memory_bytes: 256
// 工夫0の山登り
#include<iostream>
#include<set>
#include<random>
#include<chrono>
using namespace std;
typedef long long ll;

int main(){
    auto start = std::chrono::system_clock::now(); 
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<int> randd(1,365);
    uniform_int_distribution<int> randq(1,26);
    
    int d;
    cin >> d;
    int c[27];
    for(int i = 1; i <= 26; i++) cin >> c[i];
    int s[365+1][27];
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++){
            cin >> s[i][j];
        }
    }
    set<int> h[27];
    for(int i = 1; i <= 26; i++) h[i].insert(0), h[i].insert(d+1);
    int t[365+1];
    int last[27] = {};
    ll now = 0;
    for(int i = 1; i <= 365; i++){
        t[i] = i%26+1;
        h[t[i]].insert(i);
        now += s[i][t[i]];
        last[t[i]] = i;
        ll dec = 0;
        for(int j = 1; j <= 26; j++)    dec += c[j]*(i-last[j]);
        now -= dec;
    }

    while(1){
        auto nowt = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()-start).count();
        if(nowt > 1900)  break;
        int d = randd(mt), q = randq(mt);
        ll diff = 0;
        int bef = t[d];
        diff -= s[d][bef];
        h[bef].erase(d);
        {
            int from = *(--h[bef].lower_bound(d));
            int to = *(h[bef].lower_bound(d));
            diff -= (ll)c[bef]*(to-d)*(d-from);
        }
        t[d] = q;
        diff += s[d][q];
        h[q].insert(d);
        {
            int from = *(--h[q].lower_bound(d));
            int to = *(h[q].upper_bound(d));
            diff += (ll)c[q]*(to-d)*(d-from);
        }
        if(diff < 0){
            int bef = t[d];
            h[bef].erase(d);
            t[d] = q;
            h[q].insert(d);
        }else{
            now += diff;
        }
    }

    for(int i = 1; i <= d; i++) cout << t[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3716
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
  	
  	int a;
  	cin >> a;
  	cout << 3 * a * a << '\n';
  	
	return 0;
}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)

using namespace std;

ll A, B, C;
ll X, Y;
ll ans = inf*1LL*inf;

int main()
{
	cin >> A >> B >> C >> X >> Y;
	FOR (i,0,200010) {
		ll ret = i*C;
		
		if (X > i/2)
			ret+=(X-i/2)*A;
		if (Y > i/2)
			ret+=(Y-i/2)*B;
			
		ans = min(ans, ret);
		
		i++;
	}
	cout << ans;
}


Measured memory_bytes: 256
s = input()
t = input()
answer = 0
for i in range(len(s) - len(t) + 1):
    w = s[i:i + len(t)]
    w_match = 0
    for w_t, w_w in zip(t, w):
        if w_t == w_w:
            w_match += 1
    answer = max(answer, w_match)
print(len(t) - answer)



Measured memory_bytes: 8952
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
int mod = (int) 1e9 + 7;
int main(){
    long D , T  , S ;
    cin >> D >> T >> S ;
    if(T * S >= D){
         cout << "Yes" << endl;
         
    }else{
         cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int a,l,j,p=0;
        a=tan.nextInt();
        l=tan.nextInt();
        if(l%2==0 && (a*2<=l && a*4>=l))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35776
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    ll ans = 0;
    rep(c,1,n){
        ll lp = 0, rp = n-1;
        ll temp = 0;
        bool is_div = (n - 1) % c == 0;

        for(; lp < n; lp += c){
            if(rp < c)break;
            if(is_div && lp >= rp)break;
            temp += s[lp];
            temp += s[rp];
            chmax(ans, temp);
            debug(c, lp, rp, temp);
            rp -= c;
        }
    }

    cout << ans << "\n";
}

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

ll solve(ll h, ll w) {
  if (h % 3 == 0 || w % 3 == 0) {
    return 0;
  } else {
    ll a, b, c;
    a = h * (w / 3) + (w % 3 == 2) * h;
    b = (h / 2) * ((2 * (w / 3)) + 1);
    c = (h / 2 + h % 2) * ((2 * (w / 3)) + 1);
    return max(max(abs(a - b), abs(a - c)), abs(b - c));
  }
}
int main() {
  ll h, w;
  cin >> h >> w;
  if (h == w)
    cout << min(h, solve(h, w)) << endl;
  else
    cout << min(min(h, w), min(solve(h, w), solve(w, h))) << endl;
}


Measured memory_bytes: 256