akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	M := nextInt()
	C := nextInt()
	b := make([]int, M)
	for i := 0; i < M; i++ {
		b[i] = nextInt()
	}

	var res int
	for i := 0; i < N; i++ {
		var ans int
		for j := 0; j < M; j++ {
			ans += nextInt() * b[j]
		}

		if ans+C > 0 {
			res++
		}
	}

	fmt.Println(res)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
 	public static void main(String[] args){
    	
      	Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	int answer = A*B;
      	System.out.println(answer);
      
	}  
}


Measured memory_bytes: 35800
import java.util.Scanner;

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

		int n = scanner.nextInt();
		int list01[] = new int[n];
		for (int i = 0; i < n; i++) {
			list01[i] = scanner.nextInt();
		}

		int m = scanner.nextInt();
		int list02[] = new int[m];
		for (int i = 0; i < m; i++) {
			list02[i] = scanner.nextInt();
		}
		scanner.close();

		for (int i = 0; i < m; i++) {
			int num = list02[i];
			boolean flag = roundRobin(list01, num, 0, 0);
			if (flag == true) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}

	static boolean roundRobin(int[] list01, int num, int temp, int i) {
		if (num == temp) {
			return true;
		}
		if (i >= list01.length) {
			return false;
		}
		return roundRobin(list01, num, temp, i + 1) || roundRobin(list01, num, temp + list01[i], i + 1);
	}
}

Measured memory_bytes: 26732
// ABC096-B
// OrangeStar

#include<stdio.h>

