akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        char s1[] = inp.next().toCharArray();
        char s2[] = inp.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < 3; i++) {
            if (s1[i] == s2[i]) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ar[N];
int dp[N];

signed main(){
 	// #ifndef ONLINE_JUDGE
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// #endif
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin >>s;
		map<string,int>mp;
		mp["SUN"]=0;
		mp["MON"]=1;
		mp["TUE"]=2;
		mp["WED"]=3;
		mp["THU"]=4;
		mp["FRI"]=5;
		mp["SAT"]=6;
		int j =mp[s];
		int cnt =0 ;
		if( j == 0){
			cout << 7<<endl;
			continue;
		}
		while(j%7!=0){
			cnt++;
			j++;
		}
		cout<<cnt<<endl;
	
	}
	
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}


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

bool countACGT(string s,int start,int end){
    for(int i=start;i<=end;i++){
        if(s[i]!='A' && s[i]!='C' && s[i]!='G' && s[i]!='T')return false;
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    int max=0;

    for(int i=0;i<s.length();i++){
        for(int j=i;j<s.length();j++){
            if(countACGT(s,i,j)){
                if(j-i+1>max)max=j-i+1;

            }
        }
    }
    cout << max << endl;
    return 0;
}






Measured memory_bytes: 256
n = int(input())
b = [int(i) for i in input().split()]

a = [0] * n

a[0] = b[0]
a[n-1] = b[n-2]
for i in range(1, n - 1):
    a[i] = min(b[i-1], b[i])
print(sum(a))


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  V a;
  rep(i,4){
    a.pb(n%10);
    n/=10;
  }
  reverse(all(a));
  str ans,op="+-";
  rep(i,2){
    rep(j,2){
      rep(k,2){
        int res=a[0];
        if(i==0)res+=a[1];
        else res-=a[1];
        if(j==0)res+=a[2];
        else res-=a[2];
        if(k==0)res+=a[3];
        else res-=a[3];
        if(res==7){
          ans=to_string(a[0])+op[i]+to_string(a[1])+op[j]+to_string(a[2])+op[k]+to_string(a[3])+"=7";
          cout<<ans<<endl;
          return 0;
        }
      }
    }
  }

  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int b[10];
  int t;
  cin>>t;
  while(t--){
    for(int i=0;i<10;i++)
      cin>>b[i];
    int now=b[0];
    b[0]=0;
    for(int i=1;i<10;i++)
      if(b[i]>now){
	now=b[i];
	b[i]=0;
      }
    /*for(int i=0;i<10;i++)
      cout<<b[i]<<" ";
      cout<<"\n";*/
    for(int i=0;i<10;i++)
      if(b[i]>0){
	now=i;
	break;
      }
    bool flag=true;
    for(int i=now;i<10;i++)
      if(b[i]>0&&b[i]<b[now])
	flag=false;
      else if(b[i]>0)
	now=i;
    if(flag)cout<<"YES\n";
    else cout<<"NO\n";
  }
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair

bool compare(pair<int,pii> a, pair<int,pii> b){
    if(a.first!=b.first)return a.first>b.first;
    return a.second<b.second;
}

const int mod = 998244353;//1e9 + 7;
const ll inf = ll(1e18);

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll n,m=998244353;
    cin>>n;
    vl a(n,0),b(n,0);
    f(i,0,n)cin>>a[i],b[a[i]]++;
    if(a[0]>0){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1,cp=n-1-b[1];
    f(i,2,n){
        if(cp>0 and b[i]==0){
            cout<<0<<endl;
            return 0;
        }
        ans=(modexp(b[i-1],b[i])*ans)%m;
        cp-=b[i];
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

char C;

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

  char ans = C + 1;

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int e = kbd.nextInt();
	    if(e != 0){
		int ans = solve(e);
		System.out.println(ans);
	    }
	}
    }

    static int solve(int e){
	int ans=e, x=0, y=0, z=0;
	int s=0, r;

	for(z=(int)Math.cbrt(e); z>=0; z--){
	    s = z*z*z;
	    if(s>e) continue;
	    for(y=(int)Math.sqrt(e); y>=0; y--){
		s = y*y + z*z*z;
		if(s>e) continue;
		x=(e-s);
		s = x + y*y + z*z*z;
		//System.out.println(s);
		//if(s != e) continue;
		r = x+y+z;
		if(s==e && r<ans) ans = r;
	    }
	}
	return ans;
    }
}

Measured memory_bytes: 26128
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

name = input()
print(name[:3])

