akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  struct node *cur = nil->next;
  while(cur != nil && cur->key != key){
      cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);

}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if(t == nil){
      return;
  }
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if(t != nil){
      deleteNode(t);
  }
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->prev = nil;
  x->next = nil->next;
  x->next->prev = x;
  nil->next = x;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32972
import sys
sys.setrecursionlimit(20000000)
#input = sys.stdin.readline
m,k = map(int,input().split())
if k == 0:
    ans = []
    for i in range(2**(m)):
        ans.append(i)
        ans.append(i)
    print(" ".join(map(str,ans)))
    exit()
if k > (2**(m))-1:
    print(-1)
    exit()
a = 0
for i in range(2**m):
    if i != k:
        a ^= i
if a != k:
    print(-1)
    exit()
ans = []
for i in range(2**m):
    if i == k:
        continue
    ans.append(str(i))
ans = ans + [str(k)] + ans[::-1] + [str(k)]
print(" ".join(ans))

Measured memory_bytes: 91832
#include <bits/stdc++.h>
#define fr first
#define se second
typedef long long int ll;
using namespace std;
typedef  pair<float , float> pff;
int main(int argc, char const *argv[])
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
//	
    int n;
    cin>>n;
    vector< pair<double, double> > v(n);
    for(int i=0 ; i<n ; i++) {
        cin>>v[i].fr>>v[i].se;
    }
    //cout<<"edwdw";
    double sum = 0.0;
    for(int i=0 ; i<n ; i++) {
        for(int j = i+1 ; j<n ; j++) {
            sum += sqrt( (v[i].fr-v[j].fr)*(v[i].fr-v[j].fr) + (v[i].se-v[j].se)*(v[i].se-v[j].se) );
        }
    }
    
    double ans = sum/(double(n));
    //cout<<2.00000000*ans<<"\n";
    printf("%-8f",2.00000000*ans);
    
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){

int L,R;
cin>>L>>R;

int mod;
int min=2019;
if(R-L>=2019){
    R=L+2019;
}

for(int i=L;i<R;i++){
    for(int j=i+1;j<=R;j++){
        mod=((i%2019)*(j%2019))%2019;
        if(mod<min){
        min=mod;
        }
    }
}

cout<<min<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#include <atcoder/dsu>
using namespace atcoder;

int main() {
  int n, m;
  cin >> n >> m;
  dsu uf(n);
  rep(i,0,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.merge(a, b);
  }
  vector<vector<int>> g = uf.groups();
  int ans = len(g) - 1;
  cout << ans << endl;
  return 0;
}

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

const int maxn = 2e3 + 10;

int n, x, y;
int d[maxn];

void solve() {
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j) {
      int d_min = j - i;
      d_min = min(d_min, abs(i - x) + 1 + abs(j - y));
      d_min = min(d_min, abs(i - y) + 1 + abs(j - x));
      ++d[d_min];
    }
}

int main() {
  scanf("%d %d %d", &n, &x, &y);
  solve();
  for (int k = 1; k < n; ++k) 
    printf("%d\n", d[k]);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long int li;
#define dist(a,b) max(a-b,b-a)
#define abs(n) max(n,-n)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0

int main(){
  int n;cin>>n; 
  vector<li>  a(1,0);
  rep(i,n){
    int b; cin >>b;
    a.push_back(b);
  }
  a.push_back(0);
  li ans=0;
  rep(i,n+1){
    ans+=dist(a[i],a[i+1]);
  }
  rep(i,n){
    cout << ans-dist(a[i],a[i+1])-dist(a[i+1],a[i+2])+dist(a[i],a[i+2])
         << "\n";
  }
  
}


Measured memory_bytes: 2164
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: i64,
    }
    let mut n = n;
    let mut dd = Vec::new();
    for _ in 0..4 {
        dd.push(n % 10);
        n /= 10;
    }
    dd.reverse();
    // 1 << d := pow(2, d)
    for i in 0..1 << 3 {
        let mut sum = dd[0];
        let mut ans = String::new();
        ans.push(std::char::from_digit(dd[0] as u32, 10).unwrap());
        for j in 0..3 {
            // iのj番目ビットが立っているか -> jがiに含まれるか
            if 1 << j & i == 0 {
                sum+=dd[j+1];
                ans.push('+');
                ans.push(std::char::from_digit(dd[j+1] as u32, 10).unwrap());
            } else {
                sum-=dd[j+1];
                ans.push('-');
                ans.push(std::char::from_digit(dd[j+1] as u32, 10).unwrap());
            }
        }
        if sum == 7 {
            println!("{}=7", ans);
            return;
        }
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s; lint K;
    cin >> s >> K;
    lint len_s = s.size();
    range(i, 0, len_s - 1) {
        char c = s.at(i);
        lint dist_to_a = (26 - (c - 'a')) % 26;
        if (K >= dist_to_a) {
            s.at(i) = 'a';
            K -= dist_to_a;
        }
    }
    char last_char = s.at(len_s - 1);
    s.at(len_s - 1) = (last_char - 'a' + K) % 26 + 'a';
    cout << s << "\n";
}

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

