akhauriyash/Code-Regression huggingface dataset:
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
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; }

// ***************************************

ll cnt = 0;
int K;

void rec(string num, ll keta, int x) {
	if (keta == 1) {
		cnt++;
		if (cnt == K){
			cout << num << endl;
			exit(0);
		}
		return;
	}

	for (int i = max(0, x - 1); i <= min(x + 1, 9); i++) {
		char tmp = '0' + i;
		rec(num + tmp, keta - 1, i);
	}
}

int main(void) {

	cin >> K;


	ll cnt = 1;
	FOR(keta, 1, 1000) {
		for (char i = 1; i < 10; i++) {
			char num = '0' + i;
			rec(string{ num }, keta, i);
		}
	}

	return 0;
}

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

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

    double x = l / 3.0;
    cout << fixed << setprecision(10);
    cout << x * x * (l - 2 * x) << endl;

    return 0;
}


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

using namespace std;

int main()
{
	int n, ans = 0;
	cin >> n;
	vector<int> h(n);
	int score = 0;
	for(auto&& i : h)
	{
		cin >> i;
		if(score < i)
		{
			score = i;
		}
		if(score > i)
		{
			ans += score - i;
			score = i;
		}
	}
	ans += score;
	cout << ans;
  return 0;
}
  

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long N, std::vector<long long> T, std::vector<long long> A)
{
    ll takahashi = 1, aoki = 1;

    for (int i = 0; i < N; i++)
    {
        ll k = max((takahashi+T[i]-1)/T[i],(aoki+A[i]-1)/A[i]);
        
        takahashi = T[i] * k;
        aoki = A[i] * k;
    }

    cout << takahashi + aoki << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> T(N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &T[i]);
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(T), std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define lowbit(x) (x&-x)
using namespace std;
ll x[1000005],xx[1000005],w[1000005],i,j,k,l,r,s,t,n,m,c;
int main()
{
    scanf("%lld%lld%lld",&n,&l,&t);
    for(reg int i=1;i<=n;i++)scanf("%lld%lld",&x[i],&w[i]);
    for(reg int i=1;i<=n;i++)
    {
        if(w[i]==2)w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0)(c+=r/l)%=n;
        else if(r<0)(c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    for(reg int i=c+1;i<=n;i++)printf("%lld\n",xx[i]);
    for(reg int i=1;i<=c;i++)printf("%lld\n",xx[i]);
}

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

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(i == j) continue;
      int p = x[i]-x[j];
      int q = y[i]-y[j];
      int cnt = 0;
      for (int a = 0; a < N; a++) {
        for (int b = 0; b < N; b++) {
          if(a == b) continue;
          if(x[a]-x[b] == p && y[a]-y[b] == q) cnt++;
        }
      }
      ans = max(ans,cnt);
    }
  }

  printf("%d\n",N-ans);

  return 0;
}

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

int main(void){
    int i;
    string S;
    long long K;
    cin>>S>>K;
    
    if(S.size()==1){
        cout<<S[0]<<endl;
        return 0;
    }else if(S[0]=='1'){
        for(i=0;i<S.size();i++){
            if(S[i]!='1')break;
            if(i==S.size()-1)break;
        }
        if(K-1<i){
            cout<<1<<endl;
            return 0;
        }else{
            cout<<S[i]<<endl;
            return 0;
        }
    }else{
        cout<<S[0]<<endl;
        return 0;
    }
    
}

Measured memory_bytes: 256
let N = Int(readLine()!)!
var ABs = [(Int, Int)]()
for _ in 0..<N {
    let AB = readLine()!.characters.split(" ").map{Int(String($0))!}
    ABs += [(AB[0], AB[1])]
}
var ans = 0
for (A, B) in ABs.reverse() {
    ans += (B-(A+ans)%B)%B
}
print(ans)

