akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  var A = input[1].split(" ").map(i => parseInt(i));
  A.sort(function(a,b){return b-a});
  var t = new Array(M);
  input.shift();
  input.shift();
  var t=input.map(i => i.split(" ").map(i => parseInt(i)));
  t.pop();

  t.sort(function(a, b) {
    if (a[1] < b[1]) return 1;
    if (a[1] > b[1]) return -1;
    return 0;
  });
  var ans=0;
  while(A.length!=0){
    if(A[0]>=t[0][1]){
      ans+=A[0];
      A.shift();
    }else{
      break;
    }
  }
  for(var i=0;i<M;i++){
    var c=t[i][0];
    while(c>0&&A[A.length-1]<t[i][1]){
      A.pop();
      ans+=t[i][1];
      c--;
    }
  }
  for(var i=0;i<A.length;i++){
    ans+=A[i];
  }


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 58888
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;
int palin(string s)
{
	int l=s.size(),i,f=0;
	for(i=0;i<l;i++)
	{
		if (s[i]!=s[l-i-1])
		{
			f=1;
			break;
		}
		
	}
	if (f==0)
	return 1;
	else
	return 0;
}
int main()
{
  string s,s1,s2;
  cin>>s;
  ll int l=s.size();
  
  s1=s.substr(0,(l-1)/2);
  
  s2=s.substr((l+1)/2,(l-1)/2);
  
  if((palin(s1)==1)&& (palin(s2)==1) &&(palin(s)==1))
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}



	
  
  

		
		
		
		
		
		
	
	
	 
		
		
	
	
	

	


	
	
	
   



Measured memory_bytes: 256
using System;

public class ABC162_A {
	private static void Main(string[] args) {
		var n = ReadInt();

		var answer = (n / 100 == 7 || n / 10 % 10 == 7 || n % 10 == 7) ? "Yes" : "No";
		Console.WriteLine(answer);
	}

	private static int ReadInt() => int.Parse(Console.ReadLine().Trim());
}

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

