akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i] >> B[i];
	}

	//pair<int, int> は int2つの型
	vector<pair<int, int>> AB(N);
	for (int i = 0; i < N; i++)
	{
		AB[i] = make_pair(A[i], B[i]);
	}
	sort(AB.begin(), AB.end());

	long long ans = 0;
	for (int i = 0; i < N; i++)
	{
		//このお店で購入する数を決める
		int buy = min(M, AB[i].second);

		//買った金額を加算する
		ans += (long long)buy * AB[i].first;
		//残り本数を減らす
		M -= buy;
	}

	cout << ans << endl;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;

#define N  3
#define N2 9

static const int dx[4]   = {-1,0,1,0};
static const int dy[4]   = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p)const {
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};



bool isTarget(Puzzle x){
  for(int i=0;i<N2;i++)
    if(x.f[i]!=(i+1))   return false;
    return true;
}

string bfs(Puzzle start){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  start.path = "";
  Q.push(start);
  V[start] = true;

  while(!Q.empty()){
    u = Q.front(); Q.pop();
    if(isTarget(u))return u.path;
    int xStart = u.space / N;
    int yStart = u.space % N;

    for(int k=0;k<4;k++){
	    int xTarget = xStart + dx[k];
	    int yTarget = yStart + dy[k];
	    if(xTarget<0 || yTarget<0 || xTarget >=N || yTarget>=N) continue;
	    v = u;
	    swap(v.f[u.space],v.f[xTarget*N+yTarget]);
	    v.space = xTarget*N+yTarget;
	    if(!V[v]){
	      V[v] = true;
	      v.path += dir[k];
	      Q.push(v);
	    }
    }
  }
  return NULL;
}
  

int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]  = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout<<ans.size()<<endl;
  
  return 0;
}



Measured memory_bytes: 30516
def dfs(i, f):
  if i == n-1:
    return sum(list(map(int,f.split("+"))))
  return dfs(i+1, f+"+"+s[i+1])+dfs(i+1, f+s[i+1])

s = input()
n = len(s)

print(dfs(0,s[0]))

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }    
  bool e[n][n]; memset(e, 0, sizeof(e));
  for (int i = 0; i < m; i++) e[a[i]][b[i]] = e[b[i]][a[i]] = 1;
  int res = 0;
  int path[n];
  for (int i = 0; i < n; i++) path[i] = i;
  do {
    bool f = 1;
    for (int i = 0; i < n - 1; i++) if (!e[path[i]][path[i + 1]]) f = 0;
    res += f;
  } while (next_permutation(path + 1, path + n));
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
my $stdin = "";
while (<STDIN>) {
  $stdin = $_;
  chomp $stdin;
}

my @num = split /\s/, $stdin;
@num = sort { $b <=> $a } @num;
 
my $sum = 0;
$sum += $_ for @num[1..$#num];
print $sum > $num[0] ? "Yes" : "No"; 

Measured memory_bytes: 512
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

#define pmax 200002
int recnum[32][pmax];

int main(){
    ll N,C;
    cin >> N >>C;
    Fill(recnum,0);

    int s,t,c;
    for(int i=0; i<N; i++){
        cin >> s >> t >> c;
        recnum[c][2*s-1]++;
        recnum[c][2*t]--;
    }
    int ans=0;
    for(int i=0; i<pmax; i++){
        int temp=0;
        for(int j=1; j<=C; j++) {
            recnum[j][i + 1] += recnum[j][i];
            if(recnum[j][i + 1]>0) {
                temp++;
            }
        }
        ans=max(ans,temp);
    }

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



Measured memory_bytes: 25216
N = int(input())
W = []
flg = True
for i in range(N):
    w = input()
    if i != 0:
        if W[i-1][len(W[i-1])-1] != w[0]:
            print('No')
            flg = False
            break
        if w in W:
            print('No')
            flg = False
            break
    W += [w]
if flg:
    print('Yes')

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

public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		double L = in.nextInt();
		double l = L / 3;
		System.out.println(BigDecimal.valueOf(l*l*l).toPlainString());
	}


	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

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

int dp[45];

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

    dp[0]=1;
    dp[1]=1;
    
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }

    cout<<dp[n]<<endl;
    
    return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	int a,b;
	cin>>a>>b;
	if(a>=13)cout<<b;
	else if(a>5)cout<<b/2;
	else cout<<0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <string.h>
