akhauriyash/Code-Regression huggingface dataset:
// A
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	if (s.back() == 's') cout << s + "es" << endl;
	else cout << s + "s" << endl;

	return 0;
}


Measured memory_bytes: 3660
N=int(input())
sl=[]
for i in range(N):
  sl.append(list(map(int,input().split())))
sl.sort()
sl_table = [True for i in range(len(sl))]

for i in range(N):
  for j in range(min(i+1,N),N):
    if sl[j][0]-sl[i][1]>0:
      break
    sl[i]=[min(min(sl[i]),min(sl[j])),max(max(sl[i]),max(sl[j]))]
    sl_table[j]=False

print(sum((s[1]-s[0]+1)*sl_table[i] for i,s in enumerate(sl)))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
#define fi cin
#define fo cout 
#define repi(i,a,n) for(i=a;i<n;i++)
#define repie(i,a,n) for(i=a;i<=n;i++)
#define repd(i,a,n) for(i=n;i>a;i--)
#define repde(i,a,n) for(i=n;i>=a;i--) 
#define pb(n) push_back(n)
#define ff first
#define ss second
#define dfo if(0) cout
#define mod 1000000007

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	fi.tie(0);
	fo.tie(0);

	ll i,j,k,t,tc,n,m,x,a,b;
	fi>>a>>b>>x;

	if(x >= a && x <= a+b)
		cout<<"YES"<<endl;
	else cout<<"NO"<<endl;		


}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define MAX 10005

struct Node {
    int v, p, h;
};

Node node[MAX];

int findSet(int x) {
    int now, p, result;
    now = x;
    p = node[now].p;
    while (now != p) {
        now = p;
        p = node[now].p;
    }
    result = p;
    p = x;
    while (p != result) {
        now = p;
        p = node[now].p;
        node[now].p = result;
    }
    return result;
}

void unite(int x, int y) {
    int a = findSet(x);
    int b = findSet(y);
    if (a == b) return;
    if (node[a].h > node[b].h) {
        node[b].p = a;
    } else if (node[a].h < node[b].h) {
        node[a].p = b;
    } else {
        node[b].p = a;
        node[a].h++;
    }
}