Measured memory_bytes: 5860
#include <stdio.h>
#define dif(a,b) (((a)>(b))?(a)-(b):(b)-(a))
int main(void){
	int n,m,i,j,k,t[16],c[16],p,d;
	for( t[0] = n = i = 1; i < 16; i++ )t[i] = n *= 3;
	for(;scanf("%d%d",&n,&m),n|m;){
		for( k = 0; k < 3; k++ )
			for( scanf("%d",&i); i--; c[j] = k )scanf("%d",&j);
		p = j = 0;
		for( k = 1; k <= n; k++ ){
			d = dif( p, c[k] );
			j += t[n-k] * d;
			p = d * 2 + p & 3;
		}
		k = t[n] - 1 - j;
		if( j > k ) j = k;
		printf("%d\n", j > m ? -1 : j );
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin >> N >> M;
  for(int i=0; i<N; i++){
    string S;
    cin>>S;
    cout<<S<<endl;
    cout<<S<<endl;
 }
  return 0;
}


Measured memory_bytes: 3676
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [n,i] <- readInts
  print . showAnswer $ solve (n,i)

type Input  = (Int, Int)
type Output = Int

solve :: Input -> Output
solve (n,i) = n-i+1

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include<stdio.h>

int main(void){
  int E,Y;
  scanf("%d %d",&E,&Y);
  switch (E) {
    case 0:
      if(1<=Y-1868+1 && Y-1868+1<=44){ printf("M%d\n",Y-1868+1); }
      else if(1<=Y-1912+1 && Y-1912+1<=14){ printf("T%d\n",Y-1912+1); }
      else if(1<=Y-1868-1 && Y-1926+1<=63){ printf("S%d\n",Y-1926+1); }
      else{ printf("H%d\n",Y-1989+1); }
      break;
    case 1:
      Y+=1868-1;
      printf("%d\n",Y);
      break;
    case 2:
      Y+=1912-1;
      printf("%d\n",Y);
      break;
    case 3:
      Y+=1926-1;
      printf("%d\n",Y);
      break;
    case 4:
      Y+=1989-1;
      printf("%d\n",Y);
      break;
    default:
      break;
  }
  return 0;
}



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

int main() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int count=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if((500*i+100*j+50*k)==x){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

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

K = int(input())

A = [-1]*(K+1)

ans = -1
t = 7 % K
for s in range(K+1):
    if t == 0:
        ans = s + 1
        break
    if A[t] != -1:
        break
    A[t] = 1
    t = (t*10 + 7) % K

print(ans)

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

#define iFOR(idx, from, upto) for (int  idx = from; idx < upto; ++idx)
#define lFOR(idx, from, upto) for (long idx = from; idx < upto; ++idx)

#define ll long long

using namespace std;

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

    bool exists = false;
    int candidate_price, candidate_tax08;
    iFOR(i, 0, 10) {
        candidate_price = 10 * b + i;
        candidate_tax08 = (int) (candidate_price * 0.08);
        if (candidate_tax08 == a) {
            exists = true;
            break;
        }
    }

    if (!exists) candidate_price = -1;

    cout << candidate_price << endl;

    return 0;
}


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

using namespace std;

int main() {
  int W, a, b;
  cin >> W >> a >> b;
  if (a + W < b || b + W < a) cout << min(abs(b - (a + W)), abs(a - (b + W))) << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
import random

name = str(input())
a = len(name)

if  3<= a <= 20:
    b = random.randint(0,a-3) 
    
    ada_1 = name[b]
    ada_2 = name[b+1]
    ada_3 = name[b+2]
    
    print(ada_1+ada_2+ada_3)
else:
    None

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

using namespace std;

tuple<int,int,char,long long,string> a[100010];

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

    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int p1,p2;
        char p3;
        long long p4;
        string p5;
        cin>>p1>>p2>>p3>>p4>>p5;
        a[i]=make_tuple(p1,p2,p3,p4,p5);
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
        cout<<get<0>(a[i])<<" "<<get<1>(a[i])<<" "
            <<get<2>(a[i])<<" "<<get<3>(a[i])<<" "
            <<get<4>(a[i])<<endl;

    return 0;
}



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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
int main() {
    ll r,ans;
    cin>>r;
    ans=r*r;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	n = int(input())
	d , x = IN()
	for _ in range(n):
		ai=int(input())
		init=1
		x+=1
		for i in range(1, 1000):
			if ai*i + 1 > d:
				break
			x+=1
	print(x)
	#s = input()
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
import java.util.Scanner;

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

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int X = scanner.nextInt();
    int Y = scanner.nextInt();

    int AB = Math.min(A + B, C * 2);
    int res = 0;
    int numAB = Math.min(X, Y);
    res += numAB * AB;
    X -= numAB;
    Y -= numAB;
    res += Math.min(A, C * 2) * X;
    res += Math.min(B, C * 2) * Y;
    System.out.println(res);
  }
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
N = int(input())
ac = wa = tle = re = 0
for i in range(N):
    Si = input()
    if Si == "AC":
        ac = ac + 1
    elif Si == "WA":
        wa = wa + 1
    elif Si == "TLE":
        tle = tle + 1
    elif Si == "RE":
        re = re + 1
print("AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(ac, wa, tle, re))

Measured memory_bytes: 9028
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    t = input()
    ans = len(t)
    for l in range(len(s)-len(t)+1):
        r = l+len(t)
        m = 0
        for i in range(len(t)):
            if t[i] != s[l+i]:
                m += 1
        if m < ans:ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 73836
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

ll x[100001];
ll y[100001];
ll xd[100001];
ll yd[100001];

int main()
{
	ll n,m;
	ll ans=0;
	ll xs=0;ll ys=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>x[i];
	for(int i=0;i<m;i++)
		cin>>y[i];
	for(int i=1;i<n;i++)
		xd[i-1]=x[i]-x[i-1];
	for(int i=1;i<m;i++)
		yd[i-1]=y[i]-y[i-1];
	for(int i=0;i<n-1;i++)
	{
		ll tmp=0;
		tmp+=xd[i]*(ll)(i+1);
		tmp%=MOD;	
		tmp*=(ll)(n-1-i);
		tmp%=MOD;
		xs+=tmp;
		xs%=MOD;
	}
	for(int i=0;i<m-1;i++)
	{
		ll tmp=0;
		tmp+=yd[i]*(ll)(i+1);
		tmp%=MOD;
		tmp*=(ll)(m-1-i);
		tmp%=MOD;
		ys+=tmp;
		ys%=MOD;
	}
	ans=ys*xs;
	ans%=MOD;
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
n, k = map(int, input().split())
p = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 4 * 10**18
for i in range(k, n + 1):
    for j in range(n - i + 1):  # x座標に関して j から i + j まで含む
        x = p[i + j - 1][0] - p[j][0]
        s = sorted([p[a][1] for a in range(j, i + j)])
        y = min(s[a + k - 1] - s[a] for a in range(i - k + 1))
        ans = min(ans, x * y)
print(ans)


Measured memory_bytes: 74136
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int x;
   cin >> x;
   if (x >= 400 && x < 600)
      cout << 8 << endl;
   else if (x >= 600 && x < 800)
      cout << 7 << endl;
   else if (x >= 800 && x < 1000)
      cout << 6 << endl;
   else if (x >= 1000 && x < 1200)
      cout << 5 << endl;
   else if (x >= 1200 && x < 1400)
      cout << 4 << endl;
   else if (x >= 1400 && x < 1600)
      cout << 3 << endl;
   else if (x >= 1600 && x < 1800)
      cout << 2 << endl;
   else
      cout << 1 << endl;

   return 0;
}

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

// why am I so weak

int n, a[100055];

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

	int odd = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 1) odd++;
	}

	puts(odd % 2 == 0 ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 640
##(N,K)=map(int,input().split())

N=int(input())
c=list(map(int, input().split()))
z=int(0)
k=int(0)

for i in range(N-1):
    if(c[i]>=c[i+1]):
        k=k+1
    else:
        z=max(z,k)
        k=0

z=max(z,k)
print(z)

Measured memory_bytes: 14224
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{

long long int n,i,a[400002],k=0,c=0;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<(n-1);i++)
{if(a[i]<a[i+1])
k=0;
else
k++;
if(k>c)
c=k;
}
cout<<c;
				return 0;
				}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N, M, K;
  cin >> N >> M;
  vector<int> seq(M+2, 0);
  REP(i, N) {
    cin >> K;
    REP(j, K) {
      int l;
      cin >> l;
      seq[l]++;
    }
  }
  int ans = 0;
  REP(i, seq.size()) {
    if (seq[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

const string r = "rsp";
signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n,k,s[3],sum=0;
   cin>>n>>k;
   rep(i,0,3) cin>>s[i];
   string v;
   cin>>v;

   rep(i,0,n){
      if(i - k >= 0 && v[i-k] == v[i]){
         v[i] = '#';
         continue;
      }
      sum += s[(r.find(v[i]) + 2) % 3];
   }

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

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

int main(){
	int n;
	cin>>n;
	int h[n];
	rep(i,n) cin>>h[i];
	
	int cnt=0;
	int ans=0;
	rep(i,n-1){
		if(h[i]>=h[i+1]){
			cnt++;
			if(cnt>ans) ans=cnt;
		} else {
			cnt=0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int bfs(int h, int w, char farm[][102], int vector[][2]);

int main(void) 
{
	int i, j, k;
	int H, W;
	char farm[102][102];
	int vector[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
	int ans=0;
	while (scanf("%d %d\n",&H,&W) != EOF)
	{
		if (H == 0 && W == 0)
		{
			break;
		}
		for (i = 0; i < H + 2; i++)
		{
			if (i == 0 || i == H + 1)
			{
				for (j = 0; j < W + 2; j++)
				{
					farm[i][j] = 'o';
				}
			}
			else
			{
				farm[i][0] = 'o';
				scanf("%s", &farm[i][1]);
				farm[i][W+1] = 'o';
			}
		}
		ans = 0;
		for (i = 1; i < H + 1; i++)
		{
			for (j = 1; j < W + 1; j++)
			{
				if (farm[i][j] != 'o')
				{
					ans += bfs(i, j, farm, vector);
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

int bfs(int h, int w, char farm[][102], int vector[][2])
{
	int i, j;
	char now = farm[h][w];
	farm[h][w] = 'o';
	for (i = 0; i < 4; i++)
	{
		if (now == farm[h+vector[i][0]][w+vector[i][1]])
		{
			bfs(h+vector[i][0], w+vector[i][1], farm, vector);
		}
	}
	return 1;
}

Measured memory_bytes: 1396
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main{
	static int G;
	static int D;
	static int[] p;
	static int[] c;
	static boolean[] used;
	static long ans = 1000000000;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		ArrayList<Pair> pairs = new ArrayList<Pair>();
		for(int i  = 0;i < m;i++){
			Pair pair = new Pair();
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
			pair.from = a[i];
			pair.end = b[i];
			pairs.add(pair);
		}
		Collections.sort(pairs);
		
		int minR = pairs.get(0).end;
		int ans = 0;
		for(int i = 1;i < m;i++){
//			System.out.println(minR);
			if(pairs.get(i).from >= minR){
				ans++;
				minR = pairs.get(i).end;
			}else{
				if(pairs.get(i).end < minR){
					minR = pairs.get(i).end;
				}
			}
			
		}
		ans++;
		System.out.println(ans);
		
		
		
		


		
	}
	

}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



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

int main(){
  int k;cin>>k;
  priority_queue<ll,vector<ll>,greater<ll>> que;
  for(int i = 1; i < 10; i++){
    que.push(i);
  }

  while(k){
    ll v = que.top();
    que.pop();
    if(k==1){
      cout<<v<<endl;
      return 0;
    }
    que.push(10*v+v%10);
    if(v%10==0){
      que.push(10*v+v%10+1);
    }else if(v%10==9){
      que.push(10*v+v%10-1);
    }else{
      que.push(10*v+v%10+1);
      que.push(10*v+v%10-1);      
    }
    k--;
  }
  return 0;
}

Measured memory_bytes: 2420
def f(n):
    summ = 0 
    for ele in str(n):
        summ+=(int(ele))
    return n/summ
    
l = []

for i in range(1,10):
    l.append(i)

st = 19 
diff = 10 
while True:
    if f(st)<=f(st+diff):
        l.append(st)
    else:
        st-=diff
        diff*=10
    st+=diff
    if st>10**16:
        break
print(*l[:int(input())],sep='\n')

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

int main(){

  int sum1=0,sum2=0;
  int a;
  for(int i=0; i<4; i++){
    cin>>a;
    sum1 += a;
  }
 for(int i=0; i<4; i++){
    cin>>a;
    sum2 += a;
  }

 (sum1>sum2)? cout<<sum1<<endl : cout<<sum2<<endl;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    int a = stoi(s.substr(0,2));
    int b = stoi(s.substr(2,2));
    if(1<=a&&a<=12){
        if(1<=b&&b<=12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }else{
        if(1<=b&&b<=12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, T, A;
    cin >> N >> T >> A;
    vec H(N);
    REP(i,0,N) cin >> H[i];

    ll m = INF, mi = 0;
    REP(i,0,N) {
        ll d = abs(1000*A-(1000*T-H[i]*6));
        if(d < m) {
            m = MIN(m,d);
            mi = i;
        }
    }
    PR(mi+1);

    return 0;
}

/*



*/

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
	COMinit();

	ll N;
	ll M;
	cin >> N >> M;

	ll fac[100] = {};

	ll d = 2;
	ll i = 1;
	while (M != 1) {
		
		if (M%d == 0) {
			while (M%d == 0) {
				fac[i]++;
				M /= d;
			}
			i++;
		}

		d++;
	}

	ll ans = 1;

	repn(i, 99) {
		ans = ans*COM(N + fac[i] - 1, fac[i])%MOD;

	}

	cout << ans;
	

	system("PAUSE");
}

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

int main() {

    int n;
    cin >> n;
    ll ans = 0;
    vector<ll> v;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        v.push_back(a + b);
        ans -= b;
    }
    sort(v.rbegin(), v.rend());

    rep(i, n){
        if(i % 2 == 0){
            ans += v[i];
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

int main() {
  long A, B;
  char OP;
  cin >> A >> OP >> B;

  if (OP == '+') {
    cout << A + B << endl;
  } else if (OP == '-') {
    cout << A - B << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int id;
	int t;
} car_t;

int main(void) {
	int m,n;
	while(scanf("%d%d",&m,&n)==2 && (m|n)!=0) {
		car_t chusyazyo[100][2];
		car_t cars[100];
		int i;
		int sim_time;
		int id_to_park;
		int first_car_went=0;
		for(i=0;i<n;i++) {
			cars[i].id=i+1;
			if(scanf("%d",&cars[i].t)!=1)return 1;
		}
		for(i=0;i<m;i++) {
			chusyazyo[i][0].id=chusyazyo[i][0].t=0;
			chusyazyo[i][1].id=chusyazyo[i][1].t=0;
		}
		id_to_park=0;
		for(sim_time=0;;sim_time++) {
			/* zikan keika */
			for(i=0;i<m;i++) {
				if(chusyazyo[i][0].t>0)chusyazyo[i][0].t--;
				if(chusyazyo[i][1].t>0)chusyazyo[i][1].t--;
			}
			/* syukko */
			for(i=0;i<m;i++) {
				if(chusyazyo[i][1].id>0 && chusyazyo[i][1].t<=0) {
					if(first_car_went)putchar(' ');
					printf("%d",chusyazyo[i][1].id);
					chusyazyo[i][1].id=chusyazyo[i][1].t=0;
					first_car_went=1;
				}
				if(chusyazyo[i][1].id==0 && chusyazyo[i][0].id>0 && chusyazyo[i][0].t<=0) {
					if(first_car_went)putchar(' ');
					printf("%d",chusyazyo[i][0].id);
					chusyazyo[i][0].id=chusyazyo[i][0].t=0;
					first_car_went=1;
				}
			}
			/* chusya */
			while(id_to_park<n && id_to_park<sim_time/10) {
				/* aiteru tokoro wo sagasu */
				for(i=0;i<m;i++) {
					if(chusyazyo[i][0].id==0) {
						chusyazyo[i][0]=cars[id_to_park++];
						break;
					}
				}
				if(i<m)continue;
				/* 1. izyou wo sagasu */
				int hi_score=1000000;
				int hi_index=-1;
				for(i=0;i<m;i++) {
					if(chusyazyo[i][1].id==0 && chusyazyo[i][0].t>=cars[id_to_park].t) {
						int score=chusyazyo[i][0].t-cars[id_to_park].t;
						if(score<hi_score) {
							hi_score=score;
							hi_index=i;
						}
					}
				}
				if(hi_index>=0) {
					chusyazyo[hi_index][1]=cars[id_to_park++];
					continue;
				}
				/* 2. sagasu */
				for(i=0;i<m;i++) {
					if(chusyazyo[i][1].id==0) {
						int score=cars[id_to_park].t-chusyazyo[i][0].t;
						if(score<hi_score) {
							hi_score=score;
							hi_index=i;
						}
					}
				}
				if(hi_index>=0) {
					chusyazyo[hi_index][1]=cars[id_to_park++];
					continue;
				}
				/* chusya dekinai */
				break;
			}
			/* syuuryou hantei */
			if(id_to_park>=n) {
				int nokotteru=0;
				for(i=0;i<m;i++) {
					if(chusyazyo[i][0].id>0 || chusyazyo[i][1].id>0)nokotteru=1;
				}
				if(!nokotteru)break;
			}
#if 0
			printf("time = %d\n",sim_time);
			for(i=0;i<m;i++)printf("[%2d,t=%2d]",chusyazyo[i][1].id,chusyazyo[i][1].t);
			puts("");
			for(i=0;i<m;i++)printf("[%2d,t=%2d]",chusyazyo[i][0].id,chusyazyo[i][0].t);
			puts("");
#endif
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,l,a[200],ans=0;
	cin>>n>>l;
	for(ll i=0;i<n;i++){
		a[i]=l+i+1-1;
	}
	for(ll i=0;i<n;i++){
		ans+=a[i];
	}
	ll ch=inf;
	ll ans2=0;
	for(ll i=0;i<n;i++){
		ll now=ans-a[i];
		if(abs(now-ans)<ch){
			ch=abs(now-ans);
			ans2=now;
		}
	}
	cout <<ans2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main(int argc, char **argv)
{
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl;
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    long long n;
    string s;
    cin >> n >> s;
    long long cnt1[4005] = {0}, cnt2[4005] = {0}, cnt3[4005] = {0};
    for(long long i = n - 1; i >= 0; i--){
        if(s[i] == 'R'){
            cnt1[i] = cnt1[i + 1] + 1;
            cnt2[i] = cnt2[i + 1];
            cnt3[i] = cnt3[i + 1];
        }
        if(s[i] == 'G'){
            cnt2[i] = cnt2[i + 1] + 1;
            cnt1[i] = cnt1[i + 1];
            cnt3[i] = cnt3[i + 1];
        }
        if(s[i] == 'B'){
            cnt3[i] = cnt3[i + 1] + 1;
            cnt1[i] = cnt1[i + 1];
            cnt2[i] = cnt2[i + 1];
        }
    }
    long long sum = 0;
    for(long long i = 0;i < n - 1; i++){
        for(long long j = i + 1; j < n; j++){
            if(s[i] == s[j])
                continue;
            else if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
                long long x = j - i;
                sum += cnt2[j+1];
                if(j + x < n)
                    if(s[j + x] == 'G')
                        sum--;
            }
            else if((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')){
                long long x = j - i;
                sum += cnt1[j+1];
                if(j + x < n)
                    if(s[j + x] == 'R')
                        sum--;
            }
            else if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')){
                long long x = j - i;
                sum += cnt3[j+1];
                if(j + x < n)
                    if(s[j + x] == 'B')
                        sum--;
            }
            
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3716
import java.util.*;
import java.io.*;
import java.math.*;

class Main {

    static Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);

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

       int n = sc.nextInt();
       int k = sc.nextInt();
       int[] arr = init(n);
       
       Arrays.sort(arr);
       long sum =0;
       
       for(int i = 0; i < k; ++i)
        sum += arr[i];
        
        out.println(sum);

        out.flush();
        out.close();
        sc.close();
    }

    static final int MOD = (int) 1e9 + 7;
    static final double PI = 3.14159265358979323846;

    // takes array input
    public static int[] init(int n) {

        int[] arr = new int[n];

        for (int i = 0; i < n; ++i)
            arr[i] = sc.nextInt();

        return arr;
    }

    // finds GCD of two number
    public static int gcd(int a, int b) {

        if (a == 0) {
            return b;
        }

        return gcd(b % a, a);
    }

    // checks whether a number is prime or not
    public static boolean prime(int n) {

        if (n < 2)
            return false;

        for (int i = 2; i * i <= n; ++i)
            if (n % i == 0)
                return false;

        return true;
    }
}


Measured memory_bytes: 30316
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;
int n, m;
int s, t;
using Graph = vector<vector<int>>;
Graph G;
vector<int> d,w;
bool flag[100010];
bool flag1, flag2,flag0;
struct Object
{
    // 任意の構造体
    ll hoge;
    ll depth;
};

long long bfs(int s,int t)
{
    queue<Object> q;
    vector<vector<long long>> dist(n, vector<long long>(3, -1));
    dist[s][0] = 0;
    Object x = {s, 0};
    q.push(x);
    while (!q.empty())
    {
        Object y = q.front();
        q.pop();
        for(auto u:G[y.hoge]){
            int np = (y.depth + 1)% 3;
            if(dist[u][np]==-1){
                dist[u][np] = dist[y.hoge][y.depth] + 1;
                q.push({u, np});
            }

            //q.push({u, y.depth + 1});
            //cerr << y.depth+1 << endl;
            }
        }
    
    if(dist[t][0]==-1){
        return -1;
    }
    else{
        return dist[t][0] / 3;
    }
}
int main()
{
    cin >> n >> m;
    G.assign(n,vector<int>());
    int u, v;
    d.assign(n, -1);
    w.assign(n, 0);
    REP(i, m)
    {
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
    }
    cin >> s >> t;
    s--;
    t--;
    cout<<bfs(s,t)<<endl;
    //cout << d[t] << endl;

    return 0;
}

Measured memory_bytes: 11904
#include<stdio.h>
#define MAX 100
#define INF (1<<22)

int G[MAX][MAX];

void span(int);

int main(){
  int a,n,i,j;

  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&a);

      if(a <= -1){
	G[i][j] = INF;
      } else {
	G[i][j] = a;
      }
    }
  }

  span(n);

  return 0;
}

void span(int n){
  int col[MAX],par[MAX],wei[MAX],i,min,hen;
  int sum = 0;

  for(i = 0;i < n;i++){
    col[i] = 0;
    par[i] = -1;
    wei[i] = INF;
  }
  
  wei[0] = 0;

  while(1){
    min = INF;
    hen = -1;
    
    for(i = 0;i < n;i++){
      if(col[i] != 2 && wei[i] < min){
	min = wei[i];
	hen = i;
      }
    }
    
    if(hen <= -1)break;
    col[hen] = 2;

    for(i = 0;i < n;i++){
      if(col[i] != 2 && G[hen][i] != INF){
	if(wei[i] > G[hen][i]){
	  par[i] = hen;
	  col[i] = 1;
	  wei[i] = G[hen][i];
	}
      }
    }
  }
  for(i = 0;i < n;i++){
    if(par[i] != -1){
      sum += G[i][par[i]];
    }
  }
  printf("%d\n",sum);
}



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

using namespace std;

struct Complex {
	double a,b;
	Complex(){
		a = b = 0;
	}
	Complex(double a,double b):a(a),b(b) {}
	Complex operator +(const Complex &r) {
		return Complex(a+r.a,b+r.b);
	}
	Complex operator -(const Complex &r) {
		return Complex(a-r.a,b-r.b);
	}
	Complex operator *(const Complex &r) {
		return Complex(a*r.a-b*r.b,a*r.b+b*r.a);
	}
	Complex operator /(const double &r) {
		return Complex(a/r,b/r);
	}
	Complex conj() {
		return Complex(a,-b);
	}
}a[804040],b[804040],w1[804040],w2[804040];
int nn = 1,rev[804040],n,m;
const int mod = 200003;
const double pi = acos(-1);
inline void FFT(Complex *x,Complex *w) {
	register int i,j,k;
	for (i = 1;i < nn; i++)
		if (rev[i] > i)
			swap(x[rev[i]],x[i]);
	Complex t0,t1;
	for (i = 1;i < nn; i <<= 1)
		for (j = 0;j < nn;j += (i<<1))
			for (k = 0;k < i; k++) {
				t0 = x[j|k],t1 = x[i|j|k]*w[i|k];
				x[j|k] = t0+t1,x[i|j|k] = t0-t1;
			}
}
int rg[202020],rgcnt = 0;

inline int quick_pow(int x,int p,int mul=1) {
	for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline int getRoot() {
	for (int i = 2;i < mod-1; i++)
		if ((mod-1)%i == 0)
			rg[++rgcnt] = i;
	for (int i = 2;i < mod; i++) {
		int j;
		for (j = 1;j <= rgcnt; j++)
			if (quick_pow(i,rg[j]) == 1)
				break;
	//	if (j > rgcnt)
	//		cout << i << endl;
	}
	return 0;
}
int pows[202020] = {0},t[202020];
	int aa[202020];
int main() {
	int rt = getRoot();
	rt = 5;
	pows[0] = 1;
	t[1] = 0;
	for (int i = 1;i <= mod-1; i++) {
		pows[i] = pows[i-1]*rt%mod;
		t[pows[i]] = i;
	}
	scanf("%d",&n);
	for (int i = 1;i <= n; i++) {
		scanf("%d",&aa[i]);
		if (aa[i])
		a[t[aa[i]]].a++;
	}
	int N = n;
	n = m = mod-1;
	while (nn <= n+m)
		nn <<= 1;
	int half = nn/2;
	for (int i = 1;i < nn; i++)
		rev[i] = ((rev[i>>1]>>1)|((i&1)?half:0));
	for (int i = 0;i < half; i++)
		w1[i|half] = Complex(cos(pi*i/half),sin(pi*i/half));
	for (int i = half-1;i; i--)
		w1[i] = w1[i<<1];
	for (int i = 0;i < nn; i++)
		w2[i] = w1[i].conj();
	FFT(a,w1);
	for (int i = 0;i < nn; i++)
		a[i] = a[i]*a[i];
	FFT(a,w2);
	long long ans = 0,now = 1;
	for (int i = 0;i <= n+m; i++) {
		ans += now*(long long)(a[i].a/nn+.5);
		now *= rt;
		now %= mod;
	}
	for (int i = 1;i <= n; i++)
		ans -= (long long)aa[i]*aa[i]%mod;
	ans /= 2;
	printf("%lld\n",ans);
	return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  int N; cin >> N;
  map<string, int> mm;
  
  string input;
  rep(i, N) {
    cin >> input;
    mm[input]++;
  }
  
  int M; cin >> M;
  rep(i, M) {
    cin >> input;
    mm[input]--;
  }
  
  int ans=0;
  for(auto i=mm.begin(); i!=mm.end(); ++i) {
    ans = max(ans, i->second);
  }
  dump(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a,min=INT_MAX,max=INT_MIN;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a;
        if(a>max){
            max=a;
        }
        if(a<min){
            min=a;
        }
    }
    cout<< max-min <<endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for i in range(10):
  a = S.find(str(i))
  if a != -1:
    for j in range(10):
      b = S.find(str(j), a+1)
      if b != -1:
        for k in range(10):
          c = S.find(str(k), b+1)
          if c != -1:
            ans += 1
print(ans)

Measured memory_bytes: 9152
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  (n:q:_) <- map read . words <$> getLine :: IO [Int]
  s <- getLine :: IO String
  tds <- replicateM q $ (\(a:b:_) -> (head a, head b)) . words <$> getLine :: IO [(Char, Char)]
  print $ solve n s tds

solve n s tds = rbound - lbound - 1
  where
    rbound = if vanishRight n 
             then lowerBound vanishRight (1, n) 
             else n + 1
    lbound = if vanishLeft 1 
             then upperBound vanishLeft (1, n) 
             else 0

    sarr = listArray (1, n) s
    vanish left right i = go i tds
      where
        go :: Int -> [(Char, Char)] -> Bool
        go i tds
          | i > n = right
          | i < 1 = left
          | null tds = False
          | otherwise = if sarr ! i == t
                        then if d == 'R'
                             then go (i+1) $ tail tds
                             else go (i-1) $ tail tds
                        else go i $ tail tds
            where (t, d) = head tds

    vanishRight = vanish False True
    vanishLeft = vanish True False
          
lowerBound :: (Int -> Bool) -> (Int, Int) -> Int
lowerBound predicate bounds = go bounds
  where
    go (l, h) | l + 1 == h = if predicate l then l else h
              | predicate m = go (l, m)
              | otherwise = go (m, h)
      where m = (l + h) `div` 2
    
upperBound :: (Int -> Bool) -> (Int, Int) -> Int
upperBound predicate bounds = go bounds
  where
    go (l, h) | l + 1 == h = if predicate h then h else l
              | predicate m = go (m, h)
              | otherwise = go (l, m)
      where m = (l + h) `div` 2
    

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
  tmp[A[i] - 1] += 1


ans = N
flag = False
for i in range(10 ** 5):
  if tmp[i] == 0:
    continue
  elif tmp[i] % 2 == 1:
    ans -= (tmp[i] - 1)
  else:
    if flag:
      ans -= (tmp[i] - 2)
      flag = False
    else:
      ans -= tmp[i]
      flag = True

print(ans)

Measured memory_bytes: 20736
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}



signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1];
    set<int>s;
    map<int,int>mm;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    int cnt=0;
    for(auto i:s)
        mm[i]=++cnt;
    for(int i=1;i<=n;i++)
        a[i]=mm[a[i]];
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]&1)!=(i&1))
        {
            ans++;
        }
    }
    cout<<ans/2; 
    

} 
    
 

Measured memory_bytes: 15356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next().replaceAll("\\?", ".");
		String t = sc.next();
		int ns = s.length();
		int nt = t.length();
		for(int i = ns - nt ; i >= 0 ; i--) {
			String regex = s.substring(i, i + nt);
			if(t.matches(regex)) {
				System.out.println(s.replaceFirst(s.substring(0, i) + regex, s.substring(0, i) + t).replaceAll("\\.", "a"));
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
}

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

using namespace std;

#define int long long

inline int read(){
	int x=0,f=1;
	char p=getchar();
	while(!isdigit(p)){
		if(p=='-') f=-1;
		p=getchar();
	}
	while(isdigit(p)) x=(x<<3)+(x<<1)+(p^48),p=getchar();
	return x*f;
}

const int maxn=1e5+5,mod=1e9+7;

int n,K,a[maxn],ans1,ans2,cheng[maxn],inv[maxn];

inline int power(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

inline int C(int n,int m){
	return cheng[n]*inv[m]%mod*inv[n-m]%mod;
}

inline bool cmp(int a,int b){
	return a>b;
}

signed main(){
	n=read();K=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n,cmp);
	cheng[0]=1;for(int i=1;i<=n;i++) cheng[i]=cheng[i-1]*i%mod;
	inv[0]=inv[1]=1;inv[n]=power(cheng[n],mod-2);
	for(int i=n-1;i>=2;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=1;i+K-1<=n;i++){
		ans1=(ans1+ a[i] * C( n-i , K-1 ) %mod ) %mod;
	}
	for(int i=K;i<=n;i++){
		ans2=(ans2+ a[i] * C( i-1 , K-1 ) %mod ) %mod;
	}
	cout<<(ans1-ans2+mod)%mod<<endl;
	return 0;
}













Measured memory_bytes: 2560