akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n, x;
   cin >> n >> x;
   while(!(n==0&&x==0)) {
       int count = 0;
       for(int i = 1;i <= n - 2;i++) {
           for(int j = i + 1;j<=n-1;j++) {
               for(int k = j + 1;k <= n;k++) {
                   if(i+j+k==x) {
                       count++;
                   }
               }
           }
       }
       cout << count << endl;
       cin >> n >> x;
   }
   return 0;
}


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

using namespace std;

string s[101];

int main() {
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    int r = 0;
    for (int i = 0; i < n + 2; ++i) {
        if (i == 0 || i == n + 1) {
            for (int j = 0; j < k + 2; ++j) {
                cout << '#';
            }
            cout << endl;
        } else {
            for (int j = 0; j < k + 2; ++j) {
                if (j == 0 || j == k + 1) {
                    cout << '#';
                } else {
                    cout << s[r];
                    j+=s[r].length() - 1;
                    r++;
                }
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    Ai = tuple(map(int, input().split()))
    P = 10**9 + 7

    # print(N)
    # print(Ai)

    lis = []
    if N % 2 == 0:
        for i in range(1, N, 2):
            lis.append(i)
            lis.append(i)
        # print(lis)
    else:
        lis.append(0)
        for i in range(2, N, 2):
            lis.append(i)
            lis.append(i)
        # print(lis)

    if not (len(Ai) == len(lis) and sorted(Ai) == sorted(lis)):
        return 0

    if N % 2 == 0:
        return pow(2, len(lis) // 2, P)
    else:
        return pow(2, (len(lis) - 1) // 2, P)


if __name__ == '__main__':
    res = solve()
    print(res)


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a < b)
        OP("a < b")
    else if (a > b)
        OP("a > b")
    else
        OP("a == b")

    return 0;
}


Measured memory_bytes: 3084
n=int(input())
a=list(map(int,input().split()))
color=[]
count=int(0)
for i in range(9):
    color.append(0)
for i in range(n):
    if 1<=a[i]<400:
        color[0]+=1
    elif 400<=a[i]<800:
        color[1]+=1
    elif 800<=a[i]<1200:
        color[2]+=1
    elif 1200<=a[i]<1600:
        color[3]+=1
    elif 1600<=a[i]<2000:
        color[4]+=1
    elif 2000<=a[i]<2400:
        color[5]+=1
    elif 2400<=a[i]<2800:
        color[6]+=1
    elif 2800<=a[i]<3200:
        color[7]+=1
    elif 3200<=a[i]:
        color[8]+=1
for i in range(8):
    if color[i]!=0:
        count+=1
high=int(0)
low=int(0)
high=max(count,count+color[8])
if count>=1:
    low=count
elif count==0:
    low=1
print(low,high)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#include <string>
#include <cctype>

int main() {
    int pTarou = 0, pHanako = 0, n;
    string sTarou, sHanako;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> sTarou >> sHanako;
        if (sTarou > sHanako) pTarou += 3;
        else if (sTarou < sHanako) pHanako += 3;
        else if (sTarou == sHanako){
            pTarou++;
            pHanako++;
        }
    }

    cout << pTarou << " " << pHanako << endl;

    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>

#define REP(i,n) for(int i = 0; i < (n); i++)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = 0;
	for (auto c : s) {
		if (c == '+') { ++n; }
		else { --n; }
	}
	cout << n << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt)
    var all = 3
    repeat(n - 1) {
        all *= 3
    }

    val reuslt = all - an.map { if (it % 2 == 1) 1 else 2 }.reduce { i1, i2 -> i1 * i2 }
    println(reuslt)
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
  ios::sync_with_stdio(false); \
  cin.tie(NULL);               \
  cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
  if (a > b)
    a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
  if (a < b)
    a = b;
}
template <typename T>
void print(vector<T> &a)
{
  for (int i = 0; i < a.size(); i++)
    cout << a[i] << ' ';
  cout << en;
}
template <typename T>
void print(deque<T> &a)
{
  for (int i = 0; i < a.size(); i++)
    cout << a[i] << ' ';
  cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
  for (int i = 0; i < a.size(); i++)
  {
    for (int j = 0; j < a[i].size(); j++)
      cout << a[i][j] << ' ';
    cout << en;
  }
}

int main()
{
  
  #ifndef ONLINE_JUDGE
  freopen("input.txt.txt","r",stdin);
  freopen("output.txt.txt","w",stdout);
  freopen("error.txt","w",stderr);
  #endif
  ll n,i;
  cin >> n;
  ll a[n];
  ll x=0;
  for(i=0;i<n;i++){
    cin>>a[i];
    x=x^a[i];
  }
  for(i=0;i<n;i++){
    ll y=x^a[i];
    cout<<y<<" ";
  }
}


Measured memory_bytes: 5168
#include<stdio.h>
int main()
{
  int a,b,a1[3],i,large;
  scanf("%d%d",&a,&b);
  a1[0]=a+b; a1[1]=a-b; a1[2]=a*b;
  large=a1[0];
  for(i=1;i<=2;i++)
  {
    if(a1[i]>large)
    {
      large=a1[i];
    }
  }
  printf("%d\n",large);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

using namespace std;

const int INF = 1e9;
int k;
int a[50][100005];

int f(int p, int q)
{
    if(p > 45) return INF;
    if(q == 0 && p != 0) return p;
    if(a[p][q]) return a[p][q];
    a[p][q] = INF;
    for(int i = 0; i <= 9; i++)
    {
        a[p][q] = min(a[p][q], f(i + p, (q * 10 + i) % k));
    }
    return a[p][q];
}

int main()
{
    scanf("%d", &k);
    while(k % 10 == 0)
    {
        k /= 10;
    }
    printf("%d", f(0, 0));
    return 0;
}


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

typedef long long ll;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    int n = s.size();
    for(i = 0;i < n;++i){
        if(s.at(i) != s.at(n-1-i)){
            cout << "No" << endl;
            return 0;
        }
    }
    for(i = 0;i < (n-1)/2;++i){
        if(s.at(i) != s.at((n-3)/2 - i)){
            cout << "No" << endl;
            return 0;
        }
    }
    for(i = 0;i < (n-1)/2;++i){
        if(s.at(i + (n+1)/2) != s.at(n- 1 - i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 2e5+5;
const int MOD= 998244353;
int n,b[MAXN];
struct node{
    int x,y;
}a[MAXN];
bool cmp(node a,node b){
    return a.x<b.x;
}
struct nd{int id,x;};
ll dp[MAXN];
int main()
{
    scanf("%d",&n);
    rep(i,1,n){
        scanf("%d%d",&a[i].x,&a[i].y);
        a[i].y+=a[i].x-1;
    }
    sort(a+1,a+n+1,cmp);
    rep(i,1,n)b[i]=a[i].x;
    dp[n+1]=1;
    stack<nd>st;
    nd xx;
    xx.id=n+1,xx.x=0x3f3f3f3f;
    st.push(xx);
    per(i,n,1){
        while(a[i].y>=st.top().x)st.pop();
        nd p=st.top();
        //if(i!=n&&a[i].y>a[i+1].x)a[i].y=max(a[i].y,a[i+1].y);
        //int p=upper_bound(b+1,b+n+1,a[i].y)-b;
        dp[i]=(dp[i+1]+dp[p.id])%MOD;
        p.id=i;
        p.x=a[i].x;
        st.push(p);

    }
    printf("%lld\n",dp[1]);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<lu> vu;
typedef vector<v> vv;
typedef vector<vu> vvu;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
typedef pair<lu, lu> puu;
typedef vector<puu> vpuu;
const ll MOD = 1000000007;
const ld PI = 2 * acos(0.0);
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo        \
    {              \
        no return; \
    }

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false)
{
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++)
    {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1)
{
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++)
    {
        // printf("%lu ", a[i]);
        cout << a[i] << " ";
    }
    cout << endl;
}

template <typename T, typename A>
void papair(vector<T, A> const &a, ll begin = 0, ll end = -1)
{
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++)
    {
        // printf("%lu ", a[i]);
        cout << a[i].first << " " << a[i].second << endl;
    }
}

void solve()
{
    ll n;
    cin >> n;
    vector<ll> arr = ga(n + 1);
    // if (arr[0] != 0)
    // {
    //     cout << -1;
    //     return;
    // }
    v sufs = arr;
    for (ll i = n - 1; i >= 0; i--)
    {
        sufs[i] += sufs[i + 1];
    }
    ll nv = 0, cur = 1;
    for (ll i = 0; i <= n; i++)
    {
        // cout << sufs[i] << '\n';
        // if (i <= 60)
        // {
        //     if (arr[i] > (1LL << i))
        //     {
        //         cout << -1;
        //         return;
        //     }
        // }
        // cout << sufs[i] << " " << cur << "\n";
        if (cur <= (1LL << 62))
        {
            if (arr[i] > cur)
            {
                cout << -1;
                return;
            }
            nv += min(sufs[i], cur);
            cur -= arr[i];
            cur *= 2;
        }
        else
        {
            nv += sufs[i];
        }
    }
    cout << nv;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll n,temp;
    cin >> n;

    ll result = 0;
    rep(i,n){
        cin >> temp;
        if((i+1)%2!=0){
            if(temp % 2 != 0){
                result++;
            }
        }
    }

    cout << result;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+100;
int a[maxn];
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[n/2-1];
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    string s;
    ll n,m;
    while(cin>>s>>n>>m){
        cout<<s<<" ";
        cout<<n+m<<" ";
        cout<<n*200+m*300<<endl;
    }
    
    return 0;
}


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


public class Main {
    static char bondBase(char b){
        if(b=='A') return 'T';
        if(b=='T') return 'A';
        if(b=='C') return 'G';
        if(b=='G') return 'C';
        return '?';
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char b = sc.next().charAt(0);
        System.out.println(bondBase(b));
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e8+1000;
int t,p[maxn],k,q;
bool vis[maxn];
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    if(t>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

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

		int r = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());

		for (int i = 0; i < 10; i++) {
			x = r * x - d;
			System.out.println(x);
		}

	}
}

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

void fnInput(int &rnMaxSiz, vector<int> &rvnBSort, int &rnMaxElm)
{
  rnMaxElm = 0;
  cin >> rnMaxSiz;

  rvnBSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
  {
    cin >> rvnBSort[i];
    rnMaxElm = max(rnMaxElm, rvnBSort[i]);
  }
}

void fnCntSort(const vector<int> &cnrvnBSort,vector<int> &rvnASort, int nMaxElm)
{
  vector<int> vnCnt;

  vnCnt.resize(nMaxElm);

  for (int i = 0; i < cnrvnBSort.size(); i++)
    vnCnt[cnrvnBSort[i]]++;

  for (int i = 1; i <= nMaxElm; i++)
    vnCnt[i] += vnCnt[i - 1];

  for (int i = cnrvnBSort.size() - 1; i >= 0; i--)
  {
    rvnASort[vnCnt[cnrvnBSort[i]] - 1] = cnrvnBSort[i];
    vnCnt[cnrvnBSort[i]]--;
  }
}

void fnResult(const vector<int> &cnrvnASort)
{
  for (int i = 0; i < cnrvnASort.size(); i++)
  {
    if (i)  cout << " ";
    cout << cnrvnASort[i];
  }
  cout << endl;
}

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

  int nMaxSiz, nMaxElm;
  vector<int> vnBSort, vnASort;

  fnInput(nMaxSiz, vnBSort, nMaxElm);
  vnASort.resize(nMaxSiz);

  fnCntSort(vnBSort, vnASort, nMaxElm);

  fnResult(vnASort);

  return 0;
}

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

int main() {
  int N,
      nowD = 0,
      max = 0;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  for (int i = 0; i < N; i++) {
    if (nowD < d.at(i)) {
      max++;
      nowD = d.at(i);
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] data = new String[3];
		for(int i=0; i<3; i++){
			data[i] = sc.next();
		}
		for(int i=0; i<3; i++){
			System.out.print(data[i].charAt(i));
		}
	}
}

Measured memory_bytes: 21588
N, C = map(int, input().split())
D = [list(map(int, input().split())) for k in range(C)]
G = [list(map(int, input().split())) for k in range(N)]

M = [[0,0,0] for k in range(C)]
for x in range(N):
    for y in range(N):
        M[G[x][y]-1][(x+y)%3] += 1

ans = 10**9
for p in range(C):
    for q in range(C):
        for r in range(C):
            if p!=q and q!=r and r!=p:
                t = 0
                for s in range(C):
                    t += D[s][p]*M[s][0]+ D[s][q]*M[s][1] + D[s][r]*M[s][2]
                ans = min(t,ans)

print(ans)

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

ll ara[100005] ;
ll ans[100005] ;

ll ck( ll x , ll y ){
    if( x<0 && y <0  ){
         x*=-1 , y*=-1;
         return abs(x-y) ;
    }
    else if( x<0 || y<0 ){
         x = abs(x) , y = abs(y) ;
         return x+y;
    }
    else{
        return abs(x-y) ;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) ;
   // freopen("input.txt" , "r" , stdin) ;
    ll n ;
    cin >> n ;
    for( ll i = 1; i<=n ; ++i ){
          cin >> ara[i] ;
    }
    ll s = 0 ;
    ll y ;
    for( ll i = 0 ; i<=n ; ++i  ){
         s+=ck( ara[i] , ara[i+1] ) ;
         if(i==n-2) y = s;
    }
    ans[n] = y + ck( ara[n-1] , 0 ) ;
    for( ll i = n-1 ; i>=1 ; --i ){
         ans[i] = s - ck(ara[i] , ara[i-1])-ck( ara[i] , ara[i+1] ) + ck( ara[i-1] , ara[i+1] ) ;
    }
    for( ll i = 1 ; i<=n ; ++i ){
         cout << ans[i] << endl;
    }
}


Measured memory_bytes: 2816
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val dict = mutableMapOf<Pair<Byte, Byte>, Long>()
	for (i in 1..n){
		val dig = dig(i)
		dict[dig] = dict.getOrElse(dig, {0L}) + 1L
	}
	var s = 0L
	dict.keys.forEach { k ->
		val t = k.exchange()
		s += dict[k]!!*dict.getOrElse(t, {0L})
	}
	println(s)
}

fun numDig(n:Int): Int{
	var ans = 1
	var n = n
	while (n/10!=0){
		ans *= 10
		n /= 10
	}
	return ans
}

fun dig(n: Int): Pair<Byte, Byte> =
	Pair(((n / numDig(n)) % 10).toByte(), (n % 10).toByte())

fun Pair<Byte, Byte>.exchange() = Pair(this.second, this.first)

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

int main() {

    long long int a,b,x;

    cin >> a >> b >> x;

    long long int ans = 0;

    if(a==b){
        if(b%x == 0){
            ans++;
        }
        cout << ans << endl;
        return 0;
    }

    if(a==0){
        ans++;
        cout << ans + b/x << endl;
        return 0;
    }

    ans = b/x - (a-1)/x;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
answer = 0
## k = sorted(k, reverse=True, key=lambda x: len(x))

all = [] # 全てのスイッチの状態
for i in range(0, 2**n):
  all.append(list(str(format(i, 'b').zfill(n))))

for a in all:
  for index in range(len(k)):
    switch_count = 0 
    for switch in k[index]: #1,2
        switch_count+=int(a[switch-1])
    #一つの電球に繋がってる全てのスイッチ確認終了
    if switch_count%2 == p[index]:
      if index == len(k)-1:
      	answer+=1
      continue
    break

print(answer)
    

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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

bool solve(string s) {
    if (s.substr(0, 7) == "keyence") return true;
    if (s.substr(s.size() - 7, 7) == "keyence") return true;

    string keyence = "keyence";
    int l = 0;
    rep(i, 7) {
        if (s[i] != keyence[i]) {
            l = i;
            break;
        }
    }
    if (l < 0) return false;
    reverse(keyence.begin(), keyence.end());
    reverse(s.begin(), s.end());
    int r = 0;
    rep(i, 7) {
        if (s[i] != keyence[i]) {
            r = i;
            break;
        }
    }
    if (r < 0) return false;
    return l + r >= 7;
}

signed main(void){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << (solve(s) ? "YES" : "NO") << endl;

    return 0;
}


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

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

    vector<P> ab(m);

    for ( int i = 0; i < m; i++ ) {
        int tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b;
        ab[i] = make_pair(tmp_b, tmp_a);
    }

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

    int right_place = ab[0].first;
    vector<int> right_num;
    right_num.push_back(right_place);
    for ( int i = 1; i < m; i++ ) {
        if ( right_place <= ab[i].second ) {
            right_place = ab[i].first;
            right_num.push_back(right_place);
        }
    }

    cout << right_num.size() << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;
  bool operator<(const Puzzle &p) const{
	for(int i=0;i<N2;i++){
	  if(f[i]==p.f[i]) continue;
	  return f[i]>p.f[i];
	}
	return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)
	if(p.f[i]!=(i+1)) return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
	u=Q.front(); Q.pop();
	if(isTarget(u)) return u.path;
	int sx = u.space /N;
	int sy =u.space %N;
	for(int r=0;r<4;r++){
	  int tx=sx+dx[r];
	  int ty = sy+dy[r];
	  if(tx<0||ty<0||tx>=N||ty>=N) continue;
	  v=u;
	  swap(v.f[u.space],v.f[tx*N+ty]);
	  v.space=tx*N+ty;
	  if(!V[v]){
		V[v]=true;
		v.path+=dir[r];
		Q.push(v);
	  }
	}
  }
  return "unsolvable";
}

int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
	cin>>in.f[i];
	if(in.f[i]==0){
	  in.f[i]=N2;
	  in.space=i;
	}
  }
  string ans = bfs(in);
  cout <<ans.size()<<endl;
  return 0;
}