int main(void) {
    int n, p, com, x, y;
    cin >> n >> p;
    for (int i = 0; i < n; i++) {
        node[i].v = i;
        node[i].p = i;
        node[i].h = 0;
    }
    while (p--) {
        cin >> com >> x >> y;
        if (com == 0) {
            unite(x, y);
        } else {
            if (findSet(x) == findSet(y)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}


Measured memory_bytes: 3200
<?php

$input = trim(fgets(STDIN));


$array = array();

for ($i =0; $i < strlen($input);$i++)
{
	if (isset($array[$input[$i]]))
	{
		echo "no\n";
		die();
	}
	else
	{
		$array[$input[$i]] = true;
	}
	
	
}	


echo "yes\n";
		die();

Measured memory_bytes: 3828
n, t = map(int, input().split())
c_lists = []
t_lists = []
for i in range(n):
  c_i, t_i = map(int, input().split())
  c_lists.append(c_i)
  t_lists.append(t_i)

costs = []
for j in range(n):
    if t_lists[j] <= t:
        costs.append(c_lists[j])
if not costs:
    ans = 'TLE'
else:
    costs.sort()
    ans = costs[0]
print(ans)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

#define over 1000000000000000000

signed main(void)
{
	int n, a[100005]; cin >> n;
	rep (i, n) cin >> a[i];
	int ans = 1;
	rep (i, n) {if (a[i] == 0) {cout << 0 << endl; return 0;}}
	rep (i, n) {if (ans > over / a[i] + 1 || ans * a[i] > over) {cout << -1 << endl; return 0;} ans *= a[i];}
	cout << ans << endl;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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 keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll ans = 0;
    char f = s[0];
    for(ll i=1;i<s.size();++i){
        if(f == s[i]){
            continue;
        }else{
            f = s[i];
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		if(a==1) {
			System.out.println("Hello World");
		}
		else {
			int b=scan.nextInt();
			int c=scan.nextInt();
			System.out.println(b+c);
		}
		}
	}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <queue>
#include <iomanip>
using namespace std;

#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)


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


  return 0;
}

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


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    sort(a.begin(), a.end());
    vector<int> counter(n);
    
    int j = 0;
    
    for (int i = 0; i < n; i++){
        //cout << a.at(i) << " ";
        if (i == 0){
            counter.at(j) = 1;
        }
        else if (a.at(i) == a.at(i - 1)){
            counter.at(j) += 1;
        }
        else{
            j ++;
            counter.at(j) += 1;
        }
    }
    
    sort(counter.begin(), counter.end());
    //reverse(counter.begin(), counter.end());
    //for (int i = 0; i < counter.size(); i ++) cout << counter.at(i) << " ";
    
    int del = 0;
    while (del < k){
        counter.pop_back();
        del ++;
    }
    
    int ans = 0;
    for (int i = 0; i < counter.size(); i++){
        ans += counter.at(i);
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1792
using System;

public class hello
{

    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var result = "";
        for (int i = 0; i < s.Length; i++)
        {
            if (char.IsUpper(s[i])) result += s[i].ToString().ToLower();
            else result += s[i].ToString().ToUpper();
        }
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

ll n;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	ll total = n*((n-1)/2);
	if(n%2 == 0) {
		total += n/2;
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
def input(cnt):
    inp = []
    for i in range(cnt):
        inp.append(map(int, raw_input().split()))
    return inp

(n, m), X, Y = input(3)

moder = 10**9 + 7
u, v = 0, 0
for i in xrange(1, n):
    u += (X[i] - X[i-1]) * i * (n - i) % moder
for j in xrange(1, m):
    v += (Y[j] - Y[j-1]) * j * (m - j) % moder
res = u * v % moder

print res

Measured memory_bytes: 14512
n = int(input())
a_l = list(map(int,input().split()))

# if a_l[0] != 0:
#     if n == 0:
#         print(1)
#     else:
#         print(-1)
#     exit()

tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2
# print(tree)

if tree[-1] < a_l[-1]:
    print(-1)
    exit()

# print(tree)
tree[-1] = a_l[-1]
for i in range(2,n+2):
    # print(i, tree[-i], tree[-(i-1)] + a_l[-i])
    if tree[-i] == tree[-(i-1)] + a_l[-i]:
        break
    else:
        tree[-i] = min(tree[-i], tree[-(i-1)] + a_l[-i])
    # print(tree)
# print(tree)

# while tree[-1] != a_l[-1]:
#     tree[-1] -= 1
#     i = 1
#     while True:
#         i += 1 
#         if tree[-(i-1)] >= (tree[-i] - a_l[-i]):
#             break
#         tree[-i] -= 1
# print(tree)

ans = 0
for val in tree:
    ans += val
print(ans)

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

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

  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  vector<int> s;
  vector<int> ord(n + 1, -1);
  int c = 1, l = 0;
  int v = 1;
  while (ord.at(v) == -1) {
    ord.at(v) = s.size();
    s.push_back(v);
    v = a.at(v - 1);
  }
  c = s.size() - ord.at(v); // the size of loop list
  l = ord.at(v);            // the begining of loop point

  if (k < l) {
    cout << s.at(k) << endl;
  } else {
    k -= l;
    k %= c;
    cout << s.at(l + k) << endl;
  }

  return 0;
}


Measured memory_bytes: 5780
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;

int main()
{
   FAST/**/
   
   ll n,k;
   cin>>n>>k;
   
   ll dp[n+5][n+5][n*n+5];
   for(ll i=0;i<n+5;i++)
        for(ll j=0;j<n+5;j++)
            for(ll i1=0;i1<n*n+5;i1++)
                dp[i][j][i1] = 0;
   
   dp[0][0][0] = 1;
   dp[0][1][2] = 1;
   
   for(ll i=1;i<n;i++)
   {
       for(ll j=0;j<=i+1;j++)
       {
           for(ll i1=0;i1<=n*n;i1++)
           {
               if(i1>=2*j)
                    dp[i][j][i1]+=(2*j+1)*dp[i-1][j][i1-2*j], dp[i][j][i1]%=MOD;
               if(i1>=2*j && j+1<=i)        
                    dp[i][j][i1]+=(j+1)*(j+1)*dp[i-1][j+1][i1 - 2*(j)], dp[i][j][i1]%=MOD;
               if(i1 - 2*j>=0 && j>0)        
                    dp[i][j][i1]+=dp[i-1][j-1][i1 - 2*j], dp[i][j][i1]%=MOD;
               dp[i][j][i1]%=MOD;       
           }
       }
   }
   
   cout<<dp[n-1][0][k];
   
   
   return 0;
}

Measured memory_bytes: 59520
#include<stdio.h>

int gcd(int n,int m){
  if(n<m)return gcd(m,n);
  if(m==0)return n;
  return gcd(m,n%m);
}

#define lcm(a,b) ((a)*(b)/gcd((a),(b)))

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

  int r_max,ans=0;
  r_max=n/r;

  int i,j,nn,del;
  del=gcd(g,b);
  g/=del; b/=del;
  nn=n+r;
  for(i=0;i<=r_max;i++){
    nn=n-r*i;
    if(nn%del) continue;
    nn/=del;
    j=0;
    while(nn%b){
      nn-=g;
    }
    if(nn>=0)    ans+=(nn/b/g+1);
    //    printf("i:%d %d\n",i, ans);
  }
    

  printf("%d",ans);
  return 0;
}



Measured memory_bytes: 128
S = input()
q = int(input())
order = [input().split() for _ in range(q)]
for x in order:
    a,b,c,d = x[0],int(x[1]),int(x[2]),x[3] if x[0] == 'replace' else None
    if a == 'print':
        print(S[b:c+1])
    elif a == 'reverse':
        S = S[:b] + S[b:c+1][::-1] + S[c+1:]
    else:
        S = S[:b] + S[b:c+1].replace(S[b:c+1],d) + S[c+1:]


Measured memory_bytes: 5624
#include <stdio.h>

int gcd(int x, int y){
    if(y==0)
       return (x);
    else
       return (gcd(y,x%y));

}

int main(void){
    int x,y;

    scanf("%d %d",&x,&y);

    printf("%d\n", gcd(x,y));

    return (0);
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=998244353;

int main(void){
    int x,n;
    cin>>x>>n;
    map<int,int> P;
    rep(i,n){
        int p;
        cin>>p;
        P[p]=1;
    }
    rep(i,100){
        if(P[x-i]!=1){
            cout<<x-i<<endl;
            break;
        }
        if(P[x+i]!=1){
            cout<<x+i<<endl;
            break;
        }
    }
    return 0;
}

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

int main()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
	{
		cout << "vowel" << endl;
	}
	else
	{
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			int[,] dp = new int[3, n];
			int[,] points = new int[3, n];

			for (int i = 0; i < n; i++)
			{
				string[] line = Console.ReadLine().Split(' ');
				points[0, i] = int.Parse(line[0]);
				points[1, i] = int.Parse(line[1]);
				points[2, i] = int.Parse(line[2]);
			}

			dp[0, 0] = points[0, 0];
			dp[1, 0] = points[1, 0];
			dp[2, 0] = points[2, 0];

			for (int i = 1; i < n; i++)
			{
				int prev = i - 1;
				dp[0, i] = Math.Max(dp[1, prev], dp[2, prev]) + points[0, i];
				dp[1, i] = Math.Max(dp[0, prev], dp[2, prev]) + points[1, i];
				dp[2, i] = Math.Max(dp[0, prev], dp[1, prev]) + points[2, i];
			}

			int ans = Math.Max(dp[0, n - 1], Math.Max(dp[1, n - 1], dp[2, n - 1]));
			Console.WriteLine(ans);
		}
	}
}


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

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

using namespace std;
const long long INF = 1LL << 61;

int main() {
	long long N; cin >> N;
	long long ans = N * (N - 1) / 2;
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()
{
    char a;
    cin >> a;
    if (a < 91)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b,c;
  cin>>a>>b>>c;
  cout<<(a==b&&b==c?"Yes":"No")<<endl;  
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

int query(int i){
    cout << i << endl;
    string s;
    cin >> s;
    if(s == "Male") return 1;
    else if(s == "Female") return 2;
    else exit(0);
}

void Main() {
    int n; cin >> n;
    vi s(n);
    
    int l = 0;
    int r = n-1;

    s[l] = query(l);
    s[r] = query(r);

    // 常に next > now で, 
    // s[now] != s[next] && (next - now) % 2 == 0
    // s[now] == s[next] && (next - now) % 2 == 1
    // のどちらかが成立    

    while(1){
        int mid = (l + r) / 2;
        s[mid] = query(mid);

        if(s[l] != s[mid] && (mid - l) % 2 == 0) {
            r = mid;    
        }
        else if(s[l] == s[mid] && (mid - l) % 2 == 1){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return;
}

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

Measured memory_bytes: 4024
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P,int> PP;
struct edge { int to; int to2; int cost; };
vector<int>G[155555];
int d[100006];
int pt[100006];
int nump[100006];int n, k; 
void dfs(int now) {
	rep(i, G[now].size()){
		int e = G[now][i];
		if (d[e] != inf)continue;
		d[e] = d[now] + 1;
		pt[e] = k - nump[now]-1;
		nump[now]++;
		nump[e]++;
		dfs(e);
	}
}
signed main() {
	cin >> n >> k;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	fill(d, d + n, inf);
	d[0] = 0;
	pt[0] = k;
	int ans = 1;
	dfs(0);
	rep(i, n) {
		//cout << pt[i] << endl;
		ans *= pt[i];
		ans %= MOD;
	}
	cout << ans << endl;
}

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

using namespace std;

const int MOD=1e9+7;

//const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    string s;
    cin>>n>>s;
    
    vector<long long> cts(26);
    for(char c:s){
        cts[c-'a']++;
    }
    long long ans=1;
    for(int i=0; i<26; i++){
        ans*=cts[i]+1;
        ans%=MOD;
    }
    cout<<(ans-1+MOD)%MOD;
    
    
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll LL_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> ship_go;
    map<int, int> ship_back;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        if(a == 1) ship_go[b] = 1;
        if(b == N) ship_back[a] = N;
    }
    bool exist = false;
    for(int i = 2; i <= N - 1; i++){
        if(ship_go[i] == 1 and ship_back[i] == N){
            exist = true;
            break;
        }
    }
    if(exist) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}

Measured memory_bytes: 19072
//B - Some Sums: 
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int n, a, b, soma = 0;

bool sumDig(int num) {
    string s = to_string(num);
    int soma = 0;
    for(auto x : s) {
        soma += x - '0';
    }
    if(soma >= a and soma <= b) return true;\
    return false;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> a >> b;
    loop(i, 0, n+1) {
        if(sumDig(i)) soma += i;
    }
    cout << soma << "\n";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int ddx[8]={0,0,-1,1,1,1,-1,-1};
int ddy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int check(string s){
	int sz=s.length();
	if(sz%2)
		return 0;
	string a,b;
	a=s.substr(sz/2);
	b=s.substr(0,sz/2);
	//cout<<b<<" "<<a<<endl;
	if(a==b)
		return 1;
	else
		return 0;
}
int main(){
	string s;
	cin>>s;
	int sz=s.length();
	string t;
	int maxi=0;
	for(int i=0;i<sz-1;i++){
		t+=s[i];
		if(check(t)){
			maxi=i;
		}
	}
	cout<<maxi+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
void Sort(float numbers[], int array_size)
{
  int i, j; 
  float temp;

  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (numbers[j-1] > numbers[j]) {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}
int main(void) {
  int i,n;
  float v[50];
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%f",&v[i]);
  }
  Sort(v,n);
  float sum=v[0];
  for(i=1;i<n;i++) {
    sum = (sum+v[i])/2;
  }
  printf("%f\n",sum);
  return 0;
}


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


int main(){
  string S;
  cin >> S;
  string T = "ATCG";
  int ans = 0;
  int now = 0;
  for(int i = 0; i< S.size(); i++){
    bool isATCG = false;
    for(int j = 0; j < T.size(); j++){
      if(S[i] == T[j]) isATCG = true;
    }
    if (!isATCG){
      now = 0;
    }
    else{
      now++;
      ans = max(now, ans);
    }
  }
  cout << ans << endl;
}

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

using namespace std;

const int Nmax = 2e5 + 5;
int st, dr, mid, n, i, a[Nmax], b[Nmax];

bool check(int val)
{
    int i, l, r;
    for(i=1; i<=n; ++i) b[i] = (a[i] > val);

    if(b[n/2+1] == b[n/2] || b[n/2+1] == b[n/2+2]) return b[n/2+1];

    for(l = n/2; l>1; --l)
        if(b[l] == b[l-1]) break;

    for(r = n/2+2; r<n; ++r)
        if(b[r] == b[r+1]) break;

    if(l == 1 && r == n) return b[1];

    if(l == 1) return b[r];
    if(r == n) return b[l];
    if(b[l] == b[r]) return b[l];
    if(n/2 + 1 - l < r - n / 2 - 1) return b[l];
        else return b[r];
}

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n;
    if(n == 1) { cout << "1\n"; return 0; }

    n = 2 * n - 1;
    for(i=1; i<=n; ++i) cin >> a[i];

    st = 1; dr = n;
    while(st <= dr)
    {
        mid = (st + dr) / 2;
        if(check(mid)) st = mid + 1;
            else dr = mid - 1;
    }

    cout << st << '\n';
    return 0;
}


Measured memory_bytes: 1792
# 2019/05/02
# AtCoder Beginner Contest 094 - B

# Input 
n, m, x = map(int,input().split())
a = list(map(int, input().split()))
l = 0
r = 0
for i in range(m):
    if x > a[i]:
        l += 1
    else:
        r += 1

# Output
print(min(l, r))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<29)
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int w,h;

void solve(){
    char c[32][32];
    rep(i,h) scanf("%s",c[i]);

    int sx,sy;
    rep(i,h) rep(j,w) if(c[i][j]=='o'){
        sx = i;
        sy = j;
        break;
    }

    int g[512][512];
    rep(i,512) rep(j,512) g[i][j]=INF;
    rep(i,512) g[i][i]=0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j]=='x') continue;
            int v = i*w+j;
            for(int k=0;k<4;k++){
                int nx=i+dx[k],ny=j+dy[k];
                if(nx<0||ny<0||nx>=h||ny>=w) continue;
                if(c[nx][ny]=='x') continue;
                int nv = nx*w+ny;
                g[v][nv] = 1;
                g[nv][v] = 1;
            }
        }
    }

    int V = h*w;
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
            }
        }
    }

    vector<int> as;
    rep(i,h) rep(j,w){
        int v = i*w+j;
        if(c[i][j]=='*') as.pb(v);
    }

    sort(all(as));

    assert(as.size()<=10);
    int ans = INF;

    do{
        int tmp=0;
        int now = sx*w+sy;
        for(int i=0;i<sz(as);i++){
            tmp += g[now][as[i]];
            if(g[now][as[i]]==INF){
                cout << -1 << endl;
                return;
            }
            now = as[i];
        }
        ans = min(tmp,ans);
    }while(next_permutation(all(as)));

    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    int cnt=0;
    while(cin>>w>>h){
        //cnt++;
        //flag=false;
        //if(cnt==363) flag=true;
        if(w==0 and h==0) break;
        solve();
    }
}

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

