akhauriyash/Code-Regression huggingface dataset:
n = int(input())
parentheses = input()

count = 0
left_num = 0

for p in parentheses:
    if p == '(':
        count += 1
    else:
        count -= 1

    if count == -1:
        count = 0
        left_num += 1

print('(' * left_num + parentheses + ')' * count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n,k;
	cin >> n >> k;
	long double ans = 0;
	long double p = 1.0 / n;
	if(n >= k){
		ans = (long double)(n - k + 1) / n;
		n = k - 1;
	}
	for(int i = 1;i <= n;++i){
		int t = 0;
		int num = i;
		while(num < k){
			num = num * 2;
			++t;
		}
		ans = ans + p * pow(0.5,t);
	}
	cout << ans << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(15);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 4116
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<llint>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<llint>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,j,k,n,ans=0;cin>>n;
	vector<string>S(n);
	for(i=0;i<n;i++){cin>>S[i];}
	for(i=0;i<n;i++){
		bool ok=true;
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				if(S[j][(k+i)%n]!=S[k][(j+i)%n]){ok=false;break;}
			}
			if(!ok){break;}
		}
		if(ok){ans+=n;}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

vector<long long> len(55);
vector<long long> pat(55);

long long solve(long long n, long long x){
    
    if (x == len[n]) return pat[n];
    
    long long ans = 0;
    
    x--;
    
    if (x){
        long long l = min(x,len[n-1]);
        ans += solve(n-1,l);
        x -= l;
    }
    
    if (x){
        ans++;
        x--;
    }
    
    if (x){
        long long l = min(x,len[n-1]);
        ans += solve(n-1,l);
        x -= l;
    }
    
    return  ans;
    
}

int main(){
    long long n, x;
    cin >> n >> x;
    
    len[0] = 1;
    pat[0] = 1;
    
    for (int i = 1; i <= n; i++){
        len[i]= len[i-1]*2+3;
        pat[i] = pat[i-1]*2+1;
    }
    
    cout << solve(n,x) << endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoderIsFucking.cpp

#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <algorithm>

using namespace std;


char steps[] = { 'L', 'R', 'U', 'D' };
string S;

int main()
{
	cin >> S;

	int N = S.size();

	bool ret = true;

	for (int i = 0; i < N; i++) {
		int st = S[i] == steps[0] ? 0 : (S[i] == steps[1] ? 1 : (S[i] == steps[2] ? 2 : 3));
		if (st == i % 2) {
			ret = false;
		}
	}

    cout << (ret ? "Yes" :"No");
}



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

int N, K;
vector<int> gs[10];
int dp[11][2010];

int main() {
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    int c, g;
    cin >> c >> g;
    gs[g-1].push_back(c);
  }

  for (int i=0; i<10; i++) {
    sort(gs[i].begin(), gs[i].end(), greater<int>());
    for (int x=1; x<gs[i].size(); x++) gs[i][x] += gs[i][x-1] + 2*x;
  }
  for (int i=0; i<10; i++) {
    for (int s=0; s<=K; s++) dp[i+1][s] = dp[i][s];
    for (int s=0; s<=K; s++) {
      for (int t=0; t<gs[i].size(); t++) {
        if (s + t + 1 > K) continue;
        dp[i+1][s+t+1] = max(dp[i+1][s+t+1], dp[i][s] + gs[i][t]);
      }
    }
  }
  cout << dp[10][K] << "\n";
  return 0;
}

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

using namespace std;

