akhauriyash/Code-Regression huggingface dataset:
def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    NL = len(L)
    NR = len(R)
    i = 0
    j = 0
    for k in range(left, right):
        if i == NL:
            A[k] = R[j]
            j += 1
        elif j == NR:
            A[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return right - left


def mergesort(A, left, right):
    ans = 0
    if right - left > 1:
        mid = (left + right) // 2
        ans += mergesort(A, left, mid)
        ans += mergesort(A, mid, right)
        ans += merge(A, left, mid, right)
    return ans


def main():
    N, *S = map(int, open(0).read().split())
    ret = mergesort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65576
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B, C, D;
    scan(A, B, C, D);
    long f(long x)
    {
        long lcm = (C * D) / gcd(C, D);
        return x - (x / C) - (x / D) + (x / lcm);
    }

    writeln(f(B) - f(A - 1));
}


Measured memory_bytes: 256
from collections import deque
s = str(input())
q = int(input())
stat = 0
l = []
a = deque()
b = deque()
for i in range(q):
    l = list(map(str, input().split()))
    t = int(l[0])
    if t == 1:
        stat += 1
    else:
        f = int(l[1])
        c = l[2]
        if stat % 2 == 0:
            if f == 1:
                a.appendleft(c)
            else:
                b.append(c)
        else:
            if f == 1:
                b.append(c)
            else:
                a.appendleft(c)

#print(a, b, stat % 2)
ans = ''.join(a)+s+''.join(b)
if stat % 2 == 1:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 12348
package main

import (
	"bufio"
	"fmt"
	"os"
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

var dict = map[rune]bool{
	'A': true,
	'C': true,
	'T': true,
	'G': true,
}

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

func maxACTGCount(str string) int {
	maxCount := 0
	count := 0
	for _, c := range str {
		_, ok := dict[c]
		if ok {
			count++
			maxCount = max(maxCount, count)
		} else {
			count = 0
		}
	}
	return maxCount
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	fmt.Println(maxACTGCount(readLine(sc)))
}


Measured memory_bytes: 640
n,k = map(int,input().split())
ls = list(map(int,input().split()))
dp = [10000000000] *n
dp[0] = 0
dp[1] = abs(ls[1]-ls[0])
p = 10000000000
for i in range(2,n):
    for j in range(i-k,i):
        if (dp[j] >= p) or (abs(ls[j] - ls[i]) >= p):
            pass
        else:
            a = dp[j] + abs(ls[j] - ls[i])
            if a < p:
                p = a
                a = 0
            else:
                a = 0
    dp[i] = p
    p = 10000000000
print(dp[n-1])


Measured memory_bytes: 52576
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct UF
{
  vector<int> par;
  vector<int> sz;
  vector<int> rank;
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int n){return sz[find(n)];}
};