int main() {
  int N;
  cin>>N;
  int Z=0;
  int64_t D;
  cin>>D;
  for(int i=0;i<N;i++){
    int64_t a,b;
    cin>>a>>b;
    if(a*a+b*b<=D*D){
      Z++;
    }
  }
  cout<<Z<<endl;
}



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

int main()
{
    long Q,H,S,D,N; cin>>Q>>H>>S>>D>>N;
    long t=min({N*4*Q, N*2*H, N*S});
    cout<<min(N/2*D+N%2*t/N, t)<<endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

ll gcd(ll a, ll b){
    ll tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main() {
    int K;
    cin >> K;
    ll ans = 0;

    REPN(i, 1, K+1) REPN(j, 1, K+1) REPN(k, 1, K+1) {
        int tmp = gcd(i, j);
        tmp = gcd(tmp, k);
        ans += tmp;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int>d(n);
  for(int i=0; i<n; i++) cin >> d[i];
  sort(d.begin(),d.end());
  
  int ans = d[n/2]-d[n/2-1];
  
  cout << ans << endl;
}


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

const int mx=1e5+1;
int dp[mx][4],n;
int h[mx][4];
int solve(int d,int p1)
{
    if(d>n) return 0;
    if(dp[d][p1]!=-1) return dp[d][p1];
    int ret=0;
    for(int i=1;i<=3;i++){
        if(p1!=i){
            ret=max(ret,h[d][i]+solve(d+1,i));
        }
    }
    return dp[d][p1]=ret;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);    return 0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i][1]>>h[i][2]>>h[i][3];
    memset(dp,-1,sizeof dp);
    cout<<solve(1,0);

    return 0;
}


Measured memory_bytes: 14480
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
    if A[i] < 0:
        count += 1
Negative = False
if count % 2 == 0:
    Negative = True

for i in range(N):
    A[i] = max(A[i],-A[i])

ans = 0
if Negative:
    ans = sum(A)
else:
    ans = sum(A) - 2* min(A)

print(ans)

Measured memory_bytes: 14412
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, C: int, B: "List[int]", A: "List[List[int]]"):
    ret = 0
    for row in A:
        s = C
        for a,b in zip(row,B):
            s += (a*b)
        if s > 0:
            ret += 1

    print(ret)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    A = [ [ int(next(tokens)) for _ in range(M) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, M, C, B, A)

if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int v = 2 * d + 1;
    cout << (n + v - 1) / v << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, anst = 1, ansa = 1, a, t, now;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &a, &t);
    now = (anst + t - 1) / t > (ansa + a - 1) / a ? (anst + t - 1) / t : (ansa + a - 1) / a;
    anst = now * t, ansa = now * a;
  }
  printf("%lld", ansa + anst);
  return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int d(long long int N)
{
    int count = 0;

    while (N > 0)
    {
        N /= 10;
        count++;
    }

    return count;
}