#include <bits/stdc++.h>
using namespace std;

class Union_Find{
private:
  vector<int64_t> par;
  vector<int64_t> rank;
  vector<int64_t> num;

  int64_t find(int64_t x){
    if(par.at(x)==x){
      return x;
    }else{
      return par.at(x)=find(par.at(x));
    }
  }

public:
  Union_Find(int64_t n){
    par.resize(n);
    rank.resize(n,0);
    num.resize(n,1);
    for(int64_t i=0;i<n;i++){
      par.at(i)=i;
    }
  }

  void unite(int64_t x,int64_t y){
    x=find(x);
    y=find(y);
    if(x==y){
      return;
    }
    if(rank.at(x)<rank.at(y)){
      par.at(x)=y;
      num.at(y)+=num.at(x);
    }else if(rank.at(x)>rank.at(y)){
      par.at(y)=x;
      num.at(x)+=num.at(y);
    }else{
      par.at(x)=y;
      rank.at(y)++;
      num.at(y)+=num.at(x);
    }
  }

  bool same(int64_t x,int64_t y){
    return find(x)==find(y);
  }

  int64_t size(int64_t x){
    return num.at(find(x));
  }

};

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  Union_Find f(N+1);
  vector<int> num(N+1);

  for(int i=0;i<M;i++){
    int A,B;
    cin >> A >> B;
    f.unite(A,B);
    num.at(A)++;
    num.at(B)++;
  }

  for(int i=0;i<K;i++){
    int C,D;
    cin >> C >> D;
    if(f.same(C,D)){
      num.at(C)++;
      num.at(D)++;
    }
  }

  for(int i=1;i<=N;i++){
    cout << f.size(i)-num.at(i)-1;
    if(i==N){
      cout << endl;
    }else{
      cout << " ";
    }
  }
  return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int ts[200], vs[200];
int used[40100][210];
double dp[40100][210];

double rec(int t, int speed, int interval){
    if(used[t][speed]){
        return dp[t][speed];
    }
    
    if(t == ts[N] * 2){
        return speed == 0 ? 0 : -1e10;
    }

    if(t >= ts[interval] * 2){
        ++interval;
    }

    if(speed > vs[interval] * 2){
        return -1e10;
    }    

    // + 1m/s
    {
        int nextSpeed = min(speed + 1, vs[interval] * 2);
        dp[t][speed] = max(dp[t][speed], rec(t + 1, nextSpeed, interval) + 0.5 * 0.5 * 0.5 * (speed + nextSpeed));
    }

    // - 1m/s
    {
        int nextSpeed = max(speed - 1, 0);
        dp[t][speed] = max(dp[t][speed], rec(t + 1, nextSpeed, interval) + 0.5 * 0.5 * 0.5 * (speed + nextSpeed));
    }

    // no change
    {
        int nextSpeed = speed;
        dp[t][speed] = max(dp[t][speed], rec(t + 1, nextSpeed, interval) + 0.5 * 0.5 * 0.5 * (speed + nextSpeed));        
    }

    // printf("%d, %d: %.6f\n", t, speed, dp[t][speed]);

    used[t][speed] = true;
    return dp[t][speed];
}

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> ts[i];
    }

    for(int i=0;i<N;++i){
        ts[i+1] += ts[i];
    }

    for(int i=1;i<=N;++i){
        std::cin >> vs[i];
    }

    for(int i=0;i<40100;++i){
        for(int j=0;j<210;++j){
            dp[i][j] = -1e10;   
        }
    }

    memset(used, 0, sizeof(used));

    printf("%.6f\n", rec(0, 0, 1));
}


