akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	ans := ""
	for i := 0; i < n; i++ {
		ans += "ACL"
	}

	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 1740
import sys


def recursion_g(eges, length, f):
    if length[f] != -1:
        return length[f]
    memo = [0]
    for t in eges[f]:
        memo.append(recursion_g(eges, length, t) + 1)
    length[f] = max(memo)
    return length[f]


def p_g():
    sys.setrecursionlimit(10 ** 6)
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]
    length = [-1] * N
    for _ in range(M):
        x, y = map(int, input().split())
        edges[x - 1].append(y - 1)

    for i in range(N):
        recursion_g(edges, length, i)
    print(max(length))


if __name__ == '__main__':
    p_g()


Measured memory_bytes: 65968
import java.util.Scanner;

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

        int n = sc.nextInt();

        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            int tmp = sc.nextInt();
            if (i != tmp)
                cnt++;
        }

        if (cnt <= 2)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 21840
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <tuple>

using namespace std;

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int>x(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	int t = 0;
	for (int i = 1; i < n - 1; ++i)
	{
		if (x[i] > x[i - 1] && x[i] < x[i + 1])
		{
			t++;
		}
		else
		{
			if (x[i] < x[i - 1] && x[i] > x[i + 1])
			{
				t++;
			}
		}
	}
	cout << t;
	return 0;
}

Measured memory_bytes: 256
import sys


def test():
    a = (input())
    b = (input())
    a_l, b_l = len(a), len(b)
    if a_l < 0 and a_l >= 10 or not (a.islower() or b.islower() or a.isalpha() or b.isalpha()):
        print('No')
        sys.exit()

    if b_l - a_l == 1 and a == b[:a_l]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    test()


Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
bool vis[100005];
int main()
{
	memset(vis,0,sizeof(vis));
	IO;
	int n,m;
	cin>>n>>m;
	if(n&1){
		for(int i=1;i<=n&&m;i++,m--){
			cout<<i<<" "<<n-i<<endl;
		}
		return 0;
	}
	int l=(n+1)/2;
	
	for(int i=1;i<=l/2&&m;i++,m--){
		cout<<i<<" "<<l-i+1<<endl;
	}
	
	for(int i=1;m;i++,m--){
		cout<<i+l<<" "<<n-i<<endl;
	}
	
 	return 0;
}







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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  double n, d;
  cin >> n >> d;

  cout << ceil(double(n/(2*d+1)));
}

Measured memory_bytes: 3796
use std::io::*;//Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let a:i32 = read();
    let b:i32 = read();
    let c:i32 = read();
    println!("{}",a * b * c / std::cmp::max(a,std::cmp::max(b,c)) / 2);
}

Measured memory_bytes: 4476
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;   
typedef unsigned long long ull;
inline long long read()//inline 加速读入
{
	long long x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
 inline void write(ll x)
 {
     char F[200];
      int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
            F[cnt++]=tmp%10+'0';
            tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
 }
int NOf1(int n) 
{

	int c=0;
	for(int i = 0; i < 32; ++i){
		if(n & 1)
			++c;
		n >>= 1;
	}
	return c;
}
int gcd(int x, int y)
 {
     int MAX = max(x, y);
     int MIN = min(x, y);
     return MAX % MIN == 0? MIN : gcd(MIN, MAX % MIN);
 }
struct haha{
	int k,v;
}p[300006];
int cmp(haha x,haha y)
{
	return x.v>y.v;
}
int x,y,a,b,c;
int main() {
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		p[i].v=read();
		p[i].k=1;
	}
	for(int i=a+1;i<=a+b;i++)
	{
		p[i].v=read();
		p[i].k=2;
	}
	for(int i=a+b+1;i<=a+b+c;i++)
	{
		p[i].v=read();
		p[i].k=3;
	}
	sort(p+1,p+1+a+b+c,cmp);
	ll aum=0,ans=0,xx=0,yy=0,zz=0;
	for(int i=1;i<=a+b+c;i++)
	{
		if(p[i].k==1)
		{
			if(xx==x)continue;
			xx++;
		}
		else if(p[i].k==2)
		{
			if(yy==y)continue;
			yy++;
		}
		aum++;
		ans+=p[i].v;
		if(aum==x+y)break;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int N,A,B; cin >>N >>A >>B;
  int q1=0,q2=0,q3=0;
  rep(i,0,N) {
    int P; cin >>P;
    if (P<=A) {
      q1++;
    } else if (A<P and P<=B) {
      q2++;
    } else {
      q3++;
    }
  }
  cout <<min({q1,q2,q3}) <<endl;
  return 0;
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.A
{
    public class Program
    {
        public static string S { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            S = CR.GetText();
            switch (S)
            {
                case "AAA": return "No";
                case "AAB": return "Yes";
                case "ABA": return "Yes";
                case "BAA": return "Yes";
                case "ABB": return "Yes";
                case "BAB": return "Yes";
                case "BBA": return "Yes";
                case "BBB": return "No";
                default:
                    return "";
            }
        }
    }
}


Measured memory_bytes: 13152
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    char[] s = scanner.next()
        .toCharArray();
    Set<String> done1 = new HashSet<>();
    Set<String> done2 = new HashSet<>();
    Set<String> done3 = new HashSet<>();

    for (int i = 0; i < s.length - 2; i++) {
      if (done1.contains(String.valueOf(s[i]))) {
        continue;
      } else {
        done1.add(String.valueOf(s[i]));
      }
      for (int j = i + 1; j < s.length - 1; j++) {
        if (done2.contains(s[i] + String.valueOf(s[j]))) {
          continue;
        } else {
          done2.add(s[i] + String.valueOf(s[j]));
        }
        for (int k = j + 1; k < s.length; k++) {
          done3.add(s[i] + String.valueOf(s[j]) + s[k]);
        }
      }
    }
    System.out.println(done3.size());
  }
}


