akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 小数のときは，精度の設定する．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int64_t N, K; cin >> N >> K;
VI a(N), b(N); rep(i, 0, N) cin >> a[i] >> b[i];
VI cnt(100101, 0);

rep(i, 0, N) cnt[a[i]] += b[i];

int64_t num = 0;
rep(i, 0, 100101){
    num += cnt[i];
    if (num >= K) {
        cout << i <<"\n";
        return 0;
    }
}

}

// 境界，出力文字列 チェック



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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;

int main()
{_
    ll a , b , c ; cin >> a >> b >> c;
	return cout << (a + b >= c ? "Yes" : "No") , 0;
}
///SAliB


Measured memory_bytes: 256
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int cnt[26];

signed main() {
	int n; cin >> n;
	int t[n+2], v[n+2];
	t[0] = v[0] = t[n+1] = v[n+1] = 0;
	FOR (i,1,n+1) cin >> t[i];
	FOR (i,1,n+1) cin >> v[i];
	FOR (i,1,n+1) {
		v[i] = min(v[i],v[i-1]+t[i]);
	}
	FOR (i,0,n) {
		v[n-i] = min(v[n-i],v[n-i+1]+t[n-i]);
	}
	float ans = 0;
	FOR (i,1,n+1) {
		float tmp = 0;
		float l = min(v[i],v[i-1]);
		float r = min(v[i],v[i+1]);
		float time = (t[i] + abs(r-l));
		float high = min(l,r) + time / 2;
		tmp += min(l,r) * t[i];
		tmp += time * time / 4;
		tmp -= (float)abs(r-l) * (float)abs(r-l) / 2;
		if (high > v[i]) {
			tmp -= (high - (float)v[i]) * (high - (float)v[i]);
		}
		ans += tmp;
	}
	cout << fixed << setprecision(8) << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  vi vec;
  vec.push_back(1);
  int s = 6;
  while(s < 100000){
    vec.push_back(s);
    s *= 6;
  }
  s = 9;
  while(s < 100000){
    vec.push_back(s);
    s *= 9;
  }

  sort(ALL(vec));

  int dp[100001];
  dp[0] = 0;

  REP(i,100000){
    dp[i+1] = INFi;
    REP(j, vec.size()){
      if(vec[j] <= i+1)
      dp[i+1] = min(dp[i+1], dp[i+1-vec[j]] + 1);
    }
  }


  cout << dp[n] << endl;

  return 0;
}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  int n1=1,n2=1;
  vector<int> fib(n+1);
  fib.at(0)=1;
  fib.at(1)=1;
  for(int i=2;i<=n;i++){
    fib.at(i)=fib.at(i-1)+fib.at(i-2);
  }
  cout << fib.at(n)<< endl;
  return 0;
}