Measured memory_bytes: 101504
#include <stdio.h>

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

	// 入力
	static unsigned long long a[112345];
	for(int i = 0; i < n; ++i){
		scanf("%llu", a + i);
	}

	// もし 0 が 1 つでもあったら答えは 0
	for(int i = 0; i < n; ++i){
		if(a[i] == 0){
			puts("0");
			return 0;
		}
	}
	// ここにたどり着く時点で， a に 0 は含まれていない

	unsigned long long ans = 1;
	for(int i = 0; i < n; ++i){

		long double ans_tmp = ans;
		long double a_i_tmp = a[i];

		if(ans_tmp * a_i_tmp > 1e+18l){
			puts("-1");
			return 0;
		}

		ans *= a[i];
	}

	printf("%llu\n", ans);
}


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

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

ll n, ans, s;

ll get( ll d ) {
	ll x = n;
	while( d-- ) x /= 10;
	return x % 10;
}

int main() {
	cin >> n;
	for( ll i = 17; i >= 0; --i )
		if( get(i) ) {
			ll x = get(i);
			ans = max( ans, s+x-1 + 9*i );
			s += x;
		}
	ans = max(ans, s);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define scanf_s scanf
#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MIN 39
#define MAX 150
int main(void)
{
	char c[3];
	int A = 0, B = 0, AB = 0, O = 0, x;
	while (scanf_s("%d,", &x) != EOF) {
		gets_s(c);
		if (c[0] == 'A' && c[1] == 'B') ++AB;
		else if (c[0] == 'A') ++A;
		else if (c[0] == 'B') ++B;
		else if (c[0] == 'O') ++O;
	}
	printf("%d\n%d\n%d\n%d\n", A, B, AB, O);
}

Measured memory_bytes: 1192
n = list(input().split())

A = list(map(int, input().split()))

# flg:True プラスの想定
def chk(A, flg):
    #print("-------")
    # 初期値
    x=0
    ans =0
    for a in A:
        # 今までの合計
        x += a
        
        # 想定と違ったら、1との差分を増減する
        if flg==True and x < 1:
            ans +=1-x
            # xは1に変える
            x=1
        elif flg == False and x> -1:
            ans += x+1
            x=-1
        #print(x)
        flg = not flg

    return(ans)
print(min(chk(A, True),chk(A, False)))

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

void strInit(char str[]);//str[]を0で初期化
void extIntStr(char str[],int data[]);//str[]から数値(int)を抽出しdata[]に順次格納
void incsort(int data[],int len);//data[]を昇順ソート
void decsort(int data[],int len);//data[]を降順ソート
void printIntArray(int data[],int len);//data[]をprint
int* inputArray(int n);//文字列を受け取り数値を抽出、n個の数値(int)を格納した配列のポインタをreturn
int* cpyArray(int data[],int len);//配列(int)を複製した配列のポインタをreturn

//don't forget free(data);

int main(){
    char str[10];
    scanf("%s",str);
    if(strcmp(str,"Sunny")==0)printf("Cloudy");
    if(strcmp(str,"Cloudy")==0)printf("Rainy");
    if(strcmp(str,"Rainy")==0)printf("Sunny");
    return 0;
}

//temp##############################################

void strInit(char str[]){
    int len=strlen(str);
    for(int i=0;i<len;i++){
        str[i]=0;
    }
}

void extIntStr(char str[],int data[]){
    int length=strlen(str);
    str[length-1]=' ';
    char buff[12];
    int j,index;
    index=j=0;
    for(int i=0;i<length;i++){
        if(str[i]!=' '){
            buff[j++]=str[i];
        }else{
            data[index++]=atoi(buff);
            strInit(buff);
            j=0;
        }
    }
}

void incsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]>data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void decsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]<data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void printIntArray(int data[],int len){
    for(int i=0;i<len;i++){
        printf("%d\n",data[i]);
    }
}

int* inputArray(int n){
    int *data;
    data=(int*)malloc(sizeof(int)*n);
    char *get;
    get=(char*)malloc(sizeof(char)*11*n+1);
    fgets(get,11*n+1,stdin);
    extIntStr(get,data);
    free(get);
    return data;
}

int* cpyArray(int data[],int len){
    int *cp;
    cp=(int*)malloc(sizeof(int)*len);
    for(int i=0;i<len;i++){
        cp[i]=data[i];
    }
    return cp;
}

//temp##############################################


Measured memory_bytes: 128
#include<stdio.h>

int selectionSort(int A[], int N) {
    int i ,j ,t, sw = 0, minj;
    for (i = 0; i < N - 1; i++) {
        minj = i;
        for ( j = i; j < N; j++) {
            if (A[j] < A[minj] ) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if ( i != minj) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;

    scanf("%d", &N);
    for ( i = 0; i < N; i++) scanf("%d", &A[i]);

    sw = selectionSort(A, N);

    for ( i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}



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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
              return x>a.x;
    }
};
struct S
{
    int x,y,z;

    bool operator<(const S &a)const{
              return x<a.x;
    }
};

vector<int> v;
//bitset<4001000> b;
int a,c,i,b,k,n,d,e,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
long long l[1114000];

long long o[1114211];
int j[2];
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};


