akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
  int N, K;
  int res;
  cin >> N >> K;
  res = K;
  for(int i=0; i<N-1; i++){
    res = res * (K-1);
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;

template <class T> inline T updmax(T& a, T b) { return a = max(a, b); }
template <class T> inline T updmin(T& a, T b) { return a = min(a, b); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++) sort(s[i].begin(), s[i].end());
    unordered_map<string, long long> si;
    for (int i = 0; i < n; i++) si[s[i]]++;
    long long ret = 0;
    for (auto x : si) {
        long long p = x.second;
        ret += (p * (p - 1)) / 2;
    }
    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 16036
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

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

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  int b1=INF, b2, ans=0;
  while(--n){
    cin>>b2;
    ans += min(b1, b2);
    b1 = b2;
  }
  ans += b2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
S=input()
K=int(input())
lenS=len(S)
for i in range(lenS-1):
    ordS_i=ord(S[i])
    if (ord("a")-ordS_i)%26<=K:
        K-=(ord("a")-ordS_i)%26
        S=S[:i]+"a"+S[i+1:]
ordS_i=ord(S[lenS-1])
moda=(ordS_i-ord("a")+K)%26
S=S[:lenS-1]+chr(ord("a")+moda)
print(S)

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

typedef long long int ll;
ll a, b, c;

int main() {
    cin >> a >> b >> c;
    
    if(c - b - a > 0 && a * b * 4 < (c - b - a) * (c - b - a)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;
using   vi = vector<int>;
using   vvi = vector<vi>;
using   vs = vector<string>;
#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
int N,M;
int dp[3010][3010];
 string s,t;
stack<char> resposta;
void build(int a,int b){

	if(a < 0 || b < 0) return;

	if(s[a] == t[b]){
		resposta.push(s[a]);
		build(a-1,b-1);
		return;
	}

	if(dp[a][b+1] > dp[a+1][b]) build(a-1,b);
	else build(a,b-1);

}
int main()
{
  
   cin>>s>>t;
   N=sz(s);
   M=sz(t);
   memset(dp,0,sizeof(dp));
   ffor(i,0,N+1)
   {
       ffor(j,0,M+1)
       {    if(i==0||j==0)dp[i][j]=0;
           else if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
           else
           {
               dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
       }
   }
//    ffor(i,0,N+1)
//     {ffor(j,0,M+1)
//     cout<<dp[i][j]<<" ";
//     cout<<endl;
//     }
   build(N-1,M-1);

	while(!resposta.empty()){
		cout << resposta.top();
		resposta.pop();
	}
	cout << endl;

	return 0;

}


Measured memory_bytes: 35712
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    lint n, k;
    cin >> n >> k;

    cout << min(n % k, abs(n % k - k)) << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,i,h[100],sum,max;
int main(void){
  
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  for(i=0;i<n;i++){
    if(i==0){
      sum+=1;max=h[i];
    }
    else if(h[i]- max >= 0){
      max = h[i];sum+=1;
    }
  }
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
	int N;
	cin >> N;
	ll a[N][3];
	ll dp[100010][3];
	for(int i = 0; i < N + 1; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(i <= N - 1)cin >> a[i][j];
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				if(j == k) continue;
				chmax(dp[i+1][k],dp[i][j] + a[i][k]);//前日にa(0),できてたら、b(1) or c(2)の中で一番大きいのがdp[i + 1][]に格納されて、添字がその日何をやったかになる。
				//途中で同じ効用の日があった場合、枝分かれが発生するから、最後になんの遊びしたかが変わる。だから、最後に各終わり遊びの最大値とってあげる。
			}
		}
	}
	ll res = 0;
	for(int i = 0; i < 3; i++) chmax(res,dp[N][i]);
	cout << res << endl;
}

Measured memory_bytes: 4992
import java .util.*;
class Main 
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
String ans ="No";
for(int i =0;i<=n; i+=4)
{
if((n-i)%7==0)
{
ans ="Yes";
}
}
System.out.println(ans);
}
}

