akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
int n;
  cin >> n;
  long long int sum=0;
  long long int i=1;
  while(i<=n){
   if(i%3==0 || i%5==0){i++;continue;}
    sum+=i;
    i++;
  }
  cout << sum;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int N=105;
const int M=N*N;
const int L=10000000;

int last[N],bel[N];
int nxt[M],tov[M];
bool mark[L+5];
int pos[2][N];
bool vis[N];
int n,tot,mx,match,ans;

inline int iabs(int x){return x>0?x:-x;}

inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}

inline bool is_prime(int x)
{
	if (x==1) return 0;
	for (int i=2;i*i<=x;++i) if (!(x%i)) return 0;
	return 1;
}

bool hungary(int x)
{
	if (vis[x]) return 0;
	vis[x]=1;
	for (int i=last[x],y;i;i=nxt[i])
		if (!bel[y=tov[i]]||hungary(bel[y]))
			return bel[y]=x;
	return 0;
}

int main()
{
	//freopen("flip.in","r",stdin),freopen("flip.out","w",stdout);
	scanf("%d",&n);
	for (int i=1,x;i<=n;++i) scanf("%d",&x),mx=max(mx,x),mark[x]=1;
	for (int i=1;i<=mx+1;++i)
		if (mark[i]^mark[i-1])
			pos[i&1][++pos[i&1][0]]=i;
	for (int i=1;i<=pos[0][0];++i)
		for (int j=1;j<=pos[1][0];++j)
		{
			int d=iabs(pos[0][i]-pos[1][j]);
			if (is_prime(d)) insert(i,j);
		}
	match=0;
	for (int i=1;i<=pos[0][0];++i) memset(vis,0,sizeof vis),match+=hungary(i);
	ans=match,pos[0][0]-=match,pos[1][0]-=match;
	ans+=(pos[0][0]&1)+pos[0][0]+pos[1][0];
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 6528
# Inputを格納
r, c = map(int, input().split())
list = [list(map(int, input().split())) for i in range(r)]

# # テスト用インプット
# r, c = 2, 3
# list = [[1, 2, 3],[4, 5, 6]]

# 各行の合計値を出力
for i in range(r):
    list[i].append(sum(list[i]))
    print(*list[i])

# 各列の合計値を出力
sumList =[]
for j in range(c+1):
    sum = 0
    for i in range(r):
        sum += list[i][j]
    sumList.append(sum)
print(*sumList)



Measured memory_bytes: 6224
#include<iostream>

using namespace std;

int main(){
    int A,B,C,D;

    cin>>A>>B>>C>>D;

    if(A+B==C+D){
        cout<<"Balanced";
    }else if(A+B>C+D){
        cout<<"Left";
    }else{
        cout<<"Right";
    }
}

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

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

   int n = sc.nextInt();
   long sum = 0;
   int min = 1000000;
   int max = -1000000;

   for(int i=0; i<n; i++){
       int a = sc.nextInt();
       sum += a;
       if(a < min){
           min = a;
       }
       if(a > max){
           max = a;
       }
   }

    System.out.println(min + " " + max + " " + sum);
 }
}

Measured memory_bytes: 42496
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int count=0;
	System.out.print(" ");
	for(int i=1;i<=n;i++){
	    int num=i;
	    if(num%3==0) {
		if(count==0) System.out.print(i);
		else System.out.print(" "+i);
		count++;
	    }
	    else {
		while(num!=0){
		    if(num%10==3){
			if(count==0) System.out.print(i);
			else System.out.print(" "+i);
			count++;
			break;
		    }
		    num/=10;
		}

	    }
	  
	}
	System.out.println("");
    }
}

Measured memory_bytes: 24296
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int r, d, x2000;
    cin >> r >> d >> x2000;

    int x = x2000;
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


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

int main()
{
    std::string arc, abc, in, out;
    arc = "ARC";
    abc = "ABC";

    std::cin >> in;
    if(in == arc){
        out = abc;
    } else if (in == abc)
    {
        out = arc;
    }
    std::cout << out << std::endl;

    return 0;
}

