akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter

sys.setrecursionlimit(2502)


def paint(field, i, j, b, f, moves={(-1, 0), (1, 0), (0, 1), (0, -1)}):
    fij = field[i][j]
    if fij & f:
        return
    if fij & 4 and not fij & b:
        return
    field[i][j] |= b | f
    for di, dj in moves:
        ni = i + di
        nj = j + dj
        if nj < 0 or w <= nj or ni < 0 or h <= ni:
            continue
        paint(field, ni, nj, b, f)


buf = []
chardict = {'.': 0, 'W': 5, 'B': 6}
while True:
    w, h = map(int, input().split())
    if w == 0:
        break
    field = []
    init_w, init_b = 0, 0
    for _ in range(h):
        line = input().strip()
        init_w += line.count('W')
        init_b += line.count('B')
        field.append([chardict[c] for c in line])
    for i in range(h):
        for j in range(w):
            fij = field[i][j]
            if fij & 4 and not fij & 24:
                paint(field, i, j, fij & 3, (fij & 3) << 3)
    result = Counter(b & 3 for row in field for b in row)
    print(result[2] - init_b, result[1] - init_w)

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if(s == "SUN")  puts("7");
  else if(s == "MON")  puts("6");
  else if(s == "TUE")  puts("5");
  else if(s == "WED")  puts("4");
  else if(s == "THU")  puts("3");
  else if(s == "FRI")  puts("2");
  else if(s == "SAT")  puts("1");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MAXN 3000
#define MAXM 3000



int main(){
	int N,M;
	int a[MAXM];
	int b[MAXM];
	int c[MAXM];
	cin >> N >> M;

	long long INF  = 1000000001;
	long long INFLL = (long long)INF * INF;

	REP(M){
		cin >> a[i] >> b[i] >> c[i];
	}

	long long dist[MAXN];

	REP(N) dist[i] = -INFLL;
	
	dist[0] = 0;
	int over[MAXN] = {0};


	for(int k = 0;k<N+1;k++){
		REP(M){	

			if(dist[a[i]-1] != -INFLL && dist[b[i]-1] < dist[a[i]-1] + c[i]){
				//更新
				dist[b[i]-1] = dist[a[i]-1] + c[i];

				//無限ループしてそう
				if(k == N){
					over[b[i]-1] = 1;
				}
			}
		}
	}
	if(over[N-1] == 1) cout << "inf" << endl;	
	else cout << dist[N-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////
ll inf=(ll)1E15-1;
#define MAX_V 200000//調節！！！！！！！！！！！！！！！！！！！！！！！！
int V;//頂点数！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
struct edge{ll to,cost;};
ll d2[MAX_V];//頂点sからの最短距離
vector<edge>G2[MAX_V];
void dijkstra2(int s){
    priority_queue<i_i,vector<i_i>,greater<i_i>> que;//firstは最短距離、secondは頂点の番号
    fill(d2,d2+V+1,inf);//頂点番号は0~V-1でも1~Vでもお好きな方で
    d2[s]=0;
    que.push(i_i(0,s));
    while(!que.empty()){
        //greater<i_i>なのでfirstが小さい順に取り出せる！
        i_i p=que.top();que.pop();
        int v=p.second;
        if(d2[v]<p.first)continue;
        for(int i=0;i<G2[v].size();i++){
            edge e=G2[v][i];
            if(d2[e.to]>d2[v]+e.cost){
                d2[e.to]=d2[v]+e.cost;
                que.push(i_i(d2[e.to],e.to));
            }
        }
    }
}
ll d[MAX_V];//頂点sからの最短距離
vector<edge>G[MAX_V];
void dijkstra(int s){
    priority_queue<i_i,vector<i_i>,greater<i_i>> que;//firstは最短距離、secondは頂点の番号
    fill(d,d+V+1,inf);//頂点番号は0~V-1でも1~Vでもお好きな方で
    d[s]=0;
    que.push(i_i(0,s));
    while(!que.empty()){
        //greater<i_i>なのでfirstが小さい順に取り出せる！
        i_i p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(i_i(d[e.to],e.to));
            }
        }
    }
}
////////////////////////////////////////

