akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	
	public static int n;
	public static int[] A = new int[50];
	
	
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		A = new int[n];
		for(int i = 0;i<n;i++){
			A[i] = in.nextInt();
		}
		int q = in.nextInt();
		int[] m = new int[q];
		for(int j=0;j<q;j++){
			m[j] = in.nextInt();
			if(solve(0, m[j]))
				System.out.println("yes");
			else 
				System.out.println("no");
		}
	}
	public static boolean solve(int i,int m){
		if(m==0) return true;
		if(i>=n) return false;
		
		boolean res = solve(i+1,m)||solve(i+1,m-A[i]);
		return res;
	}
}



Measured memory_bytes: 26592
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int K;
  cin >> K;
  int o = (K + 1) / 2, e = K / 2;
  cout << (o * e);
}
#endif


Measured memory_bytes: 3588
from fractions import gcd
from functools import reduce


def lcm(x, y):
    return x * y // gcd(x, y)


divisor = 10 ** 9 + 7
len_arr = int(input())
arr = list(map(int, input().split()))

gcd_all = reduce(lcm, arr)
if min(arr) == gcd_all:
    print(len_arr)
else:
    ans = sum([gcd_all // elem for elem in arr]) % divisor
    print(ans)


Measured memory_bytes: 264700
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete


main = do
    n <- getInt
    unless (n==0) $ do
        psum <- sum <$> getInts
        js <- sortBy (flip compare) <$> getInts
        print $ maximum $ map (uncurry (*)) $ scanl (\(s, t) j -> (s+j, t-1)) ((psum, n)) js
        main


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

int main()
{
    long long n;
    cin>>n;
    long long a=2,ans=0;
    int p=0;
    while(true)
    {
        if(a>n)break;
        p++;
        a*=5;
    }
    if(n%2==0)
    {
       for(int i=1;i<=p;i++)
       {
           ans+=n/((long long)(2*pow(5,i)));
       }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/**
 * 0000：QQの解答
 * 
 * @author MS14A
 * @version 2015/06/21
 */
public class Main {

    /**
     * 九九を出力して終了する 但し、×記号の代わりに、小文字の x を使用する
     * 
     * @param args
     */
    public static void main(String[] args) {

        // 段数ごとに九九を出力
        for (int lineNumber = 1; lineNumber <= 9; ++lineNumber) {
            printMultiplicationTable(lineNumber);
        }
    }

    /**
     * 段数を受け取り、その段の九九を出力する。
     * 
     * @param lienNumber 段数
     */
    private static void printMultiplicationTable(int lienNumber) {
        for (int rowNumber = 1; rowNumber <= 9; ++rowNumber) {
            System.out.println(String.valueOf(lienNumber) + "x"
                    + String.valueOf(rowNumber) + "="
                    + lienNumber * rowNumber);
        }
    }
}

Measured memory_bytes: 16864
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N;
	cin >> N;
	int ten = N / 10;
	int one = N % 10;
	if (ten == 9 || one == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>

#define N 8

int r[N],c[N],dp[2*N-1],dn[2*N-1];
int x[N][N];

void init(){
  int i;
  for(i=0;i<N;i++){r[i]=-1;c[i]=-1;}
  for(i=0;i<2*N-1;i++){dp[i]=-1;dn[i]=-1;}
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){if(r[i]!=j) return;}
    }
  }for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(r[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  
  if(i==N){printBoard();return;}

  for(j=0;j<N;j++){
    if(1==c[j]||1==dp[i+j]||1==dn[i-j+N-1]) continue;
    r[i]=j; c[j]=dp[i+j]=dn[i-j+N-1]=1;
    recursive(i+1);
    r[i]=c[j]=dp[i+j]=dn[i-j+N-1]=-1;
  }
}

int main(){
  int i,j,k,row,col;
  
  init();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++) x[i][j]=0;
  }

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&row,&col);
    x[row][col]=1;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2100
N = int(input())
S = input()
stack = []
for s in S:
    if s == '(':
        stack.append('(')
    elif s == ')':
        if len(stack) == 0 or stack[-1] == ')':
            stack.append(')')
        elif stack[-1] == '(':
            stack.pop()

l, r = sum([1 for s in stack if s == '(']), sum([1 for s in stack if s == ')'])
print('(' * r + S + ')' * l)


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

int main()
{
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    ll * dp = new ll[n]();

    for(int i=1;i<n;i++)
    {
        if( s[i] =='C' && s[i-1] =='A')
        {
            dp[i] = 1 + dp[i-1];
        }
        else dp[i ] = dp[i-1];
    }
    for(int i=0;i<q;i++)
    {
        ll l , r;
        cin>>l>>r;
        l--;
        r--;
        cout<<dp[r] - dp[l] <<"\n";
    }
}

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

int N;
vector<int> A;
vector<vector<long long>> dp;
const long long INF = 1LL << 60;

// [left, right) の状態からゲームを開始したときの X-Y を返す
long long func(int left, int right) {
  if (left == right) return dp.at(left).at(right) = 0;
  if (dp.at(left).at(right) != -INF) return dp.at(left).at(right);
  if ((N - (right - left)) % 2 == 0) {
    // 先手 (X-Y を最大化したい)
    long long res = -INF;
    res = max(res, A.at(left) + func(left + 1, right));  // 先頭をとる
    res = max(res, A.at(right - 1) + func(left, right - 1));  // 末尾をとる
    return dp.at(left).at(right) = res;
  }
  else {
    // 後手 (X-Y を最小化したい)
    long long res = INF;
    res = min(res, (-1) * A.at(left) + func(left + 1, right));
    res = min(res, (-1) * A.at(right - 1) + func(left, right - 1));
    return dp.at(left).at(right) = res;
  }
}

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  dp = vector<vector<long long>>(N+1, vector<long long>(N+1, -INF));
  cout << func(0, N) << endl;
}

Measured memory_bytes: 70912
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<llint, llint>Pii;
typedef pair<double, double>Pdd;

#define pi 3.141592653589793)
#define mod 1000000007

string a = "abcdefghijklmnopqrstuvwxyz";

int num(char c) {
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == c)return i;
	}
}

