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

int main(void) {
int A,B;
scanf ("%d %d", &A, &B);
if(A==1)
{
	if(B==1)
	{
		printf("Draw");
	}
	else
	{
		printf("Alice");
	}
}
else if (B==1)
{
	if(A==1)
	{
		printf("Draw");
	}
	else
	{
		printf("Bob");
	}
}
else
{
	if(A<B)
	{
		printf("Bob");
	}
	else if (A>B)
	{
		printf("Alice");
	}
	else
	{
		printf("Draw");
	}
}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    string w;
    cin>>w;
    int d[200]={0};
    rep(i,w.size()) d[w[i]]++;
    rep(i,200) if(d[i]%2!=0) {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,c,m;
vector<vector<int>> a;
void dfs(int i,int j){
  c+=a[i][j];
  if(i==1&&j==n-1){
    m=max(m,c);
  }
  if(a[i][j+1]!=0){
    dfs(i,j+1);
  }
  if(a[i+1][j]!=0){
    dfs(i+1,j);
  }
  c-=a[i][j];
}
int main(){
  cin>>n;
  a.resize(3);
  for(int i=0;i<3;i++){
    a[i].resize(n+1);
    for(int j=0;j<=n;j++){
      a[i][j]=0;
    }
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  c=0;
  m=0;
  dfs(0,0);
  cout<<m<<endl;
}

Measured memory_bytes: 256
// Problem: B - Product Max
// Contest: AtCoder - AtCoder Beginner Contest 178
// URL: https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" 
//#pragma GCC diagnostic ignored "-Wformat"
using namespace std ;

#define   Pi     2*acos(0.0)
#define   LINF   1LL<<63
#define   ll     long long
#define   ull    unsigned long long
#define   pb     push_back
#define   mp     make_pair
#define   MAX    500006
#define   MAX1   10000008
#define   mem(a,v)   memset(a,v,sizeof(a))
#define   all(x) x.begin(),x.end()
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define yes   cout<<"YES"<<endl
#define no   cout<<"NO"<<endl
#define buga  cout<<1<<endl
#define bugb  cout<<2<<endl
#define bugc  cout<<3<<endl
#define bugd  cout<<4<<endl
#define buge  cout<<5<<endl

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

/*
ll bin_pow(ll o, ll s) {
    if (s == 0) return 1;
    if (s == 1) return o % mod;
    ll d = bin_pow(o, s/2);
    d = (d * 1ll * d) % mod;
    if (s % 2 == 1)
        d = (d * 1ll * o) % mod;
    return d;
}
*/

int main ()
{
    fastIO();
    ll a,b,c,d,n,m,k,l,p,q,r,t,x,y;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    ll Max= -1e18-100,Max1=-1e18+1,Min=LINF;
    string s,s1,s3,s4;
    
    //cin>>n; t = 1;
 	cin>>a>>b>>c>>d;
 		
 	Max = max(a*c,Max);
 	Max = max(a*d,Max);
 	Max = max(b*c,Max);
 	Max = max(b*d,Max);
 	cout<<Max<<endl;

    return 0;
}


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

int main()
{
  char s,t;
  cin >> s >> t;
  if(s == 'H' && t == 'H' || s == 'D' && t == 'D') 
    cout << "H" << endl;
  else
    cout << "D" << endl;
  
  
}

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

typedef unsigned long long ll;
const int MOD = 1e9 + 7;

int table[1010];
bool done[1010];

int main()
{
    int n, tmp;
    ll ans;
    cin >> n;
    memset(done, true, sizeof(done));
    memset(table, 0, sizeof(table));

    for (int i = 2; i <= n; i++)
        for (int j = 2; j <= i; j++)
        {
            if (done[j] == false)
                continue;
            if (i > j && i % j == 0)
                done[i] = false;
            tmp = i;
            while (tmp % j == 0)
            {
                tmp /= j;
                table[j]++;
            }
        }
    ans = 1;
    for (int i = 2; i <= n; i++)
        if (table[i])
            ans = (ans * (table[i] + 1)) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 256
r,c=map(int,input().split())
a=[0]*c
for i in range(r):
    x=list(map(int,input().split()))
    for j in range(c):
        a[j]+=x[j]
    print(*x, end=' ')
    print(sum(x))
print(*a, end=' ')
print(sum(a))

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

using namespace std;
using ll = long long;

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

    string s, t;
    cin >> s;
    cin >> t;

    int res = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == t[i]) res++;

    }
    cout << res << "\n";
    

}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<vector<int>> tree(N, vector<int>());
    for(int i=0; i<N-1; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    queue<pair<int,int>> que;
    que.push({0, -1});
    vector<ll> color(N, -1);
    ll ans = K;
    ll mod = 1e9 + 7;
    while(!que.empty()){
        int now = que.front().first;
        int prv = que.front().second;
        que.pop();
        
        int colorPool = K - 2;
        if(prv==-1) colorPool++;
        for(int e: tree[now]){
            if(e == prv) continue;
            ans = (ans * colorPool) % mod;
            colorPool--;
            que.push({e, now});
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7672
#include<iostream>
#include<vector>

using namespace std;

#define ll long long 

const int INF = 1e9+5;

int main(){
	//freopen("tree.in","r",stdin);
    //freopen("tree.out","w",stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector<int> height(n);
	for(int i = 0; i < n; ++i){
		cin >> height[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	int j;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j <= i+k; ++j){
			if(j < n){
				dp[j] = min(dp[j], dp[i] + abs(height[i]-height[j]));
			}
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int frecv[10];
int main()
{
    int n, obligatoriu = 0, optional = 0;
    cin >> n;
    for (int i = 1; i<=n; ++i)
    {
        int x;
        cin >> x;
        x = x/400;
        x = min(x, 8);
        frecv[x]++;
    }
    for (int i = 0; i<8; ++i)
        if (frecv[i]) ++obligatoriu;
    optional = frecv[8];
    int minim = max (obligatoriu, 1);
    int maxim = obligatoriu + optional;
    cout << minim << " " << maxim;
    return 0;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: String,
        b: String,
    }
    let ab: i64 = format!("{}{}",a, b).parse().unwrap();
    let s = (ab as f64).sqrt() as i64;

    let ans = if s * s == ab { "Yes" } else { "No" };
    ans.to_string()
}

Measured memory_bytes: 4352
import math
N = int(input())
count = 0
for _ in range(N):
    m = int(input())
    rm = int(math.sqrt(m))
    flag = 0
    for i in range(2,rm+1):
        if m %i ==0:
            flag = 1
            break
    if flag ==0 :count=count +1

print(count)

Measured memory_bytes: 5676
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

long long  gcd(long long x,long long y){
  long long mindata,maxdata;
  mindata=min(x,y);
  maxdata=max(x,y);
  while(maxdata%mindata!=0){
    long long temp;
    temp=maxdata%mindata;
    maxdata=mindata;
    mindata=temp;
  }
  return mindata;
}


int main(){
  ll N,K,A[200000],maximum=0,flag=1;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>A[i];
    maximum=max(maximum,A[i]);
  }
  if(N==1){
    if(A[0]!=K){
      flag=0;
    }
    if(flag) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  ll g=gcd(A[0],A[1]);
  for(int i=2;i<N;i++){
    g=gcd(g,A[i]);
  }
  if(maximum<K) flag=0;
  if((maximum-K)%g!=0) flag=0;
  if(flag) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=0
b=0
c=0
d=0

for _ in range(n):
  ji=input()
  if ji=="AC":
    a=a+1
  elif ji=="WA":
    b=b+1
  elif ji=="TLE":
    c=c+1
  else:
    d=d+1
    
print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))

Measured memory_bytes: 9216
def main():
	[A,B,C,K] = list(map(int, input().split()))
	if K >= A:
		K = K - A
		ans = A
	else:
		ans = K
		return ans

	if K >= B:
		K = K - B
	else:
		ans = A
		return ans

	if K > C:
		return "NG"
	else:
		return ans - K


     
if __name__ == '__main__':
	print(main())

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define  INF 1100000000
using namespace std;

int main(){
	string w;
	int a = true;
	int v[1000];
	cin >> w;
	for(int i=0;w[i]!='\0';i++){
		v[w[i]]++;
	}
	for(int i=0;i<26;i++){
		if(v['a'+i]%2==1){
			a = false;
		}
	}
	if(a){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  string in(s);
  int in(n);
  vector<string> result;
  FOR(i, 0, s.length()) {
    int target = min(6, (int)s.length() + 1 - i);
    FOR(j, 1, target) {
      result.push_back(s.substr(i, j));
    }
  }

  set<string> sresult(result.begin(), result.end());
  vector<string> vresult(sresult.begin(), sresult.end());
  sort(vresult.begin(), vresult.end());
  out(vresult[n - 1]);
}


Measured memory_bytes: 2428
C = input()
lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
print(lst[lst.index(C)+1])


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll N; scanf("%lld", &N);
  ll ans = 0;
  for (ll i = 1; i * i <= N; i++){
    if (N % i != 0) continue;
    ll a = i, m = N / i - 1;
    if (a < m) ans += m;
  }
  printf("%lld\n", ans);

  return 0;
}


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

int main(){
   int a, b;
   cin >> a;
  for(b=1;b<10;b++){
   if(a%b==0&&a/b<=9){
     cout<<"Yes"<<endl;
     return 0;
     }
    }
   cout<<"No"<<endl;

  
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[2010]={};

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,ans=0;cin>>n;

  dp[0]=1;
  rep(i,0,n){
    rep(j,i+3,n)(dp[j]+=dp[i])%=mod;
    
  }

  rep(i,0,n-2){
    ans+=dp[i];
    ans%=mod;
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3660
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
input = sys.stdin.readline # 文字列の入力のとき'/n'まで受け取るので注意!!!
sys.setrecursionlimit(500000)

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

C = Counter(A)
for i in range(N):
    print(C[i+1])


Measured memory_bytes: 35076
a, b, c, x, y = map(int, input().split())
cost1 = a * x + b * y
cost2 = max(x, y) * c * 2
cost3 = min(x, y) * c * 2
if x == y:
    pass
elif x > y:
    cost3 += (x - y) * a
else:
    cost3 += (y - x) * b
print(min(cost1, cost2, cost3))


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <set>
#include <algorithm>
using namespace std;
#define LL long long
#define MX 200005

int n;
LL a[55];

bool check(LL x){
    for (LL i=x; i>=max(x-n,(LL)0); --i) {
        LL sum=0;
        for (int j=1; j<=n; ++j) {
                if (i+a[j]-n<0) continue;
                sum+=max((LL)0,(i+a[j]-n)/(n+1)+1);
        }
        if (sum<=i) return true;
    }
    return false;
}
int main ()
{
    scanf("%d",&n);
    for (int i=1; i<=n; ++i) scanf("%lld",a+i);
    LL l=0, r=1e19+1005, mid;
    while (l<r) {
        mid=(l+r)>>1;
        if (check(mid)) r=mid;
        else l=mid+1;
    }
    printf("%lld\n",r);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int a = (2 * y - x) / 3;
    int b = (2 * x - y) / 3;

    COMinit();

    cout << COM(a + b, b) << endl;

    return 0;
}

Measured memory_bytes: 23808
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int n,k,h[605],sum[605];
long long g[605],dp[605][605];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		h[x]=y,h[y]=x;
		sum[x]=1,sum[y]=1;
	}
	n<<=1;g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=(i-1)*g[i-2]%mod;
	for(int i=2;i<=n;i++) sum[i]+=sum[i-1];
	for(int i=1;i<=n;i++)
	for(int j=i;j<=n;j++)
	{
		if((j-i)&1)
		{
			bool flag=0;
			for(int k=i;k<=j;k++)
			{
				if(h[k]&&(h[k]<i||h[k]>j))
				{
					flag=1;
					break;
				}
			}
			if(flag) continue;
			dp[i][j]=g[j-i+1-sum[j]+sum[i-1]];
			for(int k=i+1;k<j;k++) dp[i][j]=(dp[i][j]-dp[i][k]*g[j-k-sum[j]+sum[k]]%mod)%mod;
		}
	}
	k<<=1;
	long long ans=0;
	for(int i=1;i<=n;i++)
	for(int j=i;j<=n;j++)
	if(dp[i][j]) ans=(ans+dp[i][j]*g[n-(j-i+1)-(k-sum[j]+sum[i-1])])%mod;
	printf("%lld\n",ans);
}

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

using namespace std;

bool isOK2after1(vector<int> &com1Inf, vector<int> &com2Sup){
    for(int i=0; i < com1Inf.size() ; i++){
        if( com1Inf[i] >  com2Sup[i]) return false;
    }
    return true;
}
void condition(vector<int> &comInf, vector<int> &com2Inf){
    for(int i=0 ; i< comInf.size() ; i++){
        comInf[i] = max(comInf[i],com2Inf[i]);
    }
}
void conditionSup(vector<int> &comInf, vector<int> &com2Inf){
    for(int i=0 ; i< comInf.size() ; i++){
        comInf[i] = min(comInf[i],com2Inf[i]);
    }
}

int main() {
    int M,N;
    cin >> M >> N;
    int K, s, t;
    string cnd;
    vector<vector<int>> comInf(M,vector<int>(N,0));
    vector<vector<int>> comSup(M,vector<int>(N,100));
    vector<int> sp(N,0);

    for(int i=0; i<M ; i++){
        cin >> K;
        for(int j=0; j<K ; j++){
            cin >> s >> cnd >> t;
            s--;
            if(cnd == ">="){
                comInf[i][s] = max(comInf[i][s],t);
            }else{
                comSup[i][s] = min(comSup[i][s],t);
            }
        }
    }
    for(int i=0 ; i< M ; i++){
        vector<int> ansInf(N,0);
        vector<int> ansSup(N,100);
        if(!isOK2after1(comInf[i],comSup[i])){
            cout << "No" << endl;
            return 0;
        }
        vector<bool> isOK(M,false);
        for(int j=0; j<i ; j++){
            if(isOK2after1(comInf[i], comSup[j])) {
                if(!isOK2after1(comInf[j],comSup[i])){
                    conditionSup(ansSup, comSup[j]);
                }
            }else{
                condition(ansInf, comInf[j]);
                if(!isOK2after1(comInf[j],comSup[i])){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        condition(ansInf,comInf[i]);
        /*
        for(int j=0; j<i ; j++){
            if(isOK[j]){
                if(!isOK2after1(ansInf,comSup[j])){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        */
        if(!isOK2after1(ansInf,ansSup)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3316
s = input()

for i in range(len(s)):
    if s[i] == "U" or s[i] == "D":
        continue
    elif (i+1) % 2 == 0:
        if s[i] != "L":
            print("No")
            exit()
    else:
        if s[i] != "R":
            print("No")
            exit()
print("Yes")



Measured memory_bytes: 9068
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
  string s; cin >> s;
  //string key = "keyence";
  int slen = s.size();
  bool ans = false;
  if(s=="keyence"){
    cout << "YES" << endl;
    return 0;
  }
for(int i=1; i<=slen; i++){
  for(int j=0; j<=slen-i; j++){
    string t=s;
    if(t.erase(j,i)=="keyence")ans = true;
  }
}
if(ans)cout << "YES" << endl;
else cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef pair<int, int> P;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N; cin >> N;
  LL cnt = 0;
  vector<int> A(N), B(N); cin >> A >> B;
  while (A != B) {
    bool update = false;
    for (int i = 0; i < N; ++i) {
      if (A[i] > B[i]) {
        cout << -1 << endl;
        return 0;
      }

      int a = B[(i + N - 1) % N];
      int b = B[i];
      int c = B[(i + 1) % N];
      LL k = (B[i] - A[i]) / (a + c);
      if (k == 0) continue;

      update = true;
      cnt += k;
      B[i] = b - (a + c) * k;
    }
    if (!update) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cnt << endl;
}


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

int z(int x){
  return max(x,-x);
}
int main(){
  int N;
  cin >> N;
  vector<int> T(N+1);
  vector<int> X(N+1);
  vector<int> Y(N+1);
  T.at(0)=0;
  X.at(0)=0;
  Y.at(0)=0;
  for(int i=1;i<=N;i++){
    cin >> T.at(i) >> X.at(i) >> Y.at(i);
  }
  // move from i to i+1 is able?
  for(int i=0;i<N;i++){
    int dt = T.at(i+1)-T.at(i);
    int dx = z(X.at(i+1)-X.at(i));
    int dy = z(Y.at(i+1)-Y.at(i));
    if(dt < dx + dy){
      cout << "No" << endl;
      return 0;
    }else{
      if((dt-dx-dy)%2==1){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define MOD 1000000007
#define fi first
#define se second
#define ld double

using namespace std;

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

ll a, b, c, x, y, M[10][10], n, m;

int main(){
    // ifstream cin("date.in");
    // ofstream cout("date.out");

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i = 0; i <= 9; i++)
        for(int j = 0; j <= 9; j++){
            cin >> M[i][j];
            if (!M[i][j]) M[i][j] = 2e6;
        }
    
    for(int k = 0; k <= 9; k++)
        for(int i = 0; i <= 9; i++)
            for(int j = 0; j <= 9; j++){
                if(i != j && M[i][j] > M[i][k] + M[k][j])
                    M[i][j] = M[i][k] + M[k][j];
            }
    
    ll cost = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1, x; j <= m; j++){
            cin >> x;
            if (x == -1 || x == 1) continue;
            cost += M[x][1];
        }
    }

    cout << cost;

	return 0;
} 

Measured memory_bytes: 256
import collections
import math


n = int(input())

inputlist = []

for i in range(n):
    inputlist.append("".join(sorted(list(input()))))

counter = collections.Counter(inputlist)

counter = dict(counter)
valuelist = list(map(int, counter.values()))

ans = 0

for i in valuelist:
    if i == 1:
        continue
    if i == 2:
        ans += 1
        continue
    temp = math.factorial(i)
    temp /= math.factorial(i-2)
    temp = int(temp / 2)
    ans += temp

print(ans)


Measured memory_bytes: 22920
<?php
$n = fgets(STDIN);
$h = explode(' ', fgets(STDIN));
$k = 0;
$p = 0;

for ($i=0; $i<$n-1; $i++) {
    if($h[$i] >= $h[$i+1]+2) {
        $k = 999;
        break;
    }elseif($h[$i]-1 == $h[$i+1]) {
        if($p > $h[$i+1]){
            $k = 999;
        }
        $p = $h[$i+1];
    }
}
if ($k == 0) {
    echo "Yes";
} else {
    echo "No";
}

Measured memory_bytes: 14840
#include <iostream>
#define ll long long
using namespace std;

int main() {
      ll N, A, B;
      cin >> N >> A >> B;

      ll min = (N-1) * A + B;
      ll max = A + (N-1) * B;

      if(N==1 && A==B) cout << 1 << endl;
      else if(max >= min) cout << max - min + 1 << endl;
      else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9+7;
const int N = 25;
const int INF = 0x3f3f3f3f;

int h,w,dp[405][405];
char m[N][N];
int mvx[] = {1,0,0,-1};
int mvy[] = {0,1,-1,0};

inline bool check(int x,int y){
	if(x < 1 || x > h || y < 1 || y > w || m[x][y] == '#') return 0;
	return 1;
}

void cal(int x,int y){
	if(m[x][y] == '#') return ;
	
	int u = (x-1)*w+y;
	for(int i = 0;i < 4;++i){
		int tx = x+mvx[i];
		int ty = y+mvy[i];
		if(check(tx,ty)){
			int v = (tx-1)*w+ty;
			dp[u][v] = 1;
		}
	}
	return ;
}

int main()
{
    scanf("%d%d",&h,&w);
    for(int i = 1;i <= h;++i) scanf("%s",m[i]+1);
    
    int g = h*w;
    for(int i = 1;i <= g;++i){
    	for(int j = 1;j <= g;++j){
    		dp[i][j] = INF;
		}
		dp[i][i] = 0;
	}
	
	for(int i = 1;i <= h;++i){
		for(int j = 1;j <= w;++j){
			cal(i,j);
		}
	}
	
	int ans = 0;
	for(int k = 1;k <= g;++k){
		for(int i = 1;i <= g;++i){
			if(dp[i][k] == INF) continue;
			for(int j = 1;j <= g;++j){
				if(dp[k][j] == INF) continue;
				dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	
	for(int i = 1;i <= g;++i){
		for(int j = 1;j <= g;++j){
			if(dp[i][j] != INF) ans = max(ans,dp[i][j]);
		}
	}
	
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 896
//https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_a
//A - Can you get AC?
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    string S; cin>>S;
    bool ans=false;
    FOR(i,0,S.size()-1){
        if(S.at(i)=='A'&& S.at(i+1)=='C') ans=true;
    }
    cout<<(ans?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && a==c) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}


Measured memory_bytes: 3556
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;

 main()

{
    fast
    int n;
    cin>>n;
    int a[n+4];
    int sum=0;
    f(i,0,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int x=1;
    int cnt=0;
    sum-=1;
    f(i,0,n)
    {
        cnt+=x;
        if(a[i]>x)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        x=x-a[i];
        int can=min(x,sum);
        sum-=can;
        x=x+can;
    }
    cout<<cnt<<endl;
    return 0;

}





































Measured memory_bytes: 4396
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int a,b;
   cin >> a >> b;
   cout << 6 - (a + b) << endl;




   return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] L = new int[n];
			int ret = 0;
			
			for(int i=0;i<n;i++) {
				L[i] = sc.nextInt();
			}
			
			Arrays.sort(L);
			
			for(int i=0;i<=n-3;i++) {
				for(int j=i+1;j<=n-2;j++) {
					for(int k=j+1;k<=n-1;k++) {
						
						if(L[i]==L[j]||L[j]==L[k]) {
							continue;
						}
						
						if(L[i]<L[j]+L[k]&&L[j]<L[i]+L[k]&&L[k]<L[i]+L[j]) {
							ret++;
						}
					}
				}
				
			}
			
			System.out.println(ret);
	    }
				
	}
	


Measured memory_bytes: 36436
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

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

    int N;
    cin >> N;
    map<int, int> A;
    FOR(i, 1, N + 1) {
        int a;
        cin >> a;
        A[a] = i;
    }

    FOR(i, 1, N) { cout << A[i] << " "; }
    cout << A[N] << endl;

    return 0;
}


Measured memory_bytes: 5504
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

suff = 0

for i in range(n):
    suff += B[A[i]-1]

for j in range(n-1):
    if A[j+1] == A[j]+1:
        suff += C[A[j]-1]
        
print(suff)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int n;

void dfs(string now,char mx)
{
	//cout<<now.size()<<endl;
	if(now.size()==n)
	{
		cout<<now<<endl;
	}
	else
	{
		for(char i = 'a';i<=mx+1;i++)
		{
			dfs(now+i,max(i,mx));
		}
	}
	
}

int main()
{
	cin >> n;
	dfs("",'a'-1);
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main(void)
{
  int a, b, d;
  int aa, bb;

  while(scanf("%d %d",&a, &b)!= EOF)
    {
      aa = a;
      bb = b;
      if(a>b)
	{
	  for(;;)
	    {
	      d = a % b;
	      if(d==0)
		break;
	      a = b;
	      b = d;
	    }
	  d = aa/b*bb;
	  printf("%d %d\n",b,d);
	}
      else
	{
	  for(;;)
	    {
	      d = b % a;
	      if(d==0)
		break;
	      b = a;
	      a = d;
	    }
	  d = aa/a*bb;
	  printf("%d %d\n",a,d);
	}
    }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m,v,p ;
	cin >> n >> m >> v >> p ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	sort(all(a)) ;
	reverse(all(a)) ;
	ll l,r,mid ;
	l = p-1 ;
	r = n ;
	while(l+1<r){
		mid = (l+r)/2 ;
		if(a.at(p-1)>a.at(mid)+m){
			r = mid ;
			continue ;
		}
		ll cnt = 0 ;
		cnt += m*(p-1+n-mid) ;
		for(int i=p-1;i<mid;i++) cnt += a.at(mid)+m-a.at(i) ;
		if(cnt>=m*v) l = mid ;
		else r = mid ;
	}
	cout << l+1 << endl ;
}


Measured memory_bytes: 1152
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<stdio.h>
#include<vector>
#define rep(i,n)for(int i=0;i<n;i++)
//printf("%.yf\n",x); xを小数点以下y桁で
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    vector<string>data(a);
    rep(i, a) {
        cin >> data[i];
    }
    sort(data.begin(), data.end());
    rep(i, a) {
        cout << data[i];
    }
    cout << endl;
   return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        long[] line = Pattern.compile(" ").splitAsStream(stdin.readLine()).mapToLong(Long::parseLong).toArray();
        long n = line[0];
        long a = line[1];
        long b = line[2];
        long c = line[3];

        long sum = 0;
        for (long m = n; m < 2 * n; m++) {
            long numer = (modPow(a, n) * modPow(b, m - n) % mod + modPow(b, n) * modPow(a, m - n) % mod) * m * 100 % mod;
            long denom = (100 - c) * modPow(a + b, m) % mod;
            sum += c((int)(m - 1), (int)(n - 1)) * numer % mod * modInv(denom) % mod;
            sum %= mod;
        }
        stdout.println(sum);
    }

    private long mod = 1000000007;

    private long modPow(long x, long y) {
        long z = 1;
        while (y > 0) {
            if (y % 2 == 0) {
                x = (x * x) % mod;
                y /= 2;
            } else {
                z = (z * x) % mod;
                y--;
            }
        }
        return z;
    }

    private long modInv(long x) {
        return modPow(x, mod - 2);
    }

    private int maxlen = 500000;
    private long[] fct = new long[maxlen];
    private long c(int n, int r) {
        if (fct[0] == 0) {
            fct[0] = 1;
            for (int i = 1; i < maxlen; i++) {
                fct[i] = fct[i - 1] * i % mod;
            }
        }
        return fct[n] * (modInv(fct[n - r]) * modInv(fct[r]) % mod) % mod;
    }

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

Measured memory_bytes: 29268
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

type t = { h : int; i : int }

let max (x : int) y = if x > y then x else y

let solve w v =
  let (m, _, xs) = Array.fold_left (fun (m, i, xs) h -> match xs with
    | [] -> (m, i + 1, [ { h; i } ])
    | x :: _ ->
      if x.h = h then (m, i + 1, xs)
      else if x.h < h then (m, i + 1, { h; i } :: xs)
      else
        let rec doit m j = function
          | [] -> (m, i + 1, [ { h; i = j } ])
          | x :: tl as xs ->
            if x.h >= h then doit (max (x.h * (i - x.i)) m) x.i tl
            else (m, i + 1, { h; i = j } :: xs) in
        doit m i xs)
    (0, 0, [])
    v in
  List.fold_left (fun m x -> max (x.h * (w - x.i)) m) m xs

let () =
  match IO.read_ns () with
  | [h; w] ->
    let s = Array.make w 0 in
    let t = Array.make w 0 in
    let rec doit i ans =
      if i = h then ans
      else begin
        IO.read_ns () |> List.iteri (fun j e -> t.(j) <- if e = 1 then 0 else s.(j) + 1);
        Array.iteri (fun i e -> s.(i) <- e) t;
        let m = solve w t in
        doit (i + 1) (max m ans)
      end in
    doit 0 0 |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 4984
import Data.List
import Data.Ord
import Data.Maybe

data Record = Record {tid::Int, p::Int, score::Int}
instance Eq Record where
 (==) (Record tid1 p1 t1) (Record tid2 p2 t2) = p1 == p2 && t1 == t2
instance Ord Record where
 (<=) (Record tid1 p1 t1) (Record tid2 p2 t2) = 
  (p1 > p2) || (p1 == p2 && t1 < t2) || (p1 == p2 && t1 == t2 && tid1 > tid2)
instance Show Record where
 show (Record tid _ _) = show tid

main = interact $ unlines . map (show' . group . sort . judge) . read' . lines
 where
  read' ("0 0 0 0":_) = []
  read' (mtpr:xs) = (m,t,p,logs) : read' xs'
   where
    [m,t,p,r] = map read (words mtpr)
    (logs',xs') = splitAt r xs
    logs = map (map read . words) logs'
  show' [rs] = wordsBy "=" (map show . reverse . sortBy (comparing tid) $ rs)
  show' (rs:rss) = wordsBy "=" (map show . reverse . sortBy (comparing tid) $ rs) ++ "," ++ show' rss

wordsBy _ [] = []
wordsBy _ [x] = x
wordsBy punc (x:xs) = x ++ punc ++ wordsBy punc xs

judge (m,t,p,logs) = map rec (foldl' total initr logs)
 where
  rec (t,pr,s,_) = Record t (length pr) s
  fst' (x,_,_,_) = x
  initr = [(tid,[],0,replicate p 0) | tid<-[1..t]]
  total acc [time,tid,pid,stat]
   | stat /= 0 = let (t,pr,s,pe) = query tid acc in (t,pr,s,wrong pe) : (filter ((/=tid).fst') acc)
   | otherwise = let (t,pr,s,pe) = query tid acc in (t,pid:pr,score pe s,pe) : (filter ((/=tid).fst') acc)
   where
    score pe s' = s' + time + (pe!!(pid-1)*20)
    wrong = map (\(i,w) -> if i==pid then w+1 else w) . zip [1..]
    query i = fromJust . find ((==i) . fst')

Measured memory_bytes: 9240
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    bool success = false;
    for (int i = 0; 4 * i <= n; i++)
    {
        if ((n - 4 * i) % 7 == 0)
        {
            success = true;
        }
    }
    cout << (success ? "Yes" : "No") << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int ans;
    ans=abs(a[0]-a[n-1]);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
b_list = list(map(int,input().split()))
a_list = []
for i in range(n):
    if i==0:
        a_list.append(b_list[i])
    elif i==n-1:
        a_list.append(b_list[i-1])
    else:
        if b_list[i] <= b_list[i-1]:
            a_list.append(b_list[i])
        else:
            a_list.append(b_list[i - 1])
print(sum(a_list))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,k;
  cin>>n>>k;
  if(n==1){
    cout<<k;
    return 0;
  }
  if(n>1000000){
    cout<<1;
    return 0;
  }
   double c=1;
  for(double i=1;;i++){
    if(k%(ll)pow(i,(double)n)==0){
      c=i;
    }
    if(k<(ll)pow(i,(double)n)) break;
  }
  cout<<(ll)c;
}

Measured memory_bytes: 256
# ABC 123: A – Five Antennas
a = [int(input()) for _ in range(5)]
k = int(input())

isExist = False

for i in range(5):
    for j in range(i, 5):
        if abs(a[i] - a[j]) > k:
            isExist = True

print('Yay!' if not isExist else ':(')

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

int main() {
int a, b;
  cin >> a >> b;
  cout << (3*a + b) / 2<< endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s;
	bool a = true;
	cin >> s;

	for(char i = 'a';i <= 'z';i++){
		int cnt = 0;
		for(unsigned j = 0;j < s.size();j++){
			if(i == s[j]) cnt++;
		}

		if(cnt >= 2){
			cout << "no" << endl;
			a = false;
			break;
		}
	}
	if(a) cout << "yes" << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

vi a(50),b(50);
int n,m;

bool area(int min_x, int max_x, int min_y, int max_y){
  int i,j;
  int cnt=0;
  rep(i,n) if(min_x<=a[i] && a[i]<=max_x && min_y<=b[i] && b[i]<=max_y) cnt++;
  if(cnt>=m)return true;
  else return false;
}

signed main(void) {
  int i,j,k,l;
  cin>>n>>m;
  rep(i,n)cin>>a[i]>>b[i];
  int ans=(ll)INF*INF*5;
  rep(i,n)rep(j,n)rep(k,n)rep(l,n)if(i<j && k<l){
    int min_x=min(a[i],a[j]),max_x=max(a[i],a[j]);
    int min_y=min(b[k],b[l]),max_y=max(b[k],b[l]);
    if(area(min_x,max_x,min_y,max_y))
      ans=min(ans, (max_x - min_x)*(max_y - min_y));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>

using namespace std;

/*
	1 <= n <= 8		??¬??????????????°
	2 <= m <= 30	???????????°

	memo[ ???????????¬?????????bit??? ][ ??????ID ] = ?????????????????¢
*/
const long double INF = 10e25;
const int bitmax = (1 << 9) - 1;

struct node {
	int bits;
	int town;
	double cost;
	bool operator<(const node& right) const {
		return cost < right.cost;
	}
};

int solve();

int main(void) {
	//FILE *fpin = freopen("data.txt", "r", stdin);
	while (solve()) {}
	return 0;
}

int solve() {

	// input
	int n, m, p, a, b;
	cin >> n >> m >> p >> a >> b;
	vector< int > t(n);

	//	??\?¶???¶??????????????????
	//	?????????????????\?¶?????????????
	vector< vector< double > > mat(m, vector< double >(m, -1.0f));
	vector< vector< int > > isDoneNode(bitmax, vector<int>(m, 0));
	vector< vector< double > > cost(bitmax, vector<double>(m, -1.0f));
	vector< vector< int > > contains(bitmax, vector<int>(m, 0));

	if (!(n | m | p | a | b)) { return 0; }

	a--;
	b--;
	
	for (int i = 0; i < n; i++)
		cin >> t[i];

	for (int i = 0; i < p; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		mat[x - 1][y - 1] = z;
		mat[y - 1][x - 1] = z;
	}

	// solve the problem
	// first  = ????????¬?????????bit???
	// second = ??????ID

	priority_queue< node > q;
	cost[0][a] = 0;

	node startNode = { 0,a,0.0f };
	q.push(startNode);

	while (!q.empty()) {
		auto p = q.top();
		q.pop();
		contains[p.bits][p.town] = 0;
		//	?????§?????????
		for (int i = 0; i < m; i++) {
			if (mat[p.town][i] < 0.0f) { continue; }
			for (int j = 0; j < n; j++) {
				if (((1 << j)&p.bits) == 0) {
					double toCost = p.cost + mat[p.town][i] / double(t[j]);
					int bit = p.bits | (1 << j);
					if (cost[bit][i] < 0.0f || toCost < cost[bit][i] ) {
						node n = { bit,i,toCost };
						cost[bit][i] = toCost;
						if (!contains[bit][i]) {
							q.push(n);
							contains[bit][i] = 1;
						}
					}
				}
			}
		}
	}
	


	double ans = INF;
	for (int i = 0; i < cost.size(); i++) {
		if (cost[i][b] >= 0.0f)
			ans = min(ans, cost[i][b]);
	}

	if (ans == INF)
		cout << "Impossible" << endl;
	else
		cout << ans << endl;

	return 1;
}

Measured memory_bytes: 3488