akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
座圧して取れるだけ取ればok
*/

bool inf=false;
ll n,m,a[1010],b[1010],c[1010],d[1010],e[1010],f[1010], xs, ys, ans=0;
ll dx[]={0,1,0,-1},dy[]={1,0,-1,0};
ll ar[6010][6010];
V<ll> w,h;
map<ll,ll> w_i,h_i;

int main(void){
	cin>>n>>m;
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	rep(i,m)cin>>d[i]>>e[i]>>f[i];
	rep(i,n){
		w.push_back(a[i]);
		w.push_back(b[i]);
		h.push_back(c[i]);
	}
	rep(i,m){
		w.push_back(d[i]);
		h.push_back(e[i]);
		h.push_back(f[i]);
	}
	h.push_back(-2e9);  // 番兵
	h.push_back(2e9);  //
	w.push_back(-2e9);  //
	w.push_back(2e9);  //
	sort(h.begin(), h.end());
	sort(w.begin(), w.end());
	h.erase(unique(h.begin(), h.end()), h.end());  // 重複削除
	w.erase(unique(w.begin(), w.end()), w.end());  //
	rep(i,h.size()){
		h_i[h[i]]=i;
		if(h[i]<=0){  // 初期位置の計算
			ys=i;
		}
	}
	rep(i,w.size()){
		w_i[w[i]]=i;
		if(w[i]<=0){  //
			xs=i;
		}
	}
	xs=(xs+1)*2;  //
	ys=(ys+1)*2;  //
	rep(i,n){
		ll y = h_i[c[i]]*2+1;
		reg(x,w_i[a[i]]*2+1, w_i[b[i]]*2+1)ar[y][x] = 1;  // 線分を塗る
	}
	rep(i,m){
		ll x = w_i[d[i]]*2+1;
		reg(y,h_i[e[i]]*2+1, h_i[f[i]]*2+1)ar[y][x] = 1;  //
	}
	queue<pair<ll,ll>> q;
	q.push({ys, xs});
	ar[ys][xs] = 2;
	// rep(i,2*h.size()+1){
	// 	rep(j,2*w.size()+1){
	// 		cerr<<ar[i][j];
	// 	}
	// 	cerr<<endl;
	// }
	while(not q.empty()){  // dfsで通る場所を求める
		auto p = q.front();q.pop();
		ll y=p.first, x=p.second;
		if(x==0 || y==0 || x==w.size()*2 || y==h.size()*2){  // 外側に到達したら無限
			inf=true;
			break;
		}
		if(x%2==0 && y%2==0){
			ans += (w[x/2]-w[x/2-1]) * (h[y/2]-h[y/2-1]);
		}
		rep(i,4){
			if(ar[y+dy[i]][x+dx[i]]==0){
				ar[y+dy[i]][x+dx[i]]=3;
				q.push({y+dy[i],x+dx[i]});
			}
		}
	}
	if(inf){
		cout<<"INF"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 285424
N=int(input())
U=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
dp = [[-1 for j in range(400001)] for i in range(N+1)]


def func(i,X,U,dp):
    if i==0:
        if X==0:
            return True
        else:
            return False
    if X<0:
        return False
    
    if dp[i][X] !=-1:
        return dp[i][X]
    
    
    if func(i-1,X,U,dp):
        dp[i][X]=1
        return dp[i][X]
    if (func(i-1,X-U[i-1],U,dp)):
        dp[i][X]=1
        return dp[i][X]
    
    dp[i][X]=0
    return dp[i][X]

for i in range(M):
    if func(N,T[i],U,dp)==True:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 71408
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>

using namespace std;

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

	int n;
	cin >> n;

	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
	}
	vector<int> maxn(4, INT_MIN);
	vector<int> minn(4, INT_MAX);
	for (int i = 0; i < n; ++i) {
		int k = 0;
		for (int dx = -1; dx <= 1; ++dx) {
			for (int dy = -1; dy <= 1; ++dy) {
				if (dx != 0 && dy != 0) {
					maxn[k] = max(maxn[k], x[i] * dx + y[i] * dy);
					minn[k] = min(minn[k], x[i] * dx + y[i] * dy);
					++k;
				}
			}
		}
	}
	int best = 0;
	for (int i = 0; i < 4; ++i) {
		best = max(best, maxn[i] - minn[i]);
	}
	cout << best << endl;

	return 0;
}