Measured memory_bytes: 72808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int N;
    cin >> N;
    int X[N];
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        sum += X[i];
    }
    ll ans1 = 0;
    ll ans2 = 0;
    for (int i = 0; i < N; i++) {
        ll t1 = (sum + N - 1) / N - X[i];
        ll t2 = sum / N - X[i];
        ans1 += t1 * t1;
        ans2 += t2 * t2;
    }
    cout << min(ans1, ans2) <<endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> input = new ArrayList<String>();
		String buf;
		while((buf = br.readLine()) != null){
			input.add(buf);
		}
		for(String str : input){
			System.out.println(unzipString(str));
		}
	}
	public static String zipString(String str){
		StringBuffer bf = new StringBuffer();
		return bf.toString();
	}
	public static String unzipString(String str){
		StringBuffer bf = new StringBuffer();
		char[] c = str.toCharArray();
		for(int i = 0; i < c.length; i++){
			if(c[i] == '@'){
				int n = Integer.parseInt(String.valueOf(c[++i]));
				char tmp = c[++i];
				for(int j = 0; j < n; j++){
					bf.append(tmp);
				}
			}
			else{
				bf.append(c[i]);
			}
		}
		return bf.toString();
	}
}

Measured memory_bytes: 9364
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int r = 0;
  for(int i = A;i <= B; i++){
    int s = i % 10, t = i / 10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if(s == t && u == v) r++ ; 
  }
    cout << r << endl;
}

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

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

signed main(void){ 
  
  int t; cin >> t;
  
  while(t--){
    int a,b,c,d; cin >> a >> b >> c >> d;
    if( a < b || d < b ){ //明らかにダメ ジリ貧になるため
      cout << "No" << endl; continue;
    }
    
    if( c >= b ){ cout << "Yes" << endl; continue;//必ず回せるため問題なし
                }
    // 以下、 a >= b かつ d >= b かつ b > c の場合を考える
    // a+d*x-b*yがcよりでかくbより小さい値をとるとまずい(x,yは0以上の整数)
    // d*x-b*yが取れるもっとも絶対値の細かい値はgcd(b,d)と思われる
    //　c < a+k*g < bなる整数kがとれるか調べれば良い
    
    int g = gcd(b,d);
    int k = abs(b-a)/g;
    k *= -1;
    k--;
    int res = a+k*g;
    if( c < res && res < b ){ cout << "No" << endl; continue;}
    else{ cout << "Yes" << endl; continue;}
    
  }
  
  return 0;
}

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

using namespace std;


