akhauriyash/Code-Regression huggingface dataset:
n,m = [int(i) for i in input().split()]
rang = []
lmax = 0
rmin = 10**10
for i in range(m):
    l,r = [int(i) for i in input().split()]
    lmax = max(l,lmax)
    rmin = min(r,rmin)

print(max(rmin - lmax + 1,0))

Measured memory_bytes: 3060
from bisect import bisect_left as bl

H,W,K=map(int,input().split())
s=[input() for _ in range(H)]

a=[[0 for _ in range(W)] for _ in range(H)]
OK=[]
NG=[]

n=0
for h in range(H):
    if "#" in s[h]:
        OK.append(h)
        n+=1
        f=s[h].index("#")
        for w in range(W):
            if w>f and s[h][w]=="#":
                n+=1
            a[h][w]=n
    else:
        NG.append(h)

if len(NG)>0:
    for n in NG:
        if n>max(OK):
            ref=max(OK)
        else:
            ref=OK[bl(OK,n)]
        for w in range(W):
            a[n][w]=a[ref][w]
for A in a:
    print(*A)

Measured memory_bytes: 12432
#include <iostream>

using namespace std;

int main()
{
  int x;
  int c;

  cin >> x;
  c = 0;

  if( x/100 == 1 ){
    c++;
    x -= 100;
  }
  if( x/10 == 1 ){
    c++;
    x -= 10;
  }
  if( x == 1 ){
    c++;
  }

  cout << c << endl;

  return 0;
}

  



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

struct info{
    int h,a;
    double rate;
    info(int h, int a, double r):h(h), a(a), rate(r){}
    info(){}
};
bool comp(const info& a, const info& b){
    return a.rate > b.rate;
}

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

    lli h,a,d,s;
    cin >> h >> a >> d >> s;
    vector<info> e(n);
    lli sum = 0, damage = 0;
    for(int i=0; i<n; i++){
        int eh,ea,ed,es;
        cin >> eh >> ea >> ed >> es;
        ea -= d;
        if(ea <= 0){
            e[i] = info(1, 0, 0);
            continue;
        }
        if(es > s){
            damage += ea;
        }
        if(a-ed <= 0){
            h = 0;
            continue;
        }
        eh = (eh+(a-ed)-1)/(a-ed);
        e[i] = info(eh, ea, (double)ea/eh);
        sum += ea;
    }
    if(h==0){
        cout << -1 << endl;
        return 0;
    }

    sort(e.begin(), e.end(), comp);
    for(int i=0; sum>0; i++){
        int limit = (h-damage)/sum;
        if(e[i].h > limit){
            h=0;
            break;
        }
        damage += sum*(e[i].h-1);
        sum -= e[i].a;
        damage += sum;
    }
    if(h <= damage){
        cout << -1 << endl;
    }else{
        cout << damage << endl;
    }
    return 0;
}

Measured memory_bytes: 3292
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M = map(int, readline().split())

WA = [0] * (N + 1)
AC = [False] * (N + 1)
for _ in range(M):
    p, S = readline().split()
    p = int(p)
    if AC[p]:
        continue

    if S == 'AC':
        AC[p] = True
    else:
        WA[p] += 1

for i in range(1, N + 1):
    if not AC[i]:
        WA[i] = 0

print(sum(AC), sum(WA))


Measured memory_bytes: 4596
K,N=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
k=0
Anew=[]
for i in range(1,N):
    Anew.append(abs(A[i]-A[i-1]))
Anew.append(abs(K-A[-1]+A[0]))
print(K-max(Anew))

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

int main() {
  set<string> s;
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    string str;
    cin >> str;
    s.insert(str);
  }
  printf("%d\n", s.size());
}

