akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int ans = 0;
  rep(i,3){
    char c;
    cin >> c;
    if(c == '1') ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,l;
	cin >> n;
	map<ll,ll> m;
	for(ll i = 0; i < n; i++) {
		cin >> l;
		if (m.count(l) == 0){
			m.insert(mp(l,1));
		}
		else{
			m[l]++;
		}
	}

	// for(auto i = m.begin(); i != m.end(); i++) {
	// 	cout << (*i).first << (*i).second <<endl;
	// }
	ll A = 0;
	ll C = 0;
	for(auto i = m.begin(); i != m.end(); i++) {
		if ((*i).first > A && (*i).second >= 2){
			if ((*i).second >= 4){
				A = (*i).first;
				C = (*i).first;
			}
			else{
				C = A;
				A = (*i).first;
			}
		}
		else if((*i).first > C && (*i).second >= 2){
			C = (*i).first;
		}
	}
	cout << A * C << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			double dbNum = (double)intNum;
			Math.pow(dbNum, 3);
			intNum = (int)Math.pow(dbNum, 3);
			System.out.println(intNum);
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 24080
N = int(input())
Table = []
dp = [[0]*3 for i in range(10**6)]

for _ in range(N):
    a,b,c = map(int, input().split())
    Table.append([a,b,c])
dp[0][0] = Table[0][0]
dp[0][1] = Table[0][1]
dp[0][2] = Table[0][2]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+Table[i][j])


print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

Measured memory_bytes: 134820
// tzl ak IOI! 

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

int n;
deque<int> all;

void TZL()
{
	int a, b; scf(a, b);
	if(a <= b){ puts("Impossible"); fflush(stdout); exit(0); }
	n = a + b;
	return;
}

void ASK(int a, int b)
{
	printf("? %d %d\n", a, b);
	fflush(stdout);
	return;
}

bool ans[5000];