double rad2(double x)
{
    return x * (M_PI / 180);
}

int main()
{
    int A, B, H, M;
    double a,b;

    scanf("%d%d%d%d", &A, &B, &H, &M);

    a = rad2((double)90 - H*30 -M*0.5);
    b = rad2((double)90 - M*6);

    //printf("%f\n", rad2(360));
   // printf("%f %f", a, b);

    //printf("%f %f", A * cos(a), A * sin(a));
    //printf("%f %f", B * cos(b), B * sin(b)); 
 
    double x1 = A * cos(a);
    double y1 = A * sin(a);
    double x2 = B * cos(b);
    double y2 = B * sin(b);

    printf("%.20f", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));

    //printf("%lf", sqrt(pow(A * sin(a) - B * sin(b), 2) + pow(A * cos(a) - B * cos(b), 2 )) );
}

Measured memory_bytes: 4100
import math
from collections import deque
from collections import defaultdict

import bisect

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

def isInt(n):
	if isinstance(n, int):
		return True
	else:
		return n.is_integer()

s = readChar()

ex = set()

for i in s:
	ex.add(i)

al = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in range(len(ex)):
	al.remove(ex.pop())

if len(al)==0:
	print("None")
else:
	print(al[0])

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

int main(void){
    int k;
    cin>>k;
    int d[10000001];
    d[1]=7%k;
    for(int i=2;i<=k;i++){
        d[i]=(d[i-1]*10+7)%k;
        }

    for(int i=1;i<=k;i++){
        if(d[i]==0){
            cout<<i<<endl;
            return 0;
        }
    }
  	cout<<-1<<endl;
return 0;
}