Measured memory_bytes: 3096
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = std::io::BufReader::new(stdin.lock())
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let m = 1_000_000_007i64;
    let mut dp: Vec<Vec<Vec<Vec<i64>>>> = vec![vec![vec![vec![0; 4]; 4]; 4]; n + 1];
    dp[0][3][3][3] = 1;

    for len in 0..n {
        for i in 0..4 {
            for j in 0..4 {
                for k in 0..4 {
                    if dp[len][i][j][k] == 0 {
                        continue;
                    }
                    for l in 0..4 {
                        if (l == 2 && i == 1 && j == 0)
                            || (l == 2 && i == 0 && j == 1)
                            || (l == 1 && i == 2 && j == 0)
                            || (l == 2 && i == 1 && k == 0)
                            || (l == 2 && j == 1 && k == 0)
                        {
                            continue;
                        }
                        dp[len + 1][l][i][j] += dp[len][i][j][k];
                        dp[len + 1][l][i][j] %= m;
                    }
                }
            }
        }
    }

    let mut ans = 0;
    for i in 0..4 {
        for j in 0..4 {
            for k in 0..4 {
                ans += dp[n][i][j][k];
                ans %= m;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int read(){
	int a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(int x){
	char y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
int n,x,ans;
multiset<int> s;
int main(){
	n=read();
	for(int i=0;i<n;i++){
		x=read();
		multiset<int>::iterator y=s.lower_bound(x);
		if(y==s.begin())ans++,s.insert(x);
		else y--,s.erase(y),s.insert(x);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> listH = new ArrayList<Integer>();
		List<Integer> listW = new ArrayList<Integer>();
		for(;;){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0){
				break;
			}
			listH.add(H);
			listW.add(W);
		}

		for(int i = 0; i < listH.size(); i++){
			for(int j = 0; j < listH.get(i); j++){
				StringBuffer sb = new StringBuffer();
				for(int k = 0; k < listW.get(i); k++){
					if(j % 2 == 0){
						if(k % 2 == 0){
							sb.append("#");
						} else{
							sb.append(".");
						}
					} else{
						if(k % 2 == 0){
							sb.append(".");
						} else{
							sb.append("#");
						}
					}
				}
				sb.append("\n");
				String str = sb.toString();
				System.out.print(str);
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 29096
###C###
H,W = map(int,input().split())

As_is_campus=[[False for w in range(W)] for h in range(H)]
#Tobeは上下左右に1マスずつゆとりを持たせる。
To_be_campus=[[False for w in range(W+2)] for h in range(H+2)]

for h in range(H):
    for i,w in enumerate(input()):
        if w=="#":
            To_be_campus[h+1][i+1]=True
            
#print(To_be_campus)

#Trueが上下左右に並んでいるか確認する
flag = True
for i in range(1,H+2):
    if not flag :
        break
    for j in range(1,W+2):
        if To_be_campus[i][j]:
            if not (To_be_campus[i-1][j] or To_be_campus[i][j-1] or To_be_campus[i][j+1]  or To_be_campus[i+1][j] ):
                flag = False
                break

if flag:
    print("Yes")
else:
    print("No")

            
            


Measured memory_bytes: 3064
# Author: cr4zjh0bp
# Created: Thu Mar 12 20:03:57 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

M = ni()

print((24 - M) + 24)

Measured memory_bytes: 3064
#include <stdio.h>
#include<string.h>
int main()
{
   char str[1000];
   char str1[1000];
   int c=0;
   scanf("%s",str);
   
        for(int i=0;i<strlen(str);i++)
        { 
            if(str[i]=='0')
            { 
                str1[c]='0';
                c++;
            }
            else if(str[i]=='1')
            { 
                str1[c]='1';
                c++;
            }
            else if(c>0&&str[i]=='B')
            c--;
        }
        str1[c]='\0';printf("%s",str1);
    return 0;
}

Measured memory_bytes: 128
str= gets.chomp

a = gets.chomp.split(" ").map(&:to_i);
b = []

(a.length).times do |n|
  if n % 2 == 0
    b << a[n]
  else
    b.unshift a[n]
  end
end

b.reverse! if (a.length) % 2 == 1
puts b.join(" ")


Measured memory_bytes: 27360
s = input()
t = input()

if t in s:
    print(0)
else:
    s = list(s)
    t = list(t)

    l_t = len(t)
    l_s = len(s)
    count = [0] * (l_s - l_t + 1)
    for i in range(l_s - l_t + 1):
        s_list = s[i:i+l_t]
        for j in range(len(t)):
            if t[j] == s_list[j]:
                count[i] += 1
    
    # print(count)
    print(len(t) - max(count))

Measured memory_bytes: 9088
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	cout << (n + 1) / 2 * 1.0 / n << endl;	

	
}














Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n,a[100] = {0};
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int sum = accumulate(a,a+n,0);
	int ave = (int)(round((double)sum / n));

	//cout << "ave = " << ave << endl;

	int sol = 0;

	for(int i = 0; i < n; i++)
	{
		sol += (ave-a[i]) * (ave-a[i]);
	}

	cout << sol << endl;

	return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())

l=list(map(int, input().split()))
CW=[]

for i in range(N):
    cw=list(map(int,input().split()))
    CW.append(cw)

CW.sort(key=lambda x:x[1],reverse=True)

L=[0]*C
ans=0
count=0
for i in range(N):
    if L[CW[i][0]-1]<l[CW[i][0]-1]:
        ans+=CW[i][1]
        L[CW[i][0]-1]+=1
        count+=1
    if count==M: break

print(ans)



Measured memory_bytes: 26804
n, k = map(int, input().split())


ps = list(map(int, input().split()))
cs = list(map(int, input().split()))

graphs = []
vGraphs = []
flags = [False]*n
sumDict = dict()
for i in range(len(ps)):
    p = ps[i]
    index = p - 1
    if flags[index]:
        continue

    current = set()
    values = set()
    currentIndex = index
    while True:
        if flags[currentIndex]:
            break

        current.add(currentIndex)
        values.add(cs[currentIndex])
        flags[currentIndex] = True
        nextIndex = ps[currentIndex] - 1
        currentIndex = nextIndex
    graphs.append(current)
    vGraphs.append(values)

answer = -float('inf')
for i in range(n):

    searchI = 0
    loopSum = 0
    nextIndex = i
    loopCount = 0
    while True:
        nextIndex = ps[nextIndex] - 1
        loopSum += cs[nextIndex]
        loopCount += 1
        if nextIndex == i:
            break

    total = loopSum

    currentSum = 0
    count = 0
    ci = i
    while True:
        count += 1
        if count > k:
            break
        loop = (k - count) // loopCount
        multi = max(0, total) * loop

        ci = ps[ci] - 1

        currentV = cs[ci]
        currentSum += currentV

        answer = max(answer, multi + currentSum)
        if ci == i:
            break

print(answer)

Measured memory_bytes: 74892
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int X;
  cin >> N;
  cin >> X;
  int memo;
  int D;
  memo = 0;
  D = 0;
  int i;
  for (i=0; i<N+1; i++) {
    if(D < X+1) {
      memo = memo + 1;
    }
    int L;
    cin >> L;
    D = D + L;
  }
  cout << memo;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,k,sub;
    cin>>n>>k;
    vector<int>v;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }
    sort(all(v));
    int ans=INT_MAX;
    for(int i=0; i<=v.size()-k; i++)
    {
        int x=v[i],y=v[i+k-1];
        int z=max(abs(x),abs(y)),ex=0;
        if(x<=0 && y>=0)
        {   z=abs(x)+abs(y);
            ex=min(abs(x),abs(y));
        }
        z+=ex;
        ans=min(ans,z);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3860
#include<iostream>
main(){int n,m,i,a,c[1000001];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
inline int read()
{
	int 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*10+c-'0';c=getchar();}
	return x*f;
}
struct number
{
	int f,s;
}a[1<<MAXN];
int n;
int main()
{
	n=read();
	for(int i=0;i<1<<n;i++)
	{	
		int x;
		x=read();
		a[i].f=x;
		a[i].s=-1<<30;
	}
	for(int j=0;j<n;j++)
		for(int i=0;i<1<<n;i++)
			if(i>>j & 1)
			{
				int x=i^(1<<j);
				number ans;
				ans.f=max(a[i].f,a[x].f);
				if(a[i].f>a[x].f)
					ans.s=max(a[i].s,a[x].f);
				else
					ans.s=max(a[i].f,a[x].s);
				//cout<<ans.f<<" "<<ans.s<<endl;
				a[i]=ans;
			}
	int ans=0;
	for(int i=1;i<1<<n;i++)
	{
		ans=max(ans,a[i].f+a[i].s);
		//cout<<a[i].f<<" "<<a[i].s<<endl;
		cout<<ans<<endl;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 7168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] msg = Console.ReadLine().Split(' ');
            int K = int.Parse(msg[0]);
            int S = int.Parse(msg[1]);

            int count = 0;
            for (int x = 0; x <= K; x++) 
            {
                for (int y = 0; y <= K; y++)
                {
                    int z = S - x - y;
                    if ((0 <= z) && (z <= K)) count++;
                }
            }
            Console.WriteLine(count.ToString());
        }
    }
}


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

int main(){

  int a, b, c;
  cin >> a >> b;
  c = (a+b)/2;
  b = ((a+b)*5)%10;
  if(b > 4) cout << c + 1 << endl;
  else cout << c <<endl;
  
  return 0;
}

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

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        ArrayList<Integer> list = new ArrayList<Integer>();
        int count = 1;
        boolean flag = true;
        if(s.charAt(0)=='0'){
        	list.add(0);
        }
        else{
        	flag = false;
        }
        for(int i=1;i<n;i++){
        	if(s.charAt(i)=='0' && flag){
        		count++;
        	}
        	else if(s.charAt(i)=='1' && !flag){
        		count++;
        	}
        	else{
        		list.add(count);
        		flag = !flag;
        		count = 1;
        	}
        }
        list.add(count);
        if(flag){
        	list.add(0);
        }
        ArrayList<Integer> l = new ArrayList<Integer>();
        l.add(list.get(0));
        for(int i=1;i<list.size();i++){
        	l.add((list.get(i)+l.get(i-1)));
        }

        int max = 0;
        if(2*k+1>list.size()){
        	max = n;
        }
        else{
        	max = l.get(2*k);
        	for(int i=2;i+2*k<l.size();i+=2){
        		max = (int)Math.max(max, l.get(i+2*k)-l.get(i-1));
        	}
        }

        System.out.println(max);

    }
}

Measured memory_bytes: 30188
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

int main() {
  ll n,k;
  cin>>n>>k;
  
  ll ans=0;
  for(ll i=k;i<n+2;i++){
    ans += (i*(n-i+1))%MOD+1;    
  }
  
  cout << ans%MOD <<endl;
    
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

long long rangeSum(long long s, long long e, vector<long long>& pref){
    if(s==0) return pref[e];
    return pref[e]-pref[s-1];
}

long long rec(long long s, long long e, vector<long long>& pref, vector<vector<long long>>& dp){
    if(s==e) return 0ll;
    if(dp[s][e]!=-1)
        return dp[s][e];
    long long ans = LLONG_MAX;
    for(int i=s;i<e;i++){
        long long temp = rangeSum(s,i, pref)+rangeSum(i+1,e,pref)+rec(s,i,pref,dp)+rec(i+1,e,pref,dp);
        ans = min(ans, temp);
    }
    return dp[s][e] = ans;
}

int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    vector<long long> pref(n);
    vector<vector<long long>> dp(n+1, vector<long long>(n+1, -1));
    pref[0] = arr[0];
    for(int i=1;i<n;i++)
        pref[i] = pref[i-1]+arr[i];
    cout<<rec(0,n-1,pref,dp)<<"\n";
}

Measured memory_bytes: 4872
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Console.ReadLine();
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var p = Math.Round(a.Average());
		Console.WriteLine(a.Sum(x => (x - p) * (x - p)));
	}
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    lli n, d;
    cin2(n, d);
    cout << (n + d*2) / (d*2+1) << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 10**19
for i in range(2**n):
    colors = 0
    height = 0
    res = 0
    for j in range(n):
        if (i>>j)%2:
            colors += 1
            need = max(0,height - a[j] +1)
            res += need
            height += 1
            
        height = max(a[j] ,height)
    if colors >= k:ans = min(ans,res)
    
print(ans)
    
        

Measured memory_bytes: 44268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc066/tasks/abc066_b

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

    while(true) {
        S = S.substr(0, S.length()-1);
        if (S.length() % 2 == 0) {
            string front = S.substr(0, S.length() / 2);
            string back = S.substr(S.length() / 2, S.length() / 2);
            if (front == back) {
                cout << S.length() << "\n";
                return 0;
            }
        }
    }

    return 0;
}


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

