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

public class Main {

    static final long LIMIT = 1880L;
    static final int D = 365;
    static final int[] c = new int[27];
    static final int[][] s = new int[365][27];
    static final int[] ans = new int[365];
    static final int[] last = new int[27];
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int fla = 0;
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
            fla += c[i];
        }
        for (int i = 0; i < D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        Map<Integer, TreeSet<Integer>> lastMap = new HashMap<>();
        for (int i = 1; i <= 26; i++) {
            lastMap.put(i, new TreeSet<>());
            lastMap.get(i).add(0);
            lastMap.get(i).add(D+1);
        }
        StringBuilder sb = new StringBuilder();
        int score = 0;
        for (int i = 0; i < D; i++) {
            score -= fla;
            int max = score;
            int idx = 0;
            for (int j = 1; j <= 26; j++) {
                int tmp = score + s[i][j] +  c[j] *(i - last[j] + 1);
                if(max < tmp){
                    max = tmp;
                    idx = j;
                }
            }
            score = max;
            ans[i] = idx;
            last[idx] = i+1;
            lastMap.get(idx).add(i+1);
        }

        while(System.currentTimeMillis() - start < LIMIT){
            for (int i = 0; i < D; i++) {
                int prei = ans[i];
                int idx = prei;
                int max = s[i][prei] + c[prei] * (i - lastMap.get(prei).lower(i+1) +1) * (lastMap.get(prei).higher(i+1) - i -1);
                for (int j = 1; j <= 26; j++) {
                    if(j == prei)continue;
                    int tmp = s[i][j] + c[j] * (i - lastMap.get(j).lower(i+1) +1) * (lastMap.get(j).higher(i+1) - i -1);
                    if(max < tmp){
                        idx = j;
                        max = tmp;
                    }
                }
                if(prei != idx){
                    ans[i] = idx;
                    lastMap.get(prei).remove(i+1);
                    lastMap.get(idx).add(i+1);
                }
            }
        }


        for (int i = 0; i < D; i++) {
            sb.append(ans[i] + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 60236
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int a[200000];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	if (n % 2 == 0) {
		for (int i = n - 1; i >= 1; i -= 2) {
			cout << a[i] << " ";
		}
		for (int i = 0; i <= n - 2; i += 2) {
			cout << a[i] << " ";
		}
		cout << endl;
	}
	else {
		for (int i = n - 1; i >= 0; i -= 2) {
			cout << a[i] << " ";
		}
		for (int i = 1; i <= n - 2; i += 2) {
			cout << a[i] << " ";
		}
		cout << endl;
	}
 }

Measured memory_bytes: 2944
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')
import numpy as np

def main():
	n,m=MI()
	H=LI()
	G=[[] for _ in range(n+1)]
	for _ in range(m):
		a,b=MI()
		G[a].append(H[b-1])
		G[b].append(H[a-1])
	#print(G)
	
	ans=0
	for i in range(1,n+1):
		if G[i]==[]:
			ans+=1
		elif H[i-1]>max(G[i]):
			ans+=1
	print(ans)
	









if __name__=="__main__":
	main()


Measured memory_bytes: 40860
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
#define mod 1000000007
ll power(ll x,ll p){ll a=1;while(p>0){if(p%2==0){x*=x;p/=2;}else{a*=x;p--;}}return a;}
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 0, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll k) { ll a = 1, b = 1; rep(i, 0, k) { a = a * (n - i + 1) % mod; b = b * i % mod; }return a * mpower(b, mod - 2) % mod; }

const double PI = 3.14159265358979323846;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
	char t;
	deque<char> str;
	while (1) {
		scanf("%c", &t);
		if (t == '\n')break;
		str.push_back(t);
	}
	int c = 1, a = 0, b = 0;
	ll ans = 0, k;
	rep(i, 0, str.size() - 1) {
		if (str[i] == str[i + 1])c++;
		if(str[i] != str[i + 1] || i == str.size() - 2){
			ans += c / 2;
			c = 1;
		}
	}
	scanf("%lld", &k);
	ans *= k;
	c = 0;
	rep(i, 0, str.size()) {
		if (str[i] == str[0])c++;
		else break;
	}
	a = c;
	if (a == str.size()) {
		ans = a * k / 2;
	}
	else {
		if (str.front() == str.back()) {
			c = 0;
			for (int i = str.size() - 1; i >= 0; i--) {
				if (str[i] == str[str.size() - 1])c++;
				else break;
			}
			b = c;
			ans -= (a / 2 + b / 2) * (k - 1);
			ans += (a + b) / 2 * (k - 1);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

const int MAX_W = 10010;
const int MAX_N = 110;

int main() {
  int dp[MAX_W], w[MAX_N], v[MAX_N];
  int N, W, i, j;

  cin >> N >> W;

  for (i = 0; i < N; ++i) {
    cin >> v[i] >> w[i];
  }

  for (i = 0; i < MAX_W; ++i) {
    dp[i] = 0;
  }

  for (i = 0; i < N; ++i) {
    for (j = 0; j <= W; ++j) {
      if (j >= w[i]) {
        dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[W] << endl;

  return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL num[100][2];

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		for(j=0;j<60;j++){
			if(a&((LL)1<<j))num[j][0]++;
			else num[j][1]++;
		}
	}
	a=0;
	for(j=0;j<60;j++){
		a+=num[j][0]*num[j][1]%MAX*(((LL)1<<j)%MAX);
		a%=MAX;
	}
	cout<<a<<endl;
}

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

S = list(map(int, list(input().rstrip())))

# 先頭を0, 1 で二回走査すればいい

count = 0
before = 0
for i in range(len(S)):
    if S[i] == before:
        count += 1
    before ^= 1

ans = count

count = 0
before = 1
for i in range(len(S)):
    if S[i] == before:
        count += 1
    before ^= 1

ans = min(ans, count)

print(ans)


Measured memory_bytes: 4652
# C - H and V


def main():
    H, W, K = map(int, input().split())
    C = [int(input().replace(".", "0").replace("#", "1"), 2) for _ in range(H)]
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            (C[i] >> j) & 1 and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8988
#include <iostream>
#define ll long long
using namespace std;
int cnt_digits(ll N){
int digits=0;
while(N>0){
N/=10;
digits++;
}

 return digits;
 }

 int main(void){
 ll N;
 cin >> N;

 int ans=cnt_digits(N); // 1*N=N max(cnt_digits(1),cnt_digits(N))=cnt_digits(N)

 for(ll A=1LL;A*A<=N;++A){
 if(N%A!=0) continue;
 const ll B=N/A;

 const int cur=max(cnt_digits(A),cnt_digits(B));

 if(ans>cur){
 ans=cur;
 }
 }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  for (int i=0; i<N; i++) cin >> s.at(i);
  sort(s.begin(), s.end());
  int ans = accumulate(s.begin(), s.end(), 0);
  if (ans%10!=0) cout << ans << endl;
  else {
    bool all10 = true;
    for (int i=0; i<N; i++) {
      if (s.at(i)%10!=0) {
        all10 = false;
        ans -= s.at(i);
        break;
      }
    }
    if (all10) {
      ans = 0;
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int main() {
  string s;
  int k;
  cin>>s>>k;

  map<string, bool> m;
  for(int i=0; i<s.length(); i++) {

    for(int j=1; j<=min(k, (int)s.length()-i); j++) {
      m[s.substr(i,j)] = true;
    }
  }


  for(auto x : m) {
    if(k==1) {
      cout<<x.first<<endl;
      break;
    }
    k--;
  }
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <queue>
using namespace std;
#define tam 4995000
int dist[tam];
int main()
{
    memset(dist,-1,sizeof dist);
    queue<int> cola;
    int N,num;
    cin>>N;
    num=6;
    vector<int> vini;
    while(num<=N)
    {
        vini.push_back(num);
        num*=6;
    }
    num=9;
    while(num<=N)
    {
        vini.push_back(num);
        num*=9;
    }
    vini.push_back(1);
    for(int a=0;a<vini.size();a++)
    {
        //cout<<vini[a]<<" ";
        dist[vini[a]]=1;
        cola.push(vini[a]);
    }
    while(!cola.empty())
    {
        num=cola.front();
        cola.pop();
        if (num>N)
            continue;
        for(int a=0;a<vini.size();a++)
        {
            if (vini[a]+num<=N && dist[vini[a]+num]==-1)
            {
                dist[vini[a]+num]=dist[num]+1;
                cola.push(vini[a]+num);
            }
        }
    }
    cout<<dist[N]<<endl;
}
 

Measured memory_bytes: 19840
#include<iostream>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  long long ans = 0;
  long long i;
  for(i=K;i<=N+1;i++)ans = (ans + i*(N-i+1)+1)%1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	if(a==0)
		return b;
	return gcd(b%a,a);
}
int sol(int a,int b){
	return a*b/gcd(a,b);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	if(360%n==0)
		cout<<360/n;
	else{
		cout<<sol(360,n)/n;
	}
	return 0;
}


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

int p[101];

void solve(int n, int m) {
    for (int i = 1; i <= m; i++) {
        p[i] = 0;
    }
    int d, v;
    for (int i = 0; i < n; i++) {
        cin >> d >> v;
        p[d] = max(p[d], v);
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        ans += p[i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
        solve(N, M);
    }
    return 0;
}


Measured memory_bytes: 3012
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int count = 0;
			for(int i=0; i<N; i++) {
				String str = sc.next();
				if(str.equals("A")) {
					count++;
				} else {
					count--;
					if(count < 0) {
						System.out.println("NO"); 
						return;
					}
				}
			}
			if(count != 0) System.out.println("NO");
			else System.out.println("YES");
		}
	}
}



Measured memory_bytes: 26468
///HELLO THERE~!
///CREATED BY MD SADMAN MEHEDI SIVAN [IUT CSE(SWE)-19]

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

#define fastio          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define read            freopen("blue.txt","r",stdin);
#define write           freopen("red.txt","w",stdout);

using ll=long long;
using ull=unsigned long long;
const double pi = 2*acos(0.0);


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

   ll a[n+1];
   ll sum=0;
   map<ll,ll>mp;
   for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        mp[a[i]]++;
    }

   ll q;
   cin>>q;
   for(ll i=0;i<q;i++)
   {
       ll a,b;
       cin>>a>>b;
       sum=sum-a*mp[a]+b*mp[a];
       cout<<sum<<endl;
       mp[b]+=mp[a];
       mp[a]=0;

   }



    return 0;


}


Measured memory_bytes: 10280
# max(j)
N = int(input())
# i=1
c1 = list(map(int, input().strip().split()))
# i=2
c2 = list(map(int, input().strip().split()))

ans = 0
for j1 in range(N):
    sum = 0
    for j2 in range(N):
        if(j1 == j2):
            sum = sum + c1[j2] + c2[j2]
        elif(j1 < j2):
            sum += c2[j2]
        elif(j1 > j2):
            sum += c1[j2]
    ans = max(ans,sum)

print(ans)

Measured memory_bytes: 3064
s = input()
n = len(s)
num_center_pre = (n - 1) / 2
num_center = int(num_center_pre)
for i in range(num_center):
    if s[i] != s[n - i - 1]:
        print("No")
        exit(0)
    if s[i] != s[num_center - i - 1]:
        print("No")
        exit(0)
    if s[num_center + i + 1] != s[n - i - 1]:
        print("No")
        exit(0)
print("Yes")

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	double sm = 0;
	for(int i = 0; i < n; i++) {
		double a;
		cin>>a;
		sm += 1.0/a;
	}
	printf("%.9lf\n",1.0/sm);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=naive")
//#pragma GCC diagnostic ignored "-W"
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
char in[1005],in2[5];
int main(){
        scanf("%s%s",in,in2);
                int ans=0;
                F(i,0,3) if(in[i]==in2[i]) ans++;
                printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;



int main()
{
    int x,o;
    cin >> x;

    if (x < 600) {
        o = 8;
    }
    else if (x < 800) o = 7;
    else if (x < 1000) o = 6;
    else if (x < 1200) o = 5;
    else if (x < 1400) o = 4;
    else if (x < 1600) o = 3;
    else if (x < 1800) o = 2;
    else if (x < 2000) o = 1;

    cout << o;

    return 0;
}



Measured memory_bytes: 3616
def factorize(n):
    t = n
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while (t % i == 0):
            t //= i
            ret.append(i)
    if t > 1:
        ret.append(t)
    return ret


N = int(input())
d = []
for n in range(1, N + 1):
    d.extend(factorize(n))
d.sort()
ds = set(d)
dn = [0] * 101
for c in ds:
    dn[c] = d.count(c)
ans = 0
t = []
for i in ds:
    for j in ds:
        if i == j:
            continue
        for k in ds:
            if i == k or j == k:
                continue
            for l in [0, 2, 4, 14, 24, 74]:
                if l <= dn[i]:
                    for m in [0, 2, 4, 14, 24, 74]:
                        if m <= dn[j]:
                            for n in [0, 2, 4, 14, 24, 74]:
                                if n <= dn[k]:
                                    c = (l + 1) * (m + 1) * (n + 1)
                                    if c == 75:
                                        e = i ** l * j ** m * k ** n
                                        if not e in t:
                                            ans += 1
                                            t += [e]
print(ans)

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

struct Edge {
    ll to, cost;
};

bool bellman_ford(int n, int s, vector<vector<Edge> > &graph, vector<ll> &dist) { // nは頂点数、sは開始頂点

    dist[s] = 0; // 開始点の距離は0
    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int k = 0; k < graph[v].size(); k++) {
                Edge e = graph[v][k];
                if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = dist[v] + e.cost;
//                    if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
                }
            }
        }
    }
    return false;
}


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

    vector<vector<Edge>> graph(n);

    rep(i, m) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        c = -c;
        graph[a].push_back({b, c});
    }

    vector<ll> dist(n, INF);
    bellman_ford(n, 0, graph, dist);
    ll mi1 = dist[n - 1];
    bellman_ford(n, 0, graph, dist);
    ll mi2 = dist[n - 1];

    if (mi1 != mi2) {
        cout << "inf" << endl;
        ret();
    }
    ll mi = dist[n - 1];
    cout << -mi << endl;

}


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