Measured memory_bytes: 7548
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
int dx[] = {1, 0, -1, 0}; // {down , right , up , left}
int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
//int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

int n;
vector<int> adj[N];

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  scanf("%d", &n);
  for (int i = 2; i <= n; ++i)
  {
    int v;
    scanf("%d", &v);
    adj[v].push_back(i + 1);
  }
  for (int i = 1; i <= n; ++i)
    printf("%d\n", SZ(adj[i]));

  return 0;
}


Measured memory_bytes: 33392
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int a = 0;
                int fia = 0;
                for(int i = 0 ; i < n ; i++){
                        a = sc.nextInt();
                        if(a % 2 == 1) fia++;
                }
                if(fia % 2 == 0){
                        System.out.println("YES");

                }else{
                        System.out.println("NO");
                }
        }
}

Measured memory_bytes: 58064
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i,N) cin >> a[i];
    int ans = 0;
    rep(i,N){
        ans += a[i]-1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N, K, tmp;
vector<int> v;
int f, b;

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

    REP(i, N){
        scanf("%d", &tmp);
        v.push_back(tmp);
    }

    auto itr = find(v.begin(), v.end(), 1);
    f = distance(v.begin(), itr);
    b = N - 1 - f;

    int ans = 0;

    --K;

    if (f >= K){
        ans += (f / K);
        f = f % K;
    }
    if (b >= K){
        ans += (b / K);
        b = b % K;
    }

    int sum = f + b + 1;
    ++K;

    if (sum >= 2 && sum <= K){
        ans += 1;
    } else if (sum >= 2){
        ans += 2;
    }

    printf("%d", ans);

	return 0;
}

