akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  vi tri(3);
  int n;
  cin >> n;
  REP(i, n){
    cin >> tri[0] >> tri[1] >> tri[2];
    SORT(tri);
    cout << (SQ(tri[0]) + SQ(tri[1])== SQ(tri[2]) ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 3036
public class Main {

	public static void main(String[] args) {
		qq();
	}

	private static void qq() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				System.out.printf("%dx%d=%d\n", i, j, i * j);
			}
		}
	}

}



Measured memory_bytes: 24524
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{a:i32,b:i32,c:i32};
    println!("{}", if a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5 {"YES"} else {"NO"});
}

Measured memory_bytes: 4352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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


fn main() {
    input! {
        s: chars,
        t: chars,
    }
    let iter = s.iter().zip(t.iter());
    let mut count = 0;

    for (expected, result) in iter {
        if expected == result {
            count += 1;
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		ABC116_A();
		// ABC116_B();
		// ABC116_C();
		// ABC116_D();
	}

	private static void ABC116_A() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

			int result = lineAB * lineBC / 2;
			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC116_B() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC116_C() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC116_D() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  int ans;
  for(int i=0; i<=n; i++) {
    if(s.substr(n-i,i)==t.substr(0,i)) {
      ans=2*n-i;
    }
  }
  cout << ans << endl;
}

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

int main() {
  double x;
  cin >> x;
  int a = 0;
  double b = 100;
  while(b < x) {
    b = b * 101 / 100;
    b = floor(b);
    a++;
  }
  cout << a << endl;
}



Measured memory_bytes: 3724
import sys
input = lambda: sys.stdin.readline().rstrip()

# UnionFind
class UnionFind:
  def __init__(self,n):
    self.n=n
    self.a=[-1]*n
    self.r=[0]*n
    self.siz=n
  def root_find(self,x):
    if self.a[x]<0:
      return x
    else:
      self.a[x]=self.root_find(self.a[x])
      return self.a[x]
  def unite(self,x,y):
    x=self.root_find(x)
    y=self.root_find(y)
    if x==y:
      return
    if self.r[x]==self.r[y]:
      self.r[x]+=1
      self.a[x]+=self.a[y]
      self.a[y]=x
    elif self.r[x]>self.r[y]:
      self.a[x]+=self.a[y]
      self.a[y]=x
    else:
      self.a[y]+=self.a[x]
      self.a[x]=y
    self.siz-=1
  def root_same(self,x,y):
      return self.root_find(x)==self.root_find(y)


n,q=map(int,input().split())
u=UnionFind(n)
for _ in range(q):
    t,a,b=map(int,input().split())
    if t==0:
        u.unite(a,b)
    else:
        print(u.root_same(a,b)+0)

Measured memory_bytes: 13436
S = list(input())

odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

n = len(S)
check = True
for i in range(n):
    if i % 2 == 0:
        if S[i] not in odd:
            check = False
    else:
        if S[i] not in even:
            check = False

if check:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int x = sc.nextInt();
        int min = Math.max(x-k+1, -1000000);
        int max = Math.min(x+k-1, 1000000);
        int i = min;
        System.out.print(i);
        i++;
        while(i<=max){
            System.out.print(" ");
            System.out.print(i);
            i++;
        }
    }

}


Measured memory_bytes: 21972
import itertools
N = int(input())
P = list(input().split())
Q = list(input().split())

N_str = list(map(str, range(1, N+1)))
N_pa = list(map(lambda x: int(''.join(x)), list(itertools.permutations(N_str, N))))

p_i = N_pa.index(int(''.join(P)))
q_i = N_pa.index(int(''.join(Q)))

result = abs(p_i - q_i)
print(result)

Measured memory_bytes: 46700
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    long long int a, b, c;
    std::cin >> a >> b >> c;
    long long int d = c-a-b;
    if(d>0 && d*d > 4*a*b) std::cout << "Yes\n";
    else std::cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

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

    bool isYes = false;
    rep(i, B) {
        if (((i + 1) * A) % B == C)
            isYes = true;
    }

    string ans = isYes ? "YES" : "NO";
    cout << ans << endl;

    return 0;
}

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

object Main extends App {