Measured memory_bytes: 23252
// C - Distinct or Not
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}
int N;
set<int> A;

int main(){
	cin>>N;
	rp(i,0,N) A.insert(in<int>());
	cout<< (A.size()==N? "YES":"NO") <<endl;
}

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

int main(void) {
  char B;
  cin >> B;
  if(B == 'A') {
    B = 'T';
  }else if(B == 'T') {
    B = 'A';
  } else if(B == 'C') {
    B = 'G';
  } else if(B == 'G') {
    B ='C';
  }
  cout << B << endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,q,a,t,x;
	vll v;
	cin >> n >> q;
	vector<queue<ll>> vq(n);
	rep(i,q){
		cin >> a >> t;
		if(a==0){
			cin >> x;
			vq[t].push(x);
		}
		else if(a==1 && !(vq[t].empty())) v.pb(vq[t].front());
		else if(a==2 && !(vq[t].empty())) vq[t].pop();
	}
	for(auto e:v) cout << e << endl;
	return 0;
}


Measured memory_bytes: 5028
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans += gcd(a, b, c)

print(ans)

Measured memory_bytes: 74604
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////


int main() {
    ll N;
    string S;
    cin >> N >> S;

    ll cnt[3] = {};
    vector<ll> p(3*N + 1);

    repn(i, 3*N) {
        ll k;
        if (S[i - 1] == 'R') { k = 0; }
        else if (S[i - 1] == 'G') { k = 1; }
        else { k = 2; }
        cnt[k]++;

        if (cnt[k] > max(cnt[(k + 1) % 3], cnt[(k + 2)% 3])) { p[i] = 0; }
        else if (cnt[k] <= min(cnt[(k + 1) % 3], cnt[(k+2)%3])) { p[i] = 2; }
        else { p[i] = 1; }

        //cout << i << p[i] << endl;
    }

    mint ans = 1;

    ll c[3] = {};
    repn(i, 3*N) {
        if (p[i] == 0) { ans *= N - c[0]; }
        else if (p[i] == 1) { ans *= c[0]-c[1]; }
        else { ans *= c[1]-c[2]; }
        c[p[i]]++;
        //cout << ans << endl;
    }

    cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 3204
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <sstream>

// short keywords

#define ipow(a,b) (int)pow(a,b)
#define pi(a,b) pair<int,int>(a,b)
#define pis(a,b) pair<int,string>(a,b)
#define pc(c,d) pair<int,pair<int,string>>(c,d)
#define pp(a,b,c) pair<pair<int,int>,int>(pi(a,b),c)
#define ps(a,b,c) pair<string,pair<int,int>>(a,pi(b,c))
#define pic(c,d) pair<char,int>(c,d)
#define pii(a,b,c) pair<int,pair<int,int>>(a,pi(b,c))

// for loops

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
using namespace std;

// short keywords2
typedef long long ll;
typedef set<int>::iterator sit;
typedef vector <int> ::iterator vit;
typedef map<int,int>::iterator mit;
typedef multimap<int,int>::iterator mmit;

class Task
{
public:
    const int k=1000000;
    void solve(istream& in,ostream& out)
    {
        int n;
        in>>n;

        if(n<1200)
        {
            out<<"ABC"<<endl;
        }
        else
        {
            out<<"ARC"<<endl;
        }
    }

    int c(int a,int b)
    {
        int res=0;
        reps(i,1,15)
        {
            if(a/(int)pow(b,i)!=0)
            {
                res+=a/(int)pow(b,i);
            }
            else
            break;
        }

        return res;
    }

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

    bool isprime(int n)
    {
        if(n==1 || (n%2==0 && n!=2))
        {
            return false;
        }
        else if(n==2 || n==3)
        {
            return true;
        }
        else
        {
            int res=0;
            for(int i=3 ;i<=(int)sqrt(n) ;i+=2)
            {
                if(n%i==0)
                {
                    res++;
                    break;
                }
            }

            if(res==0)
            {
                return true;
            }
            else
            return false;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int size;
  string S,T;
  cin >> S >> T;
  size = (int)(T.length());
  int result = T.compare(0, (size-1), S);
  if(result==0){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 3632
N = int(input())
S = input()

def isOk(first, second):
    prev, now = first, second
    ret = [prev]

    for s in S[1:] + S[0]:
        ret.append(now)
        isSame = (s == 'o')

        if isSame == now:
            prev, now = now, prev
        else:
            prev, now = now, not prev

    return ret if (first == prev and second == now) else []

for first in [True, False]:
    for second in [True, False]:
        ans = isOk(first, second)
        if ans:
            print(''.join(['S' if a else 'W' for a in ans[:-1]]))
            exit()

print('-1')


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  map<int, map<string, int>> table;
  // map<int, int> table;
  for(int i=0; i<M; i++){
    int tmp;
    cin >> tmp;
    string res;
    cin >> res;
    if(table[tmp]["AC"] > 0){
    }else{
      table[tmp][res] += 1;
    }
  }

  int ans1 = 0;
  int ans2 = 0;
  for(int i=1; i<=N; i++){
    if(table[i]["AC"] > 0){
      ans1 += table[i]["AC"];
      ans2 += table[i]["WA"];
    }
  }

  cout << ans1 << ' ' << ans2 << endl;
  return 0;
}


Measured memory_bytes: 31488
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000
 
int main() {
    unsigned short *A, *B;
 
    int C[VMAX + 1];
    int n, i, j;
    scanf("%d", &n);
 
    A = (unsigned short *)malloc(sizeof(short)*n + 1);
    B = (unsigned short *)malloc(sizeof(short)*n + 1);
 
    for (i = 0; i <= VMAX; i++)C[i] = 0;
 
    for (i = 0; i < n; i++) {
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;
    }
 
    for (i = 1; i <= VMAX; i++)C[i] = C[i] + C[i - 1];
 
    for (j = 1; j <= n; j++) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
 
    for (i = 1; i <= n; i++) {
        if (i > 1)printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");
 
    return 0;
}

Measured memory_bytes: 9684
n, y = gets.strip.split.map(&:to_i)
_i, _j, _k = -1, -1, -1

(0..n).each do |i|
    (0..n-i).each do |j|
       if i * 10000 + j * 5000 + (n - i - j) * 1000 == y
           _i, _j, _k = i, j, n - i - j
       end
    end
end

puts "#{_i} #{_j} #{_k}"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];

	int mx = v[0];
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		if (v[i] < mx) ans += mx - v[i];
		mx = max(mx, v[i]);
	}
	cout << ans << '\n';
	return 0;
}


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


int main () {
    int n ;
    cin >> n ;
    vector<string> vec(n);
    rep(i, n){
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    map<string,int> maps ;
    rep(i, n){
        if(maps.count(vec[i])){
            maps.at(vec[i])++ ;
        }
        else {
            maps[vec.at(i)] = 1;
        }
    }
    int max_num = 0 ;
    vector<string> ans ;
    for(auto p :maps){
        auto t = p.first;
        auto k = p.second;
        if(max_num < k){
            max_num = k ;
            ans.clear();
            ans.shrink_to_fit();
            ans.push_back(t);
        }
        else if(max_num == k){
            ans.push_back(t);
        }
        else {
            continue;
        }

    }
    sort(ans.begin(), ans.end());
    rep(i, ans.size()){
        cout << ans.at(i) << endl;
    }
}

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

 
int main()
{
    int N;
    int A1[101]={};
    int A1l[101]={};
    int A1r[101]={};
    int A2[101]={};
    int A2l[101]={};
    int A2r[101]={};
  
    int i=0;
    int j=0;
//    int k=0;
    int max=0;
    int max_ans=0;
  
 // 整数の入力
    scanf("%d", &N);
//    scanf("%d", &A1[0]);
//    A1l[0]=A1[0];
  
   for(i=0;i<=N-1;i++){
    scanf("%d", &A1[i]);
//     A1l[i]=A1l[i-1]+A1[i];
   }
  
//    scanf("%d", &A2[0]);
//    A2l[0]=A2[0];

  for(i=0;i<=N-1;i++){
    scanf("%d", &A2[i]);
//     A2l[i]=A2l[i-1]+A2[i];
   }
 
  
   for(i=0;i<=N-1;i++){
     max=0;
     for(j=0;j<=N;j++){
       if(j<i){ max=max+A1[j];}
       else if(j==i){ max=max+A1[j]+A2[j];}
       else  {max=max+A2[j]; }
     //    printf("%d %d %d\n",i,j, max);
     }
     if(max_ans<max) max_ans=max;
   }
 
  printf("%d\n",max_ans);

return 0;
}


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

int main(void) {

	double error; //??????
	int D ,E; //??\???
	int x ,y; //??????????????§?¨?
	int k; //???????????¨
	int i=0; //??????????´???¨??????????????°
    double cost; //?????¨
    double A[100]; //??????????´???¨??????

    for(;;) {

    	error=1000000;

	scanf("%d %d",&D,&E);

	if(D==0&&E==0) break;

	for(y=D;y>=0;y--) {
		for(x=0;x<=D;x++){

			if(x+y==D) { //??§?¨?????????¶??????????????¨???

			cost = sqrt(x*x+y*y); //?????¨?????\???

			if(fabs(cost-E)<error) //?????¨??¨?????????????????¢???????????????????°????????????°??´??°
				error = fabs(cost-E);
		}
	}
	}
	A[i]=error;
	i++;
 }

    for(k=0;k<i;k++)
    	printf("%f\n",A[k]);

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    long long n,min,max,sum=0,a;
    cin>>n;
    cin>>max;
    min=max;
    sum=max;
    for (int i=0;i<n-1;i++){
        cin>>a;
        sum+=a;
        if (a>max)
            max=a;
        if (a<min)
            min=a;
    }
    cout<<min<<" "<<max<<' '<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

map<Int, Int> m;

Int f(Int h){
	if(h == 1) return m[h] = 1;
	else return m[h] = f(h/2) * 2 + 1;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int h; cin >> h;
	cout << f(h) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string stones;
	cin >> stones;

	int min_colored = 0;
	for (int i = 0; i < n; ++i) {
		if (stones[i] == '#') {
			int black = 0, white = 0;
			for (int j = i; j < n; ++j) {
				if (stones[j] == '#') {
					++black;
				} else {
					++white;
				}
			} 

			min_colored = INT_MAX;
			int black_on_the_left = 0, white_on_the_right = white;
			for (int j = i; j < n; ++j) {
				if (stones[j] == '#') {
					min_colored = min(min_colored, white_on_the_right + black_on_the_left);
					++black_on_the_left;
				} else {
					--white_on_the_right;
				}
			}

			min_colored = min(min_colored, white_on_the_right + black_on_the_left);

			break;
		}
 	}

 	cout << min_colored << "\n";

	return 0;

}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 105
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rev(a,n) reverse(a,a+n)
using namespace std;
ll x,y,ans=1; 
int main() {
	cin>>x>>y;
	while(x*2<=y){
		ans++;
		x*=2;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int X, A;
    cin >> X >> A;

    if (X < A)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 10 << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){
	std::string temp;
	std::string blue[100];
	std::string red[100];
	int ans=0;
	int val[100];
	int n,m;
	std::cin>>n;
	for(int i=0;i<100;i++){
		val[i]=0;
	}
	for(int i=0;i<n;i++){
		std::cin>>blue[i];
	}
	std::cin>>m;
	for(int i=0;i<m;i++){
		std::cin>>red[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(blue[j]==blue[i])
				val[i]++;
		}
		for(int k=0;k<m;k++){
			if(red[k]==blue[i])
				val[i]--;
		}
	}
	for(int i=0;i<n;i++){
		if(ans<val[i])ans=val[i];
	}
	std::cout<<ans<<"\n";
}

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

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long max = a * c;
    if((a*d) > max) {
        max = a * d;
    }
    if((b*c) > max) {
        max = b * c;
    }
    if((b*d) > max) {
        max = b * d;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  ll r = 0, b = 0, g = 0;
  rep(i,n) {
    if (s[i] == 'R') r++;
    if(s[i]=='G') g++;
    if(s[i]=='B') b++;  }
  ll ans = r * g * b;
  rep(j,n){
    for(int i=0; i<j; i++){
      int k = 2 * j - i;
      if(k < n && s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]){
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int MAX = 1000;
int top, stack[MAX];

void initialize() {
	top = 0;
}

void push(int num) {
	stack[++top] = num;
}

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

int main() {
	string str;
	int a, b;
	
	initialize();

	while (cin >> str) {
		//cout << str << endl;
		if (str == "+") {
			a = pop();
			b = pop();
			//cout << a + b << ' ' << endl << endl;
			push(a + b);
		}
		else if(str == "-") {
			a = pop();
			b = pop();
			//cout << b - a << ' ' << endl << endl;
			push(b - a);
		}
		else if (str == "*") {
			a = pop();
			b = pop();
			//cout << a * b << ' ' << endl << endl;
			push(a * b);
		}
		else {
			push(stoi(str));
		}
	}

	cout << pop() << endl;
}

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

int main(){
    int n;
    long long sum = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }

    for (int i = 1; i < n; i++){
        if (a[i - 1] > a[i]){
            sum += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 4416
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 300001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;

int main() {
    int n; cin >> n;
    vector<int> sum(n), diff(n);
    loop0(i, n){
        int x, y; cin >> x >> y;
        sum[i] = x + y;
        diff[i] = x - y;
    }
    int mx1 = -INF, mx2 = -INF;
    int mn1 = INF, mn2 = INF, ans = -INF;
    loop0(i, n){
        mx1 = max(mx1, sum[i]);
        mx2 = max(mx2, diff[i]);
        mn1 = min(mn1, sum[i]);
        mn2 = min(mn2, diff[i]);
        ans = max({ans, mx1 - mn1, mx2 - mn2});
    }
    cout << ans << endl;
}

Measured memory_bytes: 4356
#include <iostream>
#include <climits>
#include <memory.h>
using namespace std;
const int MAXN = 2000 + 10;
int nums[MAXN*2], tree[MAXN*2];
int costw[MAXN][MAXN], costb[MAXN][MAXN], dp[MAXN][MAXN];
int lowbit(int i) {
    return i&(-i);
}
void add (int i) {
    int n = MAXN*2;
    while (i < n) {
        tree[i]++;
        i += lowbit(i);
    }
}
int query (int i) {
    int ret = 0;
    while (i > 0) {
        ret += tree[i];
        i -= lowbit(i);
    }
    return ret;
}
int query (int i, int j) {
    if (i > j) return 0;
    if (i == 0) return query(j);
    return query(j) - query(i-1);
}

void solve(int i, int j) {
    if (dp[i][j] != -1) return;
    int val = INT_MAX;
    if (i > 0) {
        solve(i-1, j);
        val = min(val, dp[i-1][j] + costw[i][j]);
    }
    if (j > 0) {
        solve(i, j-1);
        val = min(val, dp[i][j-1]+ costb[i][j]);
    }
    dp[i][j] = val;
}


int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    char c;
    for (int i = 1; i <= 2*n; i++) {
        cin >> c >> nums[i];
        if (c == 'B') nums[i] += 2000;
    }
    for (int i = 0; i <= n; i++) {
        memset(tree, 0, sizeof(tree));
        for (int j = 1; j <= 2*n; j++) {
            add(nums[j]);
            if (nums[j] > 2000) {
                costb[i][nums[j]-2000] = query(nums[j]+1, 2000 + n);
                costb[i][nums[j]-2000] += query(i+1, 2000);
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        memset(tree, 0, sizeof(tree));
        for (int j = 1; j <= 2*n; j++) {
            add(nums[j]);
            if (nums[j] <= 2000) {
                costw[nums[j]][i] = query(nums[j]+1, 2000);
                costw[nums[j]][i] += query(2000+i+1, 2000+n);
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            solve(i, j);
        }
    }
    cout << dp[n][n] << endl;
    return 0;
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll x = n / (a+b);
    ll y = x * (a+b);
    ll ans = x * a;
    if (n-y>a) {
        ans += a;
    } else {
        ans += n-y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   int a[N];
   int ans = 0;
   for (int i = 0; i < N; i++)
   {
      cin >> a[i];
      if(i%2==0&&a[i]%2==1) ans++;
   }
   cout << ans << endl;
   
   return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<cstdio>
#include<queue>
#include<algorithm>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX_V 10100
#define MAX_E 101000
using namespace std;

struct P
{
  int to,cost;
  P(int to=inf,int cost=inf):to(to),cost(cost){}
  bool operator < (const P &a)const
  {
    return cost > a.cost;
  }
};

int V,E;
vector<P> G[MAX_V];
bool used[MAX_V];
int mincost[MAX_V];

int prim()
{
  rep(i,V)used[i] = false,mincost[i] = inf;
  mincost[0] = 0;

  priority_queue<P> Q;
  Q.push(P(0,0));

  int ans = 0;
  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      int cur = p.to;

      if(used[cur])continue;
      used[cur] = true;

      if(mincost[cur] < p.cost)continue;

      ans += p.cost;

      for(int i=0;i<G[cur].size();i++)
	{
	  int next = G[cur][i].to;
	  if(used[next])continue;
	  if(mincost[next] > G[cur][i].cost)
	    {
	      mincost[next] = G[cur][i].cost;
	      Q.push(P(next,mincost[next]));
	    }
	}
    }
  return ans;
}

int main()
{
  while(cin >> V,V)
    {
      rep(i,V)G[i].clear();
      cin >> E;
      rep(i,E)
	{
	  int from,to,w;
	  //cin >> from >> to >> w;
	  scanf("%d,%d,%d",&from,&to,&w);
	  G[from].push_back(P(to,w));
	  G[to].push_back(P(from,w));
	}
      
      cout << prim()/100 - (V-1) << endl;
      
    }
  return 0;
}

Measured memory_bytes: 1604
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    cout << N * (N + 1) / 2 << endl;
}

Measured memory_bytes: 3596
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return 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 degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll n;
int main()
{
	FAST
	cin>>n;
	FOR(i,1,n) {
		FOR(j,i+1,n){
			cout<<(__builtin_ctz((i-1)^(j-1))+1)<<' ';
		}
		cout<<'\n';
	}
}


Measured memory_bytes: 512
sa = input()
sb = input()
sc = input()
lena = len(sa)
lenb = len(sb)
lenc = len(sc)
ans = 0
tmp = 'a'
while (lena != -1) and (lenb != -1) and (lenc != -1):
    if tmp == 'a':
        if lena == 0:
            ans = 'A'
            break
        tmp = sa[len(sa)-lena]
        lena -= 1

    elif tmp == 'b':
        if lenb == 0:
            ans = 'B'
            break
        tmp = sb[len(sb)-lenb]
        lenb -= 1
        
    elif tmp == 'c':
        if lenc == 0:
            ans = 'C'
            break
        tmp = sc[len(sc)-lenc]
        lenc -= 1
        
print(ans)

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

using namespace std;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int count=0;
    for(int i=min(a,b);i>0;i--){
        if(a%i==0 && b%i==0) count++;
        
        if(count==k){
            cout<<i<<endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int W, a, b;
 
int main (){
	cin >> W >> a >> b;
	if(a+W<b){
		cout << b-(a+W) << endl;
	}
	else if(b+W<a){
		cout << a-(b+W) << endl;
	}
	else {
		cout << 0 << endl;
	}
}
//D

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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code
	int n;
	vector<int> v;
	int till=0;
	cin >> n;
	ll ans =0;
	forn(i,n){
		int a;
		cin >> a;
		ans+=a-1;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int ret = 0;
  int cnt = 0;
  for (int i=0; i<S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
      cnt++;
    } else {
      ret = max(ret, cnt);
      cnt = 0;
    }
  }
  ret = max(ret, cnt);
  cout << ret << endl;
}

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

int main() {
    ll N, Q; cin >> N >> Q;
    string s; cin >> s;
    ll l[Q], r[Q];rep(i,Q)cin >> l[i] >> r[i];
    ll count[N];rep(i,N-1)count[i]=0;
    rep(i,N-1){
        if(s[i]=='A'&&s[i+1]=='C'){
            count[i+1] = count[i] + 1;
            }
        else count[i+1] = count[i];
        }
    rep(i,Q){    
        cout << count[r[i]-1]-count[l[i]-1] << endl;
    }
}

Measured memory_bytes: 3456
#include <iostream>
#include <time.h>

int main(){
    clock_t start = clock();
    int x;
    int n, q;

    std::cin >> n;
    int S[n];
    for(int i=0; i<n; i++){
        std::cin >> x;
        S[i] = x;
    }
    
    std::cin >> q;
    int T[q];
    for(int i=0; i<q; i++){
        std::cin >> x;
        T[i] = x;
    }

    int cnt = 0;
    int left;
    int right;
    int center;
    int flag;
    for(int i=0; i<q; i++){
        left = 0;
        right = n-1;
        center = (left + right) / 2;
        if(S[left] == T[i] || S[right] == T[i] || S[center] == T[i]){
            cnt += 1;
        }
        else{
            while(S[center] != T[i]){
                flag = 1;
                //std::cout << "left:" << left << " center:" << center << " right:" << right << '\n';
                if(T[i] < S[center]){
                    //leftは変化なし
                    right = center;
                    center = (left + right) / 2;
                }
                else{
                    left = center;
                    //rightは変化なし
                    center = (left + right) / 2;
                }
                if(S[center] == T[i]){
                    break;
                }
                if(center == left){
                    flag = 0;
                    break;
                } 
            }
            if(flag){
                cnt += 1;
            }
        }
    }

    std::cout << cnt << '\n';
    clock_t end = clock();
    //std::cout << "Time of calculation:" << (double)(end-start)/CLOCKS_PER_SEC << ".sec\n";

    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>

#define EPS (1e-9)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P ,pair<int,int> > CP;

namespace std{
  bool operator<(const P &a,const P &b){
    return real(a)==real(b)?imag(a)<imag(b):real(a)<real(b);
  }
}

//for vector
double dot(P x,P y){return real(conj(x)*y);}

double cross(P x,P y){return imag(conj(x)*y);}

//for line(segment)
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

P seg_cp(L a,L b){
  double d = abs(cross(b.sc-b.fs,a.fs-b.fs));
  return a.fs + ( d /(d + abs(cross(b.sc-b.fs,a.sc-b.fs))) ) * (a.sc-a.fs);
}

int main(){
  int t,n;
  int xa,ya,xb,yb;
  int xs[110],ys[110],xt[110],yt[110],o[110],l[110];

  cin >> t;

  while(t--){
    cin >> xa >> ya >> xb >> yb;
    cin >> n;
    for(int i=0;i<n;i++)cin >> xs[i] >> ys[i] >> xt[i] >> yt[i] >> o[i] >> l[i];
   
    vector<CP> cp;
    L nl = L(P(xa,ya),P(xb,yb));
    for(int i=0;i<n;i++){
      L tmpl = L(P(xs[i],ys[i]),P(xt[i],yt[i]));
      if( is_cp(nl,tmpl) )cp.push_back(CP(seg_cp(nl,tmpl),make_pair(o[i],l[i])));
    }
    sort(cp.begin(),cp.end());
    
    int ans = 0;
    for(int i=1;i<(int)cp.size();i++){
      if( (cp[i-1].sc.fs==cp[i].sc.fs)^(cp[i-1].sc.sc==cp[i].sc.sc) )ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 944
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <string>
#include <functional>
#include <map>
#include <cstring>
using namespace std;

using ii = pair < int , int >;
using ti = tuple < int ,int ,int >;
using lint = long long;
using ll = pair < lint , lint >;
const int N = 3*1e5 + 4;
int a[N],b[N],d[N];
vector < ii > ad[N];
int n,m;
bool v1[N],v2[N];

int ro[N];
vector < int > o;
bool ok = true;
void go(int n){
	v1[n] = true;
	for(auto p:ad[n]){
		int next = p.first;
		int w = p.second;
		if(!v1[next]){
			go(next);
		}
		else if(v1[next] && !v2[next]){
			ok = false;
		}
	}
	ro[n] = o.size();
	o.push_back(n);
	v2[n] = true;
}

int d2[N];
bool v3[N];

bool solve(){
	for(int i=1;i<=n;i++){
		if(!v1[i]){
			go(i);
		}
	}
	if(!ok)return false;
	reverse(o.begin(),o.end());
	for(int i=1;i<=n;i++){
		ro[i] = n - 1 - ro[i];
	}
	v3[0] = true;
	d2[0] = 0;
	for(int i=0;i<n;i++){
		int now = o[i];
		for(int j=0;j<ad[o[i]].size();j++){
			int next = ad[now][j].first;
			int we = ad[now][j].second;
			if(!v3[next]){
				d2[ro[next]] = d2[i] + we;
				v3[next] = true;
			}
			else{
				if(d2[i]+we!=d2[ro[next]]){
					return false;
				}
			}
		}
	}
	return true;
}

int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",a+i,b+i,d+i);
		ad[a[i]].push_back(ii(b[i],d[i]));
	}
	if(solve()){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 19960
from itertools import product

N, M = map(int, input().split())
x, y, z = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# 綺麗さの和、おいしさの和、人気度の和の符号を決め打ちしたときの最大値を貪欲法により求める
# 解はそれらの最大値である
ans = max(
    sum(
        abs(sum(t[i] for t in ts))
        for i in range(3)
    )
    for ts in (
        sorted(
            zip(x, y, z),
            key=lambda t: sum(map(lambda st: st[0] * st[1], zip(s, t))),
            reverse=True
        )[:M]
        for s in product((1, -1), repeat=3)
    )
)

print(ans)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;

void solve()
{
  int n;
  cin >> n;
  cout << n*800 - n/15*200 << endl;
}

int main(){cin.tie(0);ios_base::sync_with_stdio(false);solve();return 0;}


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

int k;
int f(int n)
{
	if(n%k==0)return n/k;
	int d=n/k+1;
	return f( n-d*((n%k-1)/d+1)  );
}

int main()
{
	//freopen("1.in","r",stdin);
	int ans=0;
	int n;
	cin>>n;
	while(n--)
	{
		int a;
		cin>>a>>k;
		ans^=f(a);
	}
	if(ans)puts("Takahashi");
	else puts("Aoki");	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    // Your code here!
    char s[101],t[101];
    int n, flag = 0,temp;
    scanf("%s",s);
    scanf("%s",t);
    n = strlen(s);
    
    for(int start = 0; start < n && flag == 0; start++)
    {
        flag = 1;
        for(int i = 0; i < n; i++)
        {
            temp = (start+i < n)?  start+i: start+i-n;
            //printf("%d %c %c\n",temp,s[temp], t[i]);
            if(s[temp] != t[i])
            {
                flag = 0;
                break;
            }
        }
    }
    printf("%s\n", (flag == 1)? "Yes":"No");
}


Measured memory_bytes: 128
s = input().split()

seven = 0
five = 0

for i in range(3):
    if int(s[i]) == 5:
        five += 1
    if int(s[i]) == 7:
        seven += 1

if(five == 2 and seven == 1):
    print("Yes".upper())
else:
    print("No".upper())


Measured memory_bytes: 2940