Measured memory_bytes: 4460
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define repb(i, a, n) for (int i = (a); i >= (n); i--)
#define all(x) x.begin(), x.end()
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
/******* Variable ***************************************************/
const int maxn = 1e6 * 50;
const double inf = 0x3f3f3f3f3f;
int N;
vector<int> A, G;
ll cnt = 0;
/******* Function ***************************************************/
void OutIndent(const vector<int> &X) {
    rep(i, 0, X.size() - 1) {
        co(X[i]);
    }
}
void OutSpace(const vector<int> &X) {
    rep(i, 0, X.size() - 2) {
        cosp(X[i]);
    }
    cout << X.back() << endl;
}
/*********************************************************************/
stack<int> pila;
int operacion(string ss) {
    int a, b;
    a = pila.top();
    pila.pop();
    b = pila.top();
    pila.pop();
    if (ss == "+")
        return a + b;
    if (ss == "-")
        return b - a;
    if (ss == "*")
        return a * b;
}
/******* Main *****************************************************/
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    while (cin >> s) {
        if (s == "+" || s == "-" || s == "*") {
            pila.push(operacion(s));
        } else {
            pila.push(atoi(s.c_str()));
        }
    }
    cout << pila.top() << "\n";
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        vector<vector<ll>>A(3,vector<ll>(3));
        rep(i,3){
            rep(j,3){
                cin >> A[i][j];
            }
        }
        ll f=0;
        vector<vector<ll>>v(3,vector<ll>(3));
        ll n; cin >> n;
        vll bb(n);
        rep(i,n){
            cin >> bb[i];
            rep(a,3){
                rep(b,3){
                    if(A[a][b]==bb[i]){
                        v[a][b]=1;
                    }
                }
            }
        }
        //     rep(i,3){
        //     rep(j,3){
        //         cout << v[i][j] <<  " ";
        //     }
        //     cout << endl;
        // }

         f=0;
        if((v[0][0]==1 and v[1][1]==1 and v[2][2]==1) or (v[0][2]==1 and v[1][1]==1 and v[2][0]==1) ){
            f=1;
        }else {
            rep(i,3){
                if(v[i][0]==1 and v[i][1]==1 and v[i][2]==1){
                f=1; break;
                }else if(v[0][i]==1 and v[1][i]==1 and v[2][i]==1){
                    f=1;break;
                }
            }
        }
        if(!f){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    sort(a, a + n, greater<ll>());
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = a[0];
    n -= 2;
    int p = 0;
    while (n) {
        p++;
        ans += a[p];
        n--;
        if (n == 0) break;
        ans += a[p];
        n--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << std::fixed << std::setprecision(10) << (W * H) / 2 << " ";
    if(2 * x == W && 2 * y == H) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }
    return 0;
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define max2(a,b) ((a<b)?b:a)
#define max3(a,b,c) max2(max2(a,b),c)
#define min2(a,b) ((a>b)?b:a)
#define min3(a,b,c) min2(min2(a,b),c)
#define forn(i,val,n) for(int i = val; i < n ; i++)
#define foe(i,val,n)  for(int i = val; i <= n ; i++)
#define rfor(i,val,n) for(int i = val; i >= n ; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
 

void solve(){
 
    ll k,x,y;
    cin>> k >> x >> y;
    foe(i,x,y)
    if(i%k==0)  { cout<<"OK"; exit(0);}
    
    cout<<"NG";
    
 

}
 
int main(){
    SPEED;
 
    ll t=1; 
    while(t--) solve();
 
    return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		String[] str = { "JOI", "IOI" };
		while (scanner.hasNext()) {
			String line = scanner.next();
			for (String s : str) {
				int p = 0;
				int ans = 0;
				while (true) {
					p = line.indexOf(s, p);
					if (p == -1)
						break;
					ans++;
					p += 2;
				}
				System.out.println(ans);
			}
		}
	}
}

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

   long long N, M;

   while (cin >> N >> M) {

      if(N == 1 && M == 1){
         cout << 1 << endl;
      }
      else if(N == 1 || M == 1){
         cout << N + M  - 3 << endl;
      }
      else{
         cout << (N - 2) * (M - 2) << endl;
      }


   }

   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int i=0, A[100];
  char stack[100];

  while(scanf("%s",stack)!=EOF){
    if(stack[0]=='+'){
      A[i-2]=A[i-2]+A[i-1];
      i--;
    }
    else if(stack[0]=='-'){
      A[i-2]=A[i-2]-A[i-1];
      i--;
    }
    else if(stack[0]=='*'){
      A[i-2]=A[i-2]*A[i-1];
      i--;
    }
    else{
      A[i]=atoi(stack);
      i++;
    }
  }
  printf("%d\n",A[i-1]);
  return 0;
}

