akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif
using namespace std;

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
typedef unsigned char byte;
typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

const int MAXN = 330;
int N, M;
int mat[MAXN][MAXN];
int cnt[MAXN];
int ptr[MAXN];
bool dump[MAXN];
int dumpcnt;

int most()
{
    int res = 0;
    int ma = INT_MIN;
    for (int i = 1; i <= M; ++i)
    {
        if (!dump[i] && cnt[i] > ma)
        {
            ma = cnt[i];
            res = i;
        }
    }
    return res;
}

int main()
{
    while (cin >> N >> M)
    {
        memset(dump, 0, sizeof(dump));
        memset(ptr, 0, sizeof(ptr));

        FO (i, N) FO (j, M)
            cin >> mat[i][j];

        int res = INT_MAX;
        FO (d, M)
        {
            memset(cnt, 0, sizeof(cnt));
            FO (i, N)
            {
                for (; ptr[i] < M; ++ptr[i])
                {
                    if (!dump[mat[i][ptr[i]]])
                    {
                        ++cnt[mat[i][ptr[i]]];
                        break;
                    }
                }
            }
            int mo = most();
            res = min(res, cnt[mo]);
            dump[mo] = true;
        }
        cout << res << endl;
    }
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,count_n,count_m;
    cin>>n>>m;
    count_n = (n*(n-1))/2;
    count_m = (m*(m-1))/2;
    cout<< count_n + count_m;
}


Measured memory_bytes: 256
import scala.io.StdIn._

import Math._
object Main extends App {
  val eps0 = 1e-12

  val q = readLine.toInt
  for (i <- 0 until q) {
    val Seq(xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3) = readLine.split(' ').map(_.toDouble).toList
    val sx1 = xp1 - xp0
    val sy1 = yp1 - yp0
    val sx2 = xp3 - xp2
    val sy2 = yp3 - yp2
    val vx1 = xp2 - xp0
    val vy1 = yp2 - yp0

    val det = -sx1*sy2 + sy1*sx2

    val t = (-sy2 * vx1 + sx2 * vy1) / det
    val u = (-sy1 * vx1 + sx1 * vy1) / det

    println("%.10f %.10f".format(sx1 * t + xp0, sy1 * t + yp0))
  }
}


Measured memory_bytes: 57620
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A, B, C, X;
    cin >> A >> B >> C >> X;

    ll ans = 0;
    ll Acount = 0;
    ll Bcount = 0;
    ll Ccount = 0;
    while(X - Acount * 500 >= 0 && Acount <= A){
        Bcount = 0;
        while(X - Acount * 500 - Bcount * 100 >= 0 && Bcount <= B){
            Ccount = (X - Acount * 500 - Bcount * 100) / 50;
            if(Ccount <= C){
                ans++;
            }
            Bcount++;
        }
        Acount++;
    }

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