int main() {

	//float A, B, H, M,kaku;
	double sum, rad, A, B, H, M, kaku;
	cin >> A >> B >> H >> M;

	H = 30.0 * H + 0.50 * M;
	M = 6.0 * M;

	if (H > M) {
		kaku = H - M;
		if (kaku > 180) {
			kaku = 360 - kaku;//check
		}
		else if (kaku == 180) {
			cout << A + B << endl;
			return 0;
		}
	}

	if (M > H) {
		kaku = M - H;
		if (kaku > 180) {
			kaku = 360 - kaku;
		}
		else if (kaku == 180) {
			cout << A + B << endl;
			return 0;
		}
	}

	if (M == H) {
		cout << abs(B - A) << endl;
		return 0;
	}

	rad = kaku * acos(-1) / 180.0;

	sum = sqrt(A*A + B*B - 2.0 * A*B*cos(rad));

	printf("%10.20f\n", sum);


}


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

int main() {
    int k, x;
    cin >> k >> x;

    for (int i = (x-k+1); i < (x+k); i++) {
        cout << i << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    int k;
    cin >> n >> s >> k;
    REP(i,n){
        if(s[i]==s[k-1]){
            cout << s[i];
        }
        else{
            cout << '*';
        }
    }
    cout << endl;
}

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

using namespace std;

int main(){
	int n, v, c, res=0;
	cin >> n;
	vector<int> v_arr, c_arr;
	for(int i=0; i<n; ++i){
		cin >> v;
		v_arr.push_back(v);
	}
	for(int i=0; i<n; ++i){
		cin >> c;
		c_arr.push_back(c);
	}
	// Find the maximum result
	for(int i=0; i<n; ++i){
		if((v_arr[i] - c_arr[i]) > 0){
			res += (v_arr[i] - c_arr[i]);
		}
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
// Includes

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cstdlib>

// Defines

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define mem(name, value) memset(name, value, sizeof(name))
#define f(i,a) for(int i=0;i<a;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int arr[100005][3],dp[100005][3];
int n;

int calc(int i,int k) {
    if(i==-1)
        return 0;
    if(dp[i][k]!=-1)
        return dp[i][k];
    return dp[i][k] = max(arr[i][k] + calc(i -1,(k+1)%3),arr[i][k] + calc(i - 1,(k+2)%3));
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    
    cin >> n;
    f(i,n) {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    mem(dp,-1);

    int a1 = calc(n-1,0);
    mem(dp,-1);
    int a2 = calc(n-1,1);
    mem(dp,-1);
    int a3 = calc(n-1,2);

    cout << max(a1,max(a2,a3)) << "\n";
    return 0;
}

Measured memory_bytes: 8832
class Q
	def initialize
		@h = [] # max-heap
	end

	def enq(v)
		@h.push(v)
		up_heap
	end

	def deq
		max, min = @h[0], @h.pop
		unless @h.empty?
			@h[0] = min
			dn_heap
		end
		return max
	end

	def all(&block)
		return @h.each(&block)
	end

private
	def up_heap
		i = @h.size-1
		loop {
			iP = (i-1)/2
			break unless 0 <= iP
			break unless @h[iP] < @h[i]
			@h[iP], @h[i] = @h[i], @h[iP]
			i = iP
		}
	end

	def dn_heap
		i = 0
		loop {
			iC1 = 2*i+1
			break unless iC1 < @h.size
			iC2 = iC1+1
			iC = @h.size <= iC2 ? iC1 : @h[iC1] < @h[iC2] ? iC2 : iC1
			break unless @h[i] < @h[iC]
			@h[i], @h[iC] = @h[iC], @h[i]
			i = iC
		}
	end
end

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

q = Q.new
A.each{|a|
	q.enq a
}
M.times{
	q.enq(q.deq/2)
}
p q.all.inject(&:+)


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

int main(){
	string s,t;
	while(cin >> s){
		t = "";
		for(int i=0;i<s.size();++i){
			if(s[i]=='@'){
				for(int j=0;j<s[i+1]-'0';++j)
					t+=s[i+2];
				i+=2;
			}
			else
			t+=s[i];
		}
		cout << t << endl;
	}
}

Measured memory_bytes: 1176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		ArrayDeque<int[]> que = new ArrayDeque<int[]>();
		int x, y, flag, xs = 0, ys = 0, count = 0;
		
		String string = reader.readLine();
		y = Integer.valueOf(string.split(" ")[0]);
		x = Integer.valueOf(string.split(" ")[1]);
		flag = Integer.valueOf(string.split(" ")[2]);
		
		char map[][] = new char[y][x];
		for(int i = 0; i < y; i++){
			map[i] = reader.readLine().toCharArray();
		}
		
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				if(map[i][j] == 'S'){
					ys = i;
					xs = j;
					j = x;
					i = y;
				}
			}
		}
		
		for(int i = 1; i <= flag; i++){
			boolean visit[][] = new boolean[y][x];
			que.addLast(new int[]{ys, xs, count});
			while(!que.isEmpty()){
				ys = que.getFirst()[0];
				xs = que.getFirst()[1];
				count = que.getFirst()[2];
				que.removeFirst();
				
				if(map[ys][xs] - '0' == i){
					que = new ArrayDeque<int[]>();
					break;
				}
				if(visit[ys][xs]) continue;
				visit[ys][xs] = true;
				
				if(ys + 1 < y && map[ys + 1][xs] != 'X'){ que.addLast(new int[]{ys + 1, xs, count + 1}); }
				if(ys - 1 >=0 && map[ys - 1][xs] != 'X'){ que.addLast(new int[]{ys - 1, xs, count + 1}); }
				if(xs + 1 < x && map[ys][xs + 1] != 'X'){ que.addLast(new int[]{ys, xs + 1, count + 1}); }
				if(xs - 1 >=0 && map[ys][xs - 1] != 'X'){ que.addLast(new int[]{ys, xs - 1, count + 1}); }
			}
		}
		System.out.println(count);
		reader.readLine();
	}
}