bool isdig(char c){
  return '0' <= c && c <= '9';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,h,w;cin>>n>>h>>w;
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    ans += min(a/h,b/w);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
D, E = [], []
t,l = 0, 0
res = 0
for _ in range(N):
    S = input().rstrip()
    x,y = 0,0
    for s in S:
        if s=="(": x+=1
        else: x=max(x-1,0)
    for s in reversed(S):
        if s==")": y+=1
        else: y=max(y-1,0)
    D.append((x,y))
D.sort(key=lambda x:x[1])
t = 0
for x,y in D:
    if x-y>=0:
        if t>=y: t+=x-y
        else: print("No"); exit()
D.sort(key=lambda x:x[0])
s = 0
for x,y in D:
    if y-x>=0:
        if s>=x: s+=y-x
        else: print("No"); exit()
if t!=s: print("No")
else: print("Yes")


Measured memory_bytes: 231868
import copy


class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    def __eq__(self, other):
        if other is None or not isinstance(other, Dice):
            return False

        # different left side patterns
        dups = []
        for _ in range(6):
            dups.append(copy.copy(self))
        dups[1].roll('W')
        dups[2].roll('SW')
        dups[3].roll('NW')
        dups[4].roll('E')
        dups[5].roll('WW')

        for dup in dups:
            for _ in range(4):
                dup.roll('N')
                if other.eyes == dup.eyes:
                    return True

        return False

    @property
    def eyes(self):
        return self._eyes[1:6]

    def roll(self, direction_text):
        for d in direction_text:
            self.roll_once(d)

    def roll_once(self, direction):
        a = self._eyes
        if direction == 'N':
            self._eyes = ['dummy', a[2], a[6], a[3], a[4], a[1], a[5]]
        elif direction == 'S':
            self._eyes = ['dummy', a[5], a[1], a[3], a[4], a[6], a[2]]
        elif direction == 'W':
            self._eyes = ['dummy', a[3], a[2], a[6], a[1], a[5], a[4]]
        elif direction == 'E':
            self._eyes = ['dummy', a[4], a[2], a[1], a[6], a[5], a[3]]
        else:
            raise ValueError('NEWS箱推し')


dice1 = Dice(input().split())
dice2 = Dice(input().split())
if dice1 == dice2:
    result = 'Yes'
else:
    result = 'No'
print(result)



Measured memory_bytes: 6312
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]); lines.shift();
    var W = lines.map(i => i);

    var w_counter = {}; var before = W[0][0];
    for (var i = 0; i < N; i++) {
        var word = W[i];

        if (word[0] !== before) { console.log("No"); return (0) }
        if (w_counter[word] !== undefined) { console.log("No"); return (0) }
        
        before = word[word.length - 1];
        w_counter[word] = 1;
    }

    console.log("Yes")
});

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N=26;
	int D;
	cin >>D;
	vector<int> c(N+1, 0);
	Rep1(i, N)
		cin >>c.at(i);
	vector<vector<int>> s(D+1, vector<int> (N+1, 0));
	Rep1(i, D)
		Rep1(j, N)
			cin >>s.at(i).at(j);
	vector<int> t(D+1);
	Rep1(i, D)
		//	cin >>t.at(i);
		t.at(i)=i%26+1;
	//
	vector<vector<int>> LAST(D+1, vector<int> (N+1, 0));
	int S=0;
	vector<vector<int>> SS(D+1, vector<int> (N+1, 0));
	Rep1(i, D) {
		Rep1(j, N) {
			if (j==t.at(i)) {
				LAST.at(i).at(j)=0;
				SS.at(i).at(j)=SS.at(i-1).at(j)+s.at(i).at(j);
				S +=s.at(i).at(j);
			} else {
				LAST.at(i).at(j) =LAST.at(i-1).at(j)+c.at(j);
				SS.at(i).at(j)=SS.at(i-1).at(j)-LAST.at(i).at(j);
			}
			S -=LAST.at(i).at(j);
		}
		//cout <<S <<endl;
	}
	//
	/*
	int SSS=0;
	int M;
	cin >>M;
	Rep1(i, M) {
		int d, q;
		cin >>d >>q;
		int q0=t.at(d);
		S -=SS.at(D).at(q0)+SS.at(D).at(q);
		t.at(d)=q;
		for (auto j=d; j<=D; j++) {
			if (q0==t.at(j)) {
				LAST.at(j).at(q0)=0;
				SSS=SS.at(j-1).at(q0)+s.at(j).at(q0);
			} else {
				LAST.at(j).at(q0)=LAST.at(j-1).at(q0)+c.at(q0);
				SSS=SS.at(j-1).at(q0)-LAST.at(j).at(q0);
			}
			if (SSS==SS.at(j).at(q0))
				break;
			else
				SS.at(j).at(q0)=SSS;
		}
		for (auto j=d; j<=D; j++) {
			if (q==t.at(j)) {
				LAST.at(j).at(q)=0;
				SSS=SS.at(j-1).at(q)+s.at(j).at(q);
			} else {
				LAST.at(j).at(q)=LAST.at(j-1).at(q)+c.at(q);
				SSS=SS.at(j-1).at(q)-LAST.at(j).at(q);
			}
			if (SSS==SS.at(j).at(q))
				break;
			else
				SS.at(j).at(q)=SSS;
		}
		S +=SS.at(D).at(q0)+SS.at(D).at(q);
		cout <<S <<endl;
	}
	*/
	Rep1(i, D)
		cout <<t.at(i) <<endl;
	return 0;
}



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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

string dn = "deficient number";
string pn = "perfect number";
string an = "abundant number";

int main() {

  for (int n;cin>>n,n;) {
    int pr = 1;
    int n0 = n;
    for (int m = 2; m <= n; ++m) {
      int cx = 0;
      while (n % m == 0) {
        n /= m;
        ++cx;
      }
      if (cx > 0) {
        pr *= (pow(m, cx + 1) - 1) / (m - 1);
      }
    }
    if (pr < 2 * n0) {
      cout << dn << endl;
    } else if (pr == 2 * n0) {
      cout << pn << endl;
    } else {
      cout << an << endl;
    }
  }

  return 0;
}

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