int main() {
	string s;
	cin >> s;
	if (s.size() < 26) {

		for (int i = 0; i < a.size(); i++) {
			bool flag = false;
			int ans;
			for (int j = 0; j < s.size(); j++) {
				if (a[i] == s[j]) {
					flag = true;
					ans = a[i];
				}
			}
			if (!flag) {
				for (int j = 0; j < s.size(); j++) {
					cout << s[j];
				}
				cout << a[i] << endl;
				return 0;
			}
		}

	}

	else {

		int MAX = -1;


		for (int i = s.size()-1; i >= 0; i--) {

			for (int j = s.size() - 1; j >= i;j--) {
				int n = num(s[j]);
				for (int k = j; k >= i; k--) {
					if (n > num(s[k])) {
						s[k] = a[n];
						for (int l = 0; l < k+1; l++) {
							cout << s[l];
						}
						cout << endl;
						return 0;
					}
				}
			}

		}

/*		for (int k = s.size() - 1; k >= 0; k--) {
			int n = num(s[k]);

			for (int i = k - 1; i >= 0; i--) {


				if (n < num(s[i])) {
				}
				else {
					s[i] = a[n];
					for (int j = 0; j < i + 1; j++) {
						cout << s[j];
					}
					cout << endl;
					return 0;
				}

			}
		}*/

	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    vector<vector<int>> mat(n,vector<int>(m));
    vector<bool> checked(m,false);
    rep(i,n){
        rep(j,m){
            cin>>mat[i][j];
            mat[i][j]--;
        }
    }
    vector<int> cur(n,0);
    vector<int> tmp(m,0);
    rep(i,n){
        tmp[mat[i][0]]++;
    }
    int res = 0;
    rep(i,m){
        chmax(res, tmp[i]);
    }
    DEBUG{
        printf("res: %d\n",res);
    }
    rep(i,m-1){
        vector<int> cnt(m,0);
        rep(j,n){
            cnt[mat[j][cur[j]]]++;
        }
        int del,mx=0;
        rep(j,m){
            if(chmax(mx,cnt[j])){
                del = j;
            }
        }
        checked[del]=true;
        chmin(res, mx);
        rep(j,n){
            while(checked[mat[j][cur[j]]]){
                cur[j]++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int n, k, s, ans, a[5005];
int main(void){

    cin.tie(0);
    ios::sync_with_stdio(false);
	int i;
	cin >> n >> k;
	for(i=0; i<n; i++) cin>>a[i];
	sort(a, a+n);

	for( i = n-1; i >= 0; i--){

		if( s + a[i] >= k) ans = 0;

		else{
            ans++;
            s += a[i];
        }
	}
	cout << ans;

    return 0;
}

Measured memory_bytes: 256
N= int(input())
List = list(map(int, input().split()))
List.insert(0,0)
List_J = []
for i in range(N):
  List_J.append(0)
for i in range(N):
  List_J[List[i]] = List_J[List[i]] + 1
List_J.append(0)
for i in range (len(List_J)-1):
  print(List_J[i+1])

Measured memory_bytes: 32388
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b, n; scanf("%d%d%d", &a, &b, &n);
	
	if(n < a or a + b < n) printf("NO\n"); 
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    
    int M=(N-1)*(N-2)/2;
    if(M<K) {
        cout << -1 << endl;
    } else {
        M = N-1+M-K;
        cout << M << endl;
        
        for(int i=0; i<N-1; i++) {
            cout << 1 << " " << i+2 << endl;
        }
        M -= N-1;
        for(int j=2; j<N; j++) {
            for(int k=j+1; k<=N; k++) {
                if(M==0) break;
                cout << j << " " << k << endl;
                M--;
            }
            if(M==0) break;
        }
    }

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>

using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; const int INF=1e9; const ll LINF=1e18;

int main(){
  string s; cin>>s; int n=s.size();
  string t;
  for(int i=0;i<n;i++) {
    if (s[i]!='x') t+=s[i];
  }
  int m=t.size();
  for(int i=0;i<m;i++) {
    if (t[i] != t[m-1-i]) {
      cout<<-1<<endl;
      return 0;
    }
  }
  int a[m+1]={};
  for(int i=0,j=0;i<n;i++) {
    if (s[i]=='x') a[j]++;
    else j++;
  }
  int an=0;
  for(int i=0;i<=m;i++) {
    an += max(0, a[i]-a[m-i]);
  }
  cout<<an<<endl;
}

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

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<ll> factorList(ll x) {
    vector<ll> res;
    for (int p : primes) {
      while (x%p == 0) {
        res.push_back(p);
        x /= p;
      }
    }
    if (x != 1) res.push_back(x);
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<ll> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<ll,int>> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

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

  vector<pair<ll,int>> fs;
  for (ll i = 2; i*i <= n; ++i) {
    int x = 0;
    while (n%i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if (n != 1) fs.emplace_back(n,1);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const double PI=acos(-1.0);

int main() {
    int cnt[2][105] = {0};
    int n;
    cin >> n;
    for(int i = 0; i < 2; i++) {
        for(int j = 1; j <= n; j++) {
            cin >> cnt[i][j];
            cnt[i][j] += cnt[i][j - 1];
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int tmp = cnt[0][i] + cnt[1][n] - cnt[1][i - 1];
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

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

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

int main() {
    int x1,y1,x2,y2,dx,dy;
    cin>>x1>>y1>>x2>>y2;
    dx=x2-x1;
    dy=y2-y1;
    cout<<string(dy,'U')+string(dx,'R')+string(dy,'D')+string(dx,'L');
    cout<<'L'+string(dy+1,'U')+string(dx+1,'R')+'D'+'R'+string(dy+1,'D')+string(dx+1,'L')+'U';
   
}

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

int main() {
	string a, b;
	cin >> a >> b;
	int n = stoi(a + b);
	for (int i = 1; i*i <= 100100; i++) {
		if (n == i*i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

char b;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> b;
    if (b=='A') cout << 'T' << endl;
    else if (b=='T') cout << 'A' << endl;
    else if (b=='C') cout << 'G' << endl;
    else cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#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 modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll kaijo(int k){
	ll sum = 1;
	for(ll i=1; i<=k; i++){
		sum *= i;
		sum %= modulo;
	}
	return sum % modulo;
}

ll Comb(int n, int k){
	ll a = kaijo(n);
	ll b = modinv(kaijo(n-k)*kaijo(k), modulo);
	return a * b % modulo;
}

int main() {
	int n,k;
	cin >> n >> k;

	int a = n-k;
	ll ans;
	ll y1,y2;
	for(int i=1;i<=k;i++){
		if(a < i-1) ans = 0;
		else{
			y1 = Comb(k-1,i-1);
			y2 = Comb(a+1,i);
			ans = y1 * y2 % modulo;
		}
		cout << ans << endl;
	}

	return 0;
}

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

constexpr int INF = 1000000000;
constexpr int MAX_V = 15;

int V, E;
int memo[1 << MAX_V][MAX_V] = {-1}, dis[MAX_V][MAX_V] = {-1};

int tsp(int s = 1, int v = 0);

int main(){
    scanf("%d%d", &V, &E);
    for(int i = 0; i < 1 << V; ++i){
        for(int j = 0; j < V; ++j){
            memo[i][j] = -1;
        }
    }
    for(int i = 0; i < V; ++i){
        for(int j = 0; j < V; ++j){
            dis[i][j] = INF;
        }
    }
    for(int i = 0; i < E; ++i){
        int s, t, d;
        scanf("%d%d%d", &s, &t, &d);
        dis[s][t] = d;
    }
    int tmp = tsp();
    if(tmp >= INF){
        puts("-1");
    }
    else{
        printf("%d\n", tmp);
    }
    return 0;
}

int tsp(int s, int v){
    if(memo[s][v] != -1){
        return memo[s][v];
    }
    if(s == ((1 << V) - 1)){
        return dis[v][0];
    }
    
    int res = INF;
    for(int i = 0; i < V; ++i){
        if(s & 1 << i){
            continue;
        }
        res = std::min(res, tsp(s | (1 << i), i) + dis[v][i]);
    }

    return memo[s][v] = res;
}

Measured memory_bytes: 4608
(def N (read))
(def d (for [i (range 0 N)] (read)))

(println (loop [sum 0 i 0 j 1]
  (if (>= i N)
    sum
    (if (>= j N)
      (recur sum (+ i 1) (+ i 2))
      (recur (+ sum (* (nth d i) (nth d j))) i (+ j 1))))))

Measured memory_bytes: 66688
import math
n=int(input())
loc=[]
for i in range(n):
    loc.append(list(map(int,input().split())))

d_sum=0
for i in range(n-1):
    for j in range(i+1,n):
        x=(loc[j][0]-loc[i][0])**2
        y=(loc[j][1]-loc[i][1])**2
        dij=math.sqrt(x + y)
        d_sum+=dij
print(2*d_sum/n)

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

int main(){
	
	while(1){
		int h,w,i,k;
	    cin>>h>>w;
		if(w==0&&h==0)
		{break;}
	for(i=0;i<h;i++){
    for(k=0;k<w;k++){
			if(k==0||i==0||k==w-1||i==h-1)
			{cout<<"#";}
			else{cout<<".";}
	}
	cout<<endl; 
	}
	cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>me;
    int xori=0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        me.push_back(a);
        xori^=a;
    }
    for(int i=0;i<n;i++){
        int a=me[i];
        cout << (a^=xori) << ' ';
    }
    cout << '\n';
}

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		vector<int> w(n);
		rep(i, n) cin >> w[i];
		vector<vector<int>> dp(n + 1, vector<int>(n + 1));
		for (int d = 2; d <= n; d++) {
			for (int l = 0; l <= n - d; l++) {
				int r = l + d;
				if (dp[l + 1][r - 1] == r - l - 2 && abs(w[l] - w[r - 1]) < 2) {
					dp[l][r] = r - l;
				}
				for (int m = l + 1; m < r; m++) {
					dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);
				}
			}
		}
		cout << dp[0][n] << endl;
	}
	return 0;
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int A[n][m], C[n];
  for (int i = 0; i < n; i++) {
    cin >> C[i];
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  int ans = 1e9;
  bool ans_exist = false;

  for (int i = 0; i <= (1 << n); i++) {
    int M[m], price = 0;
    fill(M, M+m, 0);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        price += C[j];
        for (int k = 0; k < m; k++) {
          M[k] += A[j][k];
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (M[j] < x) ok = false;
    }
    if (ok) {
      ans_exist = true;
      ans = min(ans, price);
    }
  }

  if (ans_exist) cout << ans << endl;
  else cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] c = new int[N+1];

		for (int i = 0; i < M; i++) {
			c[sc.nextInt()]++;
			c[sc.nextInt()]++;
		}
		for (int i = 1; i <= N; i++) {
			System.out.println(c[i]);
		}

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5+10;
const int M = 1e6+10;
/*=================================================================================*/

int n;
string str;

int main() {
   cin>>n>>str;
   int len = str.size();
   if(len<=n) cout<<str<<endl;
   else {
      for0(i, n) cout<<str[i];
      puts("...");
   }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

int x[MX];
int y[MX];
int a;
signed main() {
  int a;
  cin >> a;
  set<char> s;
  rep(i,a){
    char c;
    cin >> c;
    s.insert(c);

  }
  if(s.size()==4)cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 3616
// 2011/09/28 Tazoe

#include <iostream>
using namespace std;

void print(int S[30], int N, int I, int L)
{
	if(N==0){
		for(int i=0; i<I; i++){
			cout << S[i];
			if(i<I-1)
				cout << ' ';
			else
				cout << endl;
		}
		return;
	}

	for(int i=L; i>=1; i--){
		S[I] = i;
		if(N-i>i)
			print(S, N-i, I+1, i);
		else
			print(S, N-i, I+1, N-i);
	}

	return;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int S[30];
		print(S, n, 0, n);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> creatures(n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &creatures[i]);
    }

    std::sort(ALL(creatures));
    std::vector<lint> cumsum(n);
    std::partial_sum(ALL(creatures), cumsum.begin());

    lint ans{0};

    for (int i = 0; i < n - 1; ++i)
    {
        if (cumsum[i] * 2 >= creatures[i + 1])
        {
            ans++;
        }
        else
        {
            ans = 0;
        }
    }

    std::cout << ans + 1 << "\n";

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;sc.hasNext();){
			String buffer= sc.next();
			
			String buffer2 = new String(buffer);
			int ans = 0;
			for(;buffer.indexOf("JOI") != -1;ans++){
				buffer = buffer.substring(buffer.indexOf("JOI")+1);
			}
			
			int ans2 = 0;
			for(;buffer2.indexOf("IOI") != -1;ans2++){
				buffer2 = buffer2.substring(buffer2.indexOf("IOI")+1);
			}
			System.out.println(ans);
			System.out.println(ans2);
			
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

int main(){
    int N;
    cin >> N;

    vector<int> A(N), B(N), C(N-1);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> B[i];
    for(int i = 0; i < N-1; ++i) cin >> C[i];

    int ans = B[A[0]-1];
    for(int i = 1; i < N; ++i){
        if(A[i] == A[i-1]+1){
            ans += C[A[i-1]-1];
        }
        ans += B[A[i]-1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int i, j, k, num;
  scanf("%d", &num);
 
  int M[num][2];
  for(i=0; i<num; i++)
    {
      scanf("%d", &M[i][0]);
      scanf("%d", &M[i][1]);
    }
 
  int x[num][num];
 
  for(i=1; i<num; i++)
    {
      for(j=0; j<num; j++)
    {
      x[i][j]=999999;
    }
    }
 
  for(j=0; j<num; j++)
    {
      x[0][j]=0;
    }
  for(j=0; j<num-1; j++)
    {
      x[1][j]=M[j][0]*M[j][1]*M[j+1][1];
    }
 
    for(i=2; i<num; i++)
    {
      for(j=0; j<num-i; j++)
    {
      for(k=0; k<i; k++)
        {
          if(x[i][j]>x[k][j]+x[i-k-1][j+k+1]+M[j][0]*M[i+j][1]*M[j+k][1])
        {
          x[i][j]=x[k][j]+x[i-k-1][j+k+1]+M[j][0]*M[i+j][1]*M[j+k][1];
        }
        }
    }
    } 
 
  printf("%d\n", x[num-1][0]);
 
  return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> vec(N), accum(N+1);
    rep(i,1,N){
        vec[i] = S.substr(i-1,2) == "AC";
    }
    
    rep(i,0,N){
        accum[i+1] = accum[i] + vec[i];
        //cout << accum[i+1] << endl;
    }
    
    rep(i,0,Q){
        int l,r;
        cin >> l >> r;
        r--,l--;
        cout << accum[r+1] - accum[l+1] << endl;
    }
}

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

typedef long long ll;
#define fr(i,n) for(int i = 0;i<n;i++)

#define prin(a) cout << #a << " = " << a << endl

#define eb emplace_back
#define all(v) (v).begin(),(v).end()

int main(){
    ll a, b, c;
    
    cin >> a >> b >> c;
    
    cout << min(c,b/a) << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class DisjointSet {
    public:
        DisjointSet(int n) : N(n), pars(n, -1) {

        }

        int find(int x) {
            return pars[x] < 0 ? x : (pars[x] = find(pars[x]));
        }

        bool merge(int x, int y) {
            x = find(x), y = find(y);
            if (x == y) {
                return false;
            }

            if (pars[x] < pars[y]) {
                swap(x, y);
            }
            pars[y] += pars[x];
            pars[x] = y;
            return true;
        }

    private:
        int N;
        vector<int> pars;
};

class Solution {
public:
    long long solve(vector<pair<int,int>>& P) {
        int n = P.size();
        DisjointSet ds(n);

        map<int,int> xm;
        map<int,int> ym;

        for (int i = 0; i < n; ++i) {
            int x = P[i].first;
            int y = P[i].second;
            if (xm.count(x) == 0) {
                xm[x] = i;
            } else {
                ds.merge(i, xm[x]);
            }
            if (ym.count(y) == 0) {
                ym[y] = i;
            } else {
                ds.merge(i, ym[y]);
            }
        }

        vector<vector<int>> Xs(n);
        vector<vector<int>> Ys(n); 
        for (int i = 0; i < n; ++i) {
            int x = ds.find(i);
            Xs[x].push_back(P[i].first);
            Ys[x].push_back(P[i].second);
        } 

        long long res = 0;
        for (int i = 0; i < n; ++i) {
            sort(Xs[i].begin(), Xs[i].end());
            Xs[i].resize(unique(Xs[i].begin(), Xs[i].end()) - Xs[i].begin());
            sort(Ys[i].begin(), Ys[i].end());
            Ys[i].resize(unique(Ys[i].begin(), Ys[i].end()) - Ys[i].begin());

            res += Xs[i].size() * 1LL * Ys[i].size();
        }
        res -= n;
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int,int>> P;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        P.emplace_back(x, y);
    }

    Solution sol;
    cout << sol.solve(P) << "\n";

    return 0;
}

Measured memory_bytes: 12404
n, m = map(int, input().split())
Lmax = 0
Rmin = n
for _ in range(m):
  L, R = map(int, input().split())
  Lmax = max(L, Lmax)
  Rmin = min(R, Rmin)
  
print(max(Rmin - Lmax + 1, 0))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
const int MAXN=10000;
using namespace std;

int x[MAXN], y[MAXN];

void mainp()
{
	string s;
	cin>>s;
	string neww="";
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]!='x') neww+=s[i];
	}
	
	int fl=1;
	int sz=neww.size();
	for(int i=0; i<sz; i++) 
		if(neww[i]!=neww[sz-i-1]) {fl=0; break;}
	
	if(fl==0) {cout<<-1<<endl; return;}
	
	int op=0;
	int l=0, r=s.size()-1;
	
	while(l<r)
	{
		if(s[l]==s[r])
		{
			l++;
			r--;
		}
		else if(s[l]=='x'&&s[r]!='x')
		{
			l++;
			op++;
		}
		else if(s[r]=='x'&&s[l]!='x')
		{
			r--;
			op++;
		}
	}
	
	cout<<op<<endl;
}
int main()
{
	mainp();
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

void Main(){
	int a, b, c; cin >> a >> b >> c;
	if((a+b)>=c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;

	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i;
  long long int profit = -2147483648;
  long long int num, min;

  scanf("%lld", &num);
  scanf("%lld", &min);
  for (i = 1; i < num; i++) {
    long long int n;
    scanf("%lld", &n);
    if (profit < (n - min))
      profit = n - min;
    if (min > n)
      min = n;
  }

  printf("%lld\n", profit);

  return 0;
}



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

ll gcd(ll a,ll b){
   if(b<a) swap(a,b);
   ll r = a%b;
   while(r){
       a = b;
       b = r;
       r = a%b;
   }
   return b;
}

int main(){
    ll n,m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    bool isPossible=true;
    ll g = gcd(n,m),n1=n/g,m1=m/g;
    for(int i = 0;i < g;i ++){
        if(s[i*n1]!=t[i*m1]) {isPossible=false;break;}
    }
    cout << (isPossible?n1*m:-1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>


 int main()
 {
 	int a,b,c;
 	scanf("%d %d %d", &a,&b,&c);
 	if(a < b && b < c)
 	{
 		printf("Yes\n");
	 }
    else
	{
		printf("No\n");
	}
 	
 	return 0;
 }


Measured memory_bytes: 2596
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

bool C[3][100007];
ll dp[3][100007];
vector<vector<ll>> V(100007);

ll dfs(ll A,ll B,ll T){
  if(C[A][B]){
    return dp[A][B];
  }
  ll K=1;
  if(A){
    rep(i,V[B].size()){
      if(V[B][i]!=T){
        K*=dfs(0,V[B][i],B);
        K%=MOD;
      }
    }
  }
  else{
    rep(i,V[B].size()){
      if(V[B][i]!=T){
        K*=dfs(0,V[B][i],B)+dfs(1,V[B][i],B);
        K%=MOD;
      }
    }
  }
  C[A][B]=1;
  dp[A][B]=K;
  return K;
}

int main(){
  ll N;
  cin >> N;
  rep(i,N-1){
    ll X,Y;
    cin >> X >> Y;
    V[X].pb(Y);
    V[Y].pb(X);
  }
  ll ans=dfs(0,1,0)+dfs(1,1,0);
  cout << ans%MOD << endl;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    string a(n,m+'0'),b(m,n+'0');
    if(a<b)cout<<a<<endl;
    else cout<<b<<endl;
}


Measured memory_bytes: 256
# https://abc084.contest.atcoder.jp/tasks/abc084_c

def main():
    N = int(input())
    # C: 所要時間、S: 始発の時間、F: 発射間隔
    CSFs = [list(map(int, input().split())) for _ in range(N-1)]
    C = [CSF[0] for CSF in CSFs]
    S = [CSF[1] for CSF in CSFs]
    F = [CSF[2] for CSF in CSFs]

    for i in range(N):
        total = 0
        for j in range(i, N-1):
            if total < S[j]:
                total = S[j] + C[j]
            elif total % F[j] == 0:
                total += C[j]
            else:
                total += C[j] + (F[j] - total % F[j])
        print(total)


main()




Measured memory_bytes: 3188
def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    inf = 1 << 40
    max_attack = max(magic_list)[0]
    dp = [inf] * (h + max_attack)
    dp[0] = 0

    # time O(HN)
    for hp in range(1, h + max_attack):
        for attack, mp in magic_list:
            if hp >= attack and dp[hp - attack] < inf:
                dp[hp] = min(dp[hp], dp[hp - attack] + mp)

    return min(dp[h:])


main()


Measured memory_bytes: 40176
#include <bits/stdc++.h>
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
char tmp[MAXN];
 
int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int l = a + b;
    int r = c + d;
    if (l < r) printf("Right\n");
    else if (l > r) printf("Left\n");
    else printf("Balanced\n");
    return 0;
}


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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int disfs[n];

	disfs[0]=0;
	for(int i=0;i<n-1;i++){
		int temp;
		cin >> temp;
		disfs[i+1]=disfs[i]+temp;
	}

	int ans=0;
	int from=0;
	for(int i=0;i<m;i++){
		int to;
		cin >> to;
		int dis=abs(disfs[from+to]-disfs[from]);
		ans+=dis;
		ans%=100000;
		from+=to;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1548
#include <stdio.h>

int main() {

	int Time = 0;

	for (int i = 0; i < 4; i++) {
		int t;
		scanf("%d", &t);
		Time += t;
	}

	printf("%d\n%d\n", Time / 60, Time % 60);

	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
int main ()
{  string s;
	cin>>s;
	ll c1=0 , c2=0 ;
	for(int i=0 ; i<3;i++)
    {
        if(s[i]=='A') c1++ ;
        if(s[i]=='B') c2++ ;
    }
    if(c1==0|| c2==0){cout<<"No"<<endl;}
    else {cout<<"Yes" << endl ;}
    return 0 ;
}



Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, K = rl()
A = []
for i in range(K):
	d = ri()
	a = rl()
	A.append(a)

cnt = [0] * N
for a in A:
	for i in a:
		cnt[i-1] = 1
ans = 0
for c in cnt:
	if c == 0:
		ans += 1
print(ans)


Measured memory_bytes: 67896
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
res = 0

def mull(Ai):
    res = C
    for i in range(M):
        res += Ai[i] * B[i]
    return res

for i in range(N):
    Ai = list(map(int,input().split()))
    if mull(Ai) > 0:
        res += 1

print(res)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);
  vector<int> p(n);
  vector<int> q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  int a, b;
  int count = 0;
  do {
    count++;
    bool b1 = true;
    bool b2 = true;
    rep(i,n) {
      if (p[i] != v[i]) b1 = false;
    }
    if (b1) a = count;
    rep(i,n) {
      if (q[i] != v[i]) b2 = false;
    }
    if (b2) b = count;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(a-b) << endl;
}

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

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




int main(void){
int h,w;

for(;;){
    scanf("%d %d",&h,&w);
    if(h==w&&h==0){break;}

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}



return 0;
}



Measured memory_bytes: 2116
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    bool isOk = true;
    if (N % 2 == 1) isOk = false;
    if (S.substr(0, N / 2) != S.substr(N / 2, N / 2)) isOk = false;

    string ans = isOk ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588
SIZE=5*10**5; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):
    finv[i-1] = finv[i]*i%MOD
    inv[i] = finv[i]*fac[i-1]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0

def f(x,y):
    return fac[x]*finv[x-y]%MOD
    
    
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m = map(int,readline().split())

ans = 0
r = 1
for u in range(n+1):
    ans += r*f(m-u,n-u)*choose(n,u)%MOD
    ans %= MOD
    r *= -1



print(ans*f(m,n)%MOD)



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


def main():
    n = int(input())
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)
        divisors.sort()
        return divisors
    l = make_divisors(n)
    if len(l)%2 == 0:
        choices = [l[len(l)//2-1], l[len(l)//2]]
        print(choices[0] + choices[1] - 2)
    else:
        print(l[len(l)//2] * 2 - 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3292
def eee(s,k):
    a = s[k-1]
    k = list(filter(lambda x:x!=a,s))
    z = ''.join(s)
    for i in k:
        z = z.replace(i,'*')
    return z

n = int(input())
s = list(input())
k = int(input())
print(eee(s,k))

Measured memory_bytes: 3060
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();
		int c = sc.nextInt();
		int k = sc.nextInt();

		for (int i=1; i<=k; i++){
			if (a > b && a > c){
				a = a*2;
			} else if (b > c){
				b = b*2;
			} else {
				c = c*2;
			}
		}
		System.out.println(a+b+c);
	}

}


Measured memory_bytes: 21844
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
l = list(range(X+1))
r = list(range(X+1, N+1))
lc, rc = 0,0
for a in A:
    if a in l:
        lc += 1
    if a in r:
        rc += 1
print(min(lc, rc))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <cmath>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
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()
{
  //input
  inputInt(N);
  vector<pair<int,int>> a(N);//<人数,番号>
  for(int i=0; i<N; i++){
    cin >> a[i].first;
    a[i].second = i+1;
  }
  sort(a.begin(), a.end());
  
  // output
  for(int i=0; i<N; i++){
    cout << a[i].second << " ";
  }
  cout << endl;
    
  return 0;
}

Measured memory_bytes: 1664