Measured memory_bytes: 96700
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <queue>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int N, M;
    std::cin >> N >> M;
    
    std::priority_queue<uint64_t> que;
    uint64_t A;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;
        que.push(A);
    }    

    int r = M;
    while (0 < r) {
        uint64_t buf = que.top();
        que.pop();
        que.push(buf / 2);
        --r;
    }

    uint64_t sum = 0;
    while (!que.empty()) {
        sum += que.top();
        que.pop();
    }

    std::cout << sum << std::endl;

    return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 11111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
    int n , a , b  , sum = 0 , k;
    ll ans = 0 ;
    scanf("%d %d %d" ,&n ,&a ,&b) ;

    for(int i = 1 ; i<=n ; i++) {
        k = i ;
        sum = 0 ;
        while(k){
            sum+=(k%10) ;
            k/=10 ;
        }
        if(sum>=a && sum <= b) ans+=(ll)i ;
    }
    printf("%lld\n" , ans) ;
    return 0 ;
}

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

using namespace std;

int main()
{
    int n, a, b, c, x;
    
    while (scanf("%d %d %d %d %d", &n, &a, &b, &c, &x) && n){
        int ctr = 0;
        
        for (int i = 0; i < n; i++){
            int y;
            scanf("%d", &y);
            
            while (ctr <= 10000){
                if (y == x){
                    if (i != n - 1){
                        x = (a * x + b) % c;
                        ctr++;
                    }
                    break;
                }
                x = (a * x + b) % c;
                ctr++;
            }
        }
        
        printf("%d\n", ctr <= 10000 ? ctr : -1);
    }
    
    return (0);
}

