akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll k; cin>>k;
    vector<ll> a(k);
    rep(i,k) cin>>a[i];
    ll nin=2, nax=2;
    for(ll i=k-1; i>=0; i--){
        if(a[i] > nax){
            cout << -1 << endl;
            return 0;
        }
        if(nin%a[i]!=0) nin = a[i] * (1 + nin/a[i]);
        nax = a[i]*(nax/a[i]) + a[i] - 1;

    }
    if(nin > nax) cout << -1 << endl;
    else cout << nin << ' ' << nax << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

int n,m,x[200005],y[200005];
vector<pair<int,int> > v[1005];
bool vis[1005],ff[1005][1005];
int f[2005],g[2005];
bool ans[200005];
void dfs(int x)
{
	vis[x]=true;
	for (int i=0;i<v[x].size();++i)
	{
		int y=v[x][i].second;
		if (vis[y]) continue;
		dfs(y);
	}
}
void dfs2(int x,int id)
{
	if (f[x]!=-1) return;
	f[x]=id;
	for (int i=0;i<v[x].size();++i)
	{
		int y=v[x][i].second;
		if (f[y]!=-1) continue;
		dfs2(y,id);
	}
}
void dfs3(int x,int id)
{
	if (g[x]!=-1) return;
	g[x]=id;
	for (int i=0;i<v[x].size();++i)
	{
		int y=v[x][i].second;
		if (g[y]!=-1) continue;
		dfs3(y,id);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",&x[i],&y[i]);
		v[x[i]].push_back(make_pair(i,y[i]));
	}
	for (int i=1;i<=n;++i) sort(v[i].begin(),v[i].end());
	memset(ff,false,sizeof(ff));
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=n;++j) vis[j]=false;
		dfs(i);
		for (int j=1;j<=n;++j) ff[i][j]=vis[j];
	}
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=n;++j) f[j]=g[j]=-1;
		vis[i]=true;
		f[i]=g[i]=0;
		for (int j=0;j<v[i].size();++j)
		{
			int x=i,y=v[i][j].second,id=v[i][j].first;
			dfs2(y,id);
		}
		for (int j=(int)v[i].size()-1;j>=0;--j)
		{
			int x=i,y=v[i][j].second,id=v[i][j].first;
			dfs3(y,id);
		}
		for (int j=0;j<v[i].size();++j)
		{
			int y=v[i][j].second,id=v[i][j].first;
			if (f[y]==id&&g[y]==id) ans[id]=false;
			else ans[id]=true;
		}
	}
	for (int i=1;i<=m;++i)
	{
		if (ans[i]==ff[y[i]][x[i]]) printf("same\n");
		else printf("diff\n");
	}
	return 0;
}

