akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

typedef pair<ll, ll> P;

int h, w;
string s[405];
bool visited[405][405];

P dfs(int x, int y) {
    P p = make_pair(0LL, 0LL);

    if (visited[x][y]) {
        return p;
    }

    visited[x][y] = true;

    if (s[x][y] == '.') {
        p.first++;
        if (x < h-1 && s[x+1][y] == '#') {
            P p2 = dfs(x+1, y);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (y < w-1 && s[x][y+1] == '#') {
            P p2 = dfs(x, y+1);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (x > 0 && s[x-1][y] == '#') {
            P p2 = dfs(x-1, y);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (y > 0 && s[x][y-1] == '#') {
            P p2 = dfs(x, y-1);
            p.first += p2.first;
            p.second += p2.second;
        }
    } else {
        p.second++;
        if (x < h-1 && s[x+1][y] == '.') {
            P p2 = dfs(x+1, y);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (y < w-1 && s[x][y+1] == '.') {
            P p2 = dfs(x, y+1);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (x > 0 && s[x-1][y] == '.') {
            P p2 = dfs(x-1, y);
            p.first += p2.first;
            p.second += p2.second;
        }

        if (y > 0 && s[x][y-1] == '.') {
            P p2 = dfs(x, y-1);
            p.first += p2.first;
            p.second += p2.second;
        }
    }

    return p;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    ll ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!visited[i][j]) {
                P p = dfs(i, j);
                ans += (p.first * p.second);
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

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

#define MAX_N 2000

using namespace std;

int main(void)
{
    int N;
    int a[MAX_N + 1];
    cin >> N;
    cin >> a[0]; // Z is not needed.
    for (int i = 0; i < N + 1; i++) {
        cin >> a[i];
    }
    int xscore[MAX_N];
    int yscore[MAX_N];
    for (int i = N - 1; i >= 0; i--) {
        xscore[i] = yscore[i] = abs(a[i] - a[N]);
        for (int j = i + 1; j < N; j++) {
            xscore[i] = max(xscore[i], yscore[j]);
            yscore[i] = min(yscore[i], xscore[j]);
        }
    }
    cout << xscore[0] << endl;
    return 0;
}


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

int main(){
  int m,f,b;
  
  cin>>m>>f>>b;
  
  if(b-m>f){
    cout<<"NA"<<endl;
  }else{
    cout<< max(b-m,0) <<endl;
  }
  return 0;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		String ans = "";
		
		if(a*b % 2 == 0) {
			ans = "No";
		} else {
			ans = "Yes";
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22740
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: i64,
        mut a: [i64; n],
        mut f: [i64; n],
    }
    a.sort();
    f.sort();f.reverse();
    let mut ng = -1;
    let mut ok = a[n-1] * f[0];
    while ng + 1 < ok {
        let mid = (ng + ok) / 2;
        let a2 = f.iter().map(|&v| mid / v).collect_vec();
        let diff = a.iter().zip(a2.iter()).map(|(&v1, &v2)| max(0, v1-v2)).sum::<i64>();
        if diff <= k {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 10040
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n, ans, tmp;
		while(sc.hasNext()){
			n = sc.nextInt();
			ans = 0;
			for(int i = 0; i <= 9; i++){
				for(int j = 0; j <= 9; j++){
					for(int k = 0; k <= 9; k++){
						tmp = n - (i + j + k);
						if(0 <= tmp && tmp <= 9){
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
int main()
{
    long long int a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    if(a*b>=c*d)
        printf("%lld",a*b);
    else
        printf("%lld",c*d);
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	private static final String[] vars_check = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k" };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String line = sc.next();
			if (line.equals("#")) {
				sc.close();
				break;
			}

			ArrayList<String> varsList = new ArrayList<String>();
			for (int i = 0; i < vars_check.length; i++) {
				if (line.indexOf(vars_check[i]) != -1) {
					varsList.add(vars_check[i]);
				}
			}
			String[] vars = varsList.toArray(new String[0]);

			boolean yes = true;
			for (int bit = 0; bit < (1 << vars.length); bit++) {
				String check = line;
				for (int j = 0; j < vars.length; j++) {
					String replace = "F";
					if ((bit & (1 << j)) != 0) {
						replace = "T";
					}
					check = check.replaceAll(vars[j], replace);
				}
				int length = check.length();
				while (true) {
					check = check.replaceAll("\\-T", "F");
					check = check.replaceAll("\\-F", "T");
					check = check.replaceAll("\\(T\\*T\\)", "T");
					check = check.replaceAll("\\(F\\*[TF]\\)", "F");
					check = check.replaceAll("\\([TF]\\*F\\)", "F");
					check = check.replaceAll("\\(F\\+F\\)", "F");
					check = check.replaceAll("\\([TF]\\+T\\)", "T");
					check = check.replaceAll("\\(T\\+[TF]\\)", "T");
					check = check.replaceAll("\\(T\\-\\>F\\)", "F");
					check = check.replaceAll("\\(T\\-\\>T\\)", "T");
					check = check.replaceAll("\\(F\\-\\>[TF]\\)", "T");
					if (check.length() == length) {
						break;
					}
					length = check.length();
				}
				if (check.equals("F=T") || check.equals("T=F")) {
					System.out.println("NO");
					yes = false;
					break;
				}
			}
			if (yes) {
				System.out.println("YES");
			}
		}

	}
}

Measured memory_bytes: 175268
import itertools
N = int(input())
L = list(map(int, input().split()))
cnt=0
X = list(itertools.combinations(L,3))
for i in range(len(X)):
    if X[i][0] == X[i][1] or X[i][1] == X[i][2] or X[i][0] == X[i][2]:
        continue
    elif X[i][0] < X[i][1]+X[i][2] and X[i][1] < X[i][0]+X[i][2] and X[i][2] < X[i][1]+X[i][0]:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 20540
#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 <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
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; }
const int INF = 1001001000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
bool E[100][100];
vector<bool> seen;
typedef pair<int, int> P;
int D[100];
int F[100];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[100];
int find_time = 0;

void dfs_search(int u) {
    //出発点を訪問済みにする＆行きのタイムスタンプを記録
    int v;
    
    color[u] = 1;
    D[u] = ++find_time;
    //cout << u+1 << " " << color[u] << " " << endl;
    for (v = 0; v < N; v++) {
        //出発点からvへの辺があるか
        if (!E[u][v]) continue;
        //辺がある&&未訪問なら発見した頂点を出発点にして再帰
        if (color[v] == 0) dfs_search(v);
    }
    //今回訪問した頂点より深い未訪問の頂点がない時にその頂点を完了する。
    color[u] = 2;
    F[u] = ++find_time;
}

void dfs() {
    int u;
    find_time = 0;
    for (int i = 0; i < N; i++) color[i] = 0;
    for (u = 0; u < N; u++) {
        //未訪問のuを出発点にしてDFS
        if (color[u] == 0 || color[u] == 1) dfs_search(u);
    }
    //出力
    for (int i = 1; i <= N; i++) {
        cout << i << " " << D[i-1] << " " << F[i-1] << endl;
    }
}

int main() {
    int H, W; cin >> H >> W;
    //vector<vector<char>> S(H+2, vector<char>(W+2,'a'));
    char S[53][53];

    for (int i = 0; i < H ; i++) {
        for (int j = 0; j < W ; j++) {
            cin >> S[i][j];
        }
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (S[i][j] == '#') {
                if (S[i + 1][j] == '#' || S[i - 1][j] == '#' || S[i][j + 1] == '#' || S[i][j - 1] == '#') {
                }
                else {
                    //cout << i << j << endl;
                    cout << "No" << endl;
                    return 0;
                }
            }
            
        }
    }
    cout << "Yes" << endl;
}


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

int main(){
	while(1){
		int n, p;
		scanf(" %d %d", &n, &p);
		if(n==0) break;
		
		int cand[50]; //candidate
		for(int i=0; i<n; ++i) cand[i]=0;
		
		int now=0;
		int stone=p;
		//ゲームシミュレーション
		while(1){
			//printf("situ: p=%d, now=%d, has %d\n", p, now, cand[now]);
			
			if(p==0){
				p=cand[now];
				cand[now]=0;		
			}
			else{ //石を１個取り次の人へ
				p--;
				cand[now]++;
				if(cand[now]==stone) break; //すべての石が１人のところにある
			}
			
			now=(now+1)%n;		
		}
		
		printf("%d\n", now);
	}
	return 0;
}

Measured memory_bytes: 1188
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

int main()
{
	ll n,a,b,c,d,i,x1,x2,y1,y2;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);n--;
	for(i=0;i<=n;i++)
	{
		x1=-i*c;x2=(n-i)*d;y1=-i*d;y2=(n-i)*c;
		if(y1+y2<=b-a&&x1+x2>=b-a)	 break;	
	}
	if(i<=n||(a+c*n<=b&&a+d*n>=b)||(a-c*n>=b&&a-d*n<=b))	printf("YES\n");
	else	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>>a(H ,vector<char>(W));
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
		cin >> a.at(i).at(j);
	}
  }
  //行削除
  vector<bool>flg(H);
  for(int i=0;i<H;i++){
	  for(int j=0;j<W;j++){
		  flg.at(i)=false;
		  if (a.at(i).at(j)=='#'){
			  flg.at(i)=true;
			  break;
		  }
	  }
  }
  //列削除
  vector<bool>flg2(W);
  for(int i=0;i<W;i++){
	  for(int j=0;j<H;j++){
		  flg2.at(i)=false;
		  if (a.at(j).at(i)=='#'){
			  flg2.at(i)=true;
			  break;
		  }
	  }
  }
  for(int i=0;i<H;i++){
	if(!flg.at(i))continue;
	for(int j=0;j<W;j++){
		if (flg.at(i)&&flg2.at(j))
		cout<< a.at(i).at(j);
	}
	cout <<endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9
/*
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    In the blazing sun I saw you
    In the shadows hiding from yourself
    When the lights are on I know you
    See you're grey from all the lies you tell 
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    for(ll i=1000;i<=10000;i+=1000){
        if(i>=n){
            cout<<i-n<<endl;
            return 0;
        }
    }
    return 0;
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template <class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template <class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

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

  p(180 * (n - 2));
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
// #include <algorithm>
// #include <numeric>
// #include <map>
#include <set>
#include <deque>
// #include <queue>

using namespace std;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<deque<pair<int, int>>> vs_table(n);
    for (int i = 0; i < n; i++) {
        deque<pair<int, int>> vs_row(n - 1);
        for (int j = 0; j < n - 1; j++) {
            int r;
            cin >> r;
            vs_row[j] = make_pair(i, r - 1);
        }
        vs_table[i] = vs_row;
    }
    set<pair<int, int>> schedule;
    set<pair<int, int>> schedule_check;
    for (int i = 0; i < n; i++) {
        pair<int, int>& vs = vs_table[i].front();
        vs_table[i].pop_front();
        schedule_check.insert(vs);
    }

    int ans = 0;
    while (!schedule_check.empty()) {
        // cout << "schedule";
        // for (auto vs: schedule) {
        //     cout << "(" << vs.first << ", " << vs.second << ")";
        // }
        // cout << endl;
        for (auto vs: schedule_check) {
            schedule.insert(vs);
        }

        set<pair<int, int>> schedule_rm;
        for (pair<int, int> vs: schedule_check) {
            pair<int, int> vs_inv = make_pair(vs.second, vs.first);
            if (schedule.find(vs_inv) != schedule.end()) {
                schedule_rm.insert(vs);
                schedule_rm.insert(vs_inv);
            }
        }
        schedule_check.clear();
        // cout << "schedule_rm";
        // for (auto vs: schedule_rm) {
        //     cout << "(" << vs.first << ", " << vs.second << ")";
        // }
        // cout << endl;
        if (schedule_rm.empty()) {
            ans = -1;
            break;
        }
        ans++;
        // erase and prepare for the next step
        for (pair<int, int> vs: schedule_rm) {
            schedule.erase(vs);
            if (!vs_table[vs.first].empty()) {
                pair<int, int>& vs_next = vs_table[vs.first].front();
                vs_table[vs.first].pop_front();
                schedule_check.insert(vs_next);
            }
        }
   }
    cout << ans << endl;   
    return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include<queue>
using namespace std;
void insertionSort(int *A,int N){
    for(int i=1;i<N+1;i++){
        
        for(int i=0;i<N;i++){
            if(i==N-1)cout<<A[i]<<endl;
            else cout<<A[i]<<' ';
        }
        int v=A[i];
        int j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
    }
}
int main(){

    int n;
    cin>>n;
    int sou[n];
    for(int i=0;i<n;i++){
        cin>>sou[i];
    }
    insertionSort(sou,n);
    
    
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
    do           \
    {            \
    } while (0)
#define dump(x) \
    do          \
    {           \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template <class T>
inline T sqr(T x) { return x * x; }

LL solve()
{
    LL n, m;
    cin >> n >> m;
    if (abs(n - m) > 1)
    {
        return 0;
    }
    if (n == m)
    {
        LL mul = 1;
        REP(i, 1, n + 1)
        mul = (mul * i) % MOD;
        return (mul * mul * 2) % MOD;
    }
    LL mul = 1;
    REP(i, 1, min(n, m) + 1)
    mul = (mul * i) % MOD;
    return ((mul * mul) % MOD * max(n, m)) % MOD;
}

int main()
{
    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,i,j,cnt[2],cur[2],u[200200];
char s[200200];
long long r;
int main() {
  scanf("%s",s);
  n=strlen(s);
  for (i=j=0; i<n; i++) if (s[i]=='1' || j%2==1) {
    cnt[j%2]+=s[i]-'0';
    u[i]=j%2+1;
    r+=cnt[0];
    j++;
  }
  for (i=n-1; i>=0; i--) if (u[i]==0) {
    swap(cur[0],cur[1]);
    cur[int(cnt[0]!=cnt[1])]+=s[i]-'0';
    r+=cnt[0]+cur[0];
  } else if (s[i]=='1') {
    cnt[u[i]-1]--;
    cur[u[i]-1]++;
  }
  printf("%lld\n",r);
  return 0;
}


Measured memory_bytes: 4812
#include<stdio.h>
int main(){
	while(1){
		int a,b,c=0,d=0,e=0,f=0,g=0,h=0,sum=0;
		scanf("%d",&a);
		if(a==0)break;
		b=1000-a;
		if(b/500!=0)c=b/500;
		if(b%500/100!=0)d=b%500/100;
		if(b%100/50!=0)e=b%100/50;
		if(b%50/10!=0)f=b%50/10;
		if(b%10/5)g=b%10/5;
		if(b%5)h=b%5;
		printf("%d\n",c+d+e+f+g+h);
	}
	return 0;
}


Measured memory_bytes: 2028
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,int>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MOD=998244353;
	void add(int &x,int y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv(ll x){return qpower(x,MOD-2);}
	const int MAX_N=6e3+10;

	int C[MAX_N][MAX_N];
	void main()
	{
		C[0][0]=1;for(int i=1;i<MAX_N;i++){C[i][0]=1;for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;}
		
		int n=qread(),X=qread();int ans=1;
		for(int ln=1;ln<=n;ln++)
		{
			int now=(X&1 or X>2*ln);
			for(int sum=ln;sum<=2*ln-1;sum++)
			{
				if(sum<X) add(now,C[ln][sum-ln]);
				else if((sum-X)&1)
				{
					int cnt=(sum-X+1)/2;if(cnt*2>=ln) continue;
					add(now,C[ln-2*cnt][2*ln-sum]);
				}
			}
			add(ans,(ll)now*C[n][ln]%MOD);
			//printf("ln=%d now=%d\n",ln,now);
		}
		write(ans);
	}
};
signed main()
{
	//freopen("a.in","r",stdin);
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 139776
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
    }
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front();
        q.pop();
        for (int v = 0; v < n; v++) {
            if (M[u][v] == 0) {
                continue;
            }
            if (d[v] != INFTY) {
                continue;
            }
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X, Y, Z = 0; cin >> X >> Y;
  cout << (max(4 - X, 0) + max(4 - Y, 0)) * 100000 + ((X + Y == 2) ? 400000 : 0) << endl;
}


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

vector<int> memo[1000005];

void init(){
  
  for(int i=1;i*i<1000005;i++){
    
    for(int j=i;j<1000005;j+=i){
      memo[j].push_back(i);
    }
    
  }
      
}

int a[200005];
unordered_map<int,int> A;

signed main(){

  init();
  
  int n;
  cin >> n;
  
  for(int i=0;i<n;i++){
    cin >> a[i];
    A[a[i]]++;
  }
  
  int ans = 0;
  
  for(int i=0;i<n;i++){
    
    A[a[i]]--;
    
    int flag = 1;
    
    for(int num : memo[a[i]] ){
      
      if( A[num] || A[a[i]/num] ){
	flag = 0;
	break;
      }
      
    }
    
    ans += flag;
    
    A[a[i]]++;
        
  }

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


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

using namespace std;

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

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

char mp[2222][2222];
ll le[2222][2222];
ll ri[2222][2222];
ll up[2222][2222];
ll dow[2222][2222];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	REP(i, 2222)REP(j, 2222)mp[i][j] = '#';

	ll h, w;cin >> h >> w;
	REP(i, h)REP(j, w)cin >> mp[i+1][j+1];
	h += 2;w += 2;

	REP(i, h){
		ll pre = 0;
		REP(j, w){
			if(mp[i][j] == '#'){
				pre = j;
			}
			le[i][j] = pre;
		}
		REV(j, w){
			if(mp[i][j] == '#'){
				pre = j;
			}
			ri[i][j] = pre;
		}
	}

	REP(j, w){
		ll pre;
		REP(i, h){
			if(mp[i][j] == '#'){
				pre = i;
			}
			up[i][j] = pre;
		}
		REV(i, h){
			if(mp[i][j] == '#'){
				pre = i;
			}
			dow[i][j] = pre;
		}
	}

	ll ans = 0;
	REP(i, h){
		REP(j, w){
			if(mp[i][j] == '#')continue;
			ll tmp = 1;
			tmp += j - le[i][j] - 1;
			tmp += ri[i][j] - j - 1;
			tmp += i - up[i][j] - 1;
			tmp += dow[i][j] - i - 1;
			ans = max(ans, tmp);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 151168
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    vector<int> a;
    while(cin>>n){
        if(n==0)break;
        a.clear();
        for(int i = 0; n > i; i++){
            int tmp;cin>>tmp;
            a.push_back(tmp);
        }
        sort(a.begin(),a.end());
        int sm = 0;
        for(int i = 1; a.size()-1 > i; i++){
            sm += a[i];
        }
        cout << sm/(n-2) << endl;
    }
}


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


ll n;
cin >> n;

ll cnt = 0;
ll sum = 0;
if(n>=11)
{
    sum += (n/11)*11 ;
    cnt += (n/11)*2;

}


for(int i=0 ; sum<n    ;i++)
{
    if(i%2==0)
    {
        sum += 6 ;
    }

     else    sum += 5 ;
        cnt++;
}
cout << cnt << endl;

}


Measured memory_bytes: 3528
N = int(input())

S = [input() for i in range(N)]

ac = 0
wa = 0
tle = 0
re = 0

for s in S:
    if s[0] == 'A':
        ac += 1
    elif s[0] == 'W':
        wa += 1
    elif s[0] == 'T':
        tle += 1
    else:
        re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 16320
N, A, B = map(int, input().split())
S = input()
K, X = 0, 1
for c in S:
    if c == 'a':
        if K < A+B:
            print('Yes')
            K += 1
        else:
            print('No')
    elif c == 'b':
        if K < A+B and X <= B:
            print('Yes')
            K += 1
            X += 1
        else:
            print('No')
            X += 1
    else:
        print('No')

Measured memory_bytes: 53080
import java.util.*;

/*
 * 
 * Sadekujjaman Saju
 * 
 */

public class Main {

	static long dp[][] = new long[201][101];
	static int grid[][] = new int[201][101];

	static int n;
	static int arr[];

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

//		BitSet bits1 = new BitSet(16);
//		BitSet bits2 = new BitSet(16);
//
//		for (int i = 0; i < 16; i++) {
//			if ((i % 2) == 0)
//				bits1.set(i);
//			if ((i % 5) != 0)
//				bits2.set(i);
//		}

//		System.out.println("Initial pattern in bits1: ");
//		System.out.println(bits1);
//		System.out.println("\nInitial pattern in bits2: ");
//		System.out.println(bits2);
//
//		// get some bit
//		
//		BitSet b1 = bits2.get(2, 8);
//		System.out.println(bits1.get(0, 11));
//		
//		
//		// AND bits
//		bits2.and(bits1);
//		System.out.println("\nbits2 AND bits1: ");
//		System.out.println(bits2);
//
//		// OR bits
//		bits2.or(bits1);
//		System.out.println("\nbits2 OR bits1: ");
//		System.out.println(bits2);

		n = sc.nextInt();
		arr = new int[n];

		int sum = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			sum += arr[i];
		}

		BitSet bs = new BitSet(sum + 1);
		bs.set(sum);

//		System.out.println(bs);
		
		for (int i = 0; i < n; i++) {
			BitSet curr = bs.get(arr[i], sum + 1);
//			System.out.println(curr);
			bs.or(curr);
//			System.out.println(bs);
		}
		
		int start = 0;
		if(sum %2 == 0){
			start = sum / 2;
		}
		else{
			start = (sum + 1) / 2;
		}
		
		for (int i = start; i <= sum; i++) {
			if (bs.get(i)) {
				System.out.println(i);
				break;
			}
		}
		sc.close();
	}

	private static void printDistSum(int arr[], int n) {
		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += arr[i];

		// dp[i][j] would be true if arr[0..i-1]
		// has a subset with sum equal to j.
		boolean[][] dp = new boolean[n + 1][sum + 1];

		// There is always a subset with 0 sum
		for (int i = 0; i <= n; i++)
			dp[i][0] = true;

		// Fill dp[][] in bottom up manner
		for (int i = 1; i <= n; i++) {
			dp[i][arr[i - 1]] = true;
			for (int j = 1; j <= sum; j++) {
				// Sums that were achievable
				// without current array element
				if (dp[i - 1][j] == true) {
					dp[i][j] = true;
					dp[i][j + arr[i - 1]] = true;
				}
			}
		}

		// Print last row elements
		for (int j = 0; j <= sum; j++)
			if (dp[n][j] == true)
				System.out.print(j + " ");
	}

}

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

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>


using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n;
int a[200000 + 5], pos[200000 + 5];
set<int> st;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        pos[a[i]] = i + 1;
    }
    st.insert(0);
    st.insert(n + 1);
    int ans = 0;
    rep2(i, 1, n + 1) {
        ans += i * (*st.upper_bound(pos[i]) - pos[i]) * (pos[i] - *(--st.lower_bound(pos[i])));
        st.insert(pos[i]);
    }
    cout << ans << endl;
}

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

//imos法を用いました。

int record[30][101010];

int main() {

    int n,C;

    cin >> n >> C;

    int s,t;
    int c;

    for(int i=0;i<n;i++){
        cin >> s >> t >> c;
        c--;
        record[c][s-1]++;
        record[c][t]--;
    }

    for(int i=0; i<C; i++) {
        for (int j = 1; j < 101010; j++) {
            record[i][j] += record[i][j-1];
        }
    }

    for(int i=0; i<C; i++) {
        for (int j = 1; j < 101010; j++) {
            if(record[i][j]>1){//同じチャンネルで同時放送はないため用いている録画機は常に1である。
                record[i][j] = 1;
            }
        }
    }

    int ans = 0;

    for(int i=0; i<101010;i++){
        int tmp_ans = 0;
        for(int j=0; j<C; j++){
            tmp_ans += record[j][i];
        }
        ans = max(ans,tmp_ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <stack>

using namespace std;
 
int main(){
    string str;
 
    while(getline(cin,str),str != "."){
	stack<char> st;
	int len = str.size();
	bool flg = false;
 
	for(int i = 0 ; i < len ; i++){
	    if(str[i] == '(' || str[i] == '['){
		st.push(str[i]);
		continue;
	    }
	    if(str[i] == ')'){
		if(st.empty()){
		    flg = true;
		    break;
		}
		else if(st.top() == '(') st.pop();
		else{
		    flg = true;
		    break;
		}
	    }
	    else if(str[i] == ']'){
		if(st.empty()){
		    flg = true;
		    break;
		}
		else if(st.top() == '[') st.pop();
		else{
		    flg = true;
		    break;
		}
	    }
	}
	if(!flg&&st.empty()) cout << "yes" << endl;
	else cout << "no" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll,ll>;

vector<vector<PL>> hen;
const ll INF = 1e15;

vector<ll> dijkstra(int s, int n) {
    vector<ll> dist(n, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s);
    dist[s] = 0;

    while(que.size()) {
        int vert = que.top().second;
        que.pop();
        for(auto i : hen[vert]) {
            if(dist[i.first] > dist[vert] + i.second) {
                dist[i.first] = dist[vert] + i.second;
                que.emplace(dist[i.first], i.first);
            }
        }
    }

    return dist;
}

int main()
{
    int n, m, s;
    cin >> n >> m >> s;
    hen.resize(n);

    for(int i = 0; i < m; i++) {
        int a, b, d; cin >> a >> b >> d;
        hen[a].emplace_back(b, d);
        //hen[b].emplace_back(a, d);
    }

    auto dist = dijkstra(s, n);
    for(int i  = 0; i < n; i++) {
        cout << (dist[i] >= INF ? "INF" : to_string(dist[i])) << endl;
    }


}


Measured memory_bytes: 18340
#include <iostream>
#include <cassert>

int div2_count(int v){
    assert(v > 0);
    int cnt = 0;
    int vv = v;
    for(;;){
        if(vv % 2 == 1){
            return cnt;
        }else{
            cnt++;
            vv = vv / 2;
        }
    }
}

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    int v = -1;
    int ans = 0;
    for(int i = 0; i < N; i++){
        int n = i + 1;
        int nv = div2_count(n);
        if(nv > v){
            v = nv;
            ans = n;
        }
    }

    std::cout << ans << std::endl;
    
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
 
int main(){
    int k,n;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int b=n-1;
    int c=k-1;
    cout << (b+c-1)/c<< endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 500 * 500 * 8 + 10;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}
 
const char col[] = "RYGB";
 
int n, m, d;
 
int main() {
#ifdef Wearry
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
 
    cin >> n >> m >> d;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) { 
            putchar(col[(((i+j-1)/d)&1) * 2 + (((m-j+i)/d) & 1)]);
        }
        puts("");
    }
    
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        String s = stdin.readLine();

        int len = s.length();
        char[] t = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        char[] u = new char[len];
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < t.length; j++) {
                if (s.charAt(i) == t[j]) {
                    u[i] = t[j + n];
                    break;
                }
            }
        }

        stdout.println(new String(u));
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 21588
#include"bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<ll> sum(N, 0), sum2(N, 0);
    sum[0] = a[0];
    sum2[0] = (a[0] > 0 ? a[0] : 0);
    for (ll i = 1; i < N; i++) {
        sum[i] = sum[i - 1] + a[i];
        sum2[i] = sum2[i - 1] + (a[i] > 0 ? a[i] : 0);
    }

    ll ans = 0;
    for (ll i = 0; i <= N - K; i++) {
        //[i,i + K)を白か黒で決め打ち
        ll tmp = max(sum[i + K - 1] - (i == 0 ? 0 : sum[i - 1]), (ll)0);
        if (i > 0) {
            tmp += sum2[i - 1];
        }
        if (i < N - K) {
            tmp += sum2[N - 1] - sum2[i + K - 1];
        }

        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()

using namespace std;

int main()
{
	int n = 0, m = 0, a = 0;
	while (cin >> n >> m >> a && n != 0)
	{
		vector<vector<int>> dat(1010, vector<int>(10000, 0));
		rep(i, m)
		{
			int tmp[3] = { 0 };
			cin >> tmp[0] >> tmp[1] >> tmp[2];
			dat[tmp[1]][tmp[0]] = tmp[2];
			dat[tmp[2]][tmp[0]] = tmp[1];
		}
		rep(i, 1001)
		{

			if (dat[a][1001 - i] == 0) { continue; }
			else if (dat[a][1001 - i] > 0) { a = dat[a][1001 - i]; }
		}
		printf("%d\n", a);
	}

	return 0;
}

Measured memory_bytes: 42412
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long N, K;
    scan(N, K);
    auto a = aryread();
    a.sort();
    a.reverse();
    a.take(K).sum().writeln();
}


Measured memory_bytes: 256
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n, q;
	while (cin >> n >> q) {
		vector<ll> a(q);
		for (int i = 0; i < q; i++) cin >> a[i];

		vector<ll> old = a;
		vector<ll> b;
		b.push_back(n);
		for (int i = 0; i < q; i++) {
			while (!b.empty() && b.back() >= a[i]) b.pop_back();
			if (b.empty() || a[i] % b.back() != 0) b.push_back(a[i]);
		}
		a = b;

		vector<vector<pair<int, ll> > > e(n);
		for (int i = 1; i < (int)b.size(); i++) {
			ll x = b[i] - b[i - 1];
			while (1) {
				int id = lower_bound(b.begin(), b.begin() + i, x + 1) - b.begin() - 1;
				if (id == -1) break;
				e[id].push_back(make_pair(i, x / b[id]));
				x %= b[id];
			}
		}
		vector<ll> cnt(b.size());
		cnt[(int)b.size() - 1] = q ?  old[q - 1] / b.back() : 1;
		for (int i = (int)b.size() - 2; i >= 0; i--) {
			cnt[i] = cnt[i + 1];
			for (auto o : e[i]) {
				cnt[i] += cnt[o.first] * o.second;
			}
		}
		
		vector<ll> ans(n);
		for (int i = 1; i < (int)b.size(); i++) {
			ll x = b[i] - b[i - 1];
			while (1) {
				int id = lower_bound(b.begin(), b.begin() + i, x + 1) - b.begin() - 1;
				if (id == -1) {
					if (x) ans[x - 1] += cnt[i];
					break;
				}
				x %= b[id];
			}
		}
		ans[b[0] - 1] += cnt[0];
		
		for (int i = n - 2; i >= 0; i--) {
			ans[i] += ans[i + 1];
		}

		for (int i = 0; i < n; i++) cout << ans[i] << "\n";
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 13408
#include<stdio.h>

int main() {
	int d,i,sum;
	while (scanf("%d", &d) != EOF) {
		sum = 0;
		for (i = d; i < 600; i += d) {
			sum += i*i*d;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans;
    ans = (double)w*h/2;
    printf("%.10lf %d\n", ans, 2*x==w && 2*y==h);
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;
    scanf("%d%d",&n,&l);
    int c=l-1;
    int flag1=0,flag2=0;
    if(l+n-1>0)flag1=1;
    if(l+1-1<0)flag2=1;
    int ans=(1+n)*n/2+n*c;
    if(flag1==1&&flag2==1)
    {
        printf("%d\n",ans);
        return 0;
    }
    if(flag1==1)
        printf("%d\n",ans-l);
    if(flag2==1)
        printf("%d\n",ans-l-n+1);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
int T[10][10];
 
bool check(vint v){
    int r=0;
    for(int i=0;i<5;i++)r=T[r][v[i]];
    return r==0;
}
 
signed main(){
    rep(i,10)rep(j,10)cin>>T[i][j];
    int cnt=0;
    rep(a,10)rep(b,10)rep(c,10)rep(d,10){
        int e=T[T[T[T[0][a]][b]][c]][d];
        vint v={a,b,c,d,e};
 
        bool ok=true;
        rep(i,5){
            reps(j,1,10){
                int tmp=v[i];
                v[i]=(v[i]+j)%10;
                if(check(v))ok=false;
                v[i]=tmp;
            }
        }
        rep(i,4){
            swap(v[i],v[i+1]);
            if(check(v)&&v[i]!=v[i+1])ok=false;
            swap(v[i],v[i+1]);
        }
        if(!ok)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3056
#include<iostream>

using namespace std;

int main(){

	int data[26]={0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0};

	string str;
	while(cin>>str){
		if(str.at(0)=='#')break;
		int cnt=0;
		for(int i=0;i<str.size();i++){
			int state = data[str.at(i)-'a'];
			if(i==str.size()-1)break;

			while(state == data[str.at(i+1)-'a']){
				i++;
				if(i==str.size()-1){
					break;
				}
			}
			
			if(i==str.size()-1){
				break;
			}
			cnt++;
		}
		cout<<cnt<<endl;

	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 100010
#define P 1000000007
int n;
int a[N], b[N];
int wa[N], wb[N];
int LA, LB;

int main () {
	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	for (int i = 0; i < n; i ++) cin >> b[i];
	sort(a, a+n);
	sort(b, b+n);
	/*
	wa[LA++] = 1;
	for (int i = 1; i < n; i ++)
		if (a[i] == a[i-1]) wa[LA-1] ++;
		else wa[LA++] = 1;
	wb[LB++] = 1;
	for (int i = 1; i < n; i ++)
		if (b[i] == b[i-1]) wb[LB-1] ++;
		else wb[LB++] = 1;
	
	int ca = 0, cb = 0;
	ll S = 1;
	while (ca < LA && cb < LB) {
		if (wa[ca] < wb[cb]) {
			for (int i = 1; i <= wa[ca]; i++)
				S = (ll) S*(wb[cb]-i+1)%P;
			wb[cb] -= wa[ca];
			ca++;
		} else
		if (wb[cb] < wa[ca]) {
			for (int i = 1; i <= wb[cb]; i++)
				S = (ll) S*(wa[ca]-i+1)%P;
			wa[ca] -= wb[cb];
			cb ++;
		} else {
			for (int i = 1; i <= wa[ca]; i++) S = (ll)S*i%P;
			ca ++;
			cb ++;
		}
	}
	cout << S << endl;
	*/
	/*
	int ca = 0, cb = 0;
	ll S = 1;
	while (ca < n && cb < n) {
		if (a[ca] > b[cb]) {
			while (cb < n && a[ca] > b[cb]) cb ++;
			if (cb >= ca) S = (ll)S*(cb-ca+1)%P;
		} else {
			while (ca < n && a[ca] < b[cb]) ca ++;
			if (ca >= cb) S = (ll)S*(ca-cb+1)%P;
		}
	}
	*/
	
	ll S = 1;
	for (int i = 0; i < n; i ++) {
		int c = lower_bound(b, b+n, a[i])-b;
		if (c > i) S = (ll)S*(c-i)%P;
	}
	for (int i = 0; i < n; i ++) {
		int c = lower_bound(a, a+n, b[i])-a;
		if (c > i) S = (ll)S*(c-i)%P;
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

vector<vector<int> > G(105);
vector<int> go(105), back(105);
vector<bool> seen(105);
int now=1;

void dfs(int s){

  go[s]   = now++;
  seen[s] = true;

  rep(i,G[s].size()){
    if(seen[G[s][i]]) continue;    
    dfs(G[s][i]);
  }
  
  back[s] = now++;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    rep(j,k){
      int x;
      cin >> x;
      G[u].push_back(x);
    }    
  }
  for(int i=1; i<=n; i++) if(!seen[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << go[i+1] << " " << back[i+1] << endl;
  }
}



Measured memory_bytes: 3092