akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a;
    REP(i,n){
        if(s[i]=='B'){
            a.push_back(i);
        }
    }
    int m = a.size();
    int ans=0;
    n--;
    for(int i=m-1;i>=0;i--){
        ans += n - a[i];
        n--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2680
N = int(input())
n = 1
S = []
while n <= N:
    s = str(input())
    S.append(s)
    n += 1

print("AC x", S.count("AC"))
print("WA x", S.count("WA"))
print("TLE x", S.count("TLE"))
print("RE x", S.count("RE"))

Measured memory_bytes: 16176
#include <iostream>

using namespace std;

int n;
int v[10000];

int main(){
		
	while(cin>>n, n){
		
		for(int i=0; i<n; ++i){
			cin>>v[i];
		}

		int step = 0;

		for(int i=n; i>0; --i){
			for(int j=0; j<i-1; ++j){
				
				if(v[j] > v[j+1]){
					swap(v[j], v[j+1]);
					step++;
				}
			}
		}

		cout << step << endl;
	}

	return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    int _1 = n % 10;
    int _2 = (n % 100 - _1) / 10;
    int _3 = (n - _1 - _2 * 10) / 100;

    if ((_1 == 7) || (_2 == 7) || (_3 == 7))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

char s[8192];
int x, y;

int xCount;
int xParts[8192];
int yCount;
int yParts[8192];

int xSum, ySum;

int xGoal, yGoal;
char xReachable[8192], yReachable[8192];

int main(void) {
	int i;
	int is_x;
	int count;
	if (scanf("%8191s", s) != 1) return 1;
	if (scanf("%d%d", &x, &y) != 2) return 1;
	for (i = 0; s[i] != '\0' && s[i] != 'T'; i++) x--;
	if (x < 0) x = -x;
	if (y < 0) y = -y;
	count = 0;
	is_x = 1;
	for (; ; i++) {
		if (s[i] == 'F') {
			count++;
		} else {
			if (count > 0) {
				if (is_x) xParts[xCount++] = count; else yParts[yCount++] = count;
			}
			if (s[i] == '\0') break;
			count = 0;
			is_x = !is_x;
		}
	}
	for (i = 0; i < xCount; i++) xSum += xParts[i];
	for (i = 0; i < yCount; i++) ySum += yParts[i];
	if (xSum < x || ySum < y || (xSum - x) % 2 != 0 || (ySum - y) % 2 != 0) {
		puts("No");
		return 0;
	}
	xGoal = (xSum - x) / 2;
	yGoal = (ySum - y) / 2;
	xReachable[0] = yReachable[0] = 1;
	for (i = 0; i < xCount; i++) {
		int j;
		int max = xGoal - xParts[i];
		for (j = 0; j <= max; j++) {
			if (xReachable[j]) xReachable[j + xParts[i]] = 1;
		}
	}
	for (i = 0; i < yCount; i++) {
		int j;
		int max = yGoal - yParts[i];
		for (j = 0; j <= max; j++) {
			if (yReachable[j]) yReachable[j + yParts[i]] = 1;
		}
	}
	puts(xReachable[xGoal] && yReachable[yGoal] ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
require "prime"

arr = Array.new(1000) { 0 }

n = gets.chomp.to_i
cnt = 0
2.upto(n) do |is|
  Prime.prime_division(is).each do |i, pi|
    arr[i] += pi
  end
end

wp = 10**9+7

puts arr.reduce(1) { |a, i|
  next a if i.zero?
  a * (i+1) % wp
}

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{ 
  ll  ans;
  for( int i = 0 ;i<5;++i)
  {
    ll x;
     cin>>x;
     if(x == 0){ans = i+1; break;}
  }
  cout<< ans;

}

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

int main(){
  	int n, m;
  	cin >> n >> m;
  
  	int ans = n * (n - 1) / 2  + m * (m - 1) / 2;
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define mpp make_pair
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 100007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int MAXN = 1e6+1;
#define MAXI 2e18+3
#define all(v) v.begin(), v.end()
#define endl "\n"
# define PI 3.14159265358979323846

int h[200000];
bool cc[200000];


signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n, m, i, cnt=0;
    cin>>n>>m;
    memset(cc, true, sizeof(cc));
    for(i=1;i<=n;i++){
    	cin>>h[i];
    }
    while(m--){
    	int a, b;
    	cin>>a>>b;
    	if(h[a]<=h[b]){
    		cc[a]=false;
    	}
    	if(h[b]<=h[a]){
    		cc[b]=false;
    	}
    }
    for(i=1;i<=n;i++){
    	if(cc[i]==true)
    		cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 4632
#

import sys
input=sys.stdin.readline

def main():
    K=int(input())
    rsum=0
    r=7
    for i in range(10**6+1):
        rsum=(rsum+r)%K
        r=(r*10)%K
        if rsum==0:
            print(i+1)
            exit()
    print(-1)
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 63076
//Frog 1

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()
const int inf = 1000000000;

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
long long n,m=100;cin>>n;
int a=0;
  for(int i=0;i<100000;i++){
    if(m>=n)
        break;
    m+=m/100;
    a++;}
  cout<<a<<endl;
return 0;}


Measured memory_bytes: 3612
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(All(ret));
    return ret;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 0;
    rep(i, N) sum += A[i];
    vector<ll> divisors = divisor(sum);
    ll res = 1;
    for(ll d : divisors) {
        vector<ll> mods(N);
        vector<ll> inv(N);
        rep(i, N) { mods[i] = A[i] % d; }
        sort(All(mods));
        rep(i, N) { inv[i] = d - mods[i]; }

        vector<ll> rsum(N + 1), lsum(N + 1);
        rep(i, N) rsum[i + 1] = rsum[i] + mods[i];
        for(int i = N - 1; i >= 0; i--)
            lsum[i] = lsum[i + 1] + inv[i];
        for(int i = 0; i < N + 1; i++) {
            if(abs(rsum[i] - lsum[i]) % d == 0) {
                if(max(rsum[i], lsum[i]) <= K)
                    res = max(d, res);
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r || H<y+r || 0>x-r||0>y-r){
	cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
	
}

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

using namespace std;

typedef long long int64;

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

  string T = "";
  int del = 0;
  T += S.front();
  for(int i = 1; i < S.size() - 1; i++) {
    if(S.front() != S[i] && S.back() != S[i]) {
      ++del;
      continue;
    }
    T += S[i];
  }
  T += S.back();

  for(int i = 1; i < T.size(); i++) {
    if(T[i - 1] == T[i]) {
      --del;
    }
  }

  if(del % 2 == 1) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}

Measured memory_bytes: 512
#include<stdio.h>
 
#define N 10000
 
int n;
int M[N];
 
int MatrixChainOrder(void);
int Min(int , int );


int MatrixChainOrder(){
 
  int i, j, k, l, q;
  int R[n+1][n+1];
 
  for(i = 1;i <= n;i++){
    R[i][i] = 0;
  }
 
  for(l = 2;l <= n;l++){
    for(i = 1;i <= n - l + 1;i++){
 
      j = i + l - 1;
      R[i][j] = 67148;
 
      for(k = i;k <= j - 1;k++){
 
	q = R[i][k] + R[k+1][j] + M[i-1] * M[k] * M[j];
 
	R[i][j] = Min(R[i][j], q);
      }
    }
  }
 
  return R[1][n];
 
}
 

int Min(int x, int y){
 
  if(x > y){
    return y;
  }
 
  else{
    return x;
  }
 
}
 

main(){
 
  int i, j;
 
  scanf("%d",&n);
 
  for(i = 0;i < n;i++){
    scanf("%d%d",&M[2 * i],&M[2 * i + 1]);
  }
 
  for(i = 1;i < 2 * n;i++){
    if(M[i] == M[i + 1]) {
      for(j = i + 1;j < 2 * n;j++){
	M[j] = M[j + 1];
      }
    }
  }
   
  printf("%d\n",MatrixChainOrder());
 
  return 0;
 
}
   
 

Measured memory_bytes: 632
n, w = map(int, input().split())
W = []
V = []
for _ in range(n):
    s, t = map(int, input().split())
    W.append(s)
    V.append(t)

Dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(w+1):
        #対象となる重さjよりも、見ているものの重さが小さい時
        if W[i] <= j:
            Dp[i+1][j] = max(Dp[i][j], Dp[i][j-W[i]]+V[i])
        else:
            Dp[i+1][j] = Dp[i][j]

ans = Dp[-1][-1]
print(ans)

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

using namespace std;

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

	vector<vector<int>> dp(555, vector<int>(555, 1e9));
	dp[0][0] = 0;
	int n, a, b;
	cin >> n >> a >> b;
	for (int l = 0; l < n; l++) {
		int x, y, c;
		cin >> x >> y >> c;
		for (int i = 500; i >= 0; i--) {
			for (int j = 500; j >= 0; j--) {
				dp[i + x][j + y] =
					min(dp[i + x][j + y], dp[i][j] + c);
			}
		}
	}
	int res = 1e9;
	for (int i = 1; i < 555; i++) {
		for (int j = 0; j < 555; j++) {
			if (a * j == b * i) {
				res = min(res, dp[i][j]);
			}
		}
	}
	if (res == 1e9) {
		res = -1;
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int par[200001],ran[200001];
int init(int n){
    rep(i,n+1) par[i]=i,ran[i]=0;
}
int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}
int unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return 0;
    if(ran[x]<ran[y]) par[x]=y;
    else{
        par[y]=x;
        if(ran[x]==ran[y]) ran[x]++;
    }
}
int same(int x,int y){
    return find(x)==find(y);
}
int n,m,k,a,b,A[200001]={0},B[200001]={0};
int main(){
    cin>>n>>m>>k;
    init(n);
    rep(i,m){
        cin>>a>>b;
        unite(a,b);
        A[a]--,A[b]--;
    }
    rep(i,n) B[find(i+1)]++;
    rep(i,n) A[i+1]+=B[find(i+1)];
    rep(i,k){
        cin>>a>>b;
        if(same(a,b)) A[a]--,A[b]--;
    }
    rep(i,n){
        cout<<A[i+1]-1<<" ";
    }
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>

using namespace std;

#define min(a,b) (a < b ? a : b)

int main(void){
    int n,x=100000000,box=0,d;
    string s;
    cin >> n;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i] == '('){
            box++;
        }else{
            box--;
        }
        x = min(x,box);
        if(i==n-1)d = box;
    }
    for(int i=0;i<-1*x;i++){
        s = '(' + s;
    }
    box=0;
    n = s.length();
    for(int i=0;i<n;i++){
        if(s[i] == '('){
            box++;
        }else{
            box--;
        }
    }
    for(int i=0;i<box;i++){
        s += ')';
    }
    cout << s << endl;
}

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

#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;

int main() {

    int n ;
    cin >> n ;
    ll a[n] ;
    rep(i,n) cin >> a[i] ;
    ll ans = 0 ;
    ll tmax = a[0] ;

    for(int i=1;i<n;++i){
        ll tmp = 0 ;
        if((a[i]-a[i-1])<0){
            tmp = max((a[i-1]-a[i]),tmax-a[i]) ;
        }

        if(a[i]<tmax){
            tmp = max(tmp,tmax-a[i]) ;
        }
        ans+= tmp ;
        tmax = max(a[i],tmax) ;
       // cout << ans << endl ;
    }

    cout << ans << endl ;

    return 0 ;
}

Measured memory_bytes: 5152
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      int L = scan.nextInt();
     
      String[] str = new String[N];
      
      for(int i = 0; i < N; i++){  
        str[i] = scan.next();
      }
      
      Arrays.sort(str);
      
      for(String out : str){
        System.out.print(out);
      }
      scan.close();    
    } 
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int k, n;
    cin >> k >> n;

    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }

    int ans = a[n-1] - a[0];

    REP(i, n) {
        chmin(ans, k-a[i]+a[i-1]);
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 0
for i in range(n):
    ans += min(a[i], b[i])
    if a[i] < b[i]:
        ans += min(a[i+1], b[i] - a[i])
        a[i+1] -= min(a[i+1], b[i] - a[i])
print(ans)

Measured memory_bytes: 18436
class Node:
    def __init__(self,z):
        self.key=z
        self.left=None
        self.right=None

def insert(z):
    global root
    if root==None:
        root=Node(z)
    else:
        x=root
        while True:
            if z<x.key:
                if x.left:
                    x=x.left
                else:
                    x.left=Node(z)
                    break
            else:
                if x.right:
                    x=x.right
                else:
                    x.right=Node(z)
                    break
def inorder(z):
    if z==None:
        return []
    else:
        return inorder(z.left)+[z.key]+inorder(z.right)
def preorder(z):
    if z==None:
        return []
    else:
        return [z.key]+preorder(z.left)+preorder(z.right)
def find(z):
    global root
    x=root
    r="no"
    while x:
        if z==x.key:
            r="yes"
            break
        elif z<x.key:
            x=x.left
        else:
            x=x.right
    return r
root=None
n=int(input())
for _ in range(n):
    p=input()
    if p[0]=="i":
        insert(int(p[7:]))
    elif p[0]=="f":
        print(find(int(p[5:])))
    else:
        print("",*inorder(root))
        print("",*preorder(root))


Measured memory_bytes: 96516
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0556?year=2011

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    n--;

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;

        int c = min({x, y, n - x, n - y});
        cout << c % 3 + 1 << endl;
    }
    return 0;
}