Measured memory_bytes: 1188
#include<iostream>
int main() {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    while (a > 0 && c > 0) {
        c -= b;
        if (c < 1) break;
        a -= d;
    }
    if (a < 1) std::cout << "No";
    else std::cout << "Yes";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int k[101];
int main(){
	int n,i,z=0;
	cin>>n;
	for(i=1;i<=n*2;i++)
		cin>>k[i];
	sort(k+1,k+n*2+1);
	for(i=1;i<=n*2;i+=2)
		z+=k[i];
	cout<<z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int in[5]={0},i,j,k,x,y;
    for(i=0;i<3;i++)
    {
        cin>>x>>y;
        ++in[x];
        ++in[y];
    }
    if(in[1]==0 || in[2]==0 || in[3]==0 || in[4]==0 || in[1]==3 || in[2]==3 || in[3]==3 ||in[4]==3)
    cout<<"NO";
    else
    cout<<"YES";
}


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

int main() {
  int x,n;cin>>x>>n;
  vector<int> p(n),vec(102);
  rep(i,n){
    cin>>p[i];
    vec[p[i]]++;
  }
  int cnt=1e9,ans=0;
  rep(i,102){
    if(vec[i]==0&&abs(x-i)<cnt){
      cnt=abs(x-i);
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl



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

    int N = S.size();
    int cnt0 = 0;
    int cnt1 = 0;
    rep(i, N) {
        if (i % 2 == 0 && S[i] != '0') cnt0++;
        if (i % 2 == 1 && S[i] != '1') cnt0++;
        if (i % 2 == 0 && S[i] != '1') cnt1++;
        if (i % 2 == 1 && S[i] != '0') cnt1++;
    }

    print(min(cnt0, cnt1));
    
}

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

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    string s;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0; i < n; ++i) {
        cin >> s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else if(s == "RE") re++;
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ac, wa, tle, re);

    return 0;
}

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

using namespace std;

bool cmp(int aa,int b)
{
	return aa>b;
}

int main()
{
	int a[100];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3,cmp);
	cout<<(a[0]*10+a[1]+a[2]);
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

vector<pair<ll, pair<ll, ll> > > edge[55];
pair<ll, ll> e[55];

ll dp[55][3000];

ll used[55];
ll dirty[55];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, m, s;
    ll i;
    memset(dirty, 0, sizeof(dirty));
    cin >> n >> m >> s;
    rep(i, n+1) { edge[i].clear(); }
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        edge[u].pb({v, {a, b}});
        edge[v].pb({u, {a, b}});
    }
    rep(i, n) {
        ll c, d;
        cin >> c >> d;
        e[i] = {c, d};
    }
    memset(dp, 0x5f, sizeof(dp));
    priority_queue<pair<ll, int> > que;
    que.push({0, 0});
    vector<ll> ans(n);
    rep(i, min(s+1, 3000ll)) dp[0][i] = 0;
    while (!que.empty()) {
        auto w = que.top();
        que.pop();
        ll dist(w.first), x(w.second);
        if (used[x] && !dirty[x]) { continue; }
        // if (used[x])  { continue; }
        dirty[x] = 0;
        used[x] = 1;
        ans[x] = dist; 
        for (ll i = 1; i <= 2500; i++) {
            dp[x][i] = min(dp[x][i], dp[x][max(i-e[x].first, 0ll)] + e[x].second);
        }
        rep(i, sz(edge[x])) {
            ll y = edge[x][i].first;
            ll costSilver = edge[x][i].second.first;
            ll costMin = edge[x][i].second.second;
            int flag1 = 0;
            if (used[y]) flag1 = 1;
            int flag2 = 0;
            for (int i = 0; i < 2500; i++) {
                ll ww = dp[x][i+costSilver]+costMin;
                if (ww < dp[y][i]) {
                    flag2 = 1;
                    dp[y][i] = ww;
                }
            }
            if (flag1 && !flag2) continue;
            if (flag1 && flag2) {
                 dirty[y] = 1;
            }
            que.push({dp[y][0], y});
        }
    }
    xrep(i, 1, n) {
        cout << dp[i][0] << endl;
    }
}


