akhauriyash/Code-Regression huggingface dataset:
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;


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

	string S1, S2;
	cin >> S1 >> S2;


	vector<int> p;


	for (int i = 0; i < S1.size(); ++i)
	{

		if (i == S1.size() - 1 || S1[i] != S1[i + 1])
		{
			p.emplace_back(1);
		}
		else
		{
			p.emplace_back(2);
			++i;
		}

	}

	
	ll ans = 1;
	int pre;

	if (p[0] == 1)
	{
		ans = 3;
		pre = 1;
	}
	else
	{
		ans = 6;
		pre = 2;
	}

	for (int i = 1; i < p.size(); ++i)
	{

		if (pre == 1 && p[i] == 1)
		{
			ans = (ans * 2) % 1000000007;
			pre = 1;
		}
		else if (pre == 1 && p[i] == 2)
		{
			ans = (ans * 2) % 1000000007;
			pre = 2;
		}
		else if (pre == 2 && p[i] == 1)
		{
			pre = 1;
		}
		else if (pre == 2 && p[i] == 2)
		{
			ans = (ans * 3) % 1000000007;
			pre = 2;
		}

	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  string ans = "APPROVED";
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        ans = "DENIED";
        break;
      }
    }
  }
  cout << ans;
}



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

using namespace std;

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

int main() {
    ll n, m, i, j, k;
    cin >> n;
    string s;
    cin >> s;
    ll cnt[3][n+1];
    for(i=0;i<3;i++){
        for(j=0;j<=n;j++)cnt[i][j]=0;
    }
    for(i=0;i<n;i++){
        if(s[i]=='R'){
            cnt[0][i+1]++;
        }
        else if(s[i]=='G'){
            cnt[1][i+1]++;
        }
        else cnt[2][i+1]++;
    }
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            cnt[j][i+1]+=cnt[j][i];
        }
    }
    ll ret = 0;
    map<char,int> mp;
    mp['R']=0;
    mp['G']=1;
    mp['B']=2;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            ll x=j-i;
            if(s[i]!=s[j]){
                ret += cnt[3 - mp[s[i]] - mp[s[j]]][n] - cnt[3 - mp[s[i]] - mp[s[j]]][j+1];
                if(j+x<n&&s[j+x]!=s[i]&&s[j+x]!=s[j])ret--;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3708
import java.util.*;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if( a == b ){
			System.out.println("Draw");
		}else if( a == 1 ){
			System.out.println("Alice");
		}else if( b == 1 ){
			System.out.println("Bob");
		}else if( a > b ){
			System.out.println("Alice");
		}else if( a < b ){
			System.out.println("Bob");
		}
	}	
}



Measured memory_bytes: 23892
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
  a, b = map(lambda x: int(x)-1, input().split())
  G[a].append(b)

for v in G[0]:
  for nv in G[v]:
    if nv == N-1:
      print("POSSIBLE")
      exit()
print("IMPOSSIBLE")

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