Measured memory_bytes: 548
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    
    let (n,x) = {
        let mut input = String::new();
        stdin.read_line(&mut input).unwrap();
        let mut input = input.split_whitespace();
        
        (
            input.next().unwrap().parse::<usize>().unwrap(),
            input.next().unwrap().parse::<i32>().unwrap(),
        )
    };

    
    let mut input = String::new();
    stdin.read_line(&mut input).unwrap();
    let input = input.trim().split_whitespace();

    let mut d: i32 = 0;
    let mut counter: usize = 1;

    for l in input.take(n).map(|s| s.parse::<i32>().unwrap()) {
        d += l;
        
        if d > x { break; }

        counter += 1;
    }
    
    println!("{}", counter);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  ll N, M;
  ll result;
  cin >> N >> M;
  if (N * 2 <= M) {
    result = N;
    result = result + (M - 2 * N) / 4;
  } else {
    result = M / 2;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
import std.range;
void main() {
        string s;
        while( (s=readln().strip()).length != 0 ){
                auto input = s.split(',').map!(to!int)().array();
                double c = input.take(10).sum()*1.0/(input[10]+input[11])*input[10];
                int a=0;
                for(int i=0;i<10;i++){
                        a+=input[i];
                        if(a>=c){writeln(i+1);break;}
                }
        }
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

int n;
int mp[111];

void out(){
	REV(i, n)cout << mp[i] << endl;
	exit(0);
}

void dfs(vector<int> &v, int dep) {
	if(v.size() == 0){
		out();
	}
	REV(i, v.size()){
		if(v[i] == i + 1){
			mp[dep] = i + 1;
			auto tmp = v;
			tmp.erase(tmp.begin() + i);
			dfs(tmp, dep + 1);
		}
		if(v[i] > i + 1)return;
	}
}

int main(){

	cin >> n;
	vector<int> v(n);
	REP(i, n)cin >> v[i];

	dfs(v, 0);
	cout << -1 << endl;

	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	double n;
	cin >> n;
	vector<double> x(n); vector<double> y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	double whole = 1;
	rep(i, n) {
		whole *= i + 1;
	}
	double keiro = 0;
	rep(i, n) {
		keiro += i;
	}
	double res = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			double k = (double)sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			res += k;
		}
	}
	/*if (n == 2) {
		res *= double(n);
	}
	else {
		res *= double(n + 1);
	}*/
	res *= (double)(whole * (n - 1) / keiro);
	//cout << res << endl;
	double ans = res / whole;
	cout << fixed << setprecision(9) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] num = new int[100001];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt() - 1;
		}
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (a[a[i]] == i) {
				ans++;
			}
		}
		System.out.println(ans / 2);
	}
}


Measured memory_bytes: 33004
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long X, Y;
    scan(X, Y);
    long ans;
    while (X <= Y)
        ans++, X += X;
    writeln(ans);
}


Measured memory_bytes: 3668
#include<stdio.h>
#include<stdlib.h>
#define MAX 199
void initalize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);
int S[MAX];
int top;
int main(){
  int y1,y2;
  char x[100];
  while( scanf("%s", x) != EOF ){
    if ( x[0] == '+' ){
      y1=pop();
      y2=pop();
      push(y1+y2);
      
    } else if ( x[0] == '-' ){
      y2=pop();
      y1=pop();
      push(y1-y2);
      
    } else if ( x[0] == '*' ){
      y1=pop();
      y2=pop();
      push(y1*y2);
      
    } else {
      y1 = atoi(x);
      push(y1);
    }
  }
    printf("%d\n",pop());
    return 0;
    
  
}

void intialize(void){
  top = 0;
}

int isEmpty(){
  if(top==0)return 0;
  else return 1;
}

int isFull(){
  if(top>=MAX-1)return 1;
  else return 0;
}

void push(int x){
  if(isFull()==1){
    fprintf(stderr,"??¨??????????????????????????????)\n");
    exit(8);
  }
  top++;
  S[top] = x;
}

int pop(void){   
  if(isEmpty()==0){
    fprintf(stderr,"??¨???????????¢?????????????????????\n");
    exit(8);
  }
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
package main

import "fmt"

func main() {
	var Q, H, S, D, N int
	fmt.Scan(&Q, &H, &S, &D, &N)
	H = Min(H, 2*Q)
	S = Min(S, 2*H)
	D = Min(D, 2*S)
	fmt.Println(N/2*D + N%2*S)
}

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


Measured memory_bytes: 1772
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

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

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

	cin >> N >> M;
	if (N % 500 <= M) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
table = [0] * (m+1)

for i in range(n):
    k, *args = map(int, input().split())
    for j in args:
        table[j] += 1

cnt = 0
for t in table:
    if t == n:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int main() {
  int n, t[86400 + 1];
  while (cin >> n, n) {
    memset(t, 0, sizeof(t));
    int H1, H2, M1, M2, S1, S2;
    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d %d:%d:%d", &H1, &M1, &S1, &H2, &M2, &S2);
      t[H1 * 3600 + M1 * 60 + S1]++;
      t[H2 * 3600 + M2 * 60 + S2]--;
    }
    int ans = 0;
    for (int i = 1; i <= 86400; i++)
      t[i] += t[i - 1];
    cout << *max_element(t, t + 86400) << endl;
  }
  return 0;
}

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