int main() {

  int h, w;
  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0){
      break;
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3024
n, k = map(int, input().split())
r, s, p = map(int, input().split())
d = {'r':r, 's':s, 'p':p}
t = input()
def janken(x):
    if x == 'r':
        return 'p'
    elif x == 's':
        return 'r'
    else:
        return 's'
l = ['']*k
for i in range(n):
    l[i%k] += t[i]
ans = 0
for i in l:
    pre = i[0]
    ans += d[janken(i[0])]
    for j in range(1, len(i)):
        if i[j] != pre:
            ans += d[janken(i[j])]
            pre = i[j]
        else:
            pre = ''
print(ans)

Measured memory_bytes: 6132
import itertools

n=int(input())
p= list(map(int, input().split()))
q= list(map(int, input().split()))
x=[i+1 for i in range(n)]

x=list(itertools.permutations(x))
a=0
b=0

for i in range(len(x)):
    if list(x[i])==p:
        a=i
    if list(x[i])==q:
        b=i

print(abs(a-b))

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

int main() {
    int x;
    cin >> x;
    if(x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int IINF = numeric_limits<int>::max();

int main() {

    int n, k;
    cin >> n >> k;
    //VLL a(n,0);
    map<string, int> m;

    REP(i,n) {
        int num;
        cin >> num;
        string tmp = to_string(num);
        if (m[tmp]==0) { m[tmp]=1;}
        else { m[tmp]+=1; }
    }

    priority_queue<int, vector<int>, greater<int>> que;

    for (auto i=m.begin();i!=m.end();i++) {
        // cout << i->first << " " << i->second << endl; 
        que.push(i->second);
    }

    int tmp_size = (int)m.size();
    int ans = 0;

    while(tmp_size>k) {
        //cout << que.top() << endl;
        ans += que.top();
        tmp_size--;
        que.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19944
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
bc = []
bc = [list(map(int,input().split())) for _ in range(M)]
bc.sort(key=lambda x:x[1],reverse=True)
ai = 0
for b,c in bc:
  cc = b
  while ai<N and cc >0:
    if A[ai] < c:
      A[ai] = c
      cc -= 1
    ai +=1
    if ai == N:
        break
print(sum(A))

  
  

Measured memory_bytes: 32968
# coding: utf-8
# Your code here!
import math

ans = 0
while True:
   try:
      n = int(input())
      if n == 2:
         ans += 1
         continue
      if n % 2 == 0:
         continue
      
      c = 0
      for i in range(2, math.floor(math.sqrt(n)) + 1):
         if n % i == 0:
            c += 1
      if c == 0:
         #print("#", n)
         ans += 1

   except EOFError:
      break
   
print(ans)
   



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

Array = [list(map(int, input().split())) for _ in range(N)]

# print(Array)

Array.sort(key=lambda x:x[0])

# print(Array)
# print(Array[0][0])

# Array.sort(key=lambda x:x[1])
#
# print(Array)

for i in range(N):
    if Array[i][1] <= T:
        print(Array[i][0])
        break
else:
  print('TLE')


Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int A = in.Int();
            int B = in.Int();
            int C = in.Int();
            int D = in.Int();
            while (0 < A) {
                A -= D;
                C -= B;
                if (C <= 0) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32844
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define rep(i,from,to) for(int i=from;i<to;i++)
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
	chutiyaap;
	int n;
    cin>>n;
	int a[n];
	map<int,int> mp;
	ll total=0;
	rep(i,0,n)
	{
		cin>>a[i];
		mp[a[i]]++;
		total+=(mp[a[i]]-1);
	}
	rep(i,0,n){
		ll ans=total-(mp[a[i]]-1);
		cout<<ans<<endl;
	}
	return 0;

}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 3e5 + 7;

ll a, b, c, T, d, e, l, r, x, y, z, mid, cnt, flag, mod = 1e9+7, p[MAX1], num[MAX1], now[MAX1], first[MAX1];
string s, t;
vector <ll> vec;

int main(){
	fast_io;
	cin >> a;
	cin >> b;
	cout << max(ll(0), a-2*b);
    return 0;
}
/*                          now or never                         */


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int n, d, x;
vector<int> a;

void solve() {
	cin >> n >> d >> x;
	int sum = 0;
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		int day = 1;
		int cnt = 1;
		while((day * a[i] + 1) <= d) {
			day++;
			cnt++;
		}
		sum += cnt++;
	}
	cout << sum  + x << endl;
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#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(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    fr(i,n){
        if(i==k-1){
            cout<<(char(s[i]+32));
        }
        else cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int ggg(int i,int j,int k){
 int a = __gcd(i,j);
  int b = __gcd(j,k);
  return __gcd(a,b);
}

int main() {
  int K;
  in(K);
  int ans =0;
  rep(i,K){
   rep(j,K){
    rep(g,K){
      ans += ggg(i+1,j+1,g+1);
    }
   }
  }
  out(ans);
}


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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int G(LL x, int p){
	int res = 0;
	while(x % p == 0){
		res++;
		x /= p;
	}
	return res;
}

const int D = 45;
const int P = 20;
int cnt[D][P];

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

	int n; cin >> n;
	LL ans = 0;
	FOR(j, 0, n){
		string s; cin >> s;
		LL x = 0;
		int C = 0;
		bool was = 0;
		for(auto i: s){
			if (i != '.'){
				x = x * 10 + i - '0';
				if (was) C++;
			}else was = 1;
		}

		FOR(it, 0, 9 - C) x *= 10;
		int a = G(x, 2), b = G(x, 5);
		FOR(c, 0, D) if (c + a >= 18) FOR(d, 0, P) if (d + b >= 18){
			ans += cnt[c][d];
		}
		cnt[a][b]++;		
	}
	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  vector<bool> vb(n,true);
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    if(v[a-1]==v[b-1]){
      vb[a-1] = false;
      vb[b-1] = false;
    }else if(v[a-1]>v[b-1]){
      vb[b-1] = false;
    }else{
      vb[a-1] = false;
    }
  }
  int cnt = 0;
  for(int i=0;i<n;i++){
    if(vb[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long temp;
long long cal(string x,long long s)
{
	if(x.length()==1)
	{
		ss.clear();
		ss<<x;
		ss>>temp;
		return temp+s;
	}
	else
    {
        long long sum=0;
        for(long long i=1;i<x.length();i++)
        {
            string y=x.substr(0,i);
            string z=x.substr(i,x.length()-i);
            ss.clear();
            ss<<y;
            ss>>temp;
            sum+=cal(z,s+temp);
        }
        ss.clear();
        ss<<x;
        ss>>temp;
        sum+=(temp+s);
        return sum;
    }
}
int main(void)
{
	string x;
	cin>>x;
	cout << cal(x,0)<<endl;
	return 0;
 }


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

int main(void)
{
	int M, N;
	cin >> M >> N;
	double rate = pow(2, N);
	int result = (100 * (M - N) + 1900 * N)*(int)rate;
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int dp[3010][3010];

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

    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
            }
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
        }
    }

    string ans="";
    int i=s.size(),j=t.size();
    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j]) i--;
        else if(dp[i][j]==dp[i][j-1]) j--;
        else{
            ans+=s[i-1];
            i--,j--;
        }
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  ll a[200010];
  string s;
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  for(i=0;i<n-2;i++){
    for(j=i+1;j<n-1;j++){
      for(k=j+1;k<n;k++){
        if(a[i]==a[j] || a[j]==a[k]) continue;
        if(a[k]<a[i]+a[j]) result++;
      }
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
N=int(input())
for _ in range(N):
    p=list(map(float,input().split()))
    a,b,c,d=map(lambda x:complex(*x),[p[:2],p[2:4],p[4:6],p[6:]])
    print(['NO','YES'][abs(((a-b).conjugate()*(c-d)).imag)<1e-11])


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  int n,k;cin>>n>>k;
  if(n%k)cout<<1<<endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int solve(int n, const std::vector<int>& values)
{
  int result = 0;
  for (int i = 0; i < n; i += 2) {
    if (values.at(i) % 2) ++result;
  }
  return result;
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> values(n);
  for (auto& a : values) {
    std::cin >> a;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, values) << std::endl;
}


Measured memory_bytes: 3600
function main(input) {
  const inputArray = input.split(/\n/);
  const N = +inputArray.shift();
  const numberArray = inputArray[0].split(/\s/);
  const sum = numberArray.reduce((a,c) => a += 1/+c, 0);
  console.log(1/sum);
}
 main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.Scanner;

// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();


		for(int i=0;i<50000;i++) {
			int a = (int) (i*1.08);
			if(a==n) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(":(");
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_RatingGoal
{
    class Program
    {
        static void Main(string[] args)
        {
            int intR = int.Parse(Console.ReadLine());

            int intG = int.Parse(Console.ReadLine());

            int intX = 2 * intG - intR;

            Console.WriteLine(intX);

        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>

int main(void){
    // Your code here!
    char str[1001] = {};
    char tmp[1001] = {};
    char b1[1001]  = {};
    char b2[1001]  = {};
    char mode[10];
    
    int num1,num2;
    char repstr[1001] = {};
    
    int i,j,cnt;
    
    scanf( "%s" , str );
    scanf( "%d" , &cnt );
    
    for( ; 0 < cnt; cnt-- ){
        scanf( "%s" , mode );
        scanf( "%d %d" , &num1, &num2 );
        
        if( strcmp( mode , "print" ) == 0 ){
            //printf("print->");
            for( i = num1; i <= num2 ; i++ ){
                printf( "%c" , str[i] );
            }
            printf("\n");
        }else if( strcmp( mode , "replace" ) == 0 ){
            scanf( "%s" , repstr );
            //printf("replace->%s",repstr);
            for( i = 0, j = 0 ; i < strlen(str) ; i++ ){
                if( i < num1 || num2 < i ){
                    tmp[i] = str[i];
                    //printf("%c を %c\n", tmp[i] , str[i] );
                }else if( num1 <= i && i <= num2 ){
                    tmp[i] = repstr[j];
                    //printf("%c を %c\n", tmp[i] , str[j] );
                    j++;
                }
            }
            for( i = 0 ; i < strlen(str) ; i++ ){
                str[i] = tmp[i];
            }
            
        }else if( strcmp( mode , "reverse" ) == 0 ){
            //printf("reverse->");
            for( j = num1; j <= num2 ; j++ ){
                tmp[num2 - j] = str[j];
                //printf("%c\n", tmp[num2 - j] );
            }
            for( i = 0 , j = num1; j <= num2 ; i++ , j++ ){
                //printf("%c を %c\n", str[j] , tmp[i] );
                str[j] = tmp[i];
            }
        }
        
        //printf("モード：%s (%s)\n" , mode , str);
    }
    
}



Measured memory_bytes: 2112
#!python3

from math import factorial

iim = lambda: map(int, input().rstrip().split())

def cmb(a, b):
    c = a - b
    if c < b:
        b = c
    if b == 0: return 1

    ans = 1
    for i in range(b):
        ans *= a - i

    return ans // factorial(b)

def cnt(N, K):
    if K == 0:
        return 1

    n10 = 10 ** (K-1)
    if N < n10:
        return 0

    n10 *= 10
    n9 = 9 ** K

    ans = 0
    a = n10
    i = 0
    while a < N:
        a *= 10; i += 1
    a //= 10; i -= 1
    if i >= 0:
        ans = cmb(i+K, K) * n9
        #print(f"{i+K}C{K}", ans)

    n, b = divmod(N, a)
    if n > 1:
        ans += (n - 1) * cnt(a-1, K - 1)
    ans += cnt(b, K - 1)


    return ans

def resolve():
    N = int(input())
    K = int(input())

    print(cnt(N, K))

if __name__ == "__main__":
    resolve()


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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 3e5+35;
map<LL,int> mp;
int n,a[maxn];
int main(){
    cin >> n; LL ans = 0;
    for(int i = 1;i <= n; ++i){
        cin >> a[i];
        if(mp.count(i-a[i])) ans += mp[i-a[i]];
        mp[i+a[i]] += 1;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 16712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main();
		StringBuilder art = new StringBuilder();
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0)
				break;
			art.append(m.makeLine("#", W) + "\n");
			for (int i = 0; i < H - 2; ++i)
				art.append("#" + m.makeLine(".", W - 2) + "#" + "\n");
			art.append(m.makeLine("#", W) + "\n");
			art.append("\n");
		}
		System.out.print(art.toString());
	}
	// ex. makeLine("#", 3) == "###".
	public String makeLine(String ch, int times) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < times; ++i)
			sb.append(ch);
		return sb.toString();
	}
}


Measured memory_bytes: 28356
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 1e+18
#define MOD 998244353
using namespace std;

int main(){
    int k;
    cin >> k;
    cout<<(k/2)*(k-k/2)<<endl;
    return 0;
}


Measured memory_bytes: 256
map = []
4.times do
    a = []
    3.times do
        b = []
        10.times do
            b.push(0)
        end
        a.push(b)
    end
    map.push(a)
end

n = gets.to_i
n.times do
    b, f, r, v = gets.split.map(&:to_i)
    map[b-1][f-1][r-1] += v
end

map.each_with_index do |b, bi|
  if bi != 0
    puts "####################"
  end
  b.each_with_index do |f, fi|
    f.each_with_index do |r, ri|
      print " #{r}"
    end
    puts
  end
end


Measured memory_bytes: 6904
N, M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
A_B = {}
for i in range(1, N+1):
  A_B[i] = []

for _ in range(M):
  a, b = [int(i) for i in input().split()]
  if a in A_B:
    A_B[a].append(H[b-1])
  else:
    A_B[a] = [H[b-1]]

  if b in A_B:
    A_B[b].append(H[a-1])
  else:
    A_B[b] = [H[a-1]]

answer = 0
for i in range(1, N+1):
  Hs = A_B[i] + [H[i-1]]
  if  max(Hs) == H[i-1] and Hs.count(H[i-1]) == 1:
    answer += 1

print(answer)

Measured memory_bytes: 31516
N = int(input())
A =sorted( list(map(int, input().split())))
A_abs = list(map(abs, A))
flag = 0
for i in range(N):
    if A[i]<0:
        flag += 1
    else:
        break
if flag%2==0:
    print(sum(A_abs))
else:
    A_abs_s = sorted(A_abs)
    A_abs_s[0] = -1*A_abs_s[0]
    print(sum(A_abs_s))

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a[300000],memo[100],hoge[300000][100],ans;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a[i];
        int z=0;
        while(a[i]) {
            memo[z] += a[i]%2;
            hoge[i][z] = a[i]%2;
            a[i] /= 2;
            z++;
        }
    }
    rep(i,n) {
        int z=1;
        rep(j,60) {
            if (!hoge[i][j]) ans = (ans+memo[j]*z)%MOD;
            z*=2;
            z %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 236928
N = int(input())
cards_number = input()
numbers = list(map(int, cards_number.split()))
ordered_numbers = sorted(numbers, reverse=True)

alice_cards = []
bob_cards = []
while len(ordered_numbers) != 0:
    try:
        alice_cards.append(ordered_numbers.pop(0))
        bob_cards.append(ordered_numbers.pop(0))
    except IndexError:
        break

alice_point = sum(alice_cards)
bob_point = sum(bob_cards)

print(alice_point-bob_point)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,ans=0;
    cin>>N;
    ll B[N];
    rep(0,i,N-1){
        cin>>B[i];
    }
    ans+=B[0]+B[N-2];
    rep(1,i,N-1){
        ans+=min(B[i],B[i-1]);
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int undiv2count = 0;
	int div4count = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a % 2 == 1) undiv2count++;
		else if (a % 4 == 0) div4count++;
	}
	if (undiv2count <= div4count || (undiv2count == div4count + 1 && undiv2count + div4count == n)) cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main (){
 
  while(1) { 
 int N,M;
     
    cin >> N >> M;
    if(N == 0 && M == 0) break;
   
  int x[15000] = {0};
  for(int i=0;i<N;i++) cin >> x[i];
 
  int t,m,flg = 0;
  int memo = 0;
  t = 1;
  for(int i=0;i<M;i++) {
    cin >> m;
    t += m;
 
    if(t >= N && flg == 0) {
      flg  =1;
      memo = i+1;
    }
 
    t += x[t-1];
 
    if(t >= N && flg == 0) {
      flg  =1;
      memo = i+1;
    }
     
  }
 
  cout << memo << endl;
 
  }
 
  return 0;
}
 

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
		if (s.equals(u)) {
			a--;
		} else {
			b--;
		}
		System.out.println(a + " " + b);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int ans;
string s;

int dfs(int l, int r){
    if (l == r) return 0;
    bool flag = false;
    FOR(i, l, r)
    {
        if (s[i] != 'A' && s[i] != 'G' && s[i] != 'C' && s[i] != 'T'){
            flag = true;
            break;
        }
    }
    if (flag){
        return max(dfs(l + 1, r), dfs(l, r - 1));
    }
    else
    {
        return r - l;
    }
}

int main()
{
    ciosup;
    cin >> s;
    int l = 0, r = s.size();
    cout << dfs(l, r) << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def knight(x, y):
    s = (0, 0)
    if x == y == 0:
        return 0
    if (x + y) % 3:
        return 0
    if (2*y-x)%3 or (2*x-y)%3:
        return 0
    
    a, b = (2*y-x)//3, (2*x-y)//3
    n = (x+y)//3
    r = min(a, b)

    if a<0 or b<0:
        return 0
    
    return cmb(n, r, mod)

print(knight(x,y))

Measured memory_bytes: 127804
import sys
input = sys.stdin.readline

N = int(input())

Alp = [chr(i) for i in range(97, 97+26)]

P = 26
t = 1
L = 1
while t + P <= N:
    t += P
    L += 1
    P *= 26

seq = N - t
ans = []
for l in range(L):
    ans.append(Alp[seq % 26])
    seq //= 26

print("".join(ans[::-1]))

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

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

    if (s == "Sunny") cout << "Cloudy";
    if (s == "Cloudy") cout << "Rainy";
    if (s == "Rainy") cout << "Sunny";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for (ll i=a;i<n;i++)
#define loopm(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define Graph(n) vector < vector < ll > > (n,vector < ll >(0,0))
#define tr(container,it)\
for(auto it=container.begin();it!=container.end();it++)
#define SZ(x) ((int)(x).size())
typedef vector<long long> VI;
typedef long long ll;
typedef vector < vector < ll > > VII;
typedef pair<ll,ll> PII;
typedef double db;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,n;
    cin>>a>>b>>n;
    ll num=min(b-1,n);
    ll ans=(num*a)/b;
    cout<<ans<<"\n";
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



////////////////////////////////////////////////////////////////////

template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

vector<int> prevn(1100);

template<typename T>
vector<T> dijkstra(int s, graph<T> &g){
  vector<T> dist(g.size()+10, INF);dist[s] = 0;rep(i,1100)prevn[i] = -1;prevn[s] = INF;
  priority_queue<P, vector<P>, greater<P>> que;que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(dist[v] < p.first)continue;
    rep(i, g[v].size()){
      edge<T> e = g[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        prevn[e.to] = v;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
  return dist;
}

#define dijkstra dijkstra<int>

////////////////////////////////////////////////////////////////////

int n, a[110000], b[110000];
signed main(){
  cin>>n;
  int sum = 0, unit = n*(n+1LL)/2LL;
  rep(i,n){
    cin>>a[i];sum += a[i];
  }
  if(sum % unit != 0){
    cout << "NO" << endl;return 0;
  }
  rep(i,n-1)b[i] = a[i+1] - a[i];
  b[n-1] = a[0] - a[n-1];
  int k = sum / unit, cnt = 0;
  rep(i, n){
    if(k-b[i] < 0 || (k-b[i]) % n != 0){
      cout << "NO" << endl;return 0;
    }else{
      cnt += (k-b[i])/n;
    }
  }
  if(cnt != k){
    cout << "NO" << endl;return 0;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
int n;
cin >>n;
if(n==1){
  cout<<0<<endl;
  return 0;
}
int a[n-1][3];
for(int i=0;i<n-1;i++){
  for(int j=0;j<3;j++){
    cin>>a[i][j];
  }
}

for(int i=0;i<n;i++){
  if(i==n-1){
    cout<<0<<endl;
    return 0;
  }
int count=0;
for(int j=i;j<n-1;j++){
  if(count<a[j][1])
  count=a[j][1];
  if(count%a[j][2]!=0)
  count+=a[j][2]-count%a[j][2];
  count+=a[j][0];
  }
cout<<count<<endl;

}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int x;
  cin >> x;

  int ans = 1;
  for (int b = 2; b <= (int)sqrt(x); b++) {
    int exp = b * b;
    for (int p = 2; p <= x; p++) {
      if (exp > x) {
        exp /= b;
        break;
      }
      exp *= b;
    }
    ans = max(ans, exp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,fri,ed;
    while(cin>>n>>m&&n!=0&&m!=0){
    int stu[501][501],myfri[501];
    for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                    stu[i][j]=0;
            }
            myfri[i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>fri>>ed;
        stu[fri][ed]=1;
        stu[ed][fri]=1;
    }
    fri=0;ed=0;
    for(int i=2;i<=n;i++){
        if(stu[1][i]==1){
            myfri[i]=1;
        }
    }
    for(int i=2;i<=n;i++){
        if(myfri[i]==1){
                for(int j=2;j<=n;j++){
                        //cout<<stu[i][j]<<" ";
                    if(stu[i][j]==1&&myfri[j]==0)myfri[j]=2;
                }//cout<<endl;
        }
    }
    for(int i=1;i<=n;i++){
        if(myfri[i]>0){
                fri++;
                //cout<<i<<endl;
        }
    }
   /* for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                        cout<<stu[i][j]<<" ";
        }
        cout<<myfri[i]<<endl;
    }*/
    cout<<fri<<endl;
    }

}

Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
def prim(edges, *, start=0, adj_matrix=False, default_value=float('inf')):
    '''
    Returns the Minimum Spanning Tree(MST) of a given graph

    # sample input when given not as adjacency list (generally works faster)
    edges = [[(1, 2), (2, 5), (3, 4)],         # node 0
             [(0, 2), (3, 3), (4, 6)],         # node 1
             [(0, 5), (3, 2), (5, 6)],         # node 2
             [(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
             [(1, 6), (3, 2), (5, 4)],         # node 4
             [(2, 6), (4, 4)]]                 # node 5

    # sample input when given as adjacency matrix
    edges = [[0, 2, 5, 4, inf, inf],           # node 0
             [2, 0, inf, 3, 6, inf],           # node 1
             [5, inf, 0, 2, inf, 6],           # node 2
             [4, 3, 2, 0, 2, inf],             # node 3
             [inf, 6, inf, 2, 0, 4],           # node 4
             [inf, inf, 6, inf, 4, 0]]         # node 5
    '''

    n = len(edges)
    mst = []
    cost = 0
    T = [start]

    while True:
        tmp_edges = [(cost, (u, v)) for u in T for v, cost in enumerate(edges[u]) if cost != default_value and v not in T] if adj_matrix else\
                    [(cost, (u, v)) for u in T for v, cost in edges[u] if v not in T]

        if tmp_edges:
            min_cost, min_edge = min(tmp_edges)
            mst.append(min_edge)
            cost += min_cost
            T.append(min_edge[1])

        else:
            if len(mst) != n - 1:
                raise NoSpanningError(
                    'There is no spanning tree in this graph (search started from node{})'.
                    format(start))

            else:
                return mst, cost


class NoSpanningError(Exception):
    pass


if __name__ == '__main__':
    '''
    an example of using this function
    AIZU ONLINE JUDGE - ALDS_1_12_A
    '''

    n = int(input())
    edges = [[int(cost) if int(cost) != -1 else float('inf') for cost in input().split()] for i in range(n)]

    print(prim(edges, adj_matrix=True)[1])



Measured memory_bytes: 6472
#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N=1e5+5, INF=1e9;
using namespace std;
int r, c, n;
int boundary(int x, int y)
{
    int ret = -1;
    if(x==0) ret=y;
    else if(y==c) ret=c+x;
    else if(x==r) ret=c+r+(c-y);
    else if(y==0) ret=c+r+c+(r-x);
    return ret; 
}
vector< pii > v;
signed main()
{
    cin >> r >> c >> n;
    for(int i = 1; i <= n; i++)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int pt1 = boundary(x1, y1);
        int pt2 = boundary(x2, y2);
        if(pt1 == -1 || pt2 == -1) continue;
        v.pb({pt1, i});
        v.pb({pt2, i});
    }
    sort(v.begin(), v.end());
    set<int> idxput;
    stack<int> stk;
    for(auto pt: v)
    {
        if(idxput.find(pt.S)==idxput.end())
        {
            idxput.insert(pt.S);
            stk.push(pt.S);
        }
        else
        {
            if(stk.top()!=pt.S)
            {
                cout << "NO";
                return 0;
            }
            stk.pop();
        }
    }
    cout << "YES";
}

Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s[0] << (int)s.length() - 2 << s.back();
}


Measured memory_bytes: 256
def bubbleSort(A):
    N = len(A)
    for i in range(N):
        for j in range(N - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
    return A


def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A


def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True


N = int(input())
A = list(input().split())

B = bubbleSort(A[:])
print(*B)
if is_stable(A, B):
    print('Stable')
else:
    print('Not stable')

S = selectionSort(A[:])
print(*S)
if is_stable(A, S):
    print('Stable')
else:
    print('Not stable')

Measured memory_bytes: 7824
package main

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

const (
	maxBufferSize     = 2000000 // check
	initialBufferSize = 20000
)

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

func solve() {
	sc := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, initialBufferSize)
	sc.Buffer(buffer, maxBufferSize)
	// read input
	// write algorithm
	// output answer
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	args := strings.Split(sc.Text(), " ")
	a := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		a[i], _ = strconv.Atoi(args[i])
	}
	sc.Scan()
	args = strings.Split(sc.Text(), " ")
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i], _ = strconv.Atoi(args[i])
	}

	sum := 0
	for i := 0; i < n+1; i++ {
		if i-1 >= 0 {
			d := Min(b[i-1], a[i])
			a[i] -= d
			b[i-1] -= d
			sum += d
		}
		if i < n {
			d := Min(b[i], a[i])
			a[i] -= d
			sum += d
			b[i] -= d
		}
	}

	fmt.Println(sum)
}

func main() {
	solve()
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

int A[NUM],B[NUM];

int main(){

	int N;
	scanf("%d",&N);

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

	int M;
	scanf("%d",&M);

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

	int A_index = 0,B_index = 0;

	while(A_index < N && B_index < M && A[A_index] == B[B_index]){
		A_index++;
		B_index++;
	}

	if(A_index < N && B_index < M){

		if(A[A_index] < B[B_index]){
			printf("1\n");
		}else{
			printf("0\n");
		}

	}else if(A_index == N && B_index < M){

		printf("1\n");

	}else if(A_index < N && B_index == M){

		printf("0\n");

	}else{ // A_index == N && B_index == M

		printf("0\n");
	}

	return 0;
}




Measured memory_bytes: 3140
n = int(raw_input())
ining, out, score = 0, 0, 0; runner = [0,0,0]
while ining < n:
    event = raw_input()
    if event == "HIT":
        if runner[2] == 1:
            score += 1
            runner[2] = 0
        runner[2] = runner[1]
        runner[1] = runner[0]
        runner[0] = 1
    elif event == "HOMERUN":
        score += runner.count(1) + 1
        runner = [0,0,0]
    else:
        out += 1
        if out == 3:
            print score
            out, score = 0, 0
            runner = [0,0,0]
            ining += 1

Measured memory_bytes: 4228
#include <iostream>

using namespace std;

class Dice {
private:
	int number[6];
public:
	void setNumber(int index, int num);
	void move(string d);
	int getTop();
};

void Dice::setNumber(int index, int num) {
	number[index] = num;
}

void Dice::move(string d) {
	int oldIndex[4][6] = {
		{1, 5, 2, 3, 0, 4},
		{3, 1, 0, 5, 4, 2},
		{2, 1, 5, 0, 4, 3},
		{4, 0, 2, 3, 5, 1},
	};
	for (int i = 0; i < d.size(); i++) {
		int newNumber[6] = {0};
		int *idx;
		char c = d[i];
		switch (c) {
			case 'N': idx = oldIndex[0]; break;
			case 'E': idx = oldIndex[1]; break;
			case 'W': idx = oldIndex[2]; break;
			case 'S': idx = oldIndex[3]; break;
			default: return;
		}
		for (int i = 0; i < 6; i++)
			newNumber[i] = number[idx[i]];
		for (int i = 0; i < 6; i++)
			number[i] = newNumber[i];
	}
}

int Dice::getTop() {
	return number[0];
}

int main() {
	Dice dice;
	int n;
	for (int i = 0; i < 6; i++) {
		cin >> n;
		dice.setNumber(i, n);
	}
	string s;
	cin >> s;
	dice.move(s);
	cout << dice.getTop() << endl;
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

string memo[110][110][2];

string rec(int o, int z, int num){
  if (o == 0 && z == 0) return num == 1 ? "" : "2";
  if (memo[o][z][num] != "") return memo[o][z][num];
  string &res = memo[o][z][num] = "2";
  if (num == 0 && z > 0 && rec(o, z - 1, 1) != "2"){
    res = '0' + rec(o, z - 1, 1);
  }
  if (num == 1){
    if (o > 0 && rec(o - 1, z, 0) != "2") res = min(res, '1' + rec(o - 1, z, 0));
    if (o > 0 && rec(o - 1, z, 1) != "2") res = min(res, '1' + rec(o - 1, z, 1));
    if (z > 0 && rec(o, z - 1, 0) != "2") res = min(res, '0' + rec(o, z - 1, 0));
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> B, O, Z;
  
  REP(i, N) {
    int num;
    cin >> num;
    if (num == 0){
      Z.push_back(num);
    } else if (num == 1){
      O.push_back(num);
    } else {
      B.push_back(num);
    }
  }
  
  sort(ALL(B));
  if (Z.size() % 2 != 0 && O.size() == 0 && B.size() != 0){
    O.push_back(B[0]);
    reverse(ALL(B));
    B.pop_back();
    sort(ALL(B));
  }
  if ((int)B.size() > 1 && B[B.size() - 2] == 2 && B[B.size() - 1] == 3){
    swap(B[B.size() - 2], B[B.size() - 1]);
  }
  
  REP(i, B.size()) cout << B[i] << endl;
  string str = rec(O.size(), Z.size(), 1);
  
  if (str == "2"){
    reverse(ALL(O));
    REP(i, Z.size()) cout << Z[i] << endl;
    REP(i, O.size()) cout << O[i] << endl;
  } else {
    REP(i, str.size()) cout << (str[i] == '0' ? 0 : O[0]) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2048
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0];
 
function main(input) {
  var result = {"SUN":"7","MON":"6","TUE":"5","WED":"4","THU":"3","FRI":"2","SAT":"1"};
  console.log(result[input]);
};

main(input);

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}


int main() {
    LL N;
    cin >> N;
    VI A(N);
    REP(i, N) {
        LL a;
        cin >> a;
        A[i] = a - 1;
    }
    LL count = 0;
    REP(i, N) {
        if (A[A[i]] == i) count++;
    }
    cout << count / 2 << endl;
	
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    rep(i,k+1,n+1){
        ans += (n/i)*(i-k);
        if (n%i != 0 && n%i >= k){
            ans += n%i-k+1;
            if (k == 0) ans--;
        }
    }
    PRINT(ans);
}


Measured memory_bytes: 256