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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;

char s[N];
int cnt[33];

signed main(){
    int n;
	scanf("%lld %s", &n, s+1);	
    
    for(int i=1; i<=n; i++)
        cnt[ s[i]-'a' ]++;
    
    int ans = 1;
    for(int i=0; i<26; i++)
        ans = ans * (cnt[i] + 1) % mod;
    
    cout << ans - 1;
    return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e3 + 10;
const int mod = 1e9 + 7;

int n, m;
char a[maxN][maxN];
int dx[] = {-1, 0};
int dy[] = {0, -1};
int dp[maxN][maxN];

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
  for (int j = 1; j <= m; ++j) {
    cin >> a[i][j];
  }
  dp[1][1] = 1;
  for (int i = 1; i <= n; ++i)
  for (int j = 1; j <= m; ++j) {
    if (a[i][j] == '#') continue;
    for (int id = 0; id < 2; ++id) {
      int u = i + dx[id], v = j + dy[id];
      if (u > 0 && v > 0)
        dp[i][j] = (0ll + dp[i][j] + dp[u][v]) % mod;
    }
  }
  cout << dp[n][m];
return 0;
}


Measured memory_bytes: 8532
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0,g=0,h=0, count = 0;
	char ac,uc[100000];
	string manji,gage;
	cin >> a>>b;
	if (b == 4 || b == 6 || b == 9 || b == 11) {
		if (a == 4 || a == 6 || a == 9 || a == 11) {
			cout << "Yes" << endl;
		}
		else { cout << "No" << endl; }
	}
	else if (b == 2) {
		if (a == 2) {
			cout << "Yes" << endl;
		}
		cout << "No" << endl;
	}
	else {
		if (a != 4 && a != 6 && a != 9 && a != 11 && a != 2) {
			cout << "Yes" << endl;
		}
		else { cout << "No" << endl; }
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, ans = 1000000000000000000, ma = 0, mi = 1000000000000000000;
  std::cin >> N;
  vvl ab = vv(N, 2, 0, ll);

  for(int i=0;i<N;i++){
    std::cin >> ab[i][0] >> ab[i][1];
    if(ab[i][0]<ab[i][1]) swap(ab[i][0], ab[i][1]);
    mi = min(mi, ab[i][1]);
    ma = max(ma, ab[i][0]);
  }
  ll bmin = 0, mmax = 1000000000000000000;
  for(int j=0;j<N;j++){
    bmin = max(bmin, ab[j][1]);
    mmax = min(mmax, ab[j][0]);
  }
  ans = (bmin - mi) * (ma - mmax);
  for(int i=0;i<N;i++){
    if(ab[i][0]==ma&&ab[i][1]==mi){
      std::cout << ans << '\n';
      return 0;
    }
  }
  multimap<ll, ll> num;
  for(int i=0;i<N;i++) {
    if(ab[i][0]==ma) swap(ab[i][0], ab[i][1]);
    else if(ab[i][1]!=mi) swap(ab[i][0], ab[i][1]);
    num.emplace(ab[i][0], ab[i][1]);
  }
  while(true){
    auto itr = num.begin();
    auto it = --num.end();
    ll x =(*it).first, y = (*itr).first, z = (*itr).second;
    ans = min(ans, (ma-mi)*(x - y));
    if(z!=mi&&z!=ma&&y<z) num.erase(itr),num.emplace(z, y);
    else break;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 23680
module Main where

-- import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

data Tree a = Nil | Node a (Tree a) (Tree a) deriving (Show)
data Command = Print | Delete Int | Find Int | Insert Int deriving (Show)
data Order = Preorder | Inorder deriving (Eq, Show)

sDelete = B.pack "delete"
sFind   = B.pack "find"
sInsert = B.pack "insert"
sPrint  = B.pack "print"

solve :: [Command] -> [String]
solve = iter Nil where
    iter :: Tree Int-> [Command] -> [String]
    iter _ [] = []
    iter rt (c:cs) = case c of
        Print    -> (inorder rt):(preorder rt):(iter rt cs)
        Delete x -> iter (delete x rt) cs
        Find x   -> (find x rt):(iter rt cs)
        Insert x -> iter (insert x rt) cs

    delete x = iter where
        iter Nil = Nil 
        iter (Node y l r)             
            | x < y  = Node y (iter l) r
            | x > y  = Node y l (iter r)
            | x == y = case (l, r) of
                (Nil, Nil) -> Nil
                (Nil, r)   -> r
                (l, Nil)   -> l
                (l, r)     -> Node z l (delete z r) where
                    z = min r
    
    min (Node x Nil _) = x
    min (Node x l   _) = min l

    find x = iter where
        iter (Node y l r)
            | x == y = "yes"
            | x <  y = iter l
            | x >  y = iter r 
        iter Nil = "no"

    insert x = iter where
        iter (Node y l r)             
            | x < y     = Node y (iter l) r
            | otherwise = Node y l (iter r) 
        iter Nil = Node x Nil Nil 

    preorder = toString . (toList Preorder)
    inorder  = toString . (toList Inorder)

toList :: Ord a => Order -> Tree a -> [a]
toList ord = iter where
    iter Nil = []
    iter (Node id l r)
        | ord == Preorder = id:(iter l) ++ iter r
        | ord == Inorder  = (iter l) ++ id:iter r

toString:: [Int] -> String
toString [] = []
toString (x:xs) = ' ':(show x)++ toString xs

toInt :: B.ByteString -> Int
toInt = fst . fromJust . B.readInt
                    
readIntLn:: IO Int
readIntLn = toInt <$> B.getLine

readCommand:: IO Command
readCommand = do
    l <- B.words <$> B.getLine
    return $ case l of
        [cmd, n]
            | cmd == sDelete -> Delete $ toInt n
            | cmd == sFind   -> Find   $ toInt n
            | cmd == sInsert -> Insert $ toInt n
        [sPrint]     -> Print

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readCommand
    mapM_ putStrLn $ solve l



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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  if(a)
    cout << b / x - (a-1)/x << endl;
  else
    cout << b / x  + 1 << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"unicode"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	var s string
	fmt.Scanf("%s", &s)

	flag := true
	i := 0
	for ; i < a; i++ {
		if unicode.IsDigit(rune(s[i])) == false {
			flag = false
			break
		}
	}
	if s[i] != '-' {
		flag = false
	}
	i += 1
	for ; i < a + b + 1; i++ {
		if unicode.IsDigit(rune(s[i])) == false {
			flag = false
			break
		}
	}

	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
Dx=abs(dx)
Dy=abs(dy)
val='U'*Dy+'R'*Dx+'D'*Dy+'L'*(Dx+1)+'U'*(Dy+1)+'R'*(Dx+1)+'D'+'R'+'D'*(Dy+1)+'L'*(Dx+1)+'U'
ans_l=[]
for _ in range(len(val)):
	ans_l.append(val[_])
l=len(ans_l)
if dy<0:
	for i in range(l):
		if ans_l[i]=='U':
			ans_l[i]='D'
		elif ans_l[i]=='D':
			ans_l[i]='U'
if dx<0:
	for j in range(l):
		if ans_l[j]=='R':
			ans_l[j]='L'
		elif ans_l[j]=='L':
			ans_l[j]='R'
print("".join(ans_l))

Measured memory_bytes: 3188
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Ord
import Data.Function
import Control.Monad.State (State, evalState, runState, put, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)

main :: IO ()
main = readContents 2 >>= putStrLn . solve

solve :: [[Int]] -> String
solve [[n, m], as] = build . calc n m $ candidates as

build :: [Int] -> String
build = map (\x -> chr $ zero + x)
    where
        zero = ord '0'

calc :: Int -> Int -> [(Int, Int)] -> [Int]
calc n m xs = evalState (choose n xs) empty
    where
        choose i (x@(a, c) : ys) = check >>= next
            where
                check = (==) <$> res1 <*> res2
                res1 = f (i - c, x : ys)
                res2 = pred <$> f (i, x : ys)
                next b 
                    | b = (a :) <$> choose (i - c) (x : ys)
                    | otherwise = choose i ys
        choose _ _ = return []

        f = memoizeFix memo 

type Key = (Int, [(Int, Int)])

memo :: Memoizer Key Int -> Memoizer Key Int
memo f (i, x@(_, c) : xs)
    | i > 0 = max <$> next1 <*> next2
    | i < 0 = return ninf
    | otherwise = return 0
    where
        next1 = succ <$> f (i - c, x : xs)
        next2 = f (i, xs)
memo _ _ = return ninf

ninf :: Int
ninf = -100000

candidates :: [Int] -> [(Int, Int)]
candidates = sortBy (flip cmpFst) . map head . groupBy ((==) `on` snd) . sortBy cmpf . map acf
    where
        acf n 
            | n == 1 = (n, 2)
            | n `elem` [2, 3, 5] = (n, 5)
            | n == 4 = (n, 4)
            | n `elem` [6, 9] = (n, 6)
            | n == 7 = (n, 3)
            | otherwise = (n, 7)

        cmpf lhs rhs = comparing snd lhs rhs `mappend` cmpFst rhs lhs

        cmpFst = comparing fst

type Memoizer a b = a -> State (Map a b) b

evalMemo :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
evalMemo f = flip evalState empty . memoizeFix f

runMemo :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> (b, Map a b)
runMemo f = flip runState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 12668
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1000006
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

string s;

bool palindrome(string x){
  int l = x.length();
  for (int i = 0; i<(l+1)/2; ++i){
    if (x[i] != x[l-1-i]) return false;
  }
  return true;
}
int main(){
    //freopen("data.txt","r",stdin);
    cin >> s;
    bool pali = true;
    if (!palindrome(s)) pali = false;
    string str_1 = "";
    int l = s.length();
    for (int i = 0; i< (l-1)/2; ++i){
        str_1 += s[i];
    }
    if (!palindrome(str_1)) pali = false;
    string str_2 = "";
    for (int i = ((l+3)/2)-1; i < l; ++i){
        str_2 += s[i];
    }
    if (!palindrome(str_2)) pali = false;
    if (pali) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>

using namespace std;
using experimental::any;

#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define MODE 0
#define DEB(X) if(MODE)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(MODE)cout<<X<<" ";
#define ARDEB(i,X) if(MODE)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) if(MODE){(f)? cout<<"true ":cout<<"false ";}
#define FORDEB(n,X) if(MODE)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(MODE)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
struct P2{int x,y;};
//struct edge{int from,cost,to;};
#define Endl endl

const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000;

int main(){
	int a[31][100001]={},n,m,count=0,max=0;
	cin>>n>>m;
	REP(i,n){
		int s,t,c;
		cin>>s>>t>>c;
		a[c-1][s-1]++,a[c-1][t]--;
	}
	REP(i,m){//シミュレーション
		REP(j,100000){
			a[i][j+1]+=a[i][j];
		}
	}
	REP(i,100001){
		count=0;
		REP(j,m){
			if(a[j][i]>0){
				count++;
			}
		}
		if(count>max){
			max=count;
		}
	}
	cout<<max<<endl;
	return 0;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int h[n];
	for(int i=0; i<n; i++) {
		cin>>h[i];
	}
	int dp[n];
	dp[0] = 0;
	for(int i=1; i<n; i++) {
		dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
		if(i != 1)
			dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
import sys
n, m, x = [int(i) for i in sys.stdin.readline().split()]
c_ls = []
a_ls = []
INF = 10**18
for i in range(1,1+n):
    inp = [int(i) for i in sys.stdin.readline().split()]
    c = inp[0]
    a_s = inp[1:]
    c_ls.append(c)
    a_ls.append(a_s)

best = INF
for i in range(1 << n):
    _sum = 0
    scores = [0] * n
    combi = bin(i)[2:].zfill(n)
    for i, c in enumerate(combi):
        if c == "1":
            _sum += c_ls[i]
            scores = [s + a for s, a in zip(scores, a_ls[i])]
    if min(scores) < x:
        continue
    if best > _sum:
        best = _sum
if best == INF:
    print(-1)
else:
    print(best)

Measured memory_bytes: 69000
using System.Linq;

public class Hello{
    public static void Main(){

        int[] nums = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        
        System.Console.WriteLine(
            nums.Count(x => x == 5) == 2 &&
            nums.Count(x => x == 7) == 1 ?
            "YES" : "NO"
        );
    }
}


Measured memory_bytes: 11348
W, H, N = map(int, input().split())
maxX,minX,maxY,minY = W, 0, H ,0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > minX:
        minX = x
    elif a == 2 and x < maxX:
        maxX = x
    elif a == 3 and y > minY:
        minY = y
    elif a == 4 and y < maxY:
        maxY = y
        
x1 = maxX - minX
y1 = maxY - minY
if x1 > 0 and y1 > 0:
    print(x1*y1)
else:
    print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int Mod=1000000007;
int a[200010];
char s[200010];
int f[200010],g[200010];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=m;i++)
		a[i]=s[i]=='B';
	if(a[1]){
		for(int i=1;i<=m;i++)
			a[i]^=1;
	}
	bool flag=true;
	for(int i=1;i<=m;i++)
		if(a[i])flag=false;
	if(flag){
		f[0]=1;
		g[0]=1;
		for(int i=1;i<=n;i++)
		{
			if(i>1)f[i]=g[i-2];
			g[i]=(g[i-1]+f[i])%Mod;
		}
		int ans=1;
		for(int i=2;i<=n;i++)
			ans=(ans+1ll*f[n-i]*i)%Mod;
		printf("%d\n",ans);
		return 0;
	}
	if(n&1){
		printf("0\n");
		return 0;
	}
	int lim=n;
	int lst=0;
	for(int i=1;i<=m;i++)
		if(a[i]){
			if(!lst)lim=min(lim,i-lst+1);
			else if((i-lst)%2==0)lim=min(lim,i-lst);
			lst=i;
		}
	lim/=2;
	f[0]=1;
	g[0]=1;
	for(int i=1;i<=n/2;i++)
	{
		f[i]=g[i-1];
		if(i-lim>0)f[i]=(f[i]-g[i-lim-1]+Mod)%Mod;
		g[i]=(g[i-1]+f[i])%Mod;
	}
	int ans=0;
	for(int i=1;i<=lim;i++)
		ans=(ans+1ll*i*2*f[n/2-i])%Mod;
	printf("%d\n",ans);
	return 0;
}

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

int as(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int de(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}


int re_number(int *s,int l){
    int sum,i,ll;
    sum = 0;
    ll = l - 1;
    for(i = 0; i < l ; i++){
        sum += s[i] * pow(10,ll);
        ll--;
    }
    return sum;

}

void make_string(int *s,int l,int num){

    int count = l-1;
    int i;
        
    for(i = 0 ; i < l ; i++){
        s[i] = num / (int)pow(10,count);
        num = num % (int)pow(10,count);
        count--;
            
    }

}
typedef struct{
    int x;
    int value;
}MAX_MIN;

int struct_sort( const void *p, const void *q ) {
    return ((MAX_MIN*)p)->value - ((MAX_MIN*)q)->value;
}


int main(){

    int s[6],l,i,j,num,k,t;
    int max, min;
    MAX_MIN a[20];
    int ij[20];
    int dis_min;
    int x1_dmin,x2_dmin,value_dmin,i_min,j_min;
    int a0;

    while(1){
        scanf("%d %d",&num,&l);
        if(num == 0 && l == 0)
            break;

         for(i = 0; i < 6 ; i++){
             s[i] == 0;
         }   

    
        make_string(s,l,num);
        a[0].value = re_number(s,l);
        a0 = a[0].value;
        a[0].x = 0;
        for(i = 1; i < 20 ; i++ ){
        ij[i] = 0;
        max = 0;
        min = 0;
        qsort(s,l,sizeof(int),as);
        min = re_number(s,l);
        qsort(s,l,sizeof(int),de);
        max = re_number(s,l);
        make_string(s,l,max-min);
        a[i].value = re_number(s,l);
        a[i].x = i;

        //printf("%d\n",a[i].value);
        }
        qsort(a,20,sizeof(MAX_MIN),struct_sort);
        dis_min = 20;
        /*
        for(i = 0; i < 20; i++)
            printf("sort = %d, x = %d\n",a[i].value,a[i].x);
          */
        x1_dmin = 0;x2_dmin = 0; value_dmin = -1; j_min = 20,i_min = 20;j = 0;k = 0;
        for(i = 0; i < 20 ; i++){
            t = 0;
            //printf("i = %d\n",i);
            //printf("value of : %d\n",a[i].value);
            if(a[i].value == a[i+1].value){
                j = i;  
                while(a[j].value == a[i].value){
                    ij[t] = a[j].x;
                    t++;
                    j++;

                }
                qsort(ij,t,sizeof(int),as);
                x1_dmin = ij[0];//j
                x2_dmin = ij[1];//i
                //printf("%d %d\n",j_min,x1_dmin);
                if(j_min > x1_dmin){
                    j_min = x1_dmin;
                    i_min = x2_dmin;
                    
                    value_dmin = a[i].value;
                }
                i = j-1;       
            }
        }
            
    if(value_dmin == -1){
        if(a[0].value == a0){
            printf("%d %d %d\n",a[1].x,a[1].value,20 - a[1].x);
        }else{
            printf("%d %d %d\n",a[0].x,a[0].value,20 - a[0].x);
        }
    }else{        
        printf("%d %d %d\n",j_min,value_dmin,i_min - j_min);
    }

    }
    return 0;

}



Measured memory_bytes: 2064
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

vector<int> z_function(string s, int n) {
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if(i <= r) z[i] = min (r - i + 1, z[i - l]);
    while(i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int N; cin >> N;
  string S; cin >> S;
  
  int ans=0;
  for(int i=0; i<N; i++){
    string tmp = S.substr(i);
    vector<int> vec = z_function(tmp, N-i);
    for(int j=0; j<N-i; j++) if(vec[j]<=j) ans=max(ans,vec[j]);
  }
  cout << ans << "\n";
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(void)
{
    vector<long long int> a;
    long long int n;
    long long int x;

    cin>>n>>x;
    for(int i = 0;i < n;i++) {
	long long int temp;
	cin>>temp;
	a.push_back(temp);
    }


    long long count = 0;
    for(int i = 0;i < n-1;i++)
    {
	if(a[i]+a[i+1] > x) {
	    int diff;
	    diff = (a[i]+a[i+1]) - x;
	    count += diff;

	    a[i+1] -= diff;
	    if(a[i+1] < 0) {
		int c = -a[i+1];
		a[i] -= c;
		a[i+1] = 0;
	    }
	}
    }

    cout<<count<<endl;

    return 0;
}


Measured memory_bytes: 1400
def main():
    n, k = map(int, input().split())
    nt = tuple(range(n))
    kt = tuple(range(1, k + 1))
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in nt:
        for j in kt:
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 24716
#include <iostream>
#include <vector>
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];
  int mx = 0, s = 0;
  rep(i, 1, n) {
    if(v[i] <= v[i-1]) {
      s++;
    } else {
      if(mx < s) mx = s;
      s = 0;
    }
  }
  if(mx < s) mx = s;
  cout << mx << "\n";
}

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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=1010,mod=1e9+7;
int n,m;
string f[N];
int dp[N][N];

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<n;++i)cin>>f[i];
	dp[0][0]=f[0][0]=='.';
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
			if(f[i][j]!='#'){
				dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
				dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod;
			}
	cout<<(f[n-1][m-1]=='.')*dp[n-1][m-1]<<endl;
}


Measured memory_bytes: 8560
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 4e3 + 5; 
int dp[N][N]; 

void solve(int test) {
	int n; cin >> n ;
	int a[n+1] , pf[n+1] = {} ; rep(i,1,n+1) cin >> a[i] , pf[i] = pf[i-1] + a[i] ;

	rep(i,1,n+1) rep(j,1,n+1) if(i != j) dp[i][j] = INF ; 

	for(int i = n ; i > 0 ; --i ) {
		for(int j=i+1 ; j <= n ; ++j) {
			for(int k = i ; k < j ;++k) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pf[j] - pf[i-1] );
			}
		}
	}
	
	cout << dp[1][n] ; 
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif   

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

namespace _20180305_AOJ
{
    class ALDS1_5D
    {
        static int count;
        static long invCnt;
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                count = 0;
                invCnt = 0;
                int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                MergeSort(A, 0, A.Length);

                /*
                for (int i = 0; i < A.Length - 1; i++)
                {
                    Console.Write(string.Format("{0} ", A[i]));
                }
                Console.WriteLine(A[A.Length - 1]);
                */
                //Console.WriteLine(count);
                Console.WriteLine(invCnt);
            }
        }

        static void Merge(int[] A, int left, int mid, int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;
            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];
            int i = 0;
            for (i = 0; i < n1; i++)
            {
                L[i] = A[left + i];
            }
            for (i = 0; i < n2; i++)
            {
                R[i] = A[mid + i];
            }
            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;

            i = 0;
            int j = 0;
            for (int k = left; k < right; k++)
            {
                if (L[i] <= R[j])
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];

                    invCnt += n1 - i;

                    j++;
                }

                count++;
            }
        }

        static void MergeSort(int[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                int mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }
    }
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int d = 0;
    // 1 回の反転で最大でも 2 幸福が増えるだけ 
    REP(i, N-1){
        if(S[i+1] != S[i]) ++d;
    }
    d = max(0, d-2*K);
    cout << N-1-d << endl;

    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}