Measured memory_bytes: 892
N, M = map(int, input().split())
ac = [0] * N
wa = [0] * N

for p, S in [tuple(input().split()) for _ in range(M)]:
    p = int(p) - 1
    if S == 'WA' and ac[p] != 1:
        wa[p] += 1
        continue
    if S == 'AC':
        ac[p] = 1
pena = 0
for i in range(N):
    if ac[i] == 1:
        pena += wa[i]
print(sum(ac), pena)



Measured memory_bytes: 70616
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, temp, temp2;
  cin >> N;

  vector<int> seq;
  vector<int> slime;
  vector<int> birth;
  vector<pair<decltype(slime)::iterator, int>> slime_done;

  long long n2 = 1 << N;
  for (long long i = 0; i < n2; i++) {
    cin >> temp;
    seq.push_back(temp);
  }
  sort(seq.begin(), seq.end());
  slime.push_back(seq.back());
  seq.back() = -INF;
  long long cnt = 0;

  for (int i = 0; i < N; i++) {
    vector<int> pre = slime;
    sort(pre.begin(), pre.end());
    auto now = seq.end() - 1;
    cnt = n2 - 1;
    while (pre.size() > 0 && cnt >= 0) {
      if (seq[cnt] == -INF) {
        cnt--;
        continue;
      }
      if (seq[cnt] < pre.back()) {
        slime.push_back(seq[cnt]);
        pre.pop_back();
        seq[cnt] = -INF;
      }
      cnt--;
    }
    if (pre.size() > 0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 3316
#pragma GCC optimize ("O3")
    
#include <bits/stdc++.h>
 
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long
 
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
 
signed main()
{
	fast;
	int n;
	string s;
	cin >> n;
	cin >> s;
	vector<int> r, g, b;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') r.push_back(i);
		else if(s[i] == 'G') g.push_back(i);
		else b.push_back(i);
	}
	int ans = r.size() * b.size() * g.size();
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if ((2*j - i < n) && ((s[i] != s[j]) && (s[j] != s[2*j - i]) && (s[i] != s[2*j - i]))) {
				ans--;
			}
		}
	}
	cout << ans;
}
//4 * 3 * 2 / 6 = 4

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
const ll INF = 1LL << 60;

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

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

