akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int Cnt = 0;

vector<int> GetCounts(string s, int c) {
  int n = s.size();
  vector<int> a(n);
  int r = -1;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    a[i] = cnt;
    if (i <= r) continue;
    if (s[i] == 'x') continue;
    cnt++;
    r = i + c;
  }
  Cnt = cnt;
  return a;
}

int main()
{
  int n, m, c;
  string s;
  cin >> n >> m >> c >> s;

  vector<int> left, right;
  left = GetCounts(s, c);
  reverse(s.begin(), s.end());
  right = GetCounts(s, c);
  reverse(s.begin(), s.end());
  reverse(right.begin(), right.end());

  //for (int x : left) cout << x; cout << endl;
  //for (int x : right) cout << x; cout << endl;

  //cerr << s << endl;

  for (int i = 0; i < n; ++i) {
    //cerr << left[i] + right[i];
    if (s[i] == 'x') continue;
    if (left[i] + right[i] < m) {
      cout << i + 1 << endl;
    }
  }
  //cerr << endl;

  return 0;
}


Measured memory_bytes: 3520
import sys

def num(x):
  return [0, 1, 1, 2, 3, 5, 8, 13, 21][x + 2]

H, W, K = map(int, input().split())

if W == 1:
  print(1)
  sys.exit()

f = [[0 for _ in range(W + 2)] for _ in range(H + 1)]
f[0][1] = 1

for h in range(1, H + 1):
  for k in range(1, W + 1):
    f[h][k] = (num(k - 2) * num(W - k - 1)) * f[h - 1][k] + (num(k - 3) * num(W - k - 1)) * f[h - 1][k - 1] + (num(k - 2) * num(W - k - 2)) * f[h - 1][k + 1]

print(f[H][K] % 1000000007)


Measured memory_bytes: 3064
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/8/ITP1_8_C
/*
    A:65
    a:97
    space:32
*/
#include <iostream>
#include <string.h>
#include <cstring>

int main()
{
    std::string str;
    int cnt[26] = {};

        while (getline(std::cin, str))
    {
        // if (std::cin.eof())
        //     break;

        int len = str.length();
        char cstr[len];
        strcpy(cstr, str.c_str());

        for (int i = 0; i < len; i++)
        {
            int ASCII = (int)(cstr[i]);
            if (ASCII >= 97 && ASCII <= 122)
            {
                cnt[ASCII - 97]++;
            }
            else if (ASCII >= 65 && ASCII <= 90)
            {
                cnt[ASCII - 65]++;
            }
        }
    }
    for (int i = 0; i < 26; i++)
    {
        std::cout << (char)(i + 97) << " : " << cnt[i] << std::endl;
    }
}


Measured memory_bytes: 3132
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

}