Measured memory_bytes: 3580
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> ss(n); cin >> ss;
    vector<int> ts(m); cin >> ts;
    vector<int> dp[2] = {vector<int>(m + 1, 1), vector<int>(m + 1)};
    // vector<vector<int>> dp(2, vector<int>(m + 1, 1));
    for(int i = 0; i < n; i++){
        int i1 = i & 1, i2 = !i1;
        dp[i2][0] = 1;
        int* num = &dp[i2][0];
        int* num2 = &dp[i1][0];
        for(int j = 0; j < m; j++){
            num++;
            num2++;
            if(ss[i] == ts[j]){
                *num = *(num - 1) + *num2;
                if(*num >= M){
                    *num -= M;
                }
            }else{
                *num = *(num - 1) + *num2 - *(num2 - 1);
                if(*num >= M){
                    *num -= M;
                }else if(*num < 0){
                    *num += M;
                }
            }
        }
        if(i == n - 1){
            cout << *num << '\n';
        }
    }
    // printde(dp);
    // cout << dp[n & 1][m] << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),K=sc.nextInt();
		int ans=0;

		for(int i=0;i<N;i++) {
			int h=sc.nextInt();
			if(h>=K) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 47116
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	hs <- sort <$> replicateM n readInt
	print $ minimum $ map abs $ zipWith (-) hs $ drop ( k - 1 ) hs

Measured memory_bytes: 65916
use std::cmp::max;
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:u32 = read();
    let b:u32 = read();
    let c:u32 = read();
    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 5016
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> A(5);
  for(int i = 0;i<A.size();i++){
    cin >> A.at(i);
  }
  priority_queue<int, vector<int>, greater<int>> pq;
  for(int i = 0;i<A.size();i++){
    int b,bb;
    bb = A.at(i)%10;
    if(bb != 0)
      pq.push(bb);
  }
  int sum = 0;
  for(int i = 0;i<A.size();i++){
    if(A.at(i)%10 == 0)
      sum += A.at(i);
    else
      sum += A.at(i)-A.at(i)%10 + 10;
  }
  if(pq.size() != 0)
    cout << sum -10 + pq.top()<< endl;
  else
    cout << sum << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n,m;
  cin >> n >>  m;
  vector<bool> alllike(m,true);
  
  rep(i,n){
    int a;cin >> a;
    vector<bool> Ilike(m,false);
    rep(j,a){
      int t;
      cin >> t;
      Ilike[t-1]=true;
    }
    rep(j,m)if(!Ilike[j])alllike[j]=false;
  }
  
  int cnt=0;
  rep(i,m)if(alllike[i])cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,ans=0,cnt=0;
  cin >> n;
  set<int> st;
  rep(i,n){
    int x;
    cin >> x;
    if(st.find(x)!=st.end()){
      cnt++;
    } else {
      st.insert(x);
    }
  }
  ans = st.size();
  if(cnt%2){ans--;}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_E
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		long d[] = new long[N];
		long dR[] = new long[N];


		for(int i=0; i<N; i++) {
			long x = sc.nextLong();
			long y = sc.nextLong();
			d[i] = x + y;
			dR[i] = 1000000000 - x + y;
		}

		Arrays.sort(d);
		Arrays.sort(dR);

		if(d[N-1]-d[0] > dR[N-1]-dR[0]) {
			System.out.println(d[N-1]-d[0]);
		} else {
			System.out.println(dR[N-1]-dR[0]);
		}

		// Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 63960
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M);
  REP(i, N){
    cin >> a[i] >> b[i];
  }
  REP(i, M){
    cin >> c[i] >> d[i];
  }

  REP(i, N){
    int minj, mind = INF;
    REP(j, M){
      int dist = abs(a[i] - c[j])+abs(b[i] - d[j]);
      if(mind > dist){
        mind = dist;
        minj = j;
      }
    }
    cout << minj + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Id int
	Time int
}

type ByTime []Team
func (a ByTime) Len() int {
	return len(a)
}
func (a ByTime) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a ByTime) Less(i, j int) bool {
	return a[i].Time < a[j].Time
}

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			id, _ := strconv.Atoi(buf[0])
			m1, _ := strconv.Atoi(buf[1])
			s1, _ := strconv.Atoi(buf[2])
			m2, _ := strconv.Atoi(buf[3])
			s2, _ := strconv.Atoi(buf[4])
			m3, _ := strconv.Atoi(buf[5])
			s3, _ := strconv.Atoi(buf[6])
			m4, _ := strconv.Atoi(buf[7])
			s4, _ := strconv.Atoi(buf[8])
			team := Team{id, m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4}
			teams[i] = team
		}
		sort.Sort(ByTime(teams))
		fmt.Println(teams[0].Id)
		fmt.Println(teams[1].Id)
		fmt.Println(teams[len(teams)-2].Id)
	}
}


Measured memory_bytes: 2952
#include <stdio.h>

#define H 250

int parent(int);
int left(int);
int right(int);