Measured memory_bytes: 5000
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  ll N;
  cin >> N;
  ll tmp;
  for(ll i=1; i*i<=N; i++){
    if(N%i==0) tmp = N/i;
  }
  int cnt = 0;
    while(tmp>0){
      tmp/=10;
      cnt++;
    }
  cout << cnt << endl;
}


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

using namespace std;

int C[100][100];

int main(){
  int N; cin >> N;
  for(int i=0;i<N;++i)
    for(int j=0;j<N;++j)
      cin >> C[i][j];
  long long ans=0;
  for(int i=0;i<N;++i)
    for(int j=i+1;j<N;++j)
      ans+=min(C[i][j],C[j][i]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3112
using System.Collections.Generic;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System;

namespace cysharp_test
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().solve();
        }

        void solve()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var A = input[0];var B = input[1]; var H = input[2];var M = input[3];

            double sita = Math.Min(Math.Abs(((double)H + (double)M / 60.00000000000) / 12.000000000000 - (double)M / 60.000000000000000), 1.000000000000 - Math.Abs(((double)H + (double)M / 60.00000000000) / 12.000000000000 - (double)M / 60.000000000000000));

            Console.WriteLine(Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) - 2.00000000 * (double)A * (double)B * Math.Cos(sita * 2.000000000 * Math.PI)));

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 20104
from itertools import accumulate
from operator import add
N = int(input())
S = input()