using namespace std;

struct DATA{
  int d;
  int p;
};

bool Compare(const DATA&, const DATA&);

int main(){
  int i, n, m, d, p, sum;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<n; ++i){
      cin >> d >> p;
      _data.d = d;
      _data.p = p;
      data.push_back(_data);
    }
    sort(data.begin(), data.end(), Compare);

    while(data.size() != 0){
      if(m > data[0].d){
	m -= data[0].d;
	data.erase(data.begin());
      }else{
	data[0].d -= m;
	break;
      }
    }

    for(i=0, sum=0; i<data.size(); ++i)
      sum += data[i].d * data[i].p;

    cout << sum << endl;
    data.clear();
  }
  return 0;
}

bool Compare(const DATA& x, const DATA& y){
  if(x.p == y.p)
    return x.d < y.d;
  else
    return x.p > y.p;
}

Measured memory_bytes: 1352
#include<cstdio>
#include<vector>
#include<string.h>
using namespace std;

int board[1000][1000];
int res[1000][1000];

int main() {

  int n;
  char c;
  while(1) {
    scanf("%d", &n);
    if(!n) break;

    memset(board, 0, sizeof(board));
    memset(res, 0, sizeof(res));
    scanf("%c", &c);
    for(int i=0; i<n; ++i) {
      for(int j=0; j<n; ++j) {
	scanf("%c", &c);
	if(c == '.') {
	  board[i][j] = 1;
	  res[i][j] = 1;
	} else if(c == '*') board[i][j] = 2;
      }
      scanf("%c", &c);
    }

    int maxi = 0;
    for(int i=0; i<n; ++i) {
      for(int j=0; j<n; ++j) {
	if(board[i][j] == 1) {
	  if(i == 0 || j == 0 || board[i-1][j] == 2 || board[i][j-1] == 2 || board[i-1][j-1] == 2) {
	    res[i][j] = 1;
	  } else {
	    res[i][j] = min( res[i-1][j], min( res[i-1][j-1], res[i][j-1] ) ) + 1;
	  }
	  maxi = max( maxi, res[i][j] );
	}
      }
    }

    /*
    for(int i=0; i<n; ++i) {
      for(int j=0; j<n; ++j) {
	printf("%d", res[j][i]);
      }
      printf("\n");
    }
    */
    printf("%d\n", maxi);
  }
}