int main() {
  
  string N;
  cin>>N;
  if(N[0]==N[1]&&N[1]==N[2]||N[1]==N[2]&&N[3]==N[2]){
    printf("Yes");
  }else{printf("No");}
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    char s; cin >> s;
    if(s=='a' || s=='e' || s=='i'||s=='o'||s=='u') cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  if d[t]*d[u]==1:d[s]=0
  if d[u]*d[s]==1:d[t]=0
  if d[s]*d[t]==1:d[u]=0
 for x in d[1:]:print(x)


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      cin >> a[i][j];
    }
  }

  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  string ans = "Yes";
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      if (a[i][j] != '#') continue;

      int flag = 0;
      for (int k = 0; k < 4; k ++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ni >= 0 && nj >= 0 && ni < h && nj < w && a[ni][nj] == '#') flag = 1;
      }
      if (!flag) ans = "No";
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//遅延伝搬なし、方を指定できるセグ木
template<typename Monoid>
struct SegmentTree {
    vector<Monoid> data;
    LL n;
    const function<Monoid(Monoid, Monoid)> f;
    const Monoid M;
    //std::functionを使うと関数やラムダ式を格納できる
    SegmentTree(LL x, const function<Monoid(Monoid, Monoid)> f, const Monoid &M) : f(f), M(M) {
        n = 1;
        while(n<x) n <<= 1;
        data.resize(2*n,M);
    }
    void set(LL k, const Monoid &p) {
        data[k+n] = p;
    }
    void build() {
        for(int k = n-1; k > 0; --k) {
            data[k] = f(data[2*k + 0], data[2*k + 1]);
        }
    }
    void update(LL k, const Monoid &p) {
        k += n;
        data[k] = p;
        while (k >>= 1) {
            data[k] = f(data[k*2], data[k*2 + 1]);
        }
    }
    Monoid query(LL a,LL b) {
        Monoid L = M, R = M;
        for(a += n, b += n; a<b; a >>= 1, b >>= 1) {
            if(a&1) L = f(L, data[a++]);
            if(b&1) R = f(data[--b], R);
        }
        return f(L,R);
    }
    Monoid operator[](const LL &k) const {
        return data[k+n];
    }
};

LL N,K;
LL P[200000];

LL ans = 1;