int main()
{
    string s;
    int n;
    cin >> s;
    cin >> n;
    int l = s.length();

    string ans ;
    int j = n;
    
    for(int i= 0; i<l; i++){
        if(i%n == 0){
            ans += s[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/* Node treeMinimum(Node x){ */


/* } */

Node treeSearch(Node u, int k){ 
  while(u != NIL && k != u->key){
    if(k < (u->key)) u = u->left;
    else u = u->right;
  }
  return u;
 } 

/* Node treeSuccessor(Node x){ */


/* } */

/* void treeDelete(Node z){ */
/*   Node y; // node to be deleted */
/*   Node x; // child of y */



/* } */

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if((z->key) < (x->key)) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if((z->key) < (y->key)) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char command[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", command);
    if ( command[0] == 'f' ){ 
      scanf("%d", &x); 
      Node t = treeSearch(root, x); 
      if ( t != NIL ) printf("yes\n"); 
      else printf("no\n"); 
    }  
    else if ( command[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( command[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
/*     else if ( command[0] == 'd' ){ */
/*       scanf("%d", &x); */
/*       treeDelete(treeSearch(root, x)); */
/*     } */
  }

  return 0;
}

Measured memory_bytes: 19364
using System;
class Prpgram
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        string[] inputlist = input.Split(' ');
        string A = inputlist[0];
        string B = inputlist[1];
        string C = inputlist[2];


        if (A == B && A == C) Console.Write("No");
        else if (A != B && A != C && B != C) Console.Write("No");
        else if (A == B && A != C) Console.Write("Yes");
        else if (A == C && A != B) Console.Write("Yes");
        else if (B == C && A != B) Console.Write("Yes");
    }
}

Measured memory_bytes: 11092
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        String S = sc.next();
                        for (int i = 0; i < S.length(); i++) {
                                if (i == 5 || i == 13) {
                                        System.out.print(" ");
                                } else {
                                        System.out.print(S.charAt(i));
                                }
                        }
                        System.out.println("");
                }
        }
}

Measured memory_bytes: 9680
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int K;
  cin>>K;
  VEC<int>A={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<A[K-1]<<endl;


  return 0;
}


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

int main()
{
  int x, ans;
  cin >> x;
  x /= 100;
  if (x <= 5)
  {
    ans = 8;
  }
  else if (x <= 7)
  {
    ans = 7;
  }
  else if (x <= 9)
  {
    ans = 6;
  }
  else if (x <= 11)
  {
    ans = 5;
  }
  else if (x <= 13)
  {
    ans = 4;
  }
  else if (x <= 15)
  {
    ans = 3;
  }
  else if (x <= 17)
  {
    ans = 2;
  }
  else if (x <= 19)
  {
    ans = 1;
  }
  cout << ans << endl;
}


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

int numeros[105];

int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>numeros[i];
}
sort(numeros,numeros+n);
cout<<numeros[n-1]-numeros[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
// D - Practical Skill Test
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int H,W,D; cin>>H>>W>>D;

	vector<tuple<int,int,int>> A(H*W+1);//<h,w,distance>

	rp(h,H){
		rp(w,W){
			int a; cin>>a;
			A[a] = make_tuple(h+1,w+1,0);
		}
	}

	for(int pre=1; pre<H*W; ++pre){
		int now = pre + D;
		if(now>H*W) break;
		int hb,wb,d; tie(hb,wb,d)=A[pre];
		int ha,wa; tie(ha,wa,ignore)=A[now];
		d += abs(hb-ha) + abs(wb-wa);
		A[now] = make_tuple(ha,wa,d);
	}

	int Q; cin>>Q;
	while(Q--){
		int l,r; cin>>l>>r;
		int dl; tie(ignore,ignore,dl) = A[l];
		int dr; tie(ignore,ignore,dr) = A[r];
		cout<< dr-dl <<endl;
	}
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    ll n,a,b; std::cin >> n >> a >> b;
    ll buf = n/(a+b);
    std::cout << a*buf + std::min(n%(a+b),a) << "\n";
    return 0;
}


Measured memory_bytes: 256
H = gets.chomp.to_i
mhp = H

def kickTheMonster(mhp)
  hit=0
  if mhp == 1
    hit += 1
  else
    hit += 1
    new_mhp = mhp / 2
    hit += (kickTheMonster(new_mhp) *2)
  end
  return hit
end

puts kickTheMonster(mhp)


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int j=n/2,p=n/2,cnt=1;
    if(n==1){
        cout<<a[0];
        return 0;
    }
    if(n%2==1){
        int p=n-1;
        while(p>=0){
            cout<<a[p]<<" ";
            p-=2;
        }
        p=1;
        while(p<n-1){
            cout<<a[p]<<" ";
            p+=2;
        }
    }else{
        int p=n-1;
        while(p>0){
            cout<<a[p]<<" ";
            p-=2;
        }
        p=0;
        while(p<n-1){
            cout<<a[p]<<" ";
            p+=2;
        }
    }


    return 0;
}


