akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll K) {
  ll x(7);
  ll ans(0);
  while (true) {
    ans++;
    if (x % K)
      x = (x * 10 + 7 ) % K;
    else
      break;
    if (ans > K) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll K;
  cin >> K;

  solve(K);

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int n;
int fibonaci(int n){
    static int F[44];
    int i;
    F[0]=1;
    F[1]=1;
    for(i=2;i<=n;i++){
        F[i]=F[i-2]+F[i-1];
    }
    return F[n];
}
int main(){
    scanf("%d",&n);
    printf("%d\n",fibonaci(n));
    
return 0;
}



Measured memory_bytes: 2108
/**
 * There is a start and there is no end in the space. ---Infinity.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the land.
 * It can be said that this is an final ultimatum from the god to the people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

const int N = 100010;

int a[N], b[N], c[N], d[N], A[N], n, k, vis[N], B[N], dis[N], C[N], D[N];
int t1[2][N], t2[2][N], t3[2][N], ans[7][N];
std::vector<int> v[N];

inline int Find(int x, int t) {
    int loop = v[vis[x]].size() - 1;
    t = (t + dis[x]) % loop;
    return v[vis[x]][t];
}

int main() {

    scanf("%d%d", &n, &k);
    k--;
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &b[i]);

    /// get A  c = b-1  d = a-1
    for(int i = 1; i <= n; i++) {
        c[b[i]] = i;
        d[a[i]] = i;
    }
    /*for(int i = 1; i <= n; i++) {
        printf("%d ", c[i]);
    }
    puts("");
    for(int i = 1; i <= n; i++) {
        printf("%d ", d[i]);
    }
    puts("");*/
    for(int i = 1; i <= n; i++) {
        A[i] = b[d[c[ a[i] ]]];
    }
    int t = k / 6;
    //printf("t = %d \n", t);
    /// get B = A^t
    for(int i = 1; i <= n; i++) {
        if(vis[i]) continue;
        /// !vis[i]
        int j = i;
        v[i].push_back(i);
        do {
            j = A[j];
            dis[j] = v[i].size();
            vis[j] = i;
            v[i].push_back(j);
        } while(j != i);
        dis[i] = 0;
    }
    for(int i = 1; i <= n; i++) {
        B[i] = t ? Find(i, t) : i;
    }

    /*printf("vis : \n");
    for(int i = 1; i <= n; i++) {
        printf("%d ", vis[i]);
    }
    puts("");

    printf("A : \n");
    for(int i = 1; i <= n; i++) {
        printf("%d ", A[i]);
    }
    puts("");*/

    memcpy(t1[0] + 1, B + 1, n * sizeof(int));
    memcpy(t1[1] + 1, B + 1, n * sizeof(int));
    memcpy(t2[0] + 1, a + 1, n * sizeof(int));
    memcpy(t2[1] + 1, b + 1, n * sizeof(int));
    for(int i = 1; i <= n; i++) {
        t3[0][t1[0][i]] = i;
        t3[1][t1[1][i]] = i;
    }

    for(int i = 1; i <= n; i++) {
        ans[0][i] = t1[0][t2[0][t3[0][i]]];
        ans[1][i] = t1[1][t2[1][t3[1][i]]];
    }
    t = k % 6;
    //printf("t = %d \n", t);
    for(int i = 2; i <= t; i++) {
        for(int j = 1; j <= n; j++) {
            ans[i][ans[i - 2][j]] = ans[i - 1][j];
        }
    }

    /*puts("");
    for(int i = 0; i <= 1; i++) {
        for(int j = 1; j <= n; j++) {
            printf("%d ", ans[i][j]);
        }
        puts("");
    }
    puts("");*/

    for(int i = 1; i <= n; i++) {
        printf("%d ", ans[t][i]);
    }

    return 0;
}


Measured memory_bytes: 12664
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c;
  cin >> a >> b >> c;

  bool is_ok = false;
  if (a == 5 && b == 5 && c == 7)
    is_ok = true;
  if (a == 5 && b == 7 && c == 5)
    is_ok = true;
  if (a == 7 && b == 5 && c == 5)
    is_ok = true;
  if (is_ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, n, a) for(int i = (a); i >= (n); i--)
#define mod 1e9+7
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, k;
  cin >> n >> k;
  int x[100005] = {};
  int mid = -1;
  rep(i, 0, n) {
    cin >> x[i];
    if(mid == -1 && x[i] >= 0) {
      mid = i;
    }
  }
  if(mid == -1) {
    cout << abs(x[n - k]) << endl;
    return 0;
  }
  if(k == 1) {
    int ans = x[mid];
    if(mid > 0) ans = min(ans, x[mid - 1]);
    cout << ans << endl;
    return 0;
  }
  int ans = 1145141919810;
  if(mid + k - 1 < n) ans = min(ans, x[mid + k - 1]);
  if(mid - k >= 0) ans = min(ans, abs(x[mid - k]));
  rep(i, 0, n) {
    if(i + k - 1 >= n) break;
    if(x[i] < 0 && x[i + k - 1] >= 0) {
      ans = min(ans, abs(x[i] * 2) + x[i + k - 1]);
      ans = min(ans, abs(x[i]) + x[i + k - 1] * 2);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int A[5], B[5];
    while ( cin >> A[0] && A[0] ) {
        int state = 1 << A[0];
        for ( int i = 1; i < 5; ++ i ) {
            cin >> A[i];
            state |= 1 << A[i];
        }
        if ( state == ( 1 << 1 | 1 << 2 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 1 ? 1 : 2;
            }
        } else if ( state == ( 1 << 2 | 1 << 3 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 2 ? 1 : 2;
            }
        } else if ( state == ( 1 << 3 | 1 << 1 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 3 ? 1 : 2;
            }
        } else {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = 3;
            }
        }
        for ( int i = 0; i < 5; ++ i ) {
            cout << B[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int isprime(int);

int main()
{
  int n,x,i,count;

  count = 0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&x);
    if(isprime(x))count++;
  }
  printf("%d\n",count);
  return 0;
}

int isprime(int x){
  int i;

  if(x == 2) return 1;
  if(x < 2 || x % 2 == 0) return 0;

  i =3;
  while(i <= sqrt(x)){
    if(x % i == 0) return 0;
    i = i + 2;
  }
  return 1;
}



Measured memory_bytes: 2048
import sys

N=input()
#print N
A=list(map(int,raw_input().split()))
A.sort()
#print A

hen=[]
tmp_hen=-1
for i in reversed(A):
	if len(hen)==2:
		break
	if tmp_hen==i:
		hen.append(i)
		tmp_hen=-1
	else:
		tmp_hen=i


if len(hen)<2:
	print 0
else:
	print hen[0]*hen[1]



Measured memory_bytes: 11320
/**
 * Title: D - Xor Sum 4
 * Url: https://atcoder.jp/contests/abc147/tasks/abc147_d
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long
#define MOD 1000000007

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    auto max_elm = max_element(a.begin(), a.end());
    ll keta = log2(*max_elm);
    long long res = 0;
    for(int d = 0; d <= keta; ++d){
        long long n0 = 0, n1 = 0;
        for(int i = 0; i < n; ++i){
            if((a[i] >> d) & 1) ++n1;   // d 桁目が 1
            else    ++n0;               // d 桁目が 0
        }
        long long tmp = (1ll << d) % MOD;   // 2^d
        // B の要素 (xor 演算を施した数) で d 桁目が 1 である個数
        long long n = n0 * n1 % MOD;
        // B の要素 (xor 演算を施した数) の d 桁目の総和 (= 2^d * n0 * n1)
        tmp = tmp * n % MOD;
        res = (res + tmp) % MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(){
	int n,nn;
	int nmax,nmin;
	vector<int> v(10000,0);
	vector<int> free;
	int point;
	int ss,s;

	while(1){
		cin >> n;
		cin >> nmin;
		cin >> nmax; 
		ss = 0;
		s = 0;
		nn = 0;

		if(n == 0 && nmax == 0 && nmin == 0){
			break;
		}

		for(int i = 0; i < n; i++){
			cin >> v[i];
		}
		
		for(int i = nmin - 1;i < nmax; i++){
			s = v[i] - v[i+1];
			if(i == nmin -1 || ss <= s){
				ss = s;
				nn = i+1;
			}
		}

		cout << nn <<endl;
	
	}
}

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




using namespace std;

vector<int> adj[500000];

int visited[500000] = {};

int k = 0;

int p[500000];

int x[500000];

int counter[500000] = {};
int flag = 0;


void DFS(int child,int sum)
{



    //visited[child] = 1;

    counter[child] = counter[child] + sum;
    sum = counter[child];

    for(int i = 0;i < adj[child].size();i++)
    {
        if(!visited[adj[child][i]])
        {

            DFS(adj[child][i],sum);


        }

    }

}


int main()
{
    int i;

    int prefix[500000];
    int n;

    int a,b;
    cin >> n;

    int q;

    cin >> q;



     for(i = 1;i <= n-1;i++)
    {
        cin >> a;
        cin >> b;
        //cout << "YO";
        adj[a].push_back(b); // Add p to i’s vector

    }


     for(i = 1;i <= q;i++)
    {
        cin >> p[i];
        cin >> x[i];

    }


     for(i = 1;i <=q;i++)
    {

        counter[p[i]] += x[i];

    }
    DFS(1,0);

     for(i = 1;i <= n;i++)
    {
       cout << counter[i] << " ";
    }




}
















Measured memory_bytes: 36352
program main
  implicit none
  
  integer :: n,i
  character*1 :: s(100)
  
  read(*,*)n
  read(*,*)(s(i),i=1, n)
  do i = 1, n
    if (s(i) == 'Y') then
      write(*,*)'Four'
      stop
    end if
  end do
  
  write(*,*)'Three'
end program main

Measured memory_bytes: 256
N, K = map(int, input().split())  # N個の寿司からK個
sushi = []
for i in range(N):
    t, d = map(int, input().split())  # 寿司の種類, 寿司の美味しさ
    sushi.append([t, d])

sushi.sort(key=lambda x: x[1], reverse=True)  # 美味しさで降順ソート
kind = set()
stack = []
ans = 0
for t, d in sushi[:K]:
    if t in kind:
        stack.append(d)
    else:
        kind.add(t)
    ans += d

ans += len(kind)**2
point = ans
for t, d in sushi[K:]:
    if len(stack) == 0:  # K個の寿司全てが1つずつしか存在しないなら交換しようがない
        break

    # 交換を行う
    if t in kind:
        continue
    else:
        point -= stack.pop()
        point += d
        point += 2*len(kind) + 1  # 平方の数列の階差
        kind.add(t)
    ans = max(ans, point)
print(ans)


Measured memory_bytes: 23056
#include <stdio.h>

int n, a, b, ta, tb;
char s[100001];

int main(void) {
    scanf("%d%d%d", &n, &a, &b);
    scanf("%s", s);
    
    for(int i=0; i<n; i++) {
        char t=s[i];
        if(t=='c') printf("No\n");
        else {
            if(t=='a') {
                if(ta < a+b) {
                    printf("Yes\n");
                    ta++;
                }
                else printf("No\n");
            }
            else {
                if(ta < a+b && tb<b) {
                    printf("Yes\n");
                    ta++;
                    tb++;
                }
                else printf("No\n");
            }
        }
    }
    
    return 0;
}

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

int main(){
  int s,yy,mm,y,m;
  cin >> s;
  y=m=0;
  yy=s/100;
  mm=s%100;
  if(mm>0 && mm<=12){
    m=1;
  }

  if(yy>0 && yy<=12){
    y=1;
  }
  if(y==1 && m==1){
    cout << "AMBIGUOUS" <<endl;
  }else if(m==1){
    cout << "YYMM" << endl;
  }else if(y==1){
    cout << "MMYY" <<endl;
  }else{
    cout << "NA" << endl;
  }
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
}
signed main(){
	ic(x) ic(y)
	if((x+y)%3!=0||x*2<y||y*2<x){
		c(0)
		return 0;
	}
	int wa=(x+y)/3;
	c(com(wa,x-wa))
}	

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

typedef struct {
	int a;
	int b;
} P;

int cmp(const void *a, const void *b){
	return ((P*)a)->a - ((P*)b)->a;
}

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);

	P p[100000];

	for(int n=0; n<N; n++){
		scanf("%d %d", &(p[n].a), &(p[n].b));
	}

	qsort(p, N, sizeof(P), cmp);

	unsigned long long int res = 0;
	int c = 0;

	while(M > 0){
		if(M <= p[c].b){
			res += (unsigned long long)p[c].a * M;
			M = 0;
		} else {
			res += (unsigned long long)p[c].a * p[c].b;
			M -= p[c].b;
			c++;
		}
	}

	printf("%llu\n", res);
}


Measured memory_bytes: 1788
#include<stdio.h>

int main(){
	int S,h,H,m,M,s;
	scanf("%d",&S);
	h = S / 3600;
	H = S % 3600;
	m = H / 60;
	M = H % 60;
	s = M;
	printf("%d:%d:%d\n",h,m,s); 
	return 0;
	
}

Measured memory_bytes: 592
def main():
    a = int(input()) # 500
    b = int(input()) # 100
    c = int(input()) #  50
    x = int(input())

    ans = 0

    for i in range(a+1):
        I = i*500
        for j in range(b+1):
            J = j*100
            for k in range(c+1):
                K = k*50
                if I+J+K == x:
                    ans +=1

    print(ans)

if __name__ == '__main__':
    main()


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

int n,k;
int* a;

int binary_search(){
	int l=0,r=n-1;
	int ans = 0;
	while(l<=r){
		int m = (l+r)/2;
		if(ans++,k == a[m])
			break;
		else if(k>a[m])
			l = m+1;
		else
			r = m-1;
	}
	return ans;
}

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		a = new int[n];
		for(int i=0; i<n; i++)
			cin >> a[i];
		cin >> k;
		cout << binary_search() << endl;
		delete[] a;
	}
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0 ;i < n ;i++)
        cin >> a[i];

    int prev = a[0] - 1;
    for (int i = 1 ;i < n ;i++) {
        if (a[i] < prev) {
            cout << "No";
            return 0;
        }

        if (a[i] - 1 >= prev)
            prev = a[i] - 1;
        else
            prev = a[i];
    }

    cout << "Yes";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    string t="";
    REP(i,n-1) t+='9';
    for ( char c=s[0]; c>'0'; c-- ) {
        string ans=t+c;
        reverse(ALL(ans));
        if ( ans<=s ) {
            cout << (c-'0')+9*(n-1);
            return 0;
        }
    }
    cout << 9*(n-1) << '\n'; 
    return 0;
}




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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 3e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, t;
pii a[N];
int mem[N][N];

int f(int n, int t){
	// cerr << "f(" << n << ", " << t << ")\n";
	if (n == 0) return 0;
	if (t <= 0) return 0;
	int &ret(mem[n][t]);
	if (ret != -1) return ret;
	ret = max(f(n-1, t), f(n-1, t-a[n].st) + a[n].nd);
	return ret;
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> t;
	for(int i=1; i<=n; i++) cin >> a[i].st >> a[i].nd;
	sort(a+1, a+n+1, greater<pii>());
	memset(mem, -1, sizeof mem);
	int ans = f(n, t);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35712
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	int N;
	string s, t;
	void ans() {
		cin >> N >> s >> t;
		REP(i, N) {
			if (s.substr(i) == t.substr(0, N - i)) {
				cout << N + i << "\n";
				return;
			}
		}
		cout << 2 * N << "\n";
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lc "\n"
#define forr(i,a,n)  for(ll i=a;i<n;i++)
using namespace std;

int main()
{
    IOS;
    int n,c=0;
    cin>>n;
    int a[n],b[n];
    forr(i,0,n)
    {
        cin>>a[i]>>b[i];

    }

    forr(i,0,n)
    {
        //cin>>a[i]>>b[i];
        if(a[i]==b[i]){c++;if(c==3){cout<<"Yes";return 0;}}
        else{c=0;}
    }
    cout<<"No";

    return 0;
}


Measured memory_bytes: 3636
import math
table=[[int(i) for i in input().split()] for i in range(3)]
r=[0]*3
for i in range(3):
    a=(table[i%3][0]-table[(i+1)%3][0])**2
    b=(table[i%3][1]-table[(i+1)%3][1])**2
    r[i]=math.sqrt(a+b)
s=sum(r)/2
t=s
for i in range(3):
    t*=(s-r[i])
t=math.sqrt(t)
x=t*2/(sum(r))
u=max(r)
print(x*u/(2*x+u))

Measured memory_bytes: 38384
/* date 18/05/19
*   Author: sir_code_a_lot
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007; //10e+7;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n,k;
     cin>>n>>k;
     string s;
     cin>>s;
      s[k-1]=tolower(s[k-1]);
      cout<<s<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int p[] = new int[n];

        for (int i=0; i<n; i++){
            p[i] = sc.nextInt();
        }

        int count=0;

        for (int i=0; i<n-2; i++){
            if (((p[i]<p[i+1])&(p[i+1]<p[i+2]))|((p[i]>p[i+1])&(p[i+1]>p[i+2]))){
                count++;
            }
        }

        System.out.println(count);


        }
    }


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, W;
vector<int> v(110);
vector<int> w(110);

vector<vector<int>> dp(110, vector<int>(10100, 0));

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> N >> W;
    REP(i, N) cin >> v.at(i) >> w.at(i);

    REP(i, N) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {
            if (sum_w >= w.at(i)) {
                chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w - w.at(i)) + v.at(i));
            }

            chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w));
        }
    }

    cout << dp.at(N).at(W) << endl;


    return 0;
}


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

const int maxn = 1e5 + 5;
const long long inf = 1e12;
long long N, W, w[maxn], v[maxn], dp[105][maxn];

int main() {
	cin >> N >> W;
	for (int i=1; i<=N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i=0; i<=N; i++) {
		for (int j=0; j<maxn; j++) {
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for (int i=1; i<=N; i++) {
		for (int j=0; j<maxn; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - v[i] < 0) continue;
			dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
		}
	}
	int ans = 0;
	// for (int i=1; i<=N; i++) {
	// 	for (int j=0; j<=10; j++) {
	// 		cout << (dp[i][j] == inf ? -1 : dp[i][j]) << ' ';
	// 	}
	// 	cout << "\n";
	// }
	for (int i=0; i<maxn; i++) {
		if (dp[N][i] <= W)
			ans = i;
	}
	// cout << dp[1][30] << "\n";
	cout << ans << "\n";
}

Measured memory_bytes: 82084
using System;

namespace ABC125_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array1 = Console.ReadLine().Split(' ');
            int a = int.Parse(array1[0]);
            string[] array2 = Console.ReadLine().Split(' ');
            int[] intAry2 = Array.ConvertAll<string, int>(array2, delegate (string value)
            {
                return int.Parse(value);
            });
            string[] array3 = Console.ReadLine().Split(' ');
            int[] intAry3 = Array.ConvertAll<string, int>(array3, delegate (string value)
            {
                return int.Parse(value);
            });
            int[] minus = new int[a];
            int max = 0;
            for(int i = 0; i < a; i++)
            {
                if(intAry2[i] > intAry3[i])
                {
                    minus[i] = intAry2[i] - intAry3[i];
                }
                max = max + minus[i];
            }

            Console.WriteLine(max);

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 

int main()
{
  ll n,t,c[200],z[200],ans;
  cin >> n >> t;
  ans=INF;
  rep(i,n)cin >> c[i] >> z[i];
  rep(i,n)if(z[i]<=t&&ans>c[i])ans=c[i];
  if(ans==INF)printf("TLE");
  else printf("%lld",ans);
}

Measured memory_bytes: 256
W, H, x, y = map(int,input().split())
area = W*H/2
flg = 0
if W % 2 == 0 and H % 2 == 0:
    if x == W // 2 and y == H // 2:
        flg = 1
print(str(area) + " " + str(flg))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n];
	memset(dp,0,sizeof dp);
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
h,w,k = list(map(int,input().split()))

c = []
count = 0
for i in range(h):
    cl = list(input())
    c.append(cl)
    count += cl.count("#")

hc = 2 ** h
wc = 2 ** w
result = 0

for i in range(hc):
    for j in range(wc):
        mc = 0
        hc2 = i
        hclis = []
        if i == 0:
            hclis = [0]
        while hc2 != 0:
            hclis.append(hc2 % 2)
            hc2 = hc2 // 2
        wc2 = j
        wclis = []
        if j == 0:
            wclis = [0]
        while wc2 != 0:
            wclis.append(wc2 % 2)
            wc2 = wc2 // 2
        for k1 in range(len(hclis)):
            if hclis[k1] == 1:
                mc += c[k1].count("#")
        for k2 in range(len(wclis)):
            if wclis[k2] == 1:
                for l in range(h):
                    if c[l][k2] == "#":
                        mc += 1
        for k1 in range(len(hclis)):
            for k2 in range(len(wclis)):
                if hclis[k1] == 1 and wclis[k2] == 1 and c[k1][k2] == "#":
                    mc -= 1

        if count - mc == k:
            result += 1

print(result)

Measured memory_bytes: 9148
def S(s):
    m = ["i", "x", "c", "m"]
    res = 0
    i = 0
    tmp = 1
    while i < len(s):
        if "2" <= s[i] <= "9":
            tmp = int(s[i])
        else:
            res += tmp * 10 ** m.index(s[i])
            tmp = 1
        i += 1
    return res
def main():
    m1 = ["i", "x", "c", "m"]
    s1, s2 = list(map(str, input().split()))
    ms1 = S(s1)
    ms2 = S(s2)
    ms = ms1 + ms2
    m = str(ms)
    m = m[::-1]
    res = ""
    for i in range(len(m)):
        if m[i] == "0":
            continue
        if m[i] == "1":
            res = m1[i] + res
            continue
        res = m[i] + m1[i] + res
    print(res)


n = int(input())
for _ in range(n):
    main()


Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = 0, b = 0, c = 0; // a>=b>=c
		while (sc.hasNext()) {
			String line = sc.nextLine();
			Scanner s = new Scanner(line);
			int h = s.nextInt();
			if (a < h) {
				c = b;
				b = a;
				a = h;
			} else if (b < h) {
				c = b;
				b = h;
			} else if (c < h) {
				c = h;
			}
		}
		System.out.println(a);
		System.out.println(b);
		System.out.println(c);
	}
}

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

public class Main {

	public static void main (String[] args) throws IOException
	{
	    
		BufferedReader br= new BufferedReader (new InputStreamReader(System.in) );
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int[] A= new int[2];
		int[] B  = new int[2];
		int max_low=0;
		int min_high=0;
		
		A[0] = Integer.parseInt(st.nextToken());
        A[1] = Integer.parseInt(st.nextToken());
        B[0] = Integer.parseInt(st.nextToken());
        B[1] = Integer.parseInt(st.nextToken());
		
		max_low=Math.max(A[0],B[0]);
		min_high= Math.min(A[1],B[1]);
		
		if (max_low>min_high)
			System.out.println("0");
		
		else
			System.out.println(min_high-max_low);
		
		
	}
}

Measured memory_bytes: 32676
N, M = map(int, input().split())
S = input()
T = input()

# len(S) >= len(T) にする
if N < M:
    S, T = T, S
    N, M = M, N

for j, t in enumerate(T):
    if j * N % M == 0:
        k = j * N // M
        s = S[k]
        if t != s:
            print('-1')
            exit()

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

GCD = gcd(N, M)
LCM = N * M // GCD

print(LCM)



Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
#define MAX_E 30005
#define NIL -1
#define WHITE 0
#define BLACK 1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll n, i, a;
    cin >> n;
    ll s[n+1];
    Map mp;
    mp[0]++;
    for(i=0; i<=n; i++)
        s[i]=0;
    for(i=1; i<=n; i++) {
        cin >> a;
        s[i]=s[i-1]+a;
        mp[s[i]]++;
    }
    
    ll ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        ans+=itr->second*(itr->second-1)/2;
    }
    
    prin(ans);
}

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


#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,x,a,dp[101],ans;

main() {
    cin >> n >> x >> a;
    rep(i,n) dp[i] = 10000000000000;
    dp[0] = a;
    rep1(i,n-1) {
        vector<int> v;
        cin >> a;
        v.pb(min(dp[0],a))
        rep1(j,i+1) v.pb(min(dp[j],dp[j-1]+a))
        rep(j,i+1) {
            dp[j] = v[j];
            if (dp[j] < x) {
                if (i == n-1) ans = max(ans,j);
                else ans = max(ans,j+1);
            }
            else if (dp[j] == x) ans = max(ans,j+1);
        }
    }
    ct(ans)
}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
d = {}
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for p, nl in enumerate(NL, start=1):
    d[p] = {}
    for i, n in enumerate(sorted(nl), start=1):
        d[p][n] = i

for p, y in IN:
    print('{:06d}{:06d}'.format(p, d[p][y]))



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

int main()
{
  long long L, R;
  cin >> L >> R;
  R = min(R, L + 2019);
    
  long long a = 2018;
  for (auto i = L; i <= R; i++) {
    for (auto j = i + 1; j <= R; j++) {
      long long x = i * j % 2019;
      a = min(a, x);
    }
  }
  cout << a;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        ll n,m;
        cin >> n; if(n==0) break;
        vector<ll> hp(n);
        for(ll& in:hp) cin >> in;
        cin >> m;
        vector<ll> consume(m),damage(m);
        vector<string> type(m);
        rep(i,0,m){
            string s;
            cin >> s >> consume[i] >> type[i] >> damage[i];
        }

        const ll sup=100001;
        ll ans=inf,dp1[sup],dp2[sup];
        fill_n((ll*)dp1,sup,inf);
        fill_n((ll*)dp2,sup,inf);
        dp1[0]=dp2[0]=0;
        rep(i,0,m){
            ll* dp;
            if(type[i]=="Single") dp=dp1;
            else dp=dp2;
            rep(j,0,sup) dp[j]=min(dp[j],dp[max(j-damage[i],0LL)]+consume[i]);
        }
        rep(i,0,sup){
            ll tmp=dp2[i];
            rep(j,0,n) if(hp[j]-i>=0) tmp+=dp1[hp[j]-i];
            ans=min(ans,tmp);
        }
        cout << ans << endl;
    }
}

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

Measured memory_bytes: 4736
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var P = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var Q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = 1, b = 1;
        var list = new List<int>(8);
        for (int i = 0; i < N; i++){
            var pi = P[i];
            var count = 0;
            if (list.Any())
                for (int j = 0, len = list.Count; j < len; j++){
                    var s = list[j];
                    if (s < pi) count++;}
            var x = pi - count;
            a += i == N - 1 ? 1 : (x - 1) * Factorial(N - 1 - i);
            list.Add(pi);}
        list.Clear();
        for (int i = 0; i < N; i++){
            var qi = Q[i];
            var count = 0;
            if (list.Any())
                for (int j = 0, len = list.Count; j < len; j++){
                    var s = list[j];
                    if (s < qi) count++;}
            var x = qi - count;
            b += i == N - 1 ? 1 : (x - 1) * Factorial(N - 1 - i);
            list.Add(qi);}
        var answer = Math.Abs(a - b);
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}

    public static int Factorial(int n){
        int result = 1;
        for (int i = n; i > 1; i--){
            result *= i;}
        return result;}}

Measured memory_bytes: 28176
# -*- coding: utf-8 -*-
#D - equeue
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, readline().split())
V = list(map(int,readline().split()))

ans = 0
for l in range(min(K,N)+1):
    for r in range(min(K,N)-l+1):
        res = K - (l+r)
        minus = [] 
        total = sum(V[:l])+sum(V[N-r:])
        for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
        for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
        minus.sort()
        S = len(minus)
        rep = sum(minus[:min(S+1,res)])
        total -= rep
        # print(l,r,total,rep)
        ans = max(total,ans)
print(ans) 

Measured memory_bytes: 74224
#include<stdio.h>                                                 
                                                                  
int main(void){                                                   
   int S;                                                         
   int W;                                                         
                                                                  
   scanf("%d %d",&S,&W);                                          
   if(S <= W){                                                    
      printf("unsafe");                                           
   } else {                                                       
      printf("safe");                                             
   }                                                              
   return 0;                                                      
}  

Measured memory_bytes: 1672
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        long minMove = Long.MAX_VALUE;
        for(long x = 1; x * x <= n; x++) {
        	if(n % x != 0) continue;
        	long y = n / x;
        	minMove = Math.min(minMove, Math.abs(x - 1) + Math.abs(y - 1));
        }
        System.out.println(minMove);
    }
}


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

int N;
int main(){
	cin >> N;
	vector<int> v(N+1,0);
	bool A[N+2] = {false};
	for(int i=1;i<=N;i++){
		cin >> v[i];
		if(v[i]==i) A[i] = true;
	}
	int j=1;
	int count = 0,ans = 0;
	while(j<=N+1){
		if(A[j]) count++;
		else{
			ans += (count+1)/2;
			count = 0;
		}
		j++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int a,b,c; cin >> a >> b >> c;

  if( a + b + c <= 21) cout << "win";
  else  cout << "bust";

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------        
    s = input()
    n = len(s)
    ans = 0
    if n % 2 == 0:
        for i in range(n//2):
            if s[i] != s[n-i-1]:
                ans += 1
    else:
        for i in range(n//2):
            if s[i] != s[n-i-1]:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 5688
#include <bits/stdc++.h>
#define cal(a,b) ((a+=b)%=mo)
using namespace std;
const int N=1<<17,mo=1e9+7;
int fap(int a,int b){
    int s=1;
    for (; b; b>>=1,a=1ll*a*a%mo)
	if (b&1) s=1ll*s*a%mo;
    return s;
}
int n,m,S,a[20],f[N],pl[N],nl[N],num[N];
int C(int x,int y){
    if (x<y) return 0;
    return 1ll*pl[x]*nl[y]%mo*nl[x-y]%mo;
}
int main(){
    cin>>n>>m,S=1<<n;
    for (int i=1; i<=m; ++i) cin>>a[i];
    f[0]=pl[0]=nl[0]=1;
    for (int i=1; i<=S; ++i) pl[i]=1ll*pl[i-1]*i%mo;
    nl[S]=fap(pl[S],mo-2);
    for (int i=S-1; i; --i) nl[i]=1ll*nl[i+1]*(i+1)%mo;
    f[0]=1;
    for (int i=m; i>=1; --i)
	for (int s=S-1; ~s; --s)
	    for (int j=0; j<n; ++j)
		if (s>>j&1)
		    cal(f[s],1ll*f[s^(1<<j)]*C(S-s-a[i]+(1<<j),(1<<j)-1)%mo*pl[1<<j]%mo);
    for (int i=1; i<S; ++i) num[i]=num[i>>1]+(i&1);
    int ans=0;
    for (int i=0; i<S; ++i)
	if (!(num[i]&1))
	    cal(ans,1ll*f[i]*pl[S-i-1]%mo);
	else
	    cal(ans,mo-1ll*f[i]*pl[S-i-1]%mo);
    for (int i=1; i<=n; ++i)
	cal(ans,ans);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define in(x) scanf("%d",&x)
#define inn(x,y) scanf("%d%d",&x,&y)
#define innn(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)

const int N=2e6+5;
const int mod=1e9+7;

ll n,m;
int main(){
    re n>>m;
    cout<<(n*(n-1)+m*(m-1))/2;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
double long a,b;
cin>>a;
cin>>b;
if((a && b)>=1)
	if(a>b)
	cout<<"GREATER";
	else if (a<b)
	cout<<"LESS";
	else if (a==b)
	cout<<"EQUAL";
    else
    return 0;
	
}

Measured memory_bytes: 256
N = input()
chk = 0
if len(N)%2 == 1:
  print("No")
else:
  for i in range(len(N)//2):
    if N[(2*i):(2*i+2)] != "hi":
      chk = 1
      break
    else:
      continue
  if chk == 1:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 38336
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

struct edge
{
    int to_node_idx;
    int to_money_idx;
    int cost;
};

// <コスト, 頂点の番号, 残高>
using P = pair<int, pair<int, int>>;

int N;                    //ノード数
vector<edge> G[51][2510]; //グラフ 都市番号と残高
int d[51][2510];          //最小コストを保存する配列

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que; //vector<P>の形でコスト昇順
    REP(i, N)                                     //コストをINFで初期化
    {
        REP(j, 2510)
        {
            d[i][j] = INF;
        }
    }
    d[0][s] = 0;                             //初期値へのコストは0
    que.push(make_pair(0, make_pair(0, s))); //初期値<コスト、頂点番号>

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int node = p.second.first;
        int money = p.second.second;
        if (d[node][money] < p.first)
            continue;

        for (int i = 0; i < G[node][money].size(); ++i) //vからいけるところ
        {
            edge e = G[node][money][i];
            if (d[e.to_node_idx][e.to_money_idx] > d[node][money] + e.cost) //コストが更新できればqueueに追加
            {
                d[e.to_node_idx][e.to_money_idx] = d[node][money] + e.cost;
                que.push(make_pair(d[e.to_node_idx][e.to_money_idx], make_pair(e.to_node_idx, e.to_money_idx)));
            }
        }
    }
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int M, S;
    cin >> N >> M >> S;
    S = min(S, 2500LL);
    REP(i, M)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        REP(money, 2501)
        {
            if (money >= a) //残高があれば移動できる
            {
                edge e = {v, money - a, b};
                G[u][money].push_back(e);
            }
        }
        REP(money, 2501)
        {
            if (money >= a) //残高があれば移動できる
            {
                edge e = {u, money - a, b};
                G[v][money].push_back(e);
            }
        }
    }
    REP(i, N)
    {
        int c, d;
        cin >> c >> d;
        REP(money, 2501)
        {
            edge e = {i, min(2500LL, money + c), d};
            G[i][money].push_back(e);
        }
    }
    dijkstra(S);
    REP(i, N - 1)
    {
        int ans = INF;
        REP(j, 2501)
        {
            ans = min(ans, d[i + 1][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 31088
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 vector<int> al,sl;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    int al=-1,sl=-1;
    int flag1=0,flag2=0;
    int maxs=0;
    for(int i=0;i<len;i++)
    {
        if(!flag1&&s[i]=='A')
        {
            flag1=1;
            al=i;
        }
        if(s[i]=='Z')
        {
            sl=i;
        }
       /* if(s[i]=='A')
        {
            al.push_back(i);
        }
        if(s[i]=='Z')
        {
           sl.push_back(i);
        }
        if(sl[sl.size()-1]>al[0]&&maxs<sl[sl.size()-1]-al[0]+1)
        {
            maxs=sl[sl.size()-1]-al[0]+1;
        }*/
    }
    cout<<sl-al+1<<endl;
    return 0;
}


Measured memory_bytes: 640