akhauriyash/Code-Regression huggingface dataset:
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(r: usize, g: usize, b: usize, n: usize);

    let nax = 3001;
    let mut ans = 0;
    for i in 0..nax {
        for j in 0..nax {
            let rem: i64 = n as i64 - (r * i + g * j) as i64;
            if rem < 0 {
                continue;
            }
            if rem as usize % b == 0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>

using namespace std;

#define LL long long
#define FOR(i,l,r) for(int i = l; i <= r; ++i)
#define REP(i,l,r) for(int i = l; i < r; ++i)
#define pi pair<int,int>
#define mp make_pair

const int maxN = 1e5 + 11;
const LL oo = 1e17 + 11;
const int msk = 1 << 12;

int N,M;
int A[maxN];
vector <int> e[maxN];
LL F[1001][msk];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    //
    cin >> N >> M;
    FOR(i,1,M){
        int d,x;
        cin >> A[i] >> d;
        FOR(j,1,d){
            cin >> x;
            e[i].push_back(x);
        }
    }

    int woosh = 1 << N;
    FOR(i,0,M) REP(j,0,woosh) F[i][j] = oo;
    F[0][0] = 0;
    //
    REP(i,0,M) REP(j,0,woosh) if(F[i][j] < oo){
        F[i + 1][j] = min(F[i + 1][j],F[i][j]); // không chọn i + 1
        int newMask = j;
        REP(k,0,e[i + 1].size()){
            int z = e[i + 1][k];
            newMask |= (1 << (z - 1));
        }
        F[i + 1][newMask] = min(F[i + 1][newMask],F[i][j] + A[i + 1]);
    }
    
    if(F[M][woosh - 1] >= oo) cout << -1;
    else cout << F[M][woosh - 1];

    return 0;
}

Measured memory_bytes: 34688
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;


int main(){
    int x,n;
    cin>>x>>n;
    vector<bool> f(110,true);
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        f[p]=false;
    }
    int ans=0;
    int dis=100100;
    for(int i=0;i<=101;i++){
        if(!f[i]) continue;
        if(abs(x-i)<dis){
            ans=i;
            dis=abs(x-i);
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (s == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (s == "Rainy") {
    cout << "Sunny" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[100000];

bool solve(){
  if(n==2)return true;
  if( a[n-1] - a[0] > 1 )return false;
  
  int cnt1=upper_bound(a,a+n,1)-a;
  int cnt2=upper_bound(a,a+n,2)-lower_bound(a,a+n,2);
  
  int cntn1=upper_bound(a,a+n,n-1)-lower_bound(a,a+n,n-1);
  int cntn2=upper_bound(a,a+n,n-2)-lower_bound(a,a+n,n-2);
  
  if(cnt1>0){
    if(cnt2==n-1 && cnt1==1)return true;
    if(cnt1==n)return true;
    return false;    
  }

  if(cntn1>0){
    if(cntn1==n)return true;
    if(cntn2==n-2&&cntn1==2)return true;
    return false;
  }

  int mini=a[0];
  if( mini*2 > n )return false;
  return true;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  cout<< ( solve() ? "Yes" : "No" )<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}
int a,b,c;
int main(){
  scanf("%d %d %d",&a,&b,&c);
  if(a==b){
    printf("%d\n", c);
  }else if(b==c){
    printf("%d\n", a);
  }else{
    printf("%d\n", b);
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    System.out.print(c);
    System.out.print(" ");
    System.out.print(a);
    System.out.print(" ");
    System.out.println(b);
  }
}


Measured memory_bytes: 35844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if (A <= B*2) {
            System.out.println(0);
        } else {
            System.out.println(A-B*2);
        }
    }
}

Measured memory_bytes: 21716
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n = int(input())
    A = list(map(int, input().split()))

    ans = 1000
    for i in range(n-1):
        if A[i] < A[i+1]:
            ans += (ans//A[i])*(A[i+1]-A[i])
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int i, x, N, K;
  x = 1;
  cin >> N >> K;

  for(i = 0; i < N; i++){
  	if(x > K) x += K;
    else x *= 2;
  }
  	cout << x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String ans = a%2==1&&b%2==1?"Yes":"No";
    System.out.println(ans);


  }
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()

    fun factorize(n: Long): Map<Long, Int> {
        val r = mutableMapOf<Long, Int>()
        var x = n
        var i = 2L
        while (i * i <= n) {
            while (x % i == 0L) {
                r[i] = (r[i] ?: 0) + 1
                x /= i
            }
            i++
        }
        if (x > 1) {
            r[x] = (r[x] ?: 0) + 1
        }
        return r
    }

    val fs = factorize(n)
    val keys = fs.keys.toList()

    fun rec(list: List<Long> = emptyList()): Long {
        if (fs.isEmpty()) return 0L

        if (list.size == fs.size) {
            val x = list.reduce { acc, l -> acc * l } - 1
            return if (x > 0 && n / x == n % x) x else 0L
        }

        var r = 0L
        var i = 1L
        val key = keys[list.size]
        val cnt = fs[key] ?: 0
        repeat(cnt + 1) {
            r += rec(list.plus(i))
            i *= key
        }
        return r
    }

    println(rec())
}


Measured memory_bytes: 33760
# include <bits/stdc++.h>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

ll solve(bool b, ll n, ll m) {
    ll res = 1;
    reps(i, n) {
        res = (res * i) % mod;
    }
    reps(i, m) {
        res = (res * i) % mod;
    }
    if (b) return (2 * res) % mod;
    else return res % mod;
}

int main() {
    ll N, M; cin >> N >> M;

    ll absolute = abs(N - M);
    if (2 <= absolute) cout << 0 << endl;
    else if (absolute == 1) cout << solve(false, N, M) << endl;
    else cout << solve(true, N, M) << endl;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> S(N);
  int num = 1;
  
  for(int i = 0;i < N;++i){
    cin >> S[i];
  }

  for(int i = 1;i < N;++i){
    int num2 = 0;
    for(int k = 0;k < i;++k){
      if(S[k] > S[i]){
        num2++;
      }
    }
    if(num2 == 0){
      num++;
    }
  }
  cout << num << endl;
}
  


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n,m;
	cin>>n>>m;
	if(abs(n-m)>1){
		cout<<0;
		return;
	}
	ll ans = 1;
	if(n==m) {
		ans = 2;
	}
	for(int i=2;i<=n;i++)ans=(ans*i)%MOD;
	for(int i=2;i<=m;i++)ans=(ans*i)%MOD;
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


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

int main() {
	
	int r;
	cin >> r;
	if(r < 1200) puts("ABC");
	else if(r < 2800) puts("ARC");
	else puts("AGC");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN = 18000 + 13;
string s;
int x, y, dp1[8013][maxN];
vector<int> vec[2];
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    cin >> x >> y;
    int cur = 0;
    int dir = 0;
    for (int i = 0; i < s.size(); i++) {
	if (s[i] == 'T') {
	    vec[dir].push_back(cur);
	    cur = 0;
	    dir ^= 1;
	}
	else
	    cur++;
    }
    vec[dir].push_back(cur);
    dp1[0][9000] = 1;
    for (int i = 0; i < vec[0].size(); i++)
	for (int j = 0; j < maxN; j++) {
	    if (j - vec[0][i] >= 0)
		dp1[i + 1][j] = dp1[i][j - vec[0][i]];
	    if (i != 0 && j + vec[0][i] < maxN)
		dp1[i + 1][j] |= dp1[i][j + vec[0][i]];
	}
    if (dp1[vec[0].size()][9000 + x]) {
	dp1[0][9000] = 1;
	for (int i = 0; i < vec[1].size(); i++) {
	    for (int j = 0; j < maxN; j++) {
		if (j - vec[1][i] >= 0)
		    dp1[i + 1][j] = dp1[i][j - vec[1][i]];
		if (j + vec[1][i] < maxN)
		    dp1[i + 1][j] |= dp1[i][j + vec[1][i]];
	    }
	}
	if (dp1[vec[1].size()][9000 + y])
	    cout << "Yes" << endl;
	else
	    cout << "No" << endl;
    }
    else
	cout << "No" << endl;
    
}


Measured memory_bytes: 280832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
#define upper(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
//#define min(a) *min_element(a.begin(),a.end())
//#define max(a) *max_element(a.begin(),a.end())
#define pdd pair<long double, long double>
#define prnt(a)      \
	for (auto x : a) \
		cout << x << " ";
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define PI 3.1415926535897932385
#define INF 1000000000000000
#define M 1000000007
#define ve vector<ll>;

int main()
{
	ll n, w;
	cin >> n >> w;
	vector<ll> a(n), wt(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> wt[i];
		cin >> a[i];
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));

	for (ll i = 0; i < n + 1; i++)
	{
		dp[i][0] = 0;
	}
	for (ll i = 0; i < w + 1; i++)
	{
		dp[0][i] = 0;
	}
	for (ll i = 1; i < n + 1; i++)
	{
		for (ll j = 1; j < w + 1; j++)
		{
			if (wt[i - 1] <= j)
			{
				dp[i][j] = max(a[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
			}
			else
			{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 83096
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

uint32_t bit_count(uint32_t val)
{
	uint32_t bits = val;

	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);

	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	uint32_t n, k; cin >> n >> k;

	if ((1U << n) <= k) {
		cout << "-1" << endl;
		return 0;
	}

	if (n == 1) {
		if (k == 0) {
			cout << "0 0 1 1" << endl;
		}
		else {
			cout << "-1" << endl;
		}
		return 0;
	}

	FOR_LT(i, 0, (1U << n)) {
		if (i != k) cout << i << " ";
	}
	cout << k << " ";
	FOR_DW(i, (1U << n) - 1 , 0) {
		if (i != k) cout << i << " ";
	}
	cout << k << " ";

	cout << endl;

	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll solve(string s, char c) {
    ll n = s.length();
    bool judge = true;
    rep(i, n) {
        if (s[i] != c) {
            judge = false;
            break;
        }
    }
    if (judge) {
        return 0;
    }

    string next;
    rep(i, n - 1) {
        if (s[i] == c || s[i + 1] == c) {
            next += c;
        } else {
            next += '?';
        }
    }
    return solve(next, c) + 1;
}

int main() {
source:
    string s;
    cin >> s;
    ll ans = mod;
    for (char c = 'a'; c <= 'z'; c++) {
        ans = min(ans, solve(s, c));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str;
        int a, b;

        str = scanner.next();
        a = Integer.parseInt(str);
        str = scanner.next();
        b = Integer.parseInt(str);

        scanner.close();

        System.out.println(a*b+" "+(2*a+2*b));
    }
}


Measured memory_bytes: 26116
// template ver2.02

// include
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

using namespace std;

// conversion
inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

// typedef
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

// util
#define MP make_pair
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define CLR(a) memset((a), 0 , sizeof(a))
template<class T, class C> inline bool in(T e, C c) {return c.find(e) != c.end();}
template<class T> inline bool in(T x, T a, T b) {return a <= x && x < b;}

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define RREP(i, n) RFOR(i, 0, n)

// IO
#define PRA(a, n) cout << a[0]; FOR(itr, 1, n) {cout << " " << a[itr];} cout << endl;
#define PRF(x, w) cout << setprecision((w)); cout << setiosflags(ios::fixed); cout << (x) << endl;

// constant
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = (int)1e9;
const int DI[] = {0, 1, 0, -1};
const int DJ[] = {1, 0, -1, 0};

// debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DUMPA(a, n) cerr << #a << " = {" << a[0]; FOR(itr, 1, n) { cout << ", " << a[itr]; } cerr << "}" << endl;
#define DUMPAA(a, n, m) REP(itr, n) {REP(jtr, m) {cout << a[itr][jtr] << " ";} cout << endl;}

// template end

int n, m;
int k[3];
vi c[3];

stack<int> s[3];

int dfs(int i, int t) 
{
    if (t > m) return -1;
    if (s[0].size() == n || s[2].size() == n) return t;
    int x, y;
    x = s[i].empty() ? 0 : s[i].top();
    y = s[1].empty() ? 0 : s[1].top();    
    if (x < y) {
        s[i].push(y);
        s[1].pop();
    }
    else {
        s[1].push(x);
        s[i].pop();
    }
    return dfs((i + 2) % 4, t + 1);
}

void init_stack() 
{
    REP(i, 3) s[i] = stack<int>();
    REP(i, 3) REP(j, k[i]) s[i].push(c[i][j]);    
}

void init()
{
}

void solve()
{
    init_stack();
    int t0 = dfs(0, 0);
    init_stack();    
    int t1 = dfs(2, 0);
    int ans = t0;
    if (t1 >= 0) ans = min(ans, t1);
    cout << ans << endl;
}

int main()
{
    init();
    while (cin >> n >> m, n) {
        REP(i, 3) {
            cin >> k[i];
            c[i].clear();
            REP(j, k[i]) {
                int x;
                cin >> x;
                c[i].push_back(x);
            }
        }
        solve();        
    }

    return 0;
}


Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    set<string>st;
    int n;
    string s;
    cin>>n;
    while(n--)
    {
        cin>>s;
        st.insert(s);
    }
    cout<<(int)st.size()<<endl;
    return 0;
}


Measured memory_bytes: 19116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
    int n;
    int a, b, c;
    cin >> n;
    int dp[3][n+1];
    for(int i=0;i<3;i++) {
        for(int j=0;j<n;j++) {
            dp[i][j] = 0;
        }
    }
    //cout << "A" << endl;
    for(int i=1;i<n+1;i++) {
        cin >> a >> b >> c;
        //cout << "A" << endl;
        dp[0][i] = a + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c + max(dp[0][i-1], dp[1][i-1]);            
    }
    //cout << "A" << endl;
    cout << max(dp[0][n], max(dp[1][n], dp[2][n])) << endl;

    //for(int i=0;i<3;i++) {
    //    for(int j=0;j<n+1;j++) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}
}

//a 0 10 90  150
//b 0 40 120 180
//c 0 70 120 210

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-k) {
    if (a[i] < a[k+i]) {
      cout << "Yes\n";
    }
    else {
      cout << "No\n";
    }
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

int main()
{
  int n,tmp,reslt,nc;
  cin >> n;

  reslt = n % 10;
  nc = n / 10;
  
  while(nc)
  {
    tmp = nc % 10;
    reslt = reslt + tmp;
    nc = nc / 10;
  }

  if(n % reslt == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

int n, a[100005];
multiset<int> st;
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; ++i)
    scanf("%d", &x), a[x] = i;
  st.insert(0);
  st.insert(0);
  st.insert(n + 1);
  st.insert(n + 1);
  long long ans = 0;
  for (int i = n; i >= 1; --i) {
    auto it = st.lower_bound(a[i]);
    auto nxt = it; nxt++;
    auto prv = it; prv--;
    auto prvv = prv; prvv--;
    ans += 1LL * i * ((*nxt - *it) * (a[i] - *prv) + (*prv - *prvv) * (*it - a[i]));
    st.insert(a[i]);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 5376
n=int(input())
for i in range(n):
  Y,M,D=map(int,input().split())
  
  if Y%3!=0 and M%2==0:
    day=(19-D)+1
  else:
    day=(20-D)+1

  for j in range(M+1,11):
    #print(j,day)
    if Y%3==0:
      day+=20
    elif j%2==0:
      day+=19
    else:
      day+=20
  #print(day)
  for j in range(Y+1,1000):
    #print(j,day)
    for l in range(1,11):
      if j%3==0:
        day+=20
      elif j%3!=0 and l%2==0:
        day+=19
      else:
        day+=20
  
  print(day)


Measured memory_bytes: 5596
x, n = map(int, input().split())
try:
    a = list(map(int, input().split()))
except EOFError:
    a = []
    
if not x in a:
    print(x)
else:
    d = 1
    while True:
        if x-d not in a:
            print(x-d)
            break
        elif x+d not in a:
            print(x+d)
            break
        else:
            d+=1

Measured memory_bytes: 9188
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/c-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

def f(x):
  out=0
  while x%2==0:
    out+=1
    x//=2
  return out

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])
  
p=[f(a[i]) for i in range(N)]
p.sort()
for i in range(N-1):
  if p[i]!=p[i+1]:
    print(0)
    exit()
    
if c>M:
  print(0)
else:
  print(int((M/c-1)/2)+1)

Measured memory_bytes: 16280
using System;

class program
{
public static void Main()
{
int s;
s = int.Parse(Console.ReadLine());
int h = s/3600;
int x = s%3600;
int m = x/60;
int y = x%60;
Console.Write("{0}:{1}:{2}\n",h,m,y);
}
}

Measured memory_bytes: 5632
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

cnt = [0, 0, 0]
for pi in p:
    if pi <= a:
        cnt[0] += 1
    elif pi <= b:
        cnt[1] += 1
    else:
        cnt[2] += 1
print(min(cnt))


Measured memory_bytes: 9112
s0 = input()
t0 = input()
list_s0 = list(s0)
list_t0 = list(t0)
list_s0.sort()
list_t0.sort(reverse = True)
s1 = "".join(list_s0)
t1 = "".join(list_t0)
if s1 < t1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 1e5+5;
const int MOD = 1e9+7;

int N,M;
char S[MAXN];
char T[MAXN];
int nxt[MAXN][26];
int lst[26];
LL ans;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> S >> T;
    N = strlen(S);
    M = strlen(T);

    ford(i,26) lst[i] = -1;
    ford(i,N-1) lst[S[i]-'a'] = i;

    ford(i,N-1) {
        fori(c,26) nxt[i][c] = lst[c];
        lst[S[i]-'a'] = i;
    }

    int k = lst[T[0]-'a'];
    if (k == -1) {
        ans = -1;
    } else {
        ans = k+1;
        fore(i,1,M-1) {
            int j = nxt[k][T[i]-'a'];
            if(j == -1) {
                ans = -1;
                break;
            }
            if(j <= k) {
                ans += (j+N-k); 
            } else {
                ans += j-k;
            }
            k = j;
        }
    }

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


Measured memory_bytes: 10624
{-
A_iのうち、Xより大きいものの数と、小さいものの数のうち小さいもの
-}
import Data.List
solver::[Int]->Int->Int
solver prs x = let (a,b) = (span (\y-> y<x) prs) in min (length a) (length b)

main::IO()
main=do
  nmxc<-getLine
  let n:m:x:[] = map read (words nmxc)
  d<-getLine
  let dat = map read (words d)
  print (solver dat x)


Measured memory_bytes: 892
#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;

map<ll, ll> prime_factor(ll n) {
      map< ll, ll > ret;
      for(ll i = 2; i * i <= n; i++) {
          while(n % i == 0) {
              ret[i]++;
              n /= i;
          }
      }
      if(n != 1) ret[n] = 1;
      return ret;
}

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ll n, m;
    cin >> n >> m;
    map<ll,ll> mp = prime_factor(m);
    COMinit();
    ll ans = 1;

    for(auto v : mp){
        ll p = v.second;
        ans *= COM(n+p-1, p);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vc<pair<ll, ll>> L(N);
    rep(i, N) cin >> L[i].first >> L[i].second;
    sort(all(L));
    ll ans = 0;
    ll r = -1e9;
    rep(i, N) {
        ll x, l;
        tie(x, l) = L[i];
        if (r <= x - l) {
            ans++;
            r = x + l;
        } else {
            r = min(r, x + l);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    // dp
    public static long knapsack1(int[] w, long[] v, int C) {
        int n = w.length;
        long[][] dp = new long[n][C+1];
 
        for (int c = 1; c <= C; c++) {
            dp[0][c] = (c >= w[0]) ? v[0] : 0;
        }
 
        for (int i = 1; i < n; i++) {
            for (int c = 1; c <= C; c++) {
                dp[i][c] = dp[i-1][c];
                if (c >= w[i]) {
                    dp[i][c] = Math.max(dp[i][c], v[i] + dp[i-1][c-w[i]]);
                }
            }
        }
 
        return dp[n-1][C];
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int C = in.nextInt();
 
        int[] w = new int[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++) {
            w[i] = in.nextInt();
            v[i]  = in.nextLong();
        }
        in.close();
 
        // call function hear
        long ret = knapsack1(w, v, C);
        System.out.println(ret);
    }
}

Measured memory_bytes: 128212
n = int(input())
a = [int(input()) for _ in range(n)]

if n == 2:
    print(a[1])
    print(a[0])
    exit()

b = [0] * n
for i in range(n):
    b[i] = a[i]

b.sort()
b.reverse()

for i in range(n):
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])




Measured memory_bytes: 18904
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 100005;

int n, m;
int par[N];
int setCount;

int findSet(int x) {
	return par[x] == x ? x : par[x] = findSet(par[x]);
}

void uni(int a, int b) {
	int x = findSet(a), y = findSet(b);
	if (x != y) {
		par[y] = x;
		setCount--;
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) par[i] = i;
	setCount = n;
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d %d", &u, &v);
		uni(u,v);
	}
	printf("%d\n", setCount-1);
	return 0;
}

Measured memory_bytes: 4148
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int target = 0;
            var ans = new List<int>();
            for (int i = 0; i < n; i++)
            {
                if (inp[i] < 3200) ans.Add(inp[i] / 400);
                else target++;
            }
            Console.WriteLine("{0} {1}", Math.Max(ans.Distinct().Count(), 1), ans.Distinct().Count() + target);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> v2(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &v[i].first, &v[i].second);
        v2[i] = v[i].first;
    }
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());
    vector<int> rs(n);
    deque<tuple<int, int, mint>> Q;
    for (int i = n-1; i >= 0; --i) {
        int rr = v[i].first+v[i].second-1;
        mint val = 1;
        while(!Q.empty() && get<1>(Q.back()) <= rr){
            rr = max(rr, get<0>(Q.back()));
            val *= get<2>(Q.back());
            Q.pop_back();
        }
        rs[i] = rr;
        Q.emplace_back(rs[i], get<0>(v[i]), val+1);
    }
    mint ans = 1;
    while(!Q.empty()){
        ans *= get<2>(Q.back()); Q.pop_back();
    }
    cout << ans.val << "\n";
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N;

int main() {
    cin >> N;
    vector<int> a(N + 1, 0);
    rep(i,N) cin>>a[i+1];
    vector<int> boxes(N+1,0);
    for(int i = N; i>0; --i) {
        int count = 0;
        for(int j = i + i; j <= N; j += i) {
            if (boxes[j]) count++;
        }
        if (count%2 != a[i]) boxes[i] = 1;
    }
    vector<int> res;
    for (int i = 1; i <= N; ++i) {
        if (boxes[i]) res.push_back(i);
    }
    int M = res.size();
    cout << M << endl;
    rep(i,M) cout << res[i] << " ";
    cout << endl;
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;
    vector<ll> rank;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
        rep(i,0,N) rank.push_back(0);
    }
    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }
    void unite(ll a, ll b){
        a = root(a); b = root(b);
        if(a == b) return;
        parent[a] = b;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
    }
    void merge(ll a, ll b, ll w){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        if(rank[a] < rank[b]) swap(a,b), w = -w;
        if(rank[a] == rank[b]) ++rank[a];
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }
    bool same(ll a, ll b){ return root(a) == root(b);}
    ll sz(ll x){ return num[x];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    UnionFind uf(100010);
    ll N,M;
    cin >> N >> M;
    ll L[200010], R[200010], D[200010];
    rep(i,0,M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }
    bool ok = true;
    rep(i,0,M){
        if(not uf.same(L[i], R[i])){
            uf.merge(L[i], R[i], D[i]);
        }else{
            ll diff = uf.diff(L[i],R[i]);
            if(diff != D[i]){
                ok = false;
            }
        }
    }
    if(ok){
        print("Yes");
    }else{
        print("No");
    }
    
}

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

using namespace std;
typedef long long ll;

// #define DEBUG

vector<vector<int>> connenct_list;
vector<int> visit_list;
vector<int> lowlink_list;
vector<int> parent_list;
vector<vector<int>> children_list;

int counter = 1;
void dfs(int k, int p)
{
    // cout << k << x << p<< endl;
    visit_list[k] = counter;
    lowlink_list[k] = counter;
    counter++;
    parent_list[k] = p;
    for (int j : connenct_list[k])
    {
        if (visit_list[j] == 0)
        {
            dfs(j, k);
            children_list[k].push_back(j);
            lowlink_list[k] = min(lowlink_list[k], lowlink_list[j]);
        }
        else if (parent_list[k] != j)
            lowlink_list[k] = min(lowlink_list[k], visit_list[j]);
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int v, e, a, b;
    cin >> v >> e;
    vector<pair<int, int>> node;
    vector<pair<int, int>> bridge;
    connenct_list.resize(v);
    visit_list.resize(v);
    lowlink_list.resize(v);
    parent_list.resize(v);
    children_list.resize(v);
    for (int i = 0; i < e; i++)
    {
        cin >> a >> b;
        connenct_list[a].push_back(b);
        connenct_list[b].push_back(a);
        node.push_back(make_pair(a, b));
    }

    for (int i = 0; i < v; i++)
    {
        visit_list[i] = 0;
        sort(connenct_list[i].begin(), connenct_list[i].end());
        // for ( auto v : connenct_list[i])
        //     cout << v << " ";
        // cout << endl;
    }

    dfs(0, -1);

    // for (int x = 0; x < v; x++)
    // {
    //     printf( "%d, %d, %d\n" , x, visit_list[x], lowlink_list[x] );
    // }
    // for (int x : parent_list)
    //     cout << x << endl;
    // for (int x = 0; x < v; x++)
    //     for (auto y : children_list[x])
    //         cout << x << " " << y << endl;

    /* 関節点(Articuration Point)
    if (children_list[0].size() > 1)
        cout << 0 << endl;
    for (int i = 1; i < v; i++)
    {
        for (int j : children_list[i])
        {
            // cout << i << " " << visit_list[i] << " " << j << " " << lowlink_list[j] << endl;
            if (visit_list[i] <= lowlink_list[j])
            {
                cout << i << endl;
                break;
            }
        }
    }
*/

    for (auto x : node)
    {
        a = x.first, b = x.second;
        {
            if (visit_list[a] > visit_list[b])
                swap(a, b);
            if (visit_list[a] < lowlink_list[b])
            {
                if (a > b)
                    swap(a, b);
                bridge.push_back(make_pair(a, b));
            }
        }
    }

    sort(bridge.begin(), bridge.end());
    for (auto x : bridge)
    {
        cout << x.first << " " << x.second << endl;
    }
    return 0;
}



Measured memory_bytes: 5100
using System;

public class hello
{
    public static int n, m, L;
    public static int[,] a, b;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(line[0]);
        m = int.Parse(line[1]);
        L = int.Parse(line[2]);
        a = getMatrix(n, m);
        b = getMatrix(m, L);
        getAns();
    }
    static void getAns()
    {
        for (int i = 0; i < n; i++)
        {
            var t = new long[L];
            for (int j = 0; j < L; j++)
                for (int k = 0; k < m; k++)
                    t[j] += (long)a[i, k] * b[k, j];
            Console.WriteLine(string.Join(" ", t));
        }
    }
    static int[,] getMatrix(int h, int w)
    {
        var ans = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < w; j++) ans[i, j] = int.Parse(line[j]);
        }
        return ans;
    }
}