Measured memory_bytes: 3596
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
		int N;
		cin>>N;
		int s=0;
		int prec=1000000000;
		for(int i=0;i<N-1;i++){
			int b;
			cin>>b;
			s+=min(prec,b);
			prec=b;
		}
		s+=prec;
		cout<<s;
		return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         String s=gs();
         int a=0;
         int b=0;
         int c=0;

         for(int i=0; i<s.length();i++) {
        	 char ch=s.charAt(i);
        	 if(ch=='a') {
        		 a++;
        	 } else if(ch=='b') {
        		 b++;
        	 } else {
        		 c++;
        	 }
         }

         if(s.length()==1) {
        	 System.out.println("YES");
         } else if(s.length()==2) {
        	 if(a==2 || b==2 || c==2) {
        		 System.out.println("NO");
        	 } else {
        		 System.out.println("YES");
        	 }
         } else {
        	 int min=Math.min(Math.min(a, b), c);
        	 int max=Math.max(Math.max(a, b), c);
        	 if(min==0 || max-min>1) {
        		 System.out.println("NO");
        	 } else {
        		 System.out.println("YES");
        	 }
         }
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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

int main() {
	int n; cin>>n;
	vector<int>v(n); for(int i=0;i<n;i++)cin>>v[i];
	
	vector<int>left(n); left[0]=v[0];
	for(int i=1;i<n;i++){
		left[i]=__gcd(left[i-1],v[i]);
	}
	vector<int>right(n); right[n-1]=v[n-1];
	for(int i=n-2;i>=0;i--){
		right[i]=__gcd(right[i+1],v[i]);
	}
	
	int ret=max(right[1],left[n-2]);
	for(int i=1;i<n-1;i++){
		ret=max(ret,__gcd(left[i-1],right[i+1]));
	}
	cout<<ret<<endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int count = 1;
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1])
			count++;
		else {
			if (count % 2 == 1)
				ans++;
			count = 1;
		}
	}
	if (count % 2 == 1)
		ans++;
	cout << ans << endl;
	return 0;
}

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

#初期状態
node = [[] for _ in range(N)]
node[0] = [i for i in range(1,N)]

if K > N*(N-1)//2 - (N-1):
    print(-1)
else:
    cnt = 0
    for i in range(1,N):
        if cnt >= N*(N-1)//2-(N-1)-K:
            break
        for j in range(i+1,N):
            if cnt >= N*(N-1)//2-(N-1)-K:
                break
            node[i].append(j)
            cnt += 1
    
    print(N-1+cnt)
    for n in range(N):
        for t in node[n]:
            print(n+1,t+1)