Measured memory_bytes: 101512
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, a[N];
vector < int > tek, cif, b;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&m ,&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",a + i);
		if(a[i]%2)
			tek.pb(a[i]);
		else
			cif.pb(a[i]);
	}
	if((int)tek.size() > 2){
		printf("Impossible\n");
		return 0;
	}
	if((int)tek.size() >= 1){
		printf("%d ", tek[0]);
		b.pb(tek[0]);
	}
	for(int i = 0; i < cif.size(); i++){
		printf("%d ", cif[i]);
		b.pb(cif[i]);
	}
	if((int)tek.size() >= 2){
		printf("%d\n", tek[1]);
		b.pb(tek[1]);
	}
	if((int)b.size() == 1){
		if(b[0] == 1)
			printf("\n1\n1\n");
		else
			printf("\n2\n%d %d\n", b[0] - 1, 1);
		return 0;
	}
	printf("\n%d\n", n - (b[0] == 1) );
	for(int i = 0; i < b.size(); i++){
		// cout << "AMK"<<b[i]<<" ";
		if(i == 0){
			if(b[i] != 1)
				printf("%d ", b[i] - 1);
		}
		else if(i == (int)b.size() - 1)
			printf("%d\n", b[i] + 1);
		else
			printf("%d ", b[i]);
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh = sorted(xyh, key=lambda x:x[2])
ans = []
for i in range(101):
    for j in range(101):
        pre = xyh[-1][2] + abs(i-xyh[-1][0]) + abs(j-xyh[-1][1])
        valid = True
        for k in range(N):
            x, y, h = xyh[k]
            a = abs(x-i) + abs(y-j)
            if max(pre-a, 0) != h:
                valid = False

        if valid and pre >= 1:
            print(i, j, pre)
            exit()

Measured memory_bytes: 46060
fun main() {
  val (n, m) = readLine()!!.split(' ').map { it.toInt() }
  val fact = Array(m + 1) { ModN(it) }
  fact[0] = ModN(1)
  for (i in 3 .. m) {
    fact[i] *= fact[i - 1]
  }
  val invFact = Array(m + 1) { fact[it].inv() }
  fun a(n: Int, k: Int): ModN {
    return fact[n] * invFact[n - k]
  }
  fun c(n: Int, k: Int): ModN {
    return fact[n] * invFact[k] * invFact[n - k]
  }
  var answer = a(m, n).sqr()
  for (i in 1 .. n) {
    val cur = c(m, i) * c(n, i) * fact[i] * a(m - i, n - i).sqr()
    if (i % 2 == 0) answer += cur
    else answer -= cur
  }
  println(answer)
}

const val MODULO = 1000_000_000 + 7

private class ModN(private val x: Int) {
  operator fun plus(other: ModN) = ModN((this.x + other.x) % MODULO)
  operator fun times(other: ModN) = ModN(((this.x.toLong() * other.x) % MODULO).toInt())
  operator fun minus(other: ModN) = this + -other
  operator fun unaryMinus(): ModN = ModN(MODULO - x)
  override fun toString() = x.toString()
}

private fun ModN.pow(p: Int): ModN {
  var pow = p
  var res = ModN(1)
  var mul = this
  while (pow > 0) {
    if (pow % 2 == 1) {
      res *= mul
    }
    mul *= mul
    pow = pow ushr 1
  }
  return res
}

private fun ModN.inv(): ModN = this.pow(MODULO - 2)

private fun ModN.sqr(): ModN = this * this



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

using namespace std;


#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

class E{
public:
  int t,d,c;
  E(int t,int d,int c):t(t),d(d),c(c){}
  bool operator<(const E& a)const{
    if(d==a.d)return c>a.c;
    return d>a.d;
  }
};

const int N = 11111;
vector<E> edge[N];

int n,m;
bool input(){
  rep(i,N)edge[i].clear();

  cin>>n>>m;
  if(n==0)return false;

  rep(i,m){
    int s,t,d,c;
    cin>>s>>t>>d>>c;
    edge[s].push_back(E(t,d,c));
    edge[t].push_back(E(s,d,c));
    //cout<<s<<t<<d<<c<<endl;
  }

  reps(i,1,n){
    sort(edge[i].begin(), edge[i].end());
  }
  return true;
}


class Q{
public:
  int now,val,cost;
  Q(int now, int val,int cost):now(now),val(val),cost(cost){}
  bool operator<(const Q& a)const{
    if(val!=a.val)return val>a.val;
    if(cost!=a.cost)return cost>a.cost;
    return now>a.now;
  }
};

int visit[N]={0};

int solve(){

  priority_queue<Q> que;
  que.push(Q(1, 0, 0));

  int ret = 0;
  rep(i,N)visit[i]=0;
  
  while(!que.empty()){
    Q u = que.top();
    que.pop();

    if(visit[u.now]==1)continue;
    visit[u.now]=1;

    ret += u.cost;

    rep(i,edge[u.now].size()){
      E e = edge[u.now][i];
      que.push(Q(e.t, u.val+e.d, e.c));
    }

  }


  return ret;
}


int main(){
  while(input())cout<<solve()<<endl;
}

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

int main() {
  int a,b,c;cin>>a>>b>>c;
  if(a<c&&b<c){cout<<a*b/2;}
  else if(a<b&&c<b){cout<<a*c/2;}
  else{cout<<b*c/2;}
              
}
      



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

int main() {
  int N;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++) cin>>d[i];
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ans+=d[i]*d[j];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.array, std.string;
import std.range;
 
void main(string[] args) {
  auto input = readln().chomp.split.map!(to!int);
 
  if(input[0] <= 8 && input[1] <= 8){
    "Yay!".writeln;
  }else{
    ":(".writeln;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

int main(void) {
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int N,K;
    cin >> N >> K;
    vector<long long> v(N);
    vector<long long> dp(N + K, 1e9);
    for (int i = 0; i < N; i++)
        cin >> v[i];

    dp[0] = 0;
    

    for (int i = 1; i < N; i++)
    {
        int t = min(i,K);
        for (int j = 0; j < t;j++){
            dp[i] = min(dp[i], dp[i - j - 1] + abs(v[i] - v[i - j - 1]));
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

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

int main() {
    int a, b, c, cnt;
    
    cin >> a >> b >> c;
    
    for(a;a <= b; a++) {
        if (c % a == 0) {
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3116
while 1:
    s = raw_input()
    if s == "#": break
    ans = 10**9
    for ini in range(2):
        tmp = 0
        b = (int(s[0])-1)%3
        lr = ini
        for i in s[1:]:
            f = (int(i)-1)%3
            if [b<f, b>f][lr]: tmp += 1
            else: lr = 1-lr
            b = f
        ans = min(ans, tmp)
    print ans

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

int n , m ;
double table[110][110] ;
double memo[110][110] ;

double dp( int day , int p ){
	if( memo[day][p] != -1.0 ) return memo[day][p] ;
	if( day >= m ) return 1.0 ;
	
	double best = -100.0 ;
	for( int next=0 ; next < n ; next++ ){
		best = max( best , dp( day+1 , next ) * table[p][next] ) ;
	}
	
	return memo[day][p] = best ;
}

int main(){
	
	for( int i=0 ; i<101 ; i++ ){
		for( int j=0 ; j<101 ; j++ ){
			memo[i][j] = -1.0 ;
		}
	}
	
	while( cin >> n >> m , n ){
		for( int i=0 ; i<n ; i++ ){
			for( int j=0 ; j<n ; j++ ){
				cin >> table[i][j] ;
			}
		}
		for( int i=0 ; i<101 ; i++ ){
			for( int j=0 ; j<101 ; j++ ){
				memo[i][j] = -1.0 ;
			}
		}
		
		double ans = -100.0 ;
		for( int i=0 ; i<n ; i++ ){
			ans = max( ans , dp(1,i) ) ;
		}
		
		printf("%0.2lf\n",ans) ;
	}
	
return 0 ;
}

Measured memory_bytes: 1424
#include <stdio.h>

typedef long long ll;

char S[100005][15];
int MARCH[5];

int main() {

	int N;

	scanf("%d",&N);

	int i,j,k;

	for(i=0;i<N;i++){
	scanf("%s",&S[i]);
	if(S[i][0]=='M'){MARCH[0]++;}
	if(S[i][0]=='A'){MARCH[1]++;}
	if(S[i][0]=='R'){MARCH[2]++;}
	if(S[i][0]=='C'){MARCH[3]++;}
	if(S[i][0]=='H'){MARCH[4]++;}
	}

	ll ans=0ll;

	for(i=0;i<=3;i++){
		for(j=i+1;j<=4;j++){
			ll add=1ll;
			for(k=0;k<=4;k++){
				if(k!=i&&k!=j){
				add*=MARCH[k];
				}
			}
			ans+=add;
		}
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
double sum, a;
int n;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a;
        sum += 1.0 / a;
    }
    sum = 1.0 / sum;
    cout << fixed << setprecision(10) << sum;
    PLEC
}


Measured memory_bytes: 3764
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		
		HashMap<Character,Integer> resultMap = new HashMap();
		for(int i = 0;i<line.length();i++) {
			Character tmp = line.charAt(i);
			if(resultMap.containsKey(tmp)) {
				resultMap.put(tmp, resultMap.get(tmp)+1);
			}else {
				resultMap.put(tmp, 0);
			}
		}
		
		String strResult = "No";

		if(resultMap.size() == 2) {
			 for(Integer t:resultMap.values()) {
				 if(resultMap.containsValue(t)) {
					 strResult = "Yes";
				 }
			 }
		}
		System.out.println(strResult);
		
	}
}

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

const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

const int MAXN = 1234;
int H, W;
char A[MAXN][MAXN];
int dist[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}

	vector<pair<int, int>> q;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				q.emplace_back(i, j);
				dist[i][j] = 0;
			} else {
				dist[i][j] = -1;
			}
		}
	}
	for (size_t i = 0; i < q.size(); i++) {
		int x, y; tie(x, y) = q[i];
		for (int dir = 0; dir < 4; dir++) {
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (nx < 0 || nx >= H || ny < 0 || ny >= W || dist[nx][ny] != -1) {
				continue;
			}
			dist[nx][ny] = dist[x][y] + 1;
			q.emplace_back(nx, ny);
		}
	}

	int x, y; tie(x, y) = q.back();
	int ans = dist[x][y];
	cout << ans << endl;

	return 0;
}


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

#define ll long long
#define ld long double
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll a[n+1];
    for (int i = 1; i <=n;i++)
        cin >> a[i];
    int i = 1;
    set<int> o;
    int k = 0;
    while (true)
    {
        k++;
        ll to = a[i];
        if (o.find(to) == o.end()) {
            i = to;
            o.insert(i);
            if (i == 2)
            {
                cout << k << endl;
                return 0;
            }
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 5760
N = int(input())
a = list(map(int,input().split()))
box = [0]*N

def zero_or_one(i):
	count = 0
	num = i+1
	while num <= N:
		count += box[num-1]
		num += i+1
	if count%2 == a[i]:
		box[i] = 0
	else:
		box[i] = 1

for i in reversed(range(N)):
	zero_or_one(i)

ball = 0
ans = []
for i in range(N):
	if box[i] == 1:
		ball += 1
		ans.append(i+1)

if ball == 0:
	print(0)
else:
	print(ball)
	ans = " ".join(map(str,ans))
	print(ans)

Measured memory_bytes: 19892
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long A, B;
    scan(A, B);
    max(A + B, A - B, A * B).writeln();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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; }


int main() {
    string s; cin >> s;
    int slen = s.length();
    if(s[slen-1] == 's') s.push_back('e');
    s.push_back('s');
    cout << s << endl;
}

Measured memory_bytes: 3628
x,y = (int(i) for i in input().split())
if abs(x)>abs(y):
	if x<0 and y<=0: answer = y-x
	elif (x<0 and y>0) or (x>0 and y<=0): answer = abs(x)-abs(y)+1
	elif x>0 and y>0: answer = abs(x)-abs(y)+2
elif abs(x)==abs(y): answer = 1
elif abs(x)<abs(y):
	if x>=0 and y>0: answer = y-x
	elif (x>=0 and y<0) or (x<0 and y>0): answer = abs(y)-abs(x)+1
	elif x<0 and y<0: answer = abs(y)-abs(x)+2
print(answer)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[m+1];
        a[0] = 0;
        b[0] = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = a[i-1] + sc.nextInt();
        }
        for (int i = 1; i <= m; i++) {
            b[i] = b[i-1] + sc.nextInt();
        }
        int j = m, count = 0;
        for (int i = 0; i <= n; i++) {
            if (a[i] > k) {
                break;
            }
            while (b[j] > k - a[i]) {
                j--;
            }
            count = Math.max(count, i+j);
        }

        System.out.println(count);
    }
}

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

int main()
{
	long long int n,k;
	cin>>n>>k;
	long long int i,j,l,m,a[n],cnt=0,sum=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n,greater<long long int>());
	for(i=0;i<n;i++)
	{
		if(cnt!=k)
		{
			cnt++;
		}
		else
		{
			sum=sum+a[i];
		}
	}
	cout<<sum;
	

	
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();

        for (int i=0; i<n; i++) {
            long a=sc.nextLong();
            long b=sc.nextLong();
            long c=sc.nextLong();
            long d=sc.nextLong();
            String ans="No";

            if(a<b || d<b){
                out.println("No");
            }
            else if(c>b) {
                out.println("Yes");
            }
            else {
                long g = gcd(b,d);
                if(b - g + a%g <= c )ans="Yes"; 
                out.println(ans);
            }
        }


        // out.println(ans);
        out.flush();
    }
    
    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 21844
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    int64_t ans = 0;
    char c = S[0];
    for (size_t i = 1; i < S.size(); ++i) {
        if (S[i] != c) {
            ans++;
            c = S[i];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;


    
int main(){
    int ans = INF;
    int N, M, X;
    cin >> N >> M >> X;
    vi C(N);
    vi2 A(N,vi (M));
    REP(i,N){
        cin >> C[i];
        REP(j,M){
            cin >> A[i][j];
        }
    }
    
    REP(i,1<<N){
        int sum=0;
        vi ab (M);
        bool isOK = true;
        
        REP(j,N){
            if(1&i>>j){
                sum += C[j];
                REP(k,M){
                    ab[k] += A[j][k];
                }
            }
        }
        
        REP(k,M){
            if(ab[k]<X) isOK = false;
        }
        
        if(isOK) ans = min(ans,sum);
    }
    
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size() / 2 - 1;
    int res = 0;
    for (int i = n; i > 0; i--) {
        int flag = 1;
        for (int j = 0; j < i; j++) {
            if (s[j] != s[j + i]) {
                flag = 0;
                break;
            }
        }
        if (flag == 1) res = max(i * 2, res);
    }   
    cout << res << endl;
}


Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
 		int n = Integer.parseInt(bf.readLine());
	 		ArrayList<Long> array = new ArrayList<Long>();
	 		StringTokenizer st2 = new StringTokenizer(bf.readLine());
	 		for(int j=0;j<n;j++){
	 			array.add(Long.parseLong(st2.nextToken()));
	 		}
	 	long yen = 1000;
	 	int i = 0;
	 	long min = array.get(0);
	 	long sum = 0;
	 	long max = 0;
	 	
	 	while(i< n){
	 		max = 0;
	 		int startindex = i+0;
	 		while(i < n-1 && array.get(i) <= array.get(i+1)){
	 			i++;
	 		}
	 		yen+=(yen/array.get(startindex)*(array.get(i)-array.get(startindex)));
	 		i++;
	 		
	 	}
 		out.println(yen);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25336
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int H=gi();
         int W=gi();
         int K=gi();
         String[] s=new String[H];
         int[][] cake=new int[H][W];

         for (int i=0; i<H;i++) {
             s[i]=gs();
         }

         int lh=0;
         int ni=1;
         for (int i=0; i<H;i++) {
             String g=s[i];
             if (g.contains("#")) {
            	 boolean isFirst=true;
            	 for (int j=0; j<W;j++) {
            		 char c=g.charAt(j);
            		 if(c=='#') {
            			 if(isFirst) {
            				 isFirst=false;
            			 } else {
            				 ni++;
            			 }
            		 }
            		 cake[i][j]=ni;
            	 }
               ni++;
             } else {
            	 lh=i;
             }
         }

         for (int i=1; i<H;i++) {
             for (int j=0; j<W;j++) {
                 if(cake[i][j]==0) {
                     cake[i][j]=cake[i-1][j];
                 }
             }
         }

         for (int i=H-2; i>=0;i--) {
             for (int j=0; j<W;j++) {
                 if(cake[i][j]==0) {
                     cake[i][j]=cake[i+1][j];
                 }
             }
         }

         StringBuilder sb=new StringBuilder();
         for (int i=0; i<H;i++) {
             for (int j=0; j<W;j++) {
            	 if(j!=0)sb.append(" ");
                 sb.append(cake[i][j]);
             }
             sb.append(System.lineSeparator());
         }

         System.out.println(sb);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 41924
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  long long sum = 0;
  long long sunuke = 0;
  long long nmin = LLONG_MAX;
 
  vector<int> a(N);
  
  for(int i = 0; i < N; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  for(int i = 0; i < N - 1; i++){
    sunuke += a[i];
    nmin = min(nmin, abs(sum - (2*sunuke)));
  }
  
  cout << nmin << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;

int main(){
  int n;
  cin >> n;
  int x[n],y[n],c[n];
  for(int i=0;i<n;++i){
    cin >> x[i] >> y[i] >> c[i];
  }
  int costx[1<<n][n];
  int costy[1<<n][n];
  for(int mask=0;mask<(1<<n);++mask){
    for(int i=0;i<n;++i){
      costx[mask][i]=abs(x[i]);
      costy[mask][i]=abs(y[i]);
      for(int j=0;j<n;++j){
        if((mask>>j)&1){
          costx[mask][i]=min(costx[mask][i],abs(x[i]-x[j]));
          costy[mask][i]=min(costy[mask][i],abs(y[i]-y[j]));
        }
      }
    }
  }
  long long ans[n+1];
  for(int i=0;i<n+1;++i){
    ans[i]=INF;
  }
  for(int maskall=0;maskall<(1<<n);++maskall){
    int cnt=0;
    for(int i=0;i<n;++i){
      if((maskall>>i)&1){
        cnt++;
      }
    }
    for(int maskx=maskall;maskx>=0;--maskx){
      maskx&=maskall;
      long long cost=0;
      for(int i=0;i<n;++i){
        if(!((maskall>>i)&1)){
          cost+=1LL*min(costx[maskx][i],costy[maskall-maskx][i])*c[i];
        }
      }
      ans[cnt]=min(ans[cnt],cost);
    }
  }
  for(int i=0;i<n+1;++i){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 7356
#include "iostream"
#include "algorithm"
#include "string"
#include "set"
#include "vector"
#include "climits"
using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W;

class Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	int num;
	long long int ret;
	bool is_min;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
	void RMQ(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			if (is_min)ret = min(ret, v[place]);
			else ret = max(ret, v[place]);
			return;
		}
		if (l[place]>b || r[place]<a) return;
		RMQ(a, b, place * 2);
		RMQ(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Segment_Tree(int n, bool min) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		l.resize(num);
		r.resize(num);
		is_min = min;
		if (min) {
			v.resize(num, MOD*MOD);
		}
		else v.resize(num, -MOD * MOD);
		Left(1);
		Right(1);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = LLONG_MAX;
		else ret = LLONG_MIN;
		RMQ(a, b, 1);
		return ret;
	}
};

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

	cin >> N >> K;
	vector<pair<long long int, long long int>>v(N + 2);
	for (int i = 1; i <= N; i++) {
		cin >> v[i].first >> v[i].second;
	}
	v[N + 1].first = K;
	vector<long long int>cww(N + 2);
	vector<long long int>rcww(N + 2);
	Segment_Tree sg(N + 2, false);
	for (int i = 1; i <= N; i++) {
		cww[i] = cww[i - 1];
		cww[i] -= v[i].first - v[i - 1].first;
		cww[i] += v[i].second;
		rcww[i] = cww[i] - v[i].first;
	}
	long long int ans = 0;
	long long int sum = 0;
	for (int i = N + 1; i >= 0; i--) {
		sum += v[i].second;
		sg.Insert(i, sum - K + v[i].first, false);
	}
	sg.TopDown();
	for (int i = 0; i <= N; i++) {
		ans = max(ans, rcww[i] + sg.RMQ(i + 1, N + 1));
	}
	for (int i = 0; i <= N+1; i++) {
		sg.Insert(i, sg.RMQ(i, i) - K + v[i].first, false);
	}
	sg.TopDown();
	for (int i = 0; i <= N; i++) {
		ans = max(ans, cww[i] + sg.RMQ(i + 1, N + 1));
	}
	cout << ans << endl;
	return 0;
}

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

int main() 
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; i++)
        cin >> v[i];
    sort(v.rbegin(), v.rend());
    int sum = 0;
    bool y=true;
    for (int i=0; i<n; i++)
    {
        if (y) sum+=v[i], y=false;
        else sum-=v[i], y=true;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ans = 0

    fac = 2
    e = 1
    while True:
        div = pow(fac, e)
        if n % div == 0:
            n //= div
            ans += 1
            e += 1
        else:
            while n % fac == 0:
                n //= fac
            fac += 1
            if fac * fac > n:
                break
            e = 1
    if n != 1:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int a[10];

int main(){
	for(int i = 1;i <= 5;i++){
		cin >> a[i];
		if(a[i] == 0) cout << i;
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
//using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
using pii=pair<ll,ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__);


int main(){
    dcl(h,w);
    int a=0;
    rep(i,h){string s;get(s);a+=count(all(s),'#');}
    
    if(h+w-1==a){
        cout<<"Possible"<<endl;
    }else cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
using namespace std;
int n,m;
int arr[1005];
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d%d",&n,&m);
    arr[0]=1;
    for (int x=0;x<n;x++){
        getchar();
        if (getchar()=='#') arr[0]=0;
        for (int y=1;y<m;y++){
            if (getchar()=='#') arr[y]=0;
            else arr[y]+=arr[y-1],arr[y]%=1000000007;
        }
    }
    printf("%d\n",arr[m-1]);
}


Measured memory_bytes: 128
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
///////////////SegmentTree/////////////////
struct SegTree 
{
	int n;
	vector<ll> Tree;
	void init(int sz)
	{
		n = sz;
		Tree.resize(4*n);
	}
	void set(int k, ll x) 
	{
		k+=n;
		Tree[k]=x;
		for(k=k/2;k>=1;k/=2)
		{
			Tree[k]=Tree[2*k]+Tree[2*k+1];
		}
	}
	ll sum(int a, int b)
	{
		a+=n;b+=n;
		ll s=0;
		while(a<=b)
		{
			if(a%2==1) s+=Tree[a++];
			if(b%2==0) s+=Tree[b--];
			a/=2;b/=2;
		}
		return s;
	}
};
///////////////SegmentTree/////////////////
///////////////////PnC/////////////////////
struct PnC
{
	int n;
	vl F,I;
	void init(int n)
	{
		F.resize(n+1);
		I.resize(n+1);
		F[0]=I[0]=1;
		for(int i=1;i<=n;i++)
		{
			F[i]=(F[i-1]*i)%MOD;
			I[i]=powN(F[i],MOD-2);
		}
	}
	ll nCr(int n,int r)
	{
		if(r>n) return 0;
		return (((F[n]*I[r])%MOD)*I[n-r])%MOD;
	}
};
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int n;
	cin>>n;
	vi L(n);
	take(L,0,n);
	sort(all(L));
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(L[i]+L[j]>L[k]&&L[i]!=L[j]&&L[j]!=L[k]) ans++;
			}
		}
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 7004
import java.util.*;


/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] a = {0,1,2,1,3,1,3,1,1,3,1,3,1};


        int q = scanner.nextInt();
        int w = scanner.nextInt();

        if(a[q] == a[w]){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }



    } // mainMethod


} // MainClass


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll a, b, k;
    cin >> a >> b >> k;
    rep(i, k) {
        if(i & 1) {
            a += b / 2;
            b /= 2;
        } else {
            b += a / 2;
            a /= 2;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    map<string,bool> mp;
    for(int a = 0;a < N;a++){
        string s;cin >> s;
        mp[s] = 1;
    }
    int M;cin >> M;
    bool kagi = false;
    for(int i = 0;i < M;i++){
        string s;cin >> s;
        if(mp[s] != 1){
            cout<<"Unknown "<<s<<endl;
            continue;
        }
        if(!kagi){
            cout<<"Opened by "<<s<<endl;
            kagi = !kagi;
        }else{
            cout<<"Closed by "<<s<<endl;
            kagi = !kagi;
        }
    }
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; typedef pair<int, P2> P3;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	int n; cin >> n; vector<vector<int>> g; g.resize(n, vector<int>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> g[i][j];
		}
	}
	vector<vector<int>> G = g;
	
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
			}
		}
	}
	
	if(g != G){
		cout << -1 << endl;
		return 0;
	}
	
	long long s = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < i; j++){
			bool f = true;
			for(int k = 0; k < n; k++){
				if(k == i or k == j) continue;
				if(g[i][k] + g[k][j] == g[i][j]) f = false;
			}
			
			if(f) s += g[i][j];
		}
	}		
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
t = list(t)
max_score = 0
max_score += t.count("r") * p
max_score += t.count("s") * r
max_score += t.count("p") * s