  def getMax(i:Int,minv:Int,maxv:Int,r:Int):Int = {
    val m = r-minv
    if(i==1) m.max(maxv)
    else getMax(i-1,r.min(minv),m.max(maxv),readInt)
  }

  println(getMax(readInt-1,readInt,Int.MinValue,readInt))

}

Measured memory_bytes: 62568
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define var auto
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;

int X, X1, Y, Y1;
int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
     int w, h, n; cin>>w>>h>>n;
    X1 = w, Y1 = h;
    for(int i =0; i<n; i++){
        int x, y, a; cin>>x>>y>>a;
        if(x<X) x = X;
        else if(x>X1) x = X1;
        if(y<Y) y = Y;
        else if(y>Y1) y = Y1;
        switch(a){
            case 1:
                    X = x;
                    break;
            case 2:
                    X1 = x;
                    break;
            case 3:
                    Y = y;
                    break;
            case 4:
                    Y1 = y;
                    break;
        }
    }
    cout<<abs(X-X1)*abs(Y-Y1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
int n;
vector<int> v,dp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n;
    v.resize(n);
    for(int i=0;i<n;++i)  cin>>v[i];
    dp.resize(n,0);
    dp[0]=0;dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;++i)  dp[i]=min(abs(v[i]-v[i-2])+dp[i-2],abs(v[i]-v[i-1])+dp[i-1]);
    printf("%d",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n+1];
  int tmp=0;
  int total=0, ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i]-tmp;
    tmp=a[i];
    total+=abs(b[i]);
  }
  b[n]=-a[n-1];
  total+=abs(b[n]);
  for(int i=0;i<n;i++){
    ans = total - abs(b[i]) - abs(b[i+1]) + abs(b[i] + b[i+1]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int[] a = new int[32]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int K = int.Parse(Console.ReadLine());
		Console.WriteLine(a[K-1]);
	}
}

Measured memory_bytes: 11220
#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> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int main () {

    int n,m;cin>>n>>m;

    cout<<n*(n-1)/2 + m*(m-1)/2<<endl;

}

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

using namespace std;

int dp[21][2100000];
int anslen,ans;
int n,k;
int store[2100000];

void upd(int tmp,int ori,int len)
{
	store[ori | (1 << len)] += tmp;
	if(store[ori | (1 << len)] >= k)
	{
		if(len > anslen) ans = ori,anslen = len;
		else if(len == anslen) ans = min(ans,ori);
	}
}

char str[1050000];

int fuckfir1(int val)
{
	return val ^ (1 << (31 - __builtin_clz(val)));
}

int rem0len[1050000];
int rem0cur[1050000];
bool mark[1050000];

void print(int val,int lef)
{
	if(!lef) return ;
	if(lef == 1)
	{
		assert(val <= 1);
		printf("%d",val % 2);
		return ;
	}
	print(val / 2,lef - 1);
	printf("%d",val % 2);
}