Measured memory_bytes: 155280
#include <bits/stdc++.h> 
#include <string.h> 
  
using namespace std; 
// A utility function to find factorial of n 
int fact(int n) 
{ 
    return (n <= 1) ? 1 : n * fact(n - 1); 
} 
  
// A utility function to count smaller characters on right 
// of arr[low] 
int findSmallerInRight(int* str, int low, int high) 
{ 
    int countRight = 0, i; 
  
    for (i = low + 1; i <= high; ++i) 
        if (str[i] < str[low]) 
            ++countRight; 
  
    return countRight; 
} 
  
// A function to find rank of a string in all permutations 
// of characters 
int findRank(int* str, int n) 
{ 
    int len = n; 
    int mul = fact(len); 
    int rank = 1; 
    int countRight; 
  
    int i; 
    for (i = 0; i < len; ++i) { 
        mul /= len - i; 
  
        // count number of chars smaller than str[i] 
        // fron str[i+1] to str[len-1] 
        countRight = findSmallerInRight(str, i, len - 1); 
  
        rank += countRight * mul; 
    } 
  
    return rank; 
} 
  
// Driver program to test above function 
int main() 
{ 
    int n;
    cin>>n;
    int str[n],bstr[n]; 
    for(int i=0;i<n;i++){
        cin>>str[i];
    }
    for(int i=0;i<n;i++){
        cin>>bstr[i];
    }
    int a= findRank(str,n); 
    int b= findRank(bstr,n);
    cout<<abs(b-a);
    return 0; 
} 
  

Measured memory_bytes: 3448
#coding:utf-8
import sys
 
WHxyr=sys.stdin.readline()
nums=WHxyr.split( ' ' )
for i in range( len( nums) ):
	nums[i] = int( nums[i] )
if (0 <= nums[2]-nums[4]) and (nums[2]+nums[4] <= nums[0]) and (0 <= nums[3]-nums[4]) and (nums[3]+nums[4] <= nums[1]):
	print( "Yes" )
else:
	print( "No" )

Measured memory_bytes: 6724
S = str(input())
Q = int(input())
st = [0] * Q
n = [0] * Q
p = 0
s_h = 0
for i in range(Q):
  q = str(input())
  if int(q[0]) == 1:#Ti = 1
    s_h += 1
  else:
    if int(q[2]) == 1:#先頭
      st[p] = q[4]
      n[p] = s_h
      p += 1
    else:
      st[p] = q[4]
      n[p] = s_h + 1
      p += 1

odd = ["".join(st[a]) for a in range(Q) if ((n[a] + s_h) % 2 == 1) and (str(st[a]) != "0")]
odd = "".join(odd)
even =  ["".join(st[a]) for a in range(Q) if ((n[a] + s_h) % 2 == 0) and (str(st[a]) != "0")]
even = "".join(even)[::-1]
if s_h % 2 == 1:
  S = S[::-1]

b = [even, S, odd]
#print(S,odd,even)
print("".join(b))

Measured memory_bytes: 10772
#include <iostream>
#include <utility>
#include <algorithm>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include <math.h>
#include <map>
#include <vector>
#include <iomanip>
#include <set>
#include <deque>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const int N = 2e6, PI = 3.14159265359, M = 1e9 + 7;
typedef pair <ll, ll> pii;
map <ll, ll> dp;
ll a[N], ans = 0;
map <pii, ll> ma;