signed main() {
	int n;
	cin >> n;
	int now = 1;
	while (n) {
		if (now % 5 == 1 && prime(now)) {
			cout << now << " ";
			n--;
		}
		now++;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
item_vote = list(map(int, input().split()))
total_vote = sum(item_vote)
item_vote = sorted(item_vote, reverse=True)
boder = total_vote/(4*M)
if item_vote[M-1] < boder:
    print('No')
else:
    print('Yes')

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

 


int main()
{
   int a,b;
   int k;
   cin>>k;
   cin>>a>>b;
   
   int f=0;
   for(int i=a;i<=b;i++)
   {
      if(i%k==0)
      {
         cout<<"OK"<<endl;
         f=1;
         break;
      }
   }
   if(f==0)
   {
      cout<<"NG"<<endl;
   }



}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); 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; }
const long long INF = 1LL << 60;

int N,M;
vector<vector<int>> graph;
vector<bool> visited;

int dfs(int node, int cnt){
    if(cnt==N) return 1;

    visited[node] = true;

    int ret = 0;
    for(int next_node:graph[node]){
        if(visited[next_node]) continue;
        ret+=dfs(next_node, cnt+1);
    }
    visited[node] = false;
    return ret;
}

int main()
{
    cin >> N>>M;
    visited.resize(N);
    REP(i,N) visited[i] = false;

    graph.resize(N);
    REP(i,M){
        int a,b;
        cin>>a>>b;
      	a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int cnt=0;
    cnt = dfs(0, 1);

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e16
ll n0;
ll dp[105][100005]={0};
ll solv(vector<pair<ll,ll> > &v1,ll i,ll w)
{
    if(dp[i][w]!=0) return dp[i][w];  //memory check
    
    
    if(w==0) return 0;                  //base condition    
    if(i>=n0) return 0;             //base condition
    
    if(w-v1[i].first<0) return solv(v1,i+1,w);
    
    ll a=solv(v1,i+1,w-v1[i].first)+v1[i].second;
    ll b=solv(v1,i+1,w);
    
    
    
    dp[i][w]=max(a,b);              //creating memory
    return dp[i][w];                    //returning ans
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d,e,f,n,m,k,t,q;
    t=1;
    //cin>>t;
    string s1;
    while(t--)
    {
        cin>>n>>m;
        vector<pair<ll,ll> > v1;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            v1.push_back({a,b});
        }
        
        n0=v1.size();
        a=solv(v1,0,m);
        cout<<a;
        
    }
    return 0;
}

Measured memory_bytes: 78080
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n;
int sum,mn=1e5;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		sum+=a;
		if(a%10) mn=min(mn,a);
	}
	if(!sum){
		cout<<sum;
		re 0;
	}
	if(sum%10==0){
		sum-=mn;
		if(mn==1e5){
			cout<<0;
			re 0;
		}
	}
	cout<<sum;
	re 0;
}

