akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
ans = 0
m = max(a)+2
cnt1 = [0]*m
cnt2 = [0]*n
mod = 10**9+7

for i in range(n-1):
    cnt1[a[i]+1] += 1
    for j in range(i+1,n):
        if a[i] > a[j]: cnt2[i] += 1
cnt1[a[n-1]+1] += 1

for i in range(1,len(cnt1)):
    cnt1[i] += cnt1[i-1]

for i in range(n):
    ans = (ans + cnt1[a[i]]*(k*(k-1))//2%mod + cnt2[i]*k%mod)%mod

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 0, 3) if(s[i] == t[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
const int p=2019;
int n,k[200001],buc[p],q[p],inv[p];char s[200001];
int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=ans*bs%p;bs=bs*bs%p;ex>>=1;}return ans;}
class twoint
{
	public:
		int i1,i2;
		twoint(int c,int d)
		{
			i1=c;
			i2=d;
		}
		twoint(){}
		twoint& operator=(twoint that)
		{
			this->i1=that.i1;
			this->i2=that.i2;
			return *this;
		}
};
twoint exgcd(int a,int b)
{
	if(b==0)
	{
		return twoint(1,0);
	}
	twoint tmp;
	tmp=exgcd(b,a%b);
	twoint res;
	res=twoint(tmp.i2,tmp.i1-a/b*tmp.i2);
	return res;
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);++buc[0];for(int i=1;i<p;++i)if(i%3&&i%673){twoint t;t=exgcd(i,p);inv[i]=(t.i1+p)%p;}
	for(int i=1;i<=n;++i)k[i]=(k[i-1]*10+s[i]-'0')%p;long long ans=0;
	for(int i=1;i<=n;++i)ans+=buc[(k[i])*inv[qpow(10,i)]%p],++buc[k[i]*inv[qpow(10,i)]%p];
	printf("%lld\n",ans);return 0;
}

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

int main() {
   string s;
   cin >> s;
   s[5] = ' ';
   s[13] = ' ';
   cout << s << endl;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[]a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		for (int i = 0; i < n; i++) {
			b[i] = scan.nextInt();
		}
		for (int i = 0; i < n; i++) {
			c[i] = scan.nextInt();
		}

		List<Integer> Alist = int2List(a);
		List<Integer> Clist = int2List(c);
		long Acnt = 0;
		long Ccnt = 0;
		long ans = 0;


		for (int i = 0; i < n; i++) {
			Acnt += ~Collections.binarySearch(Alist, b[i], (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);
			Ccnt += n - (~Collections.binarySearch(Clist, b[i], (x, y) -> x.compareTo(y) > 0 ? 1 : -1));
			ans += (Acnt*Ccnt);
			Acnt = Ccnt = 0;
		}

		System.out.println(ans);
	}

//int配列をList<Integer>に変換するヘルパーメソッド
	static List<Integer> int2List(int[] arr) {
		List<Integer> list = new ArrayList<>();
		for (int i : arr) {
			list.add(i);
		}
		Collections.sort(list);
		return list;
	}
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    li res = INF;
    li n, t;
    cin >> n >> t;
    rin{
        li ci, ti;
        cin >> ci >> ti;
        if (ti <= t) {
            res = min(res, ci);
        }
    }

    if (res == INF) {
        puts("TLE");
    } else {
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a,b;
        a = scan.nextInt();
        b = scan.nextInt();
        if(a>b){
            System.out.println("a > b");
        } else if(a == b){
            System.out.println("a == b");
        } else{
            System.out.println("a < b");
        }
        scan.close();
    }
}


Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define fin freopen("E:/in.txt", "r", stdin)
#define fout freopen("E:/out.txt", "w", stdout)
#define ms(a, x) memset(a, x, sizeof(a))
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
typedef long long ll;
typedef long double ld;
const int maxn = 1e5+5;
const int mod = 1e9+7;
using namespace std;
typedef pair<int, int> pii;
ll n, m;