void solve(){
    SegmentTree<LL> segmin(N,[](LL a,LL b){return min(a,b);},INF);
    SegmentTree<LL> segmax(N,[](LL a,LL b){return max(a,b);},-INF);
    for(int i=0;i<N;i++){
        segmin.update(i,P[i]);
        segmax.update(i,P[i]);
    }
    vector<LL> accum(N);
    for(int i=0;i<=N-2;i++){
        accum[i+1] = accum[i] + (P[i]>P[i+1]);
    }
    bool flag = (accum[K-1]-accum[0]>0);
    for(int i=0;i<N-K;i++){
        int x = segmin.query(i,i+K+1);
        int y = segmax.query(i,i+K+1);
        if((flag || accum[i+K]-accum[i+1]>0) && (P[i]!=x || P[i+K]!=y)) {
            if(accum[i+K]-accum[i+1]==0) flag = false;
            ans++;
        }
    }
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> P[i];

    solve();

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

Measured memory_bytes: 14184
N = int (input())
W = list(map(int, input().split()))
w = 0
for i in range(N - 1):
    w += W[i]
    if w > sum(W) / 2:
        break
print(min(abs(sum(W[0: i]) - sum(W[i: N])), abs(sum(W[0: i + 1]) - sum(W[i + 1: N]))))

Measured memory_bytes: 9148
class Dice
  def initialize(*lbl)
    @lbl = lbl
  end

  def W
    Dice.new(*[2,1,5,0,4,3].map{|x| @lbl[x]})
  end
  def E
    Dice.new(*[3,1,0,5,4,2].map{|x| @lbl[x]})
  end
  def N
    Dice.new(*[1,5,2,3,0,4].map{|x| @lbl[x]})
  end
  def S
    Dice.new(*[4,0,2,3,5,1].map{|x| @lbl[x]})
  end

  [:top, :front, :right, :left, :back, :bottom].each_with_index do |x,i|
    define_method(x){ @lbl[i] }
  end
end

dice = Dice.new(*gets.split)
gets.chomp.chars do |c|
  eval "dice = dice.#{c}"
end

puts dice.top

Measured memory_bytes: 8812
import heapq
import sys
input = sys.stdin.readline

INF = 10**20
A = 50  # max A


def inpl():
    return list(map(int, input().split()))


def main():
    N, M, S = inpl()
    S = min(S, M * A)

    lines = [[] for _ in range(N * (M * A + 1))]
    for _ in range(M):
        in_s, in_t, cost, time = inpl()
        in_s -= 1
        in_t -= 1

        for n in range(cost, M * A + 1):
            s = in_s + n * N
            t = in_t + (n - cost) * N
            lines[s].append((t, time))

            s = in_s + (n - cost) * N
            t = in_t + n * N
            lines[t].append((s, time))

    for i in range(N):
        cost, time = inpl()
        for n in range(0, M * A + 1):
            s = i + n * N
            if n + cost > M * A:
                t = i + (M * A) * N
            else:
                t = i + (n + cost) * N
            lines[s].append((t, time))

    def dijkstra(N, S):
        weight = [INF] * N
        weight[S] = 0
        q = [[0, S]]
        heapq.heapify(q)
        while q:
            w0, s = heapq.heappop(q)
            for t, w in lines[s]:
                w += w0
                if weight[t] > w:
                    heapq.heappush(q, [w, t])
                    weight[t] = w

        return weight

    weight = dijkstra(N * (M * A + 1), 0 + S * N)

    ansl = [INF] * N
    for i, w in enumerate(weight):
        n = i % N
        if n == 0:
            continue
        else:
            ansl[n] = min(w, ansl[n])

    print("\n".join(map(str, ansl[1:])))


if __name__ == "__main__":
    main()


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

// Union-Find Tree
struct UnionFind {
  vector<int> par, sz;
  
  UnionFind(int n): par(n), sz(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  
  void init(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  
  // 根の検索
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  
  // xとyの属する集合を併合
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    par[x] = y;
    sz[y] += sz[x];
    return true;
  }
  
  // xとyが同じ集合に属するか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  
  int tree_size(int x) {
    return (sz[par[x]]);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, uf.tree_size(i));
  
  cout << ans << '\n';
}

Measured memory_bytes: 4788
def gcd(x, y):
  if x < y:
    a = y
    y = x
    x = a
  
  while y > 0:
    r = x % y
    x = y
    y = r
  
  return x

def main():
  N = int(input())
  a = list(map(int, input().split()))
  r = a[0]
  
  for i in range(1, len(a)):
    r = gcd(r, a[i])
    if r == 1:
      break

  print(r)
    

if __name__ == '__main__':
  main()

Measured memory_bytes: 14252
n = int(input())
rh_list = list(input())
#Rの個数
r_n = rh_list.count('R')
#Rの個数までのlist
R_list=[]
for i in range(r_n):
  R_list.append(rh_list[i])
#listのｒ個数
R_r_n = R_list.count('R')
print(r_n-R_r_n)

Measured memory_bytes: 12244
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll n,m,ny[1100000],jc[1100000];
ll c(ll n,ll m)
{
    return (ll)jc[n]*ny[m]%mod*ny[n-m]%mod;
}
 
int main()
{
    cin>>n>>m;
    if(n<=m)swap(n,m);
    jc[0]=jc[1]=ny[0]=ny[1]=1;
    for(int i=2;i<=n+m;i++)jc[i]=(ll)jc[i-1]*i%mod,ny[i]=(ll)(mod-mod/i)*ny[mod%i]%mod;
    for(int i=2;i<=n+m;i++)ny[i]=(ll)ny[i-1]*ny[i]%mod;
    ll ans=0;
    for(int i=1;i<=m;i++)
    {
        ans+=(ll)c(n+m-i*2,n-i)%mod*c(i*2,i)%mod;
        ans%=mod;
    }
    ans=(ll)ans*ny[n+m]%mod*jc[n]%mod*jc[m]%mod*ny[2]%mod;
    ans+=n;
    ans%=mod;
     
    cout<<ans<<endl;
}


Measured memory_bytes: 16640
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    s = input()
    s = s + 'g'

    happiness = 0

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            happiness += 1

    ans = []
    last_one = s[0]
    tmp = []

    for s in s:
        if s != last_one:
            ans.append(tmp)
            tmp = []

        tmp.append(s)
        last_one = s

    if len(ans) - 1 > k * 2:
        print(happiness + (k * 2))
    else:
        print(happiness + len(ans) - 1)


if __name__ == '__main__':
    main()

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

int main()
{
	int n;
	int a[10][65];
	long q;
	unsigned long long t = 0;

	cin >> n;

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

		for (int j = 1; j <= k; j++)
			cin >> a[i][j];
	}

	cin >> q;

	for (long i = 0; i < q; i++) {
		int j, m, s = 0;
		bool f;
		cin >> j >> m;
		switch (j) {
		case 0:
			cout << (t >> m) % 2 << endl;
			break;
		case 1:
			for(int u = 1; u <= a[m][0]; u++)
				t = t | (1ull << a[m][u]);
			break;
		case 2:
			for (int u = 1; u <= a[m][0]; u++)
				t = (t | (1ull << a[m][u])) - (1ull << a[m][u]);
			break;
		case 3:
			for (int u = 1; u <= a[m][0]; u++)
				t = (t | (1ull << a[m][u])) - (t & (1ull << a[m][u]));
			break;
		case 4:
			f = 1;
			for (int u = 1; u <= a[m][0]; u++) {
				if (!(t & (1ull << a[m][u]))) {
					f = 0;
					break;
				}
			}
			cout << f << endl;
			break;
		case 5:
			f = 0;
			for (int u = 1; u <= a[m][0]; u++) {
				if ((t & (1ull << a[m][u]))) {
					f = 1;
					break;
				}
			}
			cout << f << endl;
			break;
		case 6:
			f = 1;
			for (int u = 1; u <= a[m][0]; u++) {
				if ((t & (1ull << a[m][u]))) {
					f = 0;
					break;
				}
			}
			cout << f << endl;
			break;

		case 7:
			for (int u = 1; u <= a[m][0]; u++) {
				if (t & (1ull << a[m][u]))
					s++;
			}

			cout << s << endl;
			break;

		case 8:
			unsigned long long v = 0;

			for (int u = 1; u <= a[m][0]; u++) {
				if (t & (1ull << a[m][u]))
					v += 1ull << a[m][u];
			}
			cout << v << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3140
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	n := len(s)
	if n == 2 {
		fmt.Fprintln(writer, s)
		return
	}
	for i := n - 1; i >= 0; i-- {
		fmt.Fprintf(writer, "%c", s[i])
	}
	fmt.Fprintln(writer, "")
}


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

int main()
{
    string s,t;
    cin >> s >> t;
    int cnts = 0;
    int cntt = 0;
    for(int i = 0;i < s.size()+t.size(); i++){
        if(i % 2 == 0){
            cout << s[cnts];
            cnts++;
        }else{
            cout << t[cntt];
            cntt++;
        }
    }
}


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

int main(){
  string s, t = "CODEFESTIVAL2016";
  cin >> s;
  int ans = 0;
  for(int i = 0 ; i < 16 ; i++){
    if(s[i] != t[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input().split()
for i in range(n+1):
    a[i]=int(a[i])
b=input().split()
for i in range(n):
    b[i]=int(b[i])
c=0
for i in range(n):
    if a[i]<=b[i]:
        c+=a[i]
        b[i]-=a[i]
        a[i]=0
        if a[i+1]<=b[i]:
            c+=a[i+1]
            a[i+1]=0
        else:
            c+=b[i]
            a[i+1]-=b[i]
    else:
        c+=b[i]
print(c)

Measured memory_bytes: 15424
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
using namespace std;

const int lim=100005;

ll t[lim];

int n,w,a;

ll b,wyn;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>w;
	
	for(int i=1;i<=w;i++) t[i]=-1;
	
	while(n--){
		cin>>a>>b;
		for(int i=w;i>=a;i--){
			if(t[i-a]!=-1 && t[i]<t[i-a]+b) {
				t[i]=t[i-a]+b;
				wyn=max(wyn,t[i]);
			}
		}
	}	
	cout<<wyn;
	return 0;
}

Measured memory_bytes: 1024
// AtCoder Beginner Contest 064
// D - Insertion

#include <iostream>

using namespace std;
typedef long long int ll;


int N;
string S;
int depth;

int main() {

    cin >> N;
    cin >> S;

    depth = 0;
    for (char &c : S) {
        if (c == '(') {
            depth++;
        } else {
            if (depth == 0) {
                cout << '(';
            } else {
                depth--;
            }
        }
    }
    cout << S;
    for (int i = 0; i < depth; i++) {
        cout << ')';
    }
    cout << endl;

    return 0;

}





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

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

		for(int i=1;i<=3000;i++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			if(x==0 && y==0) {
				break;
			}else if(x<y){
				System.out.println(x+" "+y);
			}else {
				System.out.println(y+" "+x);
			}
		}


	}

}



Measured memory_bytes: 36528
#include<bits/stdc++.h>
  using namespace std;
vector<int>dp[200005];
int total=0;
void dfs(int index,int par,int col)
{
  total+=col;
  for(auto it:dp[index])
  {
    if(it!=par)
      dfs(it,index,col^1);
  }


}
  

  int main()
  {


       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
    /*  #ifndef ONLINE_JUDGE
          freopen("input.txt","r",stdin);
          freopen("output.txt","w",stdout);
      #endif
*/

    int t;
    cin>>t;
    int first=0,second=0,third=0,fourth=0;
    for(int i=0;i<t;i++)
    {
      string nish;
      cin>>nish;
      if(nish=="AC")
       {
        first++;
       } 

      else if(nish=="TLE")
      {
        second++;
      } 
      else if(nish=="WA")
      { 
        third++;
      } 
      else if(nish=="RE")
      {
        fourth++;
      }
    }



    cout<<"AC x "<<first<<endl;
    cout<<"WA x "<<third<<endl;
    cout<<"TLE x "<<second<<endl;
    cout<<"RE x "<<fourth<<endl;


    return 0;

  }

Measured memory_bytes: 8340
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
ABsorted = sorted(AB, key=lambda x: x[1])

previous = -1
total = 0
for ab in ABsorted:
  if ab[0] <= previous and previous <= ab[1]-1:
    pass
  else:
    total += 1
    previous = ab[1]-1
print(total)

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

struct Dice{
	int num[6];
	void roll(char c){
		char tmp;
		if(c == 'N'){
			tmp = num[4];
			num[4] = num[0];
			num[0] = num[1];
			num[1] = num[5];
			num[5] = tmp;
		}
		else if(c == 'E'){
			tmp = num[2];
			num[2] = num[0];
			num[0] = num[3];
			num[3] = num[5];
			num[5] = tmp;
		}
		else if(c == 'S'){
			tmp = num[1];
			num[1] = num[0];
			num[0] = num[4];
			num[4] = num[5];
			num[5] = tmp;
		}
		else if(c == 'W'){
			tmp = num[3];
			num[3] = num[0];
			num[0] = num[2];
			num[2] = num[5];
			num[5] = tmp;
		}
	}
	void match1(int n){
		int i = 0;
		while(num[i] != n){
			i++;
		}
		switch(i){
			case 0: break;
			case 1: roll('N'); break;
			case 2: roll('W'); break;
			case 3: roll('E'); break;
			case 4: roll('S'); break;
			case 5: roll('S'); roll('S'); break;
		}
	}
	void match2(int n){
		int i = 0;
		while(num[i] != n){
			i++;
		}
		switch(i){
			case 1: break;
			case 2: roll('W'); roll('S'); roll('E'); break;
			case 3: roll('E'); roll('S'); roll('W'); break;
			case 4: roll('W'); roll('S'); roll('E'); roll('W'); roll('S'); roll('E'); break;
		}
	}
};

int main(){
	Dice d1, d2;
	string s;
	for(int i = 0; i < 6; i++){
		cin >> d1.num[i];
	}
	for(int i = 0; i < 6; i++){
		cin >> d2.num[i];
	}
	int same = -1;
	for(int i = 0; i < 5; i++){
		for(int j = i+1; j <= 6; j++){
			if(d1.num[i] == d1.num[j]){
				same = d1.num[i];
				break;
			}
		}
		if(same != -1)
			break;
	}
	if(same != -1){
		for(int i = 0 ; i < 6; i++){
			if(d1.num[i] != same){
				d1.match1(d1.num[i]);
				break;
			}
		}
	}
	for(int i = 0; i < 6; i++){
		if(d2.num[i] == d1.num[0]){
			d2.match1(d1.num[0]);
			break;
		}
	}
	for(int i = 0; i < 6; i++){
		if(d2.num[i] == d1.num[1]){
			d2.match2(d1.num[1]);
			break;
		}
	}
	for(int i = 0; i < 6; i++){
		if(d2.num[i] != d1.num[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3104
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n,k = inp
t = inp
rw  =na(n+1,0)
now = 0
ans = 0
h = Hash.new(0)
h[0] += 1
(1..n).each do |i|
  now += t[i-1]
  now %= k
  rw[i] = (now-i)%k
  if(i-k >= 0)
    h[rw[i-k]] -= 1
  end
  ans += h[(now-i)%k]

  h[rw[i]] += 1

end

p ans



Measured memory_bytes: 32436
open Big_int

let () =
    let main () =
        let h, w = Scanf.scanf "%d %d" (fun h w -> h, w) in
        let a = Array.init h (fun _ -> Array.init w (fun _ -> Scanf.scanf " %d" (fun n -> n))) in
        let b = Array.init h (fun _ -> Array.init w (fun _ -> Scanf.scanf " %d" (fun n -> n))) in
        let m = (h + w) * 80 in
        let ar = Array.make_matrix h w zero_big_int in
        let init = shift_left_big_int unit_big_int m in
        ar.(0).(0) <- shift_left_big_int unit_big_int m;
        for y = 0 to h - 1 do
            for x = 0 to w - 1 do
                let aa = abs(a.(y).(x) - b.(y).(x)) in
                if y > 0 then ar.(y).(x) <- or_big_int ar.(y).(x) ar.(y - 1).(x);
                if x > 0 then ar.(y).(x) <- or_big_int ar.(y).(x) ar.(y).(x - 1);
                ar.(y).(x) <- or_big_int (shift_left_big_int ar.(y).(x) aa) (shift_right_big_int ar.(y).(x) aa)
            done
        done;
        let rec loop i x y =
            if eq_big_int (and_big_int ar.(h - 1).(w - 1) x) zero_big_int &&
               eq_big_int (and_big_int ar.(h - 1).(w - 1) y) zero_big_int then
                   loop (i + 1) (shift_left_big_int x 1) (shift_right_big_int y 1)
            else i
        in
        let s = loop 0 init init in
        Printf.printf "%d\n" s
    in
    main ()

Measured memory_bytes: 32800
import java.util.*;

class Main {

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

    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    int total = 0;

    int[][] cells = new int[h][w];
    for (int y = 0; y < h; y++) {
      String row = sc.next();
      for (int x = 0; x < w; x++) {
        String c = row.substring(x, x + 1);
        cells[y][x] = c.equals("#") ? 1 : 0;
        total += cells[y][x];
      }
    }
    sc.close();

    if (k > total) {
      System.out.println(0);
      return;
    }

    int h2 = 1 << h;
    int w2 = 1 << w;

    int ans = 0;
    for (int y = 0; y < h2; y++) {
      for (int x = 0; x < w2; x++) {
        int count = 0;
        for (int y2 = 0; y2 < h; y2++) {
          if (((1 << y2) & y) == 0) continue;

          for (int x2 = 0; x2 < w; x2++) {
            if (((1 << x2) & x) == 0) continue;

            count += cells[y2][x2];
          }
        }
        if (count == k) {
          ans++;
        }

      }

    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35676
#include<stdio.h>

int SelectionSort(int *A,int length) {

  int i, j, tmp, cnt=0, mini;

  for(i = 0; i < length; i++) {
    mini = i;
    for(j = i; j < length; j++) {
      if(A[j] < A[mini]) {
	mini = j;
      }
    }
    if(i != mini) {
    tmp = A[i];
    A[i]  = A[mini];
    A[mini] = tmp;
    cnt++;
    }
  }
  return cnt;
}


main()
{
  int i;
  int n;
  int Arr[100];
  int cnt = 0;

  scanf("%d", &n);

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

  cnt = SelectionSort(Arr,n);

  /* スペースをいれない方法！ */
  printf("%d", Arr[0]);

  for(i = 1; i < n; i++) {
    printf(" %d" ,Arr[i]);
  }

  printf("\n%d\n", cnt);

  return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ok = 200000000000000ll, ng = 0;
  while(abs(ok-ng) > 1) {
    ll mid = (ok+ng) / 2;
    ll count = 0;
    rep(i, n) {
      count += a[i]/mid;
      if(a[i]%mid == 0) --count;
    }
    if(count <= k) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = LLONG_MAX;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c/b;
	if(c%b) x++;
	int y = a/d;
	if(a%d) y++;
	if(y >= x) cout << 	"Yes";
	else cout << "No";
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e5 + 5 ;
int n , k ;
ll sum[maxn] ;
map <int , int> cnt ; 
int main()
{
	scanf("%d%d" , &n , &k) ;
	for(int i = 1 ; i <= n ; i ++)
	{
	   ll x ;
	   scanf("%lld" , &x) ;
	   sum[i] = (sum[i - 1] + x) % k ;	
	} 
	for(int i = 1 ; i <= n ; i ++)
	{
	   sum[i] = (sum[i] - i + k) % k ;
	   sum[i] = (sum[i] + k) % k ;
	} 
	for(int i = 0 ; i <= min(n , k - 1) ; i ++)
	   cnt[sum[i]] ++ ;
	ll ans = 0 ;
	for(int i = 0 ; i <= n ; i ++)
	{
		cnt[sum[i]] -- ;
		ans += cnt[sum[i]] ;
		if(i + k <= n) cnt[sum[i + k]] ++ ;
    }
    printf("%lld\n" , ans) ; 
}

Measured memory_bytes: 11136