Measured memory_bytes: 2944
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int d[26];

int main(){
    string s;
    cin >> s;
    int n=s.size();
    int r=0,l=0;
    d[s[l]-'a']=l+1;
    while(l<n-1){
        if(l-r<2){
            l++;
            if(d[s[l]-'a']>0){
                cout<<d[s[l]-'a']<<' '<<l+1<<endl;
                return 0;
            }else{
                d[s[l]-'a']=l+1;
            }
        }else{
            d[s[r]-'a']=0;
            r++;
            l++;
            if(d[s[l]-'a']>0){
                cout<<d[s[l]-'a']<<' '<<l+1<<endl;
                return 0;
            }else{
                d[s[l]-'a']=l+1;
            }
        }
    }
    cout<<-1<<' '<<-1<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int H,W;cin >> H >> W;
    int A,B;cin >> A >> B;
    vector<vector<int>> s(H,vector<int>(W));
    rep(i,H)rep(j,W){
        if(i < B){
            if(j < A)s[i][j] = 0;
            else s[i][j] = 1;
        }
        else{
            if(j < A)s[i][j] = 1;
            else s[i][j] = 0;
        }
    }

    rep(i,H){
        rep(j,W)cout << s[i][j];
        cout  << endl;
    }

}

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int res=0;

    for(int i=0;i<s.size();i++){
        for(int j=0;s.size()-j>=1;j++){
            string tmp=s.substr(i,s.size()-j);

            bool flg=true;
            for(int k=0;k<tmp.size();k++){
                string ch=tmp.substr(k,1);
                if(ch != "A" && ch != "C" && ch != "G" && ch != "T") flg=false;
            }
            if(flg) res = max(res,(int)tmp.size());
        }
    }
    p(res)
}

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



int main()
{
    /*
    char x;
    cin>>x;
    char temp = x;
    char b_x = tolower(temp);

    if(b_x==x)
    {
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }
    */
   /*
    int n,k;
    cin>>n>>k;
    vector <int> p(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    int total = 0;
    for(int i=0;i<k;i++)
    {
        total+=p[i];
    }
    cout<<total<<endl;
    */
    /*
    char alpha[26]={'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
    ll n;
    cin>>n;
    ll temp = n;
    int count=0;
    if(n%26==0)
    {
        count--;
    }
    while(temp)
    {
        temp/=26;
        count++;
    }
    */

    int n;
  cin >> n;
  vector<ll> cnt(100005);
  rep(i,n) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  rep(i,100005) tot += i*cnt[i];
 
  int q;
  cin >> q;
  queue <ll> que;
  rep(i,q) {
    int b, c;
    cin >> b >> c;
    tot -= b*cnt[b];
    tot -= c*cnt[c];
    cnt[c] += cnt[b]; cnt[b] = 0;
    tot += b*cnt[b];
    tot += c*cnt[c];
    que.push(tot);
  }

  while(!que.empty())
  {
      cout<<que.front()<<endl;
      que.pop();
  }
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  int k;
  cin>>k;
  if(k==1)
  {
    cout<<(s.size()-1)*9+(s[0]-'0');
    return 0;
  }
  if(k==2)
  {
    int64_t n=s.size();
    int64_t ans=(n-1)*(n-2)/2*81;
    ans+=((s[0]-'0')-1)*(n-1)*9;
    for (int i = 1; i <s.size() ; ++i)
    {
      if(s[i]!='0') 
      {
        ans+=(n-i-1)*9;
        ans+=s[i]-'0';
        cout<<ans;
        return 0;
      }
    }
    cout<<ans;
    return 0;
  }
  else
  {
    int64_t n=s.size();
    int64_t ans=(n-1)*(n-2)*(n-3)/6*729;
    ans+=(s[0]-'0'-1)*81*(n-1)*(n-2)/2;
    for (int i = 1; i < n; ++i)
    {
      if(s[i]!='0')
      {
        ans+=(n-i-1)*(n-i-2)/2*81;
        ans+=(s[i]-'0'-1)*(n-i-1)*9;
        for (int j = i+1; j < n; ++j)
        {
          if(s[j]!='0')
          {
            ans+=(n-j-1)*9;
            ans+=s[j]-'0';
            cout<<ans;
            return 0;
          }
        }
        cout<<ans;
        return 0;
      }
    }
    cout<<ans;
    return 0;
  }
}

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