Measured memory_bytes: 19416
#include <iostream>
using namespace std;
int main()
{
	int n,s=0,f=0;
	cin >> n;
	int a[n];
	for (int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	while (f!=-1)
	{
		f=1;
		for (int i=0;i<n;i++)
		{
			if (a[i]==i+1) f=0;
		}
		if (f==1) break;
		if (a[0]==1) 
		{
			swap (a[0],a[1]);
			s++;
		}
		if (a[n-1]==n)
		{
			swap (a[n-1],a[n-2]);
			s++;
		}
		for (int i=1;i<=n-2;i++)
		{
			if (a[i]==i+1 && a[i+1]!=i+1)
			{
				swap(a[i],a[i+1]);
				s++;
			}
			if (a[i]==i+1 && a[i-1]!=i+1)
			{
				swap(a[i],a[i+1]);
				s++;
			}
		}
	}
	cout << s;
	return 0;
}

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

int
main()
{
	int n,m,output;
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for (long long i = n; i >= 1; i--) {
		m = (int)sqrt((double)i);
		if (m*m==i) {
			output = i;
			break;
		}
	}
	cout << output << endl;
}

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

struct vertex {
    int accum_weight;
    int state;
    bool isVisited;
};

int main() {
    int N; cin >> N;
    vector<vertex> vertices(N + 1);
    vector<vector<pair<int, int>>> adj(N + 1);
    for (int i = 1; i < N; i++) {
        int u, v, w; cin >> u >> v >> w;
        vertices[i].accum_weight = 0;
        vertices[i].state = 0;
        vertices[i].isVisited = false;
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
    }

    queue<int> que;
    que.push(1);
    vertices[1].isVisited = true;
    while(!que.empty()) {
        int from = que.front();
        que.pop();
        for (auto v : adj[from]) {
            int to = v.first;
            int weight = v.second;
            if (vertices[to].isVisited) continue;
            vertices[to].isVisited = true;
            que.push(to);
            vertices[to].accum_weight = vertices[from].accum_weight + weight;
            if (vertices[to].accum_weight % 2 == 0) vertices[to].state = 0;
            else vertices[to].state = 1;
        }
    }
    
    for (int i = 1; i <= N; i++) {
        cout << vertices[i].state << endl;
    }
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    int sumA = 0, count = N;
    for (int i=0; i<N; i++) {
        sumA += A[i];
    }
    if (sumA % (4*M) == 0) {
        for (int i=0; i<N; i++) {
            if (A[i] < sumA/(4*M)) {
                count--;
            }
        }
    }
    else {
        for (int i=0; i<N; i++) {
            if (A[i] <= sumA/(4*M)) {
                count--;
            }
        }
    }
    string ans = "No";
    if (count >= M) {
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
A,B,C= gets.split(" ").map!{|i | i.to_i} 

if (A==7 && B==5 && C==5) || (A==5 && B==7 && C==5) || (A==5 && B==5 && C==7)
  puts"YES"
else
  puts"NO"
end
  

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>


bool check(std::vector<int>& v, std::vector<std::vector<int> >& edge, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		bool flag = false;
		int k = v.at(i);
		for (int j = 0; j < edge.at(k).size(); j++)
		{
			if (v.at(i + 1) == edge.at(k).at(j))
			{
				flag = true;
				break;
			}
		}
		if (!flag)
			return false;
	}
	return true;

}

int main()
{
	int n, m;
	int count = 0;
	std::cin >> n >> m;
	std::vector<std::vector<int> > edge(n);
	std::vector<int> v;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		std::cin >> a >> b;
		a--;
		b--;
		edge.at(a).push_back(b);
		edge.at(b).push_back(a);
	}
	for (int i = 0; i < n; i++)
	{
		v.push_back(i);
	}

	do
	{
		if (v.at(0) != 0)
			break;
		if (check(v, edge, n))
			++count;
	}while (std::next_permutation(v.begin(),v.end()));
	std::cout << count << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX 100

long long fac[MAX], finv[MAX], inv[MAX];

//テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

//二項係数計算
long long COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    int n,p;
    cin >> n >> p;
    int a;
    int even = 0, odd = 0;
    REP(i,n){
        cin >> a;
        if(a % 2 == 0) even++;
        else odd++;
    }
    COMinit();
    ll ans = 0;
    for(int i = 0; i <= odd; i++){
        if(i % 2 == p){
            ans += COM(odd, i);
        }
    }
    REP(i,even){
        ans *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
     
    int main()
    {
      int a, b, c;
      int x;
      int i, j, k;
      int count = 0;
     
      scanf("%d", &a);  // 500円の枚数
      scanf("%d", &b);  // 100円の枚数
      scanf("%d", &c);  // 50円の枚数
      scanf("%d", &x);  // 合計金額
     
      for (i = 0; i <= a; i++) {
        for (j = 0; j <= b; j++) {
          for (k = 0; k <= c; k++) {
            int total = (500 * i) + (100 * j) + (50 * k);
            if (total == x) {
              count++;
            }
          }
        }
      }
     
      printf("%d\n", count);
     
      return 0;
    }

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

#include <cstdint>

template <long long Modulus> class modint {
  long long a;

public:
  constexpr modint(const long long x = 0) noexcept : a((x % Modulus + Modulus) % Modulus) {}
  constexpr long long val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr bool operator==(const modint rhs) const noexcept {
    return modint(*this).val() == rhs.val();
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    long long exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint = modint<MOD>;
typedef vector<mint> vec;
typedef vector<vector<mint>> mat;

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

  int n,k;
  cin >> n >> k;
 
  vector<int> a(n);
  REP(i,n) cin >> a[i];
 
  sort(a.begin(),a.end());
  
  vec fact(n+1,1);
  REP(i,n) fact[i+1] = fact[i]*(i+1);
 
  mint ans = 0;
  REP(i,n-k+1){
    ans -= fact[n-1-i]/fact[k-1]/fact[n-k-i]*a[i];
  }

  reverse(a.begin(),a.end());
  REP(i,n-k+1){
    ans += fact[n-1-i]/fact[k-1]/fact[n-k-i]*a[i];
  }
 
  cout << ans.val() << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    map<ll,ll> m;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }
    ll res=0;
    rep(i,n){
        if(m[a[i]]>a[i]){
            res+=m[a[i]]-a[i];
            m[a[i]]=a[i];
        }else if(m[a[i]]<a[i]){
            res+=m[a[i]];
            m[a[i]]=0;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 7040
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    var list = mutableListOf<Long>()
    list.add(2)
    list.add(1)
    for (i in 2..n) {
        list.add(list[i-1] + list[i-2])
    }
    print(list[n])
}

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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	int ans = min(A, B), tmp = 0;
	while (tmp < K) {
		if (A % ans == 0 && B % ans == 0) ++tmp;
		--ans;
	}
	// int ans = 0;
	// for (int i = 1; i < K; ) {
	// 	++ans;
	// 	if (A % ans == 0 && B % ans == 0) ++i;
	// }
	cout << ans + 1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] times = new int[n];
		for(int i=0; i<times.length; i++) {
			times[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[] solve = new int[m];
		int[] problem = new int[m];
		for(int i=0; i<m; i++) {
			problem[i] = sc.nextInt();
			solve[i] = sc.nextInt();
		}
		int[] sum = new int[m];
		for(int i=0; i<problem.length; i++) {
			int number = problem[i];
			int itime = solve[i];
			sum[i] += itime;
			for(int j=0; j<times.length; j++) {
				if(number-1 == j) {
					continue;
				}
				sum[i] += times[j];
			}
		}
		
		for(int i=0; i<m; i++) {
			System.out.println(sum[i]);
		}
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    long A;
    long double B;
    cin >> A >> B;

    long result;
    result = A * B;

    cout << result << endl;



}

Measured memory_bytes: 3732
import math

a,b,h,m=map(int,input().strip().split())
minDeg=m*6.0
hourDeg=h*30.0+(m/12.0)*6.0
degDif=0.0
ans=0
if abs(minDeg-hourDeg)==180:
  ans=a+b
elif abs(minDeg-hourDeg)==90:
  ans=math.sqrt(a**2+b**2)
elif abs(minDeg-hourDeg)>180:
  degDif=360.0-(abs(minDeg-hourDeg))
  ans=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(degDif)))
elif abs(minDeg-hourDeg)<180:
  degDif=abs(minDeg-hourDeg)
  ans=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(degDif)))
print(ans)
  

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int x;
  Repe(i,6,1){
    Scd(x);
    if(!x) printf("%lld\n",i);
  }
  
  return 0;
}


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

