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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, m, l; cin >> n >> m >> l;){
        vector<double> p(n);
        vi t(n), v(n);
        rep(i, n){
            cin >> p[i] >> t[i] >> v[i];
            p[i] /= 100.0;
        }

        // [human][location][num_rest]
        vector<vector<vector<double>>> dp(n, vector<vector<double>>(m + 1, vector<double>(m + 1, 0.0)));
        rep(i, n) dp[i][0][0] = 1.0;
        rep(i, n){
            rep(j, m){
                rep(k, m){
                    dp[i][j + 1][k + 1] += dp[i][j][k] * p[i];
                    dp[i][j + 1][k]     += dp[i][j][k] * (1.0 - p[i]);
                }
            }
        }

        // [human][num_rest]
        vector<vector<double>> sum_time(n, vector<double>(m + 1, (double)inf));
        rep(i, n){
            if(v[i] == 0) continue;
            rep(j, m + 1){
                sum_time[i][j] = (double)l / v[i] + (double)t[i] * j;
            }
        }

        vector<double> res(n, 0.0);
        rep(i, n){
            if(v[i] == 0) continue;
            rep(a, m + 1){
                double prov = dp[i][m][a];

                rep(j, n){
                    if(i == j) continue;
                    
                    double q = 0.0;
                    rep(b, m + 1){
                        if(sum_time[i][a] < sum_time[j][b]) q += dp[j][m][b];
                    }

                    prov *= q;
                }

                res[i] += prov;
            }
        }

        rep(i, n) printf("%.9f\n", res[i]);
    }

	return 0;
}

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