Measured memory_bytes: 20008
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, aux;
  cin >> n;
  int arr[n][3];
  int dp[n][3];
  for(int i=0; i<n; ++i){
    for(int j=0; j<3; ++j){
      cin >> arr[i][j];
    } 
  }
  dp[n-1][0]=arr[n-1][0];
  dp[n-1][1]=arr[n-1][1];
  dp[n-1][2]=arr[n-1][2];
  for(int i=n-2; i>=0; --i){
    for(int j=0; j<3; ++j){
      dp[i][0]=arr[i][0]+max(dp[i+1][1], dp[i+1][2]);
      dp[i][1]=arr[i][1]+max(dp[i+1][0], dp[i+1][2]);
      dp[i][2]=arr[i][2]+max(dp[i+1][0], dp[i+1][1]);
    }
  }
  aux = max(dp[0][0], dp[0][1]);
  cout << max(aux, dp[0][2]);
  return 0;
}

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

constexpr long long MOD = 998244353;
constexpr long long U = 1000000000000000000 % MOD;

void input(vector<vector<int> >& V) {
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		if (A > B) swap(A, B);
		V[A].push_back(B);
	}
}

void Grundy(vector<int>& G, vector<vector<int> >& V) {
	for (int i = (int)V.size() - 1; i >= 0; i--) {
		if (V[i].empty()) {
			G[i] = 0;
			continue;
		}
		vector<int> Gs;
		for (int j : V[i]) {
			Gs.push_back(G[j]);
		}
		sort(Gs.begin(), Gs.end());
		Gs.erase(unique(Gs.begin(), Gs.end()), Gs.end());
		if (Gs[Gs.size() - 1] == Gs.size() - 1) {
			G[i] = Gs.size();
			continue;
		}
		for (int j = 0; j < Gs.size(); j++) {
			if (Gs[j] != j) {
				G[i] = j;
				break;
			}
		}
	}
}

