akhauriyash/Code-Regression huggingface dataset:
def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    a = []
    c = []
    INF = 1e7
    ans = INF
    for i in range(n):
        ca.append(list(map(int, input().split(" "))))
    for i in range(n):
        c.append(ca[i][0])
        a.append(ca[i][1:])
    for i in range(1<<n):
        a_sum = [0]*m
        c_sum = 0
        for j in range(n):
            if i >> j & 1 == 1:
                for k in range(m):
                    a_sum[k] += a[j][k]
                c_sum += c[j]
        if min(a_sum) >= x and c_sum < ans:
            ans = c_sum
    if ans == INF:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

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

sum_A = sum(A)
plus_A_sum = 0
minus_num = 0
Abs = []
for i in range(N):
  if(A[i] < 0): 
    minus_num += 1
    plus_A_sum += (-A[i])
  else:
    plus_A_sum += A[i]
  Abs.append(abs(A[i]))
  
if(minus_num%2 == 0):
  ans = plus_A_sum
else:
  Abs.sort()
  tmp = Abs[0]
  plus_A_sum = plus_A_sum-2*tmp
  ans = plus_A_sum
print(ans)

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

int L[4][5] = {
	{1,4,7,10,16},
	{3,6,9,12,13},
	{1,2,3,15,19},
	{7,8,9,10,13}
};

int R[4][5] = {
	{24,27,30,21,18},
	{22,25,28,19,15},
	{28,29,30,16,21},
	{22,23,24,12,18}
};

struct Cube {
	int cube[31], s;
	
	Cube() {}
	
	void rot(int t) {
		for(int i=0;i<5;++i) swap(cube[L[t][i]], cube[R[t][i]]);
	}
	
	bool fail(int a, int b) {
		for(int i=a+1;i<=b;++i) if (cube[a] != cube[i]) return 1;
		return 0;
	}
	
	bool solved() {
		if (fail(1,9)) return 0;
		if (fail(10,12)) return 0;
		if (fail(13,15)) return 0;
		if (fail(16,18)) return 0;
		if (fail(19,21)) return 0;
		if (fail(22,30)) return 0;
		return 1;
	}
};

int main() {
	int N;
	cin >> N;
	
	for(int i=0;i<N;++i) {
		Cube ini;
		for(int i=1;i<=30;++i) cin >> ini.cube[i];
		ini.s = 0;
		
		queue< Cube > q;
		q.push(ini);
		
		while (!q.empty()) {
			Cube c = q.front(); q.pop();
			
			if (c.solved()) {
				cout << c.s << endl;
				break;
			}
			
			++c.s;
			
			for(int i=0;i<4;++i) {
				c.rot(i);
				q.push(c);
				c.rot(i);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 12164
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<Int> P(a), Q(b), R(c);
    for (int i = 0; i < a; i++) {
        cin >> P[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> Q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> R[i];
    }
    sort(P.begin(), P.end(), greater<Int>());
    sort(Q.begin(), Q.end(), greater<Int>());
    sort(R.begin(), R.end(), greater<Int>());

    vector<Int> S;
    for (int i = 0; i < x; i++) {
        S.push_back(P[i]);
    }
    for (int i = 0; i < y; i++) {
        S.push_back(Q[i]);
    }
    for (int i = 0; i < c; i++) {
        S.push_back(R[i]);
    }
    sort(S.begin(), S.end(), greater<Int>());

    Int ans = 0;
    for (int i = 0; i < x + y; i++) {
        ans += S[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8688
import itertools
def addLunLun(str_num):
    last_digit = int(str_num[len(str_num)-1:])
    if last_digit == 0:
        return [str_num+"0",str_num+"1"]
    elif last_digit == 9:
        return [str_num+"8",str_num+"9"]
    else:
        return [str_num + str(last_digit-1),str_num + str(last_digit),str_num + str(last_digit+1)]
    
digits1 = [str(i) for i in range(1,10)]
digits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))
digits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))
digits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))
digits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))
digits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))
digits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))
digits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))
digits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))
digits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))
index = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10
K = int(input())
print(index[K-1])

Measured memory_bytes: 23140
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
using namespace std;
ll mod = 1e9 + 7;