using namespace std;

const int max_n = 5055, mod = 1000000007;

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

int power(int a, int b) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

int n, m, dp[max_n][max_n], pw[max_n], coef[max_n], rpw[max_n];
int sum[max_n][max_n];

bool get_bit(int mask, int pos) {
    return (mask >> pos) & 1;
}

void prec(int i) {
    for (int j = 0; j < max_n; ++j) {
        sum[i][j] = mul(dp[i][j], pw[j]);
        if (j) {
            sum[i][j] += sum[i][j - 1];
            sum[i][j] %= mod;
        }
    }
}

int solve(int n, int m) {
    memset(dp, 0, sizeof(dp));
    dp[0][m] = 1;
    /*for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i + 1][j] += mul(j + 1, dp[i][j]);
            dp[i + 1][j] %= mod;
            for (int len = 2; len <= j; ++len) {
                dp[i + 1][j - len + 1] += mul(dp[i][j], mul(pw[len - 2], j - len + 1));
                dp[i + 1][j - len + 1] %= mod;
            }
        }
    }*/
    prec(0);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = mul(j + 1, dp[i - 1][j]);
            int add = 0;
            add = sum[i - 1][m] - sum[i - 1][j];
            add += mod;
            add %= mod;
            add = mul(add, rpw[j + 1]);
            for (int len = 2; j + len - 1 <= m; ++len) {
                break;
                add += mul(dp[i - 1][j + len - 1], pw[len - 2]);
                add %= mod;
            }
            dp[i][j] += mul(add, j);
            dp[i][j] %= mod;
        }
        prec(i);
    }
    return accumulate(dp[n] + 1, dp[n] + m + 1, 0LL) % mod;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    pw[0] = 1;
    rpw[0] = 1;
    const int r2 = inv(2);
    for (int i = 1; i < max_n; ++i) {
        pw[i] = mul(2, pw[i - 1]);
        rpw[i] = mul(r2, rpw[i - 1]);
    }
    cin >> n >> m;
    cout << solve(n, m) << endl;
    return 0;
}


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