long long Pow(int A) {
	if (A == 0) return 1;
	if (A % 2 == 0) {
		long long B = Pow(A / 2);
		return (B * B) % MOD;
	}
	return (U * Pow(A - 1)) % MOD;
}

void Count(vector<long long>& C, vector<int>& G) {
	for (int i = 0; i < G.size(); i++) {
		C[G[i]] += Pow(i + 1);
		C[G[i]] %= MOD;
	}
}

int main() {
	int N;
	cin >> N;
	vector<vector<int> > X(N), Y(N), Z(N);
	vector<int> GX(N), GY(N), GZ(N);
	vector<long long> CX(512, 0), CY(512, 0), CZ(512, 0);
	input(X), input(Y), input(Z);
	Grundy(GX, X), Grundy(GY, Y), Grundy(GZ, Z);
	Count(CX, GX), Count(CY, GY), Count(CZ, GZ);
	long long ANS = 0;
	for (int i = 0; i < 512; i++) {
		for (int j = 0; j < 512; j++) {
			long long MUL = (CX[i] * CY[j]) % MOD;
			MUL *= CZ[i ^ j];
			MUL %= MOD;
			ANS += MUL;
			ANS %= MOD;
		}
	}
	cout << ANS << endl;
}

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

int main()
{
	int n;
	while (cin >>n, n) {
		vector<string> s;
		REP(i, n) {
			string str;
			cin >> str;
			s.push_back(str);
		}

		bool l = {}, r = {};
		int cnt = 0;
		pair<bool, bool> state;
		state.first = false;
		state.second = false;
		REP(i, s.size()) {
			if (s[i] == "lu") l = true;
			else if (s[i] == "ru") r = true;
			else if (s[i] == "ld") l = false;
			else if (s[i] == "rd") r = false;

			if (!state.first && !state.second) {
				if (l && r) {
					cnt++;
					state.first = true;
					state.second = true;
				}
			}
			else if (state.first && state.second) {
				if (!l && !r) {
					cnt++;
					state.first = false;
					state.second = false;
				}
			}
		}

		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll a[N];
    ll i,k;
    for(i=0;i<N;i++){
        cin >> a[i];
    }
    ll ans=100000000,tmp;
    for(k=-100;k<=100;k++){
        tmp=0;
        for(i=0;i<N;i++){
            tmp+=(a[i]-k)*(a[i]-k);
        }
        ans=min(ans,tmp);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100
#define INF 100000
 
int main()
{
    int n;
    cin >> n;
    int d[MAX][MAX];
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < n; j++) {
	    d[i][j] = INF;
	}
    }
    for (int i = 0; i < n; i++) {
	int r, k, t;
	cin >> r >> k; r--;
	for (int j = 0; j < k; j++) {
	    cin >> t; t--;
	    d[r][t] = 1;
	}
    }
    for (int k = 0; k < n; k++) {
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < n; j++) {
		d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	    }
	}
    }
    
    int p, s, t, v;
    cin >> p;
    for (int i = 0; i < p; i++) {
	cin >> s >> t >> v; s--; t--;
	if (d[s][t]+1 <= v) {
	    cout << d[s][t]+1 << endl;
	} else {
	    cout << "NA" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long time = 0, N, last = 0, T, t;
  for (cin >> N >> T; N; N--) {
    cin >> t;
    time += T-max(0ll,last-t);
    last = t+T;
  }
  cout << time;
}

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

int main(){
    while(true){
        int n;
        cin >> n;
        double ave = 0, sta = 0; 
        int a[n];
        if(n == 0){
             break;
        }
        for(int i = 0; i < n; i++){
            cin >> a[i];
            ave += a[i];
        }
        ave /= n;
        for(int i = 0; i < n ;i++){
            sta += (a[i]-ave)*(a[i]-ave);
        }  
        sta /= n;
        sta = sqrt(sta);
        printf("%lf\n", sta);
    }
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int a,b,n,border;
vector<int> v;
string ans;
char tmp;

main() {
    cin >> a >> b;
    if (a <= b) {
        cout << "Impossible" << endl;
        return 0;
    }
    n = a+b;
    border = b+1;
    rep(i,n) {
        if (v.empty()) {
            v.pb(i)
        }
        else {
            cout << "? " << v.back() << " " << i << endl;
            cin >> tmp;
            if (tmp == 'Y') v.pb(i)
            else border--,v.pop_back();
        }
        if (border == v.size()) break;
    }
    rep(i,n) {
        cout << "? " << v.back() << " " << i << endl;
        cin >> tmp;
        if (tmp == 'Y') ans.pb('1')
        else ans.pb('0')
    }
    cout << "! " << ans << endl;
}


Measured memory_bytes: 724