int main(){

 int i;
 int n;
 int p;
 int l;
 int r;
 int A[H];

 scanf("%d",&n);

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

 for(i=1;i<=n;i++){
 printf("node %d: key = %d, ",i,A[i]);

 p = parent(i);

 if(p!=0){
 printf("parent key = %d, ",A[p]);
 }

 l = left(i);

 if(l <= n){
 printf("left key = %d, ",A[l]);
 }

 r = right(i);

 if(r <= n){
 printf("right key = %d, ",A[r]);
 }

 printf("\n");
 }
 return 0;
}

int parent(int i){
 return i / 2;
}

int left(int i){
 return 2 * i;
}

int right(int i){
 return 2 * i + 1;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i=0;i<N;i++) cin >> d[i];
    int sum = 0;
    for (int i=0;i<N;i++){
        for (int j=i+1;j<N;j++){
            sum += d[i]*d[j];
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    string s,t;
    cin >> s >> t;
    int ans = SZ(t);
    for (int i=0;i<SZ(s);++i) {
        if (i + SZ(t) > SZ(s)) break;
        debug(i);
        int cur = 0;
        for (int j=i;j<i+SZ(t);++j) {
            if (s[j] != t[j-i]) cur++;
        }
        debug(cur);
        ans = min(ans,cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<bitset>

using namespace std;

using ll = long long int;

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

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

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> b[i][j];
        }
    }

    vector<vector<bitset<12801>>> dp(h,vector<bitset<12801>>(w,bitset<12801>(0)));

    auto base = 12801/2;

    dp[0][0][base + abs(a[0][0] - b[0][0])] = true;
    dp[0][0][base - abs(a[0][0] - b[0][0])] = true;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 12801; k++){
                if(!dp[i][j][k])continue;
                if(i + 1 < h){
                    auto diff = abs(a[i+1][j] - b[i+1][j]);
                    if(k + diff < 12801){
                        dp[i+1][j][k+diff] = true;
                    }
                    if(k - diff >= 0){
                        dp[i+1][j][k-diff] = true;
                    }
                }
                if(j + 1 < w){
                    auto diff = abs(a[i][j+1] - b[i][j+1]);
                    if(k + diff < 12801){
                        dp[i][j+1][k+diff] = true;
                    }
                    if(k - diff >= 0){
                        dp[i][j+1][k-diff] = true;
                    }
                }
            }
        }
    }

    ll ans = 6400;

    for(int i = 0; i < 12801; i++){
        if(dp[h-1][w-1][i]){
            ans = min(ans,(ll)(abs(i - base)));
        }
    }

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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  vector<int> Y(X);
  sort(Y.begin(), Y.end());
  int t1 = Y[N / 2 - 1];
  int t2 = Y[N / 2];
  for (auto x : X) {
    if (x <= t1) {
      cout << t2 << endl;
    } else {
      cout << t1 << endl;
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3712
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[2];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;


int main(){
    cin>>n>>m;
    a=0;b=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>=m)b++;
    }
    C b E;

}

Measured memory_bytes: 256
D, P = map(int, input().split())    
ans = 0.0
def func(i):
    t = 0
    while(i < P):
        i *= 2
        t += 1
    return t

for i in range(1, D + 1):
    ans += float((1/D)) * float(((1 / 2) ** func(i)))

print(ans)

Measured memory_bytes: 9300
using System;

class Program {
    
    private static int Main() {
        while( true ) {
            var input = Console.ReadLine();
            var values = input.Split( ' ' );

            int n = int.Parse( values[ 0 ] );
            int x = int.Parse( values[ 1 ] );


            if( n == 0 && x == 0 ) { break; }

            int num = GetCombination( 3, n, x );
            Console.WriteLine( num );
        }

 
        return 0;
    }

    /// <summary>
    /// 組み合わせの数を取得
    /// </summary>
    /// <param name="count">合計する数値の個数</param>
    /// <param name="n">数値の最大値</param>
    /// <param name="x">目標とする合計値</param>
    /// <returns>nまでの重複のないcount個の数値の合計がxになる個数</returns>
    private static int GetCombination( int count, int n, int x ) {
        if( count == 1 ) { return ( x > 0 && n >= x ) ? 1 : 0; }

        int sum = 0;
        for( int i = n; i >= count; --i ) {
            sum += GetCombination( count - 1, i - 1, x - i );
        }
        return sum;
    }

}

Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;