int main(void) {
	int N;
	vector<int> S;
	cin >> N;
	S.push_back(0);
	for (int i = 0; i < N; i++) {
		char x; cin >> x; 
		if (x == 'W') { S.push_back(S[i]+1); }
		else { S.push_back(S[i]); }
	}

	int ans = N;
	for (int i = 1; i <= N; i++) {
		int kari = S[i-1]+(N-i)-(S[N]-S[i]);
		ans = min(ans, kari);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

// End of template code!
int main() 
{
    buff();
    int n, m;
    cin >> n >> m;
    vi v(n);
    for(int& x : v) cin >> x;
    int total = accumulate(all(v), 0, [&] (int a, int b) { return a + b; } );
    sort(all(v));
    int good = 0;
    int need = total / (4*m) + !!(total % (4*m));
    for(int i = n - 1; i >= 0; --i) {
        if(v[i] >= need) good++;
        else break;
    }
    if(good >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;

int main(){
	fast_io();
	int n,k;
	cin >> n >> k;
	vector<ll> v(n);
	cu(i,0,n)cin >> v[i];
	ll ans = LLONG_MAX;
	cu(i,0,n-k+1){
		ll st = v[i];
		ll nd = v[i + k - 1];
		gmin(ans, nd - st + min(abs(st),abs(nd)));
	}
	cout << ans << '\n';
}



Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
	"strings"
)

var a, b, c string

func main() {
	fmt.Scan(&a, &b, &c)
	a := strings.Split(a, "")
	b := strings.Split(b, "")
	c := strings.Split(c, "")

	var index string = "a"
	for 0 < len(a)+len(b)+len(c) {
		//fmt.Println(a, b, c)

		if index == "a" {
			if len(a) == 0 {
				fmt.Println("A")
				return
			}
			index = a[0]
			a = a[1:]
		} else if index == "b" {
			if len(b) == 0 {
				fmt.Println("B")
				return
			}
			index = b[0]
			b = b[1:]
		} else {
			if len(c) == 0 {
				fmt.Println("C")
				return
			}
			index = c[0]
			c = c[1:]
		}
	}
}

/*  ----------------------------------------  */

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 640
#include<stdio.h>
char s[200010];
char t[200010],d[200010];
int n,q;
int go(int x){
	for(int i=1;i<=q;i++){
		if(t[i]==s[x])x+=(d[i]=='L'?-1:1);
	}
	return x;
}
int main(){
	int i,l,r,mid,res;
	char t1[10],t2[10];
	scanf("%d%d%s",&n,&q,s+1);
	for(i=1;i<=q;i++){
		scanf("%s%s",t1,t2);
		t[i]=t1[0];
		d[i]=t2[0];
	}
	res=n;
	l=1;
	r=n;
	while(l<r){
		mid=(l+r)>>1;
		if(go(mid))
			r=mid;
		else
			l=mid+1;
	}
	if(go(l))l--;
	res-=l;
	l=1;
	r=n;
	while(l<r){
		mid=(l+r)>>1;
		if(go(mid)==n+1)
			r=mid;
		else
			l=mid+1;
	}
	if(go(l)<=n)l++;
	res-=n-l+1;
	printf("%d",res);
}

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

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 200;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3856
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)

a = _I()
s = input()

if a >= 3200:
    print(s)
else:
    print('red')


Measured memory_bytes: 8128
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,y;cin>>n>>y;
    REP(i,n+1){
        REP(j,n-i+1){
            ll money=10000*(n-i-j)+5000*i+1000*j;
            if(money==y){
                cout<<n-i-j<<" "<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;

    /*
    if(n<=a){
        if(a*10000==y){
            cout<<a<<" 0 0"<<endl;
            return 0;
        }else{
            cout<<"-1 -1 -1"<<endl;
            return 0;
        }
    }else if(n<=b){
        REP(i,a+1){
            REP(j,b+1){
                if(i*10000+j*5000==y && i+j==n){
                    cout<<i<<" "<<j<<" 0"<<endl;
                    return 0;
                }
            }
        }
        cout<<"-1 -1 -1"<<endl;
        return 0;
    }else{
        REP(i,a+1){
        if(i*10000>y)break;
        REP(j,b+1){
            if(i*10000+j*5000>y)break;
            REP(k,c+1){
                if(i*10000+j*5000+k*1000>y)break;
                ll money=i*10000+j*5000+k*1000;
                ll bill=i+j+k;
                if(money==y && bill==n){
                    cout<<i<<" "<<j<<" "<<k<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
    }
    */
}


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

Measured memory_bytes: 3620
/*
a1b1 a1b2 a1b3
a2b1 a2b2 a2b3
a3b1 a3b2 a3b3


*/

#include <iostream>
using namespace std;
 
int main() {
    int G[3][3];
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
        	cin >> G[i][j];
        }
    }
    //for (int i = 0; i < 3; ++i) {
    //    for (int j = 0; j < 3; ++j) {
    //    	cout << G[i][j];
    //    }
    //}
    bool flag = false;
    for (int a1 = 0; a1 < 100; ++a1) {
    	int b1 = G[0][0] - a1;
    	int b2 = G[0][1] - a1;
    	int b3 = G[0][2] - a1;
    	int a2 = G[1][0] - b1;
    	int a3 = G[2][0] - b1;
    	// cout << a1 << endl;
    	if (a2+b2==G[1][1] & a2+b3==G[1][2] & a3+b2==G[2][1] & a3+b3==G[2][2]){
    	     flag = true;
    	     break;
    	}
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
fn main() {
    let mut bingo = read_vec2::<i32>(3);
    let n = read::<usize>();
    for _ in 0..n {
        let b = read::<i32>();

        for i in 0..3 {
            for j in 0..3 {
                if bingo[i][j] == b {
                    bingo[i][j] = -1;
                }
            }
        }
    }

    for i in 0..3 {
        if bingo[i][0] == -1 && bingo[i][1] == -1 && bingo[i][2] == -1 {
            println!("Yes");
            return
        }
        if bingo[0][i] == -1 && bingo[1][i] == -1 && bingo[2][i] == -1 {
            println!("Yes");
            return
        }
    }

    if bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1 {
        println!("Yes");
        return
    }
    if bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1 {
        println!("Yes");
        return
    }

    println!("No");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	const int N = 5;
	int A[N];

	int index = 0;
	int d = 9;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];

		if (A[i] % 10 != 0 && A[i] % 10 < d)
		{
			d = A[i] % 10;
			index = i;
		}
	}

	int ans = A[index];
	for (int i = 0; i < N; i++)
	{
		if (index == i) continue;

		if (A[i] % 10 == 0)
		{
			ans += A[i];
		}
		else
		{
			ans += (A[i] / 10) * 10 + 10;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int c = 0;
    for (int i = 1, j; i <= N; ++i) {
        cin >> j;
        if (i != j) ++c;
    }
    cout << (c > 2 ? "NO" : "YES") << endl;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

type Pair struct {
  Value int
  Index int
}

type Pairs []Pair

func (p Pairs) Len() int { return len(p) }
func (p Pairs) Less(i, j int) bool { return p[i].Value < p[j].Value }
func (p Pairs) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

func main() {
  var N int
  fmt.Scan(&N)
  A := make([]Pair, N)
  var a int
  for i := range A {
    fmt.Scan(&a)
    A[i] = Pair{a, i}
  }
  sort.Sort(Pairs(A))
  cnt := 0
  for i, a := range A {
    if i % 2 == 0 && a.Index % 2 == 1 {
      cnt += 1
    }
  }
  fmt.Println(cnt)
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong mpow(llong n, llong m) {
	if (n == 1)
		return m;

	llong ret = mpow(n/2, m);
	ret = ret * ret % mod;
	if (n&1)
		ret = ret*m%mod;

	return ret;
}

llong ncr(llong n, llong r) {
	llong ret = 1;
	for (int i = 1; i <= r; i++) {
		ret = ret * (n-i+1) % mod;
		ret = ret * mpow(mod-2, i) % mod;
	}

	return ret;
}

int main() {
	llong N, M, K;
	cin >> N >> M >> K;

	llong ans = 0;
	for (int i = 1; i <= N-1; i++) {
		ans = (ans + i * (N-i)*M*M)%mod;
	}
	for (int i = 1; i <= M-1; i++) {
		ans = (ans + i * (M-i)*N*N)%mod;
	}

	cout << ans * ncr(N*M-2, K-2) % mod << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int a[10000], min, max, n, i;
  long long sum = 0;
  scanf("%d", &n);//1??\????????\????????????????????¨?????????
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  max = min = a[0];//??¨?????????????????????????´?????????????????????????
  for(i = 1; i < n; i++){//2????????\??????????´???¨??????
    if(a[i] > max)max = a[i];
    if(a[i] < min)min = a[i];
  }
  printf("%d %d %lld\n", min, max, sum);

return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;
int N,K,S;
int X[3][2000];
struct UF{
	int N;
	vector<int>p,sz;
	UF(int n):N(n),p(n),sz(n,1){
		for(int i=0;i<N;i++)p[i]=i;
	}
	int find(int u)
	{
		if(p[u]==u)return u;
		else return p[u]=find(p[u]);
	}
	bool unite(int u,int v)
	{
		u=find(u),v=find(v);
		if(u==v)return false;
		if(sz[u]<sz[v])
		{
			p[u]=v;
			sz[v]+=sz[u];
		}
		else
		{
			p[v]=u;
			sz[u]+=sz[v];
		}
		return true;
	}
};
vector<long>A;
bool dfs(int u,int p,int out,vector<vector<pair<int,long> > >&G)
{
	if(u==out)
	{
		return true;
	}
	bool ret=false;
	for(pair<int,long>&q:G[u])
	{
		if(q.first!=p)
		{
			A.push_back(q.second);
			ret|=dfs(q.first,u,out,G);
		}
	}
	return ret;
}
main()
{
	while(cin>>N>>K>>S,N)
	{
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<3;j++)cin>>X[j][i];
		}
		vector<pair<pair<int,int>,long> >E;
		UF uf(N);
		vector<vector<pair<int,long> > >G(N);
		for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
		{
			int d[3];
			bool flag=true;
			for(int k=0;k<3;k++)
			{
				d[k]=S-abs(X[k][i]-X[k][j]);
				if(d[k]<=0)flag=false;
			}
			if(flag)
			{
				long t=d[0]*d[1]+d[1]*d[2]+d[2]*d[0];
				t*=2;
				E.push_back(make_pair(make_pair(i,j),t));
				uf.unite(i,j);
				G[i].push_back(make_pair(j,t));
				G[j].push_back(make_pair(i,t));
			}
		}
		long ans=-1;
		vector<bool>vis(N,false);
		for(int i=0;i<N;i++)
		{
			int u=uf.find(i);
			if(uf.sz[u]<K)vis[u]=true;
			if(vis[u])continue;
			A.clear();
			vis[u]=true;
			bool flag=false;
			for(pair<int,long>&q:G[u])
			{
				A.push_back(q.second);
				if(dfs(q.first,u,u,G))
				{
					flag=true;
					break;
				}
				reverse(A.begin(),A.end());
			}
			if(flag)
			{
				int n=A.size();
				for(int i=0;i<n;i++)A.push_back(A[i]);
			}
			int get=flag&&uf.sz[u]==K?K:K-1;
			vector<long>sum(A.size()+1,0);
			for(int i=0;i<A.size();i++)sum[i+1]=sum[i]+A[i];
			for(int i=get;i<=A.size();i++)ans=max(ans,sum[i]-sum[i-get]);
		}
		if(ans<0)cout<<-1<<endl;
		else cout<<6LL*S*S*K-ans<<endl;
	}
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long a, b;

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

	string A = "";
	string B = "";

	rep(i, a) {
		A += ('0' + b);
	}
	rep(i, b) {
		B += ('0' + a);
	}
	if(A < B) {
	cout << A << endl;
	} else {
	cout << B << endl;
	}

}

Measured memory_bytes: 3556
#include<stdio.h>
#define N 1000

char map[1001][1001];

int main(){
  int n,i,j,k,l,max,e;
  while(1){
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%s",map+i);
      map[i][n]='*';
    }
    for(i=0;i<n;i++) map[n][i]='*';
    for(i=0,max=0;i<n-max;i++){
      for(j=0;j<n-max;j++){
	if(map[i][j]=='.'){
	  for(k=2;1;k++){
	    for(l=0;l<k;l++){
	      if(map[k-1+i][l+j]=='*'||map[l+i][k-1+j]=='*') goto find;
	    }
	  }
	find:
	  k--;
	  if(max<k) max=k;
	}
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    string s; int k;
    while (cin >> s >> k) {
        const int n = s.size();
        char pre = 0; int first = 0, last = 0;
        vector<LL> cnt;
        for (int i = 0; i < n; ) {            
            while (i < n && s[i] == s[pre])
                i++;
            cnt.push_back(i-pre);
            pre = i;
        }
        LL ans = 0;
        if (cnt.size() == 1)
            ans = cnt[0]*k/2;
        else {
            FOR(i,1,cnt.size()-1) 
                ans += cnt[i]/2 * k;
            if (s[0] == s.back()) {
                ans += (cnt[0]+cnt.back())/2 * (k-1);
                ans += cnt[0]/2;
                ans += cnt.back()/2;
            }
            else {
                ans += cnt[0]/2 * k;
                ans += cnt.back()/2 * k;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int n, T;
  cin >> n >> T;
  map<int, int> data;
  for(int i = 0; i < n; i++){
    int c, t;
    cin >> c >> t;
    data[c] = t;
  }
  int cost = 2000;
  for(auto x : data){
    auto a = x.first;
    auto b = x.second;
    if(b <= T && a < cost){
      cost = a;
    }
  }
  if(cost != 2000){
    cout << cost << endl;
  }
  else{
    cout << "TLE" << endl;
  }
}


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

using namespace std;

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

  string a, b, c;
  cin >> a >> b >> c;
  char card = 'a';
  int ia = 0, ib = 0, ic = 0;
  string res;
  while (true) {
    if (card == 'a') {
      if (ia == a.size()) {
        res = "A";
        break;
      }
      card = a[ia++];
    } else if (card == 'b') {
      if (ib == b.size()) {
        res = "B";
        break;
      }
      card = b[ib++];
    } else {
      if (ic == c.size()) {
        res = "C";
        break;
      }
      card = c[ic++];
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256