int main(){
    int m,s,t;cin>>V>>m>>s>>t;s--;t--;
    while(m--){
        int u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
        edge e;e.to=v;e.cost=a;
        G[u].pb(e);
        e.to=u;
        G[v].pb(e);
        e.cost=b;
        G2[v].pb(e);
        e.to=v;
        G2[u].pb(e);
    }
    dijkstra(s);
    dijkstra2(t);
    ll sum[V];
    rep(i,0,V-1)sum[i]=d[i]+d2[i];
   // rep(i,0,V-1)cout<<sum[i]<<endl;
    
    ll mi=sum[V-1];
    for(int i=V-2;i>=0;i--){
        mi=min(mi,sum[i]);
        sum[i]=mi;
    }
    rep(i,0,V-1){
        cout<<(ll)1E15-sum[i]<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 25616
#include<cstdio>
#include<queue>
#include<utility>

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 400;

const int di[] = {1, 0, -1, 0};
const int dj[] = {0, 1, 0, -1};

bool color[MAX_N][MAX_N];
int H, W;

char ch[MAX_N + 1];

void input(){
	scanf("%d%d", &H, &W);
	for(int i = 0; i < H; ++i){
		scanf("%s", ch);
		for(int j = 0; j < W; ++j){
			color[i][j] = (ch[j] == '#');
		}
	}
}

bool isin_(int i, int j){
	return i >= 0 && i < H && j >= 0 && j < W;
	//範囲内か
}

bool check_(int i, int j, int d){
	int ni = i + di[d];
	int nj = j + dj[d];
	if(!isin_(ni, nj)) return false;//範囲外
	if(color[i][j] == color[ni][nj]) return false;//同色
	return true;
}

bool used[MAX_N][MAX_N];

long long solve(){
	long long ans = 0;
	long long b = 0, w = 0;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			if(used[i][j]) continue;//?
			b = 0;
			w = 0;
			queue<P> que;
			used[i][j] = true;
			que.push(P(i, j));
			while(!que.empty()){
				P p = que.front();
				que.pop();
				int ci = p.first, cj = p.second;
				if(color[ci][cj]) b++;
				else w++;
				for(int d = 0; d < 4; ++d){//四方向
					if(!check_(ci, cj, d)) continue;//範囲と色
					int ni = ci + di[d], nj = cj + dj[d];
					if(used[ni][nj]) continue;//同じグラフ上の点は一度見れば十分
					used[ni][nj] = true;
					que.push(P(ni, nj));
				}
			}
			ans += b * w;//グラフ上の任意の白と黒は結べる\sum_{b}w
		}
	}
	return ans;
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 512
n = STDIN.gets.to_i

n1 = STDIN.gets.to_i
n2 = STDIN.gets.to_i

max = n1
min = n1

if n1 > n2 then
  min = n2
  diff = n2 - n1
  max = n2
else
  max = n2
  diff = n2 - n1
end


(3..n).each { |i|
  x = STDIN.gets.to_i

  if x > max then
    diff = x - min if x - min > diff
    max = x
  elsif x <= min then
    diff = x - max if x - max > diff
    min = x
    max = x
  end
}
puts diff

Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
#define pi 3.14159
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
    ll n,m,k,sum=0;
   /*Code*/
    cin>>n>>m;
    
    fn(i,m){
      cin>>k;
      sum+=k;
    }
    if(sum==n){cout<<0<<endl;return   0;}
    cout<<(sum<n?n-sum:-1)<<endl;
   return 0;
}
    

Measured memory_bytes: 3624
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1

const int maxn = 1e5 + 7;

int main() {
    int a,b;
    while(cin >> a >> b) {
        int temp1 = a / b;
        int temp2 = a % b;
        if(temp2 != 0) temp1++;
        cout << temp1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
R, C,K = map(int, input().split())
dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]
import random
for i in range(K):
    r, c, v = map(int,input().split())
    D[r][c] = v
 
for i in range(R+1):
    for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
 
        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]
 
ans = 0
for i in range(4):
    ans = max(ans, dp[i][-1][-1])
print(ans)

Measured memory_bytes: 447300
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

typedef pair<int, int> Pi;

int n, m;
map<int, bool> memo;
vector<int> v;

int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == 1)
      memo[b] = true;
    else if (b == n)
      v.push_back(a);
  }

  bool ans = false;
  for (int i = 0; i < v.size() && !ans; i++) {
    if (memo[v[i]])
      ans = true;
  }

  printf("%s\n", (ans ? "POSSIBLE" : "IMPOSSIBLE"));
}


Measured memory_bytes: 9976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;

  int L = (B/K)*K;
  
  if (A <= L) { 
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
  
}
  
  
  

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

int k, a, b;