int main(){
    ll n;
    ll ans = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        // for (int j=i;j<=n;j += i+1)a[j]+=1;
        ll r = n/(i+1);
        ans += (i+1)*r*(1+r)/2;
    }
    rep(i,n)ans += (i+1)*a[i];
    cout << ans << endl;
}

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

using namespace std;

const int N = 3e5+7;

int n, m;
int cnt[N], sum[N];

int main()
{
    cin >> n;
    for (int i = 1, a; i <= n; ++i) {
        cin >> a;
        ++cnt[a];
    }
    sort(cnt+1, cnt+N);
    reverse(cnt+1, cnt+N);
    m = 1;
    while (cnt[m+1]) ++m;
    reverse(cnt+1, cnt+m+1);
    for (int i = 1; i <= m; ++i)
        sum[i] = sum[i-1]+cnt[i];

    for (int k = 1, l, r, mid; k <= n; ++k) {
        if (k > m) {
            cout << 0 << endl;
            continue;
        }
        l = 0; r = n;
        while (l < r) {
            mid = (l+r+1)>>1;
            int p = lower_bound(cnt+1, cnt+m+1, mid)-cnt-1;
            if (m-p >= k || sum[p]/(k-m+p) >= mid) l = mid;
            else r = mid-1;
        }
        cout << l << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int T = sc.nextInt();

        int[] c = new int[N];
        int[] t = new int[N];

        for (int i = 0; i < N; i++) {
            c[i] = sc.nextInt();
            t[i] = sc.nextInt();
        }


        int minC = (int) 1e8;

        for (int i = 0; i < N; i++) {
            if (t[i] <= T) {
                minC = Math.min(minC, c[i]);
            }
        }

        System.out.println(minC == (int) 1e8 ? "TLE" : minC);


    }
}