Measured memory_bytes: 7040
/* while(!success_achieved())
      work_hard(); 

   code by:aman_ayush
  */
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
    ll n;
    cin>>n;
    ll arr[n],pos[n+1];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
        pos[arr[i]]=i;
    }
    multiset<ll> ms;
    ms.insert(-1);
    ms.insert(-1);
    ms.insert(n);
    ms.insert(n);
    ms.insert(pos[n]);
    ll cnt=0;
     for(ll i = n - 1; i >= 1; i--){
        auto itr = ms.upper_bound(pos[i]);
        ll r1 = *itr;
        itr++;
        ll r2 = *itr;
        for(int j = 0; j < 2; j++) itr--;
        ll l1 = *itr;
        itr--;
        ll l2 = *itr;
        cnt+= i * ((r2 - r1) * (pos[i] - l1) + (l1 - l2) * (r1 - pos[i]));
        ms.insert(pos[i]);
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            String str = sc.next();

            str = str.replace("?", "D");

            System.out.println(str);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 41088
//2018-1-17
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;
 
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (500+5)

int mat[N][N];

int main(){
	int n, m, w, h;
	scanf("%d%d%d%d", &n, &m, &w, &h);
	
	For(i, 1, n) For(j, 1, m) mat[i][j] = 1000;

	long long tmp = 0;
	int tt = -1000*w*h+999;
	for(int i = w; i <= n; i += w)
	  for(int j = h; j <= m; j += h) mat[i][j] = tt, ++tmp;

	if((1ll*n*m*1000-tmp*1000) <= abs(tmp*tt)){
		puts("No"); return 0;
	}

	puts("Yes");
	For(i, 1, n) For(j, 1, m) printf("%d%c", mat[i][j], j==m? '\n': ' ');
	
	return 0;
}

Measured memory_bytes: 2560
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>g;
vector<edge>edges;
vector<Pll>v;
map<string, LL>ma;
multiset<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000], c[3100], fact[6300];
string str, ss;
bool f[110000];
//char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % MOD, a = a * a%MOD, n >>= 1;
	return r;
}
int main() {
	cin >> n;
	MOD = n;
	rep(i, n) {
		cin >> a[i];
	}
	c[0] = 1;
	rep(i, n) {
		LL C[3100] = {};
		rep(j, i+2) {
			C[j] = (j > 0 ? c[j - 1] : 0) - (c[j]*i)%MOD;
			C[j] %= MOD;
			if (C[j] < 0)C[j] += MOD;
		}
		rep(j, n+1)c[j] = C[j];
	}
	fact[0] = 1;
	rep(i, n*2+10) {
		if ((i + 1) % MOD == 0)fact[i+1] = fact[i];
		else fact[i+1] = fact[i]*(i + 1) % MOD;
	}
	rep(i, n) {
		LL cur = 1, C[3100] = {};
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			cur *= ((i - j)+MOD);
			cur %= MOD;
		}
		cur = a[i] * modpow(cur) % MOD;
		Rrep(j, n) {
			if (j == n - 1)C[j] = c[j + 1];
			else C[j] = (c[j + 1] + C[j + 1] * i)%MOD;
			C[j] %= MOD;
			if (C[j] < 0)C[j] += MOD;
			b[j] += C[j] * cur;
			b[j] %= MOD;
		}
	}
	rep(i, n) {
		if (i)cout << " ";
		cout << b[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 512
import fileinput


def to_bits(n):
    return [int(c) for c in "{0:b}".format(n)]


def from_bits(bits):
    r = 0
    for i, b in enumerate(bits):
        if b:
            r += 2**(len(bits)-i-1)
    return r


def f(X, A):
    return sum(a ^ X for a in A)


def get_bits(Kbits, i, s, A):
    if i < s:
        first_bit = Kbits[i]
        if first_bit > 0:
            r = ([1] + get_bits(Kbits, i+1, s, A)) if f(2**(s-i-1), A) > f(0, A) else ([0] + get_bits([1]*s, i+1, s, A))
        else:
            r = [0] + get_bits(Kbits, i+1, s, A)
    else:
        r = []
    return r


def algorithm(K, A):
    Kbits = to_bits(K)
    return f(from_bits(get_bits(Kbits, 0, len(Kbits), A)), A)


def pass_inputs(input_lines):
    N, K = [n for n in input_lines[0]]
    return algorithm(K, input_lines[1])


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()


Measured memory_bytes: 16112
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,q,ans[N];
vector<pair<int,int>>v[N];
struct uzi{
  int u,v,c,d,i;

  bool operator <(const uzi & t)const{
    return u<t.u;
  }
}p[N],Q[N];
vector<int>ed[N];
int de[N],dep[N];
int fa[N][20];
int L[N],R[N],cnt;
int t1[N],t2[N];
void dfs(int x,int y,int dis=0){
  de[x]=dis;
  dep[x]=dep[y]+1;
  fa[x][0]=y;
  L[x]=++cnt;
  for(int i=1;i<20;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
  for(auto k:v[x]){
    if(k.fi==y)continue;
    dfs(k.fi,x,dis+k.se);
  }
  R[x]=++cnt;
}
int lca(int x,int y){
  if(dep[x]<dep[y])swap(x,y);
  for(int i=19;i>=0;i--)if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
  if(x==y)return x;
  for(int i=19;i>=0;i--)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
  return fa[x][0];
}
void add(int *t,int x,int y){
  for(;x<N;x+=x&-x)t[x]+=y;
}
int get(int *t,int x){
  int y=0;
  for(;x;x-=x&-x)y+=t[x];
  return y;
}
int get_dis(int x,int y){
  return de[x]+de[y]-2*de[lca(x,y)];
}
int get_pre(int x,int y){
  return get(t2,L[x])+get(t2,L[y])-2*get(t2,L[lca(x,y)]);
}
int get_new(int x,int y){
  return get(t1,L[x])+get(t1,L[y])-2*get(t1,L[lca(x,y)]);
}

int main() {
  ios::sync_with_stdio(false);
  cin>>n>>q;
  for(int i=1;i<n;i++){
    cin>>p[i].u>>p[i].v>>p[i].c>>p[i].d;
    v[p[i].u].emplace_back(p[i].v,p[i].d);
    v[p[i].v].emplace_back(p[i].u,p[i].d);
    ed[p[i].c].pb(i);
  }
  dfs(1,0);
  for(int i=1;i<=q;i++){
    cin>>Q[i].u>>Q[i].v>>Q[i].c>>Q[i].d;Q[i].i=i;
  }
  sort(Q+1,Q+1+q);
  for(int l=1,r;l<=q;l=r+1){
    r=l;
    while(r+1<=q&&Q[r+1].u==Q[r].u)r++;
    for(auto k:ed[Q[r].u]){
      int x=p[k].u,y=p[k].v;
      if(dep[x]<dep[y])swap(x,y);
      add(t1,L[x],1);
      add(t1,R[x]+1,-1);
      add(t2,L[x],p[k].d);
      add(t2,R[x]+1,-p[k].d);
    }
    for(int i=l;i<=r;i++){
      ans[Q[i].i]=get_dis(Q[i].c,Q[i].d)-get_pre(Q[i].c,Q[i].d)
                    +get_new(Q[i].c,Q[i].d)*Q[i].v;
    }
    for(auto k:ed[Q[r].u]){
      int x=p[k].u,y=p[k].v;
      if(dep[x]<dep[y])swap(x,y);
      add(t1,L[x],-1);
      add(t1,R[x]+1,1);
      add(t2,L[x],-p[k].d);
      add(t2,R[x]+1,p[k].d);
    }
  }
  for(int i=1;i<=q;i++)cout<<ans[i]<<'\n';
  return 0;
}

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

int main()
{
    int n; cin >> n;
    int a[100001], f[100001];
    for (int i=1; i<=n; i++) cin >> a[i];
    if (n<2)
    {
        cout << 0;
        return 0;
    }
    f[0] = f[1] = 0; f[2] = abs (a[2] - a[1]);
    for (int i=3; i<=n; i++)
    {
        f[i] = min (f[i-2] + abs(a[i] - a[i-2]), f[i-1] + abs(a[i] - a[i-1]));
    }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    A,B,C,K = LI()

    ans = 0
    if A < K:
        ans = A
        if A+B < K:
            ans -= K - (A+B)
    else:
        ans = K

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68844
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
  int n, m, t;

  while(cin>>n>>m && (n+m)){
    bool f = false;
    while(m--){
      cin>>t;
      if(t == 1) f = true;
    }
    if(f) n = 0;
    printf("%.10lf\n", (double)n/2.0);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <set>

using namespace std;

int n,K,ans=0;
set<int> st;
multiset<int> mst;
priority_queue<int,vector<int>,greater<int> > q;

int main()
{
	scanf("%d%d",&n,&K);
	int x;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		st.insert(x);
		mst.insert(x);
	}
	for(set<int>::iterator it=st.begin();it!=st.end();it++)
	{
		q.push(mst.count(*it));
	}
	while(q.size()>K)
	{
		ans+=q.top();
		q.pop();
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 20092
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * https://abc054.contest.atcoder.jp/tasks/abc054_c
 */
public class Main {
	
	static Node[] nodes;

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		nodes = new Node[N];
		for(int i=0; i<N; i++) nodes[i] = new Node(i);
		for(int i=0; i<M; i++){
			Node a = nodes[sc.nextInt()-1];
			Node b = nodes[sc.nextInt()-1];
			a.neighbors.add(b);
			b.neighbors.add(a);
		}
		sc.close();
		
		boolean[] visited = new boolean[N];
		for(int i=0; i<N; i++) visited[i] = false;
		long ans = dfs(nodes[0], visited, 1);
		
		System.out.println(ans);

	}
	
	private static long dfs(Node node, boolean[] visited, int current) {
		visited[node.id] = true;
		if(current==nodes.length){
			return 1;
		}
		long count = 0;
		for(Node n:node.neighbors){
			if(!visited[n.id]){
				boolean[] v = Arrays.copyOf(visited, visited.length);
				count += dfs(n, v, current+1);
			}
		}
		return count;
	}

	static class Node{
		int id;
		Set<Node> neighbors = new HashSet<>();
		Node(int id){
			this.id = id;
		}
	}

}

Measured memory_bytes: 22996
use std::io;
use std::str;
use std::usize;
use std::cmp;


static INF: i32 = 2000000000;

fn main() {
    let x = read_values::<i32>()[0];
    let k = read_values::<usize>()[0];
    let r = {
        let mut r = read_values::<i32>();
        r.push(INF);
        r
    };
    let q = read_values::<usize>()[0];
    let (t, a) = {
        let mut t = vec![INF; q + 1];
        let mut a = vec![INF; q + 1];
        for i in 0..q {
            let v = read_values::<i32>();
            t[i] = v[0];
            a[i] = v[1];
        }
        (t, a)
    };

    let mut y = 0;
    let mut x1 = 0;
    let mut x2 = x;
    let mut upper = true;

    let mut flat = false;
    let mut flat_height = 0;

    let mut r_head = 0;
    let mut t_head = 0;
    let mut prev_time = 0;
    while r_head < k || t_head < q {
        if r[r_head] < t[t_head] {
            // turn
            let time = r[r_head] - prev_time;
            if upper {
                y -= time;
                if y < 0 && x1 < -y {
                    x1 = -y;
                }
            } else {
                y += time;
                if y > 0 && x2 > x - y {
                    x2 = x - y;
                }
            }

            if flat {
                if upper {
                    flat_height -= time;
                } else {
                    flat_height += time;
                }
                flat_height = cmp::max(flat_height, 0);
                flat_height = cmp::min(flat_height, x);
            } else if x1 >= x2 {
                flat = true;
                if upper {
                    flat_height = 0;
                } else {
                    flat_height = x;
                }
            }

            prev_time = r[r_head];
            upper = !upper;
            r_head += 1;
        } else {
            // query
            let time = t[t_head] - prev_time;

            let mut ans = if a[t_head] < x1 {
                x1 + y
            } else if x2 < a[t_head] {
                x2 + y
            } else {
                a[t_head] + y
            };

            if upper {
                ans -= time;
            } else {
                ans += time;
            }

            if flat {
                ans = flat_height;
                if upper {
                    ans -= time;
                } else {
                    ans += time;
                }
            }

            ans = cmp::max(0, ans);
            ans = cmp::min(x, ans);
            println!("{}", ans);

            t_head += 1;
        }
    }
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 5244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;


ll n;


//7c3=(7*6*5)/(3*2*1)=((7*6)/(2*1))*5/3
ll com(ll n,ll m){
    ll rtn = 1;
    REP(i,m){
        rtn*=(n-i);
    }
    REP(i,m){
        rtn/=(i+1);
    }
    return rtn;
}

int main() {
    //put(com(100,4))
    //return 0;
    cin >> n;
    vector<ll> e(n+1);
    FOR(i,2,n+1){
        ll cur = i;
        FOR(j,2,i+1){
            while((cur%j)==0){
                e[j] += 1;
                cur /= j;
            }
        }
    }
    ll res = 0;
    REP(i,n){
        REP(j,n){
            REP(k,n){
                if(e[i]>=4&&e[j]>=4&&e[k]>=2&&i<j&&i!=k&&j!=k){
                    res += 1;
                }
                
            }
        }
    }
    REP(i,n){
        REP(j,n){
            if(e[i]>=14&&e[j]>=4&&i!=j){
                res++;
            }
            if(e[i]>=24&&e[j]>=2&&i!=j){
                res++;
            }
        }
    }
    REP(i,n){
        if(e[i]>=74){
            res++;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define rep(i , a , b) for (int i=a; i<(b); i++)
#define re0(i , a)     for (int i=0; i<(a); i++)
using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;

const int mod=7+1e9;
const int inf=1e9;
const int N=0;
int a[]={111,222,333,444,555,666,777,888,999};
int main()
{
//#ifndef ONLINE_JUDGE
   //freopen("input.in", "r", stdin);
//#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    int i=*lower_bound(a,a+9,n);
    cout<<i<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll h,w; cin >> h >> w;
    char a[h][w];
    char b[h][w];
    rep(i,h){
        rep(j,w) cin >> a[i][j];
    }
    rep(i,h) rep(j,w) cin >> b[i][j];
    ll cnt = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j] != b[i][j]) cnt++;
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 10904
from collections import deque

d=deque()
s=input()
for i in s:
  d.append(i)
q=int(input())
flag=1
t = [input().split() for l in range(q)]
for i in range(q):
  if t[i][0]=='1':
    flag=flag*(-1)
  else:
    if t[i][1]=='1' and flag==1:
      d.appendleft(t[i][2])
    elif t[i][1]=='1' and flag==-1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==-1:
      d.appendleft(t[i][2])
if flag==-1:
  d.reverse()
d="".join(list(d))
print(d)


Measured memory_bytes: 44660
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a,b,s,t,u,d;
int main(void){
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>d;
        if(a>=d)s++;
        else if(a<d&&d<=b)t++;
        else u++;
    }
    cout<<min(min(s,t),u)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;



int main(){
    long n,t;
    cin >> n >> t;
    vector<long> tt(n);
    for (int i = 0; i < n; ++i){
      cin >> tt[i];
    }


    long time = 0;

    // 0   t1    t2    t3
    for (int i = 1; i < n; ++i){
      if (tt[i] - tt[i-1] > t){
        time +=t; 
      }else{
        time+= tt[i] - tt[i-1];
      }
    }
    time += t;

    cout << time;

    
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
  int N;
  int A[200010]={};
  int max=0;
 long int sum=0;
  int i;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  max=A[0];
  if(i>1)
  {
  for(int j=1;j<N;j++)
  {
    if(A[j]>max)
    {
      max=A[j];
    }
    else 
    {
      sum=sum+max-A[j];
    }
  }
  }
  printf("%ld",sum);
  return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//dp[i][j], i:i個まででj個表
double dp[4000][4000];

int main(){

	lli n;
	cin>>n;
	dp[0][0]=1;

	REP(i,0,n){
		double a;
		cin>>a;

		REP(j,0,i+1){
			dp[i+1][j+1] += dp[i][j]*a;
			dp[i+1][j]   += dp[i][j]*(1-a);
		}
	}

	double sum=0;

	REP(i,n/2+1,n+1)sum+=dp[n][i];
	cout<<setprecision(15);
	cout<<sum<<endl;

    return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
}


Measured memory_bytes: 256
H, W = map(int, input().split())
area = []
for i in range(H):
  area.append(input())

for i in range(H):
  for j in range(W):
    if area[i][j] == '#':
      print('#', end='')
    else:
      count = 0
      for k in range(max(0, i-1), min(i+1, H-1)+1):
        for l in range(max(0, j-1), min(j+1, W-1)+1):
          if area[k][l] == '#':
            count += 1
      print(count, end='')
  print()


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

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

    vector<int> a(N);
    for(int i = 0; i< N; i++){
        cin >> a.at(i);
    }

    int cnt = 0;
    int p = 1;

    for(int i = 0; i < N; i++){
        p = a.at(p-1);
        cnt++;
        if(p == 2){
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 768
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]
D = dict()
for st in s:
    if st in D:
        D[st] += 1
    else:
        D[st] = 1
ans = 0
for i in D:
    k = D[i]
    ans += (k*(k-1))//2
print(ans)


Measured memory_bytes: 66776
#include<stdio.h>
int main(void)
{
	int H=1,W=1,i,j;

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

	return 0;
}


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

int main(){
    ll N; cin>>N;
    vector<ll>a(N);
    for(int i=0;i<N;i++)scanf("%lld",&a[i]);

    sort(a.begin(),a.end(),greater<ll>());
    ll h=0,w=0;
    for(int i=0;i<N;i++){
        if(h!=0&&w!=0)break;
        if(a[i]==a[i+1]){
            if(h==0)h=a[i];
            else w=a[i];
            i++;
        }
    }
    cout << h*w << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int n,m;
  string s[100],t[100];
  cin>>n;
  for (int i(0);i<n;i++) cin>>s[i];
  cin>>m;
  for (int i(0);i<m;i++) cin>>t[i];
  int a[100]={0};
  string x;
  int maxi(0);
  for (int i(0);i<n;i++){
    int cnt(0);
    if (a[i]==0){
      x=s[i];
      cerr << x << endl;
      a[i]=1;
    }
    for (int j(0);j<n;j++){
      if (s[j]==x){
        cnt++;
        a[j]=1;
      }
    }
    cerr << cnt << endl;
    for (int j(0);j<m;j++){
      if (t[j]==x) cnt--;
    }
    maxi=max(maxi,cnt);
  }
  cout << maxi << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
main(){
  int m;
  while(1){
    int sum=0;
    int r=1;
    double s1=0, s2=0;
    cin >> m;
    if(m==0) break;
    for(int i=0;i<m;i++){
      double a, b;
      int k;
      if(i==m-1){
        k=360-sum;
        s1+=sin(((double)k/180)*M_PI);
      }
      else{
        cin >> k;
        sum+=k;
        s1+=sin(((double)k/180)*M_PI);
      }
    }
    int n;
    cin >> n;
    sum=0;
    for(int i=0;i<n;i++){
      double a, b;
      int k;
      if(i==n-1){
        k=360-sum;
        s2+=sin(((double)k/180)*M_PI);
      }
      else{
        cin >> k;
        sum+=k;
        s2+=sin(((double)k/180)*M_PI);
      }
    }
    if(s1>s2) cout << 1 << endl;
    else if(s1<s2) cout << 2 << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=2147483647,a[105];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int x=1;x<=100;x++){
    	int sum=0;
    	for(int i=1;i<=n;i++)
    	    sum=sum+(a[i]-x)*(a[i]-x);
    	if(sum<ans)ans=sum;
	}
	printf("%d",ans);
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> con(m, vector<bool>(n, false));
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      con[i][s] = true;
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    int cnt = 0;
    // i個目の電球が点くか？
    for (int i = 0; i < m; i++) {
      int state = 0;
      for (int j = 0; j < n; j++) {
        if (con[i][j] && (bit & (1 << j))) {
          state ^= 1;
        }
      }
      if (state == p[i]) {
        cnt++;
      }
    }
    if (cnt == m) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int N = 1e5+45;

int n;
vector <int> g[N];
ll dp[N][2];

void dfs(int x,int p){
    dp[x][0] = dp[x][1] = 1;
    for(auto f : g[x]){
        if(f == p){
            continue;
        }
        dfs(f,x);
        dp[x][0] *= dp[f][0]+dp[f][1];
        dp[x][0] %= mod;
        dp[x][1] *= dp[f][0];
        dp[x][1] %= mod;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,-1);
    cout << (dp[1][0]+dp[1][1])%mod << endl;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    int c[h][w];
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    int i; int j;
    int tmp=0; int color=1;
    for(i=0;i<h;i++){
        if(i%2==0){
            for(j=0;j<w;j++){
                c[i][j]=color;
                tmp++;
                if(tmp==a[color-1]){
                    color++;
                    tmp=0;
                }
            }
        }
        else{
            for(j=w-1;j>=0;j--){
                c[i][j]=color;
                tmp++;
                if(tmp==a[color-1]){
                    color++;
                    tmp=0;
                }
            }
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w-1;j++)cout << c[i][j] << " ";
        cout << c[i][w-1] << endl;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL a, b, m;
    cin >> a >> b >> m;
    vector<LL> a_price(a);
    vector<LL> b_price(b);
    for(LL i = 0; i < a; ++i){
        cin >> a_price[i];
    }
    for(LL i = 0; i < b; ++i){
        cin >> b_price[i];
    }
    LL ans = *min_element(a_price.begin(), a_price.end()) + *min_element(b_price.begin(), b_price.end());
    for(LL i = 0; i < m; ++i){
        LL x, y, c;
        cin >> x >> y >> c;
        --x; --y;
        ans = min(ans, a_price[x] + b_price[y] - c);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int H, N;
  cin >> H >> N;
  int A{};
  for (int i{}; i < N; ++i) {
    int a;
    cin >> a;
    A += a;
  }
  cout << (H <= A ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, k, ans;
    bool ok[10];
    cin >> n >> k;
    REP(i,10)ok[i] = true;
    REP(i,k){
        int d;
        cin >> d;
        ok[d] = false;
    }
    ans = n;
    while(1){
        bool f = true;
        int tmp = ans;
        while(tmp>0){
            f &= ok[tmp%10];
            tmp /=10;
        }
        if(f){
            cout << ans << endl;
            break;
        }
        else{
            ans++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;


public class Main{

	static int[] unionFind;
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] first = s.nextLine().split(" ");
		int V = Integer.parseInt(first[0]);
		int E = Integer.parseInt(first[1]);
		unionFind = new int[V];
		for(int i=0 ; i<unionFind.length ; i++)
			unionFind[i] = i;
		ArrayList<Edge> edgeList = new ArrayList<Edge>();
		for(int i=0 ; i<E ; i++) {
			String[] line = s.nextLine().split(" ");
			Edge edge = new Edge(Integer.parseInt(line[0]), Integer.parseInt(line[1]), Integer.parseInt(line[2]));
			edgeList.add(edge);
		}
		Collections.sort(edgeList, new Comparator<Edge>() {
			public int compare(Edge e1, Edge e2) {
				return e1.weight - e2.weight;
			}
		});
		int result = 0;
		for(Edge e : edgeList) {
			if(getParent(e.start) == getParent(e.end))
				continue;
			unionFind[getParent(e.start)] = getParent(e.end);
			result += e.weight;
		}
		System.out.println(result);
	}

	public static int getParent(int index) {
		if(unionFind[index] == index)
			return index;
		return getParent(unionFind[index]);
	}

	public static class Edge{
		int start;
		int end;
		int weight;

		Edge(int start, int end, int weight) {
			this.start = start;
			this.end = end;
			this.weight = weight;
		}
	}

}

Measured memory_bytes: 154640
/*
関数オブジェクト ラムダ式
https://marycore.jp/prog/cpp/function-object/
非再帰部分
https://hcpc-hokudai.github.io/archive/structure_segtree_001.pdf
その他
https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
query ver2でその値を取っている添え字も欲しい？
*/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 55
#define MAX (1LL << 31) -1
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
//#define F function<T(T,T)>

template<class T,class F>
struct SegmentTree{
    //using F=function<T(T,T)>;

    const F f;
    int size;
    vector<T> seg;
    const T unit;

    SegmentTree(int N,const F f,const T &unit) :f(f),unit(unit){
        size=1;
        while(size<N) size<<=1;
        seg.assign(2*size,unit);
    }
    void set(int k,const T &x){
        seg[k+size]=x;
    }
    void build(){
        for(int k=size-1;k>0;k--){
            seg[k]=f(seg[2*k],seg[2*k+1]);
        }
    }
    void update(int k,const T &x){
        k+=size;
        seg[k]=x;
        while(k>>=1){
            seg[k]=f(seg[2*k],seg[2*k+1]);
        }
    }
    //[a:b)
    T query(int a,int b){
        T L=unit,R=unit;
        for(a+=size,b+=size;a<b;a>>=1,b>>=1){
            if(a&1) L=f(L,seg[a++]);
            if(b&1) R=f(seg[--b],R);
        }
        return f(L,R);
    }

    T operator[](const int &k) const{
        return seg[k+size];
    }
};

signed main(){
    int N,Q;
    cin>>N>>Q;
    auto f=[](int a,int b){return min(a,b);};
    SegmentTree<int,decltype(f)> seg(N,f,MAX);
    while(Q--){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==0){
            seg.update(x,y);
        }else{
            cout<<seg.query(x,y+1)<<endl;
        }
    }
}


Measured memory_bytes: 3888
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// 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(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int n,k;
    cin>>n>>k;
    int ans=k;
    rep0(i,n-1) ans*=(k-1);
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


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

//read_code(drken)
int main() {
    int d;cin>>d;
    ll g;cin>>g;
    vector<ll>p,c;
    p.resize(d); c.resize(d);
    rep(i,d)cin>>p[i]>>c[i];

    ll ans = 1e+15;
    rep(bit,1<<d){
        ll sum=0;
        ll cc =0;
        rep(i,d)if(bit & (1<<i)){
            sum+=c[i]+p[i]*100*(i+1);
            cc +=p[i];
        }
            if(sum>=g)ans = min(ans,cc);
            else{
                for(int i = d-1;i>=0;--i){
                    if(bit & (1<<i))continue;
                    rep(j,p[i]){
                        if(sum>=g)break;
                        sum+=100*(i+1);
                        ++cc;
                    }
                }
            }
            ans=min(ans,cc);
        }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    ll h,w;
    ll n,x;
    ll a,b,c,d;
    cin>>a>>b>>c>>x;
    REP(i,0,a+1)REP(j,0,b+1)REP(k,0,c+1){
        if(i*500+j*100+k*50==x) sum++;
    }
    cout<<sum<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define N 50
using namespace std;
struct data{
  string l;
  int p,a,b,c,d,e,f,s,m;
  double cal;
};
int main(){
  int n,i,j,time;
  struct data d[N];
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> d[i].l >> d[i].p >> d[i].a >> d[i].b >> d[i].c;
      cin >> d[i].d >> d[i].e >> d[i].f >> d[i].s >> d[i].m;
      time=(d[i].a+d[i].b+d[i].c+d[i].d+d[i].e);
      d[i].m--;
      time+=(d[i].d+d[i].e)*d[i].m;
      d[i].cal=((double)d[i].f*d[i].s*(d[i].m+1)-d[i].p)/time;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].l<d[j-1].l) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].cal>d[j-1].cal) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++) cout << d[i].l << endl;
    cout << '#' << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

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

    ll k = 0;  // 木の直径
    vl v(n);  // v[i] : iの個数
    rep(i, n) {
        ll a;
        cin >> a;
        v[a]++;
        chmax(k, a);
    }

    bool ok = true;
    if(k%2 == 0) {
        v[k/2]--;
        exrep(i, k/2 + 1, k) {
            v[i] -= 2;
        }
        rep(i, n) {
            if(v[i] < 0) {
                ok = false;
            }
        }
        for(ll i = k/2; i >= 1; i--) {
            if(v[i] > 0) {
                ok = false;
            }
        }
    }
    else {
        exrep(i, k/2 + 1, k) {
            v[i] -= 2;
        }
        rep(i, n) {
            if(v[i] < 0) {
                ok = false;
            }
        }
        for(ll i = k/2 + 1; i >= 1; i--) {
            if(v[i] > 0) {
                ok = false;
            }
        }
    }

    if(ok) {
        out("Possible");
    }
    else {
        out("Impossible");
    }
    
    re0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	double n;
	cin>>n;
	cout<<std::fixed<<(int(n+1)/2)/n<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <queue>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    vec<int> x(m);
    vec<int> s(m - 1);
    rep(i, m) { cin >> x[i]; }
    sort(all(x));
    rep(i, m - 1) { s[i] = x[i + 1] - x[i]; }
sort(all(s),greater<int>());
    rep(i,n-1){
	    s[i]=0;
    }
int ans=   accumulate(all(s),0);cout<<ans<<endl;

    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++) 

string data;

int main()
{
    while (cin >> data) {
        if (data[0] == data[1] && data[1] == data[2] && data[2] != 's') {
            cout << data[0] << endl;
        } else if (data[3] == data[4] && data[4] == data[5] && data[5] != 's') {
            cout << data[3] << endl;
        } else if (data[6] == data[7] && data[7] == data[8] && data[8] != 's') {
            cout << data[6] << endl;
        } else if (data[0] == data[3] && data[3] == data[6] && data[6] != 's') {
            cout << data[0] << endl;
        } else if (data[1] == data[4] && data[4] == data[7] && data[7] != 's') {
            cout << data[1] << endl;
        } else if (data[2] == data[5] && data[5] == data[8] && data[8] != 's') {
            cout << data[2] << endl;
        } else if (data[0] == data[4] && data[4] == data[8] && data[8] != 's') {
            cout << data[0] << endl;
        } else if (data[2] == data[4] && data[4] == data[6] && data[6] != 's') {
            cout << data[2] << endl;
        } else {
            cout << "d" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int x=0;
 
  
  for(int i=0; i<N ; i++ ){
  int l, r;
  cin >>l >>r;
    x += r-l+1;
   
    
  }
  cout << x << endl;
}

Measured memory_bytes: 256
class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end
end

loop {
	n, m = gets.split.map &:to_i
	break if n == 0
	
	nodes = [nil] + (1..n).map{|i| [i, gets.to_i]}

	available = {}
	(1..m).each{
		i, j, c = gets.split.map &:to_i
		u = nodes[i]
		v = nodes[j]
		r = (u[1] < v[1] ? u : v)
		available[r] ||= []
		available[r] << [u, v, c]
	}

	nodes.shift
	nodes.sort_by!(&:last)

	tree_size = 0
	node_num = 0
	uf = UnionFind.new
	separator = Float::INFINITY
	disconnected = false

	i = nodes.size-1
	until i < 0 
		max = nodes[i][1]
		while i >= 0 && nodes[i][1] == max
			v = nodes[i]
			node_num += 1
			edges = (available[v] || [])
			
			edges.sort_by!(&:last)
			edges.each{|u, v, c|
				if !uf.same?(u, v)	
					uf.union(u, v)
					tree_size += 1
				end
			}
			i -= 1
		end

		if tree_size == node_num - 1
			if disconnected
				separator = v[1]
			end
			disconnected = false
		else
			disconnected = true	
		end
	end	
	edges = []

	sum = 0
	tree_size = 0
	node_num = 0
	uf = UnionFind.new

	until nodes.empty? || nodes[-1][1] <= separator 
		v = nodes.pop
		node_num += 1
		edges += (available[v] || [])
	end

	until nodes.empty?
		max = nodes[-1][1]
		while !nodes.empty? && nodes[-1][1] == max
			v = nodes.pop
			node_num += 1
			edges += (available[v] || [])
		end
			
		edges.sort_by!(&:last)
		edges.each{|u, v, c|
			if !uf.same?(u, v)	
				uf.union(u, v)
				sum += c
				tree_size += 1
			end
		}
		edges = []
	end
	p tree_size == n - 1 ? sum : 0
}

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

using namespace std;
int const maxn = 100;
typedef long long ll;
int a[maxn], b[maxn];
int main(void) {

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = b[i - 1] + a[i];
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += 1LL * a[i] * (b[n] - b[i]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256