typedef long long ll;

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

    ll x,y;
    cin >> x >> y;
    ll ans = 0;
    while(x<=y){
        ans++;
        x *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
template <typename T>
void warshall_floyd(vector<vector<T>> &g, T inf) {
    rep(k, g.size()) {
        rep(i, g.size()) {
            rep(j, g.size()) {
                if (g[i][k] == inf || g[k][j] == inf) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

/*
vector<vector<ll>> G(V, vector<ll>(V,INF));
rep(i,V) G[i][i]=0;
rep(i,E)G[from][to]=cost;
warshall_floyd(G, )
*/
int main() {
    init();
    ll N;
    cin>>N;
    vvc<ll> G(N, vl(N,INF)), A(N, vl(N));
    rep(i, N) rep(j, N) cin >> A[i][j];

    rep(i, N) rep(j, N) G[i][j] = A[i][j];
    warshall_floyd(G, INF);

    ll ans = 0;
    bool isok = true;
    rep(i,N-1)repe(j,i+1,N){
        ll tmpmin = INF;
        rep(k,N){
            if (k == i || k == j) continue;
            chmin(tmpmin, G[i][k] + G[k][j]);
        }
        if (tmpmin < A[i][j])
            isok = false;
        else if(tmpmin>A[i][j])
            ans += A[i][j];
    }

    cout << (isok?ans:-1) << endl;
}

Measured memory_bytes: 1664
#include <iostream>

int main() {
  int h, w;
  while (std::cin >> h >> w, h | w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        std::cout << ((i + j) % 2 ? "." : "#");
      }
      std::cout << "\n";
    }
    std::cout << std::endl;
  }
}


Measured memory_bytes: 3080
/*input
4
ushi
tapu
nichia
kun

*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    map<string,int> mx;
    for(int i=0;i<n;i++){
    	string s;cin>>s;
    	mx[s]++;
    }
    int ans = 0;
    for(auto i:mx)ans = max(i.second,ans);
    vector<string> res;
    for(auto i : mx){
    	if(i.second==ans)res.push_back(i.first);
    }
    sort(res.begin(),res.end());
    for(auto i:res)cout<<i<<endl;
    //cout<<endl;
    return 0;
}

Measured memory_bytes: 25584
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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

bool is_change(string& str,int pos, int len){
	const char A[] = {'H','o','s','h','i','n','a'};
	if(str.substr(pos,len) == "Hoshino"){
		for(int i=pos,j=0;i<pos+len,j<7;i++,j++){
			str[i] = A[j];
		}
		return true;
	}

	return false;
}

int main(){

	string str;
	while(getline(cin,str)){
		int n;
		sscanf(str.c_str(),"%d",&n);
		for(int idx=0;idx<n;idx++){
			getline(cin,str);
			for(int i=0;i+6<str.size();i++){
				if(is_change(str,i,7)) i+=6;
			}

			cout << str << endl;
		}
	}
}

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

int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(S[i] ==  (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);

    //1-0-1-0-1って感じの配列が欲しい

    if(Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2 * K + 1;

    int ans = 0;

    int left = 0;
    int right = 0;
    int tmp = 0; //[left, right)のsum

    for (int i = 0; i < Nums.size(); i += 2)
    {
        int Nextleft = i;
        int Nextright = min(i + Add, (int)Nums.size());

        //サタンを移動する
        while (Nextleft > left)
        {
            tmp -= Nums[left];
            left++;
        }
        while (Nextright > right)
        {
            tmp += Nums[right];
            right++;
        }

        ans = max(tmp, ans);
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif




int main()
{
	CIN(int, N);
	int res = 0;
	rep(i, N) {
		CIN(int, t);
		if (t == i+1) {
			res++;
			if (i != N-1) cin >> t;
			i++;
		}
	}
	cout << res << endl;

}


Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    exist = [1] * N
    red = [False] * N
    red[0] = True
    for i in range(M):
        x, y = map(int, input().split())
        x -= 1; y -= 1
        exist[x] -= 1; exist[y] += 1
        if red[x]:
            red[y] = True
        if exist[x] == 0:
            red[x] = False
    ans = 0
    for i in range(N):
        if red[i] and exist[i] > 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 10384
a, b, c = sorted(map(int, input().split()))
if a % 2 == 0 and a == b and b == c:
    print(-1)
else:
    cnt = 0
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        cnt = cnt + 1
        a, b, c = (b + c) //2, (a + c) // 2, (a + b) //2
    print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <utility>

using namespace std;

const int MAX_N = 40;
pair<char, int> cardB[MAX_N], cardS[MAX_N];
int N;
pair<char, int> pattern[MAX_N];

void show(pair<char, int> *C) {
	for (int i = 0; i < N; i++) {
		printf("%c%d", C[i].first, C[i].second);
		if (i != N - 1) {
			printf(" ");
		}
	}
	printf("\n");
}

void input() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> cardB[i].first >> cardB[i].second;
		cardS[i] = cardB[i];
		pattern[i] = cardB[i];
	}
}

void BubbleSort(pair<char, int> *C, int n) {
	pair<char, int> temp;

	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= 0; j--) {
			if (C[j].second < C[j - 1].second) {
				temp = C[j];
				C[j] = C[j - 1];
				C[j - 1] = temp;
			}
		}
	}
}

void SelectionSort(pair<char, int> *C, int n) {
	pair<char, int> temp;

	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (C[j].second < C[minj].second) {
				minj = j;
			}
		}
		if (i != minj) {
			temp = C[i];
			C[i] = C[minj];
			C[minj] = temp;
		}
	}
}

void isStable(pair<char, int> *C) {
	bool f = true;

	for (int i = 0; i < N - 1; i++) {
		if (C[i].second == C[i + 1].second) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					if (pattern[j] == C[i] && pattern[k] == C[i + 1]) {
						if (j > k) {
							f = false;
						}
					}
				}
			}
		}
	}
	if (f) {
		printf("Stable\n");
	}
	else {
		printf("Not stable\n");
	}
}

void solve() {
	input();
	BubbleSort(cardB, N);
	show(cardB);
	isStable(cardB);
	SelectionSort(cardS, N);
	show(cardS);
	isStable(cardS);
}

int main() {
	solve();
}

Measured memory_bytes: 3184
def abc():
    n = int(input())
    if n == 0:
        print(2)
        return
    if n == 1:
        print(1)
        return
    lucas = [2, 1]
    for i in range(2, n+1):
        lucas.append(lucas[i-1]+lucas[i-2])
    print(lucas[-1])


abc()


Measured memory_bytes: 3060
using System;

class Program
{
    static void Main(string[] args)
    {
        int i, j;

        int n = int.Parse(Console.ReadLine());
        string strInput = Console.ReadLine();
        char[] cInput = strInput.ToCharArray();
        int result = 0;

        int startRNum = 0;  //Rで始まる。
        int endWNum = 0;

        i = 0;
        while (cInput[i] == 'R')
        {
            startRNum++;
            i++;
            if (i >= n) break;
        }

        i = n - 1;
        while(cInput[i] == 'W')
        {
            endWNum++;
            i--;
            if (i < 0) break;
        }

        //R...RW...Wになっている。またはどっちかの色のみ
        if ( startRNum + endWNum == n)
        {
            Console.WriteLine(0);
            return;
        }

        int lPtr = 0;
        int rPtr = n - 1;
        while (true)
        {
            while (cInput[lPtr] == 'R' && lPtr < n) lPtr++;
            while (cInput[rPtr] == 'W' && rPtr >= 0) rPtr--;

            if(lPtr >= rPtr)
            {
                break;
            }

            cInput[lPtr] = 'R';
            cInput[rPtr] = 'W';
            result++;

        }

        Console.WriteLine(result);

        return;
    }
}

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

int main() {
  string S, T; cin >> S >> T;
  map<char, char> m, n;
  bool ans = true;
  for (int i = 0; i < S.size(); i++) {
    char s = S.at(i);
    char t = T.at(i);
    if (m.count(s)) if (m[s] != t) ans = false;
    if (n.count(t)) if (n[t] != s) ans = false;
    m[s] = t; n[t] = s;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 776
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin>>n;
    long long temp=n;
    long long cnt=0;
    while(temp){
        temp/=2;
        ++cnt;
    }
    long long ans=0;
    ans=2*pow(2,cnt-1)-1;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        int sum=0;
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int i=1;i<=a;i++){
            for(int j=1;j<=a;j++){
                for(int k=1;k<=a;k++){
                    int g=gcd(i,j);
                    int g2=gcd(g,k);
                    sum+=g2;
                }
            }
        }
      System.out.println(sum);
    }
    public static int gcd(int a,int b){
        if(a<b){
            int tmp=a;
            a=b;
            b=tmp;
        }
        int r=a%b;
        while(r!=0){
            a = b;
            b = r;
          	r = a % b;
        }
        return b;
    }
}

Measured memory_bytes: 35812
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD =998244353 ;
#define pb push_back
#define mp make_pair
#define endl '\n'
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    float f=ceil(float(a)/d);
    float g=ceil(float(c)/b);
    if(g>f){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 3636
s = []
for i in range(3):
    s.append(list(map(int,input().split())))
s1 = s[0][0] - s[0][1] - s[1][0] + s[1][1]
s2 = s[1][1] - s[1][2] - s[2][1] + s[2][2]
s3 = s[0][0] - s[0][2] - s[2][0] + s[2][2]
print('Yes' if s1== 0 and s2==0 and s3==0 else 'No')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

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

  vector<int> P2 = P;
  std::sort(P2.begin(), P2.end());
  int count = 0;
  rep(i, N)
  {
    if (P[i] != P2[i])
      count++;
  }

  if (count == 0 || count == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  
  int n,score[100],sum;
  
  while(1){
    
    cin >>n;
    
    if(n == 0)break;

    sum=0;
    
    for(int i=0 ; i < n ; i++)cin >>score[i];
    
    sort(score,score+n);
    
    for(int i=1 ; i < n-1 ; i++)sum+=score[i];
    
    cout <<sum/(n-2)<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1176
n = int(input())
start = [0, 0]
curtime = 0
flag = True
for i in range(n):
    t, x, y = map(int, input().split())
    dist = abs(x-start[0]) + abs(y-start[1])
    time = t-curtime
    if dist <= time and dist % 2 == time % 2:
        start = [x, y]
        curtime = t
        continue
    print('No')
    flag = False
    break
if flag:
    print('Yes')

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# 整数の入力
N = int(input())
# s = 0

# while N//10 != 0 or  N%10 !=0:
#     s += N%10
#     N //= 10

if N % 9 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9572
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, m;
    while(cin>>n>>m){
        if(n+m==0) break;
        pair<int,pair<int, int>> com[20010];
        for(int i=0; i<m; i++){
            int a, b, c;
            cin >> a >> b >> c;
            com[i]=make_pair(a, make_pair(b, c));
        }
        sort(com, com+m);
        bool infected[20010];
        fill(infected, infected+(n+1), false);
        infected[1]=true;
        for(int i=0; i<m; i++){
            if(infected[com[i].second.first]) infected[com[i].second.second]=true; 
        }
        int count=0;
        for(int i=1; i<=n; i++){
            if(infected[i]) count++;
        }
        cout << count << "\n";
    }
    
}



Measured memory_bytes: 3268
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt

  var ans = 0
  while (ans == 0) {
    if(isPrime2(n))ans = n
    n += 1
  }
  println(ans)

  def isPrime(x: Int): Boolean = {
    var result = true
    if(x > 1) {
      for(i <- 2 until x) {
        if(x % i == 0) {
          result = false
        }
      }
    }else {
      result = false
    }
    result
  }
  def isPrime2(x: Int): Boolean = {
    var result = true
    if(x > 1) {
      for(i <- 2 until math.sqrt(x).toInt) {
        if(x % i == 0) {
          result = false
        }
      }
    }else {
      result = false
    }
    result
  }
}


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

using namespace std;

int main() {
	int n, l, y=0;
	cin >> n;
    string s[n], f;
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> s[i];
        cin >> a[i];
    }
    cin >> f;
    for(int i=0; i<n; i++) {
        if(strcmp(s[i].c_str(), f.c_str()) == 0) {
        	l=i+1;
            break;
        }
    }
    for(int i=l; i<n; i++) y+= a[i];
    cout << y << endl;
}

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

int main() {

  string s, t;
  cin >> s;
  cin >> t;
  int spos = 0;
  long long result = 0;
  vector<int> sna;

  for (auto& e:t)
  {
    int sn = s.substr(spos).find(e);
    if (sn == string::npos)
    {
      if (s.find(e) == string::npos )
      {
        result = -1;
        break;
      }
      spos = 0;
      sn = s.substr(spos).find(e);
    }
    sna.push_back(sn + spos);
    spos = spos + sn + 1;
    if (spos == s.size()) spos = 0;
  }
  if (result == -1)
  {
    cout << result << endl;
    return 0;
  }
  int stimes = 0;
  for (int i = 0; i < sna.size()-1; i++ )
  {
    if (sna[i] >= sna[i+1])  stimes += 1 ;
  }
  result = s.size() * stimes + sna[sna.size() - 1] + 1;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod=1e9+7;

int main(){
  int n;
  cin >> n;
  map<int, int> a;
  ll res=0;
  rep(i,n){
    int t;
    cin >> t;
    if(a[t]<t) a[t]++;
    else res++;
  }
  for(auto itr=a.begin(); itr!=a.end(); itr++){
  	if(itr->second < itr->first)
  		res += itr->second;
  }
  cout << res << endl;
  return 0;
}

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

int main(){
    while(1){
        int n;    cin>>n;
        if(n==0)break;

        int s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }

        int max=0,min=1000;;

        for(int i=0;i<n;i++){
            if(s[i]>max)max=s[i];
            if(s[i]<min)min=s[i];
        }
        
        int sum=0;
        for(int i=0;i<n;i++){
            sum +=s [i];
        }


        sum -=max;
        sum -=min;

        cout<<sum/(n-2)<<endl;
    }

    return 0;
}



Measured memory_bytes: 2988
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int n; cin >> n;
    vi v(n);
    rep (i, 0, n-1) cin >> v[i];

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

    ll res = -1;
    rep (x, v[0], v[n-1]) {
    	ll ans = 0;
    	for (int pt : v) {
    		ans += ((pt-x)*(pt-x));
    	}
    	if (res == -1 || ans < res) res = ans;
    }
    cout << res << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define pb push_back
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define N 10000005
#define INF 10000000000000

using namespace std;

const int mod=1e9+7;



void need_for_speed(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


int32_t main(){
	need_for_speed();
    int a[6];
    for(int i=1;i<=5;i++){
        cin>>a[i];
    }
    for(int i=1;i<=5;i++){
        if(a[i]==0){
            cout<<i<<endl;
            return 0;
        }
    }
    
    
    return 0;
}
        
	

		
    

        
        
    
 

Measured memory_bytes: 3568
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int i, j, k, l, m;
int a[7];
int t;

void input()
{
    //さいころに数字を割り当てる
    for (i = 1; i <= 6; i++){
        scanf("%d", &a[i]);
    }
}

//Nが入力されたらの数字の移動を行う
void N()
{
    t = a[1];
    a[1] = a[2];
    a[2] = a[6];
    a[6] = a[5];
    a[5] = t;
}

//Eが入力されたらの数字の移動を行う
void E()
{
    t = a[1];
    a[1] = a[4];
    a[4] = a[6];
    a[6] = a[3];
    a[3] = t;
}

//Sが入力されたらの数字の移動を行う
void S()
{
    t = a[1];
    a[1] = a[5];
    a[5] = a[6];
    a[6] = a[2];
    a[2] = t;
}

//Nが入力されたらの数字の移動を行う
void W()
{
    t = a[1];
    a[1] = a[3];
    a[3] = a[6];
    a[6] = a[4];
    a[4] = t;
}

int main(void)
{
    input();
    char str[100];

    scanf("%s", str);

    for (i = 0; i < strlen(str); i++){
        if (str[i] == 'N'){
            N();
        }else if (str[i] == 'E'){
            E();
        }else if (str[i] == 'S'){
            S();
        }else if (str[i] == 'W'){
            W();
        }
    }

    printf("%d\n", a[1]);

    return (0);
}



Measured memory_bytes: 2100
s=list(input())
#　文字の種類ごとにどのタイミングででたか格納
x=[[] for i in range(26)]
n=len(s)
for i in range(n):
    v=ord(s[i])-97
    x[v].append(i)

for i in range(26):
    x[i]=[-1]+x[i]+[n]


ans=float('inf')
for i in range(26):
    cnt=0
    for j in range(1,len(x[i])):
        cnt=max(x[i][j]-x[i][j-1]-1,cnt)
    ans=min(cnt,ans)
print(ans)

Measured memory_bytes: 38256
from sys import stdin
readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

t = sum(A)
d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

for _ in range(Q):
    B, C = map(int, readline().split())
    d.setdefault(B, 0)
    d.setdefault(C, 0)
    t -= B * d[B]
    t += C * d[B]
    d[C] += d[B]
    d[B] = 0
    print(t)


Measured memory_bytes: 23572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	string S;
	cin >> S;
	if(S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
    char s[111],t[111];
    cin>>s>>t;
    int len1=strlen(s),len2=strlen(t);
    for(int i=len1-1;i>=0;i--){

        if(s[i]==t[0]||s[i]=='?'){
            int cnt=0;
            for(int j=0;j<len2&&i+j<len1;j++){
                if(s[i+j]==t[j]||s[i+j]=='?') cnt++;
            }
            if(cnt==len2){
                for(int j=0;j<len2;j++) s[i+j]=t[j];
                for(int j=0;j<len1;j++){
                    if(s[j]=='?') cout<<'a';
                    else cout<<s[j];
                }
                return 0;
            }
        }

    }
    cout<<"UNRESTORABLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
public class
Main {
	private int
	run ( int[ ] a )
	{
		int res = a[ 0 ];
		
		for ( int i = 1; i < a.length; ++i )
			a[ i ] = Math.max ( a[ i ], a[ i - 1 ] + a[ i ] );
		
		for ( int i = 1; i < a.length; ++i )
			res = Math.max ( res, a[ i ] );
		
		return ( res );
	}
	
	public static void
	main ( String[ ] args )
	{
		java.util.Scanner sc = new java.util.Scanner ( System.in );

		for ( ; ; )
		{
			final int n = sc.nextInt ( );
			int[ ] a;
			
			if ( n == 0 )
				break ;
			a = new int[ n ];
			for ( int i = 0; i < a.length; ++i )
				a[ i ] = sc.nextInt ( );
			System.out.println ( ( new Main ( ) ).run ( a ) );
		}
		sc.close ( );
	}
}

Measured memory_bytes: 26972
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<5;++i){
			int x = sc.nextInt();
			if(x==0){
				System.out.println(i+1);
				break;
			}
		}
		sc.close();
	}
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() - a.front() << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int n; std::cin >> n;
  ll a[100010],ans=0;
  for(int i=0; i<n; i++) std::cin >> a[i];
  map<ll,ll> data;
  for(int i=0; i<n; i++) data[a[i]]++;

  for(auto p:data){
    ll x=p.first;
    ll nx=p.second;
    if(nx < x) ans+=nx;
    else ans+=nx-x;
  }

  std::cout << ans << '\n';
  
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	ll total = 0;
	for(int i=0;i<=N;i++){
		if(i%3 != 0 && i%5!=0){
			total += i;
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    ll ans = 1e+15;
    ll total = 0, count = 0;
    bool is_positive = true;
    for(int i = 0; i < n; ++i){
        if(is_positive){
            if(total + a[i] > 0)    total += a[i];
            else{
                count += 1 - (total + a[i]);
                total = 1;
            }
        }
        else{
            if(total + a[i] < 0)    total += a[i];
            else{
                count += total + a[i] + 1;
                total = -1;
            }
        }
        is_positive ^= true;
    }
    chmin(ans, count);
    total = 0, count = 0;
    is_positive = false;
    for(int i = 0; i < n; ++i){
        if(is_positive){
            if(total + a[i] > 0)    total += a[i];
            else{
                count += 1 - (total + a[i]);
                total = 1;
            }
        }
        else{
            if(total + a[i] < 0)    total += a[i];
            else{
                count += total + a[i] + 1;
                total = -1;
            }
        }
        is_positive ^= true;
    }
    chmin(ans, count);
    cout << ans << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int ans[maxn][31];
int N, C;
int s, t, c;

int main(void) {
    while(cin >> N >> C) {
        int lst = 0;
        memset(ans, 0, sizeof(ans));
        for(int i = 1; i <= N; ++i) {
            cin >> s >> t >> c;
            lst = max(lst, t);
            ++ans[s][c];
            --ans[t + 1][c];
        }
        int ret[31] = {0}, mx = 0;
        for(int i = 1; i <= lst; ++i) {
            int cur = 0;
            for(int j = 1; j <= C; ++j) {
                ret[j] += ans[i][j];
                if(ret[j]) ++cur;
            }
            mx  = max(mx, cur);
        }
        cout << mx << endl;
    }
}

Measured memory_bytes: 12416
#pragma GCC optimize("Ofast")
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
string s;
int num; 
int main()
{
	fast;
	cin>>s;
	for (int i=0;i<=s.size()-1;i++)
	   if (s[i]=='2')
	      num++;
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
def solve(a, t, b=[]):
	if t == sum(b):
		b.clear()
		return True
	elif len(a) == 0 or sum(b) > t or sum(a + b) < t:
		b.clear()
		return False
	else:
		for i in range(len(a)):
			if solve(a[i+1:], t, b+[a[i]]):
				return True


def main():
	input()
	a = [int(i) for i in input().split()]
	input()
	q = [int(i) for i in input().split()]
	for i in q:
		print('yes' if solve(a, i) else 'no')


if __name__ == '__main__':
	main()



Measured memory_bytes: 5628
#import math.sqrt as sqrt
#data = list(map(input().split()))

data = input()

if data == "SUN":
    print(7)
elif data == "MON":
    print(6)
elif data == "TUE":
    print(5)
elif data == "WED":
    print(4)
elif data == "THU":
    print(3)
elif data == "FRI":
    print(2)
else:
    print(1)


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

const int mod = 1000000007;

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    int ans = 0;
    int hw = max(h, w);
    while(n>0){
        n -= hw;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  deque<char> deq;
  for(int i=0;i<s.size();i++){
    deq.push_back(s[i]);
  }
  //先頭・末尾判定
  bool isHead = true;
  for(int i=0;i<q;i++){
    int t;
    cin >> t;
    if(t == 1){
      isHead = !isHead;
    }else if(t == 2){
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        if(isHead){
          deq.push_front(c);
        }else{
          deq.push_back(c);
        }
      }else if(f == 2){
        if(isHead){
          deq.push_back(c);
        }else{
          deq.push_front(c);
        }
      }
    }
  }

  if(!isHead){
    reverse(deq.begin(),deq.end());
  }
  for(auto itr = deq.begin();itr != deq.end();itr++){
    cout << *itr;
  }
  cout << endl;
}


Measured memory_bytes: 896
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    string S;
    int K;
    cin>>S>>K;;
    vector<string> s;
    for(int i=0;i<S.size();i++){
        for(int j=1;j<=5;j++){
            if(i+j > S.size()) break;
            s.push_back(S.substr(i,j));
        }
    }
    

    sort(s.begin(),s.end());
    s.erase(std::unique(s.begin(), s.end()), s.end());

    cout<<s[K-1]<<endl;

}


Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <vector>
#include <unordered_map>

#define div 1000000000+7

using ll = long long;
using namespace std;

void solve() {
    char x, y;
    cin >> x >> y;
    if(y > x){
        cout << "<" << endl;
    }else if(x == y){
        cout << "=" << endl;
    }else{
        cout << ">" << endl;
    }
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	llong sum=0;
	int a=0,ba=0,b=0;
	REP(i,n){
		string s;
		cin>>s;
		
		for(int i=0;i<s.size()-1;++i){
			if(s[i]=='A'&&s[i+1]=='B') sum++;
		}
		
		if(s[0]=='B'&&s[s.size()-1]=='A') ba++;
		else if(s[s.size()-1]=='A') a++;
		else if(s[0]=='B') b++;
	}
	
	if(ba==0){
		sum+=min(a,b);
		cout<<sum<<endl;
		return 0;		
	}
	
	if(a==0&&b==0){
		sum+=ba-1;
		cout<<sum<<endl;
		return 0;
	}
	
	while(ba!=0){
		if(ba<=a){
			sum+=ba;
			ba=0;
		}else{
			sum+=a;
			ba-=a;
		}
		if(ba<=b){
			sum+=ba;
			ba=0;
		}else{
			sum+=b;
			ba-=b;
		}
	}
	sum+=min(a,b);
	
	cout<<sum<<endl;
}


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

int n;
string out;

void solve(int now,int syurui)
{
	if (now == n-1) {
		cout << out << endl;
	}
	else {
		char alpha = 'a';
		int loop = min(now+1, syurui);
		for (int i = 0; i <= loop; i++) {
			out[now+1] = alpha;
			if (i == syurui) {
				solve(now + 1, syurui+1);
			}
			else {
				solve(now + 1, syurui);
			}
			alpha++;
		}
	}
	return;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		out += "a";
	}
	solve(0,1);
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  long long res = h * w / 2;
  if (h & 1 and w & 1) {
    ++res;
  }
  if (h == 1 or w == 1) {
    res = 1;
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;

namespace AGC032A
{
    public partial class Program
    {

        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var B = ss.Next(int.Parse, N);
            var res = new List<int>();

            foreach (var b in B)
            {
                if (res.Count < b - 1)
                {
                    sw.WriteLine(-1);
                    return;
                }
                res.Insert(b - 1, b);
            }

            sw.WriteLine(string.Join("\n", res));
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = {' '};
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 13268
#line 1 "../lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

void dfs(int cur, int par, const vector<vi> &g, vi &d) {
  d[cur] = d[par] + 1;
  for (const auto v : g[cur]) {
    if (v == par)
      continue;
    dfs(v, cur, g, d);
  }
}

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

  int n;
  cin >> n;
  vector<vi> g(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vi d0(n, 0), dn(n, 0);
  dfs(0, -1, g, d0);
  dfs(n - 1, -1, g, dn);

  int cnt = 0;
  REP(i, n) {
    if (d0[i] <= dn[i])
      cnt++;
  }
  cout << (cnt > n - cnt ? "Fennec" : "Snuke") << endl;
  return 0;
}


Measured memory_bytes: 12800
import java.util.*;
class Main{

    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
    long res = (long)n/x*t;
    if(n%x!=0)
    res += t;
    System.out.println(res);
     //   System.out.println("Hello World");
    }
}


Measured memory_bytes: 35664
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,k;cin>>a>>b>>k;
    set<int> st;
    for(int i=a;i<a+k;i++) st.insert(i);
    for(int i=b-k+1;i<=b;i++) st.insert(i);
    for(auto itr=st.begin();itr!=st.end();itr++){
        int p=*itr;
        if(a<=p && p<=b) cout<<p<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    string cardA = in<string>(), cardB = in<string>(), cardC = in<string>();
    int A_now = 0, B_now = 0, C_now = 0;
    char next = 'a', winner;

    while (true){
        if(next == 'a'){
            if(A_now == cardA.size()){
                winner = 'A';
                break;
            }
            next = cardA[A_now];
            A_now++;
        }else if(next == 'b'){
            if(B_now == cardB.size()){
                winner = 'B';
                break;
            }
            next = cardB[B_now];
            B_now++;
        }else if(next == 'c'){
            if(C_now == cardC.size()){
                winner = 'C';
                break;
            }
            next = cardC[C_now];
            C_now++;
        }else{
            cout << "error" << endl;
            break;
        }
    }
    
    cout << winner << endl;
    
}

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

using namespace std;

int main(){
	string s;
	cin>>s;
	long long ans = 0;
	long long ctr = 0;

	for(int i = 0; i < s.size(); i++){
		if (s[i] == 'W') {
			ans += ctr;
		} 
		else ctr++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

bool check(int a){
	for (int i = 1; i < 130; i++){
		int d = i*i;
		if(a==d) return true;
	}
	return false;
}

int main(){
	int n,d;
	cin >> n >> d;
	int X[11][11];
	rep(i,n){
		rep(j,d){
			int x;
			cin >> x;
			X[i][j] = x;
		}
	}
	int ans = 0;
	rep(i,n){
		for (int j = i+1; j < n; j++) {
			int d2 = 0;
			rep(k,d) d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			if(check(d2)) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=1e5+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;int a[N][2],b[2][4],c[N];
int main(){
	n=read();rep(i,1,n)a[c[i]=read()][i%2]+=1;
	rep(i,1,n)if(a[c[i]][i%2]>b[i%2][0])
	b[i%2][1]=b[i%2][0],b[i%2][0]=a[c[i]][i%2],b[i%2][2]=c[i];
	else if(a[c[i]][i%2]>b[i%2][1]&&c[i]!=b[i%2][2])
	b[i%2][1]=a[c[i]][i%2];
	if(b[0][2]!=b[1][2])printf("%d\n",n-b[0][0]-b[1][0]);
	else printf("%d\n",n-max(b[0][0]+b[1][1],b[0][1]+b[1][0]));
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int MAX_P = (int)2e6;
const int N = 10001;

int main(void){
    bool isP[MAX_P];
    MEMSET(isP, true);
    rep(i, 2) isP[i] = false;
    rep(i, MAX_P) if(isP[i]) for(ll j = i; i * j < MAX_P; j ++) isP[i * j] = false;
    
    vi res(N);
    int cur = 0;
    rep(i, N){
        if(!i) continue;
        while(!isP[++cur]);
        res[i] = res[i - 1] + cur;
    }

    for(int n; cin >> n, n; cout << res[n] << endl);

    return 0;
}

Measured memory_bytes: 3192