int ai[200001];
int av[200001];
vector<int> ga[200001];
vector<int> gb[200001];
int v1[200001];
int v2[200001];
vector<int> p1[200001];
int x=1;

void dfsxd(int j, int v[], vector<int> g[])
{
    p1[x].push_back(j);
    for(int i=0; i<g[j].size(); i++)
    {
        v[j]=x;
        if(!v[g[j][i]]) dfsxd(g[j][i], v, g);
    }
}

void dfs(int j, int v[], vector<int> g[])
{
    for(int i=0; i<g[j].size(); i++)
    {
        v[j]=x;
        if(!v[g[j][i]]) dfs(g[j][i], v, g);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, l;
    cin >> n >> k >> l;
    for(int i=0; i<k; i++)
    {
        int s, f;
        cin >> s >> f;
        ga[s].push_back(f);
        ga[f].push_back(s);
    }
    for(int i=0; i<l; i++)
    {
        int s, f;
        cin >> s >> f;
        gb[s].push_back(f);
        gb[f].push_back(s);
    }
    for(int i=1; i<=n; i++)
    {
        if(!v1[i]&&!ga[i].empty())
        {
            dfsxd(i, v1, ga);
            x++;
        }
    }
    x=1;
    for(int i=1; i<=n; i++)
    {
        if(!v2[i]&&!gb[i].empty())
        {
            dfs(i, v2, gb);
            x++;
        }
    }
    int ind=1;
    for(int i=1; i<=n; i++)
    {
        if(ai[i]||!v1[i]||!v2[i]) continue;
        ai[i]=ind;
        for(int j=0; j<p1[v1[i]].size(); j++)
        {
            if(v1[i]==v1[p1[v1[i]][j]]&&v2[i]==v2[p1[v1[i]][j]])
            {
                ai[p1[v1[i]][j]]=ind;
                av[ind]++;
            }
        }
        ind++;
    }
    for(int i=1; i<=n; i++)
        cout << max(1, av[ai[i]]) << " ";
}

//TODO: 49


Measured memory_bytes: 25728
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b,c;
	a=b=0;
	cin>>c;
	for(int d=0;d<c;d++){
		string e,f;
		cin>>e>>f;
		if(e==f){a++;b++;}
		else {
			vector<string>g(2);
			g[0]=e;g[1]=f;
			sort(g.begin(),g.end());
			if(e==g[0])b+=3;
			else a+=3;
			}
		}
		cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}
int n, W;
int w[101];
ll  v[101];
ll dp[101][100001];

int main()
{
    cin >> n >> W;
    rep(i,n) {
        cin >> w[i] >> v[i];
    }
    for (int i = n -1; i>= 0; i--) {
        for(int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i][j] = dp[i+1][j];
            } else {
                dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[0][W] << endl;
    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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 Inf = 1000000000;
ll inf = 1000000000000;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	int i;
	int a[1100], b[1100];
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	ll T = 1;
	ll A = 1;
	for (i = 0; i < n; i++) {
		ll x = max((T + a[i] - 1) / a[i], (A + b[i] - 1) / b[i]);
		T = x * a[i];
		A = x * b[i];
	}
	cout << T + A;
	return(0);
}

Measured memory_bytes: 256
import math
from functools import reduce
import itertools

def cf(x1,x2):
    cf=[1]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def solve():
    a, b, k = map(int, input().split())
    print(cf(a, b)[-k])
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3688
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), x - n3 - n2 - 1, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6428
l1=[]
ret=0
c=0
n,k=map(int,input().split())
for i in range(n):
  l1.append(input().split())
num=[0]*(10**5)

for j in range(n):
  num[int(l1[j][0])-1]+=int(l1[j][1])
#print(num)
for l in range(10**5):
  if num[l]>=k:
    print(l+1)
    break
  k-=num[l]

Measured memory_bytes: 34964
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline int updiv(int a, int b){return((a+b-1) / b);}