long long x,y,mod=1000000007;
long long z;

P u[555320];
//stack<int> s;

//set<int> s;
queue<int> q;

//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
//string r1,r;
//char r[1152][1111];
//deque<int> de;
bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y>b.y;
}

long long f(int a)
{
    if(a<0) return 0;
    else
    return o[a];
}
long long p(long long a,long long b)
{
    if(!b) return 1;
    long long x=p(a,b>>1);
    x*=x,x%=mod;
    if(b&1) x*=a,x%=mod;
    return x;
}

long long g(int a,int b)
{
    if(b<a) return 0;
    return f(b)*(p(f(a),mod-2)*p(f(b-a),mod-2)%mod)%mod;
}



int main()
{
    scanf("%d",&a);
    if(a==2)
    {
        puts("1");
        return 0;
    }
    o[0]=1;
    for(int t=1;t<=a;t++)
        o[t]=o[t-1]*t%mod;
    //l[0]=1;
    //for(int t=1;t<=a;t++)
     //   l[t]=p(o[t],mod-2);
    for(int t=2;t<a;t++)
    {
        y=x;
        x=f(a-t-1)*f(t)%mod*g(a-t-1,t-1)%mod;
        z+=(x-y+mod)%mod*t%mod;
        z%=mod;
        //printf("##%lld\n",x);
        //printf("%lld %lld %lld\n",f(a-t-1),f(t),g(a-t-1,t-1));
    }
    printf("%lld",z);
}



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

int main()
{
  int A, B;
  cin >> A;
  if (A <= 5)
  {
    cout << 0;
  }
  else
  {
    cin >> B;
    cout << (A <= 12 ? B/2 : B);
  }
  return 0;
}


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

using namespace std;

struct Node
{
    int l,r;
} node[200050];
bool cmp(Node a, Node b)
{
    return a.r<b.r;
}
int main()
{
    int n,m;
    cin>>n>>m;

    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        if(a>b)
            swap(a,b);

        node[i].l = a;
        node[i].r = b;
    }
    sort(node,node+m,cmp);

    vector<Node>v;
    Node p;
    p.l = 0,p.r=n;
    v.push_back(p);

    for(int i=0; i<m; i++)
    {
        int flag = 1;
        for(int j=0; j<v.size(); j++)
        {
            int ll = v[j].l,rr = v[j].r;
            if(node[i].l >= rr)
                continue;
            flag = 0;
            if(node[i].l <=ll && node[i].r >= rr)
                continue;

            ll = max(ll,node[i].l);
            rr = min(rr,node[i].r);
            v[j].l = ll,v[j].r = rr;
            break;
        }

        if(flag == 1)
        {
            v.push_back(node[i]);
        }

    }
    cout<<v.size()<<endl;

    return 0;
}


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

//struct Point {
//	int x,y;
//};
//long long ccw(const Point& A, const Point& B, const Point& C) { // 시계방향이면 음수 
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
ll a[101];
ll b[101];