int main(){

  string S; cin >> S;
  int ans = 0;
  int first = 0, second = S.size() - 1;
  while(first < second){
    if(S[first] != S[second])ans++;
    first++; second--;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Maybe as Maybe

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

-- ----------

rotn :: Int -> String -> String
rotn n s = map (Char.chr . (+ Char.ord 'A') . (`mod` 26) . (+ n)  . flip (-) (Char.ord 'A') . Char.ord) s

main :: IO ()
main = do
	n <- readLn
	s <- getLine
	putStrLn $ rotn n s


Measured memory_bytes: 1404
# -*- coding: utf-8 -*-

# Nを取得
n = int(input())

# Xiを取得
xs = list(map(int, input().split()))

# 昇順にソートしたXiを取得
xs_sorted = sorted(xs)

# Xiの個数およびその1/2の値を取得
l = len(xs_sorted)
l_mid = int(l / 2)

# iが全体の1/2より小さい時、大きい時の中間値をそれぞれ取得
xs_mid_1 = xs_sorted[l_mid - 1]
xs_mid_2 = xs_sorted[l_mid]

# 結果を出力
for x in xs:
    if x < xs_mid_2:
        print("{}".format(xs_mid_2))
    else:
        print("{}".format(xs_mid_1))


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

int main(){
  int N;
  cin >> N;
  vector<int> V(N);
  for(auto &v : V) cin >> v;
  sort(V.begin(), V.end());
  long double ans = V[0];
  for(int i = 1; i < N; ++i){
    ans = (ans+V[i])/2;
  }
  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:usize = read();
    let b:usize = read();
    let c:usize = read();
    let d:usize = read();
    println!("{}", num(b, c, d) - num(a-1, c, d));
}

fn gcd(x:usize, y:usize) -> usize {
    if y == 0 {
        return x;
    }
    return gcd(y, x%y)
}

fn num(n:usize, c:usize, d:usize) -> usize {
    let lcm = c / gcd(c, d) * d;
    return n - n / c - n / d + n / lcm
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    cout << (n+1) / 2 * (n/2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int nn,ans=0;
    while(cin>>nn){
        if(nn==0)return 0;
        while(nn>0){
            ans+=nn/5;
            nn/=5;
        }
        cout<<ans<<endl;
        ans=0;
         
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main()
{

    int n,m;
    cin>>n>>m;

    if(n<m)
    {
        for(int i =0 ; i<m ; i++)
            cout<<n;
    }
    else
    {

        for(int i = 0 ; i<n ; i++)
            cout<<m;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define MAX_N 10000010
vector<ll> f(MAX_N, 2); 
signed main(void)
{
	ll n, ans;
	cin >> n;
	f[1] = 1;
	for(ll i = 2; i <= MAX_N; i++)
	{
		for (ll j = 2; i * j <= MAX_N; j++)
			f[i * j]++;
	}
	ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans += i * f[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 81188
#include<bits/stdc++.h>
using namespace std;
stack<char> S;
char str[100000+5];
int main()
{
	scanf("%s",str);
	S.push(str[0]);
	for(int i = 1; i < strlen(str); i++ )
	{
		if(S.top()!=str[i])
			S.push(str[i]); 		
	}
	printf("%d\n",S.size() - 1);
	return 0;
}

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

using namespace std;
int main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s;
    int flag = 0;
    if(n%2==1){
        cout << "No";
        return 0;
    }
    for (int i = 0; i < n / 2; i++)
    {
        if(s[i] == s[i + n/2]){
            flag = 1;
            continue;
        }
        else{
            flag = 0;
            break;
        }
    }
    if(flag==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int room;
    char hospital[11];
	
    while(cin >> room, room)
    {
        sprintf(hospital, "%o", room);
    	
    	for(int i = 0; i < 11; i++)
    	{
    		if(hospital[i] == '4')
    		{
    			hospital[i] = '5';
    		}
    		else if(hospital[i] > '4')
    		{
    			hospital[i] += 2;
    		}
    	}
    	cout << hospital << endl;
    }
    
    return 0;
}

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

using namespace std;

const long long MOD = 1000000000 + 7;
const string abc = "abacaba";

void solve() {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
        cout << 3;
    } else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
        cout << 2;
    } else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << 1;
    } else {
        cout << 0;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    int t;
//    cin >> t;
//    for (int tt = 0; tt < t; tt++) {
//        solve();
//    }
    solve();
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
bool IsValidMonth(int a)
{
    return a >= 1 && a <= 12;
}

void _main()
{
    string S;
    cin >> S;
    int a, b;
    a = (S[0] - '0') * 10 + (S[1] - '0');
    b = (S[2] - '0') * 10 + (S[3] - '0');
    if (!IsValidMonth(a) && !IsValidMonth(b))
    {
        cout << "NA" << endl;
    }
    else if (IsValidMonth(a) && IsValidMonth(b))
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (IsValidMonth(a) && !IsValidMonth(b))
    {
        cout << "MMYY" << endl;
    }
    else
    {
        cout << "YYMM" << endl;
    }
}


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

public class Main {
	
    public static void main(String[] args) {
	FastScanner sc = new FastScanner();
	
	int N = sc.nextInt();
	int K = sc.nextInt();
	boolean can;
	
	if(2*K-1 <= N){
		can = true;
	}
	else{
		can = false;
	}
	
	if(can){
	    System.out.println("YES");
	}
	else{
	    System.out.println("NO");
	}
	
    }
    
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7, M = 1e9 + 7;

int f[N], inv[N], fi[N];
int	qpow(int a, int b) {
	if(b == 0) return 1;
	int t = qpow(a, b / 2);
	t = t * t % M;
	if(b & 1) return t * a % M;
	else return t;
}

int inverse(int a) {
	return qpow(a, M - 2);
}

int dp[N], ans[N], sz[N], n;
vi G[N];

void dfs(int u, int pa = -1) {
	dp[u] = 1, sz[u] = 1;
	for(int v:G[u]) if(v != pa) {
		dfs(v, u);
		sz[u] += sz[v];
		dp[u] = dp[u] * dp[v] % M;
		dp[u] = dp[u] * fi[sz[v]] % M;
	}
	dp[u] = dp[u] * f[sz[u] - 1] % M;
}

void dfs1(int u, int pa = -1, int up = 1) {
	ans[u] = dp[u] * fi[sz[u] - 1] % M;
	int upsz = n - sz[u];
	ans[u] = ans[u] * up % M;
	ans[u] = ans[u] * fi[upsz] % M;

	for(int v:G[u]) if(v != pa) {
		int pass = ans[u];
		pass = pass * inverse(dp[v]) % M;
		pass = pass * f[sz[v]] % M;
		pass = pass * f[n - sz[v] - 1] % M;
		dfs1(v, u, pass);	
	}
	ans[u] = ans[u] * f[n - 1] % M;
}

signed main()
{
	IO_OP;
	

	f[0] = 1;
	for(int i=1;i<N;i++) f[i] = f[i-1] * i % M;
	inv[1] = 1;
	for(int i=2;i<N;i++) inv[i] = M - M / i * inv[M % i] % M;
	fi[0] = 1;
	for(int i=1;i<N;i++) fi[i] = fi[i-1] * inv[i] % M;

	cin >> n;
	for(int i=0;i<n-1;i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		G[v].PB(u);
	}	
	dfs(1);
	dfs1(1);
	for(int i=1;i<=n;i++) cout << ans[i] << endl; 
	
}





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

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

	char a[3];
	int s=0;
	for (int i = 0; i < 3; i++){
		cin >> a[i];
		if (a[i] == '1') {
			s++;
		}
	}
	cout << s;
}

Measured memory_bytes: 256
Q, H, S, D = map(int, input().split())
N = int(input())

H = min(Q * 2, H)
S = min(H * 2, S)
D = min(S * 2, D)

res = 0

if S <= D/2:
    res = N * S
else:
    res = ((N // 2) * D) + ((N % 2) * S)

print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
using namespace std;
 
int main(){
  long long A, B, C, D, a, b, c, d, r;
  cin >> A >> B >> C >> D;
  a = max(C,D);
  b = min(C,D);
  c = C * D;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  d = c / b;
  cout << B - A + 1 - ((B / C - A / C + (A % C == 0)) 
                       + (B / D - A / D + (A % D == 0)) 
                       - (B / d - A / d + (A % d == 0))) << endl;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let N: isize = read();
    let A: isize = read();
    println!("{}", N*N - A);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();

        if (s[0] != 'A') {
            System.out.println("WA");
            return;
        }

        int countC = 0;
        int position = 0;
        for (int i = 2; i < s.length-1; i++) {
            if (s[i] == 'C') {
                countC++;
                position = i;
            }
        }

        if (countC != 1) {
            System.out.println("WA");
            return;
        }

        for (int i = 1; i < s.length; i++) {
            if (i == position) continue;
            if (Character.isUpperCase(s[i])) {
                System.out.println("WA");
                return;
            }
        }

        System.out.println("AC");
    }
}

Measured memory_bytes: 35720
#include <iostream>
#include <vector>
using namespace std;
int N;
vector<int> C,S,F;
int getMinTime(int n){
	int i;
	int Time=S[n]+C[n];
	for (i=n+1;i<N-1;i++){
		int t=S[i];
		while (t<Time){
			t+=F[i];
		}
		Time=t+C[i];
	}
	return Time;
}
int main(int argc, char* argv[])
{

	cin>>N;
	int c,s,f;
	int i;
	for (i=0;i<N;i++){
		cin>>c>>s>>f;
		C.push_back(c);
		S.push_back(s);
		F.push_back(f);
	}
	for (i=0;i<N-1;i++){
		cout<<getMinTime(i)<<endl;
	}
	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

ll a, b, c, cnt;
ll s;

int main(){
	cnt = 0;
	cin >> a >> b >> c;
	s = a + b + c;
	if (a == b&&b == c&&a % 2 == 0)
		cout << -1 << endl;
	else {
		while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			cnt++;
			a = (s - a) / 2;
			b = (s - b) / 2;
			c = (s - c) / 2;
//			cout << cnt << sp << a << sp << b << sp << c << endl;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n;

int main(){
    cin >> n;
    ll ans = 0;
    FOR(i,1,sqrt(n)+1){
        if(n % i == 0){
            if((n - i)/i > i)ans += (n - i)/i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))


def expectation(value):
    return 0.5 * (value + 1)


res = 0
for l in range(k):
    res += expectation(p[l])

cur = res
for l in range(k, n):
    cur += expectation(p[l]) - expectation(p[l-k])
    res = max(res, cur)
print(res)


Measured memory_bytes: 25060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
template <typename T, const T TINF>
struct Dijkstra {
  struct Edge {
    int src, dst;
    T cost;
    Edge(int dst_, T cost_ = 0) : src(-1), dst(dst_), cost(cost_) {}
    Edge(int src_, int dst_, T cost_) : src(src_), dst(dst_), cost(cost_) {}
    inline bool operator < (const Edge &rhs) { return cost < rhs.cost; }
    inline bool operator <= (const Edge &rhs) { return cost <= rhs.cost; }
    inline bool operator > (const Edge &rhs) { return cost > rhs.cost; }
    inline bool operator >= (const Edge &rhs) { return cost >= rhs.cost; }
  };

  vector<vector<Edge> > graph;
  vector<T> dist;

  Dijkstra(int sz_) : sz(sz_), graph(sz_), dist(sz_, TINF), prev(sz_, -1) {}

  void add(int src, int dst, T cost) { graph[src].emplace_back(Edge(dst, cost)); }

  void build(int start) {
    dist.assign(sz, TINF);
    prev.assign(sz, -1);
    dist[start] = 0;
    priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > que;
    que.emplace(0, start);
    while (!que.empty()) {
      pair<T, int> pr = que.top(); que.pop();
      int ver = pr.second;
      if (dist[ver] < pr.first) continue;
      for (Edge e : graph[ver]) {
        if (dist[e.dst] > dist[ver] + e.cost) {
          dist[e.dst] = dist[ver] + e.cost;
          prev[e.dst] = ver;
          que.emplace(dist[e.dst], e.dst);
        }
      }
    }
  }

  vector<int> build_path(int target) {
    vector<int> res;
    for (; target != -1; target = prev[target]) res.emplace_back(target);
    reverse(ALL(res));
    return res;
  }

private:
  int sz;
  vector<int> prev;
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, s, t; cin >> n >> m >> s >> t;
  --s;
  --t;
  Dijkstra<long long, LINF> yen(n), snuke(n);
  REP(i, m) {
    int u, v, a, b; cin >> u >> v >> a >> b;
    --u;
    --v;
    yen.add(u, v, a);
    yen.add(v, u, a);
    snuke.add(u, v, b);
    snuke.add(v, u, b);
  }
  yen.build(s);
  snuke.build(t);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > que;
  REP(i, n) que.emplace(yen.dist[i] + snuke.dist[i], i);
  auto a = que.top(); que.pop();
  REP(i, n) {
    while (i > a.second) {
      a = que.top(); que.pop();
    }
    cout << 1000000000000000 - a.first << '\n';
  }
  return 0;
}


Measured memory_bytes: 20604
#include<algorithm>//sort(all(変数),greater<型名>())で降順に,reverse()で逆に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,何文字)で文字列ゲット
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n;  cin >> n;
  vll h(n),s(n);
  rep(i,n){
    cin >> h[i];
  }
  rep(i,n){
    s[i] = h[i] - h[i+1];
  }
  int ans = 0;
  rep(i,n-1){
    int cnt = 0;
    while(i < n-1 and s[i] >= 0){
      i++;
      cnt++;
    }
    ans = max(ans,cnt);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
    while(true) {
        int N, W;
        cin >> N >> W;
        if(!N && !W) break;

        vector<int> hist(11, 0);
        int rightmost = 0;
        int maxval = 0;

        for(int i = 0; i < N; ++i) {
            int v;
            cin >> v;
            hist[v/W]++;
        }

        for(int i = 0; i < hist.size(); ++i) {
            if(hist[i] != 0) rightmost = i;
            if(hist[i] > maxval) maxval = hist[i];
        }

        double sum = 0;
        if(rightmost == 0) sum += 1;
        else {
            for(int i = 0; i <= rightmost; ++i) {
                sum += ((double)(rightmost-i) / rightmost) * hist[i] / maxval;
            }
        }
        sum += 0.01;

        printf("%.6f\n", sum);
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

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

	public static void main(String[] args) {
		int[] g = {0, 1,3,1,2,1,2,1,1,2,1,2,1};
		int a = in.nextInt(), b = in.nextInt();
		System.out.println(g[a] == g[b] ? "Yes" : "No");
		
	}
}

Measured memory_bytes: 21844
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    ld r;
    cin>>r;
    cout<<(2*PI*r);
    return 0;
}


Measured memory_bytes: 3812
N, M, Q = map(int, input().split())

LR = [[0 for _ in range(N)] for _ in range(N)]
LRsum = [[0 for _ in range(N+1)] for _ in range(N+1)]

for _ in range(M):
    l, r = map(int, input().split())
    LR[l-1][r-1] += 1

# for i in LR:
#     print(i)

#二次元累積和
for i in range(N):
    for j in range(N):
        LRsum[i+1][j+1] = LRsum[i][j+1] + LRsum[i+1][j] - LRsum[i][j] + LR[i][j]

# print(LRsum)

for _ in range(Q):
    p, q = map(int, input().split())
    print(LRsum[q][q]-LRsum[q][p-1]-LRsum[p-1][q]+LRsum[p-1][p-1])

# print(L)
# print(LL)

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

int main(){ 
    int n,t;
    cin>>n>>t;
    int b=1001;
    vector<vector<int>> a(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a.at(i).at(j);
    }
  }
  for(int i=0;i<n;i++){
      if(a[i][1]<=t){
      b=min(b,a[i][0]);
      }
  }
  if(b==1001){
      cout<<"TLE";
  }else{
      cout<<b;
  }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    ArrayList<String> S = new ArrayList<String>();
    for(int i = 0;i < N;i++){
      S.add(sc.next());
    }
    Collections.sort(S);
    for(int a = 0;a < N;a++){
      System.out.print(S.get(a));
    }
  }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,i;
cin>>n;
long long key[n+1][3],dp[n+1][3]={0};
for(int i=1;i<=n;i++)
     cin>>key[i][0]>>key[i][1]>>key[i][2];

 for(i=1;i<=n;i++)
 {
     dp[i][0]=key[i][0]+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=key[i][1]+max(dp[i-1][0],dp[i-1][2]);
       dp[i][2]=key[i][2]+max(dp[i-1][1],dp[i-1][0]);
 }
 cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;

}


Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int N = si();
  int result=0;
  std::vector<int> v(N),c(N);
  for (size_t i = 0; i < N; i++) {
    cin >> v[i];
  }
  for (size_t i = 0; i < N; i++) {
    cin >> c[i];
  }
  for (size_t i = 0; i < N; i++) {
    if(v[i]-c[i] > 0) result += v[i]-c[i];
  }

  pi(result); br();
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(A % 3 == 0){
            System.out.println("Possible");
        }else if(B % 3 == 0){
            System.out.println("Possible");
        }else if((A + B)%3 == 0){
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }
    }
}

Measured memory_bytes: 21844
const main = (input) => {
  input = input.split('\n');
  const X = parseInt(input[0], 10);
  const A = parseInt(input[1], 10);
  const B = parseInt(input[2], 10);
  
  console.log((X-A)%B);
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,k = MI()
a = RI()

# ind = a.index(1)
ans = ceil((n-k)/(k-1)) + 1
print(ans)

Measured memory_bytes: 88984
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    int ls=s.length();
    ll ans=0;
    for (int i=1;i<ls;i++){
        if (s[i]!=s[i-1])
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int gcd = 0;
	int mx = 0;
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		gcd = __gcd(x, gcd);
		mx = max(mx, x);
	}
	if(k % gcd == 0 && k <= mx) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
//
//  abc151_d.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265

int dijsktra(int x, int n, vector<int> *adj) {
  priority_queue<pair<int, int> >  q; // (-d, x) current distance to node x is d, using -d to find minimum distance
  bool processed[n];
  int distance[n];
  for (int i=0; i<n; i++) {
    distance[i] = INF;
    processed[i] = false;
  }
  // find from x
  distance[x] = 0;
  q.push({0, x});

  while (!q.empty()) {
    int a = q.top().second;
    q.pop();
    if (processed[a]) continue;;
    processed[a] = true;
    for (auto u: adj[a]) {
      int b = u; // node b
      int w = 1; // distance from a to b is w
      if (distance[b] > distance[a] + w) {
        distance[b] = distance[a] + w;
        q.push({-distance[b], b});
      }
    }
  }

  int l = 0;
  // std::cout << "distance from " << x << std::endl;
  for (int i = 0; i < n; i++) {
    if (distance[i]==INF) continue;
    l = max(l, distance[i]);
    // std::cout << " distance to " << i << ": " << distance[i] << std::endl;
  }

  return l;
}


int main() {
  int h, w;
  std::cin >> h >> w;

  bool s[h][w];
  vector<int> adj[h*w];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      std::cin >> c;
      if (c == '.') s[i][j] = true;
      else s[i][j] = false;
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!s[i][j]) continue;
      if (i > 0 && s[i-1][j]) adj[i*w+j].push_back((i-1)*w+j);
      if (i+1 < h && s[i+1][j]) adj[i*w+j].push_back((i+1)*w+j);
      if (j > 0 && s[i][j-1]) adj[i*w+j].push_back(i*w+j-1);
      if (j+1 < w && s[i][j+1]) adj[i*w+j].push_back(i*w+j+1);
    }
  }

  //dijsktra
  int ans = 0;
  for (int i = 0; i < h*w; i++) {
    ans = max(ans, dijsktra(i, h*w, adj));
  }
  std::cout << ans << std::endl;


  return 0;
}



Measured memory_bytes: 256
from collections import Counter
N = int(input())
V = list(map(int,input().split()))

if len(set(V)) == 1:
    print(N//2)
    
else:
    v1 = Counter(V[0::2]).most_common(2)
    v2 = Counter(V[1::2]).most_common(2)
    if v1[0][0] == v2[0][0]:
        print(N - max(v1[0][1] + v2[1][1], v1[1][1] + v2[0][1]))
    else:
        print(N - v1[0][1] - v2[0][1])

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

int N, M, A, B, C, T;
vector<int> S;

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for(int i=0; i<A.size(); i++){
        for(int k=0; k<B.size(); k++){
            for(int j=0; j<B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
            }
        }
    }
    return C;
}

mat pow(mat A, int n){
    mat B(A.size(), vec(A.size()));
    for(int i=0; i<A.size(); i++){
        B[i][i] = 1;
    }
    while(n>0){
        if(n&1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}


int main(){
    while(cin>>N>>M>>A>>B>>C>>T, N|M|A|B|C|T){
        S.resize(N);
        for(auto &s: S) cin >> s;
        
        vector<int> co({A, B, C});
        mat Mat = mat(N, vec(N));
        for(int i=0; i<N; i++){
            for(int j=0; j<3; j++) if(0<=j+i-1 && j+i-1<N){
                Mat[i][j+i-1] = co[j];
            }
        }
        
        mat init;
        for(int i=0; i<N; i++)
            init.push_back(vec({S[i]}));
        Mat = pow(Mat, T);
        Mat = mul(Mat, init);
        
        
        for(int i=0; i<N; i++)
            cout << Mat[i][0] << (i==N-1? "\n": " ");
    }
    
    return 0;
}

Measured memory_bytes: 3152
def bubble_sort():
    N = int(input())
    A = [int(_) for _ in input().split()]

    flag = True
    ans = 0
    i = 0

    while flag:
        flag = False
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                ans += 1
                flag = True
        i += 1
    #N-1からiの範囲で全てif文が満たされない時(並べ替えが完了した時)，flag=Falseとなり処理が終了する

    print(' '.join(map(str, A)))
    print(ans)

bubble_sort()


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

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

  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  int ans = 0;
  if (D2 == 1) ans = 1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)



int main(){
    ll N, M; cin >> N >> M;
    vector<vll> A(N);
    rep(i, N){
        ll K; cin >> K;
        ll tmp;
        rep(j, K){
            cin >> tmp;
            A[i].push_back(tmp-1);
        }
    }
    vll rec(M, 0);
    rep(i, N){
        rep(j, A[i].size()){
            rec[A[i][j]]++;
        }
    }
    ll ans = 0;
    rep(i, M){
        if(rec[i]==N)
            ans ++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
  int edge[4];
  for(int i=0; i<4; i++)cin>>edge[i];
  
  sort(edge,edge+4);
  
  if(edge[0]==edge[1] && edge[2]==edge[3])cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  
  return 0;
}


Measured memory_bytes: 3120
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

H, N, = map(int, input().split())
L = [int(v) for v in input().split()]

if H <= sum(L):
    print("Yes")
else:
    print("No")

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

using namespace std;

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

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

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

  vector<string> T;
  T.push_back("dream");
  T.push_back("dreamer");
  T.push_back("erase");
  T.push_back("eraser");
  
  for(int i = 0; i < T.size(); i++){
    reverse(T[i].begin(), T[i].end());
  }

  string S;
  cin >> S;
  reverse(S.begin(), S.end());

  bool ok = true;

  int ind = 0;
  while(ind < S.length()){

    bool tmp = false;
    for(int i = 0; i < T.size(); i++){
      if(!tmp && S.substr(ind, T[i].length()) == T[i]){
        tmp = true;
        ind += T[i].length();
      }
    }
    if(!tmp){
      ok = false;
      break;
    }
  }

  if(ok){
    cout << "YES" << endl;
  }else{
    cout <<"NO" << endl;
  }
  


  return 0;
}


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

int main(){
  string s;
  cin>>s;
  deque<char> p;
  rep(i,s.size()){
    p.push_back(s[i]);
  }
  int q; cin>>q;
  bool rev=false;
  rep(qi,q){
    int t; cin>>t;
    if(t==1){
      if(rev) rev=false;
      else rev=true;
    }else{
      int f;
      char c; 
      cin>>f>>c;
      if(!rev){
        if(f==1) p.push_front(c);
        else p.push_back(c);
      }else{
        if(f==2) p.push_front(c);
        else p.push_back(c);
      }
    }
  }
  if(rev) reverse(p.begin(),p.end());
  string ans;
  while(!p.empty()){
    ans+=p.front();
    p.pop_front();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4280
#include<bits/stdc++.h>
using namespace std;
const int N=14e4,S=131072,mo=998244353,W=716070898;
int n,mi[N],b[N],i;
inline void FWT(int*a){
	int i,j,k,m;
	for(i=2;i<=S;i<<=1)for(j=0,m=i>>1;j<S;j+=i)for(k=0;k<m;++k){
		int x=a[j+k],y=a[j+k+m];
		a[j+k]=(x+y)%mo;a[j+k+m]=(x+mo-y)%mo;
	}
}
struct graph{
	vector<int>e[N];
	int sg[N],a[N];
	void ini(){
		int i,x,y,m;
		scanf("%d",&m);
		for(i=1;i<=m;++i){
			scanf("%d%d",&x,&y);
			if(x>y)swap(x,y);e[x].push_back(y);
		}
		for(i=n;i;--i){
			static int buc[N];int d=e[i].size();
			memset(buc,0,d+2<<2);
			for(int j:e[i])if(sg[j]<d+2)++buc[sg[j]];
			for(sg[i]=0;buc[sg[i]];++sg[i]);
			a[sg[i]]=(a[sg[i]]+mi[i])%mo;
		}
		FWT(a);
	}
}g[3];
int main(){
	for(i=*mi=1;i<N;++i)mi[i]=1ll*mi[i-1]*W%mo;
	scanf("%d",&n);for(i=0;i<3;++i)g[i].ini();
	memcpy(b,g[0].a,sizeof b);
	for(i=0;i<S;++i)b[i]=1ll*b[i]*g[1].a[i]%mo;
	for(i=0;i<S;++i)b[i]=1ll*b[i]*g[2].a[i]%mo;
	FWT(b);
	printf("%lld\n",998236737ll*b[0]%mo);
}

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

using namespace std;

int main(int argc, char const *argv[]) {
        int x, y;
        cin >> x >> y;
        if(x < y) {
                int tmp = x;
                x = y;
                y = tmp;
        }
        int r = x % y;
        while(r != 0) {
                x = y;
                y = r;
                r = x % y;
        }
        cout << y << endl;
        return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int h[n];
	rep(i,0,n) cin >> h[i];
	int ma = 0;
	int cnt=0;
	rep(i,1,n){
		if(h[i-1]>=h[i])cnt++;
		else{
			ma = max(ma,cnt);
			cnt=0;
		}
	}
	ma = max(ma,cnt);
	cout << ma << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	int* input = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> input[i];
	}
	sort(input, input + n);
	n -= k;
	if (n > 0)
	{
		unsigned long long sum = 0;
		for (int i = 0; i < n; i++)
		{
			sum += (unsigned long long)input[i];
		}
		printf("%llu", sum);
	}
	else
	{
		printf("0");
	}
}

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

int main() {
	int n;
	int dxy[] = { 0,1,0,-1,0 };
	//char f2d[] = { 'N','E','S','W' };
	string f2d = "NESW";
	while (cin >> n) {
		if (!n)break;
		
		vector<vector<int> > field(21,vector<int>(21,0));
		
		for (int i = 0; i < n; ++i) {
			int _x, _y;
			cin >> _x >> _y;
			field[_x][_y] = 1;
			
		}
		int x = 10, y = 10;
		int m;
		cin >> m;

		int move; char f;

		for (int i = 0; i < m; ++i) {
			cin >> f >> move;
			int idx = (int)f2d.find(f);

			for(int j=0;j<move;j++){
				x += dxy[idx];
				y += dxy[idx+1];
				if (field[x][y]) {
					field[x][y] = 0;
					n--;
				}

			}
		}

		if (!n)cout << "Yes" << endl;
		else cout << "No" << endl;
		
	}
	return 0;
}


Measured memory_bytes: 3164