int main(void)
{
	int k, x;
	cin >> k >> x;
	int b, e;
	b = x - k + 1;
	e = x + k - 1;
	for (int i = b; i <= e; ++i)
	{
		cout << i << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

void solve()	{
	int n;
	cin >> n;
	int pt=0,px=0,py=0,f=0;
	for(int i=0; i<n; i++)	{
		int t,x,y;
		cin >> t >> x >> y;
		int T = t-pt;
		int X = abs(x-px);
		int Y = abs(y-py);
		pt=t;
		px=x;
		py=y;
		if(X+Y>T || (T-(X+Y))&1)		{
			f=1;	
			//cout << X << " " << Y << " " << T << " " << t << endl;
		}
	}
	if(f)	cout << "No\n";
	else cout << "Yes\n";
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
using namespace std;
int main(){
    string a;
    string b;
    int i,j,e=0;
    char m,t;
    getline(cin,a);
    getline(cin,b);

    for(i=0;i<a.size();i++){
            t = a[a.size()-1];
        for(j=0;j<a.size();j++){
            m = a[j];
            a[j] = t;
            t = m;
        }
        if(a == b){
            cout<<"Yes";
            e = 0;
            break;}
        else e+=1;
    }
    if(e!=0) cout << "No";
}


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

int main(){
  int n,ans=0;
   cin >> n;
  for(int i=0;i<26;i++){
    for(int j=0;j<15;j++){
      if(i*4+j*7==n){
        ans++;
        break;
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>

using namespace std;

long long a[200005]={},dp[200005]={},res=0;
string str[200005],strtmp;
int main(){
	long long n,k,l=0,odd=0,tmp,memo=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	res=n;
	for(int i=1;i<=n;i++)
	{
		if(a[i-1]==0&&a[i]==0&&i!=1)
		{
			
			memo--;
			res+=memo;
			continue;
		}
		memo=0;
		long long now=a[i];
		for(int j=i+1;j<=n;j++)
		{
			
			if((now^a[j])!=a[j]+now){
				break;
			}else{
				res++;
				memo++;
				now+=a[j];
			}
		}
	}
	cout<<res;
}


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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for(int i = 1; i <= n; i++){
    if(i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << endl;
  return 0;
}


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

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

    int m[n], sum = 0;
    for (int& i : m) cin >> i, sum += i;

    sort(m, m + n);

    cout << n + (x - sum) / m[0] << endl;

    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  vector<int> cost(N);
  cost[1] = abs(h[0] - h[1]);
  for (int i = 2; i < N; i++) {
    cost[i] = min(cost[i - 1] + abs(h[i - 1] - h[i]),
                  cost[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << cost[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 4048
a, b, n = map(int, input().split())
ans = 0
if n < b:
    ans = max(ans, a*n//b)
else:
    ans = max(ans, (a*n)//b)-a*(n//b)
    ans = max(ans, ((a*(b*(n//b)-1))//b)-a*(n//b - 1))
print(ans)


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define in(a, l, r) (l <= a && a < r)
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}


int main() {
    string s; cin >> s;
    if(s == "SUN") {        
        out(7);
    } else if(s == "SAT") {
        out(1);
    } else if(s == "FRI") {
        out(2);
    } else if(s == "THU") {
        out(3);
    } else if (s == "WED") {
        out(4);
    } else if( s == "TUE") {
        out(5);
    } else if(s == "MON") {
        out(6);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
int a,b;
    long long ans=1;
    cin >> a >> b;
    vector<int> s(a),t(b);
    vector<long long> q(a),w(b);
    for (int i=0;i<a;i++){
        cin >> s.at(i);
        q.at(i)=0;
    }
    for (int i=0;i<b;i++){
        cin >> t.at(i);
        w.at(i)=0;
    }
    for (int i=a-1;i>-1;i--){
        int p=0;
        for (int j=b-1;j>-1;j--){
            int y=w.at(j);
            if (s.at(i)==t.at(j)) {
                int pp=0;
                if (p==0) pp=1;
                else pp=p+1;
                ans=(ans+pp)%1000000007;
                w.at(j)=(pp+w.at(j))%1000000007;
                
                
            }
            p=(p+y)%1000000007;
        }
        
    }
    cout << ans << endl;
}


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

int main() {
	// your code goes here
	int n,mx1=INT_MIN,mx2=INT_MIN;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>=mx1){
			mx2=mx1;
			mx1=a[i];
		}else if(a[i]>mx2){
			mx2=a[i];
		}
	}
	for(int i=0;i<n;i++){
		if(a[i]==mx1)cout<<mx2<<endl;
		else cout<<mx1<<endl;
	}
	return 0;
}

Measured memory_bytes: 2432
X,D,C = map(int,input().split())
count=abs(X)
a = abs(X//C)
b = abs(X%C)
if a>D:
  print(count-D*C)
elif a==D:
  print(b)
elif a<D:
  D = D-a
  if D%2==0:
    print(b)
  else:
    print(min(abs(b-C),abs(b+C)))

Measured memory_bytes: 9196
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof,prof1)
print(prof)


Measured memory_bytes: 3060
import sys
import re

N, K = map(int, input().split())
A = sys.stdin.readlines()
#改行コード削除
A = [b.strip() for b in A]

l_temp = []
for i in range(K*2):
  if i % 2 == 0:
    d = A[i]
    ary = A[i+1].split()
    for item in ary:
      l_temp.append(item)

print(N - len(list(set(l_temp))))

Measured memory_bytes: 10152
#include<bits/stdc++.h>
using namespace std;
class unionfind{
    public:
        int size;
        unionfind(int n){
            size=n;
            for(int i=0;i<n;i++){
                par[i]=i;
                rank[i]=0;
            }
        }
        int find(int x){
            if(par[x]==x)
                return x;
            else
                return par[x]=find(par[x]);
        }
        void unite(int x,int y){
            x=find(x);
            y=find(y);
            if(x==y)
                return;
            size--;
            if(rank[x]<rank[y])
                par[x]=y;
            else{
                par[y]=x;
                if(rank[x]==rank[y])
                    rank[x]++;
            }
        }
        bool same(int x,int y){
            return find(x)==find(y);
        }
    private:
        int par[100000];
        int rank[100000];
};
int main(){
    int n,m,x,y,z;
    cin>>n>>m;
    unionfind uf(n);
    while(cin>>x>>y>>z)
        uf.unite(x-1,y-1);
    cout<<uf.size<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 100;

class Point {
public:
  int x, y;
  bool red;

  bool operator<(const Point& p) const { return x < p.x; }
};

int N;
Point abcd[kMaxN*2];
int ans = 0;

set<Point> s;

signed main() {
  cin >> N;
  REP(i, N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = true;
  }
  FOR(i, N, 2*N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = false;
  }

  sort(abcd, abcd + 2*N);
  REP(i, 2*N) {
    Point& p = abcd[i];
    if (p.red) {
      s.insert(p);
    } else {
      int max_y = -1;
      auto max_it = s.end();
      for (auto it = s.begin(); it != s.end(); ++it) {
        if (it->red && it->y < p.y && it->y > max_y) {
          max_y = it->y;
          max_it = it;
        }
      }
      if (max_y != -1) {
        s.erase(max_it);
        ++ans;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

int count[100001];

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

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

		if (a != 0)
			++count[a - 1];

		++count[a];
		++count[a + 1];
	}

	std::cout << *std::max_element(count, std::end(count)) << std::endl;
}

Measured memory_bytes: 640
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        if(x>=30)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35608
S = list(input())
c = ""
a = 0
if S[0]=="R":
    if S[1]=="R":
        if S[2] =="R":
            print(3)
        else:
            print(2)
    else:
        print(1)
else:
    if S[1]=="R":
        if S[2]=="R":
            print(2)
        else:
            print(1)
    else:
        if S[2]=="R":
            print(1)
        else:
            print(0)

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void YAY(bool b = true) {cout << (b ? "Yay!" : ":(") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
V<> VEC(ll n) {V<> v(n); REP(i, n) cin >> v[i]; return v;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1;} return ret;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    cout <<10 - n / 200 << endl; 
}

Measured memory_bytes: 3652
n,k=map(int,input().split())
d=list(map(int,input().split()))
n=[int(x) for x in str(n)]

ok=[]
for i in range(10):
    if i not in d:
        ok.append(i)

import bisect
for i in range(len(n)-1,-1,-1):
    if n[i]>ok[len(ok)-1]:
        for j in range(i,len(n)):
            n[j]=str(ok[0])
        if i>0:
            n[i-1] += 1
        else:
            if ok[0]==0:
                n.insert(0,str(ok[1]))
            else:
                n.insert(0,str(ok[0]))
    else:
        num=bisect.bisect_left(ok,n[i])
        if n[i]<ok[num]:
            for j in range(i+1,len(n)):
                n[j]=str(ok[0])
        n[i]=str(ok[num])

n=int(''.join(n))
print(n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N = 3003, mod = 998244353;
int a[N], dp[2][N], n, s, ans;
int M(int x)
{
    int ret = x%mod;
    ret+=mod;
    ret%=mod;
    return ret;
}
signed main()
{
    cin >> n >> s;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        dp[i%2][a[i]]=i;
        for(int j = 1; j <= s; j++)
        {
            if(j!=a[i]) dp[i%2][j]=0;
            dp[i%2][j] += dp[1 - (i%2)][j];
            dp[i%2][j] = M(dp[i%2][j]);
            if(j>=a[i]) dp[i%2][j] += dp[1 - (i%2)][j-a[i]];
            dp[i%2][j] = M(dp[i%2][j]);
         //   cout << dp[i%2][j] << " ";
        }
      //  cout << endl;
        ans += M((dp[i%2][s] - dp[1 - (i%2)][s]) * (n-i+1));
        ans = M(ans);

    }
    cout << ans;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
        if(A <= C) {
            if(B <= C) {
                System.out.println(0);
            }else if(B <= D) {
                System.out.println(B - C);
            }else {
                System.out.println(D - C);
            }
        }else {
            if(D <= A) {
                System.out.println(0);
            }else if(D <= B) {
                System.out.println(D - A);
            }else {
                System.out.println(B - A);
            }
        }
    }
}


Measured memory_bytes: 22612
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = [list(map(int, input().split())) for i in range(m)]
b.sort(key=lambda x: -x[1])

ct1 = 0
ct2 = 0
ans = 0
i = 0

while i in range(n):
    if ct2 < m:
        if a[ct1] < b[ct2][1]:
            j = min(n-i, b[ct2][0])
            ans += b[ct2][1] * j
            i += j
            ct2 += 1
        else:
            ans += a[ct1]
            ct1 += 1
            i += 1
    else:
        ans += a[ct1]
        ct1 += 1
        i += 1
print(ans)

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b<a) { a=b; return 1; } return 0; }



int d, c[30], s[400][30], t[400];
int score(int a[400], int l, int r){
	int cnt = 0;
	int last[26] = {};
	fill(last,last+26,l-1);
	
	for(int i = l; i < r; i++){
		cnt += s[i][a[i]];
		last[a[i]] = i;
		for(int j = 0; j < 26; j++){
			cnt -= c[j]*(i-last[j]);
		}
	}
	return cnt;
}
void solve(){
	cin >> d;
	for(int i = 0; i < 26; i++) cin >> c[i];
	for(int i = 0; i < d; i++){
		for(int j = 0; j < 26; j++) cin >> s[i][j];
	}
	for(int i = 0; i < d; i++){
		cin >> t[i];
		t[i]--;
	}
	
	for(int i = 0; i < d; i++){
		cout << score(t, 0,i+1) << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();

		System.out.println(n/(a + b)*a + Math.min(a, n % (a + b)));
	}
}


Measured memory_bytes: 25172
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int r;
int ans;

int main(){
	cin >> r;
	ans = 3 * r*r;
	cout << ans << endl;

	return 0;
}

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

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

  vector<int> dp(n + 1, 50001);
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    int c;
    cin >> c;

    for (int j = c; j <= n; j++) {
      dp[j] = min(dp[j], dp[j - c] + 1);
    }
  }

  cout << dp[n] << endl;
}



Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		if(s.charAt(a)=='-') {

		} else {
			System.out.println("No");
			return;
		}
		s = s.substring(0, a)+s.substring(a+1);
		for(Character c : s.toCharArray()) {
			if(Character.isDigit(c)) {

			} else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char ch[] = str.toCharArray();
        for(int i = 0; i < str.length(); i++){
            if(Character.isUpperCase(ch[i])){
                ch[i] = Character.toLowerCase(ch[i]);
            }
            else if(Character.isLowerCase(ch[i])){
                ch[i] = Character.toUpperCase(ch[i]);
            }
        }
        System.out.println(ch);
    }
}


Measured memory_bytes: 26204
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string s;
    cin >> s;
    int ans = 0;
    REP(i, s.size()){
        if(s[i] == '1') ans++;
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

ll  a[501][501], d[31][31], pre[31][3];

void calc(int c, int n){
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			pre[c][(i+j)%3] += d[a[i][j]][c];
		}
	}
}

int main(void){
	int n, c;
	cin>>n>>c;
	for(int i=1; i<=c; i++){
		for(int j=1; j<=c; j++){
			cin>>d[i][j];
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			cin>>a[i][j];
		}
	}
	memset(pre, 0, sizeof(pre));
	for(int i=1; i<=c; i++){
		calc(i, n);
	}
	ll mn = 1e18;
	for(int i=1; i<=c; i++){
		for(int j=i+1; j<=c; j++){
			for(int k=j+1; k<=c; k++){
				vector<int> tmp = {i, j, k};
				mn = min(mn, pre[tmp[0]][0]+pre[tmp[1]][1]+pre[tmp[2]][2]);
				while(next_permutation(tmp.begin(), tmp.end())){
					mn = min(mn, pre[tmp[0]][0]+pre[tmp[1]][1]+pre[tmp[2]][2]);
				}
			}
		}
	}
	cout<<mn<<endl;
}

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

using namespace std;
typedef long long ll;

long long GCD(long long a, long long b)
{
    if(a<b)
        swap(a, b);
    long long r = a % b;
    if (r == 0)
        return b;
    else
        return GCD(b, r);
}

int main(void){
    int n;
    cin >> n;
    vector<long long> mst(n);
    for (int i = 0; i < n; i++)
        cin >> mst.at(i);
    long long ans = mst.at(0);
    for (int i = 0; i < n;i++){
        ans = GCD(mst.at(i), ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
h,w = map(int, input().split())
c = []
a = []
for i in range(10):
  c.append(list(map(int, input().split())))
for i in range(h):
  a.append(list(map(int, input().split())))
 
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j], c[i][k] + c[k][j])
      
ans = 0
for i in range(h):
  for j in range(w):
    if a[i][j] != -1:
      ans += c[a[i][j]][1]
print(ans)

Measured memory_bytes: 3444
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int c=a+b;
  int d=a-b;
  int e=a*b;
  if(c>=d&&c>=e){
    printf("%d",c);
  }
  else if(d>=e&&d>=c){
    printf("%d",d);
  }
  else{
    printf("%d",e);
  }
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int R, G, d;
	cin >> R >> G;
	d = G - R;
	cout << R + 2 * d << endl;

	return 0;
}

Measured memory_bytes: 256
num = int(input())

k = input().split()

for i in range(len(k)):
    k[i] = int(k[i])

k.sort()

mul = 1

for i in range(num):
    mul *= int(k[i])
    if mul > 10**18:
        break

if mul > 10**18:
    print(-1)

else:
    print(mul)

Measured memory_bytes: 19364
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

min_solved = 1000
for i in range(2 ** d):
    i_str = "{:010b}".format(i)[::-1]
    score = 0
    solved = 0
    for j in range(d):
        if i_str[j] == "1":
            score += 100 * (j + 1) * pc[j][0] + pc[j][1]
            solved += pc[j][0]
    if score < g:
        add_i = i_str[:d].rfind("0")
        for k in range(pc[add_i][0]):
            score += 100 * (add_i + 1)
            solved += 1
            if score >= g:
                break
        else:
            continue

    if solved < min_solved:
        min_solved = solved

print(min_solved)


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
scanf("%d%d%d%d",&A,&B,&C,&D);
if(A*B>C*D)
{
    printf("%d",(A*B));
}
else
if(A*B<C*D){
printf("%d",(C*D));
}
else
    printf("%d",(A*B));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vi(C, N);
    vi(a, 2*M);
    rep(i, M){
        pair<int, int> a_i;
        cin >> a_i.first >> a_i.second;
        a[2*i] = a_i.first;
        a[2*i+1] = a_i.second;
    }
    rep(i, N) C[i] = count(a.begin(), a.end(), i+1);
    rep(i, N) cout << C[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int[] e = new int[2];
    int[] w = new int[2];
    for(int i = 0; i < n; i++){
      e[1] += (s.charAt(i) == 'E') ? 1 : 0;
      w[1] += (s.charAt(i) == 'W') ? 1 : 0;
    }
    int min;
    if(s.charAt(0) == 'E'){
      e[1]--;
      min = e[1];
    }else{
      w[1]--;
      min = e[1];
    }
    for(int i = 1; i < n; i++){
      if(s.charAt(i-1) == 'W'){
        w[0]++;
      }else{
        e[0]++;
      }
      if(s.charAt(i) == 'W'){
        w[1]--;
      }else{
        e[1]--;
      }
      min = Math.min(min, e[1] + w[0]);
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 29672
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){

double N;
cin>>N;


double ansa = N*(100.0/108.0);
int t1,t2,t3;
t1=int(ansa)-1;
t2=t1+1;
t3=t2+1;
if(int(t1*1.08)==N){
  cout<<t1<<endl;
}
else if(int(t2*1.08)==N){
  cout<<t2<<endl;
}
else if(int(t3*1.08)==N){
cout<<t3<<endl;
}
else{
 cout<<":("<<endl;
  }



}



Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)

using namespace std;

void dfs_color(vector<Int> vs[], Int colors[], Int n) {
    bool visited[n];
    loop(i,0,n)  {
        visited[i] = false;
        colors[i] = 0;
    }
    
    stack<Int> S;
    
    loop(i,0,n) {
        Int color = i + 1;
        S.push(i);
        visited[i] = true;
        if (colors[i] == 0) colors[i] = color;
        
out_of_while:
        while (!S.empty()) {
            Int i = S.top();
            for (auto c: vs[i]) {
                if (visited[c]) continue;
                S.push(c);
                visited[c] = true;
                if (colors[c] == 0) colors[c] = color;
                goto out_of_while;
            }
            
            S.pop();
        }
    }
}


int main(void) {
    Int n, m, q, v, x;
    cin >> n >> m;
    vector<Int> vs[n];
    Int colors[n];
    
    loop(i,0,m) {
        cin >> v >> x;
        vs[v].push_back(x);
        vs[x].push_back(v);
    } 
    
    dfs_color(vs, colors, n);
    
    cin >> q;
    loop(i,0,q) {
        cin >> v >> x;
        if (colors[v] == colors[x]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

using namespace std;

#define F 		first
#define S 		second
#define ll 		long long
#define ld 		long double
#define pii		pair<int, int>
#define vi 		vector<int>
#define mii 	map<int, int>
#define umii 	unordered_map<int, int>
#define pb		push_back
#define mk		make_pair
#define all(a)	a.begin(), a.end()
#define ask(x) 	cerr << #x << " = " << x << "\n";
#define INF 	1000000007
#define hell 	998244353

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

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

	int n;
	cin >> n;

	if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
		cout << "hon";
	else if (n % 10 == 3)
		cout << "bon";
	else
		cout << "pon";		

	return 0;
}

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

int main(void)
{
	int N; cin >> N;
	int a[1010];
	for(int i = 0; i < N; i++) cin >> a[i];
	int ans = 0;
	for(int i = 0; i < N - 1; i++) {
		if (a[i] == a[i + 1]) {
			a[i + 1] = 100000 + i;
			ans++;
		}
	}
	cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  for(double i=1; i<=2000; i++){
    if(floor(i*0.08)==a && floor(i*0.1)==b){cout << i; return 0;}
  }
  cout << "-1";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int H,W;
    cin >> H >> W;
    vector<string> V(H);
    rep(i,0,H)cin >> V[i];
    int dist[H][W];
    rep(i,0,H)rep(j,0,W)dist[i][j] = INF;
    queue<P> que;
    rep(i,0,H)rep(j,0,W){
        if(V[i][j] == '#'){
            dist[i][j] = 0;
            que.push(P(i, j));
        }
    }
    int maxque = 0;
    int cnt = 0;
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int y = p.first;
        int x = p.second;
        int dx[] = {0,0,-1,1};
        int dy[] = {-1,1,0,0};
        rep(i,0,4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(ny < 0 || ny >= H || nx < 0 || nx >= W)continue;
            //if(dist[ny][nx] <= dist[y][x])continue;
            if(dist[ny][nx] != INF)continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.push(P(ny, nx));
        }
        maxque = max(maxque, (int)que.size());
        cnt++;
    }
    int maxi = 0;
    rep(i,0,H)rep(j,0,W)maxi = max(maxi, dist[i][j]);
    cout << maxi << endl;
    //cout << maxque << endl;
    //cout << cnt << endl;
}

Measured memory_bytes: 13456
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar gc
inline char gc(){
	static char buf[1<<16],*p1=buf,*p2=buf;
	if(p1==p2){
		p2=(p1=buf)+fread(buf,1,1<<16,stdin);
		if(p2==p1) return EOF;
	}
	return *p1++;
}
#endif
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e5+5;
int n,m,ans,a[N];
vector<int> g[N];

signed main(){
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1,x,y;i<=m;i++){
		read(x);read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int x=1;x<=n;x++){
		bool flag=0;
		for(int y:g[x]) flag|=a[y]>=a[x];
		ans+=!flag;
	}
	write(ans);
}

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

int main(){
  int N;
  cin >> N;
  int broken=0;
  int count=1;
  int flag=1;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<N;i++){
    if(a.at(i)==count){
      count++;
      flag=0;
    }else{
      broken++;
    }
  }
  if(flag==1){
    cout << -1 << endl;
  }else{
    cout << broken << endl;
  }
}   

Measured memory_bytes: 1152
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
//template<typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define ld long double
#define int long long

void SOLVE() {
	int x;
	cin >> x;
	while (1) {
		int d = 2;
		bool ok = 1;
		while (d * d <= x) {
			if (x % d == 0) {
				ok = 0;
				break;
			}
			d++;
		}
		if (ok) {
			cout << x << '\n';
			return;
		}
		x++;
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	//freopen("longpath.in", "r", stdin);
	//freopen("longpath.out", "w", stdout);
	int Q = 1;
	//cin >> Q;
	while (Q--)
		SOLVE();

	return 0;
}
/*
*/

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

int main(void) {
  int ans = 114514;
  string s;
  cin >> s;
  for (int i = 0; i < s.size() - 2; i++) {
    int zohe = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    ans = min(ans, abs(zohe - 753));
  }
  cout << ans << endl;
}


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

import sys
import random

def main():
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    ranks = [0 for i in range(n)]
    adjs = [[] for i in range(n)]
    edges = []
    for i in range(n - 1):
        a, b = map(int, input().split())
        edges.append((a - 1, b - 1))
        ranks[a - 1] += 1
        ranks[b - 1] += 1
        adjs[a - 1].append(b - 1)
        adjs[b - 1].append(a - 1)

    for i in range(n):
        random.shuffle(adjs[i])
    visited = [False for i in range(n)]
    colors = {}  # (mi, ma) |-> color
    dfs(0, adjs, visited, -1, colors)

    print(max(ranks))
    for i in range(n - 1):
        a, b = edges[i]
        mi = min(a, b)
        ma = max(a, b)
        print(colors[(mi, ma)])

def dfs(i, adjs, visited, color_used, colors):
    visited[i] = True
    c = 1
    for j in adjs[i]:
        if visited[j]:
            continue
        if c == color_used:
            c += 1
        mi = min(i, j)
        ma = max(i, j)
        colors[(mi, ma)] = c
        dfs(j, adjs, visited, c, colors)
        c += 1

if __name__ == "__main__":
    main()


Measured memory_bytes: 122268
#include <stdio.h>

int main(void)
{
 int k,n,max = 0,i;
  
 int a[200000];
  
  scanf("%d %d", &k, &n);
  
  for(i=0;i<n;i++)
     scanf("%d", &a[i]);
  
  for(i=0;i<n;i++){
      if(a[i] - a[i-1] > max ){
        max = a[i] - a[i-1];
      }
      if((k-a[i]) + a[0] > max && i == n-1){
        max = (k-a[i]) + a[0];
      }
  }
  
  printf("%d", k - max);
  
      return 0;
  
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if (T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) {
        cout << "infinity" << endl;
        return 0;
    }
    if (A1 > B1 && A2 > B2) {
        cout << 0 << endl;
        return 0;
    }
    if (A1 < B1 && A2 < B2) {
        cout << 0 << endl;
        return 0;
    }
    if (A1 < B1) {
        int64_t a = B1, b = B2;
        B1 = A1;
        A1 = a;
        B2 = A2;
        A2 = b;
    }
    // A1 > B1 && A2 < B2 が確定
    int64_t res1 = (A1 - B1) * T1, res2 = (B2 - A2) * T2;
    if (res1 > res2) {
        cout << 0 << endl;
        return 0;
    }
    int64_t sa = res2 - res1;
    if (res1 % sa == 0) {
        cout << res1 / sa * 2 << endl;
        return 0;
    }
    int64_t ans = (res1 / sa + 1) * 2 - 1;
    cout << ans << endl;

}


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

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    S = input()
    T = input()

    S_ary = list(S)
    T_ary = list(T)

    diff = len(S_ary) - len(T_ary) + 1
    tLen = len(T_ary)

    minCounter = 1000
    for i in range(diff):
        tempS = S_ary[i : i + tLen]

        counter = 0
        for charIndex in range(tLen):
            if tempS[charIndex] != T_ary[charIndex]:
                counter += 1
        minCounter = min(minCounter, counter)

    print(minCounter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
    if (x == 1) return true;
    for (long long i = 2; i*i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
    long long n = gcd(a, b);
    vector<long long> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (n / i == i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    return ans;
}

int main() {
    long long a, b;
    cin >> a >> b;
    vector<long long> div = common_divisors(a, b);
    long long ans = 0;
    for (int i = 0; i < div.size(); i++) if (isPrime(div[i])) ans++;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3712
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  unless (n == (-1)) $ do
    putStrLn $ solve n
    main

solve :: Int -> String
solve = g . reverse . unfoldr f
  where
    f x = if x == 0 then Nothing else Just (x `mod` 4, x `div` 4)
    g x = if null x then "0" else concatMap show x
            
toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4100
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;

int W, H;
int dh[] = {0, 0, 1, -1};
int dw[] = {1, -1, 0, 0};

inline bool in_field(int h, int w){
    return 0<=h && h<H && 0<=w && w<W;
}

void dfs1(vector<string> &field, int h, int w){
    for(int i=0; i<4; i++){
        int nh = h + dh[i];
        int nw = w + dw[i];
        if(in_field(nh, nw) && field[nh][nw] == '.'){
            field[nh][nw] = '1';
            dfs1(field, nh, nw);
        }
    }
}

void dfs2(vector<string> &field, int h, int w){
    for(int i=0; i<4; i++){
        int nh = h + dh[i];
        int nw = w + dw[i];
        if(in_field(nh, nw) && (field[nh][nw] == '.' || field[nh][nw] == '1')){
            field[nh][nw] = field[nh][nw] == '.' ? '2' : '3';
            dfs2(field, nh, nw);
        }
    }
}



int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    while(cin>>W>>H, W|H){
        vector<string> field(H);
        for(int i=0; i<H; i++)
            cin >> field[i];
        
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(field[i][j] == 'B')
                    dfs1(field, i, j);
        
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(field[i][j] == 'W')
                    dfs2(field, i, j);
        
        int cnt1 = 0, cnt2 = 0;
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(field[i][j] == '1')
                    cnt1++;
                else if(field[i][j] == '2')
                    cnt2++;
        
        cout << cnt1 << " " << cnt2 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1332
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  string s; cin >> s;
  sort(all(s));

  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    print("Yes");
  } else {
    print("No");
  }

  return 0;
}

Measured memory_bytes: 764
n = list(map(int, input().split()))
n = n[0]
hs = list(map(int, input().split()))

ue = 0
flag = "Yes"

for i in range(n):
    if(hs[i]>ue):
        ue = hs[i]
    elif(ue-2>=hs[i]):
        flag = "No"
        break
    
  
print(flag)

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

typedef long long ll;

int main(){
	const int mod = 2019;
	int L,R;
	cin >> L >> R;

	if(R-L+1 >= 2019){ cout << 0 << endl; }
	else {
		ll mn=1e9;
		int range = min(R,L+mod);
		for(ll i=L; i<range; i++){
			for(ll j=i+1; j<=range; j++){
				mn = min(mn,i*j%mod);
			}
		}
		cout << mn << endl;
	}

	return 0;
}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  
  if(n%2) {cout << "No" << endl; return 0;}
  if(s.substr(0, n/2) == s.substr(n/2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <fstream>
#include <sstream>
#include <set>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;

vector<int> t;
signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  rep(i,N){
    int a;
    cin>>a;t.push_back(a);
  }

  int ans=0;
  for(auto itr:t){
    if(itr<A || itr>=B )ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256