int main(){
    cin >> n >> m;
    if(m % n == 0){
        cout << m/n << endl;
        return 0;
    }
    ll p = m/n;
    ll limit = sqrt(m);
    ll get = min(limit, p);
    ll ans = 0;
    per(i, 1, get){
        if(m%i == 0){
            ll x = m/i;
            ans = max(ans, (ll)i);
            if(x*n <= m) ans = x;
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char const* argv[])
{
    int i;
    for (i = 1; i < 10; i++) {
        int j;
        for (j = 1; j < 10; j++) {
            cout << i <<"x" << j<<"="<<i*j<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1116
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#define _for(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

std::vector<int> par;
int root(int i) {
  if(par[i]==i) return i;
  return par[i] = root(par[i]);
}

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if(x==y)return;
  par[y] = x;
}

int main() {
  int n,m;
  std::cin >> n >> m;
  par.resize(n);
  std::iota(par.begin(),par.end(),0);
  int x;
  int y;
  int z;
  _for(i,m) {
    std::cin >> x >> y >> z;
    x--;y--;
    unite(x,y);
  }
  int count = 0;
  _for(i,n) {
    if(par[i]==i) {
      count++;
    }
  }
  std::cout << count << std::endl;

  return 0;
}

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

loop_time = N - K

l_s = 0
l_e = K
max_score = 0
test_score = 0
# initial process
ans_list = p_list[l_s:l_e]
for j in ans_list:
    max_score += sum(range(1,j+1)) / j
    test_score = max_score
l_s = l_s + 1

for i in range(loop_time):
    # pop process
    pop_e = p_list[l_s-1]
    test_score = test_score - sum(range(1,pop_e+1)) / pop_e
    # push process
    push_e = p_list[l_e]
    test_score = test_score + sum(range(1,push_e+1)) / push_e
    if test_score > max_score:
        max_score = test_score
    l_s = l_s + 1
    l_e = l_e + 1

print(max_score)


Measured memory_bytes: 71792
n = int(input())
li = list(map(int,input().split()))
list.sort(li, reverse = True)
switch = 1
Alice = 0
Bob = 0
for i in li:
    if switch == 1:
        Alice += i
        switch = 0
    else:
        Bob += i
        switch = 1
print(Alice - Bob)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdint.h>

unsigned int GCD(unsigned int a, unsigned int b){
  while( 1 ){
    unsigned int r = a % b;
    if( r == 0 ) return b;
    else{
      a = b;
      b = r;
    }
  }
}

uint64_t LCM(uint64_t a, uint64_t b){
  uint64_t gcd = GCD( a, b );
  return (a / gcd) * b;
}

int main(void){
  while( 1 ){
    uint64_t moves = 0;
    int x = 1, y = 1, z = 1;
    unsigned int a1,m1,a2,m2,a3,m3;
    uint64_t lcm1 = 0, lcm2 = 0, lcm3 = 0;
    
    scanf("%d%d%d%d%d%d", &a1,&m1,&a2,&m2,&a3,&m3);
    if( a1 == 0 && m1 == 0 && a2 == 0 && m2 == 0 && a3 == 0 && m3 == 0 ) break;
    while( 1 ){ x = (a1 * x) % m1; lcm1++; if( x == 1 ) break; }
    while( 1 ){ y = (a2 * y) % m2; lcm2++; if( y == 1 ) break; }
    while( 1 ){ z = (a3 * z) % m3; lcm3++; if( z == 1 ) break; }
    moves = LCM( lcm1, LCM( lcm2, lcm3 ) );
    printf("%llu\n", moves);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
string s;
ll n,m,k;
bool nouse[100010];
int a[100010];
int main()
{
	ios::sync_with_stdio(0);
	zero(nouse);
	cin>>n>>m;
	rep(i,n) cin>>a[i];
	rep(i,m)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		if(a[x]>a[y]) nouse[y]=true;
		if(a[y]>a[x]) nouse[x]=true;
		if(a[y]==a[x]) nouse[x]=true,nouse[y]=true;
	}
	int ans=0;
	rep(i,n)
	{
		if(!nouse[i]) ans++;
	}
	cout<<ans;
	return 0;
}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int a;
    string resp;
    cin >> a;
    cin >> resp;
    if(a>=3200){
        cout << resp << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import scala.io.Source

object Main extends App {
  val lines: Iterator[String] = Source.stdin.getLines()
  val line = lines.next.split(" ").map(_.toInt)
  val a = line.head
  val b = line(1)

  val canvas: List[List[Int]] = lines.toStream
    .map(_.map(o => if (o == '#') 1 else 0).toList)
    .take(a)
    .toList

  def neigbs(i1: Int, i2: Int): List[(Int, Int)] = {
    List((i1 - 1, i2), (i1 + 1, i2), (i1, i2 - 1), (i1, i2 + 1))
      .filter(_._1 >= 0)
      .filter(_._1 < a)
      .filter(_._2 >= 0)
      .filter(_._2 < b)
  }

  def isValid(i1: Int, i2: Int, list: List[List[Int]]): Boolean = {
    if (list(i1)(i2) == 0) true else
    neigbs(i1, i2).map(t => list(t._1)(t._2)).contains(1)
  }

  val result = Stream.range(0, a - 1)
    .flatMap(i => Stream.range(0, b - 1).map((i, _)))
    .forall(t => isValid(t._1, t._2, canvas))

  println(if (result) "Yes" else "No")
}


Measured memory_bytes: 32604
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		double []v = new double[n];
		
		for(int i = 0; i < n ; i++) {
			v[i] = sc.nextDouble();
		}
		Arrays.sort(v);
		
		double ave = (v[0] + v[1])/2;
		
		for(int i = 2 ; i < n ; i++) {
			ave = (ave + v[i])/2;
		}
		System.out.println(ave);
		
		
		
	}

}


Measured memory_bytes: 22612
import math

N, D = map(int, input().split())
c = [list(input().split()) for _ in range(N)]

cnt = 0

for i in range(N):
  dis = math.sqrt(int(c[i][0]) ** 2 + int(c[i][1]) ** 2)
  if dis <= int(D):
    cnt += 1

print(cnt)

Measured memory_bytes: 51780
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int ans = 1;
    while(ans <= n){
        ans *= 2;
    }
    cout << ans / 2 << endl;
}

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

using namespace std;

long long N, M;

long long A[55];
long long B[55];
long long U[25];
long long V[25];

//条件i に違反するために白でならなければならない場所
long long state[55];

void dfs(long long pa, long long cur, long long idx, long long s) {
	if(V[idx] == cur) {
		state[idx] = s;
		return;
	}

	rep(i, N - 1) {
		if(A[i] == cur) {
			if(B[i] != pa)
				dfs(cur, B[i], idx, s | (1LL<<i));
		} else if (B[i] == cur) {
			if(A[i] != pa)
				dfs(cur, A[i], idx, s | (1LL<<i));
		}
	}
}


int main(){
	cin >> N;
	rep(i, N - 1) {
		cin >> A[i] >> B[i];
	}
	cin >> M;
	rep(i, M) {
		cin >> U[i] >> V[i];
		dfs(-1, U[i], i, 0);
	}
	long long ans = 0;

	rep(i, (1<<M)) {
		long long white = 0;
		long long zyokennum = 0;
		rep(j, M) {
			//かつ　j番目の条件を満たさない
			if((i>>j)&1) {
				white = white | state[j];
				zyokennum++;
			}
		}

		// white が 白だと 条件が満たされない
		long long whitenum = __builtin_popcountll(white);


		if(zyokennum%2 == 0) {
			ans += pow(2, N - whitenum - 1);
		} else {
			ans -= pow(2, N - whitenum - 1);
		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 4040
package main

import "fmt"

func main() {
	var N, x int
	fmt.Scan(&N, &x)
	if x == 1 || x == 2*N-1 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
		ans := make([]int, 2*N-1)
		x--
		for i := 0; i < 2*N-1; i++ {
			ans[(N+i-1)%(2*N-1)] = x + 1
			x++
			x %= 2*N - 1
			// log.Println(ans)
		}
		for i := 0; i < 2*N-1; i++ {
			fmt.Println(ans[i])
		}
	}
	return
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    priority_queue<int32> pq;
    REP(i,n){
        int32 a;
        cin >> a;
        pq.push(a);
    }
    REP(i,m){
        int32 a = pq.top();
        pq.pop();
        pq.push(a / 2);
    }
    int64 ans = 0;
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1400
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	std::set<Int> s;
	Int N, K; std::cin >> N >> K;
	rep(i, K) {
		Int d; std::cin >> d;
		rep(j, d) {
			Int A; std::cin >> A;
			s.insert(A);
		}
	}

	std::cout << N - s.size();

}


int main() {

	init();
	calc();

	return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<cstring> 
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int a=s1.length(),b=s2.length(),i,j;
    if(a>b)
    {
		for(i=0;i<s2.length();++i)
			cout<<s1[i]<<s2[i];
    	cout<<s1[i];
	}
	else
    	for(j=0;j<s1.length();++j)
    		cout<<s1[j]<<s2[j];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < 6; i++) {
    if (S[i] == '1') {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 1000000007
using namespace std;

typedef pair<int, int> P;

char s[5], t[5];

int main()
{
    scanf("%s", s);
    scanf("%s", t);
    int ans = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == t[i])
            ans++;
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
 
  int ans = 0;
  for (int i=0; i<1000; i++) {
	int d = to_string(i).size();
    string t(3-d, '0');
    t += to_string(i);

	std::string::size_type pos = -1;
    bool f = false;
    for (int i=0; i<3; i++) {
	  pos = s.find(t[i], pos+1);
      if (pos == string::npos)  break;
      if (i==2) f = true;
    }
    
    if (f) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3244
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}
int main(){
    ll n;
    cin>>n;
    map<ll,ll> res=factorize(n);
    ll ans=1;
    for(auto &p:res){
        ans*=(p.fi-1);
        n/=p.fi;
    }
    cout<<ans*n<<"\n";
}



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

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

    int N;
    cin>>N;
    char c[N];
    for(int i=0;i<N;++i)
        cin>>c[i];




    int K;
    cin>>K;
    for(int i=0;i<N;++i){
        if(c[i]==c[K-1])
            cout<<c[i];
        else
            cout<<"*";
    }
    cout<<endl;
}


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

using namespace std;

typedef long long int lli;

int main() {
    int n; cin >> n;
    vector<lli> hs(n, 0);
    for (int i = 0; i < n; i++) { cin >> hs[i]; }
    bool ans = true;
    hs[0] = hs[0] - 1;
    for (int i = 1; i < n; i++) {
        if (hs[i-1] < hs[i]) {
            hs[i]--;
        }
        if (hs[i-1] > hs[i]) {
            ans = false;
            break;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> light(N);
  for(int i=0;i<N;i++)
    cin >> light.at(i);
  int on = 1;
  int count = 0;
  for(int i = 0;i < N;i++){
    on = light.at(on-1);
    count++;
    if(on == 2)
      break;
  }
  if(on == 2)
    cout << count << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 640
import itertools

a = list(map(int,(input().split(' '))))
c = list(itertools.combinations(a, 2))
#b = int(input())
#h = int(input())
#print(c)
a.sort()

if a[0]+a[1] == a[2]:
  print('Yes')
else :
  print('No')
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<string>
#define fn(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<n;i++)
#define ll long long
#define wh while
#define pb push_back
#define sc(n) scanf("%lld",&n)
#include <vector>
#define N 100100

using namespace std; 

int main() {
    ll x,y;sc(x);sc(y);
    ll ans=0;
    while(x<=y)
    {
        ans++;
        x*=2;
    }
    
	cout<<ans<<endl;
        
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);

  rep(i,n) cin >> a[i];
  int s = 0;
  rep(i,n) s += a[i];
  int cnt = 0;
  rep(i,n){
    if (a[i]*(4*m) >= s) cnt++;
  }
  // cnt: count
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
  cout << "No" << endl;
  }
  return 0;
};

Measured memory_bytes: 256
<?php
	$s=fgets(STDIN);
	$c=[];
	for($i=0;$i<26;$i++)$c[]=0;
	for($i=0;$i<strlen($s)-1;$i++)$c[ord($s[$i])-97]++;
	$f=0;
	for($i=0;$i<26;$i++)$f+=$c[$i]%2;
	echo $f?No:Yes;


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010, p = 998244353;
ll bin_pow(ll v, ll t) {
	ll res = 1;
	for (;t;t >>= 1, v = v * v % p)
		if (t&1) res = res * v % p;
	return res;
}
#define int ll
int n, m, k;
ll res;
ll a[maxn];
ll fa[maxn], fainv[maxn], inv[maxn];
void init() {
	fa[0] = fainv[0] = fa[1] = fainv[1] = inv[1] = inv[0] = 1;
	for (int i = 2;i < maxn;++i) {
		fa[i] = fa[i-1] * i % p;
		inv[i] = (p - p / i) * inv[p % i] % p;
		fainv[i] = inv[i] * fainv[i-1] % p;
	}
}
ll C(int a, int b) {
	if (a < b) return 0;
	if (b == 0) return 1;
	return fa[a] * fainv[b] % p * fainv[a - b] % p;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	init();
	cin >> n >> m >> k;
	a[0] = 1;
	a[1] = m;
	for (int i = 2;i <= n;++i) 
		a[i] = a[i-1] * (m-1) % p;
	for (int i = 0;i <= k;++i) {
		int in = n - i;
		res += a[in] * C(in-1+i, i);
		res %= p;
	}
	cout << res << '\n';
}


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



namespace CSharpSample01
{

    
      
    class Program
    {
        
        static void Main(string[] args)
        {
            //入力1(S)
            string S = Console.ReadLine();

            string T = Console.ReadLine();

            int cnt = 0;

            for(int i = 0; i < 3; i++)
            {
                if(S[i] == T[i])
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);

            
        }
    }

}

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
 
bool IsPrime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if(n % i == 0) {
                    return false;
        }
    }
    return true;
}
 
int main(void) {
    int count = 0, n;
    cin >> n; 
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (IsPrime(p)) {
            count++;
            }
    }
    cout << count << endl;
    return 0;
}




Measured memory_bytes: 3036
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
			var inputArray = retreiveLongArray();
			var inputCount = 3;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			double a = inputArray[0];
			double b = inputArray[1];
			double x = inputArray[2];

			var taikaku = Math.Sqrt(a * a + b * b);
			var bunkiten = a * a * b / 2;

			if (x == bunkiten) {
				var answer = getAngleFromTangent(a / b);
				Console.WriteLine(answer);
				return;
			}


			var ans = x > bunkiten ? getMore(a, b, x) : getLess(a, b, x);

			//答えの出力
			Console.WriteLine(ans);
		}

		/// <summary>
		/// 分岐点より水の量が多い場合
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <param name="x"></param>
		/// <returns></returns>
		private static double getMore(double a, double b,double x) {

			var remain = a * a * b - x;

			if (remain == 0) {
				return 0;
			}

			var height = remain * 2 / (a * a);

			var angle = getAngleFromTangent(height / a);
			return angle;

		}

		/// <summary>
		/// 分岐点より水の量が少ない場合
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <param name="x"></param>
		/// <returns></returns>
		private static double getLess(double a, double b, double x) {

			if (x == 0) {
				return 90;
			}

			var height = x * 2 / (a * b);

			var angle = getAngleFromTangent(b / height);
			return angle;

		}


		/// <summary>
		/// タンジェントから360度の角度を求める
		/// </summary>
		/// <param name="tangent"></param>
		/// <returns></returns>
		private static double getAngleFromTangent(double tangent) {
			var radian = Math.Atan(tangent);
			var kakudo = radian * 180 / Math.PI;
			return kakudo;
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[1100][1100];
int dp[1100][1100];
int ans[1100][1100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",in[i]);
	}
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)ans[i][j]=mod;

	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			int tmp=mod;
			if(in[i][j]=='#')tmp=0;
			if(i)tmp=min(tmp,dp[i-1][j]+1);
			if(j)tmp=min(tmp,dp[i][j-1]+1);
			dp[i][j]=tmp;
			ans[i][j]=min(ans[i][j],dp[i][j]);
		}
	}
	for(int i=0;i<a;i++){
		for(int j=b-1;j>=0;j--){
			int tmp=mod;
			if(in[i][j]=='#')tmp=0;
			if(i)tmp=min(tmp,dp[i-1][j]+1);
			if(j<b-1)tmp=min(tmp,dp[i][j+1]+1);
			dp[i][j]=tmp;
			ans[i][j]=min(ans[i][j],dp[i][j]);
		}
	}
	for(int i=a-1;i>=0;i--){
		for(int j=0;j<b;j++){
			int tmp=mod;
			if(in[i][j]=='#')tmp=0;
			if(i<a-1)tmp=min(tmp,dp[i+1][j]+1);
			if(j)tmp=min(tmp,dp[i][j-1]+1);
			dp[i][j]=tmp;
			ans[i][j]=min(ans[i][j],dp[i][j]);
		}
	}
	for(int i=a-1;i>=0;i--){
		for(int j=b-1;j>=0;j--){
			int tmp=mod;
			if(in[i][j]=='#')tmp=0;
			if(i<a-1)tmp=min(tmp,dp[i+1][j]+1);
			if(j<b-1)tmp=min(tmp,dp[i][j+1]+1);
			dp[i][j]=tmp;
			ans[i][j]=min(ans[i][j],dp[i][j]);
		}
	}	
	int ret=0;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)ret=max(ret,ans[i][j]);printf("%d\n",ret);
}