Measured memory_bytes: 9288
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 約数の個数
template <int_fast64_t max_N> struct Prime {
    int cnt[max_N] = {0};
    constexpr Prime() : cnt() {
        for (int_fast64_t i = 1; i < max_N; ++i) {
            for (int_fast64_t j = i; j < max_N; j += i)
                cnt[j]++;
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    constexpr auto d = Prime<65535>();
    int cnt = 0;
    for (int i = 105; i <= N; i += 2) {
        cnt += d.cnt[i] == 8;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4668
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int n,a,b; cin >> n >> a >> b;
    string S; cin >> S;
    int cnt=0;
    int cb=0;
    for(int i=0;i<n;i++){
        if(S[i]=='a'){
            if(cnt<a+b){
                cout << "Yes" << endl;
                cnt++;
            }else{
                cout << "No" << endl;
            }
        }else if(S[i]=='b'){
            cb++;
            if(cnt<a+b && cb<=b){
                cout << "Yes" << endl;
                cnt++; 
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 896
isKuku :: Int -> Bool
isKuku n = any id $ map isOneDigit $ map (div' n) [1..9]

div' :: Int -> Int -> Int
div' x y
    | x `mod` y == 0 = x `div` y
    | otherwise = 0 

isOneDigit :: Int -> Bool
isOneDigit n = (n >= 1) && (n <= 9)


main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    case isKuku n of
        True -> putStrLn "Yes"
        False -> putStrLn "No"

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

int main() {
	set <int> s;
  	s.insert(1);
  	s.insert(2);
  	s.insert(3);
  	int a,b; cin >> a >> b;
  	s.erase(a);
  	s.erase(b);
  	cout << *s.begin();
}

Measured memory_bytes: 256
import fractions
N,X=map(int,input().split())
x=list(map(int,input().split()))
d=abs(x[0]-X)
if N==1:
    print(d)
    exit()
for i in range(1,len(x)):
    d=fractions.gcd(d,abs(x[i]-X))
print(d)

Measured memory_bytes: 16300
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n,k;

int main()
{
    cin>>n>>k;
    int now=1;
    for (int i=1; i<=n; ++i)
    {
        int now1=now*2;
        int now2=now+k;
        now=min(now1,now2);
    }
    cout<<now<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        //int a = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int num[] = new int[];
        String s = stdIn.next();
        //String t = stdIn.next();
        char c[] = s.toCharArray();
        int count = 0;
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < s.length() / 2; i++){
            if(c[i] != c[s.length() - i - 1]){
                count++;
            }
        }
        
        System.out.println(count);
        
        //System.out.println();
        //System.out.print();

        stdIn.close();
    }
}


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

int main(){

    string n;
    cin>>n;

    if(n.at(0)=='7'||n.at(1)=='7'||n.at(2)=='7')
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    





    return 0;
}

Measured memory_bytes: 3628
n=int(input())
l=sorted([int(input()) for i in range(n)])
if sum(l)%10!=0:
  print(sum(l))
else:
  ans=sum(l)
  for i in range(n):
    if l[i]%10!=0:
      ans-=l[i]
      print(ans)
      quit()
  print(0)

Measured memory_bytes: 3060
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

S = str(input())
ans = True
for i,s in enumerate(S):
    if i % 2 == 0 and s == "L" or i % 2 == 1 and s == "R":
        ans = False

if ans:
    print("Yes")
else:
    print("No")


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

#define int int64_t

vector< vector<int> >v , patty;
vector<int>dp , cnt;

void init() {
    int i,j;
    v.resize(51);
    patty.resize(51);
    dp.resize(51);
    cnt.resize(51);
    v[0] = {1};
    patty[0] = {1};
    dp[0] = 1;
    cnt[0] = 1;
    for(i=1;i<=50;++i) {
        dp[i] = 2 * dp[i-1] + 3;
        cnt[i] = 2 * cnt[i-1] + 1;
        v[i] = {1 , dp[i-1] , 1 , dp[i-1] , 1};
        patty[i] = {0 , cnt[i-1] , 1 , cnt[i-1] , 0};
    }
}

int solve(int n , int ele) {
    if(n == 1) {
        if(ele == 1) return 0;
        if(ele == 5) return 3;
        else return ele - 1;
    }
    // cout << n << ' ' << ele << endl;
    int s1[6] = {0} , s2[6] = {0};
    for(int i = 0; i < 5;++i) {
        s1[i+1] = s1[i] + v[n][i];
        s2[i+1] = s2[i] + patty[n][i];
    }
    // cout << "THE Contents\n";
    // for(auto x:v[n]) cout << x << ' ';cout << endl;
    // for(auto x:patty[n]) cout << x << ' ';cout << endl;
    // for(auto x:s1) cout << x << ' ';cout << endl;
    // for(auto x:s2) cout << x << ' ';cout << endl;
    int count = 0;
    for(int i=1;i<=5;++i) if(s1[i] == ele) return s2[i];
    for(int i=1;i<=5;++i) {
        if(s1[i] > ele) {
            count = s2[i-1];
            count += solve(n-1 , v[n][i-1] - (s1[i] - ele));
            break;
        }
    }
    return count;
}

int32_t main() {
    auto z = clock();
	init();
	int n , k, i , j , l;
	cin >> n >> k;
	cout << solve(n , k) << endl;
	cerr << (clock() - z)/CLOCKS_PER_SEC;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int X,A,B;
   scanf("%d %d %d",&X,&A,&B);
   if(A>=B)
   		printf("delicious\n");
   else if(A<B && (B-A)<=X)
   		printf("safe\n");
   else
   		printf("dangerous\n");					
   return 0;
}

Measured memory_bytes: 128
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    if s == "SUN":
        print(7)
    elif s == "MON":
        print(6)
    elif s == "TUE":
        print(5)
    elif s == "WED":
        print(4)
    elif s == "THU":
        print(3)
    elif s == "FRI":
        print(2)
    else:
        print(1)

    


if __name__ == '__main__':
    main()


Measured memory_bytes: 69100
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  vector<int> v(3);
  for(int i=0;i<3;i++) cin>>v[i];
  sort(v.begin(),v.end());
  cout<<v[0]*v[1]/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
map<ll,ll> p;
int main(){
    ll a,b;
    cin>>a>>b;
    ll c=GCD(a,b);
    ll d=c;
    ll k=2;
    bool q=true;
    while(c>1){
        if(k>1e8 ||k>c){q=false;break;}
        if(k<=c&&c%k==0){
            while(c%k==0&&c>1){
            p[k]++;
            c/=k;
        }
    }
     k++;
     if(c==1)break;
    }
    if(q)cout<<p.size()+1;
    else cout<<p.size()+2;
}

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

using namespace std;
using ll = long long;

const int N = 1000002;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	vector<int> prime(N);
	iota(prime.begin(), prime.end(), 0);

	for (int i = 2; i < N; i++)
		if (prime[i] == i)
			for (int j = 2 * i; j < N; j += i)
				prime[j] = i;

	vector<vector<int>> all(N);
	int n;
	cin >> n;

	int g = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		g = gcd(g, x);
		while (x != 1) {
			int now = prime[x];
			all[now].push_back(i);
			while (x % now == 0)
				x /= now;
		}
	}

	if (g != 1)
		return cout << "not coprime\n", 0;

	bool ok = true;
	for (int i = 0; i < N; i++)
		ok &= all[i].size() < 2;

	cout << (ok ? "pairwise coprime" : "setwise coprime") << '\n';
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);;
    
    int N;
    cin >> N;
    int a[N];
    set<int> as;
    int init=1;
    int result;
    for(int i=0;i<N;i++){
        cin >> a[i];
        if (a[i] == init) {
            as.insert(a[i]);
            init++;
        }
    }
    if (as.empty() == true){
        result = -1;
    }
    else{
        result = N - as.size();
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 10368
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            bool result = true;

            for (int i = 0; i < str.Length-1; i++)
            {
                char c = str[i];
                char t = str[i + 1];

                if (c == t)
                {
                    result = false;
                    break;
                }
            }

            Console.WriteLine(result?"Good":"Bad");

        }
    } 
}


Measured memory_bytes: 11092
/*
    Problem 69
    https://atcoder.jp/contests/abc084/tasks/abc084_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 100005;
/* global variables */
vector<bool> isPrime;
vector<bool> isLike2017;
vector<int> prefixSum(MAX+1);
/* function */
void eratos() {
    isPrime.assign(MAX, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i * i <= MAX; i++) {
        if (!isPrime[i]) continue;
        for (int j = i+i; j <= MAX; j+=i)
            isPrime[j] = false;
    }
}
void calcLike2017() {
    isLike2017.assign(MAX, false);
    for (int i = 1; i < MAX; i+=2) {
        if (isPrime[i] && isPrime[(i+1)/2]) isLike2017[i] = true;
    }
}
void fillPrefixSum () {
    for (int i = 0; i < MAX; i++)
        prefixSum[i+1] = prefixSum[i] + isLike2017[i];
}
int calcAns(int l, int r) {
    // [l, r)
    return prefixSum[r+1] - prefixSum[l];
}
/* main */
int main(){
    eratos();
    calcLike2017();
    fillPrefixSum();
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << calcAns(l, r) << '\n';
    }
}

Measured memory_bytes: 3656
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,dp[100000][3]={},a,b,c,ans;
    scanf("%d",&n);
    scanf("%d %d %d",&a,&b,&c);
    dp[0][0]=a;
    dp[0][1]=b;
    dp[0][2]=c;
    for(int i=1;i<n;i++){
        scanf("%d %d %d",&a,&b,&c);
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
    }
    ans=max(dp[n-1][0],dp[n-1][1]);
    ans=max(ans,dp[n-1][2]);
    printf("%d\n",ans);
}