Measured memory_bytes: 23764
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int mi=0;
long long int N,res=0,abssum=0;
long long int A,B,C,K;
string S;

pll clo[200020],revclo[200020];
int main()
{
    cout << fixed << setprecision(18);
    cin>>S;
    if(S.length()==3){
        reverse(S.begin(),S.end());
    }
    cout<<S<<endl;
}    


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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();

	{
		string t;
		rep(i,n) if(s[i]!='x') t+=s[i];
		string r=t;
		reverse(r.begin(),r.end());
		if(t!=r) return puts("-1"),0;
	}

	int ans=0,l=0,r=n-1;
	while(l<r){
		if(s[l]=='x' && s[r]=='x'){
			l++;
			r--;
		}
		else if(s[l]=='x'){
			l++;
			ans++;
		}
		else if(s[r]=='x'){
			r--;
			ans++;
		}
		else{
			assert(s[l]==s[r]);
			l++;
			r--;
		}
	}
	printf("%d\n",ans);

	return 0;
}


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

const lli mod = 1e9+7;
lli n;

lli mod_fact(lli x){
	if(x == 0) return 1;
	return (x*mod_fact(x-1))%mod;
}

int main(void){
	cin >> n;
	cout << mod_fact(n) << endl;
	return 0;
}


Measured memory_bytes: 4944
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, K;
	std::cin >> N >> K;
	
	int value = 1;
	for (int i = 0; i < N; ++i) {
		if (value < K) {
			value *= 2;
		} else {
			value += K;
		}
	}
	std::cout << value << "\n";
}


Measured memory_bytes: 256
import math
a,b,x = [int(i) for i in input().split()]

if x <= (a**2*b)/2:
    height = x/(a*b)*2
    #余弦定理
    c = b**2 + height**2 - 2*b*height*math.cos(math.radians(90))
    h2 = b*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
elif x < (a**2*b):
    square = a**2*b-(a**2*b - x)*2
    triangle = (a**2*b-x)
    ratio = square/triangle/2 + 1
    d = b/ratio
    height = triangle/(a*d)*2
    c = d**2 + height**2 - 2*d*height*math.cos(math.radians(90))
    h2 = d*height / math.sqrt(c)
    theta = math.degrees(math.asin(h2/height))
    print(theta)
else:
    print(0)