int main(void){
  int a, b, c, k, answer, i;

  scanf("%d %d %d", &a, &b, &c);
  scanf("%d", &k);

  if(a<b){
    if(b<c){
      answer=a+b;
      a=c;
    }else{
      answer=a+c;
      a=b;
    }
  }else{
    if(a<c){
      answer=a+b;
      a=c;
    }else{
      answer=b+c;
    }
  }

  for(i=0; i<k; i++){
    a*=2;
  }

  answer+=a;

  printf("%d\n", answer);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int k,temp;
	long long sum=0;
	scanf("%d",&k);
	sum=(1+k)*k/2;
	for(int i=1;i<=k;i++){
		for(int j=i+1;j<=k;j++){
			temp=__gcd(i,j);
			sum+=6*temp;
			for(int x=j+1;x<=k;x++){
				sum+=6*__gcd(temp,x);
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

struct num{
	int x;
	int times;
};

int main(){
	int n;
	std::vector<int> aList;
	std::vector<num> indList;

	bool isValid= true;

	std::cin>>n;
	aList.resize(n);
	indList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

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

	int kind= 0;
	indList[kind]= {aList[0], 1};

	for(int i=1; i<n; i++){
		if(aList[i-1]!=aList[i]){
			kind++;
			indList[kind]= {aList[i], 1};
		}
		else{
			indList[kind].times++;
		}
	}

	kind++;

	if(kind>3)
		isValid=false;

	if(kind!=1 && n%3 != 0)
		isValid=false;

	if(isValid){
		if(kind==1)
			if(indList[0].x != 0)
				isValid= false;

		if(kind==2){
			if(indList[0].times == indList[1].times*2){
				indList[0].times= indList[1].times;
				indList[2]= {indList[0].x, indList[0].times};
			}else if(indList[0].times*2 == indList[1].times){
				indList[1].times= indList[0].times;
				indList[2]= {indList[1].x, indList[1].times};
			}else{
				isValid= false;
			}
		}
		
		if(kind==3)
			if(indList[0].times != indList[1].times || indList[1].times != indList[2].times)
				isValid= false;
	}

	if(isValid && (kind==2 || kind==3)){
		while(indList[0].x!=0 || indList[1].x!=0 || indList[2].x!=0){
			int num1= 0;
			for(int i=0; i<3; i++){
				num1+= indList[i].x%2;
				indList[i].x= indList[i].x/2;
			}
			if(num1!= 0 && num1!= 2)
				isValid=false;
		}
	}

	if(isValid)
		std::cout<<"Yes"<<std::endl;
	else
		std::cout<<"No"<<std::endl;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int a;
    cin >> a;
    if(a==1){
        cout << "Hello World" << "\n";

        return 0;
    } 
    int b, c;
    cin >> b >> c;
    cout << b+c << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
	int i,n;
	int arr[100]={0};
	
	scanf("%d", &n);
	
	for(i = 0; i<n ; i++){
		scanf("%d", &arr[i]);
	}
	
	for (i = 0; i < (n/2) ; i++){
		int temp    = arr[i];
		arr[i]      = arr[(n-1) - i];
		arr[(n-1)-i]= temp;
	}
	
	for (i = 0; i < n; i++){
		if ( i ) {
			printf(" ");
		}
		printf("%d", arr[i]);
	}
	printf("\n");
    return 0;
}

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

int main()
{
    long long h;
    cin>>h;
    long long k=h;
    long long power=0;
    while(k){
        power++;
        k/=2;
    }
    long long ans=1;
    while(power--){
        ans=ans*2;
    }
    cout<<ans-1;
    return 0;
}


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

public class Main{
	public static void main(String[] args)
			throws IOException
	{
		BufferedReader br = new BufferedReader(new
		InputStreamReader(System.in));
		int i=0;

		int a=Integer.parseInt(br.readLine());
		i=1+a/2;
		if(a%2==0)
			i=a/2;
		System.out.println(i);
		

	}
}

Measured memory_bytes: 22228
from collections import defaultdict


def find_root(x):
    if parent[x] == x:
        return x
    else:
        return find_root(parent[x])


def unite(x, y):
    x = find_root(x)
    y = find_root(y)

    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
            size[y] += size[x]
        else:
            parent[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


def same(x, y):
    return find_root(x) == find_root(y)


def group_size(x):
    return size[find_root(x)]


dic1 = defaultdict(list)
dic2 = defaultdict(list)

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]


parent = [i for i in range(n)]  # 根
rank = [1] * n  # 深さ
size = [1] * n  # iを根とするグループのサイズ

edge = [[ab[m - 1 - i][0] - 1, ab[m - 1 - i][1] - 1] for i in range(m)]

for i in range(m):
    a = find_root(edge[i][0])
    b = find_root(edge[i][1])
    if a != b:
        unite(a, b)


for i in range(m):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    dic1[a].append(b)
    dic1[b].append(a)
for i in range(k):
    c = cd[i][0] - 1
    d = cd[i][1] - 1
    if same(c, d):
        dic2[c].append(d)
        dic2[d].append(c)

ans = []
for i in range(n):
    ans.append(group_size(i)-1 - len(dic1[i]) - len(dic2[i]))
print(' '.join(map(str, ans)))


Measured memory_bytes: 123480
fun main() {
    println(solve())
}

val solve: () -> Any = {
    val K = readInt()
    val S = readString()
    if (K >= S.length) S else (S.take(K) + "...")
}

val mod: Int = 1_000_000_007


fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

fun <E> List<E>.toPair() = this[0] to this[1]

fun <T> readPair(t: (String) -> T) = readPair(t, t)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }

fun Int.pow(n: Int) = Math.pow(this.toDouble(), n.toDouble())
fun Int.powInt(n: Int) = pow(n).toInt()

fun minAndMax(a: Int, b: Int) = if (a < b) a to b else b to a

fun <T> T.ifOrThis(bool: (T) -> Boolean, trans: (T) -> T) = if (bool(this)) trans(this) else this
fun <T> T.ifOrThis(bool: Boolean, trans: (T) -> T) = if (bool) trans(this) else this

Measured memory_bytes: 35964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s,t;
ll dp[1001][1001];
char mat[1001][1001];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen("test.in","r",stdin);

    cin>>n>>m;
    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < m ; ++j)
            cin>>mat[i][j],dp[i][j] = 0;

    dp[0][0] = 1;

    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < m ; ++j){
            if(mat[i][j] == '#') continue;

            if(i - 1 >= 0) dp[i][j] = dp[i - 1][j];
            if(j - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j - 1])%MOD;

        }

    cout<<dp[n - 1][m - 1]<<'\n';


    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n],b[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>b[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if (2*b[i]>=a[i]&&a[i]!=b[i])
		{
			cout<<"-1\n";
			return 0;
		}
	}
	set<int> st;
	long long ans=0LL;
	for (int i = 1; i <= 50; ++i)
	{
		st.insert(i);
	}
	for (int i = 50; i >= 1; --i)
	{
		st.erase(i);
		int dist[55][55];
		for (int j = 0; j < 55; ++j)
		{
			for (int k = 0; k < 55; ++k)
			{
				dist[j][k]=100000;
				if (j==k)
				{
					dist[j][k]=0;
				}
			}
		}
		for (auto j:st)
		{
			for (int k = 0; k <= 50; ++k)
			{
				dist[k][k%j]=1;
			}
		}
		for (int j = 0; j <= 50; ++j)
		{
			for (int k = 0; k <= 50; ++k)
			{
				for (int l = 0; l <= 50; ++l)
				{
					dist[k][l]=min(dist[k][l],dist[k][j]+dist[j][l]);
				}
			}
		}
		for (int j = 0; j < n; ++j)
		{
			if (dist[a[j]][b[j]]==100000)
			{
				st.insert(i);
				ans+=(1LL<<i);
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int a[200005],b[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lld",&a[i]);
        b[i] = a[i];
    }
    sort(b,b+n);
    ll zuo = b[n/2-1],you = b[n/2];
    for(int i = 0; i < n; i++)
    {
        printf("%lld\n",a[i]<=zuo?you:zuo);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    string s;cin>>s;
    reverse(all(s));
    int now=0;
    while(now<s.size()){
        if(s.substr(now,5)=="maerd"||s.substr(now,5)=="esare")now+=5;
        else if(s.substr(now,7)=="remaerd")now+=7;
        else if(s.substr(now,6)=="resare")now+=6;
        else break;
        // cout<<now;
        if(now==s.size()){
            cout<<"YES";return 0;
        }
    }
    cout<<"NO";
}


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

const int N = 2e5 + 10;
typedef long long ll;
typedef pair<int, int> pii;
ll n, mp[105][105], tmp, pw[20];
string s[N];
double x;

int main() {
    cin >> n;
    ll ans = 0;
    pw[0] = 1;
    rep(i, 1, 18) pw[i] = pw[i - 1] * 10;
    rep(i,1,n) {
        cin>>s[i];
        // printf("%d\n",i );
        int pos = -1;
        tmp = 0;
        rep(j,0,(int)s[i].size() - 1) if(s[i][j] == '.') pos = j;
        if(pos == -1) pos = s[i].size();
        rep(j,0,pos - 1) tmp += (s[i][j] - '0') * pw[pos + 8 - j];
        rep(j,pos+1,(int)s[i].size() - 1) tmp += (s[i][j] - '0') * pw[9 - (j - pos)];
        int cnt2 = 0, cnt5 = 0;
        while (tmp % 2 == 0) ++cnt2, tmp /= 2;
        while (tmp % 5 == 0) ++cnt5, tmp /= 5;
        if (cnt2 >= 9 && cnt5 >= 9) ans--;
        ++mp[cnt2][cnt5];
    }
    rep(i, 0, 64) {
        rep(j, 0, 64) {
            rep(k, max(18 - i, 0), 64) {
                rep(l, max(18 - j, 0), 64) {
                    ans += mp[i][j] * mp[k][l];
                }
            }
        }
    }
    printf("%lld\n", ans / 2);
    return 0;
}


Measured memory_bytes: 10048
S = input()
a = int(S[0:2])
b = int(S[2:])

if 1 <= a <= 12:
    if 1 <= b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= b <= 12:
        print('YYMM')
    else:
        print('NA')

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

string s, t;
vector<vector<long long int>> chars(26, vector<long long int>(0));

long long int solve(){
  int n = s.size(), m = t.size();
  s += s; //発想は番兵と同じ
  rep(i, n * 2){
    chars.at(s.at(i) - 'a').push_back(i);
  }
  /*
  rep(i, 26){
    for(int x : chars.at(i)){
      cerr << x <<" ";
    }
    cerr << endl;
  }
  */
  long long int ret = 0;
  int pos = -1;
  rep(i, m){
    int c = t.at(i) - 'a';
    //tに含まれておりsに含まれない文字が存在する場合-1を返す
    //配列外参照の回避も兼ねる
    if(chars.at(c).size() == 0){
      ret = -1LL;
      return ret;
    }
    //posの更新
    pos = *upper_bound(chars.at(c).begin(), chars.at(c).end(), pos);
    cerr << pos << endl;
    if(pos >= n){
      ret += (long)n;
      pos -= n;
    }
  }
  ret += (long)pos + 1LL;
  return ret;
}

int main(){
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 2804
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
s = [0]
d1 = [-1] * n
d1[0] = 0
while s:
    d = s.pop()
    for node in g[d]:
        if d1[node] == -1:
            s.append(node)
            d1[node] = d1[d] + 1
s = [n - 1]
d2 = [-1] * n
d2[n - 1] = 0
while s:
    d = s.pop()
    for node in g[d]:
        if d2[node] == -1:
            s.append(node)
            d2[node] = d2[d] + 1
f, s = 0, 0
for i in range(n):
    if d1[i] <= d2[i]:
        f += 1
    else:
        s += 1
if f > s:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 29104
n = int(raw_input())
T = map(int,raw_input().split())

m = int(raw_input())
ans = 0
for i in xrange(0, m):
    p,x = map(int,raw_input().split())
    temp = T[p-1]
    T[p-1] = x
    print sum(T)
    T[p-1] = temp


Measured memory_bytes: 2568
A,B,C,X,Y = map(int, input().split())
ans = float('inf')
for i in range(0,200001,2):
    a = max(0,X-i//2)
    b = max(0,Y-i//2)
    s = a*A+b*B+i*C
    ans = min(ans, s)
print(ans)

Measured memory_bytes: 40048
x = int(input())
if x <= 3:
  n = x
elif x == 4:
  n = 5
else:
  n = x
  j = 0
  while j == 0:
    a = int(n/2) + 1
    i = 2
    while i < a:
      if i == a-1:
        j = 1
        i = a
      elif n % i != 0:
        i += 1
      else:
        i = a
        n += 1
print(n)

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

#define ll long long
#define dd double

using namespace std;



int main(){
    string S;
    ll count = 0;
    ll Q;
    int F,T;
    string C;
    cin >> S;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        cin >> T;
        if(T == 1){
            count++;
        }
        else{
            cin >> F >> C;
            if(count % 2 == 0){
                if(F == 1){
                    S.insert(0, C);
                }
                else S += C;
            }
            else{
                if(F == 1) S += C;
                else S.insert(0, C);
            }
        }
    }
    if(count % 2 == 1) reverse(S.begin(), S.end());

    cout << S << endl;
}

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

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

	int n, t, l, b;
	while (cin >> n >> t >> l >> b , n) {
		bool lose[110] = {false}, back[110] = {false};
		int x;
		for (int i = 0; i < l; i++) {
			cin >> x;
			lose[x] = true;
		}
		for (int i = 0; i < b; i++) {
			cin >> x;
			back[x] = true;
		}

		double dp[110][110] = {0};
		dp[0][0] = 1.0;


		for (int turn = 0; turn < t; turn++) {
			for (int pos = 0; pos < n; pos++) {
				if (dp[pos][turn] == 0) continue;

				for (int dice = 1; dice <= 6; dice++) {
					int npos = pos + dice;
					if (n < npos) npos = n - (npos - n);

					if (lose[npos]) {
						dp[npos][turn + 2] += dp[pos][turn] / 6.0;
					}
					else if (back[npos]) {
						dp[0][turn + 1] += dp[pos][turn] / 6.0;
					}
					else {
						dp[npos][turn + 1] += dp[pos][turn] / 6.0;
					}
				}
			}
		}

		double ans = 0;
		for (int turn = 1; turn <= t; turn++) {
			ans += dp[n][turn];
		}
		cout <<fixed <<setprecision(6) << ans << endl;
	}
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

int f(int n, int x) {
    if (n == -1) return 0;
    return n / x + 1;
}

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

    int a, b, x;
    cin >> a >> b >> x;
    cout << f(b, x) - f(a - 1, x) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x[5];
    rep(i,5){
        cin >> x[i];
        if(x[i]==0){
            cout << i+1 << endl;
        }
    }
}


Measured memory_bytes: 3640
input = gets.chomp!.split(" ")
n = input[0].to_i
a = input[1].to_i
b = input[2].to_i

if a == 0
  print "0"
  exit
end

if b == 0
  print n
  exit
end

if a > n
  print n
  exit
end

c = n / (a + b)

d = n - (a + b)

mod = n % (a + b)
if mod > a
  print c * a + a
else
  print c * a + mod
end

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

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<int> step(n);

    for(int i = 0; i < n; ++i)
        cin >> step[i];

    vector<int> dp(n, 0);

    dp[0] = 0;
    dp[1] = abs(step[0] - step[1]);

    for(int i = 2; i < n; ++i) {

        int a = dp[i - 2] + abs(step[i] - step[i - 2]);
        int b = dp[i - 1] + abs(step[i] - step[i - 1]);

        dp[i] = min(a, b);

    }

    cout << dp[n - 1] << endl;

    return 0;
}

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

using namespace std;


int main(){
    int len_array;
    scanf("%d",&len_array);
    vector<int> int_array1(len_array);
    vector<int> int_array2(len_array);
    int temp;
    for(int i = 0;i < len_array;i++){
        scanf("%d",&temp),
        int_array1[i] = temp;
    }
    int_array2 = int_array1;
    if(prev_permutation(int_array1.begin(),int_array1.end())){
        for(int i = 0;i < int_array1.size();i++){
            if(i != int_array1.size()-1) printf("%d ",int_array1[i]);
            else printf("%d\n",int_array1[i]);
        }
    }
    for(int i = 0;i < int_array2.size();i++){
        if(i != int_array2.size()-1) printf("%d ",int_array2[i]);
        else printf("%d\n",int_array2[i]);
    }
    if(next_permutation(int_array2.begin(),int_array2.end())){
        for(int i = 0;i < int_array2.size();i++){
            if(i != int_array2.size()-1) printf("%d ",int_array2[i]);
            else printf("%d\n",int_array2[i]);
        }
    }


    return 0;   
}


Measured memory_bytes: 3276
from collections import defaultdict
import sys
from functools import lru_cache
sys.setrecursionlimit(100000)
N = int(input())
 
counts = [0,0,0]
for a in map(int,input().split()):
  counts[a-1] += 1

A,B,C = counts


# dp[i][j][k] = 残り1個の皿がi枚、残り2個の皿がj枚、残り3個の皿がk枚のときの回数の期待値
# dp[i][j][k] = (i/N)(dp[i-1][j][k])+(j/N)(dp[i+1][j-1][k])+(k/N)(dp[i][j+1][k-1])+(N-i-j-k/N)(dp[i][j][k])+1
# dp[i][j][k] = (i(dp[i-1][j][k])+j(dp[i+1][j-1][k])+k(dp[i][j+1][k-1])+N)/(i+j+k)
dp = [[[None]*(C+1) for _ in range(B+C+1)] for _ in range(A+B+C+1)]
dp[0][0][0] = 0

for k in range(C+1):
  for j in range(B+C+1-k):
    for i in range(A+B+C+1-k-j):
      try:
        dp[i][j][k] =((i*dp[i-1][j][k] if i else 0)+
                      (j*dp[i+1][j-1][k] if j else 0)+
                      (k*dp[i][j+1][k-1] if k else 0)+
                      N)/(i+j+k)
      except ZeroDivisionError:
        pass

print(dp[A][B][C])

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

using namespace std;
typedef long long ll;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint accdp[2100][2100];

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N);
  vector<ll> T(M);
  
  rep(i, N) cin >> S[i];
  rep(i, M) cin >> T[i];
  
  //「空列」という共通部分列
  accdp[1][1] = 1;
  
  rep(i, N+1) {
    rep(j, M+1) {
      if(i == 0 && j == 0) continue;
      mint dp;
      if(i>=1 && j>=1 && S[i-1] == T[j-1]) {
        dp = accdp[i][j];
      }
      //新たに単体からなる部分列でも「空列に追加」ということなので含まれる
      accdp[i+1][j+1] = accdp[i][j+1] + accdp[i+1][j] - accdp[i][j] + dp;
    }
  }
  
  cout << accdp[N+1][M+1] << endl;
}


Measured memory_bytes: 33152
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible";
	else cout<<"Impossible";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
    at, bt = map(int, input().split())
    a.append(at)
    b.append(bt)
if(n % 2 == 1):
    a.sort()
    b.sort()
    min_med = a[(n-1)//2]
    max_med = b[(n-1)//2]
    result = max_med - min_med + 1
else:
    a.sort()
    b.sort()
    min_med = (a[n//2-1] + a[n//2])/2
    max_med = (b[n//2-1] + b[n//2])/2
    result = (max_med - min_med)*2 + 1
print(int(result))

Measured memory_bytes: 99084
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

vector<vector<int> > G;
int* dist;
int* par;


void dijkstra(int n, int s) {
    for (int i = 0; i < n; i++) {
        dist[i] = 999999;
    }
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pque;
    dist[s] = 0;
    pque.push(pair<int,int>(0, s));

    while (!pque.empty()) {
        pair<int, int> p = pque.top();
        int v = p.second;
        int d = p.first;
        
        pque.pop();
        if (d > dist[v])
            continue;
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            if (dist[u] <= d+1)
                continue;
        
            dist[u] = d+1;
            pque.push(pair<int,int>(dist[u], u));
            par[u] = v;
        }
    }
}

int main() {
    int n, m;   cin >> n >> m;
    G.resize(n);
    dist = new int[n], par = new int[n];

    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        a--;    b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dijkstra(n, 0);
    
    for (int i = 0; i < n; i++) {
        if (dist[i] == 999999) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << par[i]+1 << endl;
    }
    return 0;
}

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

void call(int n);
void judge1(int a);
void judge2(int b);
void judge3(int c);

int main() {
	int input;
	cin>>input;
	call(input);
	return 0;
}

void call(int n) {
	int i;
	for (i = 1; i <= n; i++) {
		judge1(i);
	}
	cout << endl;
}

void judge1(int a) {
	if (a % 3 == 0) cout << " " << a;
	else judge2(a);
}

void judge2(int b) {
	if (b % 10 == 3) cout << " " << b;
	else judge3(b);
}

void judge3(int c) {
	int temp = 0;
	while (1) {
		if (temp == 0) temp = c;
		temp /= 10;
		if (temp) {
			if (temp % 10 == 3) {
				cout << " " << c;
				break;
			}
		}
		else break;
	}
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 2e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int h, w;
    cin >> h >> w;
    if (h % 2 == 0) swap(h, w);
    vi c(26);
    rep(i, h * w) {
        char chr;
        cin >> chr;
        c[chr - 'a']++;
    }

    int c4 = 0;
    int c42 = 0;
    int c_odd = 0;
    rep(j, 26) {
        if (c[j] % 2 != 0) {
            c_odd++;
        }
        else if (c[j] % 4 == 0) {
            c4++;
        }
        else if (c[j] % 4 == 2) {
            c42++;
        }
    }

    bool ret = [&](){
        if (h % 2 == 0 && w % 2 == 0) {
            if (c4 == 26) {
                return true;
            }
        }
        else if (h % 2 != 0 && w % 2 == 0) {
            if (c_odd == 0 && c42 <= w / 2) {
                return true;
            }
        }
        else {
            if (c_odd > 1) {
                return false;
            }
            if (c_odd == 1) {
                rep(j, 26) {
                    if (c[j] % 2 != 0) {
                        c[j]--;
                        if (c[j] % 4 == 0) {
                            c4++;
                        }
                        else {
                            c42;
                        }
                        break;
                    }
                }
            }
            if (c42 <= (h - 1) / 2 + (w - 1) / 2) {
                return true;
            }
        }
        return false;
    }();

    cout << (ret ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def kruskal(edges):
    edges.sort(key=lambda pair:pair[2])
    uf_tree = UnionFindTree(n_node)
    total_cost = 0
    for i, j, cost in edges:
        if cost < 0:
            continue

        if not uf_tree.have_same_root(i, j):
            uf_tree.unite(i, j)
            total_cost += cost
    return total_cost


class UnionFindTree:
    def __init__(self, n_node):
        self.parent = [i for i in range(n_node)]
        self.rank = [0] * n_node

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
            else:
                self.parent[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def have_same_root(self, x, y):
        return self.find(x) == self.find(y)

if __name__ == "__main__":
    n_node = int((input()))
    edges = []
    for i in range(n_node):
        for j, cost in enumerate(map(int, input().split())):
            edges.append((i, j, cost))

    print(kruskal(edges))







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

using namespace std;

int D, N, M, x[100001];

int main()
{
  while(true)
  {
    cin >> D;
    if(!D)
      break;
    cin >> N >> M;
    for(int i = 1; i < N; i++)
      cin >> x[i];
    x[N++] = D;
    sort(x, x + N);

    int ans = 0;
    for(int i = 0; i < M; i++)
    {
      int v;
      cin >> v;
      auto b = upper_bound(x, x + N, v);
      auto a = b - 1;
      ans += min(abs(*b - v), abs(*a - v));
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1560
#include <iostream>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
template<typename A> using V = std::vector<A>;
using vi = V<int>;
using vvi = V<vi>;
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vvi dp(N + 1, vi(W + 1));
  vi v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  loop(i, 1, N + 1) rep(j, W + 1) {
    dp[i][j] = dp[i - 1][j];
    if (j - w[i - 1] >= 0) cmax(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 6756
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      int n;
      cin>>n;
      int a[n+1],b[n+1],c[n];
      rep1(i,n) cin>>a[i];
      rep1(i,n) cin>>b[i];
      rep1(i,n-1) cin>>c[i];
      ll ans=0;
      rep1(i,n){
            ans+=b[a[i]];
            if(i<n){
                  if(a[i]+1==a[i+1]) ans+=c[a[i]];
            }
            //cout<<ans<<endl;
      }
      cout<<ans<<endl;
      return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, ll K) {
  auto ans {N-K+1};
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  solve(N, K);
  return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    if (N == 2) {
        if (A[0] == A[1]) cout << 1 << endl;
        else cout << 0 << endl;
        return;    
    }

    vector<int> c1(100001), c2(100001);
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            c1[A[i]]++;
        } else {
            c2[A[i]]++;
        }
    }

    int m1 = max_element(all(c1)) - c1.begin();
    int m2 = max_element(all(c2)) - c2.begin();

    if (m1 != m2) {
        cout << N - c1[m1] - c2[m2] << endl;
        return;
    } else {
        sort(c1.rbegin(), c1.rend());
        sort(c2.rbegin(), c2.rend());
        if (c1[1] < c2[1]) {
            cout << N - c1[0] - c2[1] << endl;
        } else {
            cout << N - c2[0] - c1[1] << endl;
        }
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 1408
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main() {

    int N; cin>>N;
    string S; cin>>S;

    int ans=0;
    for (int i = 0; i < N-2; ++i) {
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
            ans++;
            i+=2;
        }
    }

    cout<<ans<<endl;
    return 0;

}

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

int main(){
  string s; cin >> s;
  string ss;
  for(int i = 2;i <= s.size()-2;i+=2){//削る文字数
    ss = s.substr(0,s.size()-i);
    if(ss.substr(0,ss.size()/2) == ss.substr(ss.size()/2,ss.size()/2)){
      cout << ss.size() << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace Atc_0020
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            long A = long.Parse(s.Split(' ')[0]);
            long B = long.Parse(s.Split(' ')[1]);
            long C = long.Parse(s.Split(' ')[2]);
            long K = long.Parse(s.Split(' ')[3]);

            if (K <= A)
            {
                Console.WriteLine(K);

                return;
            }

            long ans = A;

            if (0 < (K - A - B))
            {
                ans -= ((K - A - B));
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 27488
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	vector<int>a(n);
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] != i + 1)cnt++;
	}
	if (cnt > 2)return cout << "NO\n", 0;
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100010;
int x[MAX];
vector<P> g[MAX];

vector<int> ans;

bool flag[MAX];
int dfs(int i){
  if ( flag[i] ) return 0;
  flag[i] = true;

  int odd = x[i];
  for ( P e : g[i] ) {
    int r = dfs(e.first);
    if (r != 0) ans.push_back(e.second);
    odd ^= r;
  }
  return odd;
}

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

  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());
  x[0] = a[0].second;
  rep(i,n-1) x[i+1] = a[i].second ^ a[i+1].second;
  x[n] = a[n-1].second;

  rep(i,m){
    int l, r;
    cin >> l >> r;
    l = lower_bound(a.begin(),a.end(),P(l,0)) - a.begin();
    r = upper_bound(a.begin(),a.end(),P(r,1)) - a.begin();
    g[l].emplace_back(r,i+1);
    g[r].emplace_back(l,i+1);
  }

  bool isOdd = false;
  rep(i,n+1){
    if ( dfs(i) > 0 ) {
      isOdd = true;
      break;
    }
  }

  if (isOdd) {
    cout << -1 << endl;
  } else {
    sort(ans.begin(),ans.end());
    cout << ans.size() << endl;
    rep(i,ans.size()) printf( "%d ",ans[i] );
    cout << endl;
  }
}


Measured memory_bytes: 15228
#include <cstdio>

using namespace std;

const int MAXN = 2e5 + 10;

int a[MAXN], cnt[MAXN];

int main() {
    int n;
    scanf("%d", &n);// don't forget &
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);// don't forget &
        ans += cnt[a[i]];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        int x = a[i];
        printf("%lld\n", ans - cnt[x] * (cnt[x] - 1) / 2 
        + (cnt[x] - 1) * (cnt[x] - 2) / 2);
    }
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
using P = pair<Int, Int>;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        int a, b; cin >> a >> b;
        if(a == b)
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if(cnt == 3)
        {
            ans = max(ans, cnt);
        }
    }
    if(ans > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> t(100000), x(1000000), y(100000);
    for(int i=0; i<n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool flg = true;
    if(t[0] != abs(x[0]) + abs(y[0])){
        flg = false;
        cout << "No" << endl;
        return 0;
    }
    for(int i=1; i<n; i++){
        if((t[i]-t[i-1] >= abs(x[i]-x[i-1])+abs(y[i]-y[i-1])) && (t[i]-t[i-1]-abs(x[i]-x[i-1])-abs(y[i]-y[i-1]))%2==0){
            flg =true;
        }else{flg =false; break;}
    }
    if(flg) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return 0;
}

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

using namespace std;

char a[52],b[52];

int main(){
    cin>>a;
    cin>>b;
    int la=strlen(a),lb=strlen(b);
    int l=min(la,lb),ll=max(la,lb);
    for(int i=0;i<=l-1;i++)
        cout<<a[i]<<b[i];
    if(la>lb)
        for(int i=l;i<=ll-1;i++)
            cout<<a[i];
    else for(int i=l;i<=ll-1;i++)
            cout<<b[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)

int const MOD = 1e9 + 7;
int const N = 105;
int const MX = 1e5;
using namespace std;

int wt[N], vl[N];
int dp[100010];
int32_t main(){
    memset(dp, -1, sizeof dp);
    int n, w;
    cin>>n>>w;
    for(int i = 1; i<=n; i++){
        cin>>wt[i]>>vl[i];
    }
    dp[0] = 0;
    for(int i = 1; i<=n; i++){
        int val = vl[i];
        int weight = wt[i];
        for(int j = MX-val; j>=0; j--){
            if(dp[j] != -1)
                dp[j + val] = dp[j+val] == -1 ? dp[j] + weight : min(dp[j+val], dp[j] + weight);
        }
    }
    for(int i = MX; i>=0; i--){
        if(dp[i] != -1 && dp[i] <= w){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    int N, K;
    int A[200];
    int d;
    int count = 0;
    string str;

    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        A[i] = 1;
    }

    for (int i = 0; i < K; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            A[a - 1] = 0;
        }
    }

    for (int i = 0; i < N; i++) {
        count += A[i];
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3568
n = int(input())
L = list(map(int, input().split()))
count = 0
for i in range(1,n-1):
  if (L[i-1] < L[i] and L[i] < L[i+1]) or (L[i-1] > L[i] and L[i] > L[i+1]):
    count += 1
print(count)    

Measured memory_bytes: 3188
//105


#include <iostream>


using namespace std;

//---約数が8個あるか確かめる関数---//
inline bool divisor8(const int n){
	int count = 0;
	for(int i = 0; i < n; i++){
		if (n%(i+1) == 0)	count++;
	}
	if(count == 8)	return true;
	else			return false;
}


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

	int answer = 0;

	//nが奇数のとき
	if (n%2){
		for (int i = 0; i < (n+1)/2; i++){
			if(divisor8(2*(i+1)-1))	answer++;
		}
	}

	//nが偶数のとき
	else{
		for (int i = 0; i < n/2; i++){
			if(divisor8(2*(i+1)-1))	answer++;
		}
	}

	cout << answer << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC057CSolve solve = new ABC057CSolve();
		solve.main();
	}
}

class ABC057CSolve {
	
	long N;
	
	ABC057CSolve() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextLong();
	}
	
	void main() {
		long min = Long.MAX_VALUE / 2;
		if (N == 1) {
			System.out.println(1);
			return;
		}
		for (int i = 1; i <= Math.sqrt(N); i++) {
			if (N % i == 0) {
				long a = i;
				long b = N / i;
				long f = F(a, b);
				min = Math.min(min, f);
			}
		}
		System.out.println(min);
	}
	
	int F(long a, long b) {
		int aCount = String.valueOf(a).length();
		int bCount = String.valueOf(b).length();
		return aCount > bCount ? aCount : bCount;
	}

}


Measured memory_bytes: 21844