int main()
{
	for(int i = 2;i <= 1048576;i *= 2) mark[i - 1] = 1;
//	printf("%d\n",__builtin_clz(2));
	ans = -1;
	scanf("%d%d",&n,&k);
	for(int i = 0;i <= n; ++ i)
	{
		int ta = (1 << i);
		scanf("%s",str);
		for(int j = 0;j < (1 << i); ++ j)
			dp[i][ta | j] = str[j] - '0';
	}
	for(int i = (1 << n) - 1;i >= 0; -- i)
	{
		if(mark[i]) continue;
		int cur = i;
		bool flg1 = 0;
		for(int j = n;j >= 0; -- j)
		{
			if(!(cur & 1 << j - 1) && flg1)
			{
				rem0len[i] = j - 1;
				rem0cur[i] = cur;
				break;
			}
			if(cur & 1 << j - 1) flg1 = 1,cur ^= 1 << j - 1;
		}
	}
	int all = (1 << n + 1) - 1;
	for(int i = n;i >= 0; -- i)
	{
		for(int j = all;j >= 0; -- j)
		{
			int cur = j & ((1 << i) - 1),lef = j >> i;
			int len = 31 - __builtin_clz(lef);
			upd(dp[i][j],fuckfir1(lef),len);
			if(!dp[i][j]) continue;
			if(cur)
			{
				int newlef = lef * 2 + 1;
				int newlen = (31 - __builtin_clz(cur));
				int newcur = fuckfir1(cur);
		//		printf("%d %d %d +1 -> %d %d %d\n",cur,fuckfir1(lef),i,newcur,fuckfir1(newlef),newlen);
				dp[newlen][newlef << newlen | newcur] += dp[i][j];
			}
			if(cur != (1 << i) - 1)
			{
				int newlef = lef * 2;
				if(cur & (1 << i - 1))
				{
					int newlen = rem0len[cur];
					int newcur = rem0cur[cur];
		//			printf("%d %d %d +0 -> %d %d %d\n",cur,fuckfir1(lef),i,newcur,fuckfir1(newlef),newlen);
					dp[newlen][newlef << newlen | newcur] += dp[i][j];
				}
				else
				{
					int newlen = i - 1;
					int newcur = cur;
		//			printf("%d %d %d +0 -> %d %d %d\n",cur,fuckfir1(lef),i,newcur,fuckfir1(newlef),newlen);
					dp[newlen][newlef << newlen | newcur] += dp[i][j];
				}
			}
		}
	}
	if(ans == -1) puts("");
	else
	{
		print(ans,anslen);
	}
}

Measured memory_bytes: 188032
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