int main() { // 골드 1, 플레 1
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// 0 0 10 10 10 23
	int n, k; cin >> n >> k;
	string s; cin >> s;
	char tmp = s[0];
	for (int i = 1; i < n; i++) {
		if (s[i] != tmp) {
			k -= 1;
			while (i < n && s[i] != tmp) {
				s[i] = tmp; i += 1;
			}i -= 1;
			if (k == 0)break;
		}
	}
	int ans = 0;
	int m = 1;

	for (int i = 1; i < n; i++) {
		if (s[i] == tmp) {
			m += 1;
		}
		else {
			ans += (m - 1);
			tmp = s[i]; m = 1;
		}
	}
	ans += (m - 1);
	cout << ans << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    double D, T, S; cin >> D >> T >> S;

    double m = D / T;

    if (S >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lb lower_bound
#define maxn 100005
#define lowbit(x) (x)&(-x)
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)
#define int long long
typedef long long  ll;
typedef unsigned long long ull;
template<class T> inline
void read(T &num)
{num=0; bool f=true; char ch=getchar();
 while(ch<'0'||ch>'9') {if(ch=='-')  f=false;  ch=getchar();}
 while(ch>='0'&&ch<='9') {num=num*10+ch-'0';ch=getchar();}
 num=f?num:-num;
}
int out[100];
template<class T> inline
void  write(T x,char ch)
{if(x==0) {putchar('0');putchar(ch);return;}
 if(x<0) {putchar('-'); x=-x;}
 int num=0;
 while(x){out[num++]=(x%10);x=x/10;}
 fordown(i,num-1,0) putchar(out[i]+'0');
 putchar(ch);
}
string s;
int n;
struct P
{string A,B;
 bool operator <(const P &y) const
  {if(A<y.A) return 1;
   if(A==y.A) return B<y.B; 
  } 
};
map<unsigned long long,ll> mp;
int ans=0ll; 
int a[20];

unsigned long long H(const string &s){
  unsigned long long res=0;
  for(int i=0;i<s.size();++i)res=(res+s[i])*233ll;
  return res;
}

void dfs1(int x)
{if(x>n) 
{string A,B;
 forup(i,1,n) if(a[i]==1){A=A+s[i-1];}else B=s[i-1]+B;
 //A=A+'*'+B;
 //P tmp; tmp.A=A;tmp.B=B;
 //mp[tmp]++; 
 mp[H(A+'*'+B)]++;
 return;
}
 a[x]=0;
 dfs1(x+1);
 a[x]=1; 
 dfs1(x+1); 
}
void dfs2(int x)
{if(x>n)
 {string A,B;
  forup(i,1,n) if(a[i]==1) A=A+s[n+i-1]; else B=s[n+i-1]+B; 
  //P tmp; tmp.A=B;tmp.B=A; 
  ans+=mp[H(B+'*'+A)];	
  return;
 }
  a[x]=0;
  dfs2(x+1);
  a[x]=1;
  dfs2(x+1);	
}
signed main()
{ cin>>n;
  cin>>s;
  dfs1(1);
  
  dfs2(1);	
  cout<<ans<<endl;
return 0;
 } 


Measured memory_bytes: 33024
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(N: int, A: "List[int]"):
    print(YES if len(set(A)) == len(A) else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40236
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
const ll M=1000000+1;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	vector<bool> isp(M,true);
	for(ll i=2;i*i<M;i++){
		if(isp[i]){
			for(ll j=i*i;j<M;j+=i) isp[j]=false;
		}
	}
	vi primes;
	for(ll i=2;i<M;i++){
		if(isp[i]) primes.pb(i);
	}
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=0;i<primes.size() && primes[i]*primes[i]<=n;i++){
		ll cnt=0;
		while(n%primes[i]==0){
			cnt++;
			n/=primes[i];
		}
		ll sum=0,val=0;
		while(sum+val<= cnt){
			sum+=val;
			val++;
		}
		ans+=(val-1);
	}
	if(n!=1) ans++;
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 4340
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int>A(N);
    for (int i=0; i<N; i++)cin >> A[i];
    sort(all(A));
    int ans = 0;
    for (int i=0; i<K; i++){
        ans += A[i];
    }
    cout << ans << endl;
}

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

typedef long long int int64;

#define POS(i,j) (((i)&1)*d+((j)%d))