ll f(ll n){
  ll res;
  if(((n+1)/2)%2 == 0) res = 0;
  else res = 1;
  if(n%2 == 0) return res ^ n;
  else return res;
}

int main(){
  ll a,b; cin >> a >> b;
  ll ans = 0;

  std::cout << (f(a-1) ^ f(b)) << '\n';
}


Measured memory_bytes: 256
#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)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
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;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    int n;
    cin >> n;
    int n3 = 3 * n;
    vector<ll> v(n3);
    rep(i, n3) cin >> v[i];
    sort(v.rbegin(), v.rend());
    ll ans = 0;
    rep(i, n) ans += v[i * 2 + 1];
    cout << ans << endl;
}


Measured memory_bytes: 2560
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
ans = 0.0
for x in a:
    ans += 1.0 / x
print(1.0 / ans)

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

void solve() {
    int N, a[50], x[100], y[100], m = 0, max_i = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", a+i);
        if (abs(a[i]) > abs(a[max_i])) max_i = i;
    }

    printf("%d\n", 2*N-2);
    for (int i = 0; i < N; i++) {
        if (i == max_i) continue;
        printf("%d %d\n", max_i+1, i+1);
    }
    int diff = a[max_i] < 0 ? -1 : 1;
    int init = a[max_i] < 0 ? N : 1;
    for (int i = 0; i < N-1; i++) {
        int x = init + diff * i, y = x + diff;
        printf("%d %d\n", x, y);
    }
}

