akhauriyash/Code-Regression huggingface dataset:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = [ni() - 1 for _ in range(n)]
limit = 100005
next = li[0]
ct = 1
while True:
    if ct > limit:
        ct = -1
        break
    if next == 1:
        break
    else:
        next = li[next]
        ct += 1
print(ct)

Measured memory_bytes: 7596
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


void solve() {	
	string s;
	cin >> s;\
	ll ans = 0;
	for(int i = 0; i < s.length(); ++i) {
		ans += (int(s[i] - '0'));
		}
		if(ans % 9 == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
}
	

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 
 


Measured memory_bytes: 3784
// kukan add
// kukan min
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;
const ll N_MAX = 1 << 18;//100000 kurai

ll N,M;
vector<P> lr;

ll cop_M;
ll dat1[2*N_MAX-1];
ll dat2[2*N_MAX-1];
ll add(ll,ll,ll,ll,ll,ll);
ll secmin(ll,ll,ll,ll,ll);

int main(){
  cin >> N >> M;
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    lr.push_back(make_pair(a,b));
  }
  //init(M);
  sort(lr.begin(),lr.end());

  rep(i,M+1){
    add(i,i+1,i-M,0,0,M+1);
  }
  ll ans = max(ll(0),N-M);
  rep(i,N){
    P tmp = lr[i];
    //cerr << lr[i].first << " " << lr[i].second << endl;
    add(0,lr[i].second,1,0,0,M+1);
    ans = max(ans,secmin(0,M+1,0,0,M+1)-lr[i].first);
    //cerr << secmin(0,M+1,0,0,M+1) << " " << lr[i].first << endl;
    /*
    rep(i,M+1){
      cerr << secmin(i,i+1,0,0,M+1) << " ";
    }
    cerr << endl;
    */
  }
  cout << ans << endl;
}

// [a,b) ni x wo add
//k ha setten no bango [l,r) ni taiou
//(a,b,x,0,0,N) de yobu
ll add(ll a, ll b , ll x , ll k , ll l , ll r){
  if(a <= l && r <= b){
    dat1[k] += x;
  }
  else if(l < b && a < r){
    ll vl = add(a,b,x,k*2+1,l,(l+r)/2);
    ll vr = add(a,b,x,k*2+2,(l+r)/2,r);
    dat2[k] = max(vl,vr);
  }
  return dat1[k]+dat2[k];
}


ll secmin(ll a, ll b , ll k , ll l , ll r){
  if(b <= l || r <= a){
    return -INF;
  }
  else if(a <= l && r <= b){
    return dat1[k] + dat2[k];
  }
  else{
    ll vl = secmin(a,b,k*2+1,l,(l+r)/2);
    ll vr = secmin(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr) + dat1[k];
  }
}



Measured memory_bytes: 12652
#include<stdio.h>
int main()
{
    long long int i,j,k,n,m,p,x,a[1000],s;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
    scanf("%lld",&m);
    for(j=0; j<m; j++)
    {
        scanf("%lld%lld",&p,&x);
        s=0;
        for(k=0; k<n; k++)
        {
            s=s+a[k];
        }
        s=s-a[p-1]+x;
        printf("%lld\n",s);

    }
}


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

void selectionSort(int A[], int N) {
    /// ソート後の配列と交換回数を標準出力する
    int count = 0;
    for (int i = 0; i <= N - 1; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(A[i], A[minj]);
            count++;
        }
    }

    for (int i = 0; i < N - 1; i++) {
        cout << A[i] << " ";
    }
    cout << A[N-1] << "\n" << count << endl;
}

int main() {
    int N;
    int A[1000];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    selectionSort(A, N);
    return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>
int main(){
  int a, b, resp;
  scanf("%d %d", &a, &b);
  resp=a+b;

  if((a-b)>resp)
    resp=a-b;

  if((a*b)>resp)
    resp=a*b;

  printf("%d\n", resp);
    
  return 0;
}


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

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int r = Integer.parseInt(input[0]);
        int g = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        
        out.println((100 * r + 10 * g + b) % 4 == 0 ? "YES" : "NO");
        out.close();
        
    }
}

Measured memory_bytes: 32588
#include<bits/stdc++.h>
//this code is written by Itst
using namespace std;

int arr[30][50] , N , D;