Measured memory_bytes: 3188
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,j,n;
    scanf("%d",&n);
    
    for(i=1;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            j=i;
            while(j>0){
                if(j%10==3){
                    printf(" %d",i);
                    break;
                }
                j /= 10;
            }
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int Mod=998244353;
int a[100010],b[100010],n,m,k,sum,tmp[100010];
void power(int k)
{
	while(k)
	{
		if(k&1)
		{
			for(int i=1;i<=n;i++)tmp[i]=a[b[i]];
			for(int i=1;i<=n;i++)a[i]=tmp[i];
		}
		for(int i=1;i<=n;i++)tmp[i]=b[b[i]];
		for(int i=1;i<=n;i++)b[i]=tmp[i];
		k>>=1;
	}
	return;
}
signed main()
{
//	freopen("qwq.in","r",stdin);
//	freopen("qwq.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),b[i]=i;
	for(int i=n;i>=1;i--)a[i]=a[i]-a[i-1];
	scanf("%lld%lld",&m,&k);
	for(int i=1;i<=m;i++)
	{
		int x;
		scanf("%lld",&x);
		swap(b[x],b[x+1]);
	}
	power(k);
	for(int i=1;i<=n;i++)sum=sum+a[i],printf("%lld.0\n",sum);
}

Measured memory_bytes: 3840
n,m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(n)]
C.sort()
drinks = 0
price = 0
for i in range(n):
  if drinks+C[i][1] < m:
    drinks += C[i][1]
    price += C[i][0]*C[i][1]
  else:
    price += C[i][0]*(m-drinks)
    print(price)
    exit()

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i64 n;
  cin >> n;
  vector<i64> A(n);
  cin >> A;
  sort(ALL(A));
  i64 a = A[0];
  i64 z = A[n - 1];
  vector<pair<i64, i64>> res;
  REP(i, n) {
    if (i == 0 || i == n - 1) continue;
    if (A[i] >= 0) {
      res.push_back({ a, A[i] });
      a -= A[i];
    } else {
      res.push_back({ z, A[i] });
      z -= A[i];
    }
  }
  res.push_back({ z, a });
  cout << (z - a) << endl;
  for (auto p : res) {
    cout << p.first << " " << p.second << endl;
  }
}


Measured memory_bytes: 4720
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

s = input()
t = input()
if s == t[:-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9132
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n,k,q = mi()
    alist = [0 for i in range(100005)]
    for i in range(q):
        a = ii()
        alist[a]+=1
    
    for i in range(1,n+1):
        if alist[i] > q-k:
            print('Yes')
        else:
            print('No')
    


main()


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

typedef pair<int, int> ii;

int C[200005];
vector<int> colour[200005];

int cnt = 0;
ii rep[200005];

long long dp[200005];

const int MOD = 1e9+7;


int main(){
    // Shin Takarajima
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N; i ++){
        scanf("%d", &C[i]);
    }

    for(int i = 0; i < N; i ++){
        colour[C[i]].push_back(i);
    }

    for(int i = 1; i < 200001; i ++){
        for(int j = 1; j < (int)colour[i].size(); j ++){
            if(colour[i][j] - colour[i][j-1] > 1){
                rep[cnt++] = ii(colour[i][j], colour[i][j-1]);
            }
        }
    }
    sort(rep, rep+cnt);

    dp[0] = 1;
    int j = 0;
    for(int i = 1; i < N; i ++){
        dp[i] = dp[i-1];
        while(rep[j].first == i){
            dp[i] += dp[rep[j].second];
            j ++;
        }
        dp[i] %= MOD;
    }

    printf("%lld", dp[N-1]);

    return 0;
}


Measured memory_bytes: 14592
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String line[] = br.readLine().split(" ");
        //int intArray[] = new int[n];
        /*for (int i=0; i<n; i++){
            intArray[i] = Integer.parseInt(line[i]);
        }
        */
        int mi = Integer.MAX_VALUE;
        for (int i=0; i<n; i++){
            mi = Math.min(mi,Integer.parseInt(line[i]));
        }
        
        int ma = Integer.MIN_VALUE;
        for (int i=0; i<n; i++){
            ma = Math.max(ma,Integer.parseInt(line[i]));
        }
        
        long sum = 0;
        for (int i=0; i<n; i++){
            sum += Long.parseLong(line[i]);
        }
        System.out.printf("%s %s %s\n", mi , ma, sum);
    }
}