Measured memory_bytes: 10624
package main

import (
	"fmt"
	"strconv"
)


func score(A []int, a []int, b []int, c []int, d []int) int {
	score := 0
	for i := 0; i < len(a); i++ {
		if A[b[i]-1]-A[a[i]-1] == c[i] {
			score += d[i]
		}
	}
	return score
}
var max int
var memo map[string]bool
var N int
var M int
func memocheck (A []int) bool{
	n := len(A)
	set := ""
	for i:= 0; i<n; i++{
		set = set + strconv.Itoa(A[i])
	}
	if ok := memo[set]; ok{
		return memo[set]
	} else {
		memo[set] = true
		return false
	}
}
func dfs (A []int, a []int,b []int,c []int,d []int) {
	n := N
	point := score(A,a,b,c,d)
	if (point > max) {
		max = point
	}
	if memocheck(A) {
		return
	}
	//fmt.Printf("check", A,max)
	//fmt.Println("")
	for i := 0; i< n-1; i++ {
		 if(A[i]+1 <= A[i+1]) && A[i]+1 <= M {
			 prA := []int{}
		 	for j:=0; j<n; j++ {
		 		if i == j {
					prA = append(prA,A[j]+1)
				} else {
					prA = append(prA,A[j])
				}
			}
				// prA = append(prA,A[i]+1)
			//for j:= i+1; i<n; i++ {
			//	prA = append(prA,A[j])
			//}
		 	dfs(prA,a,b,c,d)
		 }
	}

	if (A[n-1]+1 <= M) {
		prA := []int{}
		for j:=0; j<n-1; j++ {
			prA = append(prA,A[j])
		}
		prA = append(prA, A[n-1]+1)
		dfs(prA,a,b,c,d)
	}
}