Measured memory_bytes: 8580
#include <iostream>

using namespace std;

//const auto MAX_N = 200;

int main() {
    long long a, b, c, d;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

    long long res;

    long long ac = a * c;
    long long ad = a * d;
    long long bc = b * c;
    long long bd = b * d;
    res = ac;
    res = max(res, ad);
    res = max(res, bc);
    res = max(res, bd);
//
//    long long zero = 0;
//    if (a >= 0 )

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3620
x,n = gets.strip.split(" ").map do |i|
  i.to_i
end

p = gets.strip.split(" ").map do |i|
  i.to_i
end

i = 0
while(true)
  if !p.include?(x-i)
    print(x-i)
    break
  elsif !p.include?(x+i)
    print(x+i)
    break
  end
  i+=1
end


Measured memory_bytes: 14296
#include<bits/stdc++.h>
#define eps 1e-8
#define ll long long
#define ed cout<<endl
#define pb push_back
#define mp make_pair
#define fi first
#define ll long long
#define se second
#define inf 2e9
#define sz 456789
#define all(x) x.begin(), x.end()
#define pi 3.14159265359
using namespace std;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll a, b, c;
string s;
int main(){
    faster();
    cin >> s;
    a = s.size();
    for(int i = 0; i < a / 2; i++){
        if (s[i] != s[a - i - 1]){
            b++;
        }
    }
    cout << b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  long long n, ans = 0;
  cin >> n;

  for (long long i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    }

    ans += i;
  }

  cout << ans << "\n";

  return 0;
}

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