Measured memory_bytes: 25480
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


const int INF = 1<<29;

int N;
int a[10100];
int now[10100][2], next[10100][2];

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    cin >> N;
        for (int i = 0; i < N-1; ++i) cin >> a[i+1];
        for (int i = 0; i < 10100; ++i) now[i][0] = now[i][1] = INF;
        
        now[0][0] = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < 10100; ++j) next[j][0] = next[j][1] = INF;
            
            for (int j = 0; j <= N/2; ++j) {
                //cout << i << ", " << j << " : " << now[j][0] << ", " << now[j][1] << endl;
                
                chmin(next[j+1][0], now[j][0]);
                chmin(next[j][1], now[j][1]);
                
                chmin(next[j+1][0], now[j][1] + a[i]);
                chmin(next[j][1], now[j][0] + a[i]);
            }
            
            for (int j = 0; j < 10100; ++j) now[j][0] = next[j][0], now[j][1] = next[j][1];
        }   
         
        cout << min(now[N/2][0], now[N/2][1]) << endl;
    
    return 0;
}


Measured memory_bytes: 1356
#include <stdio.h>

struct Node{
  int parent;
  int left;
  int right;
};

struct Node node[25];

void setup(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    node[i].parent = -1;
    node[i].left = -1;
    node[i].right = -1;
  }
}

void input(struct Node node[], int n) {
  int id, cleft, cright;
  for (int i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &cleft);
    scanf("%d", &cright);
    node[id].left = cleft;
    node[id].right = cright;
    node[cleft].parent = id;
    node[cright].parent = id;
  }
}

void search_bro(struct Node node[], int id) {
  int oya;
  oya = node[id].parent;

  if (oya == -1) {
    printf("%d", oya);
    return;
  }
  else if (node[oya].left != id && node[oya].right == id) {
    if (node[oya].left != -1)
      printf("%d", node[oya].left);
    else
      printf("-1");
  }
  else {
    if (node[oya].right != -1)
      printf("%d", node[oya].right);
    else
      printf("-1");
  }
}

int search_deg(struct Node node[], int id) {
  int count = 0;
  if (node[id].left != -1)
    count++;
  if (node[id].right != -1)
    count++;
  return count;
}

int search_height(struct Node *node, int id) {
  int lheight = 0, rheight = 0;
  if (node[id].left == -1 && node[id].right == -1)
    return 0;
  else {
    if (node[id].left != -1)
      lheight = 1 + search_height(&node[0], node[id].left);
    if (node[id].right != -1)
      rheight = 1 + search_height(&node[0], node[id].right);
    if (lheight >= rheight)
      return lheight;
    else
      return rheight;
 }
}

void search_type(struct Node node[], int id) {
  if (node[id].parent == -1)
    printf("root");
  else if (node[id].left != -1 || node[id].right != -1)
    printf("internal node");
  else
    printf("leaf");
}

int search_dep(struct Node node[], int id) {
  int dep = 0;
  while (node[id].parent != -1) {
    dep++;
    id = node[id].parent;
  }
  return dep;
}

void output(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    printf("node %d: parent = %d, ", i, node[i].parent);
    printf("sibling = ");
    search_bro(node, i);
    printf(", ");
    printf("degree = %d, ", search_deg(node, i));
    printf("depth = %d, ", search_dep(node, i));
    printf("height = %d, ", search_height(&node[0], i));
    search_type(node, i);
    printf("\n");
  }
}

int main(void) {
  int n;
  
  scanf("%d", &n);

  setup(node, n);
  input(node, n);

  output(node, n);
  
  return 0;
}



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

using namespace std;

int  main(void) {

    int N, K = 0;
    cin >> N;
    cin >> K;

    int *p = NULL;
    p = (int*)malloc(sizeof(int)*N);
    for( int ii = 0; ii < N; ii++ ) {
        cin >> p[ii];
    }

    std::sort( p, p + N );

    int sum = 0;
    for( int ii = 0; ii < K; ii++ ) {
        sum = sum + p[ii];
    }

    cout << sum;

    if( p != NULL ) {
        free(p);
    }

    return 0;
}

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