func main() {
	var Q int
	fmt.Scan(&N,&M,&Q)
	max = 0
	memo = map[string]bool{}
	a := make([]int, Q)
	b := make([]int, Q)
	c := make([]int, Q)
	d := make([]int, Q)
	result :=  make([]int, N)
	for i := 0; i < Q; i++ {
		fmt.Scan(&a[i],&b[i],&c[i],&d[i])
	}
	for i := 0; i < N; i++ {
		result[i] += 1
	}
	dfs(result,a,b,c,d)
	fmt.Println(max)
}

Measured memory_bytes: 21392
import java.math.BigDecimal
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    readLine()
    var matelials = readLine()!!.split(" ").map { it.toInt() }.sorted()
        .map { Material(BigDecimal(it)) }.toMutableList()

    while (matelials.size > 1) {
        val a = matelials[0]
        val b = matelials[1]
        val c = a.mix(b)
        matelials.add(c)
        matelials = matelials
            .subList(2, matelials.size)
            .sortedWith(compareBy { it.value })
            .toMutableList()
    }

    print(matelials[0].value)
}

val two = BigDecimal(2)

data class Material(val value: BigDecimal) {
    fun mix(other: Material): Material {
        return Material(
            this.value.add(other.value).divide(two)
        )
    }
}


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