using namespace std;

typedef long long ll;
vector<vector<ll> > dp;
vector<vector<ll> > a;
ll mod = 1e9+7;

vector<vector<ll> > matrix_mod_pow(ll n, ll k, ll mod) {
    vector<vector<ll> > dp(n, vector<ll>(n, 0));

    if (k == 0) {
        for (int i = 0; i < n; i++)
            dp[i][i] = 1;
        return dp;
    }

    if (k % 2) {
        vector<vector<ll> > tmp = matrix_mod_pow(n, k-1, mod);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int l = 0; l < n; l++) {
                    dp[i][j] += (a[i][l]*tmp[l][j])%mod;
                    dp[i][j] %= mod;
                }
            }
        }
        return dp;
    }
    else {
        vector<vector<ll> > tmp = matrix_mod_pow(n, k/2, mod);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int l = 0; l < n; l++) {
                    dp[i][j] += tmp[i][l]*tmp[l][j]%mod;
                    dp[i][j] %= mod;
                }
            }
        }
        return dp;
    }
}

int main() {
    int n;  ll k;   cin >> n >> k;
    a.resize(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    }

    dp = matrix_mod_pow(n, k, mod);

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans = (ans + dp[i][j]) % mod;
        }
    }

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

Measured memory_bytes: 6052
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    ll h, w;
    cin >> h >> w;
    vector<bool> v;
    v[0];
    vector<int> v2;
    v2[0];
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] |= dp[i][j][l];
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] |= dp[i][j][l];
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] |= dp[i][j][l];
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] |= dp[i][j][l];
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 160256
// In The Namw Of Allah
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;
typedef pair <int, int> pii;
typedef long long ll;