void pri(){
  for(int i=0; i<20; i++) cout <<"#";
  cout << endl;
}

int main(){

  int n; cin >> n;
  int m[5][4][11]={};
  for(int i=0; i<n; i++){
    int b,f,r,v;
    cin  >> b >> f >> r >> v;
    m[b][f][r] += v;
  }
  for(int i=1; i<5; i++){
    for(int j=1; j<4; j++){
      for(int k=1; k<11; k++){
	cout << " " << m[i][j][k];
      }
      cout << endl;
    }
    if(i!=4)
      pri();
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int a[10][10];
int main() {
	int n, i=0, j=0, t, ans=0;
	cin>>n;
	for(i=1; i<=n; i++){
		t=i;
		while(t>9)
		t/=10;
		a[t][i%10]++;
	}
	for(i=1; i<=9; i++){
		for(j=1; j<=9; j++){
			ans+=a[i][j]*a[j][i];
		}
	}
	cout<<ans;
}

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

int main() {
	// your code goes here
	long long a,b,x;
	cin >> a >> b >> x;
	if(a==0){
		cout << (b/x+1) << endl;
	}
	else cout << (b/x-(a-1)/x) << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a_1,a_2,a_3;
  int sum;
  
  scanf("%d %d %d",&a_1,&a_2,&a_3);
  sum = a_1+a_2+a_3;
  
  if(sum>21){
    printf("bust");
  }
  else{
    printf("win");
  }
  return 0;
}

Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<cmath>
using namespace std;
using ll = long long;
using P = pair<double,double>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
}
double size(double x,double y){
  return sqrt(x*x+y*y);
}
void solve(P p,P p1,P p2){
  double nume = (p.first-p1.first)*(p2.first-p1.first) 
    + (p.second-p1.second)*(p2.second-p1.second);
  double deno = size(p2.first-p1.first,p2.second-p1.second);
  deno *= deno;
  double d = nume / deno;
  cout << p1.first + (p2.first-p1.first)*d <<" "<<
    p1.second + (p2.second-p1.second)*d << endl;
}
signed main(){
  init_io();
  double xp1,yp1,xp2,yp2,x,y;
  cin >> xp1 >> yp1 >> xp2 >> yp2;
  P p1 = P(xp1,yp1),p2 = P(xp2,yp2);
  ll q;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> x >> y;
    solve(P(x,y),p1,p2);
  }
}



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

int main() {
    int64_t a,b,x;
    cin >> a >> b >> x;
    int64_t n;
    if(a!=0) n = b/x - (a-1)/x;
    else n = b/x + 1;
    cout << n << endl;;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
   int x;
   int c1=0;
   int c2=0;
   scanf("%d",&x);
   if(x>=500){
   while(x>=500){
      x=x-500;
      c1++;
   }
   }
   
   if(x<500){
   while(x>=5){
      x=x-5;
      c2++;
   }
   }
   
   int a=c1*1000+c2*5;
   printf("%d",a);
   return 0;
}


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

