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

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		
		int count = 0;
		for (int i = 1; i <= n / 2; i++) {
			int sum = i;
			for (int j = i + 1; ; j++) {
				sum += j;
				if (sum == n) {
					count++;
					break;
				} else if (sum > n) {
					break;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int f(VI n, int k){
    while(n.back() == 0){
        n.pop_back();
    }
    int len = n.size();
    if(len < k) return 0;
    if(k == 1){
        return 9*(len-1) + n.back();
    }else{
        VI m(len-1, 9);
        int n0 = n.back();
        n.pop_back();
        return f(m,k) + (n0-1)*f(m,k-1) + f(n,k-1);
    }
}

int main(){
    string s;
    int k;
    cin >> s >> k;

    int len = s.size();
    VI n(len);
    rep(i,len){
        n[i] = s[len-i-1] - '0';
    }

    cout << f(n,k) << endl;

    return 0;
}

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

int g(ll n) {
   int res = 0;
   while (n) {
      n /= 10;
      res++;
   }
   return res;
}
int f(ll a, ll b) { return max(g(a), g(b)); }
int main() {
   ll n;
   cin >> n;
   int ans = 100;
   for (int i = 1;(ll) i * i <= n; i++) {
      if (n % i == 0) {
         ans = min(ans, f(i, n / i));
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
	int n;
	cin>>n;
	int a[2*n];
	rep(i,2*n) cin>>a[i];
	sort(a,a+2*n);
	int ans=0;
	rep(i,2*n){ans+=a[i];i++;}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX_N 200000

int n;
int a[MAX_N];

void solve() {
	if (n == 1) {
		cout << a[0] << endl; return;
	}
	if (n % 2 == 0) {
		for (int i = n - 1; i >= 1; i -= 2) cout << a[i] << ' ';
		for (int i = 0; i <= n - 4; i += 2) cout << a[i] << ' ';
		cout << a[n - 2] << endl;
	}
	else {
		for (int i = n - 1; i >= 0; i -= 2) cout << a[i] << ' ';
		for (int i = 1; i <= n - 3; i += 2) cout << a[i] << ' ';
		cout << a[n - 2] << endl;
	}
}

int main() {

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

	solve();

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	string S; cin >> S;
	for (int i = 0; i < S.length(); i+=2) {
		if (S[i] != 'R' && S[i] != 'U' && S[i] != 'D') {
			cout << "No" << endl;
			return;
		}
	}
	for (int i = 1; i < S.length(); i+=2) {
		if (S[i] != 'L' && S[i] != 'U' && S[i] != 'D') {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline

A, B, H, M = map(int, input().split())
h = H / 12 + (M / 60) / 12
m = M / 60

hx = 360 * h
mx = 360 * m
dx = min(abs(hx - mx), 360 - abs(hx - mx))
dtheta = math.radians(dx)
ret = (A * math.sin(dtheta)) ** 2 + (B - A * math.cos(dtheta)) ** 2
print(math.sqrt(ret))

Measured memory_bytes: 62368
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std ;
int main () {
    string s,ans;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++){
        
        if (i%2 == 0) {
            ans += s[i];
        }
        
    }
    cout << ans <<endl;
    return 0;
} 

Measured memory_bytes: 512
//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007

int main()
{
    startt
    string s;
    cin >> s;
    int ans = 0;
    int c = 0;
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == 'R')
        {
            c++;
        }
        else
        {
            c = 0;
        }
        ans = max(ans, c);
    }
    ans = max(ans, c);
    cout << ans << endl;
}


Measured memory_bytes: 3648
def check(d,j,l):

    ret = True

    for k in range(l - j + 1):
        k += j
        if a[d][k] == "#" or ans[d][k] != 0:
            ret = False
            break

    return ret
        


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

a = []

for i in range(H):

    A = list(input())

    a.append(A)

ans = [[0] * W for i in range(H) ]
num = 1
stnum = 0

for i in range(H):

    for j in range(W):

        if a[i][j] == "#":

            l = j
            d = i
            r = j
            u = i

            while l + 1 < W and a[d][l + 1] != "#" and ans[d][l+1] == 0:
                l += 1

            while r - 1 >= 0 and a[d][r-1] != "#"and ans[d][r-1] == 0:
                r -= 1

            
            while d+1 < H and check(d+1 , r , l):
                
                d += 1

            while u-1 >= 0 and check(u-1 , r , l):
                
                u -= 1

            for k in range(l - r + 1):
                k += r

                for p in range(d - u + 1):
                    p += u

                    ans[p][k] = num

            num += 1
            #print (ans,i,j,d,l)

for q in ans:
    print (" ".join(map(str,q)))
                


Measured memory_bytes: 63964
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll a, v;
    cin >> a >> v;
    ll b, w;
    cin >> b >> w;
    ll t;
    cin >> t;

    ll tmp = abs(a-b);
    ll tmp2 = (v-w) * t;

    if(tmp2 >= tmp){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),M=sc.nextInt(),X=sc.nextInt(),Y=sc.nextInt();
		int xmax = -100;
		for(int i=0; i<N; i++) {
			int n = sc.nextInt();
			if(xmax < n) xmax = n;
		}
		int ymin = 100;
		for(int i=0; i<M; i++) {
			int n = sc.nextInt();
			if(ymin > n) ymin = n;
		}

		for(int z=X+1; z<=Y; z++) {
			if(xmax < z && ymin >= z) {
				System.out.println("No War");
				return;
			}
		}
		System.out.println("War");
	}
}

Measured memory_bytes: 21972
N = int(input())
from math import sin, cos, pi
th = pi/3
def koch(d, p1, p2):
    if d == 0:
        return
    s = [0, 0]
    t = [0, 0]
    u = [0, 0]
    
    s[0] = (2 * p1[0] + p2[0])/3
    s[1] = (2 * p1[1] + p2[1])/3

    t[0] = (2 * p2[0] + p1[0])/3
    t[1] = (2 * p2[1] + p1[1])/3

    u[0] = (t[0] - s[0]) * cos(th) - (t[1] - s[1]) * sin(th) + s[0]
    u[1] = (t[0] - s[0]) * sin(th) + (t[1] - s[1]) * cos(th) + s[1]

    koch(d-1, p1, s)
    print(*s)

    koch(d-1, s, u)
    print(*u)

    koch(d-1, u, t)
    print(*t)

    koch(d-1, t, p2)

p_start = [0.0, 0.0]
p_end = [100.0, 0.0]
print(*p_start)
koch(N, p_start, p_end)
print(*p_end)


Measured memory_bytes: 5788
/* ex4_3
   moka223711 */

#include <stdio.h>
int snow(int h_west, int h_east); // 積雪量を求める関数のプロトタイプ宣言

int main(void){
    // 高さがn(n+1)/2[m](n=1,2,…,999)の999本の塔が西から順に立っている
    // 雪に埋もれていない塔の高さから雪が何m積もっているか求める
    // 雪に埋もれていない西側の塔の高さをh_west、東側の塔の高さをh_eastとする
    
    int h_west, h_east;
    scanf("%d %d", &h_west, &h_east);
    
    // 積雪量を求める関数snow()から返り値を受け取って出力
    printf("%d\n", snow(h_west, h_east));
    
    return 0;
}


    // 積雪量を求める関数の定義
int snow(int h_west, int h_east){
    int dif, ans;
    
    // 東側の塔の高さから西側の塔の高さを引き、差difを求める
    dif = h_east - h_west;
    // ここでdifは東側の塔がdif番目の塔であることを表す
    
    // 差difから東側の塔の高さを求めて、雪に埋もれていない塔の高さを引くことで
    // 雪が何m積もっているかを求める
    ans = dif * (dif + 1) / 2 - h_east;
    
    // ansを返り値として返す
    return ans;
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int A=0,B=0;
    while(a>0) {
        a -= d;
        A++;
    }
    while(c>0) {
        c -= b;
        B++;
    }
    if(A>=B) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
using namespace std;
int main(){
	
  	int n,k;
  	cin>>n>>k;
  	vector<long> v(n);
  	long sum = 0;
  	for(int i=0;i<n;i++){
		cin>>v[i];
	}	
	sort(v.begin(), v.end());
	if( n < k) 
		cout<<0;
	else
	{
		for(int i=0;i<n-k;i++){
				sum += v[i];
		}
		cout<<sum; 	
	}	
	
		
	return 0;
}


Measured memory_bytes: 1792
import sys
from collections import deque

N=int(input())
M=3**9+1
S="357"
vX=[]
appX=vX.append

vQ = deque(S)
tp = vQ.popleft
pb = vQ.append

while vQ:
  p = tp()
  if len(p)<9:
    for n in S:
      c = p + n
      pb(c)
      if all(s in c for s in S):
        appX(int(c))
print(vX[:20], file=sys.stderr)

print(sum(x<=N for x in vX))


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

int main() {
  int n;
  cin >> n;
  if (n%(n%10
     +(n%100)/10
     +(n%1000)/100
     +(n%10000)/1000
     +(n%100000)/10000
     +(n%1000000)/100000
     +(n%10000000)/1000000
     +(n%100000000)/10000000) == 0 
     ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N;
    cin >> N;

    int total;
    int num = N;
    while( num != 0 )
    {
        total += num % 10;
        num /= 10;
    }

    if(N % total == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = [int(w) for w in input().split()]

m_l = 0
m_r = n
for i in range(m):
    l, r = [int(w) for w in input().split()]
    m_l = max(m_l, l)
    m_r = min(m_r, r)
print(max(m_r - m_l + 1, 0))



Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  string S;
  cin >> S;
  if(S.at(0)=='9' || S.at(1)=='9'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    vector<double>x(N);
    vector<string>u(N);
    double ans=0;
    rep(i,N){
        cin>>x.at(i)>>u.at(i);
    }
    rep(i,N){
        if(u.at(i)=="JPY"){
            ans+=x.at(i);
        }else{
            ans+=x.at(i)*380000.0;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3684
N = int(input())
A = [int(x) for x in input().split()]

def check(x):
    work = 0
    for a in A:
        work += a
        if work < x:
            return 0
        work -= x
    return 1

ans = 0
for i in range(101):
    if check(i):
        ans = i
print(ans)
    



Measured memory_bytes: 5604
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    // each travelled node is marked true (don't check below again)
        //a queue to check each time ki kitne hogye...
        //then a loop to find the niggas unconnected
        // loop stops at unconnected=0;
    public static int  chotumc(int p,boolean[] arr)
    {for(int i=p;i<arr.length;i++)
        if(!arr[i]) return i;
        return -1;
    }
    
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner st=new Scanner(System.in);
        int n=st.nextInt();
        int m=st.nextInt();
         ArrayList<Integer>[] arr = new ArrayList[n]; 
  
        // initializing 
        for (int i = 0; i < n; i++) { 
            arr[i] = new ArrayList<Integer>(); 
        } 
        boolean[] trav= new boolean[n];
        for (int i = 0; i < n; i++) { 
           trav[i]=false;
        } 
        
        // each travelled node is marked true (don't check below again)
        //a queue to check each time ki kitne hogye...
        //then a loop to find the niggas unconnected
        // loop stops at unconnected=0;
        for(int i =0;i<m;i++)
        {int a=st.nextInt();
        int b=st.nextInt();
            arr[a-1].add(b-1); 
        arr[b-1].add(a-1); 
        }
        int p=0,res=0;
        int curr=0;
        int tot=-1;
        Queue<Integer> q 
            = new LinkedList<>(); 
        
        
            
        while(res!=-1)
        { // here to implement the queue and mark the few)
        trav[res]=true;
        for(int j=0;j<arr[res].size();j++)
            {//ek node k saare relatives ko add krre
            if(trav[arr[res].get(j)]==false)
            {q.add(arr[res].get(j));
            trav[arr[res].get(j)]=true;}}
            
    // each travelled node is marked true (don't check below again)
        //a queue to check each time ki kitne hogye...
        //then a loop to find the niggas unconnected
        // loop stops at unconnected=0;
            
            while(q.peek()!=null)
            {curr = q.poll();
            for(int j=0;j<arr[curr].size();j++)
                {//ek node k saare relatives ko add krre
                if(trav[arr[curr].get(j)]==false)
                {q.add(arr[curr].get(j));
                trav[arr[curr].get(j)]=true;}
                }
                
           }
            //ek bar ka hogya sara... now we gotta add the first unconnected element and start the drill;
            
            
            
          
          
          res=chotumc(p,trav);
          p=res; tot++;
          //loop will repeat
        } 
        
        
        
        
        
      System.out.println(tot);
            
        
        
    }
}


Measured memory_bytes: 72124
n,k  = map(int,input().split())
p = list(map(int, input().split()))
current_best = 0
sum_list = [(1+p[0])/2]

if n == 1:
  print(sum_list[0])
  exit()

#累積和の計算
for i in range(n-1):
  sum_list.append(sum_list[-1]+(1+p[i+1])/2)
  
if n==k:
  print(sum_list[-1])
  exit()
  
for j in range(n-k):
  expect = sum_list[j+k]-sum_list[j]
  if expect > current_best:
    current_best = expect
print(current_best)

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

int main() {
  int A, B, a, X, y, z;
  X = 0;
  cin >> A >> B;
  a = A;
  for (int i = 0; i < B-A+1; i++) {
    y = (a%10000-a%1000)/1000; //千の位
    z = (a%100-a%10)/10; //百の位
    if (a/10000 == a%10 && y == z) {
      X++;
      a++;
    }
    else {
      a++;
    }
  }
  cout << X << endl;
}

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

using namespace std;

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(u == s){
    a--;
  } else if(u == t) {
    b--;
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed main(){
  ll a,b,q[1000][1000]={};
  string c[10000];
  cin>>a>>b;
  for(ll i=0;i<a;i++){
    cin>>c[i];
  }
  for(ll i=1;i<=a;i++){
    for(ll j=1;j<=b;j++){
      if(c[i-1][j-1]=='#'){
        q[i][j]=-1;
        if(q[i][j+1]!=-1) q[i][j+1]++;
        if(q[i][j-1]!=-1) q[i][j-1]++;
        if(q[i+1][j]!=-1) q[i+1][j]++;
        if(q[i-1][j]!=-1) q[i-1][j]++;
        if(q[i+1][j+1]!=-1) q[i+1][j+1]++;
        if(q[i+1][j-1]!=-1) q[i+1][j-1]++;
        if(q[i-1][j+1]!=-1) q[i-1][j+1]++;
        if(q[i-1][j-1]!=-1) q[i-1][j-1]++;
      }
    }
  }
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      if(q[i][j]==-1) cout<<"#";
      else cout<<q[i][j];
    }
    cout<<"\n";
  }
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main () {
  ll N;
  cin >> N;
 
  ll A[N], sum = 0;
  
  for(ll i = 0; i < N; i++) {
    ll t;
    cin >> t;
    A[i] = t - i - 1;
  }

  sort(A,A+N);
 
  for(ll i = 0; i < N; i++) {
    sum += abs(A[i] - A[N/2]);
  }
 
  cout << sum;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <sstream>
#include <deque>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||a+c==b||b+c==a){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
ans = 0
a = 0
b = 0
if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0:
            a += 1
        if i % K == (K/2):
            b += 1
    print(a**3 + b**3)
else:
    for i in range(1,N+1):
        if i % K == 0:
            a += 1
    print(a**3)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int n, pm, pe, pj; // n…人数　pm…数学の点数　pe…英語の点数　pj…国語の点数
    while(1){
        cin >> n;
        if(n == 0) break; //終了条件
        
        for(int i=0; i<n; i++){
            cin >> pm >> pe >> pj;
        
            //100点の科目がある⇒Ａ
            if(pm == 100 || pe == 100 || pj == 100){
                cout << "A" << endl;
            }
            
            //数学と英語の平均点が90点以上⇒Ａ
            else if((pm + pe) / 2 >= 90){
                cout << "A" << endl;
            }
            
            //３科目の平均点が80点以上⇒Ａ
            
            else if((pm + pe + pj) / 3 >= 80){
                cout << "A" << endl;
            }
            
            //３科目の平均点が70点以上⇒Ｂ
            else if((pm + pe + pj) / 3 >= 70){
                cout << "B" << endl;
            }
            
            //３科目の平均点が50点以上で，数学か英語が80点以上⇒Ｂ
            else if(((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80)){
                cout << "B" << endl;
            }
        
            //上の条件を満たさない⇒Ｃ
            else cout << "C" << endl;
        }
    }
    return 0;
}

/*
　問題の通り条件式を作ります。
　評価の出力は１行です。「else」を忘れないようにしましょう。
　「and(&&)」，「or(||)」に気を付けましょう。
*/



Measured memory_bytes: 3088
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//AtCoder Beginner Contest 124
//B	Great Ocean View
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		List<Integer> H_List = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			H_List.add(sc.nextInt());
		}

		sc.close();

		int ans = 0;
		int max = 0;
		for (Integer H : H_List) {
			if (H >= max) {
				ans++;
				max = H;
			}
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  vi z(n + 1);
  bool zero = false;
  z[0] = 0;
  rep2(i, 1, n + 1) {
    z[i] = z[i - 1];
    if(s[i - 1] == '1') zero = false;
    if(s[i - 1] == '0' && !zero) {
      z[i]++;
      zero = true;
    }
  }
  int ans = 0;
  rep(i, n) {
    if(i > 0 && s[i - 1] == '0' && s[i] == '0') continue;
    int it = upper_bound(all(z), k + z[i]) - z.begin() - 1;
    ans = max(ans, it - i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
n = int(input())
a = [ int(i) for i in input().split() ]
check = True
a[0] -= 1
for i in range(1,n):
    if a[i] < a[i-1]:
        check = False
        break
    elif a[i] > a[i-1]:
        a[i] -= 1

if check == False:
    print("No")
else:
    b = sorted(a)
    if b == a:
        print("Yes")
    else:
        print("No")
        


Measured memory_bytes: 14396
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    for (i=1;i<=n;i++){
        if (i%3==0||i%10==3||i%10000%1000%100/10==3||i%10000%1000/100==3||i%10000/1000==3){
            printf(" %d",i);
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(void){
  int a,b,i,j;
  while(1)
	   {
  scanf("%d %d",&a,&b);
  if(a == 0 && b == 0){
      break;
  }
  for(i = 1; i <= a; i++)
    {
      for(j = 1; j <= b; j++)
	{
	  if(j % 2 == 1){
	      if(i % 2 == 1)
	      printf("#");
	      else 
	      printf(".");
	    }
	  else 
	    {
              if(i % 2 == 1)
              printf(".");
	      else 
	      printf("#");
	    }
	}
      printf("\n");
    }
  printf("\n");
	   }
  return 0;
}


Measured memory_bytes: 2100
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N; cin >> N;
	vector<int>ns(N);
	map<int, vector<int>>mp;
	for (int i = 0; i < N; ++i) {
		cin >> ns[i];
		mp[to_string(ns[i]).size()].push_back(ns[i]);
	}
	for (auto&m : mp) {
		sort(m.second.begin(), m.second.end());
		if (m.second.size() >= 5)m.second.resize(4);
	}
	ns.clear();
	for (auto &m : mp) {
		for (auto num : m.second) {
			ns.push_back(num);
		}
	}
	
	vector<int>anss;
	for (int i = 0; i < ns.size(); ++i) {
		for (int j = 0; j < ns.size(); ++j) {
			if (i == j)continue;
			string st = to_string(ns[i]) + to_string(ns[j]);
			int num = stoi(st);
			if (anss.size() == 3) {
				if (anss[2] < num)continue;
				else {
					anss.push_back(num);

					nth_element(anss.begin(), anss.begin() + 2, anss.end());
					if (anss.size() == 4)anss.pop_back();

				}
			}
			else {

				anss.push_back(num);
				sort(anss.begin(), anss.end());
			}
		}
	}
	cout << anss[2] << endl;
	return 0;
}

Measured memory_bytes: 3324
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	int n;
	while(cin>>n,n){
		vi c(n);
		REP(i,n){
			cin>>c[i];
		}
		int best=n;
		REP(pos,n){
			FOR(chg,1,3+1){
				int t=pos-1,b=pos+1;
				int cnt=0;
				int color=chg;
				while(1){
					if(t<0||b>=n){
						break;
					}
					int tcnt=cnt==0?1:0;
					while(t>=0&&c[t]==color){
						t--;
						tcnt++;
					}
					int bcnt=0;
					while(b<n&&c[b]==color){
						b++;
						bcnt++;
					}
					if(tcnt+bcnt<4){
						break;
					}
					cnt+=tcnt+bcnt;
					color=c[t];
				}
				best=min(best,n-cnt);
			}
		}
		cout<<best<<endl;
	}
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
  int n;
  int bridge, tresure;
  bool flag;
  while(cin >> n, n) {
    flag = false;
    pair<int, int> p[26];
    for(int i = 0 ; i < n ; i++) {
      cin >> tresure >> bridge;
      p[i] = make_pair(bridge, tresure);
    }
    sort(p, p+n); // first ツ優ツ静ヲツづortツつウツづェツづゥ
    
    int sum=0, i;
    for(i = 0 ; i < n ; i++) {
      if(sum > p[i].first || sum + p[i].second > p[i].first) break;
      sum += p[i].second;
    }
    
    if(i == n) flag = true; //ツ催古」ツづ慊づδ仰ーツプツ出ツ猟按つスツづァ YES
    else flag = false;      //ツ途ツ陳づ終ツづュツづつスツづァ NO
    
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

int main() {

	int A, B, K;
	cin >> A >> B >> K;
	
	int cnt = 0; // 今まで見つかった数
	for (int i = min(A, B); i >= 1; i--)
	{
		// A % i  →　Aをiで割った余り
		// if(A && B) → AもBも条件を満たすとき
		if (A % i == 0 && B % i == 0) {
			cnt++;	//cntを1増やす。
			if (cnt == K) {	//もし割切れる数が見つかったのがK番目だったら
				cout << i << endl;
				return 0;
			}
		}
	}
}

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

typedef long long ll;
const ll MAX_N = 100005;
ll b[MAX_N];

int main() {
  ll n;
  ll h;
  cin >> n >> h;
  ll max_a = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll ai, bi;
    cin >> ai >> bi;
    b[i] = bi;
    max_a = max(max_a, ai);
  }
  sort(b, b+n);
  for (ll i = n-1; i >= 0; i--) {
    if (b[i] >= max_a) {
      h -= b[i];
      ans++;
      if (h <= 0) break;
    }
  }
  if (h > 0) {
    if (h % max_a == 0) {
      ans += h / max_a;
    }
    else {
      ans += h / max_a + 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
ll n;
ll a[24][24];
mint dp[1<<21];
int main(){
    cin>>n;
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int bit=1;bit<(1<<n);bit++){
        ll bitcnt=0;
        rep(j,n){
            if((bit>>j)&1)bitcnt++;
        }
        rep(j,n){
            if((bit>>j)&1){
                dp[bit]+=dp[bit-(1<<j)]*a[bitcnt-1][j];
            }
        }
    }
    cout<<dp[(1<<n)-1].x<<endl;
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int stime = max(a, c);
  int ftime = min(b, d);
  
  int ans = 0;
  if(ftime - stime < 0) ans = 0;
  else ans = ftime - stime;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int n,a[100010],b[100010],c[100010],f[100010][3];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=0;i<n;i++)
	{
		f[i][0]=max(f[i-1][1],f[i-1][2])+a[i];
		f[i][1]=max(f[i-1][0],f[i-1][2])+b[i];
		f[i][2]=max(f[i-1][0],f[i-1][1])+c[i];
	}
	cout<<max(f[n-1][0],max(f[n-1][1],f[n-1][2]))<<endl;
	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);

	int n; int m; string s;
	while (cin >> n, n) {
		cin >> m >> s;
		int c = 0, res = 0;
		for (int i=0; i<m; ++i) {
			if (i == 0 || s[i-1] == s[i]) {
				c = s[i] == 'I';
			} else if (s[i] == 'I') {
				res += n < ++c;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ioso ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n';
#define maxn 1000001;
int main() {
    ioso;
    string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
    string k;
    cin >> k;
    int amar;
    for(int i=0;i<7;i++) {
        if(s[i]==k) {amar = i; break;}
    }
    cout << 7-amar << endl;
}


Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// gp_hash_table<int, int> table;

const int N = 51;
const int MOD = round(1e9 + 7);

int n;

int memo[N][N][N * N / 2];
int solve(int ind, int unused, int k) {
  if (k < 0) return 0;
  if (unused < 0) return 0;

  if (ind == n) return unused == 0 && k == 0;
  int& res = memo[ind][unused][k];
  if (res != -1) return res;

  k -= unused;

  ++unused;
  int used = ind + 1 - unused;

  // Use curr.
  res = 1LL * unused * solve(ind + 1, unused - 1, k) % MOD;

  // Use prev.
  res = (res + 1LL * (unused - 1) * solve(ind + 1, unused - 1, k)) % MOD;

  // Use curr and prev.
  int tmp = unused - 1;
  tmp = 1LL * tmp * tmp % MOD;

  res = (res + 1LL * tmp * solve(ind + 1, unused - 2, k)) % MOD;

  // Use nothing.
  res = (res + solve(ind + 1, unused, k)) % MOD;

  return res;
}

int calcK(const vector<int>& v) {
  int res = 0;
  for (int i = 0; i < v.size(); ++i) {
    res += abs(i - v[i]);
  }
  return res;
}

int calcP(const vector<int>& v) {
  int res = 0;

  for (int i = 0; i < v.size(); ++i) {
    res += max(v[i] - i, 0);
  }

  return res;
}

ostream& operator <<(ostream& cout, const vector<int>& v) {
  cout << "{";
  for (int x : v) {
    cout << x + 1 << " , ";
  }
  cout << "} ";
  return cout;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

//
//
//  int n = 4;
//  vector<int> v;
//  for (int i = 0; i < n; ++i) {
//    v.push_back(i);
//  }
//
//  do {
//    cout << v << endl;
//    cout << calcK(v) << " " << 2 * calcP(v) << endl;
//    assert(calcK(v) == 2 * calcP(v));
//  } while (next_permutation(v.begin(), v.end()));

  int k;
  cin >> n >> k;

  if (k % 2 != 0) {
    cout << 0 << endl;
    return 0;
  }

  k /= 2;

  memset(memo, -1, sizeof memo);

  cout << solve(0, 0, k) << endl;

}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, k, t=0;
	cin >> n >> k;
	for (long long i=k; i<=n+1; i++) t+=(n-i+1)*i+1, t%=1000000007;
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 3676
def nums():
    return list(map(int,input().split(" ")))
def num():
    return int(input())
def yakusu(n):
    res = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.add((i,int(n/i)))
    return res
import math
x = num()
print(math.ceil(x / 2 - 1))

Measured memory_bytes: 38512
n=int(input())

a=[0]*n
b=[0]*n
c=[0]*n
d=[0]*n
edges=[set() for _ in range(n)]
matched=[-1]*n

for i in range(n):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

for i in range(n):
    tc,td=list(map(int,input().split()))
    c[i]=tc
    d[i]=td

for i in range(n):
    for j in range(n):
        if a[i]<c[j] and b[i]<d[j]:
            edges[i].add(j)

def dfs(v,visited):
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u]==-1 or dfs(matched[u],visited):
            matched[u]=v
            return True
    
    return False

print(sum(dfs(s,set()) for s in range(n)))

Measured memory_bytes: 3188
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict
n,m=map(int, input().split())
ac=set()
ac_cnt=0
wa_cnt=0
d_ac=defaultdict(int)
d_wa=defaultdict(int)
for i in range(m):
    p,s=nm()
    if s=='AC':
        if int(p) in ac:
            continue
        ac.add(int(p))
        ac_cnt+=1
    elif s=='WA':
        if int(p) in ac:
            continue
        d_wa[p]+=1
 
for a in ac:
    wa_cnt+=d_wa[str(a)]
 
print(ac_cnt,wa_cnt)

Measured memory_bytes: 62936
import itertools
N, M, Q = map(int,input().split())
s = [tuple(map(int, input().split())) for i  in range(Q)]
l = list(range(1,M+1))
ans = []
for v in itertools.combinations_with_replacement(l, N):
    count = 0
    for i in range(Q):
        a, b, c, d = s[i]
        if v[b-1] - v[a-1] == c:
            count += d
    ans.append(count)
print(max(0, max(ans)))


Measured memory_bytes: 12624
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];

int main()
{
	int n,k,t;
	cin>>n>>k;
	while(k--){
		cin>>t;
		while(t--){
			int kk;
			cin>>kk;
			a[kk]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 2 * (1e5 + 1);
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int n;
    int p=1;
    cin >> n;
    for (int i=1; i<=n; i++) p = ((p %MOD) * (i%MOD)) % MOD;
    cout << p;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Control.Arrow
import Data.Ord
import Data.Maybe
import Numeric
import Data.Char
import Text.Printf

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [x,y,a,b,c] <- r'
    ps <- drop (a-x) <$> sort <$> r'
    qs <- drop (b-y) <$> sort <$> r'
    let eat = sort (ps ++ qs)
    rs <- (++[0,0..]) <$> sortBy (flip compare) <$> r'
    print $ sum $ zipWith max eat rs


Measured memory_bytes: 37244
Node = Struct.new(:key, :parent, :left, :right)

class BinarySearchTree
  attr_accessor :root
  def insert(key)
    node_k = Node.new(key)
    node_parent = nil
    node_x = self.root
    while node_x != nil
      node_parent = node_x
      if node_k.key < node_x.key
        node_x = node_x.left
      else
        node_x = node_x.right
      end
    end
    node_k.parent = node_parent

    if node_parent == nil
      self.root = node_k
    elsif node_k.key < node_parent.key
      node_parent.left = node_k
    else
      node_parent.right = node_k
    end
  end

  def find(key)
    node = self.root
    while node != nil && key != node.key
      if key < node.key
        node = node.left
      else
        node = node.right
      end
    end
    node
  end

  def find?(key)
    if find key
      puts 'yes'
    else
      puts 'no'
    end
  end

  def preorder_parse(node = self.root)
    return if node == nil
    print " #{node.key}"
    preorder_parse(node.left)
    preorder_parse(node.right)
  end

  def inorder_parse(node = self.root)
    return if node == nil
    inorder_parse(node.left)
    print " #{node.key}"
    inorder_parse(node.right)
  end
end

tree = BinarySearchTree.new
m = gets.to_i
commands = []
m.times do
  commands << gets.split
end
commands.each do |command|
  case command[0]
  when 'insert'
    tree.insert command[1].to_i
  when 'print'
    puts tree.inorder_parse
    puts tree.preorder_parse
  when 'find'
    tree.find? command[1].to_i
  else
    puts "不明なコマンド: #{command}"
  end
end



Measured memory_bytes: 153560
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
struct node {
	int id;
	pair<int, int> coor;
};
struct EDGE {
	int fr, to, di;
	EDGE() {}
	EDGE(int F, int T, int D) {
		fr=F;
		to=T;
		di=D;
	}
};
int n;
node a[100005];
vector<EDGE> v;
bool cmp1(const node& t1, const node& t2) {
	return t1.coor.first<t2.coor.first;
}
bool cmp2(const node& t1, const node& t2) {
	return t1.coor.second<t2.coor.second;
}
bool cmp3(const EDGE& t1, const EDGE& t2) {
	return t1.di<t2.di;
}
int calcdist(node t1, node t2) {
	return min(abs(t1.coor.first-t2.coor.first), abs(t1.coor.second-t2.coor.second));
}
int fa[100005];
int Find(int x) {
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}
ll kruskal() {
	ll res=0ll;
	for (int i=0; i<n; i++)
		fa[i]=i;
	for (int i=0; i<v.size(); i++) {
		int rx=Find(v[i].fr), ry=Find(v[i].to);
		if (rx==ry) continue;
		res+=(ll)v[i].di;
		fa[rx]=ry;
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for (int i=0; i<n; i++) {
		scanf("%d%d", &a[i].coor.first, &a[i].coor.second);
		a[i].id=i;
	}
	sort(a, a+n, cmp1);
	for (int i=1; i<n; i++) {
		v.push_back(EDGE(a[i-1].id, a[i].id, calcdist(a[i-1], a[i])));
	}
	sort(a, a+n, cmp2);
	for (int i=1; i<n; i++) {
		v.push_back(EDGE(a[i-1].id, a[i].id, calcdist(a[i-1], a[i])));
	}
	sort(v.begin(), v.end(), cmp3);
	printf("%lld", kruskal());
	return 0;
}

Measured memory_bytes: 6132
#include<bits/stdc++.h>
#define For(a, b) for(int i = a; i < b; i ++)
using namespace std; 
int n, a[25], b[25], c[24], cnt = 0; 

int main()
{
	cin >> n; 
	For(0, 25)
		c[i] = 0; 
	For(0, n)
		cin >> a[i]; 
	For(0, n)
		cin >> b[i]; 
	For(0, n - 1)
		cin >> c[i]; 
	For(0, n)
	{
		cnt += b[a[i] - 1]; 
		if(i > 0)
		{
			if(a[i - 1] + 1 == a[i])
				cnt += c[a[i] - 2]; 
		}
	}
	cout << cnt << endl; 
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    int n; cin >> n;
    std::vector<ll> a(n); rep(i,n) cin >> a[i];

    unordered_map<ll,ll> cntmp;

    rep(i,n){
        cntmp[a[i]]++;
    }

    ll total = 0LL;

    for(auto const& x : cntmp){
        total += (x.second)*(x.second-1)/2;
    }

    rep(i,n){
        int x = a[i];
        
        cout << total - (cntmp[x]*(cntmp[x]-1))/2 + ((cntmp[x]-2)*(cntmp[x]-1))/2 << endl;
    }

    return 0;
}

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

int main() {

  long long int m;

  cin >> m;

  string input, t0, t1, t0_r, t1_r;

  for ( long long int i = 0; i < m; i++ ) {

    cin >> input;

    vector< string > ans;

    for ( long long int j = 1; j < input.size(); j++ ) {

      t0 = "";
      t1 = "";
      t0_r = "";
      t1_r = "";
      for ( long long int x = 0; x < input.size(); x++ ) {
	if ( x < j ) {
	  t0 += input[x];
	  t0_r = input[x] + t0_r;
	}else {
	  t1 += input[x];
	  t1_r = input[x] + t1_r;
	}
      }
      ans.push_back( t0   + t1   );
      ans.push_back( t0   + t1_r );
      ans.push_back( t0_r + t1   );
      ans.push_back( t0_r + t1_r );
      ans.push_back( t1   + t0   );
      ans.push_back( t1   + t0_r );
      ans.push_back( t1_r + t0   );
      ans.push_back( t1_r + t0_r );

    }

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

    ans.erase( unique( ans.begin(), ans.end() ), ans.end() );

    cout << ans.size() << endl;

  }

  return 0;

}

Measured memory_bytes: 1304
#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 rep11(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 pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans[1000];
queue<int> que[1000];

signed main() {
    cin >> n;
    rep(i,n) rep(j,n-1) {
        int a;
        cin >> a;
        que[i].push(a-1);
    }
    bool f=true;
    while(f) {
        f = false;
        rep(i,n) {
            if (que[i].empty()) continue;
            int dif = que[i].front();
            while(i == que[dif].front()) {
                ans[i] = ans[dif] = max(ans[i], ans[dif])+1;
                que[i].pop();
                que[dif].pop();
                if (que[i].size()) dif = que[i].front();
                else break;
                f = true;
            }
        }
    }
    int trueans = 0;
    rep(i,n) {
        if (que[i].size()) {
            cout << -1 << endl;
            return 0;
        }
        trueans = max(trueans, ans[i]);
    }
    cout << trueans << endl;
}



Measured memory_bytes: 8960
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
#include<sstream>
#include<cctype>
#include<map>
#include<set>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn = 100005;
LL a[maxn];

int main(){
    int n;
    LL sum=0;
    cin >> n;
    scanf("%lld",&a[0]);
    sum=abs(a[0]);
    for(int i=1;i<n;i++){
        scanf("%lld",&a[i]);
        sum+=abs(a[i]-a[i-1]);
    }
    sum+=abs(a[n-1]);
    for(int i=0;i<n;i++){
        if(i==0){
            printf("%lld\n",sum-abs(a[0])-abs(a[0]-a[1])+abs(a[1]));
        }
        else if(i==n-1){
            printf("%lld\n",sum-abs(a[i]-a[i-1])-abs(a[n-1])+abs(a[n-2]));
        }
        else printf("%lld\n",sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  string s;
  cin >> n;
  cout << n + n*n + n*n*n << endl;
  return 0;
}


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

int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=k && i-j>=0;j++)
		{
			dp[i]=min(dp[i-j]+abs(arr[i-j]-arr[i]),dp[i]);
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)

int n;
int a[20];
int x[20][20];
int y[20][20];
int ans;

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		rep(j, a[i]) cin >> x[i][j] >> y[i][j];
	}
	ans = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		bool k = true;
		bool sho[20];
		rep(i, n) {
			if (bit & (1 << i)) sho[i] = 1;
			else sho[i] = 0;
		}
		rep(i, n) {
			if (bit & (1 << i)) {
				rep(j, a[i]) {
					if (y[i][j] == 1) {
						if (sho[x[i][j] - 1] == 0) k = false;
					}
					else {
						if (sho[x[i][j] - 1] == 1) k = false;
					}
				}
			}
		}
		if (!k) continue;
		int sum = 0;
		rep(i, n) {
			if (sho[i] == 1) sum++;
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define fore(i, a) for(auto &i:a)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
#define MOD 1000000007
#define yes "YES"
#define no "NO"
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;

int main() {
    fastcin;
    ll a, b, ans = 0;
    cin >> a >> b;
    ll tmp = b - a;
    rep(i, 0, tmp) {
        ans += i;
    }
    ans -= a;
    print(ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
int main(){

ll flag = 1 ;
string s;
cin>>s;

sort(s.begin(),s.end());
ll len = s.size();
ll c=1;
for(ll i = 0 ; i < len ; i++){
    if(s[i]==s[i+1])
    {
        c++;


    }
    else  {
        if((c%2)!= 0)
        {
            flag = 0;


        }
        c=1;
    }
}

   if(flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;

    }



//cout<<s<<endl;




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

// 2度目、自力で解けなかった　解説を読んだが
// 100%理解出来たとは言い切れない

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int ans = n;
    for(int i = 0; i+1 < n; i++){
        if(s[i] != s[i+1])  ans = min(ans, max(i+1, n-i-1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512