int dist[N], dp[N], col[N], vis[N];
vector <pair <int, pii>> v;
vector <int> adj[N];

void bfs(int v, int d, int c) {
	queue <int> q;
	dist[v] = d + 1;
	vector <int> vc;
	q.push(v);
	vis[v] = 1;
	while(!q.empty()) {
		v = q.front(), q.pop();
		vc.push_back(v);
		for (auto u : adj[v]) {
			if(!vis[u] && dp[u] < dist[v] - 1) {
				q.push(u);
				vis[u] = 1;
				dist[u] = dist[v] - 1;
			}
		}
	}
	while(!vc.empty()) {
		v = vc.back();
		vc.pop_back();
		if(!col[v])	col[v] = c;
		vis[v] = 0, dp[v] = dist[v], dist[v] = 0;
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		adj[v].push_back(u), adj[u].push_back(v);
	}
	int tc;
	cin >> tc;
	while(tc--) {
		int u, d, c;
		cin >> u >> d >> c;
		u--;
		v.push_back({d, {u, c}});
	}
	while(!v.empty()) {
		bfs(v.back().second.first, v.back().first, v.back().second.second);
		v.pop_back();
	}
	for (int i = 0; i < n; i++)	cout << col[i] << "\n";
}

Measured memory_bytes: 14456
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
int M = 1000000000 + 7;
class Combination{
    //Combination class is written by noy72
public:
    vector<long long> fact, rev;
    Combination(int n = 200005) : fact(n), rev(n) {
        fact[0] = fact[1] = 1;
        for(int i = 2; i < n; i ++){
            (fact[i] = fact[i - 1] * i) %= M;
        }
        rev[n - 1] = power(fact[n - 1], M - 2) % M;
        for (int i = n - 1; i > 0; i--) {
            rev[i - 1] = rev[i] * i % M;
        }
    }
    long long power(long long x, long long n){
        long long res = 1;
        if(n > 0){
            res = power(x, n / 2);
            if(n % 2 == 0) res = (res * res) % M;
            else res = (((res * res) % M) * x ) % M;
        }
        return res;
    }
    long long factorial(long long l, long long r){ return fact[r] * rev[l - 1] % M; }
    long long factorial(long long n){ return fact[n]; }
    long long combination(long long n, long long r){
        return factorial(n - r + 1, n) * rev[r] % M;
    }
};
//
signed main(){
    int h,w,a,b; cin >> h >> w >> a >> b;
    Combination C(500000);
    int ans = 0;
    for(int i = b; i < w; i++ ){
        ans += (C.combination(h-a+i-1,i) * C.combination(a-1+w-i-1, a-1))%M;
        ans %= M;
    }
    cout << ans << endl;
}



Measured memory_bytes: 8064
#include "stdio.h"
#include "climits"

int n, m;
int edge[101][101];
int dis[101];
bool flag[101];
int box;
int s, e, p;

