akhauriyash/Code-Regression huggingface dataset:
N = int(input())
#a = [int(i) for i in input().split()]
#s = [[int(j) for j in input().split()] for i in range(N)]

SUM = 0
a = [0 for i in range(10000)]
for i in range(1,10000):
    SUM+=i
    a[i] = SUM
    if N<=SUM:
        tmp = 0
        for j in range(i,-1,-1):
            print(j)
            N-=j
            if a[j-2]==N:
                tmp = j-1
                break
        for j in range(1,tmp):
            print(j)
        break


Measured memory_bytes: 3572
/* ex6_2
   YSK722 */

#include <stdio.h>
#include <string.h>
#define SIZE 200

int main(void){
    int len;
    char word[SIZE];
    // 文字列入力
    fgets(word, SIZE, stdin);
    // 文字列の長さを調べる(null文字も含む)
    len = strlen(word);
    /* 1文字目を出力し、
       1文字目と最後の文字とnull文字を除いた文字数を出力し、
       null文字の1つ前の文字を出力 */
    printf("%c%d%c\n", word[0], len - 3, word[len - 2]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
ll n,k,r,s,p;
string t;
cin >> n >> k;
cin >> r >> s >> p;
cin >> t;
ll ans = 0;
string a;
rep(i,k) {
  if (t[i] == 'r') {
    ans += p;
    a.push_back('p');
  } else if (t[i] == 's') {
    ans += r;
    a.push_back('r');
  } else if (t[i] == 'p') {
    ans += s;
    a.push_back('s');
  }
}
for (int i = k;i < n;i++) {
  if (t[i] == 'r') {
    if(a[i-k] != 'p') {
    ans += p;
    a.push_back('p');
    } else a.push_back('a');
  } else if (t[i] == 's') {
    if (a[i-k] != 'r') {
    ans += r;
    a.push_back('r');
    } else a.push_back('a');
  } else if (t[i] == 'p') {
    if (a[i-k] != 's') {
    ans += s;
    a.push_back('s');
    } else a.push_back('a');
  }
}

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



Measured memory_bytes: 3692
n=int(input())
P=list(map(int,input().split()))
if P==list(range(1,n+1)):
    print('YES')
else:
    for i in range(n-1):
        for j in range(i,n):
            Q=P[:]
            Q[i]=P[j]
            Q[j]=P[i]
            if Q==list(range(1,n+1)):
                print('YES')
                exit()
    print('NO')

Measured memory_bytes: 39280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<cctype>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repp(i,j,n) for (int i = (j); i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll ans = min(b - 1, n);
	cout << (a*ans) / b << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;


int main()
{
    ll N;
    cin >> N;
    vector<ll> D(N);
    REP(i, N) cin >> D[i];
    if (D[0] != 0) {
        PRINT(0);
        return 0;
    }
    map<ll, ll> m;
    REP(i, N) m[D[i]]++;
    ll ans = 1;
    FOR(i, 1, N) {
        ans *= m[D[i]-1];
        ans %= 998244353;
    }
    PRINT(ans);
    return 0;
}


Measured memory_bytes: 7296
from copy import deepcopy

n, k = map(int, input().split())
As = list(map(int, input().split()))

for _ in range(k):
    if sum(As) == n * n:
        break
    Bs = [0] * n
    for i in range(n):
        l = max(0, i - As[i])
        r = min(n - 1, i + As[i])
        Bs[l] += 1
        if r + 1 < n:
            Bs[r + 1] -= 1
    for i in range(1, n):
        Bs[i] += Bs[i - 1]
    As = Bs

print(" ".join(map(str, As)))


Measured memory_bytes: 144816
#include<iostream> 
long long a,b,x;
long long s,e;
int main(){
    std::cin>>a>>b>>x;
    if(a%x==0)s=a/x;
    else s=a/x+1;
    e=b/x;
    std::cout<<e-s+1;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 123451

int main(){
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int x3 = x2 - x1, y3 = y2 - y1;
        printf("%d %d %d %d", (x2 - y3), (y2 + x3), (x1 - y3), (y1 + x3));
        return 0;
}




Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, h: IntArray){
    fun recSum(target: List<Int>): Int = when(target.size){
        0 -> 0
        1 -> target[0]
        else -> {
            val m = target.min()!!
            val k = target.indexOf(m)!!
            m + recSum(target.take(k).map{ it -m }) +recSum(target.drop(k+1).map{ it-m })
        }
    }
    println(recSum(h.toList()))
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val h = IntArray(N)
    for (i in 0 until N) {
        h[i] = sc.next().toInt()
    }
    solve(N, h)
}



Measured memory_bytes: 33968
#include <bits/stdc++.h>
using namespace std;
int main (){
    long long n,countv=0,countu=0,sumv=0,sumu=0;
    cin >> n;
    //条件はSi*Si+1<0(0<=i<=n-1)
    //和の符号は、最初が正と負の２パターンある
    //最適パターン→貪欲(部分最適解の積み重ね）
    
    //★ある地点まで和の条件を満たすなら、そこまで変えない
    //(変えても変えなくても最適解が得られることが実験でわかる)
    //目的をもって実験しよう
    

    vector<long long> v(n),u(n);
    for(long long i=0;i<n;i++){
        cin >> v.at(i);
        u.at(i)=v.at(i);
    }
    //vで先頭正、uで先頭負を調べる

    for(long long j=0;j<n;j++){
        sumv += v.at(j);
        if(j%2 == 0){
            while(sumv <= 0){
                sumv++;
                countv++;
            }
        }
        else{
            while(sumv >= 0){
                sumv--;
                countv++;
            }
        }
    }

     for(long long j=0;j<n;j++){
        sumu += u.at(j);
        if(j%2 == 0){
            while(sumu >= 0){
                sumu--;;
                countu++;
            }
        }
        else{
            while(sumu <= 0){
                sumu++;
                countu++;
            }
        }
    }
    
    cout << min(countv,countu) << endl;
}

Measured memory_bytes: 1792
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()

mas = []
for i in range(H):
    row = s()
    if row == '.' * W:
        continue
    mas.append(row)

rmas = ['' for i in range(W)]
for row in mas:
    for i in range(W):
        rmas[i] += row[i]

res = []
for row in rmas:
    if row == '.' * len(mas):
        continue
    res.append(row)

for i in range(len(mas)):
    row = ''
    for j in range(len(res)):
        row += res[j][i]
    print(row)



Measured memory_bytes: 3064
a1=int(input())
a2=input()
res1=[i for i in a2.split()]
res=[i for i in a2.split()]
for x in res:
    if int(x)<1 or int(x)>1000:
        res.remove(x)
empty=0
sum_all=0
if 1<=a1<=100:
    if len(res1)==len(res):
        for x in res:
            empty=sum_all
            sum_all=empty+(1/int(x))
        print((1/sum_all))

Measured memory_bytes: 9200
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque()
for i in a:
  b.append(i)
c=0
for i in range(n):
  if i%2==0:
    c+=a[i]
  else:
    c-=a[i]
print(c)
for i in range(n-1):
  c=-c+2*b.popleft()
  print(c)

Measured memory_bytes: 14404
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;
typedef long long ll;
bool sol(vector<ll> v) {
    int d = v[1] - v[0];
    for (int i = 0; i < v.size(); i++) {
        if (v[i] != v[0]+d*i) return false;
    }
    return true;
}
int main() {
    while(1) {
        int n;
        cin >> n;
        if (!n) break;
        ll d[200];
        vector<ll> v[200];
        for (int i = 0; i <= n; i++) {
            cin >> d[i];
            for (int j = 0; j <= n; j++) {
                if (i == j) continue;
                v[j].push_back(d[i]);
            }
        }
        for (int i = 0; i <= n; i++) {
            if (sol(v[i])) {
                cout << d[i] << endl;
                break;
            }
        }
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

int main(){
    int n;
    cin >> n;
    int tmp;
    map<int,int> mp;
    for(int i=0; i<n; ++i){
        cin >> tmp;
        mp[tmp]++;
    }
 
    vector<int> v(3,0),v2(3,0);
    int i = 0;
    int size = mp.size();
    if(size == 3){
        for(auto e : mp){
            v[i] = e.first;
            v2[i] = e.second;
            i++;
        }
    }
 
    if(mp[0] == n){
        cout << "Yes" << endl;
        return 0;
    }else if(mp[0] * 3 == n && size == 2){
        cout << "Yes" << endl;
        return 0;
    }else if(size == 3){
        if((v2[0] == v2[1] && v2[1] == v2[2]) && ((v[0] ^ v[1]) ^ v[2]) == 0)  {
            cout << "Yes" << endl;
            return 0;
        }
    }
 
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 7016
#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, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i,n) {
        rep(j,d) cin >> x[i][j];
    }
    int ans = 0;
    rep(i,n)rep(j,i) {
        int sq = 0;
        rep(k,d) {
            int s = x[i][k]-x[j][k];
            sq += s*s;
        }
        int s = sqrt(sq)+0.5;
        if (s*s == sq) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  string s,t;
  cin >> s >> t;
  if(s==t) {
    cout << "Yes" << endl;
    return 0;
  }
  bool ok = false;
  for(int i = 1; i < s.size(); ++i){
    string u = s.substr(i)+s.substr(0,i);
    if(u==t) {
      ok=true;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
  string S;
  cin>>S;
  long long ans=0;
  if(S.size()==1){//Sが一文字（＋を入れられない）とき
    ans+=stoi(S);
    cout<<ans<<endl;
    return 0;
  }
  //それ以外
  for(int i=0;i<(1<<S.size()-1);++i){//2のS.size()-1乗パターン。＋の有無をbitで管理。
    int x = 0;//位置
    long long sum = 0;
    rep(j,S.size()-1){
      if(i&(1<<j)){//j番目のフラグがたっているかどうか（＋を入れるかどうか）
        sum += stoll(S.substr(x, j-x+1));//stollは、string=>long longへの変換。
        x += j-x+1;
      }
    }
    sum += stoll(S.substr(x,S.size()-x));
    ans += sum;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    char ch[10];
    scanf("%s", ch,10);
    int tmp=0,ans = 0;
  
  int i=0;
	while(ch[i] != '\0'){
	    if(ch[i]=='A' ||ch[i]=='G' ||ch[i]=='T' ||ch[i]=='C'){
	        tmp+=1;
	        ans=max(ans,tmp);
	    }
	    else tmp=0;
		i++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,k;
	cin >> n >> k;
	map<int,bool> mp;
	for(int i = 0;i < n;i++)mp[i] = false;
	for(int i = 0;i < k;i++){
		int d;
		cin >> d;
		for(int j = 0;j < d;j++){
			int a;
			cin >> a;
			a--;
			mp[a] = true;
		}
	}

	int ans = 0;
	for(int i = 0;i < n;i++){
		if(mp[i] == false)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
long long int knapsack_dp(long long int n, long long int M, long long int w[],long long int p[])
{
    int i,j;
    long long int knapsack[n+1][M+1];
 
   
    for(j=0;j<=M;j++)
        knapsack[0][j]=0;
    for(i=0;i<=n;i++)
        knapsack[i][0]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=M;j++)
        {
            //check if the weight of current item i is less than or equal to the capacity of sack,
            //take maximum of once including the current item and once not including
            if(w[i-1]<=j)
            {
                knapsack[i][j]=max(knapsack[i-1][j],p[i-1]+knapsack[i-1][j-w[i-1]]);
            }
 
            //can not include the current item in this case
            else
            {
                knapsack[i][j]=knapsack[i-1][j];
            }
        }
    }
 
 
    return knapsack[n][M];
 
 
}
 
int main()
{
    int i,j;
    long long int n;
    long long int M;  cin>>n;cin>>M;
    long long int w[n];
    long long int p[n];  
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>p[i];
    }
  long long int result=knapsack_dp(n,M,w,p);
  cout<<result;
  return 0;
}


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

using namespace std;

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


int main(){
  string s;
  cin >> s;
  vector<int> v(26, 0);
  rep(i, s.size()){
    if(v[s[i] - 'a'] > 0){
      cout << "no" << endl;
      return 0;
    }
    v[s[i] - 'a']++;
  }
  cout << "yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
const long long inf = 1LL << 60;
vector<long long> IL(int n) {
    vector<long long> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}
vector<string> IS(int n) {
    vector<string> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}

void PA(vector<long long> vec) {
    for (int i=0; i<vec.size()-1; i++) cout << vec.at(i) << " ";
    cout << vec.at(vec.size()-1) << endl;
    return;
}
map<long long, long long> CL(vector<long long> vec) {
    map<long long, long long> count;
    for (long long x: vec) {
        count[x] += 1;
    }
    return count;
}

map<string, long long> CS(vector<string> vec) {
    map<string, long long> count;
    for (string s : vec) {
        count[s] += 1;
    }
    return count;
}


int main() {
    using ll = long long;
    using vl = vector<long long>;


    

    int n, m; cin >> n >> m;
    vl w(n+1);
    vl v(n+1);

    for (int i=1; i<n+1; i++) {
        cin >> w[i] >> v[i];
    }

    vector<vector<long long>> dp(n+1, vector<long long>(m+1));

    for (int i=0; i<n; i++) {
        for (int j=0; j<m+1; j++) {
            if (j<w[i+1]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i+1]] + v[i+1]);
            }
        }
    }

    cout << dp[n][m] << endl;



}


Measured memory_bytes: 83132
#include <stdio.h>

int main(void) {
	long long n, k, i, mod = 1000000007, sum=0;
	scanf("%lld %lld", &n, &k);
	for(i=k; i<=n+1; i++)
	{
		sum += i*n - i*i + i + 1;
		sum %= mod;
	}
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 1732
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int []cnt=new int[101];
		int i,max=0;
		while(sc.hasNextInt()){
			 int count=sc.nextInt();
			 cnt[count]++;
			 if(max<cnt[count])max=cnt[count];
		}
		for(i=0;i<cnt.length;i++){
			if(cnt[i]==max){System.out.println(i);}
		}
	}
}

Measured memory_bytes: 18160
#include <cstdio>
#include <cctype>
using namespace std;
typedef long long ll;
void Read(int &x){
    static char c;
    while(!isdigit(c=getchar()));
    x=(c^48);
    while(isdigit(c=getchar()))
        x=x*10+(c^48);
    return;
}
void Print(int x){
    static int i;
    for(i=1;i*10LL<=x;i*=10);
    for(;i;i/=10)
        putchar(x/i%10|48);
    putchar('\n');
    return;
}
int main(){
    int a,b;
    Read(a);
    Read(b);
    Print(a*b);
    return 0;
}

Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
#include<cmath> 
using namespace std;
const int maxn=1e5+5;
//int a[maxn];
long long dp[2][maxn];
long long cp[2][maxn];  
long long x[maxn], v[maxn];
int main()
{
	long long n,c,sum;
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++) 
	scanf("%lld%lld",&x[i],&v[i]); 
	for (int i=0;i<=n+1;i++)
	dp[0][i]=dp[1][i]=-0x3f3f3f3f;
	for(int i=1;i<=n;i++) 
	{ 
        sum+=v[i];    
        dp[0][i]=max(dp[0][i-1],sum-x[i]);  
        cp[0][i]=sum-2*x[i];  
    }  
    sum=0;  
    for(int i=n;i>=1;i--) 
	{ 
        sum+=v[i];  
        dp[1][i]=max(dp[1][i+1],sum-(c-x[i]));  
        cp[1][i]=sum-2*(c-x[i]);  
    }  
    long long ans=max(dp[0][n],dp[1][1]);  
    for(int i=1;i<=n;i++) 
	{  
        ans=max(ans,cp[0][i]+dp[1][i + 1]);  
        ans=max(ans,cp[1][i]+dp[0][i - 1]);  
    }  
    printf("%lld\n", ans>0?ans:0);   
} 

Measured memory_bytes: 4992
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }

int main()
{
  int a,b;
  cin >> a >>b;
  cout << max(a+b,max(a-b,a*b)) <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> pii;
int main(){
int n,i,sum=0,total=0;
cin>>n;
int arr[n];
for(i=0;i<n;i++){
  cin>>arr[i];
  sum+=arr[i];
}
for(i=0;i<n;i++){
  sum-=arr[i];
total+=(arr[i]*sum);
}
cout << total<<endl;








}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1 << 28;
const ll MOD = 1000000007LL;

using Graph = vector< vector<int> >;
int dist[100010][3];

int main() {
    int N, M; cin >> N >> M;
    Graph G(N);
    for(int i=0; i<M; i++) {
        int u, v; cin >> u >> v; u--; v--;
        G[u].emplace_back(v);
    }

    fill(dist[0], dist[N], INF);
    int S, T; cin >> S >> T; S--; T--;

    queue< pair<int, int> > que;
    dist[S][0] = 0;
    que.emplace(S, 0);

    while(que.size()) {
        int cur, mod; tie(cur, mod) = que.front(); que.pop();
        int nmod = (mod + 1) % 3;
        for(auto to : G[cur]) {
            if(dist[to][nmod] > dist[cur][mod] + 1) {
                dist[to][nmod] = dist[cur][mod] + 1;
                que.emplace(to, nmod);
            }
        }
    }

    int ans = dist[T][0];
    if(ans == INF) cout << -1 << endl;
    else cout << ans / 3 << endl;
    return 0;
}


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

int main(){
  string S, T;
  cin >> S >> T;

  int minChange = T.size();
  for( int i = 0; i < T.size(); ++i ){
    int p = -1;
    vector<int> ps;
    while(1 ){
      p = S.find(T.at(i), p+1 );
      if( p == string::npos || p == -1 ){
        break;
      }
      ps.emplace_back(p);
    }
    if( ps.size() == 0 ){
      continue;
    }

    for( auto c : ps ){
      if( c-i >= 0 && c + T.size()-i <= S.size() ){
        string s = S.substr( c-i, c + T.size()-i);
        
        int cost = 0;
        for( int j = 0; j < T.size(); ++j ){
          if( T.at(j) != s.at(j) ){
            ++cost;
          }
        }

        if( cost < minChange ){
          minChange = cost;
        }
      }
    }
  }

  cout << minChange << endl;

}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#define SWAP(a,b) a=a+b,b=a-b,a=a-b
int main ()
{
	int i,j,m,n,a,b,c;
	scanf ("%d%d%d",&a,&b,&c);
	if (   a==b && b!=c || a==c && b!=c  || c==b && b!=a)
	{
		printf ("Yes");
	}
	else

	{
		printf ("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1e18;

int A,B,C,D,E,N,M,K,L,R,X;
string s,t;

signed main() {
    IOS();
    cin>>s;
    int mi=INF;
    int t=0;
    rep(i,0,s.size()){
        if(i%2){
            if(s[i]!='1')t++;
        }
        else{
            if(s[i]!='0')t++;
        }
    }
    chmin(mi,t);
    
    t=0;
    rep(i,0,s.size()){
        if(i%2){
            if(s[i]!='0')t++;
        }else{
            if(s[i]!='1')t++;
        }
    }
    cout<<min(mi,t)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

long long INF = 1e9;
int N,A,B,C;
vector<int> l(8);

int dfs (int v,int a,int b,int c){
    if (v == N){
        if (a == 0 || b == 0 || c == 0) return INF;

        return abs(a - A) + abs(b - B) + abs(c - C);
    }

    int rep = dfs(v + 1,a,b,c);

    if (a == 0) rep = min(rep,dfs(v+1,a+l[v],b,c));
    else rep = min(rep,dfs(v+1,a+l[v],b,c)+10);

    if (b == 0) rep = min(rep,dfs(v+1,a,b+l[v],c));
    else rep = min(rep,dfs(v+1,a,b+l[v],c)+10);

    if (c == 0) rep = min(rep,dfs(v+1,a,b,c+l[v]));
    else rep = min(rep,dfs(v+1,a,b,c+l[v])+10);

    return rep;
}

int main(){
    cin >> N >> A >> B >> C;
    for (int i = 0;i < N;i++) cin >> l[i];

    int ans = dfs(0,0,0,0);

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
// head
const int maxn = 1e5 + 5;
int tot, n, p[maxn], ans, res;
bool vis[maxn], f[maxn];
LL a[maxn], b[maxn];
map <LL, int> Map;
map <LL, bool> pr;

int main() {
	cin>>n;
	rep(i, 2, 1e5) {
		if(!vis[i]) 
			p[++tot] = i, pr[i] = 1;
		for(int j = 1; j <= tot && p[j]*i <= 1e5; j++) {
			vis[i*p[j]] = 1;
			if(i%p[j] == 0) break;
		}
	}
	rep(i, 1, n) {
		cin>>a[i];
		LL x = a[i];
		a[i] = b[i] = 1;
		rep(j, 1, 300)  
			if(x%p[j] == 0) {
				int cnt = 0;
				while(x%p[j] == 0) cnt++, x /= p[j];
				cnt = cnt%3;
				if(cnt == 1) a[i] *= p[j], b[i] *= p[j]*p[j];
				if(cnt == 2) a[i] *= p[j]*p[j], b[i] *= p[j];
			}
		if(x > 1) {
			LL s = sqrt(x);
			if(s*s == x) a[i] *= x, b[i] *= s, Map[a[i]]++;
			else 
				if(x <= 1e5 && pr[x]) a[i] *= x, b[i] *= x*x, Map[a[i]]++;
                else f[i] = 1, ans++;
		}
		else Map[a[i]]++;
	}
	ans += (Map[1] > 0) ? 1:0;
	rep(i, 1, n) {
		if(f[i]) continue;
		if(a[i] == 1) continue;
		if(Map[a[i]] > Map[b[i]]) 
			ans++;
		if(Map[a[i]] == Map[b[i]]) 
			res++;
	}
	cout<<ans + res/2<<endl;
}


Measured memory_bytes: 15952
s = input()[::-1]
length = len(s)
a = [0] * length
d = [0] * length
ans = [0] * 2019
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = [i for i in ans if i != 0]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(len(ans_c))]) / 2) + ans[0])


Measured memory_bytes: 23380
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())
for i in range(x, 100004):
    if is_prime(i):
        print(i)
        exit()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
long long K;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s >> K;
  N = s.length();
  int k = 0;
  while(k<N && s[k] == '1'){
   ++k;
  }
  if(k+1 > K || k >= N)
   cout << 1 << "\n";
  else 
   cout << s[k] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#include<string.h>
#define rep(i,l,r) for(ll i=l;i<r;i++)

typedef long long ll;

int main() {
    ll n,a[200001]={};
    scanf("%lld", &n);
    rep(i, 0, n) scanf("%lld", &a[i]);
    ll sum = 0,max=0;
    rep(i, 0, n) {
        if (a[i] > max) {
          	max=a[i];
        }
        else if (a[i] < max) {
            sum += max - a[i];
        }
    }
    printf("%lld", sum);

    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main(){
	string str;
	int i;
	
	while(1){
		getline(cin, str);
		if(str == ".")
			break;
		stack<char> tmp;
		tmp.push('$');
		for(i = 0; i < str.size(); i++){
			if(str[i] == '(' || str[i] == '[')
				tmp.push(str[i]);
			
			else if(str[i] == ')'){
				if(tmp.top() == '(')
					tmp.pop();
				else break;
			}
			
			else if(str[i] == ']'){
				if(tmp.top() == '[')
					tmp.pop();
				else break;
			}
		}
		if(i == str.size() && tmp.size() == 1)
			cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 904
n, a, b, c, d = map(int, input().split())

S = input()
x = [0]

for s in S:
    if s == '#':
        x.append(1)
    else:
        x.append(0)

flag = 0

for i in range(a, c):
    if x[i] + x[i+1] == 2:
        flag = 1
for i in range(b, d):
    if x[i] + x[i+1] == 2:
        flag = 1

flag2 = 1

if c > d:
    for i in range(b-1, d):
        if x[i] + x[i+1] + x[i+2] == 0:
            flag2 = 0
else:
    flag2 = 0

if flag + flag2 == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
const int INF = 1001001001;
int main(){
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1!=m2) cout << 1;
    else cout << 0;
}


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
bool cmp(int x, int y){
    return x > y;
}
long long n, m, a[111], sum;
int main(){
    n = read(), m = read();
    for (int i = 1; i <= n; i++){
        a[i] = read();
        sum += a[i];
    }
    sort (a+1, a+n+1, cmp);
    a[0] = 0;
    double k = sum / 4.0 / m;
    for (int i = 1; i <= m; i++){
        if (a[i] < k){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int x1, x2;
	scanf("%d", &x1);
	scanf("%d", &x2);
	if (x1 > x2) {
		x1 = x1 - x2;
		printf("%d\n", x1);
	}
	else {
		x2 = x2 - x1;
		printf("%d\n", x2);
	}
	return 0;
}


Measured memory_bytes: 2756
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 1002
#define MOD 1000000007

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool itp[N];
char ch;
int n,P[N],num,nxt[N];
ll c[N],ans;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

inline void PrimeBuild(void)
{
	itp[1]=true;
	rep(i,2,1001)
	{
		if(!itp[i])P[++num]=i;
		rcp(j,1,j<=num&&i*P[j]<=1001,j++)
		{
			itp[i*P[j]]=true;
			if(i%P[j]==0)break;
		}
	}
	rep(i,1,1001)if(itp[i-1])nxt[i]=nxt[i-1];else nxt[i]=i-1;
}

inline void slv(int x)
{
	for(int i=nxt[x+1];i;i=nxt[i])
		while(x%i==0)x/=i,c[i]++;
}

int main(void)
{
	PrimeBuild();
	read(n);
	ans=1;
	rep(i,1,n)slv(i);
	rep(i,1,n)ans=ans*(c[i]+1)%MOD;
	printf("%lld",ans);
	return 0;
}


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

int main() {
    stack<int> S;
    int a, b, x;
    string s;
    while (cin >> s) {
        if (s[0]=='+') {
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a+b);
        } else if (s[0]=='-') {
            b=S.top();
            S.pop();
            a=S.top();
            S.pop();
            S.push(a-b);
        } else if (s[0]=='*') {
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a*b);
        } else {
            S.push(atoi(s.c_str()));
        }
    }
    printf("%d\n",S.top());
    return 0;
}

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

#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
    int n;
    cin >> n;
    int a[n];
    vector<pair<int, int> > pairs(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pairs[i] = make_pair(i, a[i]);
    }

    sort(ALL(pairs), compare_by_b);
    for (int i = 1; i <= n; ++i) {
        cout << pairs[i].first << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2048
program problemB
  implicit none

real(8) :: a,  d, e
integer(8) :: n, m, yr, l, i, k, j,judge, small, kref, r, b, t, f
integer(8) :: BNUM, RNUM, NMAX, count
character(len=4) :: color


read(*,*) NMAX

count=0
do n=1, NMAX
  t=mod(n,3)
  f=mod(n,5)
  if (t/=0 .and. f/=0) then
    count=n+count
  end if
end do

write(*,*) count


stop
end program


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

const long long MOD = 1000000007;
const int MAX = 100005;
long long  X[MAX], Y[MAX];
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%lld", &X[i]);
    for (int i = 0; i < m; i++) scanf("%lld", &Y[i]);

    long long x, y;
    x = y = 0;
    for (int i = 1; i <= n; i++) {
        x += ((i - 1) * X[i-1] - (n - i) * X[i-1]) % MOD;
        x %= MOD;
    }
    for (int i = 1; i <= m; i++) {
        y += ((i - 1) * Y[i-1] - (m - i) * Y[i-1]) % MOD;
        y %= MOD;
    }

    long long ans;
    ans = (x * y) % MOD;
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String line;
        // ????????\???
        while((line=br.readLine()) != null) {
            // ??\???????????????????§???????????????§????????????
            String[] input = line.split(" ");
            int[] in = new int[input.length];
            
            // ??????????????°????????????
            for(int i = 0; i < input.length; i++) {
                in[i] = Integer.parseInt(input[i]);
            }
            
            // ?????????????????????????????????
            for(int i = 0; i < in.length-1; i++) {
                for(int j = in.length - 1; j > i; j--) {
                    if(in[j] < in[j-1]) {
                        int temp = in[j];
                        in[j] = in[j-1];
                        in[j-1] = temp;
                    }
                }
            }
            String out = "";
            for(int k = 0; k < in.length; k++) {
                out += in[k] + " ";
            }
            System.out.println(out.substring(0, out.length()-1));
        }
    }
}

Measured memory_bytes: 24244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe

ll gcd(ll c, ll d) { return d ? gcd(d, c%d) : c;}
ll lcm(ll c, ll d) { return c / gcd(c,   d) * d;}


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


string s;
cin >>  s;
if (s[0]==s[1]&&s[1]==s[2]&&s[2]==s[3])
{
    cout << "No" << endl;
}else
{
    if (s[0]==s[1]&&s[2]==s[3])
    {
        cout << "Yes" << endl;
    }else if (s[0]==s[2]&&s[1]==s[3])
    {
        cout << "Yes" << endl;
    }else if (s[0]==s[3]&&s[1]==s[2])
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
}  
}





//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    string s;
    cin >> s;
    LL n = s.size();
    LL l=0, r=0;
    LL ans=0;
    for(int i=0; i<n;){
        l=0; r=0;
        while(i<n && s[i]=='<'){
            l++;
            i++;
        }
        while(i<n && s[i]=='>'){
            r++;
            i++;
        }
        if(r<l) swap(l, r);
        ans += r*(r+1)/2;
        ans += max(0LL, (l-1)*l/2);
        // cout  << i << " " << ans << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1172
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
    cnt[i] += 1
for j in range(q):
    b,c = map(int,input().split())
    sums += cnt[b]*(c-b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sums)

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

int main(){
  int A,B,C,X,Y;
  cin >>A>>B>>C>>X>>Y;
  
  int ans = A*X+B*Y;
  for(int i=0;i<=100000;i++){
    int work = A*max(0,X-i) + B*max(0,Y-i) + 2*C*i;
    ans = min(ans,work);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def gcd(A, B):
    while B > 0:
        A, B = B, A % B
    return A

n, x = map(int, input().split())
# li = list(map(int, input().split()))
li = [abs(int(i) - x) for i in input().split()]
ans = li[0]
for i in range(n):
    ans = gcd(ans, li[i])
print(ans)


Measured memory_bytes: 14248
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{   
	    Scanner sc = new Scanner(System.in);
	    int[] arr = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
	    Arrays.sort(arr);
	    System.out.println(arr[0]+arr[1]+arr[2]*10);
	    
	}
}


Measured memory_bytes: 22868
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i >= K) {
            ans += 1.0 / N;
        } else {
            int x = i;
            for (int j = 2; x < K; j *= 2) {
                x *= 2;
                if (x >= K) {
                    ans += 1.0 / N / j;
                }
            }
        }
    }
    cout << setprecision(10) << ans << endl;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    if(N==1){
        p(0);
        return 0;
    }

    string s;
    cin >> s;
    ll L = s.size();

    vector<ll> B(L); // 右から見る
    vector<ll> W(L);

    if(s[0]=='#'){
        B[0] = 1;
    }
    FOR(i, 1, L){
        B[i] = B[i-1];
        if(s[i]=='#'){
            B[i]++;
        }
    }
    // vprint(B);

    // 白は右から見る
    string t = s;
    reverse(ALL(t));
    if(t[0]=='.'){
        W[0] = 1;
    }
    FOR(i, 1, L){
        W[i] = W[i-1];
        if(t[i]=='.'){
            W[i]++;
        }
    }
    reverse(ALL(W));
    // vprint(W);

    ll min_swap = W[0];
    // i以降、黒、i-1までは白
    FOR(i, 1, N){
        ll num = B[i-1] + W[i];
        min_swap = min(min_swap, num);
    }
    min_swap = min(min_swap, B[N-1]); // all W
    
    p(min_swap);
    
    return 0;
}

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

int main()
{
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    int ans = 1, a = p[0];

    for (int i = 1; i < n; i++) {
        a = min(a,p[i]);
        if (p[i] <= a) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int i,j;
	int n,m;
	int a[100][100],b[100];
	
	
	for(i=0;i<100;i++){
		b[i]=0;
		for(j=0;j<100;j++)a[i][j]=0;
	}
	
	scanf("%d%d",&n,&m);
	int ans[n];
	for(i=0;i<n;i++){
		ans[i]=0;
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(j=0;j<m;j++){
			scanf("%d",&b[j]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			ans[i]+=a[i][j]*b[j];
		}
		printf("%d\n",ans[i]);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void no(){
  cout << -1 << endl;
  exit(0);
}

//vectorのn番目を削除
void ope(vector<ll>& a, ll n){
  auto it = a.begin() + n;
  a.erase(it);
}

int main() {
  ll n; cin >> n;
  vector<ll> b(n);
  REP(i, n){
    cin >> b[i];
    if(b[i] > i+1) no();
  }

  vector<ll> ans;
  REP(i, n){
    ll l = b.size();
    IREP(j, l){
      if(b[j] == j+1){
        ope(b, j);
        ans.push_back(j+1);
        break;
      }
    }
  }

  IREP(i, n) cout << ans[i] << endl;
}

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

struct card{
    char mark;
    int value;
};

void BubbleSort(card A[],int N){
    for(int i=1;i<N;i++){
        for(int j=1;j<N;j++){
            if(A[j].value<A[j-1].value){
                card k=A[j];
                A[j]=A[j-1];
                A[j-1]=k;
            }
        }
    }

    for(int i=0;i<N;i++){
        if(i!=N-1){
            cout<<A[i].mark<<A[i].value<<" ";
        }else{
            cout<<A[i].mark<<A[i].value<<endl;
        }
    }
}

void SelectionSort(card B[],int N){
    for(int i=0;i<N;i++){
        int minj=i;
        for(int j=i;j<N;j++){
            if(B[j].value<B[minj].value){
                minj=j;
            }
        }
        if(minj!=i){
            card k=B[minj];
            B[minj]=B[i];
            B[i]=k;
        }     
    }

    for(int i=0;i<N;i++){
        if(i!=N-1){
            cout<<B[i].mark<<B[i].value<<" ";
        }else{
            cout<<B[i].mark<<B[i].value<<endl;
        }
    }
}

int main(){
    int N;
    bool b=true;
    cin>>N;
    card A[N],B[N];

    for(int a=0;a<N;a++){
        cin>>A[a].mark>>A[a].value;
        B[a]=A[a];
    }

    BubbleSort(A,N);
    cout<<"Stable"<<endl;
    
    SelectionSort(B,N);
    for(int i=0;i<N;i++){
        if(A[i].mark != B[i].mark){
            b=false;
        }
    }
    if(b==true){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <cmath>

using namespace std;
//zatu
int main() {
	int n;
	int ans;
	int a[65];
	int i, j;
	cin >> n;
	ans = n;
	i = 0; j = 0; int k = 3; a[0] = 0;
	while (n > 1) {
		if (n % 2 != 0)break;
		else { n = n / 2; a[i] = 2; i++; }
	}
	while (n > 1) {
		if (n % k != 0) k += 2;
		else { n = n / k; a[i] = k; i++;}
		//except
		if (k > ans / 2)break;
	}
	if (a[0] == 0) {
		a[0] = ans;
		i++;
	}
	printf("%d:", ans);
	for (j = 0; j < i; j++) {
		printf(" %d", a[j]);
	}
	cout << endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    int s;
    vector<int> b(m);
    vector<int> p(m);
    rep(i, m)
    {
        int k;
        cin >> k;
        rep(j, k)
        {
            int r;
            cin >> r;
            r--;
            b[i] |= 1 << r;
        }
    }

    rep(i, m)
    {
        cin >> p[i];
    }

    int ans = 0;
    rep(i, pow(2, n))
    {
        bool ok = true;
        rep(j, m)
        {
            int q = b[j] & i;
            q = __builtin_popcount(q) % 2;
            ok = ok && (p[j] == q);
            if (!ok)
            {
                break;
            }
        }
        if (ok)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 200 + 5;
int n;

int vis[N], match[N];
vector<int> g[N];

bool dfs(int u){
    for (auto v: g[u]) { //对u的每个邻接点
        if (!vis[v]) {  //要求不在交替路中
            vis[v] = 1; // 放入交替路
            if (match[v] == -1 || dfs(match[v])) {
                match[v] = u; //只保存图右边的匹配
                return true;
            }
        }
    }
    return false; // 不存在增广路，返回失败
}

int hungarian(int n){
    int ans = 0;
    memset(match, -1, sizeof(match));
    for (int u = 0; u < n; ++u) {
        memset(vis, 0, sizeof(vis));
        if(dfs(u)) ++ans;
    }
    return ans;
}



int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    
    vector<pair<int, int> > pts;
    int x,y;
    for (int i = 0; i < 2*n; i++){
        cin>>x>>y;
        pts.push_back({x,y});
    }
    
    for (int i = 0; i < n; i++){
        for (int j = n; j < n+n; j++){
            if(pts[i].first<pts[j].first&&pts[i].second<pts[j].second){
                g[i].push_back(j);
            }
        }
    }
    cout<<hungarian(n)<<endl;
    
    return 0;
}



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

int main()
{
    int N;
    cin >> N;
    if(N%2==0){
        cout << N / 2 << endl;
    }
    else{
        cout << (N / 2) + 1 << endl;
    }
}

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

using namespace std;
string a,b;
int m,n;
int dp[3010][3010];

void backtrack() {
    vector<char> path;
    int curM=m,curN=n;
    while(curM and curN) {
        if(a[curM-1]==b[curN-1]) {
            path.push_back(a[curM-1]);
            curM--; curN--;
        }
        else if(dp[curM-1][curN]>dp[curM][curN-1]) {
            curM--;
        }
        else curN--;
    }
    reverse(path.begin(),path.end());
    for(auto e:path) cout<<e;
}

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>a>>b;
    m=a.size(); n=b.size();
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=n;j++) {
            if(a[i-1]==b[j-1]) {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    backtrack();
}


Measured memory_bytes: 35584