cnt_w = [0] * (N+1) # 左からWの数
for i in range(N): # cumsum
  if S[i] == "W":
    cnt_w[i+1] = cnt_w[i] + 1
  else:
    cnt_w[i+1] = cnt_w[i]
  
cnt_e = [0] * (N+1) # 右からEの数
for i in range(N-1, -1, -1):
  if S[i] == "E":
    cnt_e[i] = cnt_e[i+1] + 1
  else:
    cnt_e[i] = cnt_e[i+1]
    
ans = [w+e for w, e in zip(cnt_w, cnt_e)]
print(min(ans))

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

using namespace std;


int main() {

	long long a, n, mod = 1000 * 1000 * 1000 + 7, i;

	cin >> n;
	a = 1;

	for (i = 1; i <= n; i++) {
		a = a * i;
		a %= mod;
	}

	cout << a << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] ab = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            string[] AB = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
            // List<long> kl=new List<long>(hs.Keys);
            // kl.Sort();
            // foreach(long k in kl){
            //     s[1]-=hs[k];
            //     if(s[1]<1){Console.WriteLine("{0}",k);break;}
            // }
            if(AB[0]=="H"&&AB[1]=="H"){
                Console.WriteLine("H");
            }else if(AB[0]=="D"&&AB[1]=="D"){
                Console.WriteLine("H");
            }else{
                Console.WriteLine("D");
            }
        }
        //最小公倍数
        static long Lcm(long a, long b)
        {
            return a/Gcd(a,b)*b;
        }

        //最大公約数
        static long Gcd(long m, long n)
        {
            if(n==0)return m;
            return Gcd(n,m%n);
        }
    }
}