int main() {
	scanf("%d %d", &n, &m);
	while (n != 0) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				edge[i][j] = 200000000;
			}
		}
		for (int i = 0; i < m; i++) {
			scanf("%d", &box);
			if (box == 1) {
				scanf("%d %d %d", &s, &e, &p);
				if (edge[s][e] > p) {
					edge[s][e] = p;
					edge[e][s] = p;
				}
			}
			else {
				scanf("%d %d", &s, &e);
				for (int j = 1; j <= n; j++) {
					flag[j] = true;
					dis[j] = 200000000;
				}
				dis[s] = 0;
				box = s;
				while (flag[e]) {
					flag[box] = false;
					for (int j = 1; j <= n; j++) {
						if (dis[box] + edge[box][j] < dis[j]) {
							dis[j] = dis[box] + edge[box][j];
						}
					}
					for (int j = 1; j <= n; j++) {
						if (flag[j]) {
							box = j;
							break;
						}
					}
					for (int j = box; j <= n; j++) {
						if (flag[j]) {
							if (dis[box] > dis[j])box = j;
						}
					}
				}
				if (dis[e] == 200000000)printf("-1\n");
				else printf("%d\n", dis[e]);
			}
		}
		scanf("%d %d", &n, &m);
	}
	return 0;
}

Measured memory_bytes: 2592
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

typedef struct data {
	int a;
	int b;
} data;

FILE *in, *ans;
int tno;


int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int fnc() {

	int n = geti();
	char s[16];
	getstr(s);
	int k = geti();
	
	for (int i = 0; i < n; i++) {
		if (s[i] != s[k - 1]) {
			s[i] = '*';
		}
	}
	s[n] = '\n';
	s[n + 1] = '\0';
	out(s);

	return 0;
}

int main() {
#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc();
#endif

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;



int main() {
  string s;
  cin >> s;
  bool ok = true;
  rep (i,s.size()){
      if(i%2==0){
          //cout << 0 << endl;
          if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
            ok = false;
            break;
          }
      }
      if(i%2!=0){
          //cout << 1 << endl;
          if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
            ok = false;
            break;
          }
      }

  }
  if(ok) cout << "Yes"  << endl;
  else cout << "No" << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int n,taro=0,hanako=0;string a,b;cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(a>b) taro+=3;
        else if(a<b) hanako+=3;
        else{
            taro++;
            hanako++;
        }
    }
    printf("%d %d\n",taro,hanako);
}


Measured memory_bytes: 3276
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int n;

void dfs(int i, double x1, double y1, double x2, double y2){
	if(i == n){
		cout << setprecision(10) << x1 << " " << y1 << endl;
		return;
	}
	//double l = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	double tx = (x1*2+x2)/3;
	double ty = (y1*2+y2)/3;
	double vx = (x1+x2*2)/3;
	double vy = (y1+y2*2)/3;
	double ux = tx + 0.5*(vx-tx) - sin(acos(0.5))*(vy-ty);
	double uy = ty + sin(acos(0.5))*(vx-tx) + 0.5*(vy-ty);
	dfs(i+1, x1, y1, tx, ty);
	dfs(i+1, tx, ty, ux, uy);
	dfs(i+1, ux, uy, vx, vy);
	dfs(i+1, vx, vy, x2, y2);
}

int main(){
	cin >> n;
	dfs(0, 0, 0, 100, 0);
	cout << 100 << " " << 0 << endl;
}


Measured memory_bytes: 3260
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
  int N,D,i,j,k;
  double l;
  scanf("%d %d",&N,&D);
  int x[N][D];

  for(i=0;i<N;i++){
    for(j=0;j<D;j++)
    scanf("%d",&x[i][j]);
  }
  int c=0;
  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++){
      int n=0;
      for(k=0;k<D;k++){
        n +=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
        l=sqrt(n);
      if(ceil(l)==floor(l))
        c++;
    }
  }
  printf("%d",c);
}


Measured memory_bytes: 128
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

p = [1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15]

n = int(input())
if n == 1:
    print(0)
else:
    ans = 0
    for j in factorization(n):
        ans += p[j[1]-1]

    print(ans)

Measured memory_bytes: 9620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef unsigned long long ll;
const int maxn = 105;

int n,a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  int ret = 0;
  for(int i=1;i+1<n;i++){
    if(!((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1])))ret++;
  }
  cout<<ret<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

 ll n, count=0, ans=0;
 string s;
 int p,q,r,m;
 cin >> p >> q >> r;
 ans = p + q + r;
 m = max(p,q);
 m = max(m,r);
 ans -= m;


 cout << ans << endl;
}

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