int main() {
	ll n, sum = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		sum += y;
		a[i] = x + y;
	} 
	sort(a, a + n);
	ll r = n / 2, t = 0;
	for(int i = n - 1; i >= 0; i -= 2)
		t += a[i];
	cout << -1 * (sum - t);
}

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

struct RUP{
  int n;
  vector<int> dat,laz;
  const int def=INT_MAX;
  RUP(){}
  RUP(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
    laz.clear();
    laz.resize(2*n-1,-1);
  }
  inline void eval(int len,int k){
    if(laz[k]<0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=laz[k];
      laz[k*2+2]=laz[k];
    }
    dat[k]=laz[k];
    laz[k]=-1;
  }
  int update(int a,int b,int x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b) return laz[k]=x;
    eval(r-l,k);
    dat[k]=min(update(a,b,x,k*2+1,l,(l+r)/2),
           update(a,b,x,k*2+2,(l+r)/2,r));
    return dat[k];
  }
  int query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  void update(int a,int b,int x){
    update(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};

int N,Q;
int S[200010],T[200010],X[200010];
map<int,int> m;
int main(){
    cin >> N >> Q;
    vector<pair<int,int>> K;
    for(int i=1;i<=N;i++){
        cin >> S[i] >> T[i] >> X[i];
        K.push_back({X[i],i});
    }
    sort(K.begin(),K.end(),greater<pair<int,int>>());
    vector<int> D(Q+1,-INT_MAX);
    for(int i=1;i<=Q;i++){
        cin >> D[i];
        m[D[i]] = i;
    }
    RUP seg(Q+1);
    for(int i=0;i<N;i++){
        int id = K[i].second;
        int id1 = lower_bound(D.begin(),D.end(),S[id]-X[id])-D.begin();
        int id2 = lower_bound(D.begin(),D.end(),T[id]-X[id])-D.begin();
        seg.update(id1,id2,X[id]);
    }
    for(int i=1;i<=Q;i++){
        int num = seg.query(m[D[i]],m[D[i]]+1);
        cout << (num!=INT_MAX? num:-1) << endl;
    }
}

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

namespace AtCoderCs
{
    class Program
    {
        static void Main(string[] args)
        {

            var num = int.Parse(Console.ReadLine());
            var collection = new Dictionary<string, int>();
            StringComparer cmp = StringComparer.OrdinalIgnoreCase;

            for (int i = 0; i < num; ++i)
            {

                var str = Console.ReadLine();

                if (collection.ContainsKey(str))
                    collection[str] += 1;
                else collection.Add(str, 1);

            }

            int max = 0;
            collection.ToList().ForEach(x =>
            {

                if (x.Value > max) max = x.Value;

            });

            var Strings = collection.Where(Pair => Pair.Value == max).Select(Pair => Pair.Key);

            var Result = Strings.ToArray();
            Array.Sort(Result, cmp);

            foreach (var @string in Result)
            {

                Console.WriteLine(@string);

            }
            return;

        }
    }
}

Measured memory_bytes: 45552
#include<iostream>

using namespace std;

int main() {
	int a,b;
	char c;
	cin >> a >> b;
	int x[a];
	int m,n,p;
	for(int i = 0;i<a;i++){
		x[i] = i+1;
	}

	for(int j = 0;j<b;j++){
		cin >> n >> c >> m;
		m--;
		n--;
		p = x[m];
		x[m] = x[n];
		x[n] = p;
	}
	for(int k = 0;k<a;k++){
		cout << x[k] << endl;
	}


	return 0;
}



Measured memory_bytes: 3044
#include <iostream>

using namespace std;

int dp[1024][500];

int main(){
  int n, s;
  dp[0][0] = 1;
  for(int i=0;i<350;i++){
    for(int j=0;j<1024;j++){
      int cnt = 1;
      for(int k=0;k<10;k++)
        if(j&(1<<k)) cnt++;
      for(int k=0;k<10;k++){
        if(j&(1<<k)) continue;
        dp[j|(1<<k)][i+cnt*k] += dp[j][i];
      }
    }
  }
  while(cin >> n >> s){
    int res = 0;
    for(int i=0;i<1024;i++){
      if(s > 400) continue;
      int c = 0;
      for(int j=0;j<10;j++)
        if(i&(1<<j)) c++;
      if(c==n) res += dp[i][s];
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 0
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string s;
  cin >> s;
  int ans = 0;
  fore(i, 0, SZ(s)) {
    ans += (s[i] - '0');
  }
  ans %= 9;
  if (ans == 0)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}

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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<tuple<int, int, int, int>> o;
	int y = 0;
	for (int i = 0; i < h; i++) {
		int x = 0;
		for (int j = 0; j < w; j++) {
			int a;
			scanf("%d", &a);
			if (x & 1) o.emplace_back(i + 1, j, i + 1, j + 1);
			x ^= a;
		}
		if (y & 1) o.emplace_back(i, w, i + 1, w);
		y ^= x;
	}
	cout << o.size() << '\n';
	for (auto t : o)
		cout << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t) << ' ' << get<3>(t) << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 4208
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = [], []
for i in range(m):
    a,b = MAP()
    l.append(a)
    r.append(b)

max_l = max(l)
min_r = min(r)
if min_r<max_l:
    print(0)
    exit()
print(min_r-max_l+1)

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

int main(){
  int n;
  cin>>n;
  vector<int> arr(n+1,0);
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        int v=i*i+j*j+k*k+i*j+j*k+k*i;
        if(v>n) break;
        arr[v]+=1;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<arr[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100001;

string s;
int arr[N];
int sum[N];
bool check(int len){
  int lst = s.size() - len;
  for(int j = lst + 1;j <  len;j++){
    int a = j - len + 1;
    int b = j - 1;
    a = max(a, 0);
    b = min(b, lst);
//    cout << j << ' ' << a << ' ' << b << endl;
    if((sum[b] - (a ? sum[a - 1] : 0)) % 2 != arr[j])
      return 0;
  }
  return 1;
}
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> s;
  for(int i = 0;i < s.size();i++)
    arr[i] = s[i] - '0';

  sum[0] = arr[0];
  for(int i = 1;i < s.size();i++)
    sum[i] = (arr[i] != arr[i - 1] ? 1 : 0) + sum[i - 1];
  int lo = 1, hi = s.size();
  while(lo < hi){
    int mid = (lo + hi + 1) / 2;
    if(check(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo;
  return 0;
}


Measured memory_bytes: 1280
N, T = map(int, input().split())
A = list(map(int, input().split()))
M, m, ans = 0, A[0], 0
for i in range(1, N):
    if M < A[i] - m:
        M = A[i] - m
        ans = 1
    elif M == A[i] - m:
        ans += 1
    if A[i] < m:
        m = A[i]
print(ans)


Measured memory_bytes: 62704
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if n != '' and n[0] == '0':
        return
    if n != '' and int(n) >= ans:
        return
    if len(n) >= len(str(N)):
        if int(n) >= N:
            ans = int(n)
    for l in L:
        dfs(n + str(l))


dfs('')
print(ans)

Measured memory_bytes: 44892
from itertools import permutations as pm
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
y,ans = [i for i in range(n)],0
for i in pm(y):
    for j in range(n-1): ans+=((x[i[j]][0]-x[i[j+1]][0])**2+(x[i[j]][1]-x[i[j+1]][1])**2)**0.5
num = 1
for i in range(n): num*=(i+1)
print(ans/num)

Measured memory_bytes: 3188
n = int(input())
h = list(map(int, input().split()))

dp = [float("inf")] * 110000
dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if n - 2 > i:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[n-1])

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    double gokei = 0;
    REP(i, n) cin >> a[i];
    REP(i, n) gokei += a[i];
    gokei /= (double)n;
    double max_ = INF;
    int ans;
    REP(i, n) {
        //cout << abs(gokei - a[i]) << endl;
        if(abs(gokei - a[i]) < max_) {
            max_ = abs(gokei - a[i]);
            ans = i;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int ans=0; string s,t; cin>>s>>t;
  rep(i,3){
    if(s[i]==t[i]){
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int N=2e5+10;
int n,A,B,C,D;
char s[N];
bool check(int l,int r){if(l>r)return 0;
	int lst=l;
	for(int i=l+1;i<=r;i++){
		if(s[i]=='.'&&i-lst<=2) lst=i; 
	}return lst==r;
}
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d%d%d%d%d%s",&n,&A,&B,&C,&D,s+1);
	if(!check(A,C)||!check(B,D)){puts("No");return 0;}
	if(C<D){puts("Yes");return 0;}
	bool ok=0;
	if(check(A,B-1)){
		for(int i=B-1;i<=min(D-1,C);i++)if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')ok=1;}else{
		for(int i=B;i<=min(D-1,C);i++)if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')ok=1;
	}
	if(ok)puts("Yes");else puts("No");
}

Measured memory_bytes: 384
init = list(input().split() for _ in range(3))

flag = 0

n = int(input())


for i in range(n):
    num = int(input())
    for j in range(3):
        for l in range(3):
            if(int(init[j][l]) == num):
                init[j][l] = 0

for i in range(3):
    if(init[1][i] == init[2][i] == init[0][i] == 0):
        flag = 1

for i in range(3):
    if(init[i][1] == init[i][2] == init[i][0] == 0):
        flag = 1


if(init[0][0] == init[1][1] == init[2][2] == 0):
    flag = 1
    
if(init[0][2] == init[1][1] == init[2][0] == 0):
    flag = 1


if(flag == 1):
    print("Yes")
else:
    print("No")

#print(init)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
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(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <class T> struct BIT {
    vector<T> dat;

    BIT(int n) {
        dat.resize(n + 1);
        for(int i = 0; i < (int)dat.size(); i++)
            dat[i] = 0;
    }
    BIT(vector<T> &vec) {
        dat.resize(vec.size() + 1);
        for(int i = 0; i < vec.size(); i++) {
            add(i + 1, vec[i]);
        }
    }

    // a is 1-indexed
    void add(int a, T x) {
        for(int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    // [1,a], a is 1-indexed
    T sum(int a) {
        T res = 0;
        for(int i = a; i > 0; i -= i & -i) {
            res = res + dat[i];
        }
        return res;
    }

    // [a,b), a and b are 1-indexed
    T sum(int a, int b) { return sum(b - 1) - sum(a - 1); }

    // k-th number (k is 1-indexed)
    // lower_bound
    int get(int k) {
        if(k <= 0)
            return 0;
        int res = 0;
        int N = 1;
        while(N < (int)dat.size())
            N *= 2;
        for(int i = N / 2; i > 0; i /= 2) {
            if(res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    BIT<ll> bit(A);
    rep(i, Q) {
        int q;
        cin >> q;
        if(q == 0) {
            int p, x;
            cin >> p >> x;
            bit.add(p + 1, x);
        } else {
            int l, r;
            cin >> l >> r;
            l++, r++;
            cout << bit.sum(l, r) << endl;
        }
    }
}

Measured memory_bytes: 12144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,s=0,x,i,j,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
              x=__gcd(i,j);
              x=__gcd(x,k);
              s=s+x;
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3620
import math
def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
n=int(input())
a=list(map(int,input().split()))
ans=computeGCD(a[0],a[1])
for i in range(2,n):
  ans=computeGCD(ans,a[i])
print(ans)

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

int main(){
    int N;
    int count = 0;
    int ans = 0;
    char tmp;
    std::cin >> N;
    vector<char> stones(N);
    for(int i = 0; i < N; i++){
        std::cin >> tmp;
        stones[i] = tmp;
        if(tmp == 'R'){
            count++;
        }
    }

    for(int i = 0; i < count; i++){
        if(stones[i] == 'W'){
            ans++;
        }
    }

    std::cout << ans;

}

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

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<pair<long long, int> > v;
    for (long long i = 0; i * i * i * i * i <= 4e18; ++i) {
        v.push_back({i * i * i * i * i, i});
        v.push_back({-i * -i * -i * -i * -i, -i});
    }
    for (int i = 0; i < (int)v.size(); ++i) {
        for (int j = 0; j < (int)v.size(); ++j) {
            if(v[i].first + v[j].first == n) {
                return cout << v[i].second << " " << -v[j].second << "\n",0;
            }
        }
    }
    return 0;
}


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

int main(){
 	int N,ans(0);
    double T,A;
  	cin >> N >> T >> A;
  	vector<double> H(N);
  	for(int i = 0 ; i < N ; i ++){
      	cin >> H[i];
      	if(abs(A - (T - H[ans] * 0.006)) > abs(A - (T - H[i] * 0.006)) &&  i) ans = i;
    }
  	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int sq=10000;
const int mod=1e9+7;
int n,k,fac[400001],inv[400001];
#define inc(x,y) x+=y,x>=mod?x-=mod:0
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
inline int C(int x,int y) {
	if(x<y||x<0||y<0) return 0;
	return (ll)fac[x]*inv[x-y]%mod*inv[y]%mod;
}
int main()
{
	read(n),read(k),fac[0]=1;
	for(res i=1;i<=n*2;++i) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n*2]=kuai(fac[n*2],mod-2,mod);
	for(res i=2*n-1;~i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	if(k>=n-1) return print((ll)kuai(2,mod-2,mod)*C(2*n,n)%mod,'\n'),0;
	int tot=1;
	for(res i=1;i<=k;++i) inc(tot,(ll)C(n-1,n-i-1)*C(n,i)%mod);
	print(tot,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 3328
N = 5
ARR = [24, 11, 8, 3, 16]


N = 4
ARR = [5, 5, 5, 5]


N = 10
ARR = [33, 18, 45, 28, 8, 19, 89, 86, 2, 4]

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

def calculate(n, arr):

    prr = [0 for i in range(2000005)]

    for i in range(n):
        start = arr[i]
        #
        if prr[start] > 0:
            prr[start] = 2
            continue

        for j in range(start, 2000005, start):
            prr[j] = prr[j] + 1


    result = 0
    for i in range(n):
        start = arr[i]
        if prr[start] == 1:
            result += 1


    print(result)

calculate(N, ARR)


Measured memory_bytes: 36436
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
  string S;
  cin >> S;
  int k, t;
  k=S.size();
  t=0;
  for (int i=0; i<k; i++) {
    if (S[i]=='o') {
      t=t+1;
    }
  }
  if (t-k+7>=0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> VE(N);
    for(int i=0;i<N;i++){
        cin >> V.at(i);
        VE.at(i) = V.at(i);
    }

    sort(VE.begin(),VE.end());
    int count = 0;
    for (int j = 0;j<N;j++){
        if (V.at(j)!=VE.at(j)){
            count++;
        }
    }

    if (count<=2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  std::sort(va.begin(), va.end());

  std::vector< std::pair<ll, ll> > vans;
  ll ans = 0LL;
  if (va[0] >= 0) {
    for (ll i=1; i < N-1; i++){
      vans.push_back({va[0], va[i]});
      va[0] -= va[i];
    }
    vans.push_back({va[N-1], va[0]});
    ans = va[N-1] - va[0];
  } else if (va[N-1] <= 0) {
    for (ll i = N-2; i >= 0; i--) {
      vans.push_back({va[N-1], va[i]});
      va[N-1] -= va[i];
    }
    ans = va[N-1];
  } else {
    for (ll i = 1; i < N-1; i++) {
      if (va[i] >= 0) {
	vans.push_back({va[0], va[i]});
	va[0] -= va[i];
      }
    }
    for (ll i = 0; i < N-1; i++) {
      if (va[i] < 0) {
	vans.push_back({va[N-1], va[i]});
	va[N-1] -= va[i];
      }
    }
    ans = va[N-1];
  }

  print(ans);
  for (auto& p : vans) { print(p.first, p.second); }
  return 0;
}


Measured memory_bytes: 4336
import sys
s = str(input())
t = str(input())
sl = list(s)
tl = list(t)
sl.sort()
tl.sort()
tl = tl[::-1]
a = "".join(sl)
b = "".join(tl)
if a == b:
    print("No")
    sys.exit()
ls = [a,b]
new = sorted(ls)
if ls[0] == new[0]:
    print("Yes")
else:
    print("No")

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

int main(void){

  string s;
  int cnt;
  int i;
  
  cin >> s;
  
  cnt = 0;

  if (s == "RRR")
  {
    cout << 3;
    return 0;
  }
  
  if (s == "RRS" || s == "SRR")
  {
    cout << 2;
    return 0;
  }
  
  if (s == "RSR" || s == "RSS" || s == "SSR" || s == "SRS")
  {
    cout << 1;
    return 0;
  }

  cout << 0;
  return 0;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll comb(ll a, ll b);
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
   int n;
   int k;
   cin>>n>>k;
   vector<int>h(n);
   rep(i, n)cin>>h[i];
   vector<int>dp(n+k,INF);
   dp[0]=0;
   rep(i,n){
       rep(j,k+1){
           dp[i+j]=min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
       }
   }
   c(dp[n-1]);
    return 0;
}


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

using int64 = long long;
using uint64 = unsigned long long;

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

    int N;
    cin >> N;

    string S;
    cin >> S;

    map<pair<string, string>, int64> counter;
    // 先頭N文字のうち、どれを赤に塗るか
    for (int mask = 0; mask < (1 << N); mask++)
    {
        string red = "", blue = "";
        for (int i = 0; i < N; i++)
        {
            if ((mask >> i) & 1) red.push_back(S[i]);
            else blue.push_back(S[i]);
        }
        reverse(blue.begin(), blue.end());
        counter[make_pair(red, blue)]++;
    }

    int64 ans = 0;
    // 後半N文字のうち、どれを赤に塗るか
    for (int mask = 0; mask < (1 << N); mask++)
    {
        string red = "", blue = "";
        for (int i = 0; i < N; i++)
        {
            if ((mask >> i) & 1) red.push_back(S[i + N]);
            else blue.push_back(S[i + N]);
        }
        reverse(blue.begin(), blue.end());
        ans += counter[make_pair(blue, red)];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 87040
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	ll r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; ++i)
	{
		x = x * r - d;
		cout << x << "\n";
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int A,B,C,D;
  scanf("%d%d%d%d", &A, &B, &C, &D);
  int x; 

  if( A < B)
   x = A;
   else
   x = B;

   int y;

   if( C < D )
   y= C;
   else
   y = D;

   int ans = x + y;
   printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxn 100050
#define mm(a,b) memset(a,b,sizeof(a))
using namespace std;
set<int>s;
int main(){
//	freopen("input.txt","r",stdin);
	int n;
	scanf("%d",&n);
	s.clear();
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(!s.count(x)) s.insert(x);
		else s.erase(x);
	}
	printf("%d",s.size());
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<vector>

struct Edge {
	int row, column, weight;
};

void divide_graph(bool[], int);

int n;
Edge edges[99]{};

int main()
{
	int in_tmp, min{}, matrix[100][100]{};

	std::cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			std::cin >> in_tmp;
			matrix[i][j] = in_tmp;
		}

	int rest = n - 1, pre_size = 0;
	std::vector<int> queue{ 0 };
	bool visited[100]{ true };
	for (int i = 1; rest; ++i)
	{
		int now_size = queue.size();
		for (int j = pre_size; j < now_size; ++j)
			for (int k = 0; k < n; ++k)
			{
				int tmp = matrix[queue[j]][k];
				if (tmp != -1 && !visited[k])
				{
					visited[k] = true;
					rest--;
					edges[queue.size() - 1] = { queue[j], k , tmp};
					queue.push_back(k);
				}
			}
		pre_size = now_size;
	}
	for (int i = 0; i < n - 1; ++i)
	{
		bool conne_row[100]{};
		divide_graph(conne_row, i);

		for (int j = 0; j < n; ++j)
		{
			if (!conne_row[j]) continue;
			for (int k = 0; k < n; ++k)
			{
				if (conne_row[k]) continue;
				if (matrix[j][k] == -1 || matrix[j][k] >= edges[i].weight) continue;

				edges[i] = { j, k, matrix[j][k] };
			}
		}
	}

	for (int i = 0; i < n - 1; ++i)
		min += edges[i].weight;

	std::cout << min << std::endl;
	
	return 0;
}

void divide_graph(bool conne_row[], int max_edge)
{
	conne_row[edges[max_edge].row] = true;

	std::vector<int> queue = { edges[max_edge].row };
	int pre_size = 0;

	bool visit_edge[100]{};
	visit_edge[max_edge] = true;

	while (pre_size != queue.size())
	{
		int now_size = queue.size();
		for (int j = pre_size; j < now_size; ++j)
		{
			for (int k = 0; k < n - 1; ++k)
			{
				if (visit_edge[k]) continue;
				if (edges[k].row == queue[j])
				{
					visit_edge[k] = true;
					conne_row[edges[k].column] = true;
					queue.push_back(edges[k].column);
				}
				else if (edges[k].column == queue[j])
				{
					visit_edge[k] = true;
					conne_row[edges[k].row] = true;
					queue.push_back(edges[k].row);
				}
			}
		}
		pre_size = now_size;
	}
	return;
}


Measured memory_bytes: 3184
#include <iostream>

using ll = long long int;

int main() {
    ll n, c;

    ll *x;
    ll *v;
    ll *maxDA;
    ll *maxDAX;

    std::cin >> n >> c;

    maxDA = new ll[n]();
    maxDAX = new ll[n]();
    x = new ll[n]();
    v = new ll[n]();

    ll maxProfit = 0;
    ll dA = 0;
    ll _maxDAX = 0;

    for (ll i = 0; i < n; ++i) {
        std::cin >> x[i] >> v[i];

        if (i > 0) {
            dA = dA + x[i-1];
        }
        dA = dA + v[i] - x[i];

        if (dA > maxProfit) {
            maxProfit = dA;
            _maxDAX = x[i];
        }

        maxDA[i] = maxProfit;
        maxDAX[i] = _maxDAX;
    }


    ll rProfit = 0;
    ll maxRProfit = 0;
    ll maxRProfitDist = 0;

    for (ll j = n - 1; j >= 0; --j) {
        ll rDist = c - x[j];
        rProfit = rProfit + v[j] - rDist;
        if (j < n - 1) {
            ll prevDist = c - x[j+1];
            rProfit = rProfit + prevDist;
        }

        if (rProfit > maxProfit) {
            maxProfit = rProfit;
        }

        if (rProfit > maxRProfit) {
            maxRProfit = rProfit;
            maxRProfitDist = rDist;
        }

        if (j > 0) {
            ll lrProfit = maxDA[j - 1] + maxRProfit;
            ll shortestDist = std::min(maxRProfitDist, maxDAX[j-1]);
            lrProfit = lrProfit - shortestDist;

            if (lrProfit > maxProfit) {
                maxProfit = lrProfit;
            }
        }
    }

    std::cout << maxProfit << std::endl;

    delete[](x);
    delete[](v);
    delete[](maxDA);
    delete[](maxDAX);

    return 0;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
//        List<Integer> array = new ArrayList<>();
        int[] array = new int[N];
        for(int i=0; i<N; i++){
//            array.add(sc.nextInt());
            array[i] = sc.nextInt();
        }

        int[] sortedArray = new int[N];
        for(int i=0; i<N; i++){
            sortedArray[i] = array[i];
        }
        Arrays.sort(sortedArray);

        for(int i=0; i<N; i++){
            int mid = -1;
            int num = array[i];

            if(num <= sortedArray[sortedArray.length/2-1]) mid = sortedArray[sortedArray.length/2];
            else mid = sortedArray[sortedArray.length/2-1];
            System.out.println(mid);
        }
    }
}


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

typedef long long ll;
const ll md = 1000000007;

int prime[1001]={1};
int prime_num;
int prime_set(int n){
  int index = 0;
  for(int i=2; i<=n; i++){
    int flag=1;
    for(int j=2; j<i; j++){
      if(i%j == 0){
        flag = 0;
        break;
      }
    }
    if(flag==0)
      continue;
    prime[index] = i;
    index++;
  }
  prime_num = index;
}      

int main(){
  int n;
  cin >> n;
  
  prime_set(n);
  map<int,int> mp;
  
  
  while(n>0){
    int quot=1;
    for(int i=0; i<prime_num; i++){
      quot = prime[i];
      while(n % quot == 0 && n / quot > 0){
        mp[i]++;
        quot *= prime[i];
      }
    }
    n--;
  }
  
  ll ans = 1;
  
  for(auto itr=mp.begin(); itr != mp.end(); itr++){
    ans *= (1+(itr->second));
    ans %= md;
  }
  
  cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;

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

    int minv = r[0];
    int maxv = -2000000000; 

    for(int i=1; i<n; i++) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;
}





Measured memory_bytes: 3900
fun main(a:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt)
    val list = IntArray(n)
    for (i in 0 until n) {
        list[a[i]-1] = i + 1
    }
    println(list.joinToString(" "))
}

Measured memory_bytes: 57856
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
d = {}
for py in sort_PY:
  if(py[0] not in d):
    d[py[0]] = 1
  else:
    d[py[0]] += 1
  py[2] = d[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll D, G;
pll P[15];

ll calc(ll bit) {
    ll ret = 0;
    REP(i, D) {
        if ((bit >> i) & 1) {
            ret += 100LL * (i + 1) * P[i].first + P[i].second;
        }
    }
    return ret;
}

int main() {
    cin >> D >> G;
    REP(i, D) {
        cin >> P[i].first >> P[i].second;
    }

    ll ans = INF;
    REP(bit, pow(2LL, D)) {
        ll score = calc(bit);
        ll sum = 0;
        REP(i, D) {
            if ((bit >> i) & 1) {
                sum += P[i].first;
            }
        }
        if (score >= G) {
            ans = std::min(ans, sum);
            continue;
        }
        REP(i, D) {
            if ((bit >> i) & 1)
                continue;
            ll s = (i + 1) * 100LL;
            REP(j, P[i].first) {
                if (score + s * j >= G) {
                    ans = std::min(ans, sum + j);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split(" ")]
s = [0 for i in range(m)]

for i in range(m):
    s[i] = [int(j) for j in input().split(" ")]
    s[i] = s[i][1:]

p = [int(i) for i in input().split(" ")]
c = 0

def r(a):
    if len(a) < n:
        r(a + [0])
        r(a + [1])
        return

    global c
    for i in range(m):
        if sum([a[k - 1] for k in s[i]]) % 2 != p[i]:
            return
    c += 1

r([])
print(c)

Measured memory_bytes: 3064