Measured memory_bytes: 30540
N,M = map(int,input().split())
A = list(map(int,input().split()))

R = [A[0]%M]


for i in range(1,N):
  R.append((R[-1]+A[i])%M)

k = set(R)
dic = {i:0 for i in k}
for item in R:
  dic[item]+=1
  
  
ans = 0
if 0 in dic:
  ans = (dic[0]*(dic[0]+1))/2


for i in k:
  if i !=0 :
    ans += (dic[i]*(dic[i]-1))/2
    

    
print(int(ans))


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

using namespace std;

namespace FastFourierTransform
{
  using C = complex< double >;

  void DiscreteFourierTransform(vector< C > &F, bool rev)
  {
    const int N = (int) F.size();
    const double PI = (rev ? -1 : 1) * acos(-1);
    for(int i = 0, j = 1; j + 1 < N; j++) {
      for(int k = N >> 1; k > (i ^= k); k >>= 1);
      if(i > j) swap(F[i], F[j]);
    }
    C w, s, t;
    for(int i = 1; i < N; i <<= 1) {
      for(int k = 0; k < i; k++) {
        w = polar(1.0, PI / i * k);
        for(int j = 0; j < N; j += i * 2) {
          s = F[j + k];
          t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
                F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
          F[j + k] = s + t, F[j + k + i] = s - t;
        }
      }
    }
    if(rev) for(int i = 0; i < N; i++) F[i] /= N;
  }