int res,res2,res3;
int a,b,c,x,y;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	res=c*2*min(x,y);
	res+=a*(x-min(x,y));
	res+=b*(y-min(x,y));
	res2=c*2*max(x,y);
	res3=a*x+b*y;
	printf("%d\n",min(res,min(res2,res3)));
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, h = [int(x) for x in input().split()]
    t = [int(x) for x in input().split()]
    total = 0
    off = 0
    for e in t:
        if e >= off:
            total += h
        else:
            total += h - (off - e)
        off = e + h
            
    print(total)
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""


Measured memory_bytes: 31568
#include<bits/stdc++.h>
#define pb push_back
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto i : x){cerr << " [" << i << "]";} cerr << "\n";
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vii = vector<pii>;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int a, b, c;
	cin >> a >> b >> c;
	cout << min({a + b, a + c, b + c}) << "\n";
	return 0;
}
 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Point{
public:
	int x,y;
	Point(){}
	Point( int dx, int dy ) : x( dx ), y( dy ) {}
};

Point place[7][4] = { { Point( 0, 0 ), Point( 1, 0 ), Point( 0, 1 ), Point( 1, 1 ) },
	{ Point( 0, 0 ), Point( 0, 1 ), Point( 0, 2 ), Point( 0, 3 ) },
	{ Point( 0, 0 ), Point( 1, 0 ), Point( 2, 0 ), Point( 3, 0 ) },
	{ Point( 0, 0 ), Point( 0, 1 ), Point( -1, 1 ), Point( -1, 2 ) },
	{ Point( 0, 0 ), Point( 1, 0 ), Point( 1, 1 ), Point( 2, 1 ) },
	{ Point( 0, 0 ), Point( 0, 1 ), Point( 1, 1 ), Point( 1, 2 ) },
	{ Point( 0, 0 ), Point( 1, 0 ), Point( 0, 1 ), Point( -1, 1 ) } };