void solve() {
    int N; cin >> N;
    vector<long long> A(N+1);
    for (int i = 0; i < N+1; i++) cin >> A[i];

    if (N == 0) {
        if (A[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return;
    }
    else {
        if (A[0] > 0) {
            cout << -1 << endl;
            return;
        }
    }

    vector<long long> max_node(N+1);
    max_node[N] = A[N];
    for (int i = N-1; i >= 0; i--)  {
        max_node[i] = max_node[i+1] + A[i];
    }

    long long sum = 0;
    long long node = 1;
    for (int i = 0; i < N+1; i++) {
        node = min(node, max_node[i]);
        sum += node;
        node = (node - A[i]) * 2;
        //cout << node << endl;
        if (node < 0) {
            cout << -1 << endl;
            return;
        }
    }

    cout << sum << endl;
}


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

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

int32_t main(){
    int t;
    t = 1;
    while(t--){
        int k;
        cin >> k;
        string s = "";
        for(int i=0; i<k; i++)
          s += "ACL";
        cout << s << endl;
    }
}



Measured memory_bytes: 3616
// #include <algorithm>
// #include <cmath>
// #include <cstdio>
// #include <cstring>
// #include <string>
// #include <iomanip>
// #include <iostream>
// #include <vector>
// #include <cstdlib>
// #include <set>
// #include <map>
// #include <queue>
// #include <stack>
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ull qpow(ull a, ull b)
{
    ull ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
inline bool isPalindrome(const string &s)
{
    return equal(s.begin(), s.end(), s.rbegin());
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if ((v - w) * t >= abs(b - a))
        cout << "YES\n";
    else
        cout << "NO\n";
}

Measured memory_bytes: 3604
///Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
#define        ll                              long long int
#define        FOR(x,y,z)                      for(int x=y;x<z;x++)
#define        pii                             pair<int,int>
#define        pll                             pair<ll,ll>
#define        CLR(a)                          memset(a,0,sizeof(a))
#define        SET(a)                          memset(a,-1,sizeof(a))
#define        N                               1000010
#define        M                               1000000007
#define        pi                              acos(-1.0)
#define        ff                              first
#define        ss                              second
#define        pb                              push_back
#define        inf                              (1e9)+1000
#define        eps                             1e-9
#define        ALL(x)                          x.begin(),x.end()
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
template < class T> inline T biton(T n,T pos){return n |((T)1<<pos);}
template < class T> inline T bitoff(T n,T pos){return n & ~((T)1<<pos);}
template < class T> inline T ison(T n,T pos){return (bool)(n & ((T)1<<pos));}
template < class T> inline T gcd(T a, T b){while(b){a%=b;swap(a,b);}return a;}
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
inline int nxt(){int aaa;scanf("%d",&aaa);return aaa;}
inline ll lxt(){ll aaa;scanf("%lld",&aaa);return aaa;}
inline double dxt(){double aaa;scanf("%lf",&aaa);return aaa;}
template <class T> inline T bigmod(T p,T e,T m){T ret = 1;
for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % m;p = (p * p) % m;
} return (T)ret;}
#ifdef sayed
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************
int ar[N];
int main(){
    #ifdef sayed
    //freopen("out.txt","w",stdout);
    // freopen("in.txt","r",stdin);
    #endif
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int r = nxt(),g = nxt(),b = nxt();
    int n = nxt();
    int ans = 0;
    for(int i = 0;i<=n;i++) {
        for(int j = 0;j<=n;j++) {
            int tot = i*r+j*g;
            if(tot>n) continue;
            int Left = n-tot;
            if(Left%b==0) ans++;

        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        int h,a;
        cin>>h>>a;
        if(h%a == 0) cout<<h/a;
        else cout<<h/a+1;
    }
	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=2e5+20,inf=0x3f3f3f3f;
ll n,k,a[N],b[N];
int main()
{	
	ll ans=0,val=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		if((a[i]&k)==a[i])
			ans+=b[i];
	}
	for(ll bit=30;bit>=0;bit--)
	{
		if((k>>bit)&1)
		{
			val=val|(1ll<<bit);
			ll res=0;
			for(int j=1;j<=n;j++)
				if(!(val&a[j]))
					res+=b[j];
			ans=max(ans,res);
			
			val=val^(1ll<<bit);
		}
		else
			val=val|(1ll<<bit);// val=lcp'
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Wall {

}

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int height = scan.nextInt();
		int width = scan.nextInt();
		int c[][] = new int[10][10];
		int a[][] = new int[height][width];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = scan.nextInt();
			}
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (c[i][j] > c[i][k] + c[k][j]) {
						c[i][j] = c[i][k] + c[k][j];
					}
				}
			}
		}
		int totalCost=0;
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				a[i][j] = scan.nextInt();
				if(a[i][j]!=-1) {
					totalCost+=c[a[i][j]][1];
				}
			}
		}
		System.out.println(totalCost);
	}
}

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