for i in range(k,n):
  if t[i] == t[i-k]:
    if t[i] == "p":
      max_score -= s
    if t[i] == "r":
      max_score -= p
    if t[i] == "s":
      max_score -= r
    t[i] = "f"
    
print(max_score)
      
      
    

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

struct citys
{
    long city_num;
    long year;
    std::string number;
    citys(long city_num1, long year1, std::string number1){
    city_num=city_num1;
    year=year1;
    number = number1;
  }
  bool operator<( const citys &another ) const {
        return year<another.year;
  }
};

struct num_and_name
{
    long city_num;
    std::string number;
    num_and_name(long city_num1, std::string number1){
    city_num=city_num1;
    number = number1;
  }
  bool operator<( const num_and_name &another ) const {
        return city_num<another.city_num;
  }
};

std::vector<std::vector<citys> > map(100000+1);

int main(){
    long N,M;
    std::cin >> N >> M;
    for(long i=0; i<M; i++){
        long P,Y;
        std::cin >> P >> Y;
        map[P].push_back(citys(i,Y,"T"));
    }

    for(long i=1; i<100000+1; i++){
        std::sort(map[i].begin(),map[i].end());
    }

    for(long i=1; i<100000+1; i++){
        std::string name("000000");
        long P_num=i;
        long count=6-1;
        while(P_num>0){
            name[count]='0'+(P_num%10);
            P_num=P_num/10;
            count-=1;
        }

        for(long j=0; j<map[i].size(); j++){
            std::string Cname("000000");
            long C_num=j+1;
            long countC=6-1;
            while(C_num>0){
                Cname[countC]='0'+(C_num%10);
                C_num=C_num/10;
                countC-=1;
            }
            map[i][j].number = name+Cname;
        }
    }

    std::vector<num_and_name> result;
    for(long i=1; i<100000+1; i++){
        for(long j=0; j<map[i].size(); j++){
            result.push_back(num_and_name(map[i][j].city_num,map[i][j].number));
        }
    }
    std::sort(result.begin(),result.end());
    for(long i=0;i<M; i++){
        std::cout << result[i].number << std::endl;
    }
    return 0;
}