int main(){
    ll H,W;
    cin >> H >> W;
    map<char,int> mp;
    ll edge_4 = 0;
    ll edge_2 = 0;
    ll center = 0;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char tmp;
            cin >> tmp;
            mp[tmp]++;
            if(mp[tmp] % 4 == 0){
                mp[tmp] = 0;
                edge_4++;
            }
        }
    }

    for(int i = 0; i < 26; i++){
        if(mp['a' + i] == 2){
            edge_2++;
        }else if(mp['a' + i] == 1){
            center++;
        }
    }

    if(H % 2 == 0 && W % 2 == 0){
        if(edge_4 == (H * W) / 4){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    else if(H % 2 == 1 && W % 2 == 1){

        if(center == 1 && (H * W - (center + 2 * edge_2)) % 4 == 0 && edge_4 == (H * W - (center + 2 * edge_2)) / 4){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    else{
        if((H * W - (2 * edge_2)) % 4 == 0 && edge_4 == (H * W - (2 * edge_2)) / 4){
            if((H % 2 == 0 && 2 * edge_2 <= H) || (W % 2 == 0 && 2 * edge_2 <= W)){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
                
        }else{
            cout << "No" << endl;
        }
    }

}




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

public class Main {
	public void run() throws Exception {
		FastScanner file = new FastScanner();
		int N = file.nextInt();
		long[] h = new long[N + 1];
		long[] dp = new long[N + 1];
		for(int i = 1; i <= N; i++) h[i] = file.nextLong();
		dp[1] = 0;
		dp[2] = Math.abs(h[1]-h[2]);
		for(int i = 3; i <= N; i++) {
			dp[i] = Math.min(dp[i-2] + Math.abs(h[i] - h[i-2]), dp[i-1] + Math.abs(h[i] - h[i-1]));
		}
		System.out.println(dp[N]);
	}
	class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
}


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

using namespace std;


void solve(string S)
{
    int c0 = 0;
    for (auto &c: S) {
        if (c == '0') ++c0;
    }
    cout << 2 * min(c0, (int)S.size()-c0) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	int a,b;
	char op;
	cin>>a>>op>>b;
	cout<<(op=='+'?a+b:a-b)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int n,m;
    cin>>n>>m;
    int a[50],b[50];
    int count[50]={};
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        count[a[i]-1]++;
        count[b[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<count[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
using System.Text;
using System;

public class hello
{
    public static void Main()
    {
        var sb = new StringBuilder();
        var INF = " 1000000001";
        var INF2 = 1000000001;
        Console.ReadLine().Trim();
        string[] line = (Console.ReadLine().Trim() + INF).Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Console.ReadLine().Trim();
        line = (Console.ReadLine().Trim() + INF).Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var p = 0; var q = 0;
        while (true)
        {
            if (a[p] == INF2) break;
            else if (a[p] == b[q]) { p++; q++; }
            else if (a[p] < b[q]) { sb.Append(string.Format("{0}\n", a[p++])); }
            else q++;
        }
        Console.Write(sb);
    }
}


Measured memory_bytes: 51804
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] LR = ReadLineParseIntArray();
        int L = LR[0];
        int R = LR[1];
        int upper = Min(L + 2019, R);
        int min = int.MaxValue;
        for(int i = L; i < upper; i++)
        {
            for(int j = i + 1; j <= upper; j++)
            {
                min = Min(min, ((i % 2019) * (j % 2019)) % 2019);
            }
        }
        WriteLine(min);
    }
    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 13396
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
for i in range(N):
    if A[i]>=B[i]:
        cnt+=B[i]
        A[i]-=B[i]
    elif B[i]>=A[i]+A[i+1]:
        cnt+=A[i]+A[i+1]
        A[i]=0
        A[i+1]=0
    else:
        cnt+=B[i]
        A[i+1]-=B[i]-A[i]
print(cnt)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, P;
  cin >> A >> P;
  P += A * 3;
  COUT(P / 2);
  return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    from collections import Counter

    n = int(input())
    aa = list(map(int, input().split()))
    c = Counter(aa)

    all_sum = 0
    for value in c.values():
        all_sum += int(value*(value-1)/2)

    for a in aa:
        print(all_sum-c[a]+1)


Measured memory_bytes: 25920
#include <stdio.h>
 
int main(){
  int num,dig,sum; 
  int n;
  
  scanf("%d",&num);
 
  for(n = 0;n < 3;n++){
  	dig = num % 10;
  	sum += dig;
  	num /= 10;
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 200005;
const int Maxm = 20;

int n, x, y;
vector <int> neigh1[Maxn], neigh2[Maxn];
int L[Maxn], P[Maxn][Maxm];
int L2[Maxn];

void Traverse(int v)
{
    for (int i = 0; i < neigh2[v].size(); i++) {
        int u = neigh2[v][i];
        if (u == P[v][0]) continue;
        P[u][0] = v; L[u] = L[v] + 1;
        Traverse(u);
    }
}

void Traverse2(int v, int p = 0)
{
    for (int i = 0; i < neigh1[v].size(); i++) {
        int u = neigh1[v][i];
        if (u == p) continue;
        if (L2[v] + 1 < L[u]) {
            L2[u] = L2[v] + 1;
            Traverse2(u, v);
        }
    }
}

int getLCA(int a, int b)
{
    if (L[a] < L[b]) swap(a, b);
    for (int i = Maxm - 1; i >= 0; i--)
        if (L[a] - (1 << i) >= L[b])
            a = P[a][i];
    if (a == b) return a;
    for (int i = Maxm - 1; i >= 0; i--)
        if (P[a][i] != P[b][i])
            a = P[a][i], b = P[b][i];
    return P[a][0];
}

int getDist(int a, int b) { return L[a] + L[b] - 2 * L[getLCA(a, b)]; }

int main()
{
    scanf("%d %d %d", &n, &x, &y);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh1[a].push_back(b);
        neigh1[b].push_back(a);
    }
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh2[a].push_back(b);
        neigh2[b].push_back(a);
    }
    Traverse(y);
    for (int j = 1; j < Maxm; j++)
        for (int i = 1; i <= n; i++)
            P[i][j] = P[P[i][j - 1]][j - 1];
    fill(L2, L2 + Maxn, Maxn);
    L2[x] = 0;
    Traverse2(x);
    int res = 0;
    for (int i = 1; i <= n; i++)
        if (L2[i] < L[i]) {
            res = max(res, 2 * L[i]);
            for (int j = 0; j < neigh1[i].size(); j++) {
                int u = neigh1[i][j];
                if (getDist(i, u) > 2) { printf("-1\n"); return 0; }
            }
        }
    printf("%d\n", res);
    return 0;
}


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

int main()
{
    ll n,m,a,b,i,j,x,y,k,ans;

    while(scanf("%lld %lld %lld",&n,&k,&m)==3)
    {
        n = abs(n);
        x = n/m;
        if(x>=k)printf("%lld\n",n-m*k);
        else
        {
            ans = n-m*x;
            k-=x;

            if(k%2==0)
            {
                printf("%lld\n",ans);
            }
            else
            {
                printf("%lld\n",abs(ans-m));
            }
        }
    }










return 0;
}


Measured memory_bytes: 3828
M=10**6+1
_,*l=map(int,open(0).read().split())
b=[0]*M
for i in l: b[i]+=1
a=[]
for i in sorted(l):
  if b[i]:
    if b[i]==1: a+=[i]
    for j in range(i,M,i): b[j]=0
print(len(a))

Measured memory_bytes: 33208
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int pt[123456], n, m, ans;
vector<pair<int, pair<int, int>>>v;
void setup() {
	ans = 0; v.clear();
	for0 (i, n)pt[i] = i;
	return;
}
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
int main() {
	while (cin >> n >> m, n) {
		setup();
		for0(i, m) {
			int a, b, c; cin >> a >> b >> c;
			v.push_back(mp(c, mp(a, b)));
		}
		sort(all(v));
		for0(i, m) {
			int a = v[i].second.first, b = v[i].second.second, c = v[i].first;
			if (root(a) != root(b)) {
				unite(a, b);
				ans += c;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
struct node{
	int dh;
	int mg;
};
int main()
{
	int h,n,i,j;
	cin>>h>>n;
	struct node a[n+1];
	for(i=1;i<=n;i++)
	{
		cin>>a[i].dh;
		cin>>a[i].mg;
	}
	int dp[h+5];
	dp[0]=0;
	for(i=1;i<=h;i++)
	{
		dp[i]=100000000;
	}
	for(i=1;i<=n;i++) 
	{
        for(j=0;j<=h;j++) 
		{
			if(j-a[i].dh>0)
			{
				dp[j]=min(dp[j],dp[j-a[i].dh]+a[i].mg);
			}
			else
			{
				dp[j]=min(dp[j],a[i].mg);
			}
        }
    }
    cout<<dp[h]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include	<iostream>
#include	<cstdio>

using namespace std;

int main(void) {
	char f, t;
	int data[3] = {1, 0, 0};
	while(1) {
		int tmp;
		if( scanf("%c,%c", &f, &t) == EOF )		break;
		tmp = data[t - 'A'];
		data[t - 'A'] = data[f - 'A'];
		data[f - 'A'] = tmp;
	}
	if(data[0] == 1)		cout << 'A' << endl;
	else if(data[1] == 1)	cout << 'B' << endl;
	else					cout << 'C' << endl;
	return 0;
}

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

int main(){
    long long int n;
    cin >> n;
    int ans = INT_MAX;
    for(long long int a=1;a<=sqrt(n);++a){
        if(n%a == 0){
            long long int b = n / a;
            string sa = to_string(a), sb = to_string(b);
            ans = min(ans, max((int)sa.size(), (int)sb.size()));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
x = int(input())
a = 0
f = False
res = 0

#while True:
while f == False:
    for i in range(a+1):
        if (a ** 5) - (i ** 5) == x:
            f = True
            res = i
            break
        elif (a ** 5) - (-i ** 5) == x:
            f = True
            res = -i
            break    
    a += 1

print(str(a-1) + " " + str(res))
    

Measured memory_bytes: 9192
n = int(input())
a = input().split()

d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
for i in d:
    d[i] //= 2

ans = []
for i in d:
    ans += [int(i)] * int(d.get(i))
if len(ans) >= 2:
    ans.sort()
    print(ans[-1] * ans[-2])
else:
    print(0)


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

int main() {
   int n;
   cin >> n;
   int ans=1;
   while (ans * 2 <= n)
   ans *= 2;
   cout << ans << endl;
}

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

using namespace std;
using ll = long long int;

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

    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<char> r(n);

    vector<string> inp(n);
    for(auto &e: inp) cin >> e;
    bool ok = false;
    for(ll i=0; i<n; i++) {
        string s = inp[i];
        if(s == "AB") {
            if(a == 1 && b == 1) {
                if(i==n-1 || inp[i+1] == "BC")
                    b++, a--, r[i] = 'B';
                else
                    a++, b--, r[i] = 'A';
            continue;
            }

            ok |= a == 0 && b == 0;
            if(a <= b) a++, b--, r[i] = 'A';
            else a--, b++, r[i] = 'B';
        }else if(s == "AC") {
            if(a == 1 && c == 1) {
                if(i==n-1 || inp[i+1] == "AB")
                    a++, c--, r[i] = 'A';
                else
                    c++, a--, r[i] = 'C';
            continue;
            }
            ok |= a == 0 && c == 0;
            if(a <= c) a++, c--, r[i] = 'A';
            else a--, c++, r[i] = 'C';
        } else if(s == "BC") {
            if(b == 1 && c == 1) {
                if(i==n-1 || inp[i+1] == "AB")
                    b++, c--, r[i] = 'B';
                else
                    c++, b--, r[i] = 'C';
            continue;
            }
            ok |= b == 0 && c == 0;
            if(b <= c) b++, c--, r[i] = 'B';
            else b--, c++, r[i] = 'C';
        }
    }

    if(!ok) {
        cout << "Yes" << endl;
        for(auto &e: r) cout << e << endl;
    } else
        cout << "No" << endl;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n, m;
  cin >> n >> m;

  int k = 1;
  for (int i = 0; i < m; i++) {
    k *= 2;
  }

  int ans = (1900 * m + (n - m) * 100) * k;

  cout << ans << endl;

  return 0;
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    while (a>0 && k>0) {
        ans += 1;
        --k;
        --a;
    }
    while (b>0 && k>0) {
        ans +=0;
        --k;
        --b;
    }
    while (c>0 && k>0) {
        ans -= 1;
        --k;
        --c;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto d = readln.chomp.split.to!(int[]);
  immutable mod = 998244353;

  int[int] cnt;
  foreach (i; 0..n) {
    cnt[d[i]]++;
  }

  if (d[0] != 0 || cnt.get(0, 0) != 1) {
    writeln(0);
    return;
  }

  if (n == 1) {
    writeln(1);
    return;
  }

  long res = 1;
  auto m = cnt.keys.reduce!(max);
  auto pat = new long[](m+1);
  pat[0..2] = 1;
  foreach (i; 2..m+1) {
    auto num = cnt.get(i, 0);
    long tmp = cnt.get(i-1, 0);
    foreach (_; 1..num) {
      tmp = (tmp * cnt.get(i-1, 0)) % mod;
    }
    pat[i] = (pat[i-1] * tmp) % mod;
  }

  pat[$-1].writeln;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<string> words(N);
    for (int i = 0; i < N; i++)
    {
        cin >> words.at(i);
    }
    map<string, int> counts;
    char prev;
    for (int i = 0; i < N; i++)
    {
        if (counts[words.at(i)])
        {
            cout << "No" << endl;
            return 0;
        }
        if (i > 0 && prev != words.at(i).at(0))
        {
            cout << "No" << endl;
            return 0;
        }
        counts[words.at(i)]++;
        prev = words.at(i).at(words.at(i).size() - 1);
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

int main() {
    long long int N;
    cin >> N;
    
    vector<vector<long long int> > vec(10, vector<long long int>(10, 0));
    for(long long int i=1; i<=9; i++) {
        for(long long int j=1; j<=9; j++) {
            // cout << i << ", " << j << ": " << endl;
            long long int cnt=0;
            if(i==j && i<=N) cnt++;
            long long int tmp=0;
            long long int pow=10;
            long long int cur=pow*i+j;
            while(cur<=N) {
                // cout << "comp" << cur << " and " << N << endl;
                if(tmp>0) {
                    long long int k=1;
                    for(int l=0; l<tmp-1; l++) {
                        k*=10;
                    }
                    cnt += k;
                }
                tmp++;
                pow *= 10;
                cur = pow*i+j;
            }
            // cout << "comp " << cur << " and " << N << endl;
            // cout << "current tmp = " << tmp << endl;

            if(tmp==1) {
                cnt++;
            } else if(tmp>1) {
                cur = pow/10*i+j;
                long long int mx=1;
                for(int k=0; k<tmp-1; k++) {
                    mx*=10;
                }
                mx--;
                for(long long int l=0; l<=mx; l++) {
                    if(l*10+cur<=N) cnt++;
                }
            }
            // cout << "cnt = " << cnt << endl;
            vec[i][j] = cnt;
        }
    }
    // for(int i=1; i<=9; i++) {
    //     for(int j=1; j<=9; j++) {
    //         cout << vec[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    long long int ans=0;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=i; j++) {
            if(i==j) {
                ans += vec[i][j]*vec[i][j];
            } else {
                ans += 2*vec[i][j]*vec[j][i];
            }
        }
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a,ans,T;
inline bool check(ll x,ll k)
{
    ll cnt=1;
    for(int i=0;i<=k;i++){
        cnt*=x;
        if(cnt>=n) return 1;
    }
    return 0;
}
int main()
{
    while(cin>>n>>a){
        ans=n;
        for(int i=1;i<=40;i++){
            ll l=1,r=(ll)1e9+1;
            while(l+1<r){
                ll mid=(l+r)>>1;
                if(check(mid,i)) r=mid;
                else l=mid;
            }
            ll u=1,x=a*i;
            for(int j=0;j<=i;j++) u*=(l);
            x+=(i+1)*(l);
            for(int j=0;j<=i;j++){
                u/=(l); u*=r;
                x++;
                if(u>=n) break;
            }
            ans=min(ans,x);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        
        for (int i=1; i<n; i++){
            String str1 = s.substring(0,i);
            String str2 = s.substring(i);
            int count = 0;
            int[] flg1 = new int[26];
            int[] flg2 = new int[26];
            
            for (int j=0; j<str1.length(); j++){
                flg1[str1.charAt(j)-'a']=1;
            }
            for (int j=0; j<str2.length(); j++){
                flg2[str2.charAt(j)-'a']=1;
            }
            for (int j=0; j<26; j++){
                if (flg1[j]==1 && flg2[j]==1){
                  count++;
                }
            }
            
            ans = Math.max(ans,count);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 35648
#include <stdio.h>

int main(void){
    int n,i,j;
    float x[4], y[4];
    double ab, cd;
    
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        for(j=0; j<4; j++)
            scanf("%f%f", &x[j], &y[j]);
        ab = (y[1]-y[0]) / (x[1]-x[0]);
        cd = (y[3]-y[2]) / (x[3]-x[2]);
        if(ab == cd) printf("YES\n");	//傾きが等しければ平行
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int odd = 0;
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] % 2) odd++;
    }   
    if(odd % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1024
/*input

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

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}


void solve(){
	int a,b;cin >> a >> b;
	if(b%a == 0)cout << a+b;
	else cout << b-a;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
a = []
for i in range(len(S)):
  if S[i] == 'R':
    a.append(0)
  elif S[i] == 'G':
    a.append(1)
  elif S[i] == 'B':
    a.append(2)
    
cnt = [0] * 3
for i in range(N):
  cnt[a[i]] += 1
ans = cnt[0] * cnt[1] * cnt[2]

for j in range(N):
  for i in range(j):
    k = j + (j - i)
    if k < N:
      if a[i] == a[j]:
        continue
      if a[i] == a[k]:
        continue
      if a[k] == a[j]:
        continue
      ans -= 1
      
print(ans)

Measured memory_bytes: 9256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];

    int mn = INF;
    for (int i =0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        mn = min(mn, a[x] + b[y] - c);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    mn = min(mn, a[0] + b[0]);

    cout << mn << endl;

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  while(n>0){
    if(n%10==7){
      cout<<"Yes"<<endl;
      return 0;
    }
    n/=10;
  }
  
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3644
import Data.Char

main :: IO ()
main = interact $ unlines . map (\(c,n) -> [c] ++ " : " ++ show n) . counts ['a'..'z'] . map toLower

counts :: Eq a => [a] -> [a] -> [(a, Int)]
counts xs ys = map (\x -> (x, count x ys)) xs

count :: Eq a => a -> [a] -> Int
count x = length . filter (== x)


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n, cap;
  cin >> n >> cap;
  vector <LL> w (n + 1);
  vector <LL> v (n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> w[i] >> v[i];
  }
  vector <vector <LL> > dp (n + 5, vector <LL> (cap + 5, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= cap; j++) {
      dp[i][j] = dp[i - 1][j];
      if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
    }
  }
  cout << dp[n][cap] << endl;
  return 0;
}


Measured memory_bytes: 83328
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  vector<int> water;
  vector<int> sugar;
  REP(i, F / (100 * A) + 1) {
    REP(j, F / (100 * B) + 1) {
      int w = 100 * A * i + 100 * B * j;
      if(w <= F) {
        water.push_back(w);
      }
    }
  }
  REP(i, F / C + 1) {
    REP(j, F / D + 1) {
      int s = C * i + D * j;
      if(s <= F) {
        sugar.push_back(s);
      }
    }
  }
  double ans_c = -1;
  int ans_w, ans_s;
  REP(i, water.size()) {
    REP(j, sugar.size()) {
      if(water[i] + sugar[j] > F) continue;
      if(sugar[j] > water[i] / 100 * E) continue;
      double c = (100.0 * sugar[j]) / (water[i] + sugar[j]);
      if(c > ans_c) {
        ans_c = c;
        ans_w = water[i];
        ans_s = sugar[j];
      }
    }
  }
  cout << ans_w + ans_s << " " << ans_s << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;


bool used[30];

int main() {

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		deque<char> que;

		char fr = s[0];
		char bk = s[0];

		que.push_back(s[0]);
		used[s[0] - 'a'] = 1;
		for (int i = 0; i < s.size(); i += 3)
		{
			if (i == 0)
			{
				continue;
			}
			if (s[i - 1] == '>')
			{
				if (used[s[i] - 'a'] == 0)
				{
					que.push_back(s[i]);
					used[s[i] - 'a'] = 1;
				}
				bk = s[i];
				
			}
			else
			{
				if (used[s[i] - 'a'] == 0)
				{
					que.push_front(s[i]);
					used[s[i] - 'a'] = 1;
				}
				fr = s[i];
			}
		}

		int cnt = 0;
		for (auto itr : que)
		{
			if (cnt == 0)
			{
				cout << itr;
			}
		}
		cout << endl;

		for (int i = 0; i < 30; i++)
		{
			used[i] = 0;
		}
		que.clear();
	}

	return 0;
}


Measured memory_bytes: 3092
N,A,B = map(int,input().split(' '))

if (B - A)%2 == 0:
    print((B - A)//2)
else:
    if A-1 < N-B:
        reach_min = A
        b_num = B - A
        num_second = (b_num-1)//2
        print(reach_min+num_second)
    else:
        reach_min = N - B + 1
        b_num = A + reach_min
        num_second = (N-b_num)//2
        print(reach_min+num_second)
    

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

typedef long long LL;

using namespace std;

array<LL, 2> find_alphas(LL a, LL b) {
	if (b == 0)
		return {1, 0};
	auto result = find_alphas(b, a % b);
	LL k = a / b;
	return {result[1], (result[0] - result[1] * k)};
}

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

LL solve_test(LL n) {
	n *= 2;

	LL min_k = n - 1;
	for (LL i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			LL n1 = i;
			LL n2 = n / i;
			if (gcd(n1, n2) == 1) {
				auto alphas = find_alphas(n1, n2);
				LL k;
				if (alphas[0] < 0)
					k = -alphas[0] * n1;
				else
					k = -alphas[1] * n2;
				min_k = min(min_k, k);
			}
		}
	}

	return min_k;
}

int random_test() {
	return rand();
}

bool check_solution(LL n, LL k) {
	if (k * (k + 1) / 2 % n == 0)
		return true;
	return false;
}

int main() {
	LL n;
	cin >> n;
	cout << solve_test(n) << '\n';

	return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
//#pragma GCC optimize("Ofast")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#define mp make_pair
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937_64 gen(time(NULL));
ll const maxn = 1e5 + 4;
ll dp[maxn];
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	vector<ll>h(1 + n);
	for (ll i = 1; i <= n; i++) {
		cin >> h[i];
	}
	for (ll i = 0; i < maxn; i++) dp[i] = 1e9;
	dp[1] = 0;
	for (ll i = 2; i <= n; i++) {
		dp[i] = min(dp[i], dp[i - 1] + abs(h[i]-h[i-1]));
		if (i == 2)continue;
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n] << endl;
	return 0;
}
/*
7 27 2	
9 1 1 27 3 27 3

7 60 4
30 1 1 3 10 6 4
*/

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

#define A 200000

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ib - ia;
}

int main() {
	static int kk[A + 1];
	int n, k, a, ans;

	scanf("%d%d", &n, &k);
	while (n--) {
		scanf("%d", &a);
		kk[a]++;
	}
	qsort(kk, A + 1, sizeof *kk, compare);
	ans = 0;
	for (a = k; a <= A; a++)
		ans += kk[a];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

long getOpen(long b) {
  long ret = 0;
  rep (i, b) {
    long c;
    cin >> c;
    ret += 1 << c;
  }
  return ret;
}

void solve() {
  long N, M;
  cin >> N >> M;

  long full = 0;
  for (long i = 1; i <= N; i++) {
    full += 1 << i;
  }

  map<long, long> mp;
  mp[0] = 0;

  rep (i, M) {
    long a, b;
    cin >> a >> b;
    long open = getOpen(b);
    for (auto it: mp) {
      long merged_open = it.first | open;
      long merged_cost = it.second + a;
      if (mp.count(merged_open) == 0) mp[merged_open] = merged_cost;
      else mp[merged_open] = min(mp[merged_open], merged_cost);
    }
  }

  if (mp.count(full) == 0) cout << -1 << endl;
  else cout << mp[full] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
/*#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif
*/

using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vi arr(n);
    rep(i,0,n){
        cin>>arr[i];
    }
    ll c=0;
    stable_sort(arr.begin(),arr.end(),greater<int>());
    c+=arr[0];
    int k=n/2;
    int s=n%2;
    for(int i=1;i<k;++i){
        c+=1LL*2*arr[i];

    }
    if(s!=0)
    c+=arr[k];
    cout<<c<<endl;
}


Measured memory_bytes: 4520
n = int(input())
a = [0]
tmp = [int(input()) for _ in range(n)]
a = a + tmp

r = -1
cnt = 1
next = a[1]
while cnt < n:
  if next == 2:
    r = cnt
    break
  else:
    next = a[next]
    cnt += 1
print(r)

Measured memory_bytes: 7980
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const int BIG = 998244353;





int main() {

	int N;

	cin >> N;

	int a[300000];

	for(int i=1; i<=N; i++){
		cin >> a[i];
	}

	int b[300000] = {};//入れたボールの数

	int m = 0;


	for (int i = N; i >=1; i--) {

		int sum = 0;

		for (int j = i; j <= N; j = j + i) {
			sum += b[j];
		}

		sum %= 2;

		if (sum != a[i]) {
			b[i] = 1;
			m++;
		}

		
	}


	cout << m << endl;;
	for (int i = 1; i <= N; i++) {

		if (b[i] == 1) {
			cout << i << " ";
		}
	}

	system("PAUSE");
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char a;
	cin >> a;
	if (a >= 'A' && a <= 'Z') {
		cout << "A" << endl;
	} else {
		cout << "a" << endl;
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int main() {
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == ',')
            s[i] = ' ';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    string s;
    cin >> s;

    ll n = s.size();
    // dp[i][j] : i 文字目までで j 文字選択
    vvll dp(n + 1, vll(4));
    dp[0][0] = 1;
    REP(i, n){
        if(s[i] == '?'){
            REP(j, 4) dp[i + 1][j] = 3 * dp[i][j] % mod;
            REP(j, 3){
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %= mod;
            }
        }
        else{
            REP(j, 4) dp[i + 1][j] = dp[i][j] % mod;
            ll c = s[i] - 'A';
            dp[i + 1][c + 1] += dp[i][c];
            dp[i + 1][c + 1] %= mod;
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}

Measured memory_bytes: 7376
import heapq

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: -x, A))

heapq.heapify(A)
a = - heapq.heappop(A)
for i in range(N-1):
    b = - heapq.heappop(A)
    if a == b:
        x = a
        break
    else:
        a = b
else:
    x = 0

if len(A) >= 2:
    c = - heapq.heappop(A)
    for j in range(len(A)):
        d = - heapq.heappop(A)
        if c == d:
            y = c
            break
        else:
            c = d
    else:
        y = 0
else:
    y = 0

ans = x*y
print(ans)



Measured memory_bytes: 14380
#include<bits/stdc++.h>
using namespace std;
struct Dice{
    int lab[6];
    void in(){
        for(int i=0;i<6;i++){
            cin >> lab[i];
        }
    }
    void roll(char a){
        if(a=='S'){
            int stock;
            stock=lab[0];
            lab[0]=lab[4];
            lab[4]=lab[5];
            lab[5]=lab[1];
            lab[1]=stock;
        }
        if(a=='N'){
            int stock;
            stock=lab[0];
            lab[0]=lab[1];
            lab[1]=lab[5];
            lab[5]=lab[4];
            lab[4]=stock;
        }
        if(a=='W'){
            int stock;
            stock=lab[0];
            lab[0]=lab[2];
            lab[2]=lab[5];
            lab[5]=lab[3];
            lab[3]=stock;
        }
        if(a=='E'){
            int stock;
            stock=lab[0];
            lab[0]=lab[3];
            lab[3]=lab[5];
            lab[5]=lab[2];
            lab[2]=stock;
        }
        if(a=='R'){
            roll('N');roll('E');roll('S');
        }
        if(a=='L'){
            roll('N');roll('W');roll('S');
        }
    }
    
    int top(){
        return lab[0];
    }
    void right(int a,int b){
        int i;
        for(i=0;i<6;i++){
            if(lab[i]==a){
                break;
            }
        }
            
        if(i==1){
            roll('N');
        }
        if(i==2){
            roll('W');
        }
        if(i==3){
            roll('E');
        }
        if(i==4){
            roll('S');
        }
        if(i==5){
            roll('N');roll('N');
        }
            
        for(int j=1;j<5;j++){
            roll('L');
            
            if(lab[1]==b){
                break;
            }
        }
        return;
    }
};

int main() {
    Dice d;
    d.in();
    int a,b;
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> a >> b;
        d.right(a,b);
        cout << d.lab[2] << endl;
    }
}


Measured memory_bytes: 3068
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
# 入力の C は M とする
N,M = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(M)]
C = [list(map(int,input().split())) for _ in range(N)]

# X[x][y] : (i+j)%3 == x の, 初期状態での色が y(0-indexed) のマスの数
X = [[0 for _ in range(M)] for _ in range(3)]
for i in range(N):
    for j in range(N):
        x = (i+1 + j+1)%3
        y = C[i][j] - 1
        X[x][y] += 1

# Y[x][y] : (i+j)%3 == x の領域を y で塗る場合に必要なコスト
Y = [[0 for _ in range(M)] for _ in range(3)]
for i in range(3):
    for c_to in range(M):
        total = 0
        for c_from in range(M):
            total += X[i][c_from] * D[c_from][c_to]
        Y[i][c_to] = total

ans = 10**10
# 塗る色の組み合わせで全探索
for i in range(M):
    for j in range(M):
        for k in range(M):
            # 全ての色が異なる場合のみ考える
            if i != j and j != k and k != i:
                ans = min(ans, Y[0][i] +Y[1][j] + Y[2][k] )

print(ans)

Measured memory_bytes: 5620
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll N, x, y;
  cin >> N;
  vector<pair<pair<int, int>,ll > > h(N);

  rep(i, N){
    cin >> h[i].first.first >>  h[i].first.second >> h[i].second;
  }

  ll H, cnt = 0;
  map<ll, int> m;
  // i-jを答えとして全探索を行う
  rep(i, 101){ // X
    rep(j, 101) { // Y
      m.clear();
      cnt = 0;
      rep(k, N){ // 間違っていないかを確認する
        if(h[k].second == 0) continue;
        cnt++;
        H = abs(h[k].first.first - i) + abs(h[k].first.second - j) + h[k].second;
        if(m.find(H)==m.end()){
          m.insert(make_pair(H, 1));
        } else {
          m[H]++;
        }
      }
      
      if (m.size()==1 && cnt > 1){
        printf("%d %d %lld\n", i, j, H);
        return 0;
      }
    }
  }
  rep(i, N){
    if(h[i].second == 0) continue;
    printf("%d %d %lld\n", h[i].first.first, h[i].first.second, h[i].second);
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n >> m;
  ll cur = 0;
  rep(i, n) {
    cin >> tmp;
    if (cur <= m) ans++;
    cur += tmp;
  }
  if (cur <= m) ans++;
  cout << ans << endl;




  

  return 0;
}

Measured memory_bytes: 256