int main(void){
 
  int N;
  
  cin >> N;
  
  int t[N + 1],x[N + 1],y[N + 1];
  
  t[0] = x[0] = y[0] = 0;
  
  for(int i = 0; i < N ; ++i){
    cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
  }
  
  
  bool can = true;
  
  for(int i = 0; i < N; ++i){
    int dt = t[i + 1] - t[i];
    int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    
    if(dt < dist){
      can = false;
    }
    
    if(dist % 2 != dt % 2){
      can = false;
    }
  }
  
  if(can){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

int main()
{
	char num[1000];
	int sum;
	while(1){
		cin >> num;
		if(num[0] == '0') break;
		sum = 0;
		for(int i = 0;i < strlen(num);i++){
			sum += num[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;	
}

Measured memory_bytes: 3088
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
lx = 0
ly = 0
rx = W
ry = H

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if lx < x[i]:
            lx = x[i]
    elif a[i] == 2:
        if x[i] < rx:
            rx = x[i]
    elif a[i] == 3:
        if ly < y[i]:
            ly = y[i]
    else:
        if y[i] < ry:
            ry = y[i]

if lx >= rx or ly >= ry:
    print(0)
else:
    print((rx - lx) * (ry - ly))


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def divide(N):
    ret = {}
    p = 2
    tn = int(N**0.5)
    while N != 1:
        if N % p == 0:
            if p not in ret:
                ret[p] = 1
            else:
                ret[p] += 1
            N //= p
        elif p > tn:
            p = N
        else:
            p += 1

    return ret


def solve(N):
    p_dict = divide(N)
    ans = 0
    for v in p_dict.values():
        ans += int(((1 + 8 * v)**0.5 - 1) * 0.5)
    return ans


def main():

    N = int(input())
    print(solve(N))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9484
import sys


n = int(input())
W = [input() for _ in range(n)]

w_set = set(W)
if len(w_set) != len(W):
    print("No")
    sys.exit()

prev = W[0]
for i in range(1, n):
    if W[i-1][-1] != W[i][0]:
        print("No")
        sys.exit()
print("Yes")


    




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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi a(n);
  REP(i,n)cin>>a[i],a[i]--;
  int cur = 0;
  REP(s,n){
    cur = a[cur];
    if(cur==1){
      cout<<(s+1)<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


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

using namespace std;

const int MAXN = 1e4+1;

int f[MAXN];

int main(){
  for(int i = 0; i < MAXN; i++){
    f[i] = 0;
  }

  for(long long x = 1; x*x < MAXN; x++){
    for(long long y = 1; x*x + y*y + x*y < MAXN; y++){
      for(long long z = 1; x*x + y*y + z*z + x*y + y*z + z*x < MAXN; z++){
	f[x*x + y*y + z*z + x*y + y*z + z*x]++;
      }
    }
  }

  int N;
  while(scanf("%d", &N) > 0){
    for(int i = 1; i <= N; i++){
      printf("%d\n", f[i]);
    }
  }
}


Measured memory_bytes: 3844
def main():
    N = int(input())
    D = list(map(int, input().split()))
    M = int(input())
    T = list(map(int, input().split()))
    D.sort()
    T.sort()
    idx = 0
    for d in D:
        if idx < M and T[idx] == d:
            idx += 1
    if idx == M:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 127700
#!/usr/bin/env ruby

def prime?(x)
  return true if x == 2
  return false if x < 2 || (x % 2).zero?

  i = 3
  while i <= Math.sqrt(x)
    return false if (x % i).zero?
    i += 2
  end
  true
end

n = gets.chomp.to_i

cnt = 0
n.times do
  cnt += 1 if prime?(gets.chomp.to_i)
end

puts cnt

Measured memory_bytes: 6892
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);


int main()
{
	// cout<<INT_MAX;
	fast
	ll k,n;
	cin>>k>>n;
	ll a[n],i;
	for(i=0;i<n;i++)
		cin>>a[i];
	ll d=0,j=0,dif;
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			dif=a[i]+k-a[n-1];
			if(d<dif)
			{
				d=dif;
				j=i;
			}
		}
		else
		{
			dif=a[i]-a[i-1];
			if(d<dif)
			{
				d=dif;
				j=i-1;
			}
		}
		// cout<<dif<<"\n";
	}
	// cout<<j<<"\n";
	ll sum=0;
	if(j==0)
	{
		for(i=1;i<n;i++)
			sum+=(a[i]-a[i-1]);
	}
	else
	{
		for(i=j;i>0;i--)
			sum+=(a[i]-a[i-1]);
		sum+=(a[0]+k-a[n-1]);
		// cout<<sum<<" ";
		for(i=n-1;i>j+1;i--)
			sum+=(a[i]-a[i-1]);
	}
	cout<<sum;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#define PI 3.14159265358979 
int main(){
double a,b,c;
double s,hen,r;
scanf("%lf %lf %lf",&a,&b,&c);
r=c/180*PI; s=a*b*sin(r)/2;
hen=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(r))+a+b;
printf("%lf\n",s);
printf("%lf\n",hen);
printf("%lf\n",s*2/a);
return 0; }


Measured memory_bytes: 2048
import sys
readline = sys.stdin.readline

S = list(map(ord, readline().strip()))
N = len(S)
S = [None] + S + [None]
K = int(readline())

if N == 1:
    ans = 1
elif N == 2:
    ans = 1
    if S[1] == S[2]:
        ans = 2
    if K:
        ans = 2
else:
    dp1 = [[0]*(K+1) for _ in range(N+2)]
    dp2 = [[0]*(K+1) for _ in range(N+2)]
    for i in range(1, N+1):
        dp1[i][0] = 1
    for i in range(1, N):
        dp2[i][0] = 1
        if S[i] == S[i+1]:
            dp2[i][0] = 2    
        elif K:    
            dp2[i][1] = 2
    for s in range(3, N+1):
        dp3 = [[0]*(K+1) for _ in range(N+2)]
        for i in range(1, N-s+2):
            j = i+s-1    
            if S[i] == S[j]:
                for k in range(K+1):
                    dp3[i][k] = max(dp2[i+1][k], dp2[i][k], 2+dp1[i+1][k])
            else:
                dp3[i][0] = max(dp2[i+1][0], dp2[i][0], dp2[i+1][0])
                for k in range(1, K+1):
                    dp3[i][k] = max(dp2[i+1][k], dp2[i][k], dp1[i+1][k], 2+dp1[i+1][k-1])
        dp1 = [k[:] for k in dp2]
        dp2 = [k[:] for k in dp3]
    ans = max(dp3[1][k] for k in range(K+1))
print(ans)
'''
MLEした
dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)]
for i in range(1, N+1):
    dp[i][i][0] = 1
for i in range(1, N):
    dp[i][i+1][0] = 1
    if S[i] == S[i+1]:
        dp[i][i+1][0] = 2    
    elif K:    
        dp[i][i+1][1] = 2
for s in range(3, N+1):
    for i in range(1, N-s+2):
        j = i+s-1
        if S[i] == S[j]:
            for k in range(K+1):
                dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k])
        else:
            dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0])
            for k in range(1, K+1):
                dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k])
print(max(dp[1][N][k] for k in range(K+1)))
'''   

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

struct dice{
    int nums[7];
};

void North(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[1];
    nums[1]=nums[5];
    nums[5]=nums[4];
    nums[4]=nums[6];
}
void East(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[3];
    nums[3]=nums[5];
    nums[5]=nums[2];
    nums[2]=nums[6];
}
void South(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[4];
    nums[4]=nums[5];
    nums[5]=nums[1];
    nums[1]=nums[6];
}
void West(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[2];
    nums[2]=nums[5];
    nums[5]=nums[3];
    nums[3]=nums[6];
}
int main(void){
    int n;
    cin>>n;
    struct dice DICE[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<6;j++){
            cin>>DICE[i].nums[j];
        }
    }
    /*cout<<" "<<DICE[0].nums[4]<<endl;
    cout<<DICE[0].nums[3]<<DICE[0].nums[0]<<DICE[0].nums[2]<<DICE[0].nums[5]<<endl;
    cout<<" "<<DICE[0].nums[1]<<endl<<endl;*/
    for(int j=1;j<n;j++){
        for(int i=0;i<4;i++){
            if(DICE[0].nums[1]==DICE[j].nums[0])break;
            North(DICE[j].nums);
        }
        for(int i=0;i<4;i++){
            if(DICE[0].nums[1]==DICE[j].nums[0])break;
            West(DICE[j].nums);
        }
    South(DICE[j].nums);
        
    /*cout<<" "<<DICE[j].nums[4]<<endl;
    cout<<DICE[j].nums[3]<<DICE[j].nums[0]<<DICE[j].nums[2]<<DICE[j].nums[5]<<endl;
    cout<<" "<<DICE[j].nums[1]<<endl<<endl;*/
    }
    
    for(int j=1;j<n;j++){
        for(int i=0;i<j;i++){
            for(int k=0;k<4;k++){
                if(DICE[i].nums[3]==DICE[j].nums[3]&&DICE[i].nums[0]==DICE[j].nums[0]&&DICE[i].nums[2]==DICE[j].nums[2]&&DICE[i].nums[5]==DICE[j].nums[5]&&DICE[i].nums[4]==DICE[j].nums[4]){
                    cout<<"No"<<endl;
                    return 0;
                }
                /*cout<<j<<endl;
                cout<<" "<<DICE[j].nums[4]<<endl;
                cout<<DICE[j].nums[3]<<DICE[j].nums[0]<<DICE[j].nums[2]<<DICE[j].nums[5]<<endl;
                cout<<" "<<DICE[j].nums[1]<<endl<<endl;*/
                West(DICE[j].nums);
            }
        }
    }
    
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=a+b,y=c+d;
    if(x>y) cout<<"Left"<<endl;
    else if(x==y) cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,m = map(int,input().split())
grid = [list(input()) for i in range(n)]
def jc(a,b):
  l = len(a)
  used = [0]*l
  for i in range(l):
    if used[i]:
      continue
    for j in range(i+1,l):
      if used[j]:
        continue
      if a[i] == b[j] and b[i] == a[j]:
        used[i] = 1
        used[j] = 1
        break
  if used.count(0) <= l%2:
    return True
  else:
    return False
def judge(a):
  h = len(a)
  w = len(a[0])
  used = [0]*h
  for i in range(h):
    if used[i]:
      continue
    ci = Counter(a[i])
    for j in range(i+1,h):
      if used[j]:
        continue
      cj = Counter(a[j])
      if ci == cj:
        if jc(a[i],a[j]):
          used[i] = 1
          used[j] = 1
          break
  if used.count(0) <= h%2:
    return True
  else:
    return False
gt = list(zip(*grid))
if judge(grid) & judge(gt):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 38512
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int main() {
  int h, w;
  cin >> h >> w;

  int table[26] = {0};
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, s.length()) {
      table[s[j]-'a']++;
    }
  }
  if (h%2 == 0 && w%2 == 0) {
    rep(i, 26) {
      if ( table[i] % 4 != 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  } else if (h%2 == 1 && w%2 == 1) {
    int cnt1 = 0, cnt2 = 0;
    rep(i, 26) {
      if (table[i]%4 == 1) { cnt1++; }
      if (table[i]%4 == 2) { cnt2++; }
      if (table[i]%4 == 3) {
        cnt1++;
        cnt2++;
      }
      if (cnt1 > 1 || cnt2 > (w+h-2)/2) {
        cout << "No" << endl;
        return 0;
      }
    }
  } else {
    int cnt2 = 0;
    rep(i, 26) {
      if (table[i]%4 == 1) {
        cout << "No" << endl;
        return 0;
      }
      if (table[i]%4 == 2) { cnt2++; }
      if (table[i]%4 == 3) {
        cout << "No" << endl;
        return 0;
      }
      if ( (h&1 && cnt2 > w/2) || (w&1 && cnt2 > h/2) ) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
ac,tle,wa,re=0,0,0,0
n = int(input())
for i in range(n):
    s = input()
    if s=="AC":
        ac+=1
    elif s=="WA":
        wa+=1
    elif s=="TLE":
        tle+=1
    else:
        re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)


Measured memory_bytes: 9192
#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define ll long long
#define sz(x) (int)(x).size()
#define endl '\n'
#define print_case() cout << "Case #" << test_case_number++ << ": "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long

int test_case_number = 1;

void solve(){
    print_case();
}

int weight, val;
void show(vec<vec<int>> dp){
    for(auto x : dp){
        for(int y : x)
            cout << y << '\t';
        cout << endl;
    }
    cout << "-----------------------------" << endl;
}
int32_t main(){
    int n, k;
    cin >> n >> k;
    vec<vec<int>> dp(n + 1, vec<int>(k + 1, 0));
    for(int i = 1; i <= n; ++i){
        cin >> weight >> val;
        for(int j = 1; j <= k; ++j){
            if(weight > j){
                dp[i][j] = dp[i - 1][j];
            }
            else{
                dp[i][j] = max(dp[i - 1][j], val + dp[i - 1][j - weight]);
            }
        }
    }
    cout << dp[n][k] << endl;
}


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

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

    int N;

    cin >> N;

   vector<int> V(N);
  
    rep(i, N) cin >> V[i];

    sort(V.begin(), V.end());

    float sum = V[0];

    for(int i=1; i<V.size(); ++i)
    {
        sum = (sum + V[i]) / 2;
    }

    cout << sum;

    return 0;
}

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

int main() {
  int sum,x,N,K;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> x;
    if(x<K-x){
      sum+=x*2;
    }else{
      sum+=(K-x)*2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}	
	sort(a,a+n);
	ll s=0;
	for(int i=0;i<k;i++){
		s=s+a[i];
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3644
/************************************************************
	> File Name: c.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 19 Jan 2020 01:35:27 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
#include <string>
using namespace std;
const int MAXN = 1e5+6;
int n, m, id;
bool AC[MAXN];
int a[MAXN],w[MAXN];
string status;
int main(void){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	int ans1 = 0,ans2 = 0;
	for(int i = 1;i <= m;i++){
		cin >> id >> status;
		if(AC[id])
			continue;
		if(status=="AC"){
			AC[id] = true;
			ans1++;
			ans2 += w[id];
		}else if(status=="WA")
			w[id]++;
	}
	cout << ans1 << " " << ans2 << endl;
	return 0;
}


Measured memory_bytes: 768
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N1 300005
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
using namespace std;


struct SEG{
int ma[N1<<2];
void pushup(int rt){ ma[rt]=max(ma[rt<<1],ma[rt<<1|1]); }
void upd(int l,int r,int x,int rt,int w)
{
	if(l==r){ ma[rt]=max(ma[rt],w); return;}
	int mid=(l+r)>>1;
	if(x<=mid) upd(l,mid,x,rt<<1,w);
	else upd(mid+1,r,x,rt<<1|1,w);
	pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
	if(L<=l&&r<=R) return ma[rt];
	int mid=(l+r)>>1,ans=0;
	if(L<=mid) ans=max(ans,query(L,R,l,mid,rt<<1));
	if(R>mid) ans=max(ans,query(L,R,mid+1,r,rt<<1|1));
	pushup(rt);
	return ans;
}
}s;

int n,K,a[N1],f[N1];

int main()
{
//	freopen("d.txt","r",stdin);
	scanf("%d%d",&n,&K);
	int l,r,ma=0,ans=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]), ma=max(ma,a[i]);
	for(int i=1;i<=n;i++)
	{
		l=max(0,a[i]-K), r=min(ma,a[i]+K);
		f[i]=s.query(l,r,1,ma,1)+1;
		ans=max(ans,f[i]);
		s.upd(1,ma,a[i],1,f[i]);
	}
	printf("%d\n",ans);
	return 0;
}



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

using namespace std;
typedef         long long int   ll;

#define         input           freopen("input.txt","r",stdin)
#define         output          freopen("output.txt","w",stdout)
#define         si(a)           scanf("%d",&a)
#define         sii(a,b)        scanf("%d%d",&a,&b)
#define         siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define         pi(a)           printf("%d",a)
#define         spc             printf(" ")
#define         bl              printf("\n")
#define         here(a)         printf("#### %d ####",a)
#define         pii             pair<int,int>
#define         fr(i,n)         for(int i=0;i<n;i++)
#define         case(num)       printf("Case %d:",num)
#define         inf             1000000050
#define         MAX             100010*2
#define         MOD             1000000007

vector<int>edge[MAX+10];
int cnt;
int visited[MAX+10];
void dfs(int s){
    visited[s] = 1;
    cnt++;

    for(int i=0;i<edge[s].size();i++){
        if(visited[edge[s][i]]==0){
            dfs(edge[s][i]);
        }
    }
}


int main(){

    //input;
    //output;

    int n,m,x,y;

    cin>>n>>m;

    for(int i=0;i<m;i++){
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(visited[i]==0){
            cnt = 0;
            dfs(i);
            ans = max(ans,cnt);
        }
    }

    cout<<ans<<endl;



    return 0;
}
/**
*/


Measured memory_bytes: 21504
import sys
sys.setrecursionlimit(10**9)

def stgsn(N, maked_num, now_num):
    if now_num != '':
        if int(now_num) > N:
            return

        maked_num.append(now_num)

    stgsn(N, maked_num, now_num + '7')

    stgsn(N, maked_num, now_num + '5')

    stgsn(N, maked_num, now_num + '3')

    return maked_num


def main():
    N = int(input())


    maked_num = []
    now_num = ''

    maked_num = stgsn(N, maked_num, now_num)

    ans = [s for s in maked_num if '3' in s and '5' in s and '7' in s]
    print(len(ans))


main()

Measured memory_bytes: 5388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=1e6+10,mod=998244353;
int n,a[N],f[N],p[N],top[N],e[N][10],dd[N],A[N],m;
ll ans;
void snt()
{
    forinc(i,2,N-10) if(!p[i])
    for(int j=i;j<=N-10;j+=i) p[j]=i;
    forinc(i,2,N-10)
    {
        int x=i;
        while(x!=1)
        {
            if(dd[p[x]]!=i) dd[p[x]]=i,e[i][++top[i]]=p[x];
            x/=p[x];
        }
    }
}
void add(int i,int s,int j,int o)
{
    if(i==top[j]+1) f[s]=(f[s]+j*o)%mod;
    else
    {
        add(i+1,s,j,o);
        add(i+1,s*e[j][i],j,o);
    }
}
int get(int i,int s,int j)
{
    if(i==top[j]+1) return f[s];
    return (get(i+1,s,j)-get(i+1,s*e[j][i],j))%mod;
}
main()
{
    //freopen("agc038_c.inp","r",stdin);
    //freopen("agc038_c.out","w",stdout);
    n=in;
    snt();
    forinc(i,1,n) a[in]++;
    forinc(i,1,N-10)
    {
        if(a[i]%2==0) ans=(ans+i*(a[i]/2)%mod*(a[i]-1))%mod;
        else ans=(ans+i*a[i]%mod*((a[i]-1)/2))%mod;
    }
    forinc(i,1,N-10)
    {
        for(int j=i;j<=N-10;j+=i) if(a[j])
        {
            int x=j/i;
            ans=(ans+j*a[j]%mod*get(1,1,x))%mod;
            add(1,1,x,a[j]);
        }
        for(int j=i;j<=N-10;j+=i) if(a[j]) add(1,1,j/i,-a[j]);
    }
    cout<<(ans+mod)%mod<<"\n";
}


Measured memory_bytes: 119168
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[101010];
set<int> S;
vector<int> seq;
int hate_count[101010];
set<pair<int, int>> hate; // # of hater, id

void emit()
{
	for (int i = 0; i < N; ++i) printf("%d%c", seq[i] + 1, i == N - 1 ? '\n' : ' ');
	exit(0);
}

void solve(int);

void step(int n, int pre, int v)
{
	if (n >= 1 && A[pre] == v) return;
	seq.push_back(v);
	S.erase(v);
	hate.erase({hate_count[v], v});

	solve(n + 1);

	hate.insert({hate_count[v], v});
	S.insert(v);
	seq.pop_back();
}

void solve(int n)
{
	if (n == N) {
		emit();
	}
	int pre = -1;
	if (n >= 1) pre = seq[n - 1];
	bool flg = false;
	if (pre != -1) {
		int nx = A[pre];
		if (hate.count({hate_count[nx], nx})) {
			flg = true;
			hate.erase(make_pair(hate_count[nx], nx));
			--hate_count[nx];
			hate.insert(make_pair(hate_count[nx], nx));
		}
	}

	bool sr = false;
	if (hate.size() > 0) {
		auto last = *--hate.end();
		//printf("%d, %d %d\n", n, last.first, last.second);
		if (last.first >= N - n) {

		} else if (last.first == N - n - 1) {
			step(n, pre, last.second);
		} else {
			sr = true;
		}
	}
	sr = true;

	if (sr) {
		for (int v = *S.begin(); ; ) {
			step(n, pre, v);
			auto nxt = ++S.lower_bound(v);
			if (nxt == S.end()) break;
			v = *nxt;
		}
	}

	if (pre != -1 && flg) {
		int nx = A[pre];
		hate.erase(make_pair(hate_count[nx], nx));
		++hate_count[nx];
		hate.insert(make_pair(hate_count[nx], nx));
	}
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", A + i); --A[i];
	}
	for (int i = 0; i < N; ++i) ++hate_count[A[i]];
	for (int i = 0; i < N; ++i) S.insert(i);
	for (int i = 0; i < N; ++i) hate.insert({hate_count[i], i});
	solve(0);

	puts("-1");
	return 0;
}


Measured memory_bytes: 23424
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

const int maxn = 205;
int a[maxn];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    int n = read(), L = read();
    int ans = INT_MAX;
    int cmp = INT_MAX;
    ll sum = 0;
    rep(i, 1, n) {
        a[i] = i + L - 1;
        sum += a[i];
    }
    for (int i = 1; i <= n; ++i) {
        int t = sum - a[i];
        int dif = abs(sum - t);
        if (dif < cmp) {
            ans = t;
            cmp = dif;
        }
    }
    cout << ans << endl;

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

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

using namespace std;

#define debug(a) cerr << #a << ": " << a << endl

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

#define x first
#define y second

const int N = 2e5 + 10;

int n, m;
char s[N];
vector<int> adj[N];
int cnt[N][2];
bool vis[N];
queue<int> q;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> m;
	scanf("%s", s + 1);

	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);

		adj[u].push_back(v);
		cnt[u][s[v] - 'A']++;

		adj[v].push_back(u);
		cnt[v][s[u] - 'A']++;
	}

	for (int i = 1; i <= n; i++) {
		if (cnt[i][0] == 0 || cnt[i][1] == 0)
			q.push(i);
	}

	while (!q.empty()) {
		int at = q.front();
		q.pop();

		if (vis[at]) continue;
		vis[at] = true;

		for (int adj_at : adj[at]) if (!vis[adj_at]) {
			cnt[adj_at][s[at] - 'A']--;
			if (cnt[adj_at][s[at] - 'A'] == 0) q.push(adj_at);
		}
	}

	int visited = accumulate(vis + 1, vis + n + 1, 0);
	if (visited < n) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

vector< bool > get_prime(int n){
  vector< bool > prime( n + 1, true);
  
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  
  for(int i = 2; i * i <= n; i++){
    if(prime[i]){
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }
  
  return(prime);
}

int main(){
    int h, w;
    char mas[60][60];
    cin >> h >> w;
    REP(i, h) REP(j, w) cin >> mas[i+1][j+1];
    bool flag = true;
    FOR(i, 1, h + 1) FOR(j, 1, w + 1){
        if(mas[i][j] == '#'){
            bool tmp = true;
            REP(k, 4){
                if(mas[i+dx[k]][j+dy[k]] == '#') tmp = false;
            }
            if(tmp) flag = false;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256