Measured memory_bytes: 19188
import java.util.Scanner;

public class Main {

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

		while (true) {
			int n = scan.nextInt();
			if (n == 0)
				break;
			int[] x = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++)
				x[i] = scan.nextInt();
			for (int i = 0; i < n; i++)
				y[i] = scan.nextInt();

			for (int p = 1; p <= 3; p++) {
				double D = 0;
				for (int i = 0; i < n; i++)
					D += Math.pow(Math.abs(x[i] - y[i]), p);
				D = Math.pow(D, 1 / (double) p);
				System.out.println(D);
			}
			int D = 0;
			for (int i = 0; i < n; i++)
				D = Math.max(Math.abs(x[i] - y[i]), D);
			System.out.println(D);

			break;
		}

		scan.close();
		System.exit(0);
	}

}

Measured memory_bytes: 26572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <cassert>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
int a[maxn];
int n;

ll cal() {
    ll t = a[0], ans = 0;
    for (int i = 1; i < n; ++i) {
        if (t < 0) {
            t += a[i];
            if (t <= 0) { ans += 1 - t; t = 1; } continue;
        }
        t += a[i];
        if (t >= 0) { ans += t + 1; t = -1; }
    }
    return ans;
}

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d", &n);
    REP(i, n) { scanf("%d", &a[i]); }
    ll ans1 = 0, ans2 = 0, ans3 = 0, ans = 0; int t = a[0];
    if (t == 0) {
        a[0] = 1; ans1 = cal();
        a[0] = -1; ans2 = cal();
        ans = min(ans1, ans2) + 1;
    } else {
        ans1 = cal();
        a[0] = 1;  ans2 = cal() + abs(1 - t);
        a[0] = -1; ans3 = cal() + abs(-1 - t);
        ans = min(ans1, min(ans2, ans3));
    }
    printf("%lld\n", ans);
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


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