Measured memory_bytes: 3660
// #include <bits/stdc++.h>
#include <iostream> // cin, cout, string
#include <algorithm> // sort, min, max
#include <vector>
#include <utility> // pair, swap
#include <functional>

using namespace std;

// #define int long long

using ll = long long;
using ld = long double;

using vi = vector<int>;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
// const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N, K;
string S;

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

  cin >> N >> K;
  cin >> S;

  S[K-1] = S[K-1] - 'A' + 'a';

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>

using namespace std;
typedef long long ll;

ll n, a[100001] = {}, ans, ma = 0, mi = 1e9;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ma = max(ma, a[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (ma % 2 == 0 || (a[i] < ma)) {
			if (mi > abs(ma / 2 - a[i]) && a[i] != ma) {
				mi = abs(ma / 2 - a[i]);
				ans = a[i];
			}
		}
		else {
			if (mi > abs(ma / 2 + 1 -a[i]) && a[i] != ma) {
				mi = abs(ma / 2 + 1 -a[i]);
				ans = a[i];
			}
		}
	}
	cout << ma << " " << ans << endl;
	return 0;
}

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

int main() {
    int n;
    long long v;
    cin >> n >> v;
    vector<long long> a(n), b(n), c(n), d(n);
    for (auto &e : a) cin >> e;
    for (auto &e : b) cin >> e;
    for (auto &e : c) cin >> e;
    for (auto &e : d) cin >> e;
    vector<long long> s, t;
    for (auto e : a) for (auto f : b) s.push_back(e + f);
    for (auto e : c) for (auto f : d) t.push_back(e + f);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    
    long long ans = 0;
    for (auto e : s) {
        long long val = v - e;
        ans += upper_bound(t.begin(), t.end(), val) - lower_bound(t.begin(), t.end(), val);
    }
    
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 23020
"""
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_d

D - Knapsack 1
"""

def solve(wv_pairs):
    dp = [0] * (W + 1)
    for i in range(N):
        w_i, v_i = wv_pairs[i]
        for ww in range(W, w_i - 1, -1):
            dp[ww] = max(dp[ww], dp[ww - w_i] + v_i)
    return max(dp)


N, W = map(int, input().split())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
res = solve(pairs)
print(res)


Measured memory_bytes: 40432
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll int n;
    cin>>n;
    ll int a[n];
    ll int b[n];
    for(int i=0;i<n;i++){
          cin>>a[i];
          b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[n-1]){

            cout<<b[n-1]<<" ";

        }else {

        	cout<<b[n-2]<<" ";

        }
    }
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main()
{
	LL l, r, mid, no, wei; 
	string res;
	for(no = 0, wei = 100000000000000000LL; ; wei /= 10)
	{
		l = (no ? 0 : 1), r = 9;
		while(l < r)
		{
			mid = (l + r) >> 1;
			cout << "? " << (no * 10 + mid + 1) * wei - 1 << endl << flush;
			cin >> res;
			if(res[0] == 'Y') r = mid;
			else l = mid + 1;
		} 
		no = no * 10 + r;
		cout << "? " << no * wei << endl << flush;
		cin >> res;
		if(res[0] == 'Y')
		{
			if(no == 1)
				for(wei = 1;; wei *= 10)
				{
					cout << "? " << wei + 1 << endl << flush;
					cin >> res;
					if(res[0] == 'Y')
					{
						cout << "! " << wei << endl << flush;
						return 0;
					}
				}
			
			for(wei = 1;; wei *= 10)
			{
				cout << "? " << (no - 1) * wei << endl << flush;
				cin >> res;
				if(res[0] == 'N') break;
			} 
			cout << "! " << no * wei / 10 << endl << flush;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 596
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
from collections import defaultdict
from pprint import pprint
import math
import datetime
import sys

N = int(input())
P = [int(x) for x in input().split()]

sortedP = sorted(P)

diff = 0
for p1, p2 in zip(P, sortedP):
    if p1 != p2:
        diff += 1

if diff == 0 or diff == 2:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 3952
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
const int INF = 1<<31;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int LL;

const int MOD=1e9+7;
int p;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(NULL);
    cout.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

    cin >> p;
    int cc=1;

    FORN(i,2,p){
        bool flag=false;

        FOR(j,2,i){
            if(i%j==0){
                flag=true;
                break;
            }
        }
        if(!flag){
            ll cur=i;
            ll sum=0;

            while(p/cur){
                sum+=p/cur;
                cur*=i;
            }
            cc=(1LL*cc*(sum+1))%MOD;
        }
    }

    cout << cc << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    static List<Integer> list = new ArrayList<>();
    static HashMap<Integer, Integer> ans = new HashMap<>();
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        
        calc(0, 0);
        
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            if (ans.containsKey(sc.nextInt())) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }
    
    static void calc(int rep, int sum) {
        if (rep == list.size()) {
            ans.put(sum, sum);
            return;
        }
        int val = list.get(rep);
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                calc(rep + 1, sum + val);
            } else {
                calc(rep + 1, sum);
            }
        }
    }
}