void run(void){
  char *s=(char *)calloc(10000+1,sizeof(char));
  scanf("%s",s);
  const int n=strlen(s);
  int d;
  scanf("%d",&d);
  const int mod=1000000007;
  const int f=10;
  int sup=0;
  int *dp=(int *)calloc(2*d,sizeof(int));
  for(int i=0;i<n;i++){
    memset(dp+POS(i+1,0),0,sizeof(int)*d);
    int j,k;
    for(j=0;j<d;j++){
      for(k=0;k<f;k++){
	dp[POS(i+1,j+k)]+=dp[POS(i,j)];
	dp[POS(i+1,j+k)]%=mod;
      }
    }
    for(j=0;j<s[i]-'0';j++){
      dp[POS(i+1,sup+j)]++;
      dp[POS(i+1,sup+j)]%=mod;
    }
    sup=(sup+s[i]-'0')%d;
  }
  int ans=dp[POS(n,0)]+(sup==0?1:0)+mod-1;
  printf("%d\n",ans%mod);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.math.BigInteger
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val l = sc.nextInt()
    val lst = (l until l + n).toMutableList()
    lst.sortBy { Math.abs(it) }
    println(lst.sum() - lst[0])
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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


int main(){
int a,b,c,x,y;
cin >> a >> b >> c >> x >> y;
int sum = 1000000000;


rep(r,200000){
    int p =max(0,x-r/2);
    int q =max(0,y-r/2);
    sum = min(a*p+b*q+c*r,sum);
}



cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int n;
	int cnt = 0;

	cin >>n;

	if(n >= 64){
		cout << 64;
	}else if(n >= 32){
		cout << 32;
	}else if(n >= 16){
		cout << 16;
	}else if(n >= 8){
		cout << 8;
	}else if(n >= 4){
		cout <<4;
	}else if(n >= 2){
		cout <<2;
	}else {
		cout <<1;
	}

	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	dp := make([]int, K+1)
	ans := 0
	for i := K; i >= 1; i-- {
		sum := modPow(K/i, N, MOD)
		for j := 2; j*i <= K; j++ {
			sum -= dp[j*i]
			if sum < 0 {
				sum += MOD
			}
		}
		dp[i] = sum
		ans += sum * i
		ans %= MOD
	}

	fmt.Fprintln(wtr, ans)
}

func modPow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if (n & 1) > 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//const int INF = 100100100;
const int INF = INT_MAX;
const ll MOD = pow(10, 9) + 7; //10e9 + 7

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), dp(100100100, INF);//多めに生成
  for(int i=0; i<M; i++){
    cin >> a.at(i);
    dp.at(a.at(i)) = 0; //壊れている段に行く方法は0通り
  }
  
  dp.at(0) = 1;//初期化
  dp.at(1) = min(dp.at(1), dp.at(0));//1段なら必ず1通り(壊れてないなら)
  //dp.at(2) = min(dp.at(2), dp.at(0) + dp.at(1));//2通りかな(壊れてないなら)
  //dp.at(3) = min(dp.at(3), dp.at(1) + dp.at(2));
  
  for(int i=2; i<=N; i++){
    dp.at(i) = min(dp.at(i), dp.at(i-2)+dp.at(i-1)) % MOD;
  	//cout << "dp.at(" << i << "): "<< dp.at(i) << endl;
  }
  
  cout << dp.at(N) << endl;

}


Measured memory_bytes: 391680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

const ll inf = 1LL<<60;
const int MAX_V = 5050;
const int MAX_E = 5050;

struct Edge{ll from, to, cost; };

int V; // 頂点の数
int E; // 辺の数
vector<ll> d(MAX_V, inf); // 距離
vector<bool> negative(MAX_V, false); // 負の閉路検出
vector<Edge> edge;

void Bellman_Ford(){
    d[0] = 0; // 始点の初期化
    for(int loop=0; loop<V-1; ++loop){
        for(int i=0; i<E; ++i){
            if(d[edge[i].from] == inf) continue;

            if(d[edge[i].to] > d[edge[i].from]+edge[i].cost){
                d[edge[i].to] = d[edge[i].from]+edge[i].cost;
            }
        }
    }

    for(int loop=0; loop<2*V; ++loop){
        for(int i=0; i<E; ++i){
            if(d[edge[i].from] == inf) continue;

            if(d[edge[i].to] > d[edge[i].from]+edge[i].cost){
                d[edge[i].to] = d[edge[i].from]+edge[i].cost;
                negative[edge[i].to] = true;
            }

            if(negative[edge[i].from] == true) negative[edge[i].to] = true;
            
        }
    }
}



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

    cin >> V >> E;
    for(int i=0; i<E; ++i){
        ll a,b,c; cin >> a >> b >> c;
        --a; --b; c = -c;
        edge.push_back({a, b, c});
    }

    Bellman_Ford();

    if(negative[V-1]) cout << "inf" << endl;
    else cout << -d[V-1] << endl;

	return 0;
}


Measured memory_bytes: 384
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = B[i] + A[i];

    auto dp = new long[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) if (i != j) dp[i][j] = 1L << 59;

    foreach (len; 2..N+1) {
        foreach (i; 0..N-len+1) {
            int j = i + len - 1;
            foreach (k; i..j) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + B[j+1] - B[i]);
            }
        }
    }

    dp[0][N-1].writeln;
}


Measured memory_bytes: 3964
def d_grid_coloring():
    H, W = [int(i) for i in input().split()]
    N = int(input())
    A = [int(i) for i in input().split()]

    # 方針: 数字を「うなぎ」のように並べればそれが条件を満たす
    # a) 1から順にその数字をそれで塗る回数だけ書き込む
    # b) W 個ごとに分割し，奇数番目は逆にする
    tmp = []
    for k, a in enumerate(A, 1):
        tmp.extend([k] * a)
    ans = [tmp[r * W:(r + 1) * W][::(-1)**r] for r in range(H)]
    return '\n'.join(' '.join(map(str, row)) for row in ans)