typedef long long int ll;

ll MOD = 1000000007;
ll INF = 100000000000;

int main(){
 ll N,M;
 cin >>  N >> M;
 priority_queue<ll> Q;
 for(int i = 0;i < N;i++){
   ll a;cin >> a;
   Q.push(a);
 }
 for(int i = 0;i < M;i++){
   ll x = Q.top();
   Q.pop();
   Q.push(x/2);
   //cout << Q.size() << ' ' << x/2 << endl;
 }
 ll ans = 0;
 for(int i = 0;i < N;i++){
   ans += Q.top();
   Q.pop();
 }
 cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


int main() {

    int A[100];
    int N;
    cin >> N;

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

    sort(A, A+N);

    int Alice = 0;
    int Bob = 0;

    for (int i=N-1; i>=0; i-=2) Alice += A[i];

    for (int i=N-2; i>=0; i-=2) Bob += A[i];

    cout << Alice - Bob << endl;
    

}

Measured memory_bytes: 256
a,b,c,k = map(int,input().split())
res=0
if k>a:
    k=k-a
    res=res+a
    if k>b:
        k=k-b
        
        if k>c:
            res-=c
        else:
            res-=k
    
else:
    res=k
print(res)




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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> cost_ans;
    int N, T;
    cin >> N >> T;
    for (int i = 0; i < N; ++i) {
        int cost, length;
        cin >> cost >> length;
        if (length <= T) {
            cost_ans.push_back(cost);
        }
    }

    if (cost_ans.empty()) cout << "TLE" << endl;
    else {
        sort(cost_ans.begin(), cost_ans.end());
        cout << cost_ans[0] << endl;
    }
}

Measured memory_bytes: 256