Measured memory_bytes: 62740
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> w(n),c(n),j(10001),index(10001);
    for(int i=0;i<n;i++){
        cin>>w[i];
    }

    c=w;
    for(int i=0;i<10001;i++){
        j[i]=1;
    }
    int m=10001,ans=0;
    for(int i=0;i<n;i++){
        m=min(m,w[i]);
    }
    sort(c.begin(),c.end());
    for(int i=0;i<n;i++){
        index[c[i]]=i;
    }
    for(int i=0;i<n;i++){
        if(j[w[i]]){
            int cnt=0,x=w[i],min1=10001;
            do{
                j[x]=0;
                min1=(min1,x);
                ans+=x;
                x=w[index[x]];
                cnt++;
            }while(x!=w[i]);
            if(cnt==1) ans-=x;
            else if(cnt>=3){
                ans+=min(min1*(cnt-2),min1+m*(cnt+1));
            }            
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3232
/**
 *    author:  tourist
 *    created: 14.07.2019 16:01:35       
**/
#include <bits/stdc++.h>

using namespace std;

mt19937 rng(58);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  vector<int> all(n);
  iota(all.begin(), all.end(), 1);
  int v = 0;
  for (int x : all) {
    v ^= x;
  }
  if (v == 0) {
    for (int i = 1; i < 2 * n; i++) {
      cout << i << " " << i + 1 << '\n';
    }
    return 0;
  }
  if (v <= n) {
    all.erase(all.begin() + v - 1);
    while (true) {
      shuffle(all.begin(), all.end(), rng);
      vector<int> pref(1, 0);
      for (int rot = 0; rot < 2; rot++) {
        for (int i = 0; i < n - 1; i++) {
          pref.push_back(pref.back() ^ all[i]);
        }
      }
      map<int, int> mp;
      int from = -1, to = -1;
      for (int it = 0; it < (int) pref.size(); it++) {
        int x = pref[it];
        if (mp.find(x ^ v) != mp.end()) {
          from = mp[x ^ v];
          to = it;
          break;
        }
        mp[x] = it;
      }
      if (from != -1) {
        vector<int> vers;
        for (int i = 0; i < n - 1; i++) {
          vers.push_back(all[i]);
        }
        for (int i = 0; i < n - 1; i++) {
          vers.push_back(all[i] + n);
        }
        for (int i = 0; i < 2 * n - 3; i++) {
          cout << vers[i] << " " << vers[i + 1] << '\n';
        }
        cout << vers[from] << " " << v << '\n';
        cout << vers[to - 1] << " " << v + n << '\n';
        break;
      }
    }
    return 0;
  }
  assert(v == n + 1);
  vector<int> vers;
  for (int i = 2; i <= n - 1; i++) {
    vers.push_back(i);
  }
  swap(vers[vers.size() - 2], vers[vers.size() - 1]);
  for (int i = 2; i <= n - 1; i++) {
    vers.push_back(i + n);
  }
  swap(vers[vers.size() - 2], vers[vers.size() - 1]);
  for (int i = 0; i < (int) vers.size() - 1; i++) {
    cout << vers[i] << " " << vers[i + 1] << '\n';
  }
  cout << n - 1 << " " << 1 << '\n';
  cout << n - 2 << " " << n + 1 << '\n';
  cout << n - 2 << " " << n << '\n';
  cout << n + 2 << " " << n + n << '\n';
  return 0;
}


Measured memory_bytes: 4852
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		String str = "ABC";
		if (n >= 1000) {
			str = "ABD";
			n -= 999;
		}
		System.out.println(str);
//		System.out.println(str + (n / 100) + "" + (n / 10 % 10) + "" + (n % 10));
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		int nextInt() {
			return (int) nextLong();
		}
	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <set>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;

using namespace std;

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

  set<string> SS;
  for (int size = 1; size <= K; size++) {
    for (int j = 0; size + j <= s.size(); j++) {
      SS.insert(s.substr(j, size));
    }
  }
  auto p = SS.begin();
  for (int i = 0; i < K - 1; i++)
    p++;
  cout << (*p) << endl;
}


Measured memory_bytes: 1664
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();
    println!(
        "{}",
        a.iter()
            .map(|a| {
                let mut a = *a;
                let mut cnt = 0;
                while a % 2 == 0 {
                    cnt += 1;
                    a /= 2;
                }
                cnt
            })
            .min()
            .unwrap()
    );
}


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

  string s; cin >> s;
  sort(s.begin(),s.end());
  if(s.at(0)==s.at(1)&&s.at(2) == s.at(3) && s.at(1)!=s.at(2))
    cout<< "Yes" << endl;
  else
    cout<< "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main(){
    using A = array<int, 3>;
    int n;
    cin >> n;
    set<A> s;
    for (int i = 0; i < n; ++i) {
        A x;
        for (auto &&j : x) cin >> j;
        sort(x.begin(),x.end());
        s.emplace(x);
    }
    cout << n-s.size() << "\n";
    return 0;
}


Measured memory_bytes: 3220