signed main() {
	cin >> k >> a >> b;
	
	if (b - a <= 2 || k <= a - 1) {
		cout << k + 1 << endl;
		return 0;
	}
	
	int cnt = k - (a - 1);
	
	cout << a + (cnt / 2) * (b - a) + (cnt % 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long s[555555];
long long a[555555];
long long ans;
int main(){;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		s[i]=s[i-1]+x;
		a[i]=a[i-1]^x;
	}
	int l=1;
	for (int r=1;r<=n;r++){
		for (;(s[r]-s[l-1])!=(a[r]^a[l-1]);l++);
		ans+=r-l+1;
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

int main(){
    int N;
    cin >> N;
    vector<P> C;
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        C.push_back(make_pair(B, A));
    }

    sort(C.begin(), C.end());
    int time = 0;
    for (int i = 0; i < N; i++) {
        time += C.at(i).second;
        if (time > C.at(i).first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 7464
#include <bits/stdc++.h>
using namespace std ;
int n , k , s ;
signed main () {
    cin >> n >> k >> s ;
    for ( int i = 1 ; i <= k ; i ++ ) cout << s << " " ;
    if ( s != 1e9 ) {
        for ( int i = k + 1 ; i <= n ; i ++ ) cout << 1000000000 << " " ;
    }
    else {
        for ( int i = k + 1 ; i <= n ; i ++ ) cout << 19260817 << " " ;
    }
    cout << endl ;
}

Measured memory_bytes: 1280
n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] != l[j] != l[k]:
                if l[i] + l[j] > l[k]:
                    ans += 1
print(ans)

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

int solve(int arr[],int n){
	int dp[n+1];
	for(int i=0;i<n+1;i++){
		if(i==0){
			dp[i]=0;
		}
		else if(i==1){
			dp[i]=abs(arr[i]-arr[i-1]);
		}
		else{
			dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
		}
	}
	return dp[n];
} 

int main(){
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int x=solve(arr,n-1);
	cout<<x<<endl;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define rep(k,dst)    for(int i=k; i<dst;  i++)
#define rep2(k,dst)   for(int j=k; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);

int main(){
    string s; cin >> s;
    
    rep(0,s.size()) cout << 'x';
    cout << endl;
    return 0;
}
/*
3 3
1 7
3 2
1 7
*/


Measured memory_bytes: 3564
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

// 1-indexed
template <typename T=int>
struct BIT {
    vector<T> v;
    const int n;

    BIT(int n): n(n), v(n+1,0) {}

    void add(int i, int x) {
        while (i <= n) {
            v[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += v[i];
            i -= i & -i;
        }
        return ret;
    }
    T sum(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

bool solve(long long index, VI &a) {
    int n = a.size();
    VI ru(n+1);
    ru[0] = 0;
    REP(i,0,n) ru[i+1] = a[i] < index ? -1 : 1;
    ru[0] += n+2;
    REP(i,0,n) ru[i+1] += ru[i];
    BIT<> bit(n+n+2);
    LL sum = 0;
    REP(i,0,n+1) {
        sum += bit.sum(ru[i]);
        bit.add(ru[i], 1);
    }
    //dump(index);
    //dump(sum);
    return sum >= ((LL)n * (n+1) / 2 + 1) / 2;
}

long long meguru_bin(VI &a) {
    long long ok = 0;
    long long ng = 1'000'000'000+1;

    while (abs(ok - ng) > 1) {
        long long mid = ng + (ok - ng) / 2;
        //cerr << ok << " " << mid << " " << ng << endl;
        if (solve(mid, a)) ok = mid;
        else ng = mid;
    }

    return ok;
}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    //REP(i,0,n) cerr << a[i] << endl;
    cout << meguru_bin(a) << endl;

    //cout << solve(10, a) << endl;
}

int main() {
    solve();
    
    return 0;
}

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

int main(){
	string a;
	cin >> a;
	ll maxi = 0;
	ll count = 0;
	for (int z=0;z<a.size();z++){
		if (a[z] == 'A' || a[z] == 'G' || a[z] == 'C' || a[z] == 'T'){
			count ++;
			maxi = max(maxi,count);
		} else {
			count = 0;
		}
	}
	cout << maxi << endl;
	cin >> a;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),
            b = sc.nextInt(),
            c = sc.nextInt(),
            d = sc.nextInt();

        int s = 0;
        while (a > 0 && c > 0) {
            if (s == 0) {
                c -= b;
                s = 1;
            }
            else {
                a -= d;
                s = 0;
            }
        }

        System.out.println(a > 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 35776
#include <iostream>
using namespace std;
int main()
{
	int n, x, y, h, w, s, p, i;
	while (cin >> n && n)
	{
		p = 0;
		for (i = 0; i < n; i++)
		{
			cin >> x >> y >> h >> w;
			s = x + y + h;
			     if (s <=  60 && w <=  2)	p +=  600;
			else if (s <=  80 && w <=  5)	p +=  800;
			else if (s <= 100 && w <= 10)	p += 1000;
			else if (s <= 120 && w <= 15)	p += 1200;
			else if (s <= 140 && w <= 20)	p += 1400;
			else if (s <= 160 && w <= 25)	p += 1600;
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 0
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  2 11:20:26 2020
//
package main

import (
	"fmt"
	"math/big"
)

const MOD = 1e9 + 7

var N int
var A []*big.Int

func solve() int64 {
	mod := big.NewInt(MOD)

	lcm := big.NewInt(A[0].Int64())
	for _, a := range A {
		g := big.NewInt(0).GCD(nil, nil, lcm, a)
		lcm.Mul(lcm, a)
		lcm.Div(lcm, g)
	}

	ans := big.NewInt(0)
	for _, a := range A {
		x := big.NewInt(0).Div(lcm, a)
		ans.Add(ans, x)
	}
	return ans.Mod(ans, mod).Int64()
}

func main() {
	fmt.Scan(&N)
	A = make([]*big.Int, N)
	for i := range A {
		var a int64
		fmt.Scan(&a)
		A[i] = big.NewInt(a)
	}

	fmt.Println(solve())
}


Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] atgc = {'A', 'T', 'G', 'C'};
        
        int length = 0;
        int tmpLength = 0;
        boolean checkNow = false;
        for(int i = 0;i < s.length;i++) {
            // ATGCかどうかチェック
            boolean preCheckNow = false;
            for(int j = 0;j < 4;j++) {
                if(s[i] == atgc[j]) preCheckNow = true;
            }
            if(preCheckNow) {
                if(checkNow) tmpLength++;
                else {
                    checkNow = true;
                    tmpLength++;
                }
            }
            else {
                if(checkNow) {
                    checkNow = false;
                    length = length < tmpLength ? tmpLength : length;
                    tmpLength = 0;
                }
            }
            
            checkNow = preCheckNow;
        }
        if(checkNow) length = length < tmpLength ? tmpLength : length;
        
        System.out.println(length);
    }
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int N;
	cin >> N;
	bool t = false;
	if ((N % 10) == 7) {
		t = true;
	}
	if ((N%100) / 10 == 7) {
		t = true;
	}
	if (N / 100 == 7) {
		t = true;
	}
	cout << (t ? "Yes" : "No") << endl;

	return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define INF 2000'000'000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
unsigned int n, W;
vector < int > w(101), v(101);

vector < unsigned int > dp(100001, INF);

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);
	cin >> n >> W;
	for(unsigned int i = 0; i < n; i++)
		cin >> w[i] >> v[i];	

	dp[0] = 0;
	for(unsigned int i = 0; i <= n; i++){
		for(int j = 100000 - v[i]; j >= 0; j--){
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= 100'000; i++)
		if(dp[i] <= W)
			ans = i;
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    string s;
    int r = 700;

    cin >> s;
    for (int i = 0; i < 3; i++){
        if(s[i] == 'o') r = r + 100;
    }

    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
import math

N,M,X = map(int, input().split())
S = set([tuple([0]*(M+1))])

for _ in range(N):
    CA = list(map(int, input().split()))

    S2 = set()
    for s in S:
        S2.add(tuple([s[i] + CA[i] for i in range(M+1)]))

    S |= S2

minC = math.inf
for s in S:
    for i in range(M):
        if s[i+1] < X:
            break
    else:
        minC = min(minC, s[0])

if minC == math.inf:
    print(-1)
else:
    print(minC)


Measured memory_bytes: 11492
#include<stdio.h>
#include<stdlib.h>
int comp(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int main(){
  int n,a[200000],b,i;
  long long int ans;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    a[i]-=i+1;
  }
  qsort(a,n,sizeof(int),comp);
  b=a[n/2];
  ans=0;
  for(i=0;i<n;i++)
    ans+=abs(a[i]-b);
  printf("%lld\n",ans);
  return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll n, cnt[42];
ll dp[42][2];
ll k;

ll calc(int i, bool tight){
	if(i == -1)return 0;
	if(dp[i][tight] != -1)return dp[i][tight];
	int md = (tight)?((k>>i)&1):1;
	ll ret = 0;
	for(int d = 0; d <= md; d++){
		bool ntg = tight && (((k>>i)&1) == d);
		// cout<<i<<" "<<ntg<<" "<<d<<" "<<((k>>i)&1)<<" "<<tight<<endl;
		ll tmp = calc(i - 1, ntg);
		if(d == 0){
			tmp += (cnt[i])*(1LL<<i);
		}else{
			tmp += (n-cnt[i])*(1LL<<i);
		}
		ret = max(ret, tmp);
	}
	return dp[i][tight] = ret;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;
    ll x;
    memset(cnt, 0, sizeof(cnt));
    memset(dp, -1, sizeof(dp));
    for(int j = 0; j < n; j++){
    	cin>>x;
    	for(int i = 40; i >= 0; i--){
    		if(x&(1LL<<i))cnt[i]++;
    	}
    }
    cout<<calc(40, true)<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

#define N_MAX 500100

struct bit{
  long long dat[N_MAX + 1];

  void init(){
    for(int i = 0; i < N_MAX; i++){
      dat[i] = 0;
    }
  }

  long long sum(int i){
    long long s = 0;
    while(i > 0){
      s += dat[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, long long x){
    while(i <= N_MAX){
      dat[i] += x;
      i += i & -i;
    }
  }
}bit1;

ll la[500100];
ll ans[500100];

int main(){
  clr(la,-1);
  clr(ans,0);
  ll n,q;
  cin>>n>>q;
  bit1.init();
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  vector<pair<pair<ll,ll>,ll> > vp;
  rep(i,0,q){
    ll a,b;
    cin>>a>>b;
    vp.pb(mp(mp(b,a),i));
  }
  sort(all(vp));
  ll index = 0;
  rep(i,0,n){
    if(la[v[i]]==-1){
      la[v[i]] = i+10;
      bit1.add(i+10,1);
    }
    else{
      bit1.add(la[v[i]],-1);
      la[v[i]] = i+10;
      bit1.add(i+10,1);
    }
    while(i+1==vp[index].fi.fi){
      ans[vp[index].se] = bit1.sum(vp[index].fi.fi+9)-bit1.sum(vp[index].fi.se+8);
      index++;
    }
  }
  rep(i,0,q){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 34180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
string a,b,c;cin>>a>>b>>c;
cout<<char(toupper(a[0]))<<char(toupper(b[0]))<<char(toupper(c[0]));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    if(abs(n-m) > 1){
        cout << 0;
        exit(0);
    }
    ll ans = 1;
    REP(i, n){
        ans = ans * i % mod;
    }
    REP(i, m){
        ans = ans * i % mod;
    }
    if(n == m)ans = ans * 2 % mod;
    cout << ans;
}   

Measured memory_bytes: 256
// Comment
// 정렬 방향을 잘 생각하면 풀 수 있다.

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MOD = 1e9 + 7;

void add(int &a, int b) {
	a += b;
	if(a >= MOD) a -= MOD;
	if(a < 0) a += MOD;
}

struct BIT {
	int P; vector<int> val;
	BIT(int n) {
		P = n + 20;
		val = vector<int>(P, 0);
	}
	void update(int v, int k) {
		for(v+=10; v<P; v+=v&-v) add(val[v], k);
	}
	int getSum(int v) {
		int res = 0;
		for(v+=10; v>0; v-=v&-v) add(res, val[v]);
		return res;
	}
	int getSum(int a, int b) {
		int res = getSum(a) - getSum(b);
		add(res, 0);
		return res;
	}
};

int N, M;
vector<int> Nr, Mr;
vector<pi> Ps;
int main() {
	cin >> N >> M;
	Nr.resize(N), Mr.resize(M);
	for(int i=0; i<N; i++) scanf("%d", &Nr[i]);
	for(int i=0; i<M; i++) scanf("%d", &Mr[i]);
	vector<int> ys;
	for(int i=0; i<N; i++) {
		int ix = lower_bound(ALL(Mr), Nr[i]) - Mr.begin();
		if(ix == 0 || ix == M) continue;
		int dl = Nr[i] - Mr[ix-1];
		int dr = Mr[ix] - Nr[i];
		Ps.emplace_back(dl, dr);
		ys.push_back(dr);
	}
	ys.push_back(-INF);
	sort(ALL(ys));
	ys.erase(unique(ALL(ys)), ys.end());
	sort(ALL(Ps));
	Ps.erase(unique(ALL(Ps)), Ps.end());
	sort(ALL(Ps), [](pi a, pi b) {
		if (a.one == b.one) return a.two > b.two;
		return a.one < b.one;
	});

	BIT bit = BIT(SZ(ys));
	bit.update(0, 1);
	for(pi p: Ps) {
		int x, y; tie(x, y) = p;
		y = lower_bound(ALL(ys), y) - ys.begin();
		int add = bit.getSum(y-1);
		bit.update(y, add);
	}
	printf("%d\n", bit.getSum(SZ(ys)-1));
	return 0;
}


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

vector<int> rights;
int n, l, m;
string s;

vector<int> conv(vector<int> a, vector<int> b) {
    vector<int> ret(m);
    for (int i = 0; i < m; ++i) {
        ret[i] = a[b[i]];
    }
    return ret;
}

vector<int> dubl(vector<int> a, int times) {
    vector<int> ret(m);
    vector<int> dbs(m);
    for (int i = 0; i < m; ++i) {
        ret[i] = i;
        dbs[i] = a[i];
    }
    for (int i = 0; (1 << i) <= times; ++i) {
        if ((times >> i) & 1) {
            ret = conv(ret, dbs);
        }
        dbs = conv(dbs, dbs);
    }
    return ret;
}

vector<int> dfs(int lef, int rig) {
    vector<int> ret(m);
    for (int i = 0; i < m; ++i) {
        ret[i] = i;
    }
    if (rights[lef] < rig) {
        int p = lef;
        while (p < rig) {
            ret = conv(ret, dfs(p, rights[p]));
            p = rights[p];
        }
        return ret;
    }
    if (s[lef] == '(') {
        int j = rig - 1;
        for (; '0' <= s[j] && s[j] <= '9'; --j);
        int times = 0;
        for (int i = j + 1; i < rig; ++i) {
            times = times * 10 + s[i] - '0';
        }
        return dubl(dfs(lef + 1, j), times);
    }
    int idx = 0;
    for (int i = lef + 1; i < rig; ++i) {
        idx = idx * 10 + s[i] - '0';
    }
    --idx;
    if (s[lef] == 'R') {
        for (int i = 0; i < n; ++i) {
            --ret[idx * n + i];
        }
        ret[idx * n] += n;
    }
    if (s[lef] == 'L') {
        for (int i = 0; i < n; ++i) {
            ++ret[idx * n + i];
        }
        ret[idx * n + n - 1] -= n;
    }
    if (s[lef] == 'D') {
        for (int i = 0; i < n; ++i) {
            ret[i * n + idx] -= n;
        }
        ret[idx] += n * n;
    }
    if (s[lef] == 'U') {
        for (int i = 0; i < n; ++i) {
            ret[i * n + idx] += n;
        }
        ret[(n - 1) * n + idx] -= n * n;
    }
    return ret;
}


int main() {
    cin >> n >> l >> s;
    m = n * n;
    rights.resize(l, -1);
    for (int i = 0; i < l; ++i) {
        if (('0' <= s[i] && s[i] <= '9') || s[i] == ')') continue;
        if (s[i] == '(') {
            int dep = 0;
            for (int j = i; j < l; ++j) {
                if (s[j] == '(') ++dep;
                if (s[j] == ')') --dep;

                if (dep == 0) {
                    for (int k = j + 1; k < l; ++k) {
                        if ('0' > s[k] || '9' < s[k]) {
                            rights[i] = k;
                            goto A;
                        }
                    }
                    rights[i] = l;
                }
            }
        }
        else {
            for (int j = i + 1; j < l; ++j) {
                if ('0' > s[j] || '9' < s[j]) {
                    rights[i] = j;
                    goto A;
                }
            }
            rights[i] = l;
        }
        A:
        continue;
    }
    vector<int> ret = dfs(0, l);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int k = i * n + j;
            if (j < n - 1)
                cout << ret[k] + 1 << " ";
            else
                cout << ret[k] + 1 << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 16188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int n;
    cin >> n;
    vint p(n);
    rep(i, n)
    {
        cin >> p[i];
    }
    int ans = 0;
    rep2(i, 1, n - 1)
    {
        if ((p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i + 1] < p[i] and p[i] < p[i - 1]))
            ans++;
    }
    cout << ans;
    return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
int x, y;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2])
    No();
  else
    Yes();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
int main(void) {
  ll h, a; cin >> h >> a;
  if (h % a == 0) cout << h / a << endl;
  else cout << (h/a)+1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    string s = a + b;
    int tmp = stoi(s);
    rep(i, 10000){
        int k = i * i;
        if(k == tmp){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[55];
	int p=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if(a[i] != i) p++;
	}		
	if(p == 1 || p>2) printf("NO\n");
	else printf("YES\n");
		
	return 0;
}

Measured memory_bytes: 384
from sys import stdin

[N, M] = [int(x) for x in stdin.readline().rstrip().split()]

As = [int(x) for x in stdin.readline().rstrip().split()]


shukudai_sum = sum(As)

if N>=shukudai_sum:
    print(N-shukudai_sum)
else:
    print(-1)



Measured memory_bytes: 9988
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
#define en M_PI*2

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double min = en/60*m;
    double hour = en/720*(60*h+m);
    //cout << cos(min-hour) << endl;
    double c = a*a + b*b - 2*a*b*cos(min-hour);
    //cout << c << endl;
    //cout << pow(c,0.5) << endl;
    cout << fixed << setprecision(12) << pow(c,0.5) << endl;
}

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

int main()
{
  string s;
  cin >> s;
  
  int marbles = 0;
  for (int i = 0; i < s.length(); i++)
  {
    if (s.at(i) == '1') marbles++;
  }
  
  cout << marbles << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

cnt_2 = 0
cnt_4 = 0
for a in A:
  if a % 4 == 0:
    cnt_4 += 1
  elif a % 2 == 0:
    cnt_2 += 1

cnt_1 = N - cnt_2 - cnt_4
    
if cnt_2 == 0 and cnt_1 <= cnt_4 + 1:
  print('Yes')
elif cnt_1 <= cnt_4:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
int main(){
     int a, b, c, k, m, s;
     cin>>a>>b>>c>>k;
    s=a+b+c;
     m=max(a,b);
     m=max(m,c);
     m=m*pow(2,k)+s-m;
    cout<<m;
      return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())
s = s.replace("W","1")
s = s.replace("E","0")
fl = sum(list(map(int,s)))
k = 0
p = 0
for i in range(n):
    if i == 0:
        p = fl - int(s[0])
        k = p
    elif i == n-1:
        p = n-1-fl+int(s[n-1])
        if p > k:
            k = p
    else:
        if (s[i-1] == "1" and s[i] == "1"):
            p -= 1
        elif (s[i-1] == "1" and s[i] == "0"):
            continue
        elif (s[i-1] == "0" and s[i] == "1"):
            continue
        else:
            p += 1
            if p > k:
                k = p
print(n-k-1)

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

int main(){
    int n;
    while(cin >> n, n){
        int mat[100][100] = {};
        bool hand[100][100] = {};

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cin >> mat[i][j];
            }
        }

        for(int i = 0; i < n; i++){
            int minval = 1000000;
            vector<int> minpos;
            for(int j = 0; j < n; j++){
                if(mat[i][j] < minval){
                    minval = mat[i][j];
                    minpos.clear();
                    minpos.push_back(j);
                }else if(mat[i][j] == minval){
                    minpos.push_back(j);
                }
            }
            for(int x : minpos) hand[i][x] = true;
        }

        int ans = 0;
        for(int j = 0; j < n; j++){
            int maxval = -1;
            vector<int> maxpos;
            for(int i = 0; i < n; i++){
                if(mat[i][j] > maxval){
                    maxval = mat[i][j];
                    maxpos.clear();
                    maxpos.push_back(i);
                }else if(mat[i][j] == maxval){
                    maxpos.push_back(i);
                }
            }
            for(int x : maxpos) if(hand[x][j]) ans = maxval;
        }

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


Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#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()

typedef long long lint;

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 B--;
  cout<<A<<" "<<B<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;
int n,m,mat[15][15],cost[15],k;
int rec(int i,vector<int>subs){
	if(i == n)
	{
		vector<int>T(m,0);
		int ans = 0;
		for(auto i : subs){
			ans += cost[i];
			for(int j=0;j<m;j++){
				T[j] += mat[i][j];
			}
		}
		for(int j=0;j<m;j++){
			if(T[j] < k){
				return inf;
			}
		}
		return ans;
	}
	int a1 = rec(i+1,subs);
	subs.pb(i);
	int a2 = rec(i+1,subs);
	subs.pop_back();
	return min(a1,a2);
}
int32_t main(){

	
	FASTIO;
	cin >> n >> m >> k;
	REP(i,0,n){
		cin >> cost[i];
		REP(j,0,m){
			cin >> mat[i][j];
		}
	}
	vi subs;
	int ans = rec(0,subs);
	if(ans == inf){
		cout << "-1\n";
	} 
	else
		cout << ans << endl;
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

Measured memory_bytes: 3712
n,m=map(int,input().split())
if n%2==1:
	for i in range(m):
		print(i+1,n-i-1)
else:
	if m%2==0:
		for i in range(m//2):
			print(1+i,1+m-i)
		for i in range(m//2):
			print(m+2+i,m+2+m-1-i)
	else:
		for i in range(m//2+1):
			print(1+i,1+m-i)
		for i in range(m//2):
			print(m+2+i,m+2+m-1-i)


Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
	int n,m;
	cin>>n>>m;
	int a[m+1],sum=0;
	for(int i=1;i<=m;i++)
	{
	cin>>a[i];
	sum=sum+a[i];
    }
  if(n>=sum)
  cout<<n-sum;
  else
  cout<<-1;
	
	
}

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

using ll = long long;
using namespace std;

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


int main()
{
   int p[33][214514] = {};
  int N, C;
  cin >> N >> C;
  rep(i, N) {
    int s, t, f;
    cin >> s >> t >> f;
    p[f-1][2*s] ++ ;
    p[f-1][2*t + 2] --;
  }

  int ans = 0;
  rep2(i,1, 200050) {
    int count = 0;
    rep(j, C) {
      p[j][i] += p[j][i-1];
      if (p[j][i] )
        count++;
    }
    if (i == 1) 
      ans = count; else 
    ans = max(ans,count);
    
  }

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


Measured memory_bytes: 27904
N = gets.to_i
xx, yy, tt = 0, 0, 0
N.times do
    t, x, y = gets.split.map(&:to_i)
    d = (x - xx).abs + (y - yy).abs
    dt = (t - tt)
    if d > dt
        puts 'No'
        exit
    end
    if d % 2 == dt % 2
        xx, yy, tt = x, y, t
    else
        puts 'No'
        exit
    end
end
puts 'Yes'

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

int N;
char F[301][301],C[301][301];
int counts[301][301] = {{0}}; 

int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> F[i][j];
		}
	}
	int ans = 0;
	for(int k=0;k<N;k++){
		bool judge = true;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				C[i][j] = F[(i+k)%N][j];
			}
		}
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				if(C[i][j] != C[j][i]) judge = false;
			}
		}
		if(judge) ans++;
	}
	cout << N*ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int arr[200010], arr2[200010];
int32_t main()
{


    int n, k;
    cin >> n >> k;

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

    // for(int i=1; i<=n+1; i++)
    // {
    //     cout << arr[i] << " ";
    // }
    // cout << endl;

    arr2[n+1] = n;
    for(int i=n; i>=1; i--)
    {
        arr2[i] = arr2[i+1] + (i-1);
    }

    // for(int i=1; i<=n+1; i++)
    // {
    //     cout << arr2[i] << " ";
    // }
    // cout << endl;

    int mod = 1e9+7;
    int ans = 0;
    for(int i=k; i<=n+1; i++)
    {
        int l = arr[i];
        int r = arr2[n+1-i+1];
        ans += (r - l + 1);
        ans %= mod;
    }

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


Measured memory_bytes: 6716
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000007
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> P;

int main() {

	char pai[52][52];
	int dx[4] = { 0,1,0,-1 };
	int dy[4] = { 1,0,-1,0 };

	int H, W;
	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		for (int k = 0; k < W; k++) {
			cin >> pai[i][k];
		}
	}


	for (int i = 0; i < H; i++) {
		for (int k = 0; k < W; k++) {
			if (pai[i][k] == '#') {
				for (int l = 0; l < 4; l++) {
					if (i + dy[l] >= 0 && i + dy[l] <= H - 1 && k + dx[l] >= 0 && k + dx[l] <= W - 1&& pai[i + dy[l]][k + dx[l]] == '#') { break; }
					if(l==3){
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  ll k;
  cin >> n >> k;
  if ((n - 1)*(n - 2) / 2 < k) {
    cout << "-1" << endl;
    return 0;
  }
  vpll edge;
  FOR(i, 2, n + 1) edge.pb(make_pair(1, i));
  ll cur = (n - 1)*(n - 2) / 2;
  FOR(i, 2, n + 1) {
    FOR(j, i + 1, n + 1) {
      if (cur == k) break;
      edge.pb(make_pair(i, j));
      cur--;
    }
  }
  cout << edge.size() << endl;
  rep(i, edge.size()) cout << edge[i].first << " " << edge[i].second << endl;
  

  return 0;
}

Measured memory_bytes: 512
using System;

namespace ABC117_a
{
    class Program
    {
        static void Main(string[] args)
        {
            double c;
            string[] array = Console.ReadLine().Split(' ');
            double a = double.Parse(array[0]);
            double b = double.Parse(array[1]);
            c = a / b;
            Console.WriteLine(c);
        }
    }
}


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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    ll n,d;
    cin>>n>>d;

    ll ans=0;

    rep(i,n){
        ll x,y;
        cin>>x>>y;

        if(x*x+y*y<=d*d)ans++;

    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3636