/*
 * 壁画の中央に青が固まっているのがいやらしい。
 * 対称性を利用する。縦横の対称性から
 * x=min(x,n-x), y=min(y,n-y)
 * としてよい。さらに斜め線に関する対称性から
 * min(x,y)=min(x,y,n-x,n-y)
 * だけ考えればよい。周期は3。
 *
 */


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

int main() {
    string s;
    cin>>s;
    int flag = 1;
    for(int i=0;i<3;i++) {
        if(s[i]=='7') {
            cout<<"Yes"<<endl;
            flag = 0;
            break;
        }
    }
    if(flag) {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
s=list(input())
n=len(s)

a=[0]*(n+1)
for i in range(n):
    if s[i]=="<":
        a[i+1]=max(1+a[i],a[i+1])

s.reverse()
a.reverse()
for i in range(n):
    if s[i]==">":
        a[i+1]=max(1+a[i],a[i+1])
s.reverse()
a.reverse()
print(sum(a))


Measured memory_bytes: 27072
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

  int usable_outlet = 1;
  int cnt = 0;
  while(usable_outlet < b){
    usable_outlet--;
    usable_outlet += a;
    cnt++;
  }

  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int N;
int a[111];
main(){
  while(1){
    int m,n;
    scanf("%d %d",&m,&n);
    if(!m && !n) break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    
    int st=1,ed=1500000,h;
    int res;
    while(st<=ed){
      h=(st+ed)/2;
      int co=0;
      for(int i=0;i<m;i++){
	int j;
	int sum=0;
	for(j=co;j<n;j++){
	  sum+=a[j];
	  if(sum>h){
	    break;
	  }
	}
	co=j;
	if(co==n) break;
      }
      if(co==n){
	ed=h-1;
	res=h;
      }
      else st=h+1;
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1188
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
ll divisors(ll n) 
{ 
    ll cn=0,tn = n;
    for (ll i=2; i*i<=n; i++) 
    { 
    	if(n%i==0) {
    	cn++;
        while(n%i==0)
        {
        	n /= i;
        }
        }
    } 
    if(n!=1) cn++;
    return cn;
}
signed main()
{
    fast;
    
    ll a,b;
    cin>>a>>b;
    ll gc = __gcd(a,b);
    cout<<divisors(gc)+1;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }


int main(void){
  int n,m,ans=0;cin >> n >> m;
  vector<pair<vint,bool>> sp(m);
  rep(i,m){
    int k;cin >> k;
    sp[i].first.resize(k);
    rep(j,k){ 
      cin >> sp[i].first[j];
      sp[i].first[j]--;
    }
  }
  rep(i,m) cin >> sp[i].second;

  rep(i,pow(2,n)){
    vint onoff(n);
    rep(j,n){
      onoff[j] = (i&(int)pow(2,j))==(int)pow(2,j);
    }
    int flag=1;
    rfor(sp,t){
      int sum=0;
      rfor(t.first,x) sum+=onoff[x];
      flag&=sum%2==t.second;
      if(!flag)break;
    }
    if(flag){
      //cout << i << " is all on" << endl;
      ans++;
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

const long long MOD_CONST = 1000000007;


int main() {

	int n, y;
	cin >> n >> y;
	bool isTrue = false;
	for (int i = 0; i <=n; i++) {
		for (int j = 0; j + i <=n; j++) {
			int k = n - i - j;
			if (i * 10000 + j * 5000 + k * 1000 == y) {
				isTrue = true;
				cout << i << " " << j << " " << k << endl;
				break;
			}
		}
		if (isTrue) {
			break;
		}
	}
	if (!isTrue) {
		cout << -1 << " " << -1 << " " << -1 << endl;
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;

int n;
ll k, a[200000], f[200000];
int check(ll x) {
    ll cost = 0;
    for (int i = 0; i < n; ++i) {
        ll need = a[i] - x / f[i];
        if (0 < need)cost += need;
    }
    return cost <= k;
}

int lesser(const void* a, const void* b) {
    if (*(ll*)a > * (ll*)b)return 1;
    if (*(ll*)a < *(ll*)b)return -1;
    return 0;
}
int greater(const void* a, const void* b) {
    if (*(ll*)a < *(ll*)b)return 1;
    if (*(ll*)a > * (ll*)b)return -1;
    return 0;
}

int main(void) {
    scanf("%d %lld", &n, &k);
    for (int i = 0; i < n; ++i)scanf("%lld", &a[i]);
    for (int i = 0; i < n; ++i)scanf("%lld", &f[i]);
    qsort(a, n, sizeof(ll), lesser);
    qsort(f, n, sizeof(ll), greater);

    ll ng = -1, ok = 1000000000000LL;
    while (ok - ng > 1) {
        ll mid = ng + ok >> 1;
        if (check(mid) == 1)ok = mid;
        else ng = mid;
    }

    printf("%lld", ok);

    return 0;
}


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

using namespace std; 

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	string s ;
	cin>>s ;
	if(n < 3200)
		return cout<<"red\n" , 0 ;
	return cout<<s<<"\n" , 0 ;
}

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

long long dif[100005];
long long sum[100005];

int dat[100005];

int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&dat[i]);
        --dat[i];
    }

    // 먼저 1일 때 값을 sum[1]에 계산한다.

    long long diff = 0;

    for (int i = 1; i < n; i++)
    {
        if (dat[i] == dat[i - 1]) continue;
        if ((dat[i - 1] + 1) % m == dat[i])
        {
            sum[0]++;
            continue;
        }

        int d1 = dat[i] + 1;
        int d2 = (dat[i] - dat[i - 1] + m) % m;

        sum[0] += min(d1, d2);

        if (dat[i] > dat[i - 1])
        {
            dif[dat[i - 1] + 2]--;
            dif[dat[i] + 1]++;
            sum[dat[i] + 1] += dat[i] - dat[i - 1] - 1;
        }
        else
        {
            diff--;
            dif[dat[i] + 1]++;
            dif[dat[i - 1] + 2]--;
            sum[dat[i] + 1] += dat[i] + m - dat[i - 1] - 1;
        }
    }

    for (int i = 1; i < m; i++)
    {
        diff += dif[i];
        sum[i] += sum[i - 1] + diff;
    }

    printf("%lld\n", *min_element(sum, sum + m));
}


Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 20000 // スタックの最大値

typedef struct 
{
	int top; // スタックポインタ(一番上の位置)
	int S[MAX]; 
}Stack;

// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
	
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量
  
	

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
    	push(i, &st1); // 位置 i を st1 にプッシュ
       
    	
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      		
    	// 水たまりの総水量 sum を更新
      

    	int j = pop(&st1);
    	
    	sum = sum + (i-j); //前に求めた面積と足して総面積を出す。
    	
    	int a = i - j;   // 更新する水たまりの水量を a に格納していく
    	
    	// st2_j と st2_a を用いて水たまりの水量を更新 
    	
    	
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置がj よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく 
      	pop(&st2_j);
      	a += pop(&st2_a);
      	
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 
    	
    	push(j, &st2_j);
    	push(a, &st2_a);
    	
    }
  	
  	
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
	
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,D;cin>>N>>D;
  cout<<(N-1)/(2*D+1)+1<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()
T = input()

for i in range(N):
  j = 0
  fl = True
  while j+i < N:
    if S[i+j] == T[j]:
      j += 1
      #print(i,j)
    else:
      fl = False
      break
      
  if(fl):
    print(N+i)
    exit(0)
    
print(2*N)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (1900 * m + 100 * (n - m)) * pow(2, m) << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, a, b;
	cin >> N >> a >> b;
	int goukei = 0;
	for (int i = 1; i < N + 1; i++)
	{
		string str = to_string(i);
		int baba = 0;
		for (int i = 0; i < str.size(); i++)
		{
			baba += str[i] - '0';
		}
		if (a <= baba && baba <= b)
		{
			goukei += i;
		}
	}
	cout << goukei << "\n";
}

Measured memory_bytes: 256
// Example program
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main()
{
 int W, H, x, y, r;
 cin >> W >> H >> x >> y >> r;
 if ( x-r<0 || x+r>W || y-r<0 || y+r>H )
 {
     cout << "No" << endl;
 }else{
     cout << "Yes" << endl;
 }
}

Measured memory_bytes: 1160
num = gets.to_i
val = gets.split.map(&:to_i)
# p val.count
sum = 0
val.each do |v|
    sum += v
end
# p sum
mini = sum
prefix_sum = 0
aa = []
val.each do |i|
    prefix_sum += i
    # mini = (mini, (prefix_sum - (sum - prefix_sum)).abs).min
    aa.push((prefix_sum - (sum - prefix_sum)).abs)
    # p mini
end
p aa.push(mini).min

# p val
# p val.reverse

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 4; i++)
    {
        if (s[i] == '+') {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#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)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (5003)
#define MAXM (203)
ll n, m, A[MAXN][MAXM], sum[MAXN][MAXN], dist[MAXN];
int main()
{
	FAST
	cin>>n>>m;
	FOR(i,1,n-1)cin>>dist[i],dist[i]+=dist[i-1];
	FOR(i,1,n)FOR(j,1,m)cin>>A[i][j];
	FOR(j,1,m){
		vector<ll> v={0};
		A[0][j]=LLINF;
		FOR(i,1,n){
			ll until = i, x=0;
			while(A[v.back()][j] < A[i][j]) {
				x=v.back(), v.pop_back(), sum[v.back() + 1][i]-=A[x][j], sum[x+1][i]+=A[x][j];
				until = v.back() + 1;
			}
			// cerr<<i<<' '<<j<<' '<<until<<' '<<A[i][j]<<'\n';
			sum[until][i] += A[i][j], sum[i+1][i] -= A[i][j];
			v.eb(i);
		}
	}
	FOR(i,1,n)FOR(j,1,n)sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
	ll ans = 0;
	FOR(i,1,n)FOR(j,i,n){
		ans=max(ans,sum[i][j]-(dist[j-1]-dist[i-1]));
	}
	cout<<ans<<'\n';
}
/*
3 3
1 1 1
1 1 1
1 10 1
1 1 1
*/ 


Measured memory_bytes: 203776
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, k;
int a[114514];
int sum[114514], psum[114514];
signed main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	sum[0] = a[0], psum[0] = max(0LL, a[0]);
	REP(i, n) {
		sum[i] += sum[i - 1];
		psum[i] += psum[i - 1];
		sum[i] += a[i];
		psum[i] += max(0LL, a[i]);
	}
	int ans = max(0LL, sum[k - 1]) + psum[n - 1] - psum[k - 1];
	REP(i, n - k + 1) {
		ans = max(ans, max(0LL, sum[i + k - 1] - sum[i - 1]) + psum[i - 1] + psum[n - 1] - psum[i + k - 1]);
	}
	cout << ans << endl;
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

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

	string s; cin >> s;
	int n = s.length();
	int ans = 0;
	for (int i = 0, j = n - 1; i < j; i++, j--) {
		if (s[i] == s[j]) continue;
		if (s[i] == 'x') {
			++j, ++ans;
		} else if (s[j] == 'x') {
			--i, ++ans;
		} else{
			ans = -1;
			break;
		}
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    
    for(int i = 0; i < 4; i++){
        cin >>a>>b;
        
        if(a == 1){
            c = 6000 * b;
        }else if(a == 2){
            c = 4000*b;
        }else if(a == 3){
            c = 3000*b;
        }else if(a == 4){
            c = 2000*b;
        }
        
        cout<<c<<endl;
    }
    
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  set<string> ss;
  bool ok = true;
  char prv;
  rep(i, n) {
    string s; std::cin >> s;
    if (ss.count(s)) ok = false;
    if (i > 0 && prv != s[0]) ok = false;
    prv = s.back();
    ss.insert(s);
  }
  std::cout << (ok ? "Yes" : "No") << "\n";
}


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 sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#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<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

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);
const int mod=1000000007;
const int mod2=998244353;

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	double N;
	cin >> N;
	for(double h=1.0;h<=3500.0;h+=1.0){
		for(double n=1.0;n<=3500.0;n+=1.0){
			double w=(N*h*n)/(4*h*n-N*n-N*h);
			if((ll)w==w && w>0.0){
				cout << (ll)h << " " << (ll)n << " " << (ll)w << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            String sorted = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .sorted()
                    .boxed()
                    .map(Object::toString)
                    .collect(Collectors.joining(" "));
            System.out.println(sorted);
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 32064
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> str:
    ret, cur, prev = "", a, b
    for i in S:
        ret += cur
        if (cur == "S" and i == "o") or (cur == "W" and i == "x"):
            prev, cur = cur, prev
        elif (cur == "S" and i == "x") or (cur == "W" and i == "o"):
            x = "W" if prev == "S" else "S"
            prev, cur = cur, x
    flg = cur == a and prev == b
    return ret if flg else ""


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans = check(a, b)
            if ans:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


int main() {
  long double a, b, c;
  // int a, b, c;
  cin >> a >> b >> c;

  const long double eps = 1e-14;
  if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for i in range(N+1) ]	#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#リバース隣接リスト
O=[ 0 for i in range(N+1) ] #出次数
edge=[] #辺の集合

for _ in range(M):
    s,t=map(int, sys.stdin.readline().split())
    al[s].append(t)
    rev_al[t].append(s)
    #I[t]+=1
    O[s]+=1
    edge.append((s,t))


#頂点毎の到達する確立
P=[ 0 for i in range(N+1) ]   #確率
P[1]=1
 
for x in range(1,N+1):
    if O[x]!=0:
        p=float(1)/O[x]
        for to in al[x]:
            P[to]+=P[x]*p
        
#頂点毎の期待値
E=[ 0 for i in range(N+1) ]   #期待値

for x in range(N,0,-1):
    for to in rev_al[x]:
        p=float(1)/O[to]
        E[to]+=(E[x]+1)*p


#消す辺
ans=E[1]
for del_s,del_t in edge:
    if O[del_s]-1==0:
        continue
    new_E=float(E[del_s]*O[del_s]-(E[del_t]+1))/(O[del_s]-1)
    #print "del_s,del_t,new_E, :: ",del_s,del_t,new_E,E,E[1]+(new_E-E[del_s])*P[del_s]
    if new_E<E[del_s]:
        ans=min(ans,E[1]-(E[del_s]-new_E)*P[del_s])

print ans

Measured memory_bytes: 67100
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;



int main(){

	int A_P,B_P;
	char buf[110];

	while(true){
		scanf("%s",buf);
		if(buf[0] == '0')break;

		A_P = B_P = 0;

		for(int i= 1;buf[i] != '\0'; i++){
			if(buf[i] == 'A'){
				A_P++;
				if(buf[i+1] == '\0'){
					if(A_P > B_P)A_P++;
					else{
						B_P++;
					}
				}
			}
			else{
				B_P++;
				if(buf[i+1] == '\0'){
					if(A_P > B_P)A_P++;
					else{
						B_P++;
					}
				}
			}
		}
		printf("%d %d\n",A_P,B_P);
	}
    return 0;
}

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

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    int A[n][m],B[m][l];
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<m;++i){
        for(int j=0;j<l;++j){
            cin >> B[i][j];
        }
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<l;++j){
            long long cij = 0;
            for(int k=0;k<m;++k) cij += A[i][k] * B[k][j];
            cout << (j==0?"":" ") << cij;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
long long f(long long h)
{
    if (h==1)return 1;
    else{
        return f(h/2) * 2 +1;
    }
}
int main()
{
    long long h;
    cin>>h;
    cout<<f(h);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n),l(n),r(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    l[0]=a[0];
    r[n-1]=a[n-1];
    for(ll i=1;i<n-1;i++) l[i]=gcd(l[i-1],a[i]);
    for(ll i=n-2;i>0;i--) r[i]=gcd(r[i+1],a[i]);
    ll m=r[1];
    for(ll i=1;i<n-1;i++) m=max(m,gcd(l[i-1],r[i+1]));
    m=max(m,l[n-2]);
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 2560
# coding: utf-8
 
 
def main():
 
    in_ninzu = int(input())
    
    # '/'で割ると小数点付きの表示になるので’//’で商を求めると整数になる
    in_candy = in_ninzu * (in_ninzu + 1) // 2
    
    print(in_candy)
  
    return 0
 
 
if __name__ == '__main__':
    main()

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

int main() {
  //ビンゴカードを作る
  vector<vector<int>> vec(3,vector<int> (3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> vec.at(i).at(j);
    }
  }
  int n;
  cin >> n;
  //それぞれのbについて、カードの数字と一致したらカードを0にする
  for(int k=0;k<n;k++){
    int b;
    cin >> b;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(b == vec.at(i).at(j))
          vec.at(i).at(j) = 0;
      }
    }
  }
  bool a = 0,ans = 0;
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      //0じゃないときaを1にする
      if(vec.at(i).at(j) != 0){
        a = 1;
      }
    }
    //全部0なら答えを1にする
    if(a == 0)
     ans = 1;
    a = 0;
  }
  for(int j=0;j<3;j++){
    for(int i=0;i<3;i++){
      if(vec.at(i).at(j) != 0){
        a = 1;
      }
    }
    if(a == 0)
      ans = 1;
    a = 0;
  }
  if(vec.at(0).at(0) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(2) == 0)
    ans = 1;
  if(vec.at(0).at(2) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(0) == 0)
    ans = 1;
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3600