int c1, c2;
int main()
{
    int n;
    char card1[101], card2[101];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 101; j++)
        {
            card1[j] = 0;
        }
        for (int j = 0; j < 101; j++)
        {
            card2[j] = 0;
        }
        scanf("%s %s", card1, card2);
        if (strcmp(card1, card2) == 0)
        {
            c1 += 1;
            c2 += 1;
        }
        else if (strcmp(card1, card2) > 0)
        {
            c1 += 3;
        }
        else if (strcmp(card1, card2) < 0)
        {
            c2 += 3;
        }
    }
    printf("%d %d\n", c1, c2);
}


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

int A[100005],n;
int partition(int A[],int p,int r)
{
	int x = A[r];
	int i = p-1;
	for (int j = p; j < r; ++j)
	{
		if (A[j] <= x)
		{
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

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

	int q = partition(A,0,n-1);

	for (int i = 0; i < n; ++i)
	{
		if(i)
		{
			printf(" ");
		}
		if (i == q)
		{
			printf("[");
		}
		printf("%d",A[i]);
		if (i == q)
		{
			printf("]");
		}
	}
	printf("\n");	
	return 0;
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
int a[1000];
signed main()
{
	ri n=read();ri ans=1e17;
	rep(i,1,n)a[i]=read();
	rep(j,-100,200){
		ri s=0;
		rep(i,1,n)s+=(a[i]-j)*(a[i]-j);
		ans=min(ans,s);
	}cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;


int main()
{
	int n;
	string s;
	cin >> n >> s;
	ll js[100010]={}, is[100010]={};
	ll ans=0, ans1=0, ans2=0, mx=0;
	rep(i, n-1)
	{
		js[i+1]=js[i]+(s[i]=='J');
		is[n-2-i]=is[n-1-i]+(s[n-1-i]=='I');
	}
	rep(i, n)
	{
		ans+=((s[i]=='O')*js[i]*is[i]);
		ans1+=((s[i]=='O')*(js[i]+1)*is[i]);
		ans2+=((s[i]=='O')*js[i]*(is[i]+1));
	}
	rep(i, n) mx=max(mx, js[i+1]*is[i]);
	cout << max(ans+mx, max(ans1, ans2)) << endl;
	return 0;
}

Measured memory_bytes: 4832
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  D = list(map(int, readline().split()))
  ans = 0
  for i in range(N-1):
    for j in range(i+1,N):
      ans += D[i]*D[j]
  print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<map>
#define ll long long
using namespace std;
int T,d;
int w[5],dv[5]={2,3,5};
ll n;
const ll inf=4e18;
map<ll,ll>f;
ll dfs(ll x){
	//cout<<x<<endl;
	if(!x)return 0;
	if(f[x])return f[x];
	ll res=x>inf/d?inf:x*d;
	for(register int i=0;i<3;i++){
		ll y=x/dv[i];
		//cout<<"x="<<x<<" dfs="<<y<<endl;
		if(y<x)res=min(res,dfs(y)+w[i]+(x-y*dv[i])*d);
		y=(x+dv[i]-1)/dv[i];
		//cout<<"x="<<x<<" dfs="<<y<<endl;
		if(y<x)res=min(res,dfs(y)+w[i]+(y*dv[i]-x)*d);
	}
	return f[x]=res;
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%lld%d%d%d%d",&n,&w[0],&w[1],&w[2],&d);
		f.clear();
		printf("%lld\n",dfs(n));
	}
	return 0;
}

Measured memory_bytes: 4460
#include <iostream>
int main() {
    int h,w;
    while (scanf("%d %d", &h, &w)) {
        if (h == 0 && w == 0) break;
        char o[w+1], e[w+1];
        for (int i = 0; i < w; i++) {
            if (i % 2 == 0) {
                o[i] = '#';
                e[i] = '.';
            } else {
                o[i] = '.';
                e[i] = '#';
            }
        }
        o[w] = '\0';
        e[w] = '\0';
        for (int i = 0; i < h; i++) {
            if (i % 2 == 0) puts(o);
            else puts(e);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 3132
def divisors(N):
    i = 1
    U = int(N ** 0.5)
    res = []
    for i in range(1, U):
        if N % i == 0:
            res += [i, N // i]
    if N % i == 0:
        res.append(i)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    s <- getInt
    let f 1 a _ _ = a
        f n a b c = f (n-1) b c ((a+c) `mod` 1000000007)
    print $ f s 0 0 1


Measured memory_bytes: 3948
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	final int MAX = Integer.MAX_VALUE;
	
	void run() {
		while (true) {
			int n = sc.nextInt(), m = sc.nextInt();
			if (n == 0 && m == 0) break;
			
			int[] c = new int[m];
			int[] x = new int[n];
			for (int i = 0; i < m; i++)
				c[i] = sc.nextInt();
			for (int i = 0; i < n; i++)
				x[i] = sc.nextInt();
			
			int[][] dp = new int[n+1][256];
			for (int i = 0; i <= n; i++)
				for (int j = 0; j < 256; j++)
					dp[i][j] = MAX;
			dp[0][128] = 0;
			
			for (int i = 1; i <= n; i++) {
				for (int j = 0; j < 256; j++) {
					if (dp[i-1][j] < MAX) {
						for (int k = 0; k < m; k++) {
							int t;
							if (c[k] > 0)
								t = Math.min(j+c[k], 255);
							else 
								t = Math.max(j+c[k], 0);
							dp[i][t] = Math.min(dp[i][t], dp[i-1][j] + (x[i-1] - t)*(x[i-1] - t));
						}
					}
				}
			}
			Arrays.sort(dp[n]);
			out.println(dp[n][0]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

int main () {
    string S;
    cin >> S;
    int L = S.size();

    string ans = "AC";
    if (S[0] != 'A') ans = "WA";

    int cnt = 0;
    for (int i = 1; i < L; i++) {
        if (isupper(S[i])) { //isupper関数は、括弧内の文字が大文字なら真
            if (i == 1 || i == L - 1 || S[i] != 'C') ans = "WA";
            cnt++;
        }
    }
    if (cnt != 1) {
        ans = "WA";
    }
    cout << ans << endl;

    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);

  ll A,B,C,K;
  cin >> A >> B >> C >> K;

  ll ans;
  if(K <= A){
    ans = K;
  } else if(K <= A + B){ 
    ans = A;
  } else {
    ans = A - (K-A-B);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;

const int mod = 1e9+7;
const int N = 6e5+2;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int edge[N] = {0};
vector<pii> e[N];
void dfs(int u, int p, int pc) {
    int c = 1;
    rep(i, 0, sz(e[u])) {
        int v = e[u][i].se, id = e[u][i].fi;
        if(v == p) continue;
        if(c == pc) c++;
        edge[id] = c;
        dfs(v, u, c);
        c++;
    }
}
int main() {
    int n; cin>>n;
    int mx = 0;
    rep(i, 1, n) {
        int u, v; cin>>u>>v;
        e[u].pb(mp(i, v));
        e[v].pb(mp(i, u));
    }
    dfs(1, -1, -1);
    cout<<*max_element(edge + 1, edge + n)<<endl;
    rep(i, 1, n) cout<<edge[i]<<endl;
    return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

vector<int> calc(const vector<int> &a) {
	const int n = a.size();
	vector<int> dp(n, 0);

	int value = 0;
	for(int i = 0; i < n; ++i) {
		if(value > 0) --value;

		if(a[i] == 0) {
			value = INT_MAX;
		}
		else if(a[i] < 0) {
			chmin(value, -a[i]);
		}

		dp[i] = value;
	}

	return dp;
}

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

	int n;
	cin >> n;

	vector<int> a(n);
	for(auto &e : a) cin >> e;

	vector<int> left = calc(a);
	reverse(begin(a), end(a));
	vector<int> right = calc(a);
	reverse(begin(a), end(a));

	reverse(begin(right), end(right));

	dump(left, right);

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(a[i] > 0) ans += min(a[i], max(left[i], right[i]));
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2316
#include<iostream>
using namespace std;
int main(void){
  string s[110],t[110];
  int n,m;cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  cin>>m;
  for(int i=0;i<m;i++)cin>>t[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int sc=0;
    for(int j=0;j<n;j++)if(s[i]==s[j])sc++;
    for(int j=0;j<m;j++)if(s[i]==t[j])sc--;
    ans=max(ans,sc);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    s = S()
    print("A" if s.upper() == s else "a")

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

char a;

main() {
    cin >> a;
    if (a == 'A') cout << 'T' << endl;
    else if (a == 'C') cout << 'G' << endl;
    else if (a == 'G') cout << 'C' << endl;
    else cout << 'A' << endl;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
S = list(input())
ans = 0
k = 0
c = 0

for i in range(N-1):
    if S[i] != S[i+1]:
        if c < K:
            if k == 0:
                k += 1
            else:
                ans += 2
                c += 1
                k = 0
    else:
        ans += 1

if k == 1 and c < K:
    ans += 1

print(ans)

Measured memory_bytes: 49648
#include <iostream>

using namespace std;

int main()
{
	int n;
	char c;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> c;
		if (c == 'Y')
		{
			cout << "Four";
			return 0;
		}
	}
	cout << "Three";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            List<string> lstW = new List<string>();
            for (int i = 0; i < iN; i++) { lstW.Add(System.Console.ReadLine().Trim()); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yes";
            int iWC = lstW.Count;
            for (int i = 1; i < iWC; i++)
            {
                int iBL = lstW[i - 1].Length - 1;   // 前の語の末尾文字
                if (lstW[i - 1].Substring(iBL, 1) != lstW[i].Substring(0, 1)) { sOut = "No"; break; }
            }
            lstW = lstW.Distinct().ToList();        // 重複あれば削除
            int iWDC = lstW.Count;
            if (iWC != iWDC) { sOut = "No"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13280
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    long long N,K,R,S,P;
    string T;
    cin>>N>>K;
    cin>>R>>S>>P;
    cin>>T;
    ll res=0;
    for(int i=0;i<N;i++)
    {
        if(T[i]=='r'){
            if(T[i+K]=='r')T[i+K]='x';
        }
        else if(T[i]=='s'){
            if(T[i+K]=='s')T[i+K]='x';
        }
        else if(T[i]=='p'){
            if(T[i+K]=='p')T[i+K]='x';
        }
    }
    for(int i=0;i<N;i++)
    {
        if(T[i]=='r')res+=P;
        else if(T[i]=='s')res+=R;
        else if(T[i]=='p')res+=S;
    }
    cout<<res;
}

Measured memory_bytes: 3728
import sys

N,M=map(int,input().split())
bad=set(map(int,sys.stdin))
MOD=10**9+7

a,b=0,1
for i in range(1,N+1):
    if i in bad:
        a,b=b,0
        if a==0:
            break
    else:
        a,b=b,(a+b)%MOD

print(b)


Measured memory_bytes: 17228
#include <iostream>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;

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

    int numStart[m];
    int numEnd[m];
    for (int i = 0; i < m; i++)
    {
        cin >> numStart[i] >> numEnd[i];
    }
    
    int startMaxNum = numStart[0];
    int endMinNum = numEnd[0];
    for (int gateIndex = 0; gateIndex < m; gateIndex++)
    {
        if (numStart[gateIndex] > startMaxNum)
        {
            startMaxNum = numStart[gateIndex];
        }

        if (numEnd[gateIndex] < endMinNum)
        {
            endMinNum = numEnd[gateIndex];
        }
    }

    int result = max(0, (endMinNum - startMaxNum + 1));

    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define debug(var)                  \
    do {                            \
        std::cout << #var << " : "; \
        view(var);                  \
    } while (0)
template <typename T>
void view(T e) { std::cout << e << std::endl; }

template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}

template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

using namespace std;
//yosupo
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

int main() {
    int X;
    cin >> X;
    cout << 8 - (X - 400) / 200 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

signed main(){
    ll N;
    cin >> N;
    ld p[N];
    ld DP[N][N+1];
    FOR(i,0,N)cin >> p[i];
    FOR(i,0,N)FOR(j,0,N+1)DP[i][j] = 0;
    DP[0][0] = (ld)1-p[0];
    DP[0][1] = (ld)p[0];
    FOR(i,1,N)FOR(j,0,N+1){
        if(j == 0){
            DP[i][j] = ((ld)1-p[i])*(DP[i-1][j]);
        }
        else{
            DP[i][j] = p[i]*DP[i-1][j-1]+((ld)1-p[i])*DP[i-1][j];
        }
    }
    vector<ld> v;
    FOR(i,N/2+1,N+1)v.pb(DP[N-1][i]);
    sort(ALL(v));
    ld ans = 0;
    FOR(i,0,v.size())ans += v[i];
    cout << fixed << setprecision(20) << ans << endl;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> B(N-1);
    for (int i=0;i<N-1;i++) cin >> B[i];
    int sum = B[0];
    for (int i=1;i<N-1;i++){
        sum += min(B[i-1],B[i]);
    }
    sum += B[N-2];
    cout << sum << endl;

    return 0;
}

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

int n,m;
string s,t;
int dp[maxn][maxn];

int main() {
	cin >> s >> t;
	n = s.length();
	m = t.length();
	for( int i = n-1 ; i >= 0 ; i-- )
		for( int j = m-1 ; j >= 0 ; j-- ) {
			if(s[i] == t[j])
				dp[i][j] = dp[i+1][j+1] + 1;
			dp[i][j] = max( dp[i][j] , dp[i][j+1] );
			dp[i][j] = max( dp[i][j] , dp[i+1][j] );
		}
	int i=0,j=0;
	while(i < n && j < m) {
		if(s[i] == t[j] && dp[i][j] == dp[i+1][j+1] + 1)
			j++, printf("%c",s[i++]);
		else if(dp[i][j] == dp[i][j+1])
			j++;
		else
			i++;
	}
	puts("");
	return 0;
}


Measured memory_bytes: 35456
#!/usr/bin/env python3
import sys, math, fractions, itertools, bisect

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str

def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    G = [[] for _ in range(N)]
    for i in range(M):
        G[a[i]-1].append(b[i]-1)
        G[b[i]-1].append(a[i]-1)
    G[0].sort()
    G[-1].sort()
    flag = False
    for g in G[0]:
        i = bisect.bisect_left(G[-1], g)
        if 0 <= i <= len(G[-1])-1:
            if G[-1][i] == g:
                flag = True
    if flag:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


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

int main() {
  int n; cin >> n;
  vector<int> houses(n);
  for (int i = 0; i < n; i++) cin >> houses[i];
  
  int max = *max_element(houses.begin(), houses.end());
  int min = *min_element(houses.begin(), houses.end());
  
  cout << max - min << endl;
}

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

int main() {
   int N,W;
   cin >> N >> W;
   long long v[N],w[N];
   for (int i=0; i<N; i++) {
       cin >> v[i] >> w[i];
   }
   long long V[N][W+1];
   for (int i=0; i<N; i++) {
       for (int j=0; j<=W; j++) {
           V[i][j]=0;
       }
   }
   for (int i=0; i<N; i++) {
       for (int j=0; j<=W; j++) {
           if (j<w[i]) {
               if (i!=0) {
                   V[i][j]=V[i-1][j];
               }
               continue;
           }
           if (i==0) {
               int a=j/w[0];
               V[i][j]=v[0]*a;
               continue;
           }
           V[i][j]=max(/*max(*/V[i-1][j]/*,V[i-1][j-w[i]]+v[i])*/,V[i][j-w[i]]+v[i]);
       }
   }
   cout << V[N-1][W] << endl;
}


Measured memory_bytes: 10904
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>

#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int main()
{
        string moji;
        cin >> moji;

        for (int i = 0; i < moji.size(); i++)
        {
                if (moji[i] == moji[i + 1])
                {
                        cout << i + 1 << ' ' << i + 2 << endl;
                        return 0;
                }
                else if (i < moji.size() - 2 && moji[i] == moji[i + 2])
                {
                        cout << i + 1 << ' ' << i + 3 << endl;
                        return 0;
                }
        }

        cout << "-1 -1" << endl;
        return 0;
}


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;



int main() {
	int K, S;
	cin >> K >> S;
	ll ans = 0;
	rep(i, K+1)rep(j, K+1) {
		if (S - i - j >= 0 && S - i - j <= K)ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int n;
  std::string s;
  std::cin >> n >> s;

  if (n % 2 != 0) {
    std::cout << "No" << std::endl;
    return 0;
  }

  bool flag = true;
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[i + n / 2]) {
      flag = false;
      break;
    }
  }

  std::cout << (flag ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 256
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <cassert>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET{IOSET(){cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main Code
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, n + 1) rep(j, m + 1) {
        if (i * j + (n - i) * (m - j) == k) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=0;
  if(a>=b)
    ans+=b;
  else
    ans+=a;
  if(c>=d)
    ans+=d;
  else
    ans+=c;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 0; i < (ll)c; i++)
#define ll long long
const int inf = 1000000000; // 10^9

int main(){
    ll n, m, a[110], all = 0, cnt = 0;
    cin >> n >> m;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        all += a[i];
    }

    for(ll i = 0; i < n; i++){
        if(all <= 4 * m * a[i]) cnt++;
    }

    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	ArrayList<Long> list;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		init();
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if((n|k) == 0) break;
			int ind = binarySearch(n);
			ind++;
			long num  = pow(ind - 1);
			int diff = (int) (n - list.get(ind-1));
			int div = diff / ind;
			int mod = diff % ind;
			long num2 = num + div;
			StringBuilder sb = new StringBuilder();
			while(sb.length() < k + mod){
				sb.append(num2);
				num2++;
			}
			System.out.println(sb.substring(mod, k + mod));
		}
	}
	
	private int binarySearch(int patt){
		int mid, left = 0, right = list.size()-1;
		while(left <= right){
			mid = (left + right) / 2;
			if(list.get(mid) == patt){
				return mid;
			}
			if(list.get(mid) < patt){
				left = mid + 1;
			}
			else{
				right = mid - 1;
			}
		}
		return right;
	}

	private void init() {
		list = new ArrayList<Long>();
		list.add(1L);
		for(int i = 1; i <= 9; i++){
			long temp = (pow(i) - 1 - pow(i-1) + 1) * i + list.get(i-1);
			list.add(temp);
		}
	}

	private long pow(int num) {
		long sum = 1;
		for(int i = 0; i < num; i++){
			sum *= 10;
		}
		return sum;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 19800
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

LL dp[2010] ;

int main()
{
	int S ;
	scanf ("%d", &S) ;
	
	for (int i=3; i<=S; i++)
	{
		dp[i] = 1 ;
		for (int j=3; j<=i-3; j++)
			dp[i] = (dp[i] + dp[j]) % MOD ;
	}
	
	cout << dp[S] << endl ;

	return 0 ;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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;
}

int main(){
    int N; cin >> N;
    vector<int> p(N, 0);
    rep(i, N) {
        cin >> p[i];
    }
    sort(p.begin(), p.end(), greater<int>());
    int ans = p[0] / 2;
    rep(i, N - 1) {
        ans += p[i + 1];
    }
    cout << ans << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 10 || b >= 10) {
		cout << -1 << endl;
		return 0;
	}
	cout << a * b << endl;
	return 0;
}


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

i64 N;

using P = pair<i64,i64>;

map<P,i64> dp;
i64 MOD = 1e9 + 7;
i64 rec(i64 S,i64 X){
  if(S == 0 && X == 0){
    return 1;
  }
  if(dp.count({S,X})) return dp[{S,X}];

  i64 res = 0;
  res = (res + rec(S / 2 , X / 2)) % MOD;
  if(S - 1 >= 0 && X - 1 >= 0){
    res = (res + rec((S - 1) / 2 , (X - 1) / 2)) % MOD;
  }
  if(S - 2 >= 0){
    res = (res + rec((S - 2) / 2 , X)) % MOD;
  }
  return dp[{S,X}] = res;
}

int main(){
  cin >> N;

  cout << rec(N,N) << endl;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    ll L0 = 2;
    ll L1 = 1;
    ll tmp;
    if ( N == 1 ) printf("1\n");
    else{
        REP(ll, i, 1, N){
            ans = L1 + L0;
            tmp = L1;
            L1  = ans;
            L0  = tmp; 
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

using namespace std;


    long long g(long long a,long long b){

	int r=max(a,b)%min(a,b);
	if(r==0)  return min(a,b);
	else return g(min(a,b),r);
}

int main(){

	long long a,b;

	while(1){

	cin >> a >> b;

	if(cin.fail()) break;

	cout << g(a,b) << " " << (a*b)/g(a,b) << endl;

	}

	return 0;
}

Measured memory_bytes: 1156
package main

import (
    "fmt"
)

var n, k int 
var as []int
var dp [][]int
var sdp [][]int

const mod = int(1e9 + 7)

func main() {
    fmt.Scan(&n, &k) 
    as = make([]int, n)
    for i := range as {
        var a int 
        fmt.Scan(&a)
        as[i] = a 
    }   

    // dp[i][k] i番目まででk個になる通り
    dp = make([][]int, n)
    sdp = make([][]int, n)
    for i := 0; i < n; i++ {
        dp[i] = make([]int, k+1)
        sdp[i] = make([]int, k+2)
    }   

    dp[0][0] = 1 
    sdp[0][1] = 1 
    for j := 1; j < k+1; j++ {
        if j <= as[0] {
            dp[0][j] = 1 
        }   
        sdp[0][j+1] = sdp[0][j] + dp[0][j]
    }   

    for i := 1; i < n; i++ {
        for j := 0; j < k+1; j++ {
            dp[i][j] = gm(sdp[i-1][j+1] - sdp[i-1][max(j-as[i], 0)])
            sdp[i][j+1] = gm(sdp[i][j] + dp[i][j])
        }   
    }   

    fmt.Println(dp[n-1][k])
}

func max(a, b int) int {
    if a > b { 
        return a
    }   
    return b
}

func gm(n int) int {
    if n < 0 { 
        n += mod 
    }   
    return n % mod 
}


Measured memory_bytes: 162944
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let n:usize=read!();
    let k:usize=read!();
    let mut v=Vec::new();
    for _i in 0..n {
        let b:usize=read!();
        v.push(b);
    }
    v.sort();
    let mut ans:usize=100000000000;
    for i in 0..=n-k {
        if v[i+k-1]-v[i]<ans {ans=v[i+k-1]-v[i]}
    }
    println!("{}",ans)
}

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

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  cout << (N-K>0?K*X+(N-K)*Y:N*X) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<stdlib.h>
#include<stdio.h>
int main()
{
	int n, flag = 1;
	scanf("%d", &n);
	int x = 0, y = 0, t = 0;
	for (int i = 0;i < n;i++)
	{
		int x1, y1, t1;
		scanf("%d%d%d",&t1, &x1, &y1);
		if ((abs(t1 - t)-abs(x1 - x) + abs(y1 - y)) % 2 != 0|| abs(t1 - t)<(abs(x1 - x) + abs(y1 - y)))flag = 0;
		x = x1;
		y = y1;
		t = t1;
	}
	printf(flag ? "Yes\n" : "No\n");
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    string N;
    cin >> N;
    int d = 0;
    for (auto c : N) {
        d += c - '0';
    }
    auto n = stol(N);
    if (n % d) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3620
from collections import deque
N,M=map(int,input().split())
arr=[[] for n in range(N)]
que=deque([1])

for m in range(M):
  a,b=map(int,input().split())
  arr[a-1].append(b)
  arr[b-1].append(a)

dist=[-1]*N
dist[0]=0
arr2=[0]*(N-1)

print("Yes")
while que:
  c=que.popleft()
  for i in arr[c-1]:
    if dist[i-1]!=-1:
      continue
    
    dist[i-1]=0
    arr2[i-2]=c
    que.append(i)
       
for i in arr2:
  print(i)
  
  

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

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int K	 = scn.nextInt();
		String S = scn.next();
		scn.close();
		if (S.length() <= K) {
			System.out.println(S);
		}else {
			String ans = S.substring(0,K);
			System.out.println(ans+"...");
		}
	}

}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll M = 1e9+7;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  map<char, int> mp;

  int N;
  cin >> N;
  string S;
  cin >> S;
  for(int i = 0; i < S.length(); i++){
    mp[S[i]]++;
  }

  ll ans = 1;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    ans *= (itr->second+1);
    ans = ans % M;
  }

  cout << ans - 1 << endl;


  return 0;
}



Measured memory_bytes: 512
import sys
from functools import reduce

n, m = map(int, input().split())
ps = [r.split() for r in sys.stdin.read().split('\n') if r != '']
ps.sort(key=lambda t: int(t[0]))
log = []
for i in range(0, n):
    log.append([])
for j in range(0, m):
    i = int(ps[j][0])
    log[i-1].append(ps[j][1])
wacount = sum(map(lambda l: l.index('AC'), filter(lambda e: e.count('AC') > 0, log)))
print(len(list(filter(lambda e: e.count('AC') > 0, log))),
        wacount)

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

int countBom(vector<string> map, int x1, int x2, int y1, int y2)
{
  int count = 0;

  for(int Y=y1; Y<=y2; Y++)
  {
    for(int X=x1; X<=x2; X++)
    {
      if(map[Y].at(X) == '#')
        count++;
    }
  }
  
  return count;
}

int main() {

  int x, y;
  cin >> y >> x;
  vector<string> ss;
  
  for(int j=0; j<y; j++)
  {
    string s;
    cin >> s;
    ss.push_back(s);
  }
  
  for(int j=0; j<y; j++)
  {
//    cout << ss[j] << endl;
    for(int i=0; i<x; i++)
    {
      if(ss[j].at(i) == '#'){
        cout << "#";
        continue;
      }
      
      // count boms
      int x1 = max(0, i-1);
      int x2 = min(i+1, x-1);
      int y1 = max(0, j-1);
      int y2 = min(j+1, y-1);
      
//      cout << y1 << ", " << y2 << " | ";
      
      int count = countBom(ss, x1, x2, y1, y2);
      
//      cout << count << ", ";
//      if(count > 0){
         cout << count;
//      }else{
//        cout << ss[j].at(i);
//      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
/*
1 4 1 4 1
1 4 2 2 2
1 4 1 4 1 4 1
1 4 2 2 2 2 2 
1 4 1 4 1 4 1 4 1
1 4 2 2 2 2 2 2 2 

1 4 1 4
1 4 2 2
1 4 1 4 1 4
1 4 2 2 2 2 
*/

#include <iostream>

using namespace std;

int main() {
    int n, a, fr = 0, to = 0;

    cin >> n;

    for (int i=0; i<n; i++) {
        cin >> a;

        if (!(a%4)) {
            fr++;
        }
        else if (!(a%2)) {
            to++;
        }
    }

    //cout << fr << " " << to << " " << n/2 << endl;

    if (n/2 <= fr) {
        cout << "Yes" << endl;
    }
    else if (n%2 && (n/2-fr)*2+1 <= to) {
        cout << "Yes" << endl;
    }
    else if (!(n%2) && (n/2-fr)*2 <= to) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long N[200];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> N[i];
        if (N[i] % 2 != 0)
        {
            cout << "0" << endl;
            return 0;
        }
    }

    int result = 0;
    while (true)
    {
        for (int i = 0; i < n; ++i)
        {
            if (N[i] == 0)
            {
                continue;
            }

            if (N[i] % 2 == 0)
            {
                N[i] /= 2;
            }
            else
            {
                cout << result << endl;
                return 0;
            }
        }
        ++result;
    }

    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        List<Integer> h = new ArrayList<>();
        IntStream.range(0, n).forEach(i -> h.add(sc.nextInt()));

        int palace = 0;
        double nearestMeter = 0;
        for (int i = 0; i < n; i++) {
            double temp = t - h.get(i) * 0.006;
            if (i == 0 || nearestMeter > Math.abs(temp - a)) {
                palace = i + 1;
                nearestMeter = Math.abs(temp - a);
            }
        }
        System.out.println(palace);
    }

}


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

namespace AtCoder.Abc
{
    class A_170_Five_Variables
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            int[] inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int result = Array.IndexOf(inputLongArray,0) + 1;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27940
import java.util.*

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val m = ArrayList<String>()
  for (i in 0..n-1) m.add(readLine()!!.toCharArray().sorted().joinToString(""))
  var ans = 0L
  val cnt = mutableMapOf<String,Int>()
  for (i in 0..n-1)
  {
    ans += cnt[m[i]]?.toLong() ?: 0
    cnt[m[i]] = (cnt[m[i]]?: 0) + 1
  }
  println(ans)
}


Measured memory_bytes: 77236
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define bit(x) (1 << x)
#define par pair<int,int>
#define maxn 200005

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

int N,M;

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2;



}


Measured memory_bytes: 256