bool prime(int n){
    if((n & 1) == 0)return(n == 2);
    for(int i=3; i*i<=n; i+=2){
        if(n % i == 0)return(false);
    }
    return(true);
}

int main()
{
    FAST();
    int n, a, cnt = 0;
    cin >> n;
    while(n--){
        cin >> a;
        cnt += prime(a);
    }
    outl(cnt);
}

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

int main(){

  ll H,W=0;

  cin>>H>>W;  
	
  string s[H];
  rep(i,H){

    cin>>s[i];
    
  }
  
  map<int,int> mp1;
  map<int,int> mp2;
  
  
  rep(i,H){
    mp1[i]=0;
    
    int flag=0;
    rep(j,W){

      if(s[i][j]=='#')flag=1;
      
    }
    if(flag==0)mp1[i]=1;
    flag=0;
  }
  
  
  rep(j,W){
    mp2[j]=0;
    
    int flag=0;
    rep(i,H){

      if(s[i][j]=='#')flag=1;

    }
    if(flag==0)mp2[j]=1;
    flag=0;
    
  }
  
  rep(i,H){

    rep(j,W){

      if(mp1[i]==0 && mp2[j] ==0)cout<<s[i][j];
      
    }
    if(mp1[i]==0)cout<<endl;
    
  
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
  int n;cin >> n;int p;cin >> p;
  p += n*3;
  cout << p/2  << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  string s;
  cin >> s;
  ll cnt = 0;
  for(ll i = 1; i < s.size(); i++){
    if(s[i] == '9') cnt++;
  }
  if(cnt == s.size()-1) cout << (s[0]-'0') + (s.size()-1)*9 << endl;
  else cout << (s[0]-'0'-1) + (s.size()-1)*9 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a[5] = {};
    int t;
    for (int i = 0; i < 6; i++)
    {
        scanf("%d", &t);
        a[t]++;
    }
    for (int i = 1; i <= 4; i++)
    {
        if (a[i] == 3)
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cstdio>

const int N = 300000;
const int MOD = (int)1e9 + 7;

int inv[N + N + 1], a, b, c, bn_b[N], bn_c[N];

void update(int& x, int a)
{
    x += a;
    if (x >= MOD) {
        x -= MOD;
    }
}

void prepare(int* bn, int a, int b) // bn[i] = binom{i + b}{b} 0 <= i < a
{
    bn[0] = 1;
    for (int i = 1; i < a; ++ i) {
        bn[i] = 1LL * bn[i - 1] * (i + b) % MOD * inv[i] % MOD;
    }
}

int binom[1000][1000];

int main()
{
// #ifdef LOCAL_JUDGE
//     freopen("F.in", "r", stdin);
// #endif
    inv[1] = 1;
    for (int i = 2; i <= N + N; ++ i) {
        inv[i] = 1LL * (MOD - MOD / i) * inv[MOD % i] % MOD;
    }
    while (scanf("%d%d%d", &a, &b, &c) == 3) {
        a --;
        prepare(bn_b, b, c);
        prepare(bn_c, c, b);
        int three = 1;
        for (int i = 0; i < b + c; ++ i) {
            three = 3LL * three % MOD;
        }
        int bn_a = 1;
        int ds = 1;
        int result = three;
        for (int s = 1; s <= b + c; ++ s) {
            three = 1LL * three * inv[3] % MOD;
            bn_a = 1LL * bn_a * (s + a) % MOD * inv[s] % MOD;
            ds = 2LL * ds % MOD;
            if (s > b) {
                update(ds, MOD - bn_c[s - b - 1]);
            }
            if (s > c) {
                update(ds, MOD - bn_b[s - c - 1]);
            }
            update(result, 1LL * bn_a * ds % MOD * three % MOD);
        }
        printf("%d\n", result);
    }
}


Measured memory_bytes: 6656
using System;
class aoj
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        string[] k = new string[a];
        for(int b = 0; b < a; b++)
        {
            string[] c = Console.ReadLine().Split(' ');
            int[] d = new int[10];
            int[] e = new int[10];
            int d1 = 0,e1 = 0;

            int[] f = new int[10];
            for(int i = 0; i < 10; i++)
            {
                f[i] = int.Parse(c[i]);
            }
            d[0] = f[0];
            d1++;
            e[0] = f[1];
            e1++;
            for(int i = 2; i < 10; i++)
            {
                if ((f[i] - d[d1-1] < f[i] - e[e1-1] && f[i] >d[d1-1])||(f[i]>d[d1-1]&&f[i]<e[e1-1]))
                {
                    d[d1] = f[i];
                    d1++;
                }
                else if ((f[i] - e[e1 - 1] < f[i] - d[d1 - 1]&&f[i]>0)|| (f[i] >e[e1 - 1]&&f[i]<d[d1-1]))
                {
                    e[e1] = f[i];
                    e1++;
                }
                else
                {
                    k[b] = "NO";
                    goto stop;
                }
            }
            k[b] = "YES";
            stop:;
        }
        foreach(string i in k)
        {
            Console.WriteLine(i);
        }
    }	
}

Measured memory_bytes: 8832
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

	if ((S[2] == S[3]) && S[4] == S[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
L,R = (int(i) for i in input().split())
ans=0
amari=2018
if R-L>=2018:
    print(ans)
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            if amari>=(i*j)%2019:
                amari=(i*j)%2019
    print(amari)


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 2; return 0;
  }

  vector<ll> B(100, 0);
  ll max_digit = 0;
  rep0(i, 100) {
    B[i] = N % 2;
    N /= 2;
    max_digit = i + 1;
    if (N == 0) break;
  }

  ll MOD = 1e9 + 7;
  vector<ll> dp_eq(max_digit, 0), dp_ls1(max_digit, 0), dp_ls2(max_digit, 0);
  dp_eq[max_digit - 1] = dp_ls1[max_digit - 1] = 1;
  dp_ls2[max_digit - 1] = 0;

  repR0(i, max_digit - 1) {
    if (B[i] == 1) {
      dp_eq[i] = dp_eq[i + 1];
      dp_ls1[i] = dp_eq[i + 1] + dp_ls1[i + 1];
      dp_ls2[i] = dp_ls1[i + 1] * 2 + dp_ls2[i + 1] * 3;
    } else {
      dp_eq[i] = dp_eq[i + 1] + dp_ls1[i + 1];
      dp_ls1[i] = dp_ls1[i + 1];
      dp_ls2[i] = dp_ls1[i + 1] + dp_ls2[i + 1] * 3;
    }
    if (dp_ls2[i] == 0) dp_ls2[i] = 1;
    dp_eq[i] %= MOD;
    dp_ls1[i] %= MOD;
    dp_ls2[i] %= MOD;
  }

  ll ans = (dp_eq[0] + dp_ls1[0] + dp_ls2[0]) % MOD;
  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void){

	int a[3];
	int i, j;
	
	for(i = 0; i < 3; i++){
		scanf("%d", &a[i]);
	}

	int K;
	scanf("%d", &K);

	int temp = 0;

	for(i = 0; i < 2; i++){
		for(j = 1; j < 3; j++){

			if(a[i] > a[j]){
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}

		}
	}

	int count = 0;

	while(count != K){
		a[2] = a[2] * 2;
		count++;
	}

	int ans = 0;

	ans = a[0] + a[1] + a[2];
	printf("%d\n", ans);

	return 0;

}

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

using Graph=vector<vector<int>>;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string> o(n);
    for(int i=1;i<n;i++) cin>>o[i];

    Graph g(n);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    function<int(int,int,int,int,int,int)> game=[&](int v,int pre,int dep,int t,int x,int y){
        if(v==0){
            t=0;
        }
        else{
            int tar=(o[v][4]=='X' ? x : y);
            if(o[v][3]=='&') t&=tar;
            if(o[v][3]=='|') t|=tar;
            if(o[v][3]=='^') t^=tar;
        }
        if(g[v].size()==1 && g[v][0]==pre) return t;
        const int INF=1e9;
        int res=(dep&1) ? INF : 0;
        for(int i=0;i<g[v].size();i++){
            if(g[v][i]!=pre){
                if(dep&1) res=min(res,game(g[v][i],v,dep+1,t,x,y));
                else res=max(res,game(g[v][i],v,dep+1,t,x,y));
            }   
        }
        return res;
    };
    map<pair<int,int>,int> val;
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            set<pair<int,int>> s;
            bool isok=true;
            for(int k=0;k<3;k++){
                int xb=((i>>k)&1),yb=((j>>k)&1);
                if(xb || yb){
                    isok&=!(s.count(make_pair(xb,yb)));
                    s.insert(make_pair(xb,yb));
                }
            }   
            if(!isok)continue;
            val[make_pair(i,j)]=game(0,0,0,0,i,j);
        }
    }

    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        set<pair<int,int>> s;
        int realx=0,realy=0;
        for(int j=20;j>=0;j--){
            int xb=(x>>j)&1,yb=(y>>j)&1;
            if(xb|yb){
                if(!s.count(make_pair(xb,yb))){
                    s.insert(make_pair(xb,yb));
                    realx<<=1,realy<<=1;
                    realx+=xb,realy+=yb;
                }
            }
        }
        int res=0;
        assert(val.count(make_pair(realx,realy)));
        int tar=val[make_pair(realx,realy)];
        for(int j=0;j<18;j++){
            int xb=(x>>j)&1,yb=(y>>j)&1;
            for(int k=0;k<4;k++){
                if((xb==((realx>>k)&1)) && (yb==((realy>>k)&1))){
                    res+=((tar>>k)&1)<<j;
                    break;
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 29484
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}



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

 



Measured memory_bytes: 3048
import java.util.Scanner;

public class Main {
    private static final String YES = "YES";
    private static final String NO = "NO";

    public static String process(TestCase testCase) {
        int X = testCase.X;

        return is753(X) ? YES : NO;
    }

    private static boolean is753(int x) {
        return x == 7 || x == 5 || x == 3;
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        sc.close();
        return new TestCase(X);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int X;

        public TestCase(int X) {
            this.X = X;
        }
    }
}


Measured memory_bytes: 21844
/*
 * 英小文字 c が与えられるので、c が母音であるか判定してください。ここで、英小文字のうち母音は a、e、i、o、uの 5 つです。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            String s = sc.next();
            
            if(s.equals("a") || s.equals("i") || s.equals("u") || s.equals("e") || s.equals("o")){
            	System.out.println("vowel");
            }else{
            	System.out.println("consonant");
            }
            sc.close();
        }
    }
	

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+')
    cout << a + b << endl;
  else
    cout << a - b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll c[550], s[550], f[550];

int main(){
    int n;
    cin >> n;
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

    
    for (int k = 0; k < n; k++){
        ll now = 0;
        for(int i = k; i < n - 1; i++){
            ll p;
            if (now <= s[i]) p = 0;
            else p = (now - s[i] + f[i] - 1) / f[i];
            now = s[i] + p * f[i] + c[i];
        }
        cout << now << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  int min=1000,max=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a<min)min=a;
    if(a>max)max=a;
  }
  cout<<max-min<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	char c=s[k-1];
	if(c >= 'a'&&c <= 'z')
		c -= 32;
	else if(c >= 'A'&&c <= 'Z')
		c += 32;
	s[k-1]=c;
	cout<<s<<endl;
	return 0;
}

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


int main(){
    int n,x;
    cin >> n >> x;
    if(x==1 || x==2*n-1) cout << "No" << endl;
    else if(x < n){
        cout << "Yes" << endl;
        for(int i=n; i>0; i--){
            if(i == x)continue;
            cout << i << ' ';
        }
        cout << x << ' ';
        for(int i = n+1; i<2*n; i++){
            cout << i << ' ';
        }
        cout << endl;
    }
    else if(x == n){
        cout << "Yes" << endl;
        for(int i=1; i<=2*n-1; i++){
            cout << i << ' ';
        }
        cout << endl;
    }
    else {
        cout << "Yes" << endl;
        for(int i=1; i<n; i++){
            cout << i << ' ';
        }
        cout << x << ' ';
        for(int i=2*n-1; i>=n; i--){
            if(i == x) continue;
            cout << i << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(void)
{
	int n, q, S[100000], T[50000], count = 0, i, j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> S[i];
	}
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> T[i];
	}
	for (i = 0; i < q; i++) {
		int a = 0, b = n - 1, ab;
		for (j = 0; j < (n / 2) + (n % 2); j++) {
			ab = ((b - a + 1) / 2) + a;
			if (S[ab] == T[i]) {
				count++; break;
			}
			else {
				if (S[ab] < T[i]) { a = ab + 1; }
				else {
					b = ab - 1;
				}
			}
		}
	}
	printf("%d\n", count);
}

Measured memory_bytes: 1728
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; 
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
 
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'
 
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 
 
const ll MOD = 998244353;
const ll INF = 1e9 + 7;

const int MX = 1e5 + 5;
int N;
ll ans, A[MX], DP[MX][2];

//check int vs ll and precision
//check logic
int main(){ FAST

	cin >> N;
	FOR(i,1,N+1) cin >> A[i];

	//DP[i-1][0] = max from [1,i] if not used at i - 1
	DP[1][0] = A[1] + A[2]; DP[1][1] = -A[1]-A[2];
	FOR(i,2,N){
		//DP[i][0], DP[i][1] = max from [1,i+1]
		DP[i][0] = max({DP[i-1][0]+A[i+1],DP[i-1][1]+A[i+1]});
		DP[i][1] = max({DP[i-1][0]-2*A[i]-A[i+1],DP[i-1][1]+2*A[i]-A[i+1]});
	}
	//FOR(i,0,N) F0R(j,2) bug(i _ j _ DP[i][j]);
	ans = max({ans,DP[N-1][0],DP[N-1][1]});
	finish(ans);

	


    return 0;
}


Measured memory_bytes: 5944
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define sz 200000
typedef long long ll;
using namespace std;
int main()
{

         int n;
         cin>>n;
         if(n>=400&&n<=599)
            cout<<8;
         if(n>=600&&n<=799)
            cout<<7;
         if(n>=800&&n<=999)
            cout<<6;
         if(n>=1000&&n<=1199)
            cout<<5;
        if(n>=1200&&n<=1399)
            cout<<4;
        if(n>=1400&&n<=1599)
            cout<<3;
        if(n>=1600&&n<=1799)
            cout<<2;
        if(n>=1800&&n<=1999)
            cout<<1;

return 0;

}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
int32_t main() {
	IAMSPEED
	// set testing to 0 when submitting to judge
	int n; cin >> n;
	bool can = 1;
	FOR(i,1,n) {
		int x; cin >> x;
		if(x%2==0) {
			if(x%3!=0&&x%5!=0)can = 0;
		}
	}
	if(can) cout << "APPROVED";
	else cout << "DENIED";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = [ii() for _ in range(N)]
    dic = {}
    for a in A:
        if (not a in dic) or (dic[a] == 0):
            dic[a] = 1
        else:
            dic[a] = 0
    print(sum(dic.values()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 89620
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

vector <int> v;
char s[maxn];

int main()
{
	int n=read(); scanf("%s",s+1);
	for(int i=1;i<n;i++) v.push_back(abs(s[i]-s[i+1]));
	int f=0,p=v.size()-1,ans=0;
	for(int i=0;i<v.size();i++) if(v[i]==1) f=1;
	for(int i=0;i<v.size();i++) if((p&i)==i) ans+=v[i]; ans%=2;
	if(ans==0)
	{
		if(f==1) puts("0");
		else
		{
			int c1=0,c2=0; ans=0;
			for(int i=0;i<v.size();i++) v[i]/=2;
			for(int i=0;i<v.size();i++) if((p&i)==i) ans+=v[i]; ans%=2;
			if(ans==0) puts("0"); else puts("2");
		}
	}
	else puts("1");
	return 0;
}

Measured memory_bytes: 7280