vector<int> bfs(int s,const graph &g){
    int _size = g.size();
    vector<int> c(_size,-1);
    c[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int x = que.front();
        que.pop();
        for(auto nx: g[x]){
            if(c[nx]<0){
                que.push(nx);
                c[nx] = c[x]+1;
            }
        }
    }
    return c;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll s = 0;
    rep(i,1,n+1){
        if(i%3==0 || i%5==0){
            continue;
        }
        s += i;
    }
    cout << s << endl;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 100;
  for (int i = 0; i < N; i++){
    int a;
    cin >> a;
    int cnt =0;
    while(a % 2 == 0){
      cnt++;
      a/=2;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//Dijkstra法
struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;


//基数ヒープ
template<typename T > class RadixHeapInt64 {
private:
	vector< pair<ull, T> > v[65];
	ll last, size;
	int bsr(ull x) {
		if (x == 0)return -1;
		return 64 - __builtin_clzll(x);
	}
public:
	RadixHeapInt64() {
		last = size = 0;
	}
	bool empty() {
		return size == 0;
	}
	//p = {priority,value}
	void push(ull priority, const T& value) {
		size++;
		v[bsr(priority ^ last) + 1].emplace_back(priority, value);
	}
	pair<ull, T> pop() {
		if (!v[0].size()) {
			int i = 1;
			while (!v[i].size())i++;
			last = (*min_element(v[i].begin(), v[i].end())).first;
			for (int j = 0; j < v[i].size(); j++) {
				v[bsr(v[i][j].first ^ last) + 1].push_back(v[i][j]);
			}
			v[i].clear();
		}
		size--;
		auto ret = v[0].back();
		v[0].pop_back();
		return ret;
	}
};

void Dijkstra(int s, vector<vector<edge>>& g, vector<ll>& d) {
	RadixHeapInt64<ll> q;
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	q.push(0, s);

	while (!q.empty()) {
		P p = q.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(d[e.to], e.to);
			}
		}
	}
}
int main() {
	io_init;
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<vector<edge>> g(N);
	g[X - 1].push_back({ Y - 1,1 });
	g[Y - 1].push_back({ X - 1,1 });
	for (int i = 0; i < N - 1; i++) {
		g[i].push_back({ i + 1,1 });
		g[i + 1].push_back({ i,1 });
	}
	vector<ll> tmp;
	map<int, int> ans;
	for (int i = 0; i < N; i++) {
		Dijkstra(i, g, tmp);
		for (int j = 0; j < N; j++) {
			ans[tmp[j]]++;
		}
	}
	for (int i = 1; i < N; i++) {
		cout << ans[i]/2 << endl;
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


Int bfs(Int K){
  priority_queue<Int, vector<Int>, greater<Int> > Q;
  set<Int> used;
  for(Int i=1;i<10;i++) Q.push(i), used.insert(i);

  Int cnt = 0;
  while(!Q.empty()){
    Int num = Q.top(); Q.pop();
    cnt++;
    if(cnt == K) return num;

    Int pre = num % 10;
    for(Int i = pre - 1; i <= pre + 1; i++){
      if(i < 0 || i >= 10) continue;
      Int nnum = num * 10 + i;
      if(used.count(nnum)) continue;
      used.insert(nnum);
      Q.push(nnum);
    }
  }
  assert(0);
  return 0;
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  Int K;
  cin>>K;

  Int ans = bfs(K);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 15344
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int A[N], B[N], C[N - 1];
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N - 1) cin >> C[i];

    int s;
    s = B[A[0] - 1];
    FOR(i, 1, N) {
        s += B[A[i] - 1];
        if (A[i - 1] + 1 == A[i]) s += C[A[i - 1] - 1];
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mod=1e9+7;
int a[101];
int dp[100001][101];
int qzh[100001][101];
int main()
{
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	qzh[0][0]=dp[0][0]=1;
	for(int i=1;i<=k;i++)
		qzh[i][0]=qzh[i-1][0]+dp[i][0];
	for(int i=1;i<=n;i++)
		qzh[0][i]=dp[0][i]=1;
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n;j++)
		{
			dp[i][j]=(qzh[i][j-1]-((i-a[j]>0)?qzh[i-a[j]-1][j-1]:0))%mod;
			qzh[i][j]=(qzh[i-1][j]+dp[i][j])%mod;
		}
	cout<<(dp[k][n]+mod)%mod;
	return 0;
}

Measured memory_bytes: 82476
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,k=MI()
    ans=0
    if a>=k:
        ans=k
    else:
        ans=a
        k-=a
        if b>=k:
            pass
        else:
            k-=b
            ans-=k
            
    print(ans)

main()


Measured memory_bytes: 61892
#include <stdio.h>
int main(void) {
	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}
			a = a / 2;
			b = b + a;
		}
		else {
			if (b % 2 == 1) {
				b--;
			}
			b = b / 2;
			a = a + b;
		}
	}
	printf("%d %d", a, b);
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N, M;
int v[1123];

int main() {
	cin >> N >> M;
	
	REP(i, M) {
		int a, b;
		scanf("%d %d", &a, &b);
		v[i] = a;
	}
	
	sort(v, v + M, greater<int>());
	
	int ans = 0;
	REP(i, M - 1) {
		ans += max(N - v[i], 0);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3196
program main
  implicit none
  integer :: n, i, largest, second
  integer, allocatable :: a(:)
  read (*, *) n
  allocate (a(n))
  read (*, *) (a(i), i = 1, n)
  largest = 0
  second = 0
  do i = 1, n
    if (a(i) > largest) then
      second = largest
      largest = a(i)
    else if (a(i) > second) then
      second = a(i)
    end if
  end do

  do i = 1, n
    if (a(i) == largest) then
      write (*, "(i0)") second
    else
      write (*, "(i0)") largest
    end if
  end do
end program main


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

typedef long long ll;

int N;
int D, H;
ll mod = 1000000007;
ll dp[1000010], cmp[1000010] = {0};
ll F[1000010] = {1};
ll FF;

int main()
{
    cin >> N >> H >> D;

    for(int i = 1; i < 1000010; i++)
    {
        F[i] = (F[i - 1] * i) % mod;
        if(i <= N)FF = (FF + F[i]) % mod;
    }
    dp[0] = cmp[0] = F[N];

    for(int i = 1; i < H; i++)
    {
        dp[i] = (mod + cmp[i - 1] - ((i - D - 1 >= 0) ? cmp[i - D - 1] : 0)) % mod;
        dp[i] = dp[i] * FF % mod;
        cmp[i] = (cmp[i - 1] + dp[i]) % mod;
    }
    cout << (mod + cmp[H - 1] - ((H - D - 1 >= 0) ? cmp[H - D - 1] : 0)) % mod << endl;

    return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int N;ll K;
vec A;
bool b(ll d){
    vec r;
    rep(i,N){
        if(A[i]%d==0) continue;
        r.pb(A[i]%d);
    }
    sort(all(r));
    int R=SZ(r);
    vec S(R+1),T(R+1);S[0]=T[0]=0;
    rep(i,R){
        S[i+1]=S[i]+r[i];
        T[i+1]=T[i]+d-r[R-1-i];
    }
    FOR(i,1,R){
        if(S[i]==T[R-i] && S[i]<=K) return true;
    }
    return false;
}

int main(){
    scanf("%d %lld",&N,&K);
    A.resize(N);ll sum=0;
    rep(i,N){
        scanf("%lld",&A[i]);
        sum+=A[i];
    }
    ll ans=1,M=(ll)sqrt(sum)+1;
    FOR(i,1,M){
        if(sum%i!=0) continue;
        if(b(i)) ans=max(ans,(ll)i);
        if(b(sum/i)) ans=max(ans,sum/i);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
s = input()

l_odd = ['R', 'U', 'D']
l_even = ['L', 'U', 'D'] 

for i, ch in enumerate(s):
    if (i+1)%2 != 0 and ch not in l_odd:
        print('No')
        break
    if (i+1)%2 == 0 and ch not in l_even:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int INF = 1e9 + 10;

int N;
int A[200010];
int sum[200010];
map<int, int> m;

signed main()
{
	cin >> N;
	rep1(i, N) cin >> A[i];
	
	int ans = 0;
	m[0]++;
	rep1(i, N) {
		sum[i] = A[i] + sum[i - 1];
		ans += m[sum[i]];
		m[sum[i]]++;
	}

	cout << ans << endl;
}



Measured memory_bytes: 15872
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
constexpr int inf = 1 << 30;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; ++i) {
        ans += (p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] < p[i - 1] && p[i] > p[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

using namespace std;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	int x = n%10;
	if(x==3) cout<<"bon"<<endl;
	else if(x==0 || x==1 || x==6 || x==8)cout<<"pon"<<endl;
	else cout<<"hon"<<endl;
	return 0;
}

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

using namespace std;

long long mod_pow(long long a,long long b,long long mod){
	long long res=1,c=a;
	while(b){
		if(b&1) res=res*c%mod;
		c=c*c%mod;
		b/=2;
	}
	return res;
}

long long inv(long long a,long long mod){
	long long b=mod,p=1,q=0;
	while(b){
		long long c=a/b,d=a;
		a=b;
		b=d%b;
		d=p;
		p=q;
		q=d-c*q;
	}
	return (p+mod)%mod;
}
int fs=505050;
vector<long long> fact(fs),ifact(fs);
long long binom(int a,int b,long long mod){
	if(a<b) return 0;
	return fact[a]*ifact[b]%mod*ifact[a-b]%mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	
	long long mod=1000000007;
	
	fact[0]=1;
	for(int i=1;i<fs;i++) fact[i]=fact[i-1]*i%mod;
	ifact[fs-1]=inv(fact[fs-1],mod);
	for(int i=fs-1;i>0;i--) ifact[i-1]=ifact[i]*i%mod;
	
	long long res=0;
	vector<long long> rui(fs);
	for(int i=1;i<fs;i++){
		long long iv=inv(i,mod);
		rui[i]=(rui[i-1]+iv)%mod;
	}
	for(int i=0;i<(n-1);i++){
		//i i+1
		long long coef=rui[i+1];
		res=(res+coef*(a[i+1]-a[i])%mod)%mod;
	}
	res=res*fact[n-1]%mod;
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 14976
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  ll in(N); ll in(K);

  ll ans = N % K;
  cout << min(ans, abs(ans - K)) << endl;
  return 0;
}


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

Measured memory_bytes: 640
#include <iostream>
using namespace std;
  int n;
  int k;
  int respuestas[100000];
  int h[100000];
int dp(int pos)
{
	
  if(pos>=n-1)return 0;
  if(respuestas[pos]!=-1)
	return respuestas[pos];
  if(n-1-pos==1)return abs(h[pos]-h[pos+1]) ;
  int imin=1e9;
  for(int i=pos+1;i<n && i-pos<=k;i++)
  {
  
  	imin=min(imin,abs(h[pos]-h[i])+dp(i));
  }
  
  
  respuestas[pos]=imin;
  return imin;

}
int main() {
  cin>>n;
	cin>>k;
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
	for(int i=0;i<n;i++)
	{
		respuestas[i]=-1;
		
	}
cout<<dp(0)<<endl;
	
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;



int main()
{

    SPEED;

    ll a,b,n;
    cin >> a >> b >> n;

    ll x = min(n,b-1);

    cout << (a*x)/b <<endl;

    R 0;
}


Measured memory_bytes: 3652
using System;
using System.Linq;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str1=Console.ReadLine().Split(' ');
    int x=int.Parse(str1[0]);
    int N=int.Parse(str1[1]);
    string[] str2=Console.ReadLine().Split(' ');
    
      if(N!=0){
          int[] str2ToInt=new int[N];

          for(int i=0;i<N;i++){
              str2ToInt[i]=int.Parse(str2[i]);
          }

          int[] str3ToInt=new int[str2ToInt.Max() - str2ToInt.Min() + 3];
          int j = 0;

          for(int ii=str2ToInt.Min()-1;ii<str2ToInt.Max()+2;ii++){
            if(!str2ToInt.Contains(ii)){
              str3ToInt[j]=ii;
              j = j + 1;
            }
          }

          int str3_num = j;

          //コピー先の配列を作成する
          int[] ary2 = new int[str3_num];
          //指定された範囲をコピーする
          Array.Copy(str3ToInt, 0, ary2, 0, str3_num);

          int[] ary3 = new int[str3_num];
          for(int l=0;l<ary3.Length;l++){
              ary3[l] = System.Math.Abs(ary2[l] - x);
          }

          Console.WriteLine( ary2.Where(num => System.Math.Abs(num - x) == ary3.Min()).Min() );

      }else{
        Console.WriteLine(x);
      }
   }
  }

}

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

int sigma(int n){
    return n==1 ? 1 : n+sigma(n-1);
}

int main(){
    int N;
    while(cin>>N,N){
        int cnt=0,i=1;
        while(N-sigma(++i-1)>0){
            if((N-sigma(i-1))%i==0){
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;


template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
struct Graph{
	struct Edge{
		int from, to, cost;
		Edge(int from,int to,int cost) :
			from(from), to(to), cost(cost) {}
		bool operator < (const Edge &f) const {
			return cost != f.cost ? cost > f.cost : // !!INVERSE!!
				from != f.from ? from < f.from : to < f.to;
		}
	};
	typedef vector<Edge> Edges;
	vector<Edges> G;
	Graph(int size): G(size) {}
	inline void add(int from, int to, int cost){
		G[from].push_back(Edge(from, to, cost));
	}
	//O(ElogV)
	pair<vector<int>, vector<int> > dijkstra(int s){
		int n = G.size();
		vector<int> dist(n, INF); dist[s] = 0;
		vector<int> prev(n, -1);
		priority_queue<Edge> que;
		for(que.push(Edge(s,s,0)); !que.empty();){
			Edge e = que.top(); que.pop();
			if(prev[e.to] != -1) continue;
			prev[e.to] = e.from;
			FORIT(f,G[e.to]){
				if(dist[f->to] > dist[f->from] + f->cost){
					dist[f->to] = dist[f->from] + f->cost;
					que.push(*f);
				}
			}
		}
		return make_pair(dist, prev);
	}
	pair<vector<int>, vector<int> > BellmanFord(int s){
		int n = G.size();
		vector<int> dist(n, INF); dist[s] = 0;
		vector<int> prev(n, -1);
		REP(i,n){
			FORIT(e,G[i]){
				if(dist[e->to] > dist[e->from] + e->cost){
					dist[e->to] = dist[e->from] + e->cost;
					if(i == n - 1){
						return make_pair(vector<int>(n, -INF),vector<int>(n, -1));
					}
				}
			}
		}
		return make_pair(dist, prev);
	}
	//O(ElogV)
	int prim2(int s, int c){
		int n = G.size();
		vector<bool> used(n, false);
		int ret = 0;
		int usenum = 0;
		priority_queue<Edge> que;
		for(que.push(Edge(s,s,0)); !que.empty();){
			Edge e = que.top(); que.pop();
			if(used[e.to]) continue;
			used[e.to] = true;
			ret = max(ret, e.cost);
			usenum++;
			FORIT(f,G[e.to]){
				if(f->cost >= c && !used[f->to]){
					que.push(*f);
				}
			}
		}
		if(usenum < n) ret = INF;
		return ret;
	}
};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		Graph graph(n);
		REP(i,m){
			int u,v,w;
			cin>>u>>v>>w; u--; v--;
			graph.add(u,v,w);
			graph.add(v,u,w);
		}
		int ans = INF;
		REP(i,n)FORIT(f,graph.G[i]){
			if(f->from > f->to) continue;
			int t = graph.prim2(f->from, f->cost);
			if(t != INF) ans = min(ans, t - f->cost);
		}
		if(ans == INF) ans = -1;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cstdio>
#include <utility>
#include <bitset>
#include <complex>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const ll INF = 1e7;
const ll MOD = (1e9)+7;
int main(){
	ll N;
	cin >> N;
	vector<ll> x(N);
	for(int i=0;i<N;i++)
		cin >> x[i];
	ll ans = 1;
	ll now = 1;
	ll num = 0;
	for(ll i=0;i<N;i++){
		if(x[i]>=now){
			now+=2;
			num++;
		}else{
			ans=(ans*(num+1))%MOD;
		}
	}
	for(ll i=1;i<=num;i++)
		ans=(ans*i)%MOD;
	cout << ans << endl;
	return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t), greater<>());
    if (s < t) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// 基本テンプレート
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// Effective std
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }


// グラフテンプレート
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main(void){
    int r,c;
    cin >> r >> c;
    int **a = new int*[r+1];
    for(int i = 0; i < r+1; i++ ){
        a[i] = new int[c+1];
    }
    for(int i = 0; i < r; i++ ){
        for(int j = 0; j < c; j++ ){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < r; i++ ){
        for(int j = 0; j < c; j++ ){
            a[i][c] += a[i][j];
        }
    }
    for(int j = 0; j < c; j++ ){
        for(int i = 0; i < r; i++ ){
            a[r][j] += a[i][j];
        }
    }
    for(int i = 0; i < r; i++ ){
        a[r][c] += a[i][c];
    }
    for(int i = 0; i < r+1; i++ ){
        for(int j = 0; j < c+1; j++ ){
            cout << a[i][j];
            if( j != c ) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3108
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n, m, x, y;
	cin >> n >> m >> x >> y;

	vector<int> X(n);
	vector<int> Y(m);

	rep(i, 0, n) {
		cin >> X[i];
	}
	rep(i, 0, m) {
		cin >> Y[i];
	}
	sort(X.begin(), X.end(),greater<int>());

	sort(Y.begin(), Y.end());

	bool ans = true;
	if (X[0] >= Y[0]) {
		ans = false;
	}

	if (Y[0] <= x || y<=X[0]) {
		ans = false;
	}

	if (ans)cout << "No War" << endl;
	else cout << "War" << endl;

}
	

Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s; cin >> s;
	bool flag = false;
	for (int i = 0; i < 4; ++i)
		if (s[i] == s[i + 1]) flag = true;
	if (flag) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
string T,work;

int main(){

	scanf("%d",&N);
	cin >> T;
	work = T;

	stack<int> S;

	for(int i = 0; i < N; i++){
		if(work[i] == '('){

			S.push(i);

		}else{ //work[i] == ')'

			if(S.empty()){

				T = '(' + T;
			}else{

				S.pop();
			}
		}
	}

	while(!S.empty()){

		T = T+')';
		S.pop();
	}

	printf("%s\n",T.c_str());

	return 0;
}


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

int main() {
	int N;
	double x[100], y[100], dis[100], sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> y[i];
		dis[i] = abs(x[i] - y[i]);
	}
	for (int i = 1; i <= 3; i++) {
		for (int j = 0; j < N; j++) {
			sum += pow(dis[j], i);
		}
		printf("%.8f\n", pow(sum, 1.0 / i));
		sum = 0;
	}
	for (int i = 0; i < N; i++) {
		sum = max(sum, dis[i]);
	}
	printf("%.8f\n", sum);
}


Measured memory_bytes: 3396