void RANK1()
{
	rep(i, n)
	{
		if(!SZ(all)) all.pb(i);
		else
		{
			ASK(all.back(), i);
			char c = mygetchar();
			if(c == 'N') all.pop_back();
			else all.pb(i);
		}
	}

	int tr = all.back();
	rep(i, n)
	{
		ASK(tr, i);
		char c = mygetchar();
		ans[i] = (c == 'Y');
	}

	printf("! ");
	rep(i, n) putchar('0' + ans[i]);
	putchar('\n');
	fflush(stdout);
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(){
    int i;
    int height[10];
    
    for(i=0;i<10;i++){
      scanf("%d", height+i);
    }

    qsort(height, 10, sizeof(int), compare_int);

    for(i=0;i<3;i++){
      printf("%d\n", height[i]);
    }

    return 0;
}

Measured memory_bytes: 604
s = input()

l = int(s[0:2])
r = int(s[2:4])

if (l == 00 and r == 00) or (l>12 and r > 12) or (l == 00 and r > 12) or(l > 12 and r == 00):
    print("NA")
elif l > 12 and r < 13:
    print("YYMM")
elif l < 13 and r > 12:
    print("MMYY")
elif l == 00 and r < 13:
    print("YYMM")
elif l < 13 and r == 00:
    print("MMYY")
elif l <= 12 and r <= 12:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
void main() {
	auto s = rs;
	if(s.length == 2) writeln(s);
	else writeln(s[2], s[1], s[0]);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int c [10][10];
int h,w,a,res;
int main ()
{
    cin>>h>>w;
    rep(i,10)rep(j,10)cin>>c[i][j];
    rep(k,10)rep(i,10)rep(j,10) c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
    rep(i,h)rep(j,w)
    {
        cin>>a;
        if(a!=-1)res+=c[a][1];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c){
	int tmp = a;
	a = c;
	c = tmp;
    }

    if ((b <= a) || (c <= b)){
	if (c-a <= d) cout << "Yes" << endl;
	else cout << "No" << endl;
    } else {
	if ((b-a <= d) && (c-b <= d)) cout << "Yes" << endl;
	else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>

using namespace std;

int main(){
    int A, B, C, X;

    cin >> A >> B >> C >> X;

    int ans = 0, total;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                total = i*500 + j*100 + k*50;
                //cout << total << endl;
                if(total == X) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int v[20], c[20];

signed main() {
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> v[i];
	
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		if (v[i] - c[i] > 0) ans += v[i] - c[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI = 3.14159265358979323846;
int main() {
	double a, b, x;
	scanf("%lf %lf %lf", &a, &b, &x);
	if (x > a * a * b / 2) printf("%.9lf", atan(2.0 * (b - x / a / a) / a) * 180 / PI);
	else printf("%.9lf", atan(a * b * b / x / 2.0) * 180 / PI);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>

#define inf 500000
using namespace std;

int main() {
    int n, tmp, tweight, kazu;
    int g[100][100] = {};//与えられるグラフ
    cin >> n;

    //初期化
    int d[100] = {};
    for (int i = 1; i < n; ++i) {
        d[i] = inf;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            g[i][j] = -1;
        }
    }
    for (int i = 0; i < n; ++i) {
        g[i][i] = 0;
    }

    //入力を受け取る
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        cin >> kazu;
        for (int j = 0; j < kazu; ++j) {
            cin >> tmp >> tweight;
            g[i][tmp] = tweight;
        }
    }
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
     */

    for (int k = 0; k < n; ++k) {

        for (int i = 0; i < n; ++i) { // i 今最短経路を求めているノード
            /*
            for (int l = 0; l < n; ++l) {
                cout << d[i] << " ";
            }
            cout << endl;
             */
            for (int j = 0; j < n; ++j) { // j k の組でその２点間の重み
                //cout << i << " " << d[i] << " " << d[j] << " " << g[j][i] << endl;
                if (d[i] > d[j] + g[j][i] && g[j][i] != -1) {
                    d[i] = d[j] + g[j][i];

                }
            }
        }

    }
    for (int i = 0; i < n; ++i) {
        cout << i << " "  << d[i] << endl;
    }

    return 0;
}


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


int main(){
	string s, result;
	cin >> s;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == 'B'){
			if (!result.empty()){
				result.erase(result.size()-1);
			}
		}else{
			result += s[i];
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    int n;
    cin >> n;
    string taro;
    string hanako;
    int t_point = 0;
    int h_point = 0;
    F(i, 0, n){
        cin >> taro;
        cin >> hanako;
        int k = 0;
        while(1){
            if(taro[k] > hanako[k]){
                t_point +=3;
                break;
            }
            if(taro[k] < hanako[k]){
                h_point += 3;
                break;
            }
            if(taro[k] == '\0' && hanako[k] == '\0'){
                t_point ++;
                h_point ++;
                break;
            }
            k++;
        }
    }
    cout << t_point << space <<  h_point << endl;
}



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

int main(){
  int h, a;
  cin >> h >> a;
  int ans = 0;
  while(h > 0){
    h -= a;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
const int VMAX=200010;
int n,q;
int a[VMAX],b[VMAX];
int p[VMAX],x[VMAX];
int d[VMAX];
bool f[VMAX];
vector<pair<int,int> > res;
vector<int> edge[VMAX];
void add_edge(int from,int to){
  edge[from].push_back(to);
  edge[to].push_back(from);
}


void dfs(int v,int c){
  f[v] = true;
  res.push_back(make_pair(v,c+d[v]));
  int s = edge[v].size();
  rep(i,s){
    int w = edge[v][i];
    if(f[w]) continue;
    dfs(w,c+d[v]);
  }
}

int main()
{
  cin >> n >> q;
  rep(i,n-1){
    cin >> a[i] >> b[i];
    add_edge(--a[i],--b[i]);
  }
  
  rep(i,n){
    d[i] = 0;
    f[i] = false;
  }
  
  rep(i,q){
    cin >> p[i] >> x[i];
    d[--p[i]] += x[i];
  }
  
  dfs(0,0);

  sort(res.begin(), res.end());

  rep(i,res.size()) cout << res[i].second << "\n";

  
  return 0;
}


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

bool check_zero(vector<int> h) { //配列全部0でtrueを返す
  bool a = true;
  int s = h.size();
  for (int i = 0; i < s; i++) {
    if (!h.at(i) == 0) {
      a = false;
    }
  }
  return a;
}


int main() {
  int N;
  cin >> N;
  vector<int> h(N); //hは目標高さ
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  
  int count = 0;
  
  while(true) {
    if (check_zero(h)) {
      break;
    }
    
    int i = 0;
    while (i < N) {
      if (h.at(i) == 0) {
        i++;
      }
      else {
        count++;
        while(i < N && h.at(i) > 0) {
          h.at(i)--;
          i++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   ll ans = 0;
   rep(i, 1, n + 1) {
      if (i % 3 == 0 || i % 5 == 0) continue;
      ans += i;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3692
import java.math.BigDecimal;
import java.util.Scanner;


public class Main {
	public static void main(String args[]) {
	    int a, b, c, d, e, f;
	    double x, y;
	    Scanner s = new Scanner(System.in);
	    while (s.hasNext()) {
	    	a = s.nextInt();
	    	b = s.nextInt();
		    c = s.nextInt();
		    d = s.nextInt();
	    	e = s.nextInt();
	    	f = s.nextInt();
	    	x = (c * e - b * f) * 10000 / (a * e - d * b);
//	        BigDecimal x2 = new BigDecimal(String.valueOf(x));
//	        double x3= x2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
        	y = (c * d - a * f) * 10000 / (b * d - a * e);
//	        BigDecimal y2 = new BigDecimal(String.valueOf(y));
//	        double y3= y2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
	        System.out.printf("%.3f %.3f\n", x / 10000, y / 10000);
	    }
	}
}

Measured memory_bytes: 12000
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        long[] A = new long[N];
        long sum = 0;
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
            sum += A[i];
        }
        long x = (long)N * (N + 1) / 2;
        if (sum % x != 0) {
            _out.println("NO");
            return;
        }

        long K = sum / x;
        for (int i = 0; i < N; ++i) {
            long d = A[(i + 1) % N] - A[i];
            if ((d - K) % N != 0 || d - K > 0) {
                _out.println("NO");
                return;
            }
        }
        _out.println("YES");
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

using namespace std;
#define pb push_back
#define loop(ii,nn) for(int ii=0;ii<nn;ii++)
typedef vector<int> vi;


int main(){
		int l,r,d;cin>>l>>r>>d;
		int count =0;
		for(int i=l;i<=r;i++)
		if(i%d==0)
		count++;
		
		cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 3576
#import<iostream>
#define M 1000000007
#define F for(i=0;i<=N;
long N,a[1<<17],m[1<<17],k[1<<17],b,d,i,A,r;
long I(long n){
    long r=1;
    n%=M;
    for(A=M-2;A;A/=2){
        if(A&1)r=r*n%M;
        n=n*n%M;
    }
    return r;
}

main(){
    std::cin>>N;
    *m=*k=1;
    F ++i)m[i+1]=m[i]*(N+1-i)%M*I(i+1)%M;
    F a[b]=++i){
        std::cin>>b;
        if(a[b])d=i-a[b];
    }
    F ++i)k[i+1]=k[i]*(N-d-1-i)%M*I(i+1)%M;
    F std::cout<<(M-k[i]+m[++i])%M<<" ");
}

Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//using ll = long long;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;
    map<vector<int>,int> mp;
    do{
        mp[a] = mp.size();
    }while (next_permutation(a.begin(),a.end()));
    int ans = abs(mp[p]-mp[q]);
    cout << ans << endl;
}

Measured memory_bytes: 6656
#include<stdio.h>
#include<string.h>



int main() {

	int a, b, c;
	int moda, modb, modc;

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

	moda = a % 3;
	modb = b % 3;
	modc = c % 3;

	if (moda == 0 || modb == 0 || modc == 0) {
		printf("Possible\n");
	}
	else {
		printf("Impossible\n");
	}

	return 0;
}

Measured memory_bytes: 128
using System;

namespace _0022
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[] sums = new int[n + 1];
                int a = 0;
                for (int i = 0; i < n; i++)
                {
                    sums[i] = a;
                    a += int.Parse(Console.ReadLine());
                }
                sums[n] = a;
                int ret = int.MinValue;
                for (int i = 0; i <= n; i++)
                {
                    for (int j = i + 1; j <= n; j++)
                    {
                        ret = Math.Max(ret,sums[j] - sums[i]);
                    }
                }
                Console.WriteLine(ret);
            }
        }
    }
}


Measured memory_bytes: 9288
import sys
import math
N,H=map(int,input().split())
p=[]
x=[list(map(int,input().split())) for i in range(N)]
a=max(x[i][0] for i in range(N))
for i in range(N):
    if x[i][1]>a: p.append(x[i][1])

p.sort(reverse=True)
for i in range(len(p)):
    H-=p[i]
    if H<=0: print(i+1),sys.exit()

print(len(p)+math.ceil(H/a))
    

Measured memory_bytes: 28584
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    
    scanf("%d%d", &a, &b);
    
    if ((a*b)%2==0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }
    
    return 0;
}



Measured memory_bytes: 1600
import Control.Monad
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B

main = do
  [n,x] <- fmap (map read . words) getLine
  input <- B.getContents
  let ms = map readI . B.lines $ input
  print (solve x ms)


-- for fast read
readI :: B.ByteString -> Int
readI s = case B.readInt s of Just (n,_) -> n


solve :: Int -> [Int] -> Int
solve x ms =
  length ms + (x - sum ms)`div`m
  where
    m = minimum ms

Measured memory_bytes: 508
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード（貪欲法よる解法）
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[] b = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int j = 0;
			// 直前処理されたa[i]
			int prev = -1;
			for (int i = 0; i < n; i++) {
				if (prev != a[i]) {
					j = 0;
				}
				if (a[i] == b[i]) {
					for (; j < n; j++) {
						if ((a[j] != a[i]) && (b[j] != a[i])) {
							swap(b, i, j);
							break;
						}
					}
					if (a[i] == b[i]) {
						System.out.println("No");
						return;
					}
				}
				prev = a[i];
			}
			System.out.println("Yes");
			System.out.println(Arrays.stream(b).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
		}
	}

	/**
	 * 配列のi番目のものとj番目のものを交換する
	 * 
	 * @param array 配列
	 * @param i
	 * @param j
	 */
	private static void swap(int[] array, int i, int j) {
		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}
}


Measured memory_bytes: 68324
line = input()
charKind = [line[0]]
for c in line:
  if charKind[len(charKind)-1] != c and not c in charKind:
    charKind.append(c)
#print(charKind)
if len(charKind) > 2:
    print("No")
    quit()
charNum = [0 for i in range(len(charKind))]
for idx,c in enumerate(charKind):
    for cc in line:
        if cc == c:
            charNum[idx] += 1
if charNum[0] == 2 and charNum[1] == 2:
    print("Yes")
else:
    print("No")
quit()

Measured memory_bytes: 3064
import Data.List
main = do
  getLine
  as <- map read . words <$> getLine
  bs <- map read . words <$> getLine
  let cs = zipWith max as bs
      x = length $ filter id $ zipWith (/=) as cs
      d = sum cs - sum as
      y = findIndex (>= d) $ scanl (+) 0 $ reverse $ sort $ zipWith (-) cs bs
  print $ maybe (-1) (x +) y 

Measured memory_bytes: 103804
N=int(input())
l=input()
l=list(map(int,l.split()))
i=0
s=0
b=sum(l)-2*l[0]
for T in range(N) :
    while i<T :
        s=s+l[i]
        i=i+1
    a=abs(sum(l)-2*s)
    if b<=a :
        b=b
    else :
        b=a
print(b)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    vi v(n);
    map<int, int>cnt;
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin>>v[i];
        cnt[i+v[i]+1]++;
        ans+=cnt[i-v[i]+1];
    }
    cout<<ans;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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

using namespace std;
typedef int long long ill;
typedef long long ll;

int main(){
    int W, H, x, y, r; cin >> W >> H >> x >> y >> r;
    if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b;
    cin >> a >> b;
    int t[1000] = {};
    for (int i = 1; i <= 999; i++)
    {
        t[i] += t[i - 1] + i;
    }

    for (int i = 1; i <= 998; i++)
    {
        if (t[i] - a == t[i + 1] - b)
        {
            OP(t[i] - a);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
char A[6][7];
int nr_black_line[6], nr_black_col[6];
int H, W, K, res, tot_nr_black;


int main()
{
    cin.sync_with_stdio(0);

    cin >> H >> W >> K;

    for (int i = 0; i < H; ++i)
    {
        cin >> A[i];
        for (int j = 0; j < W; ++j)
        {
            nr_black_line[i] += A[i][j] == '#';
            nr_black_col[j] += A[i][j] == '#';
            tot_nr_black += A[i][j] == '#';
        }
    }

    vector<int> lines;
    int res = 0;
    for (int lines_subset = 0; lines_subset < (1 << H); ++lines_subset)
    {
        for (int cols_subset = 0; cols_subset < (1 << W); ++cols_subset)
        {
            int nr_del = 0;
            for (int i = 0; i < H; ++i)
            {
                if ((1 << i) & lines_subset)
                {
                    nr_del += nr_black_line[i];
                    lines.emplace_back(i);
                }
            }
            for (int j = 0; j < W; ++j)
            {
                if ((1 << j) & cols_subset)
                {
                    nr_del += nr_black_col[j];
                    for (const int &line : lines)
                    {
                        nr_del -= A[line][j] == '#';
                    }
                }
            }
            
            if (tot_nr_black - nr_del == K)
            {
                ++res;
            }

            lines.clear();
        }
    }

    cout << res;
}

Measured memory_bytes: 3648
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
l=[]
s=0
i=1
while i<N:
  if A[i]==A[i-1]:
    l.append(A[i])
    i+=1
  if len(l)==2:
    s=l[0]*l[1]
    break
  i+=1
print(s)

Measured memory_bytes: 19928
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int tmp = 0;

        if (a > b) {
            tmp = a;
            a = b;
            b = tmp;
        }
        if (b > c) {
            tmp = b;
            b = c;
            c = tmp;
        }
        if (a > b) {
            tmp = a;
            a = b;
            b = tmp;
        }

        System.out.println(a + " " + b + " " + c);
   }
}



Measured memory_bytes: 26136
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a = sc.read_vec::<i64>(n);

    for _ in 0..cmp::min(k, 100) {
        let mut sim = vec![0_i64; n];
        for i in 0..n {
            let idx_start = if i < a[i] as usize {
                0
            } else {
                i - a[i] as usize
            };
            let idx_end = cmp::min(i + a[i] as usize, n - 1);
            sim[idx_start] += 1;
            if idx_end + 1 < n {
                sim[idx_end + 1] -= 1;
            }
        }
        for i in 1..n {
            sim[i] += sim[i - 1];
        }
        a = sim;
    }

    for i in 0..n {
        println!("{}", a[i]);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 5300
n, k = map(int, input().split())
xs= list(map(int, input().split()))

l = []
r = []
for i in range(n):
  x = xs[i]
  if x < 0:
    l.append(x)
  else:
    r.append(x)
    
if l == []:
  print(r[k-1])
  exit()
elif r == []:
  print(-l[-k])
  exit()
  
if n == k:
  print(min(r[-1], -l[0])*2+max(r[-1], -l[0]))
  exit()
  
ts = []
for i in range(max(k-len(l), 0), min(len(r), k+1)):
  if i == 0:
    t = -l[-k]
  elif i == k:
    t = r[k-1]
  else:
    t = min(r[i-1], -l[-(k-i)])*2+max(r[i-1], -l[-(k-i)])
  ts.append(t)
#print(ts)
print(min(ts))

Measured memory_bytes: 62872
nums = input().split()
nums = [int(i) for i in nums]

point = [0]*nums[0]
question =[nums[2]]*nums[0]
first = [nums[1]]*nums[0]

for i in range(nums[2]):
  a = int(input())
  point[a-1] += 1  
 
diff = [x - y for (x, y) in zip(question, point)]
result = [x - y for (x, y) in zip(first, diff)]
 
for i in result:
  if i >= 1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 14152
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int ans=0,i;
  if(s[0]=='R')
  {
  	if(s[1]=='S' )
		cout<<1<<endl;
	else
	{
		if(s[2]=='R')
			cout<<3<<endl;
		else
		cout<<2<<endl;

	}

  }
	if(s[0]=='S')
  {
  	if(s[1]=='S' ) {
		if(s[2]=='R')
		cout<<1<<endl;
	else
		cout<<0<<endl;
  }
	else
	{
		if(s[2]=='R')
			cout<<2<<endl;
		else
		cout<<1<<endl;

	}
  }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)
char chenge[] = {'m','c','x','i'};
char _chenge[] = {'i','x','c','m'};
int c[] = {1000,100,10,1};
     
int getNUM(string s){
    int len = s.size();
    char prev = '$';
    int ret = 0;
    rep(i,len){
        bool f = false;
        rep(j,4){
            if(s[i] == chenge[j]){
                if(prev == '$'){
                    ret += c[j];
                    prev = '$';
                    f = true;
                }
                else{
                    ret += (prev-'0')*c[j];
                    prev = '$';
                    f = true;
                }
            }
        }
        if(!f){
            prev = s[i];
        }
    }
    return ret;
}
string decode(int a){
    string res = "";
    int index = 0;
    while(a){
        int t = a%10;
        if(t == 0){
            ;
        }
        else if(t == 1){
            res += _chenge[index];
        }
        else{
            res += _chenge[index];
            res += (t+'0');
        }
        a/=10;
        index++;
    }
    reverse(res.begin(),res.end());
    return res;
}
int main(){
    int N;
    cin >> N;
    rep(i,N){
        string a,b;
        int _a = 0;
        int _b = 0;
        cin >> a >> b;
        _a = getNUM(a);
        _b = getNUM(b);
        int res = _a+_b;
        cout << decode(res) << "\n";
    }
    return 0;
}

Measured memory_bytes: 1192
n, k = gets.split.map(&:to_i)
h = Hash.new {|h, e| h[e] = 0}
gets.split.map(&:to_i).each {|x| h[x] += 1}

if h.size <= k
  puts 0
else
  puts h.values.sort.reverse[k..-1].reduce(&:+)
end

Measured memory_bytes: 32880
import queue
adjacent=((1,3), (0,2,4), (1,5), (0,4,6), (1,3,5,7), (2,4,8), (3,7), (4,6,8), (5,7))
 
class State:
    def __init__(self, board, space, prev):
        self.board = board
        self.space = space
        self.prev = prev
 
def bf_search(start, GOAL):
    q = queue.Queue()
    q.put(State(start, start.index(0), None))
    table = {}
    table[tuple(start)] = True
    while not q.empty():
        a = q.get()
        for x in adjacent[a.space]:
            b = a.board[:]
            b[a.space] = b[x]
            b[x] = 0
            key = tuple(b)
            if key in table: continue
            c = State(b,x,a)
            if b == GOAL:
                return print_answer(c)
            q.put(c)
            table[key] = True
 
cnt = -1
def print_answer(x):
    global cnt
    if x is not None:
        cnt += 1
        print_answer(x.prev)
    return str(cnt)
 
GOAL = [1,2,3,4,5,6,7,8,0]
start = []
for i in range(3):
 x,y,z = map(int, input().split())
 start += [x,y,z]

if start == GOAL:
    print("0")
else:
    print(bf_search(start, GOAL))

Measured memory_bytes: 78024
N,M=map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)

    return divisors

l=make_divisors(M)
l.sort()
ans=0
for i in range(len(l)):
    if (l[i]*N)<=M:
        ans=max(l[i],ans)
print(ans)

Measured memory_bytes: 38640
local day = io.read("*n")
local c = {}
for i = 1, 26 do
  c[i] = io.read("*n")
end
local s = {}
for id = 1, day do
  s[id] = {}
  for i = 1, 26 do
    s[id][i] = io.read("*n")
  end
end

local scores = {}
local penalties = {}
for i = 1, 26 do
  scores[i] = 0
  penalties[i] = 0
end
local ld = {}
local function solveAll(t)
  for i = 1, 26 do ld[i] = 0 end
  for id = 1, day do
    local pid = t[id]
    scores[pid] = scores[pid] + s[id][pid]
    ld[pid] = id
    for i = 1, 26 do
      penalties[i] = penalties[i] + c[i] * (id - ld[i])
    end
  end
end
local function solveDiff(t, iday, pto)
  local pfrom = t[iday]
  scores[pfrom] = scores[pfrom] - s[iday][pfrom]
  scores[pto] = scores[pto] + s[iday][pto]
  t[iday] = pto
  penalties[pfrom] = 0
  penalties[pto] = 0
  for i = 1, 26 do ld[i] = 0 end
  for id = 1, day do
    local p = t[id]
    ld[p] = id
    for ip = pfrom, pto, (pto - pfrom) do
      penalties[ip] = penalties[ip] + c[ip] * (id - ld[ip])
    end
  end
end

local function solveSum()
  local z = 0
  for i = 1, 26 do z = z + scores[i] - penalties[i] end
  return z
end

local t = {}
for id = 1, day do
  t[id] = 1 + (id % 26)
end
solveAll(t)
local score = solveSum()
math.randomseed(1)
local iter = 1
local random = math.random

local candidate = {}
for i = 1, 365 do
  candidate[i] = {}
  for j = 1, 26 do
    if 1 + (i % 26) ~= j then
      table.insert(candidate[i], j)
    end
  end
end
local day_candidate = {}
for i = 1, 365 do day_candidate[i] = i end

while os.clock() < 1.85 do
  iter = iter + 1
  if #day_candidate == 0 then
    -- reset
    for i = 1, 365 do
      day_candidate[i] = i
      candidate[i] = {}
      for j = 1, 26 do
        if t[i] ~= j then
          table.insert(candidate[i], j)
        end
      end
    end
  end
  local changeday_idx = random(1, #day_candidate)
  local changeday = day_candidate[changeday_idx]
  local changeto_idx = random(1, #candidate[changeday])
  local changeto = candidate[changeday][changeto_idx]
  table.remove(candidate[changeday], changeto_idx)
  if #candidate[changeday] == 0 then
    table.remove(day_candidate, changeday_idx)
  end
  local changefrom = t[changeday]
  -- if changefrom <= changeto then
  --   changeto = changeto + 1
  -- end
  local score_before_p1 = scores[changefrom]
  local score_before_p2 = scores[changeto]
  local penalty_before_p1 = penalties[changefrom]
  local penalty_before_p2 = penalties[changeto]
  solveDiff(t, changeday, changeto)
  local tmp = solveSum()
  if score < tmp then
    score = tmp
  else
    scores[changefrom] = score_before_p1
    scores[changeto] = score_before_p2
    penalties[changefrom] = penalty_before_p1
    penalties[changeto] = penalty_before_p2
    t[changeday] = changefrom
  end
end
-- print(iter)
print(table.concat(t, "\n"))


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam -1];
#define range(n) for(int i = 0; i < n; i++)
#define forn(x, n) for(int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
int n, m, a, b, c, k;

int main(){
	sc("%d %d", &n, &k);
    if (k == 1) {
        pr("0\n"); return 0;
    }
    pr("%d\n", n-k);
 	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

string S;

int main(){
	cin >> S;
	int N = S.size();
	int ans = N;
	repp(i,1,N) if(S[i] != S[i-1]) ans = min(ans,max(i,N-i));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
L = [list(map(int, input().split()))[1::] for _ in range(N)]

root = [i for i in range(M + 1)]
comp_size = [1] * (M + 1)

def root_find(x):
  y = root[x]
  if y == x:
    return x
  else:
    z = root_find(y)
    root[x] = z
    return z

def merge(x, y):
  rx = root_find(x)
  ry = root_find(y)
  sx = comp_size[x]
  sy = comp_size[y]
  if sx >= sy:
    root[ry] = rx
    comp_size[rx] = sx + sy
  else:
    root[rx] = ry
    comp_size[ry] = sx + sy

for l in L:
  for i in range(len(l) - 1):
    merge(l[i], l[i + 1])
#print("root:", root)

r = root_find(L[0][0])
for i in range(1, N):
  if r != root_find(L[i][0]):
    print("NO")
    exit()
#print("root:", root)
print("YES")  

Measured memory_bytes: 85720
#include <iostream>
#include <vector>
#define MAX 10000001
using namespace std;

int main() {
    int num;
    cin >> num;
    int array[101][101];

    for(int i=0; i<=num; i++) {
        array[i][i] = 0;
    }

    vector<int> p;
    for(int i=0; i<num; i++) {
        int row, col;
        cin >> row >> col;
        if(i==0) p.push_back(row);
        p.push_back(col);
    }

    for(int l=0; l<num; l++) {
        for(int i=0; (i+l+1)<num; i++) {
            int j=i+l+1;
            array[i][j] = MAX;
            for(int k=i+l; k>=i; k--) {
                int value = array[i][k]+array[k+1][i+l+1]+(p[i]*p[k+1]*p[i+l+2]);
                array[i][j] = min(array[i][j],value);
            }
        }
    }
    cout << array[0][num-1] << endl;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=100005;
int p[N],q[N],P[N],Q[N];
int a[N],A[N],n,k;
int b[N],c[N],d[N];
void power(int *a,int y){
	For(i,1,n) b[i]=i;
	for (;y;){
		if (y&1){
			For(i,1,n) c[i]=b[a[i]];
			For(i,1,n) b[i]=c[i];
		}
		if (y/=2){
			For(i,1,n) c[i]=a[a[i]];
			For(i,1,n) a[i]=c[i];
		}
	}
	For(i,1,n) a[i]=b[i];
}
int main(){
	scanf("%d%d",&n,&k);
	For(i,1,n) scanf("%d",&p[i]),P[p[i]]=i;
	For(i,1,n) scanf("%d",&q[i]),Q[q[i]]=i;
	For(i,1,n) a[i]=q[P[Q[p[i]]]],A[a[i]]=i;
	int T=(k-1)/6; k-=T*6;
	power(a,T); power(A,T);
	For(i,1,n) b[i]=a[p[A[i]]];
	For(i,1,n) c[i]=a[q[A[i]]];
	for (;k>=2;k--){
		For(i,1,n) d[b[i]]=c[i];
		For(i,1,n) b[i]=c[i],c[i]=d[i];
	}
	if (k==2) For(i,1,n) b[i]=c[i];
	For(i,1,n) printf("%d ",b[i]);
}
/*
p
q
qP
qPQ
qPQpQ
qPQpQqpQ
qPQppPqpQ
qPQpqPqpQ
*/

Measured memory_bytes: 4352
n_k = list(map(int, input().split()))
n, k = n_k[0], n_k[1]
tree_list = []
for i in range(n):
    tree_list.append(int(input()))
tree_list.sort()
min = 999999999
for i in range(n-k+1):
    if tree_list[i+k-1]-tree_list[i] <= min:

        min = tree_list[i+k-1]-tree_list[i]
print(int(min))


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

struct edge{ int u,v,cost; };
bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;
int V,E; //頂点数、辺数
const int N = 1e5+10;

int n,m;

struct UF{
  const int N = 1e5+10;
  vector<int> par; //親
  vector<int> depth; //木の深さ

  void init(){
    par.resize(N);
    depth.resize(N);
    for(int i = 0; i < N; i++){
      par[i] = i;
      depth[i] = 0;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) swap(x,y);
    par[y] = x;
    if(depth[x] == depth[y]) depth[x]++;
  }
}uf;

int kruskal(){
  sort(es.begin(),es.end(),comp);
  uf.init();
  int min_cost = 0;
  int need = m-n;
  for(int i = 0; i < es.size(); i++){
    if(need <= 0) break;
    edge e = es[i];
    if(uf.root(e.u) != uf.root(e.v)){
      min_cost += e.cost;
      uf.unite(e.u,e.v);
      need--;
    }
  }
  return min_cost;
}

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

  cin >> n >> m;
  vector<int> x(m);
  for(int i = 0; i < m; i++){
    cin >> x[i];
  }
  sort(x.begin(),x.end());

  for(int i = 0; i < m-1; i++){
    es.push_back({i,i+1,abs(x[i+1]-x[i])});
    es.push_back({i+1,i,abs(x[i+1]-x[i])});
  }
  cout << kruskal() << endl;

  return 0;
}


Measured memory_bytes: 9072
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  string S; cin>>S;
  ll N=S.size();
  ll count=0;
  ll num=0;
  rep(i,N)
  {
    if(S.at(i)=='W')
    {
      count++;
      num+=i;
    }
  }
  //cout<<num<<" "<<count<<endl;
  ll ans=num-(ll)(count*(count-1)/2);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b;
  string op;
  while (1) {
    cin >> a >> op >> b;
    if (op == "?") break;
    else if (op == "+") cout << a+b << endl;
    else if (op == "-") cout << a-b << endl;
    else if (op == "*") cout << a*b << endl;
    else if (op == "/") cout << a/b << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(m)]
ans = [0] * n
for a, b in ab:
    ans[a - 1] += 1
    ans[b - 1] += 1
for i in range(n):
    if ans[i] % 2 == 1:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 28148