print(d_grid_coloring())

Measured memory_bytes: 3700
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)

    val a = datN % 1000
    val ans = if (a == 0) a else (1000 - a)
    println(ans)
  }
}


Measured memory_bytes: 54680
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int K,S,r=0;
	scanf("%d%d",&K,&S);
	for(int x=0;x<=K;x++)
		for(int y=0;y<=K;y++)
			if(S-x-y>=0&&S-x-y<=K)
				r++;
	printf("%d\n",r);
	return 0;
}


Measured memory_bytes: 256
//2018.09.20 20min

#include <iostream>
using namespace std;

int main() {

    string s;
    cin >>s;

    bool ans=true;

    if(s[0]!='A') ans=false;

    int numc=0;
    int numsmall=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C')numc++;
    }
    if(numc!=1)ans=false;

    for(int i=1;i<s.size();i++){
        if(s[i]>='a') numsmall++;
    }
    if(numsmall+2!=s.size()) ans=false;

    if(ans)cout<<"AC"<<endl;
    else cout<<"WA"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
ll n;
ll p[65001];
ll j[65001];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  while(n!=0){
    ll ans=0;
    FOR(i,n){
      cin>>p[i];
      ans+=p[i];
    }
    FOR(i,n-1){
      cin>>j[i];
    }
    ll N=n;
    ll ma=ans*N;
    sort(j,j+n,greater<ll>());
    FOR(i,n-1){

      ans+=j[i];
      N--;
      ll temp=ans*N;
      ma=max(ma,temp);
    }
    cout<<ma<<endl; 
    cin>>n;
  }
  return 0;
}



Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
struct segtree{
private:
	T init;
	int n;
	function<T(T,T)> op;
	vector<T>arr;
	vector<T>st;
	vector<T>lz;
	void build(int lo,int hi,int u){
		if(lo==hi){
			st[u]=arr[lo];
		}
		else{
			int mi=(hi+lo)>>1;
			build(lo,mi,u<<1);
			build(mi+1,hi,u<<1|1);
			st[u]=op(st[u<<1],st[u<<1|1]);
		}
	}
	void apply(T x,int u,int lo,int hi){
// 		st[u]+=x*(hi-lo+1);
// 		st[u]+=x;
		st[u]=x;
// 		st[u]=x*(hi-lo+1);
//  	lz[u]+=x;
		lz[u]=x;
	}
	void push(int u,int lo,int hi){
		if(lz[u]!=init){
			int mi=(lo+hi)>>1;
			apply(lz[u],u<<1,lo,mi);
			apply(lz[u],u<<1|1,mi+1,hi);
			lz[u]=init;
		}
	}
	void modify(int l,int r,T x,int u,int lo,int hi){
		if(r<lo||l>hi||l>r)return;
		if(l<=lo&&r>=hi){
			apply(x,u,lo,hi);
			return;
		}
		push(u,lo,hi);
		int mi=(lo+hi)>>1;
		if(mi>=r){
			modify(l,r,x,u<<1,lo,mi);
		}
		else if(mi<l){
			modify(l,r,x,u<<1|1,mi+1,hi);
		}
		else{
			modify(l,mi,x,u<<1,lo,mi);
			modify(mi+1,r,x,u<<1|1,mi+1,hi);
		}
		st[u]=op(st[u<<1],st[u<<1|1]);
	}
	T query(int l,int r,int u,int lo,int hi){
		if(l>r||l>hi||r<lo)return init;
		if(l<=lo&&r>=hi){
			return st[u];
		}
		push(u,lo,hi);
		int mi=(hi+lo)>>1;
		if(mi>=r){
			return query(l,r,u<<1,lo,mi);
		}
		else if(mi<l){
			return query(l,r,u<<1|1,mi+1,hi);
		}
		else{
			return op(query(l,mi,u<<1,lo,mi),query(mi+1,r,u<<1|1,mi+1,hi));
		}
	}
public:
	segtree(T n,function<T(T,T)> op):n(n),st(n*4),op(op),lz(n*4){
		init=T();
	}
	segtree(vector<T> v,function<T(T,T)> op):n(v.size()),st(v.size()*4),op(op),lz(v.size()*4){
		init=T();
		arr=v;
		build(0,n-1,1);
	}
	T query(int l,int r){
		return query(l,r,1,0,n-1);
	}
	void setinit(T x){
		init=x;
		for(int i=0;i<4*n;i++){
			st[i]=init;
			lz[i]=init;
		}
	}
	void modify(int l,int r,T x){
		modify(l,r,x,1,0,n-1);
	}
};
int main(){
	int n,q;
	cin>>n>>q;
	segtree<int> seg(n,[](int a,int b){
		return min(a,b);
	});
	seg.setinit(INF);
	while(q--){
		int c;
		cin>>c;
		if(c){
			int l,r;
			cin>>l>>r;
			cout<<seg.query(l,r)<<"\n";
		}
		else{
			int l,r,x;
			cin>>l>>r>>x;
			seg.modify(l,r,x);
		}
	}
}