int main(){
  int N, K, l, m = 0;
  string S, s, a = "10", b = "01";
  vector<int> A, B(1);
  bool flag = true;
  cin >> N >> K;
  cin >> S;
  
  if (S.at(0) == '0'){
    A.push_back(0);
  }
  
  for (int i = 0; i < N-1; i++){
    s = S.substr(i,2);
    if (s == b){
      B.push_back(i+1);
    }
    else if (s == a){
      A.push_back(i+1);
    }
  }
  
  A.push_back(N);
  l = A.size();
  
  for (int i = 0; i < l-K; i++){
    m = max(A.at(min(i+K, l-1)) - B.at(i), m);
    flag = false;
  }
  if (flag){
    cout << N << endl;
  }
  else{
    cout << m << endl;
  }
}

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i, m, n) for(int (i)=(m);(i)<(n);(i)++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	puts((b - a) % 2 == 0 ? "Alice" : "Borys");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
x, a, b = map(int, input().split())
n = int(input())
for _ in range(n):
    s = input()
    if s == 'nobiro':
        x = max(0, x + a)
    elif s == 'tidime':
        x = max(0, x + b)
    else:
        x = 0
print(x)



Measured memory_bytes: 5600
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    X is 3 * A * A,
    writeln(X).


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

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){

    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



Measured memory_bytes: 4452
N, T = map(int, input().split())

A = []
B = []
for _ in range(N):
    aa, bb = map(int, input().split())

    A.append(aa)
    B.append(bb)

dp1 = [[0] * (T) for _ in range(N + 1)]

for x in range(1, N + 1):
    for y in range(1, T):
        if y >= A[x - 1]:
            dp1[x][y] = max(dp1[x - 1][y], dp1[x - 1][y - A[x - 1]] + B[x - 1])
        
        else:
            dp1[x][y] = dp1[x - 1][y]

dp2 = [[0] * (T) for _ in range(N + 2)]

for x in range(N, 0, -1):
    for y in range(1,T):
        if y >= A[x - 1]:
            dp2[x][y] = max(dp2[x + 1][y], dp2[x + 1][y - A[x - 1]] + B[x - 1])

        else:
            dp2[x][y] = dp2[x + 1][y]

MAX = -1
for x in range(1, N + 1):
    for y in range(T):
        MAX = max(MAX, dp1[x - 1][y] + dp2[x + 1][T - 1 - y] + B[x - 1])

print(MAX)

Measured memory_bytes: 178564
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main() {
	char a[10];
	cin>>a;
	if(a[0]=='S') cout<<"Cloudy";
	if(a[0]=='C') cout<<"Rainy";
	if(a[0]=='R') cout<<"Sunny";
	return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A(n);
    int cnt_2n = 0, cnt_4n = 0;
    rep(i, n) {
        int a;
        cin >> a;

        int g = my_gcd(a, 4);
        if (g == 1) continue;
        else if (g == 4) ++cnt_4n;
        else ++cnt_2n;
    }
    if (n == 3) {
        if (cnt_4n >= 1 || cnt_2n == 3) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    if (cnt_4n >= n / 2 || cnt_2n == n || 2 * cnt_4n + cnt_2n >= n) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

const int N = 1e5 + 5;
int in[N];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> in[i];

    int x = 1, res = 0;

    int k = 0;
    while(k <= n) {
        k++;
        int nx = in[x];
        res++;
        if(nx == 2) return !printf("%d\n", res);
        if(nx == x) return !printf("-1");
        x = nx;
    }
    puts("-1");
}

Measured memory_bytes: 640
import collections
n, k = map(int, input().split())
dat = list(map(int, input().split()))
maze = []
initmaze=[]
recurmaze=[]
used = [-1] * (n + 10)
cur = 0
cnt = 0
while True:
    if used[cur] != -1:
        break
    used[cur] = cnt
    maze.append(cur)
    cur = dat[cur] - 1
    cnt += 1

recurpoint = used[cur]
#print("return to ",recurpoint)
initmaze = maze[:recurpoint]
recurmaze = maze[recurpoint:]

#print(maze)
#print(initmaze)
#print(recurmaze)

l = len(maze)
li = len(initmaze)
lr = len(recurmaze)
if k < li:
    print(initmaze[k] + 1)
else:
    k -= li
    print(recurmaze[k%lr] + 1)



Measured memory_bytes: 98472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

void solve(string N);

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

void solve(string N){
    rep(i,3){
        if(N[i]=='7'){
            cout<<YES<<endl;
            return;
        }
    }
    cout<<NO<<endl;
}



Measured memory_bytes: 3660
n,k=map(int,input().split())
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
alre=[-1]*n
alre[0]=1
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if alre[tmp]==-1:#tmp not in num2city.values():#現在地がまだきたことない
        alre[tmp]=1
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print(tmp+1)



Measured memory_bytes: 153972
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace<'a>) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: u64 = iter.read();

	use std::collections::BTreeMap;

	let mut map: BTreeMap<String, u64> = BTreeMap::new();

	for i in 1..(n + 1) {
		let s: String = iter.read();
		let p: u64 = iter.read();
		let key = format!("{}={}", s, 2000 - p);
		map.insert(key, i);
	}

	for &v in map.values() {
		println!("{}", v);
	}
}


Measured memory_bytes: 4352