  vector< long long > Multiply(const vector< int > &A, const vector< int > &B)
  {
    int sz = 1;
    while(sz <= A.size() + B.size()) sz <<= 1;
    vector< C > F(sz), G(sz);
    for(int i = 0; i < A.size(); i++) F[i] = A[i];
    for(int i = 0; i < B.size(); i++) G[i] = B[i];
    DiscreteFourierTransform(F, false);
    DiscreteFourierTransform(G, false);
    for(int i = 0; i < sz; i++) F[i] *= G[i];
    DiscreteFourierTransform(F, true);
    vector< long long > X(A.size() + B.size() - 1);
    for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
    return (X);
  }
};

int main()
{
  int N, M, Q, A[40001], B[40001], C[100000];

  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < N; i++) scanf("%d", &A[i + 1]), A[i + 1] += A[i];
  for(int i = 0; i < M; i++) scanf("%d", &B[i + 1]), B[i + 1] += B[i];
  for(int i = 0; i < Q; i++) scanf("%d", &C[i]);

  const int SZ = 200000;
  vector< int > F(SZ + 1), G(SZ + 1);

  {
    vector< int > S(SZ + 1), T(SZ + 1);
    for(int i = 0; i <= N; i++) S[A[i]]++, T[A[i]]++;
    reverse(begin(T), end(T));
    auto R = FastFourierTransform::Multiply(S, T);
    for(int i = 1; i <= SZ; i++) {
      F[i] = R[SZ + i];
    }
  }


  {
    vector< int > S(SZ + 1), T(SZ + 1);
    for(int i = 0; i <= M; i++) S[B[i]]++, T[B[i]]++;
    reverse(begin(T), end(T));
    auto R = FastFourierTransform::Multiply(S, T);
    for(int i = 1; i <= SZ; i++) G[i] = R[SZ + i];
  }

  reverse(begin(G), end(G));
  auto X = FastFourierTransform::Multiply(F, G);
  for(int i = 0; i < Q; i++) {
    if(C[i] == 0) printf("%lld\n", X[200000]);
    else printf("%lld\n", X[200000 - C[i]] + X[200000 + C[i]]);
  }
}

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

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

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

  int ans = 1000000000;

  for (int i = -100; i < 200; ++i) {
    int tmp = 0;
    for (int j = 0; j < n; ++j) {
      int d = x[j] - i;
      tmp += d * d;
    }
    ans = min(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
S = list(input())
S_len = len(S)
num_lst = np.zeros(S_len + 1)
for i in range(S_len):
    if S[i] == "<":
        num_lst[i + 1] = max(num_lst[i] + 1, num_lst[i + 1])


for i in range(S_len - 1, -1 , -1):
    if S[i] == ">":
        num_lst[i] = max(num_lst[i], num_lst[i + 1] + 1)
print(int(np.sum(num_lst)))

Measured memory_bytes: 22568
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int y = 700;
  if(s.at(0)=='o'){y+=100;}
  if(s.at(1)=='o'){y+=100;}
  if(s.at(2)=='o'){y+=100;}
  cout << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

int main(){

	int n, m;
	
	while(cin >> n >> m, (n||m)){
		
		vector<int> tr(n), hn(m);
		int sumt=0, sumh=0, tro=-1, hno=-1;
		
		for(int i=0; i<n; ++i){
			cin >> tr[i];
			sumt+=tr[i];
		}
		
		for(int i=0; i<m; ++i){
			cin >> hn[i];
			sumh+=hn[i];
		}
		
		int dif=accumulate(tr.begin(), tr.end(), 0) - accumulate(hn.begin(), hn.end(), 0);
		
		for(int i=0; i<n; ++i){
			for(int j=0; j<m; ++j){
				if( (tr[i]-hn[j])*2==dif && ((tro<0&&hno<0) || (tro+hno>tr[i]+hn[j]))){
					tro = tr[i];
					hno = hn[j];
				}
			}
		}
		
		if(tro<0&&hno<0)
			cout << -1 << endl;
		else
			cout << tro << " " << hno << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
const long long nmax=5e6+3;
const long long mod=1e9+7;
long long d[nmax],nr[nmax],k,x,n,v[nmax];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    d[0]=1;
    for(long long i=1;i<=n;++i)
    {
        cin>>x;
        if(x==v[k]) continue;
        v[++k]=x;
        d[k]=(d[k-1]+nr[x])%mod;
        nr[x]=(nr[x]+d[k-1])%mod;
    }
    cout<<d[k];
    return 0;
}


Measured memory_bytes: 5888
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	s := make([]string, N)

	for i := 0; i < N; i++ {
		s[i] = getString()
	}

	frontB := 0
	backA := 0
	pairAB := 0
	innerAB := 0
	for i := 0; i < N; i++ {
		if s[i][0] == 'B' && s[i][len(s[i])-1] == 'A' {
			pairAB++
		} else if s[i][0] == 'B' {
			frontB++
		} else if s[i][len(s[i])-1] == 'A' {
			backA++
		}
		for j := 1; j < len(s[i]); j++ {
			if s[i][j] == 'B' && s[i][j-1] == 'A' {
				innerAB++
			}
		}
	}

	ans := 0
	if pairAB != 0 {
		ans = pairAB - 1
		if frontB > 0 {
			ans++
			frontB--
		}
		if backA > 0 {
			ans++
			backA--
		}
	}
	ans += min(backA, frontB)
	ans += innerAB

	out(ans)

}


Measured memory_bytes: 896
(function(input) {
  'use strict';
  input.split("\n").forEach(function(line) {
    var tokens = line.split(' ').map(Number)
    if (tokens.length <= 1) return
    let a = parseInt(tokens[0], 10)
    let b = parseInt(tokens[1], 10)
    let hasEven = (a % 2 == 0) || (b % 2 == 0)
    if (hasEven) {
      console.log('No')
    } else {
      console.log('Yes')
    }
  });
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int ans = 6*5/2;
    rep(i,5) {
        int a; cin >> a;
        ans -= a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
/*
    Vora Mahammadasim
*/

#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
#define ps(a) partial_sum(all(a),a.begin())
using namespace std;

int n;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x&1&&i&1) ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll wt[100+10], v[100+10], memo[100+10][100000+10];
ll n,W;
ll go(int i, int w) {
    if (i==n) return 0;
    if (memo[i][w] != -1) return memo[i][w];
    ll best = go(i+1,w);
    if (w+wt[i] <= W) best = max(best, go(i+1,w+wt[i])+v[i]);
    return memo[i][w] = best;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> W;
    for (int i = 0; i < n; i++) cin >> wt[i] >> v[i];
    memset(memo, -1, sizeof memo);
    // for (int j = 0; j <= W; j++) {
    //     for (int i = 1; i <= n; i++) {
    //         if (w[i]+j<=W) {
    //             dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j]+v[i]);
    //         }
    //     }
    // }
    // ll ans = 0;  // max val
    // for (int i = 0; i <= W; i++) 
    //     ans = max(ans, dp[n][i]);
    // cout << ans << endl;
    cout << go(0, 0) << endl;

    return 0;
}

Measured memory_bytes: 89576
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
string a;
int cnt=0;
void tran()
{
    int len=a.size();
    if(len%2!=1)
        cnt++;//翻转一次；
    if(a[0]==a[len-1])
        cnt++;//翻转一次；
}
int main()
{
    cin>>a;
    tran();
    if(cnt%2==0)
        cout<< "First" <<endl;
    else
        cout << "Second" <<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	solve();
    }

    static void solve(){
	int ans = 0, i;
	String s, a, b="";
	while(kbd.hasNext()){
	    s = kbd.nextLine();
	    for(i=0; i<s.length(); i++){
		a = s.substring(i, i+1);
		if(a.matches("[0-9]")){
		    b += a;
		}
		else{
		    if(!b.equals("")){
			ans += Integer.parseInt(b);
			b = "";
		    }
		}
	    }
	}
	System.out.println(ans);
    }
}

Measured memory_bytes: 20448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void dfs(ll v, const vvl &g,vector<bool> &seen,vl &fir,vl &last,ll &time){
    fir[v]=time++;
    seen[v]=true;
    for(auto nv:g[v]){
        if(seen[nv])continue;
        dfs(nv,g,seen,fir,last,time);
    }
    last[v]=time++;
}
int main(){
    ll n;cin >> n;
    vvl g(n);
    rep(i,n){
        ll x;cin >> x;x--;
        ll k;cin >> k;
        rep(j,k){
            ll y;cin >> y;y--;
            g[x].pb(y);
        }
    }
    vector<bool> seen(n,false);
    vl fir(n),last(n);
    ll time=1;
    ll x=0;
    while(x<n){
        dfs((ll)x,g,seen,fir,last,time);
        while(seen[x])x++;
    }
    rep(i,n)cout <<i+1<<" "<< fir[i]<< " "<<last[i] <<endl;
}



Measured memory_bytes: 3164
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	X, Y := nextInt(), nextInt()
	for i := 0; i <= X; i++ {
		var crane, turtle int
		crane = i
		turtle = X - i
		legs := crane*2 + turtle*4
		if legs == Y {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

    int x = a * b;
    int y = c * d;
    if (x != y) {
        cout << ((x > y) ? x : y) << endl;
    } else {
        cout << x << endl;
    }
    return 0;
}

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

using namespace std;

void solve(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a == b && b == c ? "Yes" : "No") << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

#define MAX 500000
#define SENTINEL 2000000000

long L[MAX/2+2], R[MAX/2+2];
long cnt;

void merge(long x[], long n, long left, long mid, long right){
	long n1=mid-left;
	long n2=right-mid;
	
	for(long i=0; i<n1; ++i) L[i]=x[left+i];
	for(long i=0; i<n2; ++i) R[i]=x[mid+i];
	L[n1]=R[n2]=SENTINEL; //?????????????????????

	long i=0, j=0;
	for(long k=left; k<right; ++k){
		++cnt;
		if(L[i]<=R[j]) x[k]=L[i++];
		else x[k]=R[j++];
	}	
}

void mergesort(long x[], long n, long left, long right){
	if(left+1 < right){
		long mid=(left+right)/2;
		
		mergesort(x, n, left, mid);
		mergesort(x, n, mid, right);
		merge(x, n, left, mid, right);	
	}
}

int main(){
	long a[MAX], n;
	
	cnt=0;
	scanf(" %ld", &n);
	for(long i=0; i<n; ++i) scanf(" %ld", &a[i]);
	
	mergesort(a, n, 0, n);
	
	for(long i=0; i<n; ++i){
		if(i>0) printf(" ");
		printf("%ld", a[i]);
	}
	printf("\n%ld\n", cnt);
}

Measured memory_bytes: 9000
#https://atcoder.jp/contests/abc153/submissions/9769348
#https://atcoder.jp/contests/abc153/submissions/9792185
def min(a, b)
  a < b ? a : b
end
INF = 1 << 30
H, N = gets.split.map(&:to_i)
AB = N.times.map{gets.split.map(&:to_i)}.sort{|a,b|a[0]<=>b[0]}

dp = Array.new(H + AB.last[0] + 1, INF)
AB.sort_by!{|a,b| b.to_f/a }
dp[0] = 0
AB.each do |hp, mp|
  H.times do |i|
    next if dp[i] == INF
    ni = i + hp
    dp[ni] = min(dp[ni], dp[i] + mp) 
  end
  break if dp[H] < INF
end
puts dp[H..-1].min

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

int main() {
  int N;
  cin >> N;
  
  int a[N+1];
  for (int i = 0; i < N; i++) {
    cin >> a[i+1];
  }
  
  
  int ans = 0;
  for (int i = 1; i<= N; i++) {
    if (a[i] == i) {
      int count = 0;
      while(a[i] == i) {
        count++;
        i++;
      }
      
      ans += (count+1) / 2;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  b[n-1]=a[n-1];
  for(int i=n-1;i>=1;i--){
    b[i-1]=__gcd(b[i],a[i-1]);
  }
  int ma=b[1];
  int tb=a[0];
  for(int i=1;i<n-1;i++){
    ma=max(ma,__gcd(tb,b[i+1]));
    tb=__gcd(a[i],tb);
  }
  cout<<max(ma,tb)<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
typedef long long int ll;
int main(){
  ll n,m,l,r,mid,k,num;

  cin>>n>>m;
  vector<ll> a(n);
  vector<ll> s(n);
  REP(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end(),greater<ll>());
  
  s[0]=a[0];
  for(int i=1;i<n;++i) s[i]=s[i-1]+a[i];
  l=-1;
  r=2*10e5+10;
  while(r-l>1){
    mid=(l+r)/2;
    num=0;
    k=n-1;
    for(int i=0;i<n;++i){
      for(int j=k;j>-1;--j){
	if(a[j]>mid-a[i]) break;
	--k;
      }
      num+=k+1;
    }
    (num>m?l:r)=mid;
  }
  ll ans=0;
  num=0;
  k=n-1;
  for(int i=0;i<n;++i){
    for(int j=k;j>-1;--j){
      if(a[j]>r-a[i]) break;
      --k;
    }
    if(k!=-1) ans+=s[k]+(k+1)*a[i];
    num+=k+1;
  }
  
  ans+=(m-num)*r;
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
S = raw_input()
T = raw_input()

CS = {}
for s in S:
	if s not in CS:
		CS[s] = 1
	else:
		CS[s] += 1
TS = {}
for t in T:
	if t not in TS:
		TS[t] = 1
	else:
		TS[t] += 1

if False in [CS[S[i]] == TS[T[i]] for i in range(len(T))]:
	print 'No'
else:
	print 'Yes'


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

int main(void){
  int n,i,sum=0,ans;
  scanf("%d",&n);
  int a[n+2];
  a[0]=a[n+1]=0;
  for(i=1;i<n+1;i++) scanf("%d",&a[i]);
  for(i=0;i<n+1;i++) sum+=abs(a[i]-a[i+1]);
  for(i=1;i<n+1;i++){
    ans=sum+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]));
    printf("%d\n",ans);
  }
  return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "No" << endl
#define yes cout << "Yes" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    ll n, m; cin >> n >> m;
    if (n == m) yes;
    else no;
}

Measured memory_bytes: 3668
w, h, n = map(int, input().split())
origin = [0,0]
edge = [w,h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
      if origin[0] < x:
          origin[0] = x
    elif a == 2:
      if x < edge[0]:
          edge[0] = x
    elif a == 3:
      if origin[1] < y:
          origin[1] = y
    else:
      if y < edge[1]:
          edge[1] = y

width = edge[0] - origin[0]
height = edge[1] - origin[1]
if width < 0:
  width = 0
if height < 0:
  height = 0

print(width * height)

Measured memory_bytes: 9112
N=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
b=prime_factorize(N)
if b==1:
    print(0)
else:
    number=0
    c=list(set(b))
    for i in tuple(c):
        d=b.count(i)
        if 1<=d<=2:
            number+=1
        elif 3<=d<=5:
            number+=2
        elif 6<=d<=9:
            number+=3
        elif 10<=d<=14:
            number+=4
        elif 15<=d<=20:
            number+=5
        elif 21<=d<=27:
            number+=6
        elif 28<=d<=35:
            number+=7
        elif 36<=d<=45:
            number+=8
    print(number)

Measured memory_bytes: 9276
while True :
    H,W = map(int,input().split(" "))

    if H == 0 and W == 0 :
        break

    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()


Measured memory_bytes: 7008
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define PI 3.14159265359

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int result[101] = {};
    repr(i, a, b+1) result[i]++;
    repr(i, c, d+1) result[i]++;
    int length = 0;
    repr(i, 0, 102){
        if(result[i] == 2) length++;
    }
    if(length != 0){
        cout << length-1 << endl;
    }else{
        cout << length << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
module Main where
 
import Control.Applicative
import Text.Printf
import Numeric
 
main :: IO ()
main = loop

loop :: IO ()
loop = do
  {[h, w] <- getInts
  ; if h == 0 && w == 0 then return ()
    else do
      { let oneline = replicate w '#'
      ; let rect    = replicate h oneline
      ; putStr $ unlines rect
      ; putStrLn ""
      ; loop
      }
  }
--
  
getInts :: IO[Int]
getInts = map read . words <$> getLine
 
putInts :: [Int] -> IO()
putInts = putStrLn . unwords. map show
 
getDoubles :: IO[Double]
getDoubles = map read. words <$> getLine
 
putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble
 
showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""
 
getStrings :: IO [String]
getStrings = words <$> getLine
 
readInt' :: String -> Int
readInt' = read



Measured memory_bytes: 4260
from fractions import gcd
from functools import reduce


def main():
    n = int(input())
    numbers_gcd = reduce(gcd, list(map(int, input().split())))
    answer = 0
    while numbers_gcd > 0:
        if numbers_gcd % 2:
            break
        else:
            numbers_gcd //= 2
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5432
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    x=gcd(360,x);
    cout<<360/x<<'\n';
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;

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

    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(S + 1));
    for (int i = 0; i < N; ++i) {
        if (A[i] <= S)
            dp[i + 1][A[i]] += (i + 1);
        for (int j = 0; j <= S; ++j) {
            dp[i + 1][j] += dp[i][j];
            if (j > A[i])
                dp[i + 1][j] += dp[i][j - A[i]];
            dp[i + 1][j] %= MOD;
        }
    }

    ll ans = 0;
    for (int i = 0; i <= N; ++i)
        (ans += dp[i][S]) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784