Measured memory_bytes: 6000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <fstream>
using namespace std;
#define INF 0x3f3f3f3f
int main() {
	int n, m, s, c;
	int dig[] = { -1,-1,-1 };
	cin >> n >> m;
	bool flag = true;
	for (int i = 0; i < m; ++i) {
		cin >> s >> c;
		--s;
		if (dig[s] == -1) dig[s] = c;
		else if (dig[s] != c) flag = false;
	}
	if (!flag) puts("-1");
	else {
		for (int i = 0; i < n; ++i) {
			if (dig[i] == -1) {
				if (flag && n != 1) putchar('1');
				else putchar('0');
			}
			else {
				if (flag && !dig[i] && n != 1) {
					printf("-1");
					break;
				}
				else printf("%d", dig[i]);
			}
			flag = false;
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
#define mem(a,z) memset(a,z,sizeof(a));
using namespace std;
//priority_queue
const ll MAXN=100006;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
int F[50003*3];
int Find(int a)
{
    return F[a]<0?a:F[a]=Find(F[a]);
}
int same(int a,int b)
{
    if(Find(a)==Find(b))return 1;
    return 0;
}
int up1(int a,int b)
{
    int x,y;
    x=Find(a);
    y=Find(b);
    if(x!=y)
    F[x]=y;
    return 0;
}
ll s[100003];
ll sum;
int ss[100003];
int ss1[100003];
map<int,int>q;
int main()
{
int t;
cin>>t;
 int sum=0;
 for(int i=1;i<=t;i++)
 {
     int a;
     cin>>a;
     sum^=a;
 }
 if(sum==0)cout<<"Yes\n";
 else cout<<"No\n";


}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

a,b,c=MI()
k=II()

while b<=a:
    b*=2
    k-=1
    if k<0:
        print("No")
        exit()

while c<=b:
    c*=2
    k-=1
    if k<0:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	string s1=s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='b') s[i]='d';
		else if(s[i]=='d') s[i]='b';
		else if(s[i]=='p') s[i]='q';
		else if(s[i]=='q') s[i]='p';
	}
	if(s==s1) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
}

Measured memory_bytes: 512
#include <stdio.h>
    
long long F_0_N(long long n)
{
     long long  pair_num;
     
     if (n <= 0) return 0;             
     pair_num =  (n + 1)/ 2;
     return  ((n & 0x01) ? (pair_num & 0x01) : (pair_num & 0x01) ^ n);       
 }
     
long long F_A_B(long long a, long long b)
{
    if (a == b) return a;
    return (F_0_N(a - 1) ^ F_0_N(b));
}
     
//A ～　B までの論理和を求める
int main(int argc, char *argv[])
{
    long long A, B;
    long long xor_v;
  
    scanf("%lld %lld", &A, &B);
    xor_v =  F_A_B(A, B);
  
    printf("%lld\n", xor_v);
     
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = sorted(list(map(int, input().split())))
 
from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4:
        if w == 0:
            w = h = k
            break
        else:
            h = k
            break
    elif v >= 2:
        if w == 0:
            w = k
        elif h == 0:
            h = k
            break
print(w*h)

Measured memory_bytes: 73752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int time = 60*H2 + M2 - (60*H1 + M1) - K;
    cout << time << endl; 
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}


ll dp[3005][3005];

void solve()
{
    int n, s;
    scanf("%d%d", &n, &s);
    vector<int> a(n);
    int i,j;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    ll mm = minv(2);
    dp[0][0] = 1;
    for (i = 0; i < n; i++) {
        for (j = 0; j <= s; j++) {
            if (dp[i][j]) {
                int j2 = j + a[i];
                if (j2 <= s) {
                    dp[i + 1][j2] = (dp[i + 1][j2] + dp[i][j] * mm %MOD) % MOD;
                }

                {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
                }
            }
        }
    }

    ll ans = dp[n][s] * mpow(2, n) %MOD;
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int a, p; cin >> a >> p;
        p += a * 3;
        cout << p / 2;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3588