Measured memory_bytes: 11092
/*
* @Author: 王文宇
* @Date:   2018-03-17 20:00:26
* @Last Modified by:   王文宇
* @Last Modified time: 2018-03-17 20:48:52
*/
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x,y;
}a[122],b[122];
int n,g[122][122];
int linker[122];
bool used[122];
bool dfs(int u)
{
    int v;
    for(v=1;v<=n;v++)
        if(g[u][v]&&!used[v])
        {
            used[v]=true;
            if(linker[v]==-1||dfs(linker[v]))
            {
                linker[v]=u;
                return true;
            }    
        }  
    return false;  
}    
int hungary()
{
    int res=0;
    int u;
    memset(linker,-1,sizeof(linker));
    for(u=1;u<=n;u++)
    {
        memset(used,0,sizeof(used));
        if(dfs(u))  res++;
    } 
    return res;   
}     
int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y;
	for(int i=1;i<=n;i++)cin>>b[i].x>>b[i].y;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i].x<=b[j].x&&a[i].y<=b[j].y)g[i][j]=1;
		}
	}
	cout<<hungary()<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    for(i=n;i<=100003;i++){
        j = i;
        for(k=2;k*k<=j;k++){
            while(j%k==0){
                j/=k;
            }
        }
        if(j==i){
            cout << j << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main() {
    int w, a, b;
    int result = 0;

    cin >> w >> a >> b;
    if(b > a+w){
        result = b-(a+w);
    }else if(b+w < a){
        result = a-(b+w);
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
  long long int n,k;
  cin>>n>>k;
  n = n%k;
  long long int av = abs(n-k);
  while(n>av){
    n = min(n, av);
    av = abs(n-k);
  }
  
  cout<<n<<endl;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    int left = 0, right = s.size()-1;
    int ans = 0;
    while(left < right){
        if (s[left] == s[right]){
            left++; right--;
        }else if (s[left] == 'x'){
            left++;
            ans++;
        }else if (s[right] == 'x'){
            right--;
            ans++;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=200*1007;

int n;
vi graf[nax];

int wyn[nax];

map <int,int> mapa[nax];

int naj[nax];

int local[nax];

void dfs1(int v, int oj)
{
	//~ debug() << "   " << v << " " << oj;
	naj[v]=max(naj[v], v);
	for (int &i : graf[v])
	{
		if (i==oj)
		{
			swap(i, graf[v].back());
			graf[v].pop_back();
			break;
		}
	}
	for (int i : graf[v])
	{
		naj[i]=max(naj[i], naj[v]);
		dfs1(i, v);
		for (auto j : mapa[i])
		{
			if (j.first<naj[oj])
			{
				local[i]+=j.second;
			}
			else
			{
				break;
			}
		}
		while(!mapa[i].empty() && mapa[i].begin()->first<v)
		{
			auto it=mapa[i].begin();
			pii x=(*it);
			mapa[i].erase(it);
			mapa[i][v]+=x.second;
		}
		//~ debug() << v << " " << i << " " << mapa[i];
	}
	mapa[v][v]++;
	for (int i : graf[v])
	{
		if ((int)mapa[i].size()>(int)mapa[v].size())
			mapa[v].swap(mapa[i]);
		for (auto j : mapa[i])
			mapa[v][j.first]+=j.second;
	}
}

void dfs2(int v, int s)
{
	for (int i : graf[v])
		s+=local[i];
	wyn[v]=s;
	for (int i : graf[v])
		dfs2(i, s-local[i]+1);
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		graf[x].push_back(y);
		graf[y].push_back(x);
	}
	dfs1(1, 0);
	debug() << range(local+1, local+1+n);
	dfs2(1, 0);
	
	for (int i=2; i<=n; i++)
		printf("%d ", wyn[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 77824
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){

    string t; cin >> t;
    int ans = INF;
    for(char c = 'a'; c <= 'z'; c++){
        //cout << ":" << c << endl;
        int temp = 0;
        int n = t.size();
        string s = t;
        while(1){

            //終了判定
            bool flag = true;
            for(int i = 0; i < n; i++){
                if(s[i] != c){
                    flag = false;
                    break;
                }
            }
            if(flag){
                ans = min(ans, temp);
                break;
            }

            for(int i = 0; i < n - 1; i++){
                if(s[i] == c || s[i + 1] == c){
                    s[i] = c;
                }
            }

            s[n - 1] = '\0';
            n--;
            temp++;
            //cout << s << endl;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

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

    for(int i = 0; i < s.size()-1; i++)
    {
        if (s[i] == 'A' && s[i+1] == 'C')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll n,ans;
    cin>>n;
    ans=n+(n*n);
    ans+=(n*n*n);
        cout<<ans<<'\n';


    return 0;
}




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

int main()
{

    //データ定義
    int n;
    int i;
    int number[101];

    //データ入力
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> number[i];
    }
    //メイン処理
    for(i = 0; i < n; i++){
        cout << number[n - 1 - i];
        if(i != (n - 1)){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

int main(){
int n,m,x,y;
cin >> n>>m>>x>>y;

int x1[n],y1[m];
for(int i=0;i<n;i++)cin >> x1[i];
for(int i=0;i<m;i++)cin >> y1[i];
sort(x1,x1+n);
sort(y1,y1+m);

int xmax=x1[n-1];
int ymin=y1[0];
int flag=0;
for(int i=x+1;i<=y;i++){
if(xmax<i && i<=ymin){
flag=1;
break;
}
}

if(flag==0)
cout << "War";
else
cout << "No War";



}


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

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

  if(4*a*b < (c-a-b)*(c-a-b) && (c-a-b) > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main(){
  vector<vector<int>> c(3, vector<int>(3));
  for ( int i = 0; i < 3 ; i++){
    for ( int j = 0; j < 3; j++){
      cin >> c.at(i).at(j);
    }
  }
  
  int sum = 0;
  int ref = 0;
  
  for (int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if(i == j){
        sum += c.at(i).at(j);
        ref += c.at(i).at(j);
       }
      else sum+= c.at(i).at(j);
      
    }   
  }
  
  if (sum == 0 && ref == 0) cout << "Yes";
  else if (sum % ref == 0) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
def main():
    n = int(input())
    words = [input() for i in range(n)]

    words_count = {}
    for w in words:
        words_count.setdefault(w, 0)
        words_count[w] += 1
    ans = ''
    count = 0
    for w in words_count:
        count = words_count[w] if words_count[w] > count else count
    ans = []
    for w in words_count:
        if words_count[w] == count:
            ans.append(w)
    ans = sorted(ans)
    for w in ans:
        print(w)




if __name__ == '__main__':
    main()

Measured memory_bytes: 104400