int main(int argc, char const* argv[])
{
	char data[10][10];

	while( true ){
		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				data[i][j] = 0;
			}
		}


		for( int i = 0;i < 8;i++ ){
			if( !( cin >> data[i] ) ) return 0;
		}

		int answer = 0;
		for( int i = 0;i < 8;i++ ){
			for( int j = 0;j < 8;j++ ){
				if( data[i][j] == '1' ){
					for( int k = 0;k < 7;k++ ){
						if( data[i + place[k][0].y][j + place[k][0].x] == '1' &&  data[i + place[k][1].y][j + place[k][1].x] == '1' && data[i + place[k][2].y][j + place[k][2].x] == '1' && data[i + place[k][3].y][j + place[k][3].x] == '1' ){
							answer = k;
							goto END;
						}
					}
				}
			}
		}
END:

		cout << static_cast<char>( 'A' + answer ) << endl;
	}


	return 0;
}

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

/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/

int sc1() {int x; scanf("%d", &x); return x;}

long long sc2() {long long x; scanf("%lld", &x); return x;}



#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>


const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}




int solve() {

    char x;
    cin>>x;
    cout<<(char)((int)x+1)<<endl;

	return 0;
}




int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}

	return 0;




}


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

const ll INF = 1e18;

int main() {
	int n;
	cin >> n;
	vector<vector<ll>> a(n, vector<ll>(n));
	rep(i, n) rep(j, n) cin >> a[i][j];
	vector<vector<bool>> ok(n, vector<bool>(n, true));
	rep(k, n) rep(i, n) rep(j, n) {
		if (i != k && k != j && a[i][j] == a[i][k] + a[k][j]) {
			ok[i][j] = false;
		}
		if (a[i][j] > a[i][k] + a[k][j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	rep(i, n) rep(j, n) {
		if (ok[i][j]) ans += a[i][j];
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
 
using namespace std;
long long int INF = 1e9 + 7;

int main()
{
    long long int n,m,ans=0;
    cin>>n>>m;

    for(long long int i = m;i<=n+1;i++)
    {
        long long int minVal = ((i-1) * (i))/2;
        long long int maxVal = (n * (n+1))/2;
        maxVal -= ((n-i) * (n-i+1))/2;

        //cout<<maxVal<<endl;
        //cout<<minVal<<endl;
        ans = (ans + maxVal -minVal + 1)%INF;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */
pair<int, int> dfs(int c, vector<vector<int>> &g, vector<int> &used, int cur, int par = -1) {
  int b = 0;
  int w = 0;
  if (c == 0) b++;
  else w++;
  used[cur] = c;
  int nc = (c + 1) % 2;

  for (auto nxt : g[cur]) {
    if (nxt == par) continue;

    if (used[nxt] == -1) {
      int bb;
      int ww;
      tie(bb, ww) = dfs(nc, g, used, nxt, cur);
      if (bb == -1) return {-1, -1};
      b += bb;
      w += ww;
    } else {
      if (used[nxt] == c) {
        return {-1, -1};
      }
    }
  }

  return {b, w};
}

int main() {
  
  int n, m; cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--;
    b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }

  int cm = 0;
  vector<vector<int>> cg(n);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (g[i][j] == 0) {
        cm++;
        cg[i].push_back(j);
        cg[j].push_back(i);
      }
    }
  }


  // 連結成分ごとに二分彩色する
  vector<pair<int, int>> cnt;
  vector<int> used(n, -1);
  for (int i = 0; i < n; i++) {
    if (used[i] == -1) {
      int b, w;
      tie(b, w) = dfs(0, cg, used, i);
      cnt.emplace_back(b, w);
      if (b == -1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  /*for (int i = 0; i < cnt.size(); i++) {
    cerr << cnt[i].first << " " << cnt[i].second << endl;
  }*/

  // dp[pos][赤の個数] := true / false
  vector<vector<bool>> dp(cnt.size() + 1, vector<bool>(n + 1, false));
  dp[0][0] = true;

  lint ans = -INF; // 最大化する

  for (int i = 0; i < cnt.size(); i++) {
    for (int j = 0; j <= n; j++) {
      if (!dp[i][j]) continue;
      dp[i + 1][j + cnt[i].first] = true;
      dp[i + 1][j + cnt[i].second] = true;
    }
  }

  for (int i = 0; i <= n; i++) {
    if (dp[cnt.size()][i]) {
      lint tmp = i * (n - i) - cm;
      ans = max(ans, tmp);
    }
  }

  cout << m - ans << endl;

  return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int sum[100010];
int main()
{
	int N, Q;
	string S;
	cin >> N >> Q >> S;
	for (int i = 1; i < N; i++) {
		sum[i] = sum[i - 1];
		if (S[i] == 'C' && S[i - 1] == 'A') sum[i]++;
	}
	while (Q--) {
		int l, r;
		cin >> l >> r;
		cout << sum[r - 1] - sum[l - 1] << endl;
	}
}

Measured memory_bytes: 4148
n = int(input())
li = [int(i) for i in input().split()]
a = 1
ans = 0
for i in range(n):
  if li[i] != a:
    ans += 1
  else:
    a += 1

if ans == n:
  print(-1)
elif ans == 0 and a == n+1:
  print(0)
else:
  print(ans)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;


int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    int fr[N];
    int g = 0;
    memset(fr, 0, sizeof fr);
    for (int i = 0; i < n; i++) {
        int e;
        cin >> e;
        fr[e]++;
        g = __gcd(g, e);
    }

    int cs = 1;
    for (int i = 2; i < N; i++) {
        int mul = 0;
        for (int j = i; j < N; j += i) {
            mul += fr[j];
        }
        if (mul > 1) {
            cs = 0;
            break;
        }
    }

    if (cs) {
        cout << "pairwise coprime";
        return 0;
    }

    cout << (g == 1 ? "setwise coprime" : "not coprime");

}

Measured memory_bytes: 7532
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int N;
ll A[4010];
ll dp[4010][4010];
ll rec(int l,int r)
{
	if(l>r)return 0ll;
	if(l==r)return A[l];
	if(dp[l][r]!=-1)return dp[l][r];
	ll res;
	ll eat_l,eat_r;
	if(A[l+1]<A[r])eat_l = rec(l+1,r-1)+A[l];
	else eat_l = rec(l+2,r)+A[l];
	if(A[l]<A[r-1])eat_r = rec(l,r-2)+A[r];
	else eat_r = rec(l+1,r-1)+A[r];
	res = max(eat_l,eat_r);
	return dp[l][r]=res;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%lld",&A[i]);
	for(int i=0;i<N;i++)A[i+N]=A[i];
	ll ans = 0ll;
	for(int i=0;i<N;i++)
	{
		//printf("%lld\n",rec(i,i+N-1));
		ans = max(ans,rec(i,i+N-1));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 126764
def main():
    e = raw_input().split()
    t = list()

    for i in e:
        if i == '+': t.append(t.pop() + t.pop())
        elif i == '-': t.append(-(t.pop()) + t.pop())
        elif i == '*': t.append(t.pop() * t.pop())
        else: t.append(int(i))

    print(t.pop())
main()

Measured memory_bytes: 4216
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 100000000000000

int main(){
  int a,b;
  cin >> a >> b;
  cout << max(a-2*b,0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    ri(N); ri(X);
    if (X == 1 || X == 2*N-1) {
        cout << "No" << endl;
    } else {
        cout << "Yes\n";
        if (X <= N) {
            for (int i = X+N; i < 2*N; i++) {
                cout << i << '\n';
            }
            for (int i = 1; i < X+N; i++) {
                cout << i << '\n';
            }
        } else {
            for (int i = X-N+1; i < 2*N; i++) {
                cout << i << '\n';
            }
            for (int i = 1; i < X-N+1; i++) {
                cout << i << '\n';
            }
        }
    }
}


Measured memory_bytes: 1536
import java.util.*;
import java.util.stream.IntStream;

public class Main {
        static boolean[][] f;
        static  int[][] p;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        f = new boolean[n][10];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                f[i][j] = scan.nextInt() == 1;
            }
        }
        p = new int[n][11];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 11; j++) {
                p[i][j] = scan.nextInt();
            }
        }
        
        int ret = Integer.MIN_VALUE;
        for (int i = 1; i < 1024; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += score(j, i);
            }
            ret = (ret > sum)? ret : sum;
        }
        System.out.println(ret);
    }

    private static int score(int mise, int i) {
        int num = 0;
        for (int j = 0; j < 10; j++) {
            if ((i & (1 << j)) > 0 && f[mise][j]) {
                num++;
            }
        }
        return p[mise][num];
    }
}

Measured memory_bytes: 27152
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>n;
    if(n==22) cout<<"Christmas Eve Eve Eve";
    if(n==23) cout<<"Christmas Eve Eve";
    if(n==24) cout<<"Christmas Eve";
    if(n==25) cout<<"Christmas";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256