Measured memory_bytes: 1280
k, n = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n-1) :
    b[i] = a[i+1] - a[i]

b[n-1] = k + a[0] - a[n-1]

print(sum(b) - max(b))


Measured memory_bytes: 26444
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, h ] :: [Int] <- map read . lines  <$> getContents
	print $ ( a + b ) * h `div` 2


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    int win=0,lose=0;
    rep(i,n){
      if(i%2==0 && s[i]=='p') lose++;
      if(i%2==1 && s[i]=='g') win++;
    }
    cout<<win-lose<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
struct state { long long cx, cy; };
bool operator<(const state& s1, const state& s2) { return s1.cx < s2.cx; }
int N, sp, c1, c2, dl, dr, c[262156]; long long D, x[33], y[33], qx[14348915], qy[14348915]; state s1[14348915], s2[14348915], st[14348915];
void dfs1(int cur, long long cx, long long cy) {
	if (cur == sp) {
		if(cx < 0 || (cx == 0 && cy <= 0)) s1[c1++] = state{ cx, cy };
		return;
	}
	dfs1(cur + 1, cx, cy);
	dfs1(cur + 1, cx + x[cur], cy + y[cur]);
	dfs1(cur + 1, cx - x[cur], cy - y[cur]);
}
void dfs2(int cur, long long cx, long long cy) {
	if (cur == N) {
		if(cx < 0 || (cx == 0 && cy <= 0)) s2[c2++] = state{ cx, cy };
		return;
	}
	dfs2(cur + 1, cx, cy);
	dfs2(cur + 1, cx - x[cur], cy + y[cur]);
	dfs2(cur + 1, cx + x[cur], cy - y[cur]);
}
int main() {
	cin >> N >> D;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
	sp = N / 2;
	dfs1(0, 0, 0);
	dfs2(sp, 0, 0);
	for (int i = 0; i < 54; i += 18) {
		fill(c, c + 262144, 0);
		for (int j = 0; j < c1; j++) c[((-s1[j].cx >> i) & 262143) + 1]++;
		for (int j = 0; j < 262144; j++) c[j + 1] += c[j];
		for (int j = 0; j < c1; j++) st[c[((-s1[j].cx) >> i) & 262143]++] = s1[j];
		for (int j = 0; j < c1; j++) s1[j] = st[j];
		fill(c, c + 262144, 0);
		for (int j = 0; j < c2; j++) c[((-s2[j].cx >> i) & 262143) + 1]++;
		for (int j = 0; j < 262144; j++) c[j + 1] += c[j];
		for (int j = 0; j < c2; j++) st[c[((-s2[j].cx) >> i) & 262143]++] = s2[j];
		for (int j = 0; j < c2; j++) s2[j] = st[j];
	}
	reverse(s1, s1 + c1);
	reverse(s2, s2 + c2);
	for (int i = 0; i < c1; i++) s1[c1 * 2 - i - 1] = state{ -s1[i].cx, -s1[i].cy }; c1 *= 2;
	for (int i = 0; i < c2; i++) s2[c2 * 2 - i - 1] = state{ -s2[i].cx, -s2[i].cy }; c2 *= 2;
	int l = 0, r = 0; long long ret = -1LL << 60;
	for (int i = 0; i < c1; i++) {
		while (r < c2 && s2[r].cx <= s1[i].cx + D) {
			while (dl != dr && s2[r].cy >= qy[dr - 1]) dr--;
			qx[dr] = r;
			qy[dr] = s2[r].cy;
			dr++;
			r++;
		}
		while (l < c2 && s2[l].cx < s1[i].cx - D) {
			if (qx[dl] == l) dl++;
			l++;
		}
		if (dl != dr) {
			ret = max(ret, qy[dl] + s1[i].cy);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 608376
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


string s;
_int used[1000001][2];
_int mem[1000001][2];

Int dfs(Int idx, Int k){

  if(idx == (Int)s.size()) return k;
  if(used[idx][k]++) return mem[idx][k];

  Int num = s[idx] - '0';
  Int a = INF, b = INF, c = INF, d = INF;

  if(k == 0){
    a = dfs(idx + 1, 0) + num;
    b = dfs(idx + 1, 1) + num + 1;
  }
  if(k == 1){
    c = dfs(idx + 1, 0) + (10 - num);
    d = dfs(idx + 1, 1) + (10 - num - 1);
  }
  Int res = min({a, b, c, d});
  pr(idx, k, a, b, c, d);
  return mem[idx][k] = res;
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>s;

  Int a = dfs(0, 0);
  Int b = dfs(0, 1) + 1;
  Int ans = min(a, b);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 95132
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll n,i,t,m,c,mx=0,T,ans=0,r,k=0,p=0,q,x,y,l;
     cin>>t;
     if(t==1)
        cout<<0<<endl;
     else cout<<1<<endl;
}






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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll N;

    cin >> N;

    cout << N * (N + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n, m; cin >> n >> m;
  //int s[10][10];
  vector<int> v[10];

  for (int i = 0; i < m; ++i) {
    int k; cin >> k;
    for (int j = 0; j < k; ++j) {
      int s; cin >> s; --s;
      v[i].emplace_back(s);
    }
  }

  int p[m];
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  int cnt = 0;

  for (int i = 0; i < (1<<n); ++i) {
    bitset<11> bit(i);
    bool all_on = true;
    for (int j = 0; j < m; ++j) {
      int on = 0;
      for (size_t k = 0; k < v[j].size(); ++k) {
        if (bit.test(v[j][k])) {
          ++on;
        }
      }
      if (on % 2 != p[j]) {
        all_on = false; break;
      }
    }
    cnt += all_on;
  }

  cout << cnt << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(min(A, B) - N + max(A, B), 0);
}



Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <vector>
#include <iomanip>
#include <iostream>
#include <stack>
#include <queue>
#include <list>
#include <utility>
 
#include <string>
#include <cstring>
 
#include <cstdio>
#include <cassert>
 
// M_PI for pi
#define _USE_MATH_DEFINES
#include <cmath>
 
using namespace std;
 
static const int MAX = 1000005;

long long int v[MAX];
int n;
 
int main(int argc, char* argv[]) {

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    long long int S = 0;
    long long int s = 0;

    for (int i = 0; i < n; ++i) {
        if (v[i] == 0) {
            S += s / 2;
            s = 0;
        } else {
            s += v[i];
        }
    }

    S += s / 2;

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> A(N);
	vector<vector<pair<int, int>>> xy;
	for (int& i : A) {
		cin >> i;
		xy.emplace_back(i);
		for (pair<int, int>& i : xy.back()) cin >> i.first >> i.second;
	}
	for (int i = 0; i < pow(2.0, N); i++) {
		bitset<15> a = i;
		bool b = true;
		for (int j = 0; j < N; j++) {
			if (a[j]) {
				bool c = true;
				for (int k = 0; k < A[j]; k++) {
					if (xy[j][k].second == 1) {
						if (!a[xy[j][k].first - 1]) {
							c = false;
							break;
						}
					}
					else {
						if (a[xy[j][k].first - 1]) {
							c = false;
							break;
						}
					}
				}
				if (!c) {
					b = false;
					break;
				}
			}
		}
		if (b) ans = max(ans, (int)a.count());
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str s;
  cin >> s;
  int n = s.length();
  int cnt[3];
  fill(cnt,cnt+3,0);
  REP(i,n) cnt[s[i]-'a']++;
  sort(cnt,cnt+3);
  if(cnt[2]-cnt[0]>=2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
def cc082():
    from collections import Counter

    n = int(input())
    an = list(map(int, input().split()))

    dan = Counter()
    for i in range(0, n):
        dan[an[i]] += 1

    cnt = 0
    for k,v in dan.items():
        if v > k:
            cnt += v - k
        elif k > v:
            cnt += v

    print(cnt)

cc082()

Measured memory_bytes: 18676
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include <string.h>
using namespace std;
int n;
long long x, y;
int main() {
	cin >> x >> y;
	long long cnt = 0;
	while (y >= x) {
		x *= 2;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int p=31;
const int m=1e9+7;
typedef long long ll;
typedef int in;
#define ff first
#define ss second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");} 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define int ll
in main (){
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	unordered_map<int,pair<int,int>>ct;

	for(int i=0;i<n;++i){
		cin>>a[i];
		ct[a[i]].ff+=1;
	}

	for(int i=0;i<n;++i){
		cin>>b[i];
		ct[b[i]].ss+=1;
	}
	bool hai=true;
	for(int i=0;i<n;++i){
		if(ct[a[i]].ff+ct[a[i]].ss>n)
			{
				hai=false;
				break;
			}
	}

	if(!hai){
		cout<<"No";
		return 0;
	}
	cout<<"Yes\n";
	vector<int>r(n);
	r=b;
	reverse(r.begin(),r.end());
	int kha=-1,val=-1;
	for(int i=0;i<n;++i){
		if(r[i]==a[i]){
			kha=i;
			val=r[kha];
			break;
		}
	}	
	int l = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == val && r[i] == val) {
            l = i;
            break;
        }
    }
	if(kha!=-1)
	for(int i=0;i<n && kha<n;++i){	
		if(a[i]!=val && r[i]!=val && kha<=l){
		swap(r[i],r[kha]);
		++kha;
	}
		// if(kha<n && r[kha]!=val)break;
	}		
	// for(int i=0;i<n && kha<n;++i){
	// 	if(a[i]==val || r[i]==val|| i==kha)continue;
	// 	swap(r[i],r[kha]);
	// 	++kha;
	// 	if(kha<n && r[kha]!=val)break;
	// }
	for(int i=0;i<n;++i){
		cout<<r[i]<<' ';
	}

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time    
}
    
/*
12
1 1 2 3 3 4 4 5 6 7 8 9
1 3 3 3 3 3 5 6 6 6 6 6
*/

Measured memory_bytes: 13748
//#include <bits/stdc++.h>                          //include all library  
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1

int main()
{
  int n;
  cin >> n;
  int s,t;
  int sum = 0;

  while(n--)
  {
    cin >> s >> t;
    sum += t-s+1;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,k;
	scanf("%lld%lld%lld",&a,&b,&k);
	if(b-a+1<=2*k)rep(i,a,b+1)printf("%lld\n",i);
	else{
		rep(i,a,a+k)printf("%lld\n",i);
		rep(i,b+1-k,b+1)printf("%lld\n",i);
	}
}

Measured memory_bytes: 128
import math
line = input().split(" ")
N = int(line[0])
A = int(line[1])
B = int(line[2])
C = int(line[3])
D = int(line[4])

tmp = 0

A_num = math.ceil(N/A)
C_num = math.ceil(N/C)

if A_num * B < C_num * D:
    print(A_num * B)
else:
    print(C_num * D)


Measured memory_bytes: 5664
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 500000
#define SENTINEL 2000000000

struct Card{
	char pattern;
	int value;
};

Card L[MAX/2+2], R[MAX/2+2];

void merge(Card A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(int i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1].value = SENTINEL;
	R[n2].value = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		if( L[i].value <= R[j].value){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(Card A[], int n, int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(Card A[], int n, int p, int r){
	int i, j;
	Card t, x;
	x = A[r];
	i = p - 1;
	for(j = p; j < r; j++){
		if(A[j].value <= x.value){
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i +1];
	A[i +1] = A[r];
	A[r] = t;
	return i+1;
}

void quickSort(Card A[], int n, int p, int r){
	int q;
	if(p < r){
		q = partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q + 1, r);
	}
}

int main(){
	Card M[MAX];
	Card Q[MAX];
	int i;
	int n = 0, inputValue = 0;
	char pattern[5];
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s %d", pattern, &inputValue);
		M[i].pattern = pattern[0];
		Q[i].pattern = pattern[0];
		M[i].value = inputValue;
		Q[i].value = inputValue;
	}
	
	mergeSort(M, n, 0, n);
	quickSort(Q, n, 0, n-1);
	
	int check = 0;
	for(i = 0; i < n; i++){
		if(M[i].pattern != Q[i].pattern){
			check++;
			break;
		}
	}
	
	if(check == 0){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	
	for(i = 0; i < n; i++){
		if(i != 0){
			printf("\n");
		}
		printf("%c %d", Q[i].pattern, Q[i].value);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 4948
import copy
n = int(input())
a = list(map(int, input().split()))
array = [(a[i], i+1) for i in range(n)]
array.sort(reverse=True)
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(n):
    for j in range(n):
        if i + j >= n:
            break
        count = i + j
        #右に移した場合
        value, index = array[count]
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + value * abs((n - j) - index))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + value * abs((i + 1) - index))
ans = 0
for i in range(n+1):
    for j in range(n+1):
        ans = max(ans, dp[i][j])
print(ans)
        




Measured memory_bytes: 102612
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        if(int.Parse(str[0]) <= int.Parse(str[2]) && int.Parse(str[2]) <= int.Parse(str[1])){
            sb.Append("Yes\n");
        }
        else{
            sb.Append("No\n");
        }
    }
}

Measured memory_bytes: 11092
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  val n = in.next().toInt
  val k = in.next().toInt

  //
  // if (k >= n) {
  //   // 任意実行なのでCombでいい感じに
  // }
  {
    val mc = new ModComb(n, MOD)
    var ans = 0L

    for (i <- 1 to (k min (n-1))) {

      val ball = i
      val stick = (n-i)-1
      ans += mc.comb(n, i) * mc.comb(ball+stick, stick)
      ans %= MOD

      // println(i, ans)
    }

    if (k % 2 == 0 || k >= 3) {
      ans += 1
    }

    println(ans)
  }
}

class ModComb(maxNum: Int, mod: Long) {

  private def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2)
    else
      (x * repeatSquares(x*x % mod, n/2)) % mod
  }

  private val fact = new Array[Long](maxNum + 1)

  fact(0) = 1
  for (i <- 1 to maxNum)
    fact(i) = (i * fact(i-1)) % mod

  val factInv = new Array[Long](maxNum + 1)

  factInv(maxNum) = repeatSquares(fact(maxNum), mod-2)
  for (i <- (1 to maxNum).reverse)
    factInv(i-1) = (i * factInv(i)) % mod


  // nCk
  def comb(n: Int, k: Int): Long = {
    val numer = fact(n)
    val denom = (factInv(n-k) * factInv(k)) % mod

    (numer * denom) % mod
  }

}


object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 29632
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp[51][51][2505];
int n,K;
main()
{
    cin>>n>>K;
    dp[0][0][0]=1;
    for(int i=0;i<n;i++)for(int j=0;j<=i;j++)
    {
        for(int k=0;k<=K-2*j+2;k++)
        {
            if(dp[i][j][k]==0)continue;
            (dp[i+1][j][k+2*j]+=dp[i][j][k]*(2*j+1)%mod)%=mod;
            if(j>0)(dp[i+1][j-1][k+2*j-2]+=dp[i][j][k]*j*j%mod)%=mod;
            (dp[i+1][j+1][k+2*j+2]+=dp[i][j][k])%=mod;
        }
    }
    printf("%lld\n",dp[n][0][K]);
    return 0;
}

Measured memory_bytes: 48512
str = gets.chomp.to_s

i = (str.length-1)/2 - 1
j = (str.length+3)/2 - 1
last = str.length-1
if str == str.reverse && 
   str[0..i]  == str[0..i].reverse &&
   str[j..last]  == str[j..last].reverse then
   puts("Yes")
else 
    puts("No")
end


Measured memory_bytes: 1788
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    string n;
    cin >> n;
    for (auto &c : n)
        if (c == '9')
            c = '1';
        else if (c == '1')
            c = '9';

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stack>	//スタック
#include<iostream>

using namespace std;

int main(void){
	int n,i,data[10],ans=1;
	stack<int> right;
	stack<int> left;

	cin>>n;
	while(n>0){
		n--;
		cin>>data[0]>>data[1]>>data[2]>>data[3]>>data[4]>>data[5]>>data[6]>>data[7]>>data[8]>>data[9];
		right.push(data[0]);
		for(i=1;i<10;i++){
			if(right.top()<data[i])
				right.push(data[i]);
			else{
				if(left.empty())
					left.push(data[i]);
				else{
					if(left.top()<data[i])
						left.push(data[i]);
					else
						ans=0;
				}
			}
		}
		if(ans==0) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
		while(!left.empty())
			left.pop();
		while(!right.empty())
			right.pop();
	}

	return 0;
}
		

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n,k;cin >> n >> k;
  vector<int> a(n);
  vector<ll> b(n);
  rep(i,n) cin >> a[i] >> b[i];
  ll res = 0;
  for(int i = 29;i >= 0;--i) {
    if( (k >> i) & 1 ) {
      ll sum = 0;
      rep( j, a.size() ) {
	if( ! ( ( a[j] >> i ) & 1 ) ) {
	  sum += b[j];
	}
      }
      res = max( res, sum );
    }
    else {
      vector<int> atmp;
      vector<ll> btmp;
      rep( j, a.size() ) {
	if( ! ( ( a[j] >> i ) & 1 ) ) {
	  atmp.push_back( a[j] );
	  btmp.push_back( b[j] );	  
	}
      }
      a = atmp;
      b = btmp;
    }
  }
  ll summ = 0;
  rep( j, a.size() ) {
    summ += b[j];
  }
  res = max( res, summ );
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0; i<x; i++)
#define repn(i,x) for(int i=0; i<=x; i++)
typedef long long int ll;
const int MAX = 200005;
const int MOD = 1000000007;
const int maxn = 100000+5;
ll fac[MAX], finv[MAX], inv[MAX];
ll memp1[maxn], memp2[maxn];
int n, A, B, C;

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(int n, int k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void make()
{
	repn(i, n)
	{
		if(i)
		{
			memp1[i] = memp1[i-1] * (ll)A % MOD * inv[A+B] % MOD; 
			memp2[i] = memp2[i-1] * (ll)B % MOD * inv[A+B] % MOD; 
		}
		else if(!i) memp1[0] = memp2[0] = 1;
	}
}

ll solve()
{
	make();
	ll sum1 = 0, sum2 = 0;;
	rep(i, n)
	{
		sum1 += memp1[n] * memp2[i] % MOD * COM(n+i-1, i) % MOD * (ll)(n+i) % MOD;
		sum2 += memp2[n] * memp1[i] % MOD * COM(n+i-1, i) % MOD * (ll)(n+i) % MOD;
	}
	return (sum1 + sum2) % MOD * 100LL % MOD * inv[A+B] % MOD;
}

void Print()
{
	cout << "SHOW p1" << endl;
	repn(i, n)
	{
		cout << memp1[i] << endl;
	}
	cout << "SHOW p2" << endl;
	repn(i, n)
	{
		cout << memp2[i] << endl;
	}
	cout << "SHOW inv" << endl;
	repn(i, n)
	{
		cout << inv[i] << endl;
	}
}

int main()
{
	COMinit();
	scanf("%d %d %d %d", &n, &A, &B, &C);
	printf("%lld\n", solve());
	//Print();
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;


int main(){
  int H, W; cin >> H >> W;
  char A[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < W + 2; i++) cout << "#";
  cout << endl;

  for (int i = 0; i < H; i++){
    cout << "#";
    for (int j = 0; j < W; j++){
      cout << A[i][j];
    }
    cout << "#" << endl;
  }

  for (int i = 0; i < W + 2; i++) cout << "#";
  cout << endl;  
  
  
  return 0;
}


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

int main()
{
    map<string,int>mp;
    set<string>s;
    int counter=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string a;
        cin>>a;
        mp[a]++;
        s.insert(a);
        counter=max(counter,mp[a]);
    }
    set<string>::iterator it;
    for(it = s.begin();it != s.end(); it++)
    {
        if(mp[*it]==counter)cout<<*it<<endl;
    }
}


Measured memory_bytes: 34560