int main() {
	// your code goes here
	string s1,s2;
	cin>>s1>>s2;
	int m=s1.length();
	int n=s2.length();
	
	int dp[m+1][n+1];
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0 || j==0)
			dp[i][j]=0;
		}
	}
	
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(s1[i-1]==s2[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int index=dp[m][n];
	char lcs[index+1];
  	lcs[index]='\0';
	int i=m,j=n;

			while(i>=0 && j>=0)
			{
				if(s1[i-1]==s2[j-1])
				{
					lcs[index-1]=s1[i-1];
					index--;
					i--;
					j--;
				}
				else
				{
					if(dp[i][j-1]>dp[i-1][j])
					j--;
					else
					i--;
				}
				
			}
			
		
	cout<<lcs;
	
	return 0;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2==1)
        cout << "No";
    else{
        if((y>=2*x)&&(y<=4*x))
            cout << "Yes";
        else
            cout << "No";
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	int q,w,z=0;
	cin >>q>>w;
	int a[q];
	for(int s=0;s<q;s++)
	{
		cin>>a[s];
	}
	sort(a,a+q);
	for(int s=0;s<w;s++)
	{
		z=a[s]+z;
	
	}
	cout<<z;
}

Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;

int k,a,b;
int main(){
cin>>k;
cin>>a>>b;
bool go=false;
for(int i=a;i<=b;i++){
	if(i%k==0){go=true;}
}
if(go){
cout<<"OK"<<endl;
}else{cout<<"NG"<<endl;}

	

}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	char str[7];
	scanf("%s",str);
	if(str[0] == str[1] && str[1] == str[2])	puts("Yes");
	else if(str[1] == str[2] && str[2] == str[3])	puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 128
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static boolean check(String s) throws IOException {
		int size = s.length();
		if (size % 2 == 1) {
			return false;
		} else {
			return s.substring(0, size / 2).equals(s.substring(size / 2, size));
		}
	}

	public static void solve() throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();
		int lMax = s.length();
		int l = s.length();
		for (int i = 0; i < lMax; i++) {
			s = s.substring(0, l - 1);
			l = s.length();
			if (check(s) == true) {
				System.out.println(l);
				break;
			}
		}
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using u32 = uint32_t;

template<typename T>
struct ExactDiv {
    T t, i, val;
    ExactDiv() {}
    ExactDiv(T n) : t(T(-1) / n), i(mul_inv(n)) , val(n) {};
    T mul_inv(T n) {
        T x = n;
        for (int i = 0; i < 5; ++i) x *= 2 - n * x;
        return x;
    }
    bool divide(T n) const {
        if(val == 2) return !(n & 1);
        return n * this->i <= this->t;
    }
};

vector<ExactDiv<u32>> get_prime(int n){
    if(n <= 1) return vector<ExactDiv<u32>>();
    vector<bool> is_prime(n+1, true);
    vector<ExactDiv<u32>> prime;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j.val > n) break;
            is_prime[i*j.val] = false;
            if(j.divide(i)) break;
        }
    }
    return prime;
}
const auto primes = get_prime(101000);

int main() {
    int x;
    cin >> x;
    for (auto &&i : primes) {
        if(i.val >= x){
            cout << i.val << "\n";
            return 0;
        }
    }
    return 0;
}

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

vector<int> input(int N){
    vector<int> vec;    
    int temp = 0;
    for (int i = 0; i < N; i++ )    {
        cin >> temp;
        vec.push_back(temp);
    }
    return vec;
}

int main(){
    int N; // 1 <= A, B <= 100, 0 <= C < B
    cin >> N;
    vector<int> vec = input(N);
    
    bool ret = false;
    int count = 0;
    int box_val = 1;    
    int idx = 0;    
    for (int i = 0; i < N; i ++){
        box_val = vec.at(idx);
        idx = box_val - 1;
        count ++;
        if(box_val == 2){
            ret = true;
            break;    
        }
    }    
    if (ret)
        cout << count << endl;
    else
        cout << "-1" << endl;
}

Measured memory_bytes: 3928