int main(){
	cin >> N >> D;
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= D ; ++j)
			cin >> arr[i][j];
	int cnt = 0;
	for(int i = 1 ; i <= N ; ++i){
		for(int j = i + 1 ; j <= N ; ++j){
			int sum = 0;
			for(int k = 1 ; k <= D ; ++k)
				sum = sum + (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
			if((int)sqrt(sum) * (int)sqrt(sum) == sum) ++cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
# 初期入力
import sys
input = sys.stdin.readline
x1,x2,x3,x4,x5 = (int(i) for i in input().split())
if x1==0:
    print(1)
elif x2==0:
    print(2)
elif x3==0:
    print(3)
elif x4==0:
    print(4)
elif x5==0:
    print(5)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
int arr[19][19];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>arr[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sum = 0;
            for(int k=0;k<m;k++){
                int x = arr[j][k] - arr[i][k];
                sum += x * x;
            }
            int x = sqrt(sum);
            if(x*x == sum) ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
from collections import defaultdict
S = defaultdict(int)
for _ in range(N):
    tmp = input()
    S[tmp] += 1
R = ['AC', 'WA', 'TLE', 'RE']
for r in R:
    ans = r + ' x ' + str(S[r])
    print(ans)

Measured memory_bytes: 69944
from collections import Counter
import heapq

N = int(input())
Vs = list(map(int,input().split()))

if len(set(Vs)) == 1:
  print(N//2)
  exit()

Veve, Vodd = [],[]
idx = 0
for v in Vs:
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

neg_num, val = heapq.heappop(Veve_cnt)
eve_val = val
eve_num = -neg_num

neg_num, val = heapq.heappop(Vodd_cnt)
odd_val = val
odd_num = -neg_num

if eve_val != odd_val:
  print(N-eve_num-odd_num)
else:
  if len(Vodd_cnt) != 0:odd_num2 = -heapq.heappop(Vodd_cnt)[0]
  else:odd_num2 = -float('inf')

  if len(Veve_cnt) != 0:eve_num2 = -heapq.heappop(Veve_cnt)[0]
  else:eve_num2 = -float('inf')

  print(min(N-eve_num2-odd_num,N-eve_num-odd_num2))

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

int main(){
  int n,d[105],x=1,min,dup;

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


  min=d[0];
  for(int i=1;i<n;i++) {
    if(min > d[i]) min=d[i];
  }
  for(int i=0;i<n;i++) {
      dup=d[i];
      for(int j=0;j<n;j++) {
        if(dup==d[j]) d[j]=0;
      }
      d[i]=dup;
    }

  for(int i=0;i<n;i++) {
    if(min < d[i]) x++;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	vector<tuple<string, int, int>> v;

	cin >> n;
	rep(i,n) {
		string s;
		int p;
		cin >> s >> p;
		v.emplace_back(s, -p, i);
	}

	sort(all(v));
	for (const auto &t : v) {
		cout << get<2>(t) + 1 << endl;
	}



	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

ll t;
int n;
ll ans;
ll x;
// 最大公約数を求める関数
ll gcd(ll x, ll y)
{
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
    

    return (x / gcd(x, y)*y);
}
int main(){

    cin>>n;

    REP(i,n){
        cin>>t;
        if(ans==0){
            ans=t;
        }else{
            ans=lcm(ans,t);
        }

    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
N,M,C = map(int, input().split())
B = [b for b in map(int, input().split())]
B = np.array(B)
ans = 0
for i in range(N):
    A = np.array([a for a in map(int, input().split())])
    if np.sum(A*B) + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 21796
N=int(input())
C=input()
R=[]
W=[]
for i in range(N):
    if C[i]=='R':
        R.append(i)
    else:
        W.append(i)

R=R[::-1]
r=len(R)
w=len(W)
ans=0
j=0
while j<r and j<w:
    if W[j]<R[j]:
        ans+=1
    j+=1

print(ans)

Measured memory_bytes: 18696
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		
        Scanner sc= new Scanner(System.in);
        
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        
        if(a<b&&b<c)
        System.out.println("Yes");
        else
        System.out.println("No");
 
}

}


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

int main (void)
{
    int A,B,C = 0;
    cin >> A;
    cin >> B;
    cin >> C;
    int max = 0;
    while(A != -1 || B != 0)
    {
        if(C == 0 && B == 0)
        {
            break;
        }
        if(C != 0)
        {
            C--;
            max++;
            if(B != 0)
            {
                B--;
                max++;
            }
            else
            {
                A--;
            }
        }
        else
        {
            max = max + B;
            B = 0;
        }
        
    }
    
    cout << max;
}

Measured memory_bytes: 256
/*
 * atcoder/dp_2nd/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long
#define MOD 10e9+7

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const ll INFTY = 10e17;
const ll MAX_N = 101;
const ll MAX_V = 100100;
ll N, CAP;
ll W[MAX_N], V[MAX_N];
ll dp[MAX_N][MAX_V+1];

void input() {
  cin >> N >> CAP;
  loop(n,0,N) {
    cin >> W[n] >> V[n];
  }
}

// dp[i][v] := i番目までの品物を選べるときにv以上を達成する最小w

void solve() {
  loop(n,0,N+1) loop(max_v,0,MAX_V+1) {
    if (max_v == 0) dp[n][max_v] = 0;
    else dp[n][max_v] = INFTY;
  }

  for (int max_v=0; max_v<=MAX_V; max_v++) {
    for (int n=1; n<=N; n++) {
      int w = W[n-1]; ll v = V[n-1];
      chmin(dp[n][max_v], dp[n-1][max_v]);
      if (v >= max_v) chmin(dp[n][max_v], (ll)w);
      if (max_v-v>=0) chmin(dp[n][max_v], dp[n-1][max_v-v] + w);
    }
  }

  ll max_v = 0;
  while (dp[N][max_v] <= CAP) max_v++;
  if (max_v > 0) max_v--;
  cout << max_v << endl;
}

void dump() {
  for (int max_v=0; max_v<=200; max_v++) {
    cout << "v = " << max_v << ": ";
    for (int n=0; n<=N; n++) {
      cout << dp[n][max_v] << " ";
    }
    cout << endl;
  }
}

int main() {
  // cout.precision(15);
  input();
  solve();
  // dump();
  return 0;
}


Measured memory_bytes: 79360
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        long k=Long.parseLong(sc.next());
        HashMap<Integer, ArrayList<Integer>> nums=new HashMap<Integer, ArrayList<Integer>>();
        ArrayList<Integer> sorted=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            int a=Integer.parseInt(sc.next());
            if(!nums.containsKey(a)){
                nums.put(a, new ArrayList<Integer>());
            }
            nums.get(a).add(Integer.parseInt(sc.next()));
            sorted.add(a);
        }
        sc.close();
        Collections.sort(sorted);
        long now=0;
        int val=sorted.get(0);
        int cnt=0;
        for(int a:sorted){
            if(a==val){
                cnt++;
            }
            else{
                val=a;
                cnt=1;
            }
            if(now+nums.get(a).get(cnt-1)>=k){
                System.out.println(a);
                System.exit(0);
            }
            else{
                now+=nums.get(a).get(cnt-1);
            }
        }
    }
}

Measured memory_bytes: 69480
from collections import defaultdict

class unique_element:
    def __init__(self,value,occurrences):
        self.value = value
        self.occurrences = occurrences

def perm_unique(elements):
    eset=set(elements)
    listunique = [unique_element(i,elements.count(i)) for i in eset]
    u=len(elements)
    return perm_unique_helper(listunique,[0]*u,u-1)

def perm_unique_helper(listunique,result_list,d):
    if d < 0:
        yield tuple(result_list)
    else:
        for i in listunique:
            if i.occurrences > 0:
                result_list[d]=i.value
                i.occurrences-=1
                for g in  perm_unique_helper(listunique,result_list,d-1):
                    yield g
                i.occurrences+=1


def partitioned(n):
    table = defaultdict(list)
    table[1] = [[1]]

    for i in range(2, n + 1):
        table[i].append([i])
        a, b = i - 1, 1
        while a >= b:
            l = [a, b]
            table[i].append(l)
            for k in table[a][1:]:
                if k[-1] >= b:
                    l = k + [b]
                    table[i].append(l)
            a, b = a - 1, b + 1
        else:
            table[i].sort(reverse=True)

    return [tuple(x) for x in table[n]]


a = list(raw_input())
total = 0

for leng in partitioned(len(a)):
    for p in perm_unique(leng):
        i = 0
        for ind in p:
            total+= int(''.join(a[i:i+ind]))
            i+=ind
print total

Measured memory_bytes: 2936
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;
use std::cmp;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    // annotate for rust-analyzer
    let n: usize = n;
    let mut a: Vec<i64> = a;

    let mut ans = 0;
    for i in 0..n - 1 {
        let mut diff = 0;
        if a[i] > a[i + 1] {
            diff = a[i] - a[i + 1];
            a[i + 1] = a[i];
        }
        ans += diff;
    }

    println!("{}", ans);
}


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

int n;
string s;

int a[3011],b[3011];
int c[6011];
int begin0;
string ans="";
vector<int>r;
string tmp;
string best="";
int main()
{
	int i,j,k;
	cin>>n>>s;
	int xx,yy,zz;
	
	xx=yy=0;
	for(i=0;i<2*n;i++)
	{
		if(s[i]=='a')
		{
			a[xx++]=i;
		}
		else
		{
			b[yy++]=i;
		}
	}
	
	bool hasba=false;
	begin0=2*n;
	memset(c,0,sizeof(c));
	int lab=2*n;
	int laa=2*n;
	for(i=n-1;i>=0;i--)
	{
		if(a[i]<b[i])
		{
			if(b[i]<begin0 && hasba==false)
			{
				ans+="ab";
				begin0=a[i];
				laa=begin0;
				r.insert(r.begin(),b[i]);
				r.insert(r.begin(),a[i]);
			}
		}
		else
		{
			if(a[i]<lab)
			{
				if(best+ans>ans)
				{
				     ans=best+ans;
			    }
				laa=lab;
				best="";
			}
			
			c[a[i]]=c[b[i]]=1;
			tmp="";
			for(j=b[i];j<laa;j++)
			{
				if(c[j]==1)
				{
					tmp+=s[j];
				}
			}
			
			if(tmp>best)
			{
				best=tmp;
			}
			lab=b[i];
			
			hasba=true;
		}
	}
	
	if(best+ans>ans)
	{
		ans=best+ans;
	}
	
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")

#define y1 fdahivue
#define y2 nhalsane

#define EPS (1e-10) //10^(-10)
#define double double

int N;
double x[50], y[50];

double dist(double x1, double y1, double x2, double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

bool isOK(double X, double Y, double r){
	rep(i, N){
		if(dist(X, Y, x[i], y[i]) > r+EPS) return false;
	}
	return true;
}

signed main(){
	scanf("%d", &N);
	rep(i, N) scanf("%lf%lf", x+i, y+i);

	double ans = INT_MAX;
	rep(i, N){
		rep(j, N){
			double X = (x[i]+x[j]) / 2.0;
			double Y = (y[i]+y[j]) / 2.0;
			double r = dist(x[i], y[i], x[j], y[j]) / 2.0;
			if(isOK(X, Y, r)) ans = min(ans, r);
		}
	}
	rep(i, N){
		rep(j, N){
			rep(k, N){
				// https://www.wolframalpha.com/input/?i=%28x_1%2C+y_1%29%2C+%28x_2%2C+y_2%29%2C+%28x_3%2C+y_3%29+%E3%82%92%E9%80%9A%E3%82%8B%E5%86%86%E3%81%AE%E6%96%B9%E7%A8%8B%E5%BC%8F&lang=ja
				double X = x[j]*x[j]*(y[k]-y[i]) + x[k]*x[k]*(y[i]-y[j]) + (y[j]-y[k])*(x[i]*x[i]+(y[i]-y[j])*(y[i]-y[k]));
				X /= 2.0 * (x[k]*(y[i]-y[j]) + x[i]*(y[j]-y[k]) + x[j]*(y[k]-y[i]));
				double Y = y[j]*y[j]*(x[k]-x[i]) + y[k]*y[k]*(x[i]-x[j]) + (x[j]-x[k])*(y[i]*y[i]+(x[i]-x[j])*(x[i]-x[k]));
				Y /= 2.0 * (y[k]*(x[i]-x[j]) + y[i]*(x[j]-x[k]) + y[j]*(x[k]-x[i]));
				double r = dist(x[i], y[i], X, Y);
				if(isOK(X, Y, r)) ans = min(ans, r);
			}
		}
	}
	printf("%0.20f", ans);
}

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

int main()
{
        int n, str1 = 0, str2 = 0;
        string s1, s2;

        cin >> n;

        for(int i = 0; i < n; i++) {
                cin >> s1 >> s2;
//              cout << s1 << endl;
//              cout << s2 << endl;


                if(s1.compare(s2) < 0) {
                        str2 += 3;
                } else if(s1.compare(s2) > 0) {
                        str1 += 3;
                } else {
                        str1 += 1;
                        str2 += 1;
                }
        }

        cout << str1 << ' ' << str2 << endl;

        return 0;
}


Measured memory_bytes: 3148
n = int(input())
sn = [input() for _ in range(n)]
m = int(input())
sm = [input() for _ in range(m)]

List = []
for i in range(len(list(set(sn)))):
    List.append(sn.count(list(set(sn))[i]) - sm.count(list(set(sn))[i]))
    
print(max(max(List), 0))

Measured memory_bytes: 3064
N, K = [int(i) for i in input().split(" ")]
R, S, P = [int(i) for i in input().split(" ")]
T = input()
score = 0

A = N*[-1]

for i in range(N):
    if T[i] == 'r':
        if i >= K:
            if A[i-K] == 5:
                pass
            else:
                score += P
                A[i] = 5
        else:
            score += P
            A[i] = 5

    elif T[i] == "s":
        if i >= K:
            if A[i-K] == 0:
                pass
            else:
                score += R
                A[i] = 0
        else:
            score += R
            A[i] = 0
    else:
        if i >= K:
            if A[i-K] == 2:
                pass
            else:
                score += S
                A[i] = 2
        else:
            score += S
            A[i] = 2

print(score)


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

int fib[100];

int fibonacci(int n){
  if(!fib[n]) fib[n] = fibonacci(n-1) + fibonacci(n-2) + fibonacci(n-3);
  return fib[n];
}

int main(){
  int n;
  memset(fib, 0, sizeof(fib));
  fib[0] = fib[1] = 1;
  fib[2] = 2;
  while((cin >> n), n){
    cout << (fibonacci(n)/3650 + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
class UnionFind():
    """unionFindツリー
    FindとUnionがきも
    https://note.nkmk.me/python-union-find/
    """
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
  a,b = map(int, input().split())
  a,b = a-1, b-1
  uf.union(a,b)

print(uf.group_count() - 1)

Measured memory_bytes: 13088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
 
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
  ll a,b,x; cin >> a >> b >> x;
  if(a <= x && x<= a+b)cout << "YES" << endl;
  else cout << "NO" << endl;
    return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N;
    cin >> N;
    LL res = N*(N - 1)/2;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()){
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double xp = sc.nextDouble();
			double yp = sc.nextDouble();
			
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point p3 = new Point(x3, y3);
			Point pp = new Point(xp, yp);
					
			Triangle t = new Triangle(p1, p2, p3);
			
			if(t.isInThisTriangle(pp)) System.out.println("YES");
			else System.out.println("NO");
		}
		sc.close();
	}
	
}

class Line{
	
	double p;
	double q;
	double r;
	
	/**
	 * ??´???px+qy=r??????????????????
	 * 
	 * @param p
	 * @param q
	 * @param r
	 */
	Line(double p, double q, double r){
		this.p = p;
		this.q = q;
		this.r = r;
	}
	
	public Line(Point p1, Point p2){
	
		if(p1.getX() != p2.getX()) {
			this.p = -(p1.getY()-p2.getY())/(p1.getX()-p2.getX());
			this.q = 1;
			this.r = p1.getX()* this.p +p1.getY();
		}else {
			if(p1.getY() != p2.getY()) {
				this.p = 1;
				this.q = 0;
				this.r = 0;
			}else {
				this.p = 1;
				this.q = 1;
				this.r = 1;
			}
		}
	}
	
	/**
	 * ????????´???????????????2????????????????????´????????????????????????????????????
	 * 
	 * @param x
	 * @param y
	 * @return 2???x, y???????????´???????????°true
	 */
	boolean isTheSameSide(Point x, Point y){
		double result = (this.calcPX_QY(x.getX(), x.getY()) - this.r)
				* (this.calcPX_QY(y.getX(), y.getY()) - this.r);
		return (result > 0) ? true: false;
	}
	
	/**
	 * ???????????????x, y????????????px+qy????¨?????????????
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	double calcPX_QY(double x, double y){
		return x * p + y * q;
	}
}

class Triangle{
	
	Point p1;
	Point p2;
	Point p3;
	
	Triangle(Point p1, Point p2, Point p3){
		this.p1 = p1;
		this.p2 = p2;
		this.p3 = p3;
	}
	
	Point getCenter(){
		return new Point((p1.getX() + p2.getX() + p3.getX()) / 3, (p1.getY()
				+ p2.getY() + p3.getY()) / 3);
	}
	
	boolean isInThisTriangle(Point p) {
		Line l12 = new Line(p1, p2);
		Line l23 = new Line(p2, p3);
		Line l31 = new Line(p3, p1);
		Point center = this.getCenter();
		
		return l12.isTheSameSide(p, center) && l23.isTheSameSide(p, center) && l31.isTheSameSide(p, center);
	}
}

class Point{
	
	private double x;
	private double y;
	
	public double getX(){
		return this.x;
	}
	
	public double getY(){
		return this.y;
	}
	
	public Point(double d, double e){
		this.x = d;
		this.y = e;
	}
}

Measured memory_bytes: 23312
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
ll a[maxn];
int main(int argc, const char * argv[]) {
    ll n;
    scanf("%lld", &n);
    for (int i = 0; i<n; i++) {
        scanf("%lld", &a[i]);
        a[i] -= (i+1);
    }
    sort(a, a+n);
    ll t1, t2, ans1 = 0, ans2 = 0;
    if (n%2==0) {
        t1 = a[n/2-1];
        t2 = a[n/2];
        for (int i = 0; i<n; i++) {
            ans1 += abs(a[i]-t1);
            ans2 += abs(a[i]-t2);
        }
        ans1 = min(ans1, ans2);
    }
    else{
        t1 = a[n/2];
        for (int i = 0; i<n; i++) {
            ans1 += abs(a[i]-t1);
        }
    }
    printf("%lld\n", ans1);
    return 0;
}

Measured memory_bytes: 1792
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int a[200005],ans[200005];
int main(){
	std::ios::sync_with_stdio(false);
	int n,i,maxx=1;
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}	
	ans[a[0]]=1;
	f(i,1,n){
		ans[a[i]]=max(1,ans[a[i]-1]+1);
		maxx=max(maxx,ans[a[i]]);
	}
	cout<<n-maxx<<endl;
} 
	

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN
#define MAXM
#define mod
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int a, b;
int main() {
	read(a, b);
	if(a == 0 || b == 0) return puts("Zero") * 0;
	if(a < 0 && b > 0) return puts("Zero") * 0;
	else if(a > 0 && b > 0) return puts("Positive") * 0;
	else puts(((b-a+1) & 1) ? "Negative" : "Positive");
	return 0;
}


Measured memory_bytes: 256
<?php
list($N,$X) =explode(" ",trim(fgets(STDIN)));
$ans = 0;
$min=$X;
for($i=0;$i<$N;$i++){
  $m[$i] = trim(fgets(STDIN));
  $X -=$m[$i];
  $ans++;
  if($min>$m[$i]){
    $min = $m[$i];
  }
}
while($X>=$min){
$X -=$min;
$ans++;
}
echo $ans;

Measured memory_bytes: 3576
s = input()
t = input()

s_ = s[:]

ti = 0
ans = 0
flag = True

while ti < len(t):
    si = s_.find(t[ti])
    
    if si != -1:
        ans += si + 1
        s_ = s_[si+1:]
        ti += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Measured memory_bytes: 3456
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

inline void solve(){ 
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for (int i=0,j=0;i<n;i++){
        if (s[i] == 'I') j++;
        else j--;
        ans = max(ans,j);
    }
    cout << ans << endl ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 998244353
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 100010


int main(){
    IOS;
 	
 	
	ll n;cin>>n;
	vll v;
	while(n){
		if(n%26)v.pb(n%26);
		else n--,v.pb((n+1)%26);
		n/=26;
	}
	for(ll i=sz(v)-1;i>=0;--i)cout<<(char)((v[i]-1+26)%26+'a');
    
     
    return 0;
}


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

ll M = 1000000007;
vector<ll> fac(200010);
vector<ll> ifac(200010);

//べき乗高速化
ll mpow(ll x, ll n){
	ll res= 1;
	while(n != 0){
		if (n&1) res = res * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return res;
}

//aCbを計算
ll comb(ll a, ll b){
	if (a == 0 && b == 0) return 1;
	if (a < b || a < 0){
		return 0;
	}
	ll temp = ifac[a-b] * ifac[b] % M;
	return temp * fac[a] % M;
}

int main(){
	ll n,k;
	cin >> n >> k;
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i<= 200005; i++){
		fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
		ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
	ll ans = 0;
	rep(i,min(k,n-1)+1){
		ans += comb(n,i)*comb(n-1,n-i-1);
		ans %= M;
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool ans = false;
    ans = ans || (a == b && a != c);
    ans = ans || (a == c && a != b);
    ans = ans || (c == b && a != c);

    cout << (ans?"Yes":"No") << endl;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 998244353;

lnt fact[210000], invfact[210000];

lnt invmod(lnt a, lnt p){ // a^-1 mod p
	lnt b = p, u = 1, v = 0;
	while(b){
		lnt t = a / b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= p;
	if(u < 0) u += p;
	return u;
}

void factmod(lnt m){
	fact[0] = invfact[0] = 1;
	for(lnt i = 1; i < 210000; i++){
		fact[i] = (fact[i-1] * i) % m;
		invfact[i] = (invfact[i-1] * invmod(i, m)) % m;
	}
}

lnt nCrmod(lnt n, lnt r, lnt m){
	return (((fact[n] * invfact[r]) % m) * invfact[n-r]) % m;
}

lnt powmod(lnt a, lnt p, lnt m){
	lnt res = 1, tmp = a;
	while(p != 0){
		if(p % 2) res = (res*tmp) % m;
		tmp = (tmp*tmp) % m;
		p /= 2;
	}
	return res;
}

int main(){
	summon_tourist;

	lnt N, M, K; cin >> N >> M >> K;
	lnt ans = 0;
	factmod(MOD);
	REP(i, K+1){
		lnt block = N-i;
		lnt plus = nCrmod(N-1, i, MOD);
		plus *= M; plus %= MOD;
		plus *= powmod(M-1, block-1, MOD); plus %= MOD;
		ans += plus;
		ans %= MOD;
	}
	cout << ans << ln;
}


Measured memory_bytes: 6948
li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]

D = list(map(int,input().split()))


minvalue=N
temp=0

for i in range(10*N):
    i=i+N
    numtemp=i
    if numtemp>=10000:
        num_4=int(i/10000)
        i=i-10000*num_4
    else:
        num_4=10
        
    if numtemp>=1000:
        num_3=int(i/1000)
        i=i-1000*num_3
    else:
        num_3=10
        
    if numtemp>=100:
        num_2=int(i/100)
        i=i-100*num_2
    else:
        num_2=10
        
    if numtemp>=10:
        num_1=int(i/10)
        i=i-10*num_1
    else:
        num_1=10
        
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
            temp+=1
            
    if temp==K:
        num=numtemp
        break
    
    temp=0

print(num)
    

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s,t;cin>>s>>t;
  bool ans=false;
  int n=s.size();
  REP(i,n){
    REP(j,n){
      if(s[(i+j)%n]==t[j]){
        ans=true;
        continue;
      }
      ans=false;
      break;
    }
    if(ans){
      break;
    }
  }
  cout << bans(ans) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N, M;
        Input(out N, out M);
        int[] p = new int[M];
        string[] s = new string[M];
        for(int i = 0; i < M; i++) {
            Input(out p[i], out s[i]);
        }
        int[] ac = new int[N];
        for(int i = 0; i < M; i++) {
            if(ac[p[i] - 1] <= 0) {
                ac[p[i] - 1]--;
                if(s[i].Equals("AC")) {
                    ac[p[i] - 1] = -ac[p[i] - 1];
                }
            }
        }
        int sum_ac = 0;
        int sum_wa = 0;
        for(int i = 0; i < N; i++) {
            if(ac[i] > 0) {
                sum_ac++;
                sum_wa += ac[i] - 1;
            }
        }
        Console.WriteLine($"{sum_ac} {sum_wa}");
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 23244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n, m; cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<vector<int>> G(n);
    rep(i, m) {
        int x, y; cin >> x >> y; x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int ans = 0;
    rep(i, n) {
        bool ok = true;
        for(const auto & nv: G[i]) {
            if (h[i]<=h[nv]) ok = false;
        }
        if(ok) ans++;
    }

    cout << ans << endl;
}

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

int main(){
	int n, x;
	cin>>n;
	vector<int> A;
	for(int i=0; i<n; i++){
		cin>>x;
		A.push_back(x);
	}
	sort(A.begin(),A.end());
	int cnt =0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(A[i] == A[j]){
				continue;
			}
			for(int k=j+1; k<n; k++){
				if(A[j] == A[k]){
					continue;
				}
				if(A[i] + A[j] > A[k]){
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int num1 = input.nextInt();
		int num2 = input.nextInt();
		
		if((num1+num2)%2 == 0)
			System.out.println((num1+num2)/2);
		else
			System.out.println("IMPOSSIBLE");
		
		input.close();

	}

}


Measured memory_bytes: 27000
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
char A[9],B[9];
#define I(s)strtol(s.c_str(),NULL,10)
string S(int i,int L){sprintf(A,"%%0%dd",L),sprintf(B,A,i);return B;}
int main(){
	for(int a,L;scanf("%d%d",&a,&L),L;){
		vector<int>v;v.push_back(a);
		for(;;v.push_back(a)){
			string t=S(a,L),s;
			sort(t.begin(),t.end());
			s=t;
			reverse(s.begin(),s.end());
			a=I(s)-I(t);
			vector<int>::iterator it=find(v.begin(),v.end(),a);
			if(it!=v.end()){
				printf("%d %d %d\n",it-v.begin(),a,v.size()-(it-v.begin()));
				break;
			}
		}
	}
}

Measured memory_bytes: 0
def main():
  n = int(input())
  a = list(map(int, input().split()))
  d = [0]*n
  for i, x in enumerate(a):
    if i+x < n: d[i+x] += 1
  ans = 0
  for i, x in enumerate(a):
    if i-x >= 0: ans += d[i-x]
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 32232
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <thread>
#include <cmath>
#include <cstring>
#include <string>
#include <typeinfo>
using namespace std;
#define nv_sort(x) sort(x.begin(),x.end())
// #define bv_sort(x) = sort(x.begin(),x.end(),greater<int>())
// #define v_count(x,p) = count(x.begin(),x.end(),p)

int main(){
    int a;
    string hoge;
    cin >> a;
    cin >> hoge;
    if(a>=3200)cout << hoge << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int mod = 998244353, L = 128;
const char id[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n;
int query(const string &s){cout << "? " << s << endl; int x; read(x); return x;}
bool check(const string &s){return query(s) + s.size() == n;}
struct cmp {bool operator () (const string &a, const string &b){return a.size() > b.size();}};
priority_queue<string, vector<string>, cmp> pq;
int main(){
	for(Rint i = 0;i < 62;++ i){
		int tmp = L - query(string(L, id[i]));
		n += tmp; if(tmp) pq.push(string(tmp, id[i]));
	}
	while(pq.size() > 1){
		string a = pq.top(); pq.pop();
		string b = pq.top(), res; pq.pop();
		int p1 = 0, p2 = 0, l1 = a.size(), l2 = b.size();
		while(p1 < l1 && p2 < l2)
			if(check(res + a[p1] + b.substr(p2))) res += a[p1 ++];
			else res += b[p2 ++];
		if(p1 < l1) res += a.substr(p1);
		if(p2 < l2) res += b.substr(p2);
		pq.push(res);
	}
	cout << "! " << pq.top() << endl;
}

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

int main(){
  
  int n;
  cin >> n;
  int b[n-1];
  for(int i=0;i<n-1;i++)cin >> b[i];
  int res = b[0];
  for(int i = 1;i < n - 1;i++){
    res += min(b[i],b[i-1]);
  }
  res = res + b[n-2];
  cout<<res;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    string a,b;
    cin >> a >> b;
    a += b;
    int new_num = atoi(a.c_str());
    int sqrt_num = (int)sqrt((double)new_num);
    if(sqrt_num*sqrt_num == new_num){
        cout << "Yes" << '\n';
    }else{
        cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll; 
int col[705], w, b; 
bool dp[705][705], app[705][705]; 
std::pair<int, int> arr[705]; 
std::vector<int> adj[705]; 
void dfs(int u, int c)
{
	if (~col[u])
	{
		if (col[u] != c)
		{
			puts("-1"); 
			exit(0); 
		}
		return; 
	}
	col[u] = c; 
	(c ? w : b)++; 
	for (int v : adj[u])
		dfs(v, c ^ 1); 
}
int main()
{
	// freopen("ARC099-E.in", "r", stdin); 
	memset(col, -1, sizeof(col)); 
	int n, m, len = 0; 
	scanf("%d%d", &n, &m); 
	for (int i = 0; i < m; i++)
	{
		int u, v; 
		scanf("%d%d", &u, &v); 
		u--; 
		v--;
		app[u][v] = app[v][u] = true; 
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (!app[i][j] && i != j)
				adj[i].pb(j); 
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (~col[i])
			continue; 
		w = 0;
		b = 0; 
		dfs(i, 0); 
		arr[len++] = {w, b}; 
	}
	dp[0][0] = true; 
	for (int i = 0; i < len; i++)
	{
		for (int x = 0; x <= n; x++)
		{
			if (dp[i][x])
			{
				dp[i + 1][x + arr[i].first] = true; 
				dp[i + 1][x + arr[i].second] = true; 
			}
		}
	}
	int ans = 1e9; 
	for (int i = 0; i <= n; i++)
	{
		if (dp[len][i])
			ans = std::min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2); 
	}
	printf("%d\n", ans >= 1e9 ? -1 : ans);
	return 0; 
}


Measured memory_bytes: 3072