int main() {
    solve();
    return 0;
    int N;
    scanf("%d", &N);
    long int a[100];
    int x[200], cnt=0; //x,yの値を入れていく
    for (int i=0; i < N; i++) { scanf("%ld", a+i); }
    for (int i=0; i < N -1; i++, cnt+=2) {
        if (a[i] > a[i+1]) {
            if (a[i] >= 0 && a[i+1] >= 0 ) {
                a[i+1] += a[i];
                x[cnt] = i+1;
                x[cnt+1] = i+2;
                //printf("%d %d", i+1, i+2); x,yがそれぞれi+1,i+2
            }else if (a[i] >= 0 && a[i+1] < 0) {
                a[i+1] += a[i];
                x[cnt] = i+1;
                x[cnt+1] = i+2;
                //printf("%d %d", i+1, i+2); x,yがそれぞれi+1,i+2
            }else if (a[i] < 0 && a[i+1] >= 0 ) {
                a[i+1] += a[i];
                x[cnt] = i+1;
                x[cnt+1] = i+2;
                //printf("%d %d", i+1, i+2); x,yがそれぞれi+1,i+2
            }else {
                a[i] += a[i+1];
                x[cnt] = i+2;
                x[cnt+1] = i+1;
                //printf("%d %d", i+2, i+1); x,yがそえぞれあi+2,i+1
            }
            i = 0; //iを0にして先頭から大小比較
        }else {
            cnt -= 2;
        }
    }
    printf("%d\n", cnt/2);
    for (int i=0; i < cnt; i+=2) {
        if (x[i] != 0) {
            printf("%d %d\n", x[i], x[i+1]);
        }else {
            continue;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
 
ll gcd(int a, int b){
  if(b == 0) return a;
  int r = a%b;
  return gcd(b,r);
}

int main(){
  int n,k;
  cin>>n>>k;
  bool ok = false;
  bool ok2 = false;
  int g = 0;
  rep(i,n){
    int a;
    cin>>a;
    if(a>k) ok = true;
    if(a==k) ok2 = true;
    
    if(ok2){
      cout << "POSSIBLE" << endl;
      return 0;
    }
    g = gcd(a,g);
  }
  if(!ok){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if(k%g == 0){
    puts("POSSIBLE");
  }else{
    puts("IMPOSSIBLE");
  }
}


Measured memory_bytes: 256