akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;

#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define in1(a,n) F(i,1,n)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define F(i,a,b) for (ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,n) F(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()

int  main(int argc, char const *argv[])
{
	crap;
	int a,b,k;
	cin>>a>>b>>k;
	int x,y;
	rep(i,k)
	{
		if (a&1 && i%2==0)
			a--;
		if (b&1 && i%2==1)
			b--;
		if (i%2==0)
			x=a/2,a/=2,b+=x;
		else	
			y=b/2,b/=2,a+=y;

	}

	cout<<a<<" "<<b<<"\n";
	return 0;
}

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

int main(){
  int n,m;
  while(cin >> n >> m,n&&m){
    int ans=0;
  vector<int> v1(n),v2;
  r(i,n)cin >> v1[i];
  v1.push_back(0);
  n++;
  
  r(i,n)r(j,n)v2.push_back(v1[i]+v1[j]);
  
  sort(v2.begin(),v2.end());
   
  int j=n*n-1;
  r(i,n*n){
    while(j>i&&v2[i]+v2[j]>m)j--;
    if(v2[i]+v2[j]<=m)ans=max(ans,v2[i]+v2[j]);
  }
  cout<<ans<<endl;
  }
}


Measured memory_bytes: 10732
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// 入力
int h, w;
char s[410][410];

vector<P>vec;
bool used1[410][410], used2[410][410];

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

int black, white;

void dfs(int x, int y) {
	memset(used1, false, sizeof(used1));
	used1[x][y] = true; used2[x][y] = true;
	if (s[x][y] == '#')black++;
	else white++;
	rep(i, 8) {
		int nx = x + dx[i]; int ny = y + dy[i];
		if (nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
		if (s[x][y] != s[nx][ny] && !used2[nx][ny])dfs(nx, ny);
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> h >> w;
	rep(i, h)rep(j, w) {
		cin >> s[i][j];
		if (s[i][j] == '#')vec.push_back({ i,j });
	}
	int ans = 0;
	for (P i : vec) {
		if (used2[i.first][i.second])continue;
		black = 0, white = 0;
		dfs(i.first, i.second);
		ans += black * white;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9584
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c; s = "";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	char c;
	while (c = gcu(), c != '\n')
		pcu('A' + (c - 'A' + 26 - 3) % 26);
	out(c);
}


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

template<class T>bool chmax(T &a,const T &b){
    if(a>b)return false;
    a=b;
    return true;
}
template<class T>bool chmin(T &a,const T &b){
    if(a<b)return false;
    a=b;
    return true;
}

/*-------------------------------------------*/

int a,p;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

vector <int> g[10005];
int mas[10005], value[10005], uk;

void dfs(int v, int pr)
{
    value[v] = mas[uk];
    uk--;
    for (int i = 0; i < (int) g[v].size(); i++)
    {
        int u = g[v][i];
        if (u != pr) dfs(u, v);
    }
    return;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    for (int i = 1; i <= n; i++) cin >> mas[i];
    sort(mas + 1, mas + n + 1);
    uk = n;
    dfs(1, -1);

    int ans = 0;
    for (int i = 1; i < n; i++) ans += mas[i];
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) cout << value[i] << ' ';
    return 0;
}



Measured memory_bytes: 1536
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
int main()
{
 int ok=0;
 int X,Y;
 cin>>X>>Y;
 int i,j;
 for(i=0;i<=X;i++)
 {
    j=X-i;
    int p=2*i+4*j;
    if(p==Y)
    {
        ok=1;
        break;
    }
 }
 if(ok)
    cout<<"Yes";
 else
    cout<<"No";
}


Measured memory_bytes: 3676
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long K = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    // 交換レートが３枚以上得でない、もしくは
    // 交換可能枚数にK-2回目に到達できない場合は単純増殖が最適
    if(B<=A+2 || 1+K-2<A) {
      System.out.println(String.format("%d", 1+K));
      return;
    }
    long result = A;
    K = K - (A-1);
    if(K % 2 != 0) {
      result++;
      K--;
    }
    result+=((K/2) * (B-A));
    System.out.println(String.format("%d", result));
  }
}


Measured memory_bytes: 23764
#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif

 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void solve()
{
	int n;
	cin>>n;
	
	int p=1+(n-1)/1000;
	
	int ans=p*1000-n;
	
	cout<<ans;
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
 
int main(){
  int a,b,c;

  cin >> a >> b >> c;

  if (a<=b && b<=c) {
    cout << a <<" "<< b <<" "<< c << endl;
  } else if (a<=c && c<=b) {
    cout << a <<" "<< c <<" "<< b << endl;
  } else if (b<=a && a<=c) {
    cout << b <<" "<< a <<" "<< c << endl;
  } else if (b<=c && c<=a) {
    cout << b <<" "<< c <<" "<< a << endl;
  } else if (c<=a && a<=b) {
    cout << c <<" "<< a <<" "<< b << endl;
  } else {
    cout << c <<" "<< b <<" "<< a << endl;
  }

  return 0;		 
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,count=0;
	cin>>n;
	if(n==1){cout<<1<<endl;return 0;}
	for(int i=2;i*i<=n;i++){
		for(int j=2;pow(i,j)<=n;j++){
			if(count<pow(i,j))count=pow(i,j);
		}
	}
	cout<<count<<endl;
}	


Measured memory_bytes: 384
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

macro_rules! tern {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition {
            $_true
        } else {
            $_false
        }
    };
}

fn main() {
    let N = get!(usize);
    let As = get!(usize | );
    let mut sum = 0f64;
    for A in As {
        sum += 1f64 / (A as f64);
    }
    println!("{}", 1f64 / sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string arr[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string s;
	cin >> s;
	int index;
	for (int i = 0; i<7; i++) {
		if(s==arr[i]) index = i;
	}
	cout << 7 - index << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 16
#define MAXC 100000000000014
#define MAXV 1000000009

int a, b;

int main()
{
    cin >> a >> b;
    if(a <= b)cout << a << endl;
    else cout << a - 1 << endl;

    return 0;
}













Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#define EPS 0.0000001
 
using namespace std;
 
main(){
  int a, b, c, d, e, f;
  double x, y;
  while ( cin >> a >> b >> c >> d >> e >> f ){
    x = 1.0 * ( c*e - b*f ) / ( a*e - b*d ) + EPS;
    y = 1.0 * ( c*d - a*f ) / ( b*d - a*e ) + EPS;
    printf("%.3lf %.3lf\n", x, y);
  }
}

Measured memory_bytes: 1196
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int K = Integer.parseInt(st.nextToken());
		int[] cost = new int[N+1];
		st = new StringTokenizer(br.readLine());
		for (int i = 1; i <= N; i++)
			cost[i] = Integer.parseInt(st.nextToken());
		int count = Integer.MAX_VALUE;
		for (int i = 1, j = i + K - 1; j <= N; i++, j++) {
			count = Math.min(count, cost[j] - cost[i] + Math.min(Math.abs(cost[i]), Math.abs(cost[j])));
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 36508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long LL;

constexpr long long INFLL = 1e18;

using namespace std;

int main()
{
    char s;
    cin >> s;

    if (isupper(s))
    {
        cout << "A" << endl;
    }
    else if (islower(s))
    {
        cout << "a" << endl;
    }

    return 0;
}

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

#define pii pair<int,int>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N=3e5+9;

int ans[N],res;
vector<pii> g[N];
void dfs(int u,int pre=0,int c=0)
{
    int nw=1;
    for(auto x:g[u]){
        int v=x.first,id=x.second;
        if(v==pre) continue;
        if(nw==c) nw++;
        ans[id]=nw;
        res=max(res,nw);
        dfs(v,u,nw);
        nw++;
    }
}
int32_t main()
{
    int n=in();
    for(int i=1;i<n;i++){
        int u=in(),v=in();
        g[u].eb(v,i);
        g[v].eb(u,i);
    }
    dfs(1);
    printf("%d\n",res);
    for(int i=1;i<n;i++) printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 14976
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

static const int INF = 0x3f3f3f3f;

signed main() {
        int n;
        while(scanf("%d", &n), n) {
                vector<int> a(n);
                for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
                int ans = 0;
                for (int k = 1; k <= 500; k ++) {
                        vector<int> b;
                        for (int i = 0; i < n; i ++) {
                                if (a[i] % k != 0) continue;
                                int c = a[i] / k;
                                if (__builtin_popcount(c) == 1) {
                                        b.push_back(c);
                                }
                        }
                        int sum = 0;
                        for (int i = 0; i < b.size(); i ++) sum += b[i];
                        vector<int> dp(sum + 1, -INF);
                        dp[0] = 0;
                        for (int i = 0; i < b.size(); i ++) {
                                int bg = (sum / b[i]) * b[i];
                                for (int s = bg; s - b[i] >= 0; s -= b[i]) {
                                        dp[s] = max(dp[s], dp[s - b[i]] + 1);
                                }
                        }
                        for (int i = 0; (1 << i) <= sum; i ++) ans = max(ans, dp[1 << i]);
                }
                printf("%d\n", ans);
        }
        return 0;
}

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

int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> f(n);
	rep(i, n - 1) if (s[i] == 'A' && s[i + 1] == 'C') f[i] = 1;
	vector<int> t(n + 1);
	rep(i, n) t[i + 1] = t[i] + f[i];
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		cout << t[r] - t[l] << endl;
	} 
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    long ans = 0;
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    int mcount = 0;

    for(int i = 0; i < N; i++){
        if(A[i] < 0){
            mcount++;
        }
    }

    if(mcount % 2 == 0){
        for(int x : A){
            ans += abs(x);        
        }
    }

    int minvalue = 1000000000;
    int minflag = 0;
    
    if(mcount % 2 != 0){
        for(int i = 0; i < N; i++){
            if(abs(A[i]) < minvalue){
                minvalue = abs(A[i]);
                minflag = i;
            }
        }

        
        for(int i = 0; i < N; i++){
            if(i == minflag){
                ans = ans - abs(A[i]);
            }else{
                ans += abs(A[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int s, n;
  cin >> s >> n;
  int k;
  bool canuse[15] = {false};
  rep(i,n){
    cin >> k;
    canuse[k] = true;
  }
  int copy;
  while(true){
    copy = s;
    while(copy != 0){
      if(canuse[copy % 10]){
	break;
      }
      copy /= 10;
    }
    if(copy == 0){
      cout << s << '\n';
      break;
    }
    s ++;
  }
  return 0;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[210][100010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X;
    cin >> N >> X;
    ll S[210];
    rep(i,0,N) cin >> S[i];
    dp[0][X] = 1;
    sort(S, S+N, greater<ll>());
    rep(i,0,N){
        rep(x,0,X+1){
            (dp[i+1][x % S[i]] += dp[i][x]) %= MOD;
            (dp[i+1][x] += dp[i][x] * (N-i-1)) %= MOD;
        }
    }
    ll ans = 0;
    // rep(x,0,X+1) print(x, dp[1][x]);
    rep(x,0,X+1){
        ans += dp[N][x] * x;
        ans %= MOD;
    }
    print(ans);


    

}

Measured memory_bytes: 157184
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

const ll MA = 1000005;
int cnt[2];
int c[2];
int main() {

	int n;
	cin >> n;
	vector<int> p(n);
	int ans = 0;
	rep(i, n)cin >> p[i];

	for (int i = 1; i < n - 1; i++) {
		vector	<int> x;
		x.push_back(p[i - 1]);
		x.push_back(p[i]);
		x.push_back(p[i + 1]);

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

		if (x[1] == p[i]) ans++; 

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#import<bits/stdc++.h>
#define LL long long
using namespace std;
int a,b,c,i,j,k,m,n,s,t,x,y,z[26];
int dgs(int x){int s=0;for(;x;x/=10)s+=x%10;return s;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int max2(int x,int y){return x>y?x:y;}
int max3(int x,int y,int z){return x>y?x>z?x:z:y>z?y:z;}
int min2(int x,int y){return x<y?x:y;}
int min3(int x,int y,int z){return x<y?x<z?x:z:y<z?y:z;}
int prime(int x){if(x<2||x%6^1&&x%6^5)return x==2|x==3;for(int i=5;i*i<=x;i+=6)if(x%i<1||x%(i+2)<1)return 0;return 1;}
char e[5];
main()
{
scanf("%s",e);
for(i=0;i<4;i++)s+=!z[e[i]-65]++;
printf(s==2?"Yes":"No");
}

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

bool solve(const string& s) {
  if (s[2] != s[3])
    return false;
  if (s[4] != s[5])
    return false;
  return true;
}

int main() {
  string s;
  cin >> s;
  cout << (solve(s) ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
S=[input() for i in range(n)]

nes=set(S[0])
for i in range(1,n):
    nes=nes&set(S[i])
nes=list(nes)

words={}
for i in range(n):
    for chr,cnt in Counter(S[i]).items():
        if chr in nes:
            if chr not in words:words[chr]=cnt
            else:words[chr]=min(words[chr],cnt)

ans=""
for i,j in sorted(words.items()):
    ans +=i*j
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n;
  string s;
  cin>>n>>s;
  ll ans=0;
  for(int i=1;i<n;i++){
    ll cnt=0;
    for(char c='a';c<='z';c++){
      bool f=0,g=0;
      for(int j=0;j<i;j++)if(s[j]==c)f=1;
      for(int j=i;j<n;j++)if(s[j]==c)g=1;
      if(f&&g)cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty = list(map(int, input().split()))
for i in range(ty-sy):
    print('U', end='')
for i in range(tx-sx):
    print('R', end='')
for i in range(ty-sy):
    print('D', end='')
for i in range(tx-sx):
    print('L', end='')


print('L', end='')
for i in range(ty-sy+1):
    print('U', end='')
for i in range(tx-sx+1):
    print('R', end='')
print('D', end='')
print('R', end='')
for i in range(ty-sy+1):
    print('D', end='')
for i in range(tx-sx+1):
    print('L', end='')
print('U', end='')

    

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e5+5;
ll n, k, h[A], dp[A];
ll table1()
{
	dp[0] = 0, dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++)
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	return dp[n-1];
}
ll table2()
{
	dp[0] = 0;
	for (int i = 1; i < n; i++)
	{
		dp[i] = 1e9;
		for (int j = max(0, i - (int)k); j < i; j++)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	return dp[n-1];
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; cin >> h[i++]);
	//cout << table1();
	cout << table2();
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stack>
#include<vector>
using namespace std;
 
int main(void){
	int n;cin >> n;
	long long a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	//a[i] = i;
	}
	stack< pair<long long,long long> > st;
	long long max_area=0;
	st.push(make_pair(0,a[0]));
	for(int i=0;i<n;i++){
		pair<long long,long long> v = st.top();
		if(a[i] == v.second)continue;
		if(a[i] > v.second){
			st.push(make_pair(i,a[i]));
		}else{
			long long k;
			while(v.second > a[i] && !st.empty()){
				v = st.top();
				k = v.first;
				max_area = max(max_area,(i-v.first)*v.second);
				st.pop();
				if(!st.empty())v = st.top(); 
			}
			st.push(make_pair(k,a[i]));
		}
	}
	
	while(!st.empty()){
		pair<long long,long long> v = st.top();
		//cout << "v.first" << v.first << "v.second " << v.second << endl;
		max_area = max(max_area,(n-v.first)*v.second);
		st.pop();
	}
	cout << max_area << endl;
	return 0;
}


Measured memory_bytes: 5408
N,M = map(int,input().split())
H = list(map(int,input().split()))
bad = []
for i in range(M):
    A,B = map(int,input().split())
    if H[A-1] > H[B-1]:
        bad.append(B-1)
    elif H[A-1] < H[B-1]:
        bad.append(A-1)
    else:
        bad.append(A-1)
        bad.append(B-1)
print(N-len(set(bad)))

Measured memory_bytes: 20024
N,Q = map(int,input().split())

graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

value_list = [0]*(N+1)

for _ in range(Q):
    p,x = map(int,input().split())
    value_list[p] += x 


from  collections import deque

que = deque([(0,1)])

while que:
    parent,me = que.popleft()
    value_list[me]+=value_list[parent]
    for child in graph[me]:
        if child==parent:
            continue
        else:
            que.append((me,child))


print(*value_list[1:])

Measured memory_bytes: 127108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = list(map(int, input().strip()))

ans1 = 0
ans2 = 0
for i, v in enumerate(s):
    if v != (i % 2):
        ans1 += 1
    else:
        ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 77020
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        System.out.println(
            calcDebt(100000.0, new Scanner(System.in).nextInt())
        );

    }

    private static int calcDebt(double firstDebt, int nWeeks) {
        double debt = firstDebt;
        for(int i = 0; i< nWeeks; i++) {
            debt = Math.ceil(debt * (1 + 0.05) / 1000.0) * 1000.0;
        }
        return (int)debt;
    }
} 

Measured memory_bytes: 17160
X=int(input())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
  
while True:
  if is_prime(X):
    print(X)
    exit()
    
  X=X+1
  

Measured memory_bytes: 3060
def main():
    s = input()
    p = input()

    S = list(s)
    P = list(p)

    C = [] #Checker
    f = False
    for x in range(len(S)):
        if P[0] == S[x]:
            C.append(x)
            f = True

    if f == False:
        print("No")
    else:
        Ans = []
        for z in range(len(C)):
            cnt = 0
            for x in range(len(S)):
                if x + C[z] >= len(S):
                    i = x + C[z] - len(S)
                else:
                    i = x + C[z]
                if P[x] == S[i]:
                    cnt += 1
                    if cnt == len(P):
                        break
                else:
                    break

            if cnt == len(P):
                Ans.append(1)
            else:
                Ans.append(0)
        
        if 1 in Ans:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 7636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

const int MAX_ROW = 70;
const int MAX_COL = 100005;
struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

void GaussJordan(BitMatrix& A, bool is_extended = false) {
	vector<bool> used(A.H, 0);
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = 0; row < A.H; ++row) {
			if (used[row]) continue;
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		for (int row = 0; row < A.H; ++row) {
			if (row != pivot && A[row][col]) A[row] ^= A[pivot];
		}
		used[pivot] = true;
	}
}
const int MD = 60;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	ll ans = 0;

	BitMatrix BM(MD+1, N+1);//65個の方程式，各方程式に対してN+1個の変数(0か1)
	//初期化時は，A_1+...+A_N=0ならば，列はN+1個で初期化すること（でないと落ちる）
	vector<bool> cannot(MD+1, 0);

	for (ll mask = MD; mask >= 0; mask--)
	{
		int num = 0;
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				num++;
			}
		}

		if (num == 0) {
			//全て0
			cannot[mask] = 1;
			continue;
		}
		else if (num & 1) {
			//1が奇数個(この桁は値は一定)
			cannot[mask] = 1;
			ans += (1LL << mask);
			continue;
		}

		//ここは1が偶数個存在する場合
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				BM[MD - mask][i] = 1;
			}

		}
		BM[MD - mask][N] = 1;
	}

	GaussJordan(BM, true);

	for (int mask = MD; mask >= 0; mask--)
	{
		if (cannot[mask]) {
			continue;
		}

		bool ok = false;

		for (int i = 0; i < N; i++)
		{
			if (BM[MD - mask][i]) {
				ok = true;
			}
		}
		if (!BM[MD - mask][N]) {
			ok = true;
		}

		if (ok) {
			ans += (1LL << (mask + 1));
		}
	}

	cout << ans << endl;
	

}



Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	char a[3];
	
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]=='a'&&a[1]=='b'&&a[2]=='c')cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

string str[3] = {"ABC", "DEF", "GHI"};
int my[] = {0, 0, 1, -1};
int mx[] = {1, -1, 0, 0};
set<string> S;

void dfs(int y, int x, string s){
  s += str[y][x];
  S.insert(s);
  if(s.length() >= 10) return ;
  REP(i, 4){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 3 || nx >= 3 || ny < 0 || nx < 0) continue;
    dfs(ny, nx, s);
  }
}

int main() {
  REP(i, 3) REP(j, 3) dfs(i, j, "");
  string s;
  while(cin >>s) if(S.find(s) != S.end()) cout <<s <<endl;
  return 0;
}

Measured memory_bytes: 16000
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;
		vector<int> A( N );
		for( int i = 0; i < N; ++i ) { cin >> A[i]; }

		long x = 1000;
		for( int i = 1; i < N; ++i ) {
			if( A[i] > A[i-1] ) {
				long y = x / A[i-1];
				x -= y * A[i-1];
				x += y * A[i];
			}
		}

		cout << x << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3680
using System;

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split(' ');
        var n = int.Parse(nk[0]);
        var k = int.Parse(nk[1]);
        Console.ReadLine();
        Console.WriteLine(ceil(n - 1, k - 1));
    }

    static int ceil(int x, int y)
    {
        return x % y == 0 ? x / y : x / y + 1;
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    string s1, s2; cin >> s1 >> s2;

    bool ok = s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0];

    cout << (ok? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function isPrime(x)
	if x <= 1
		false
	elseif x == 2
		true
	elseif x%2 == 0
		false
	else
		i = 3
		f = 0
		while i <= sqrt(x)
			if x%i == 0
				f = 1
				break
			else
				i += 2
			end
		end
		f==0?true:false
	end
end

function main()
	x = readline() |> parseInt
	while !isPrime(x)
		x += 1
	end
	println(x)
end

main()

Measured memory_bytes: 109428
import java.util.Scanner;

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

        int k = scan.nextInt();
        int x = scan.nextInt();

        scan.close();

        if(k * 500 >= x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include <iostream>

#include <algorithm>
#include <cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;
typedef long long LL;

int main() {


	int a, b,c;
	//----------------------
	LL n, X, Z,A,B,N,ans1,ans2,i,m;
	LL ans, count=0 ;
	bool f=true;
	string s;

	cin >> s;
	s[5] = ' ';
	s[13] = ' ';

	
	

	

	cout << s << endl;

	
	//------------------------
	//cin >> Z;

	return 0;
}

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

int main() {
   int N, total = 0;
   cin >> N;
   vector<int> d(N);
   vector<int> result(150);
   for(int i = 0; i < N; i++){
    cin >> d.at(i);
    result.at(d.at(i))++;
   }
   for(int i = 1; i < 150; i++){
    if(result.at(i)){
        total++;
    }
   }
   cout << total << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int i,sum=0;
    long long int n,m,a,b;
    double d;

    scanf("%lld %lld",&n,&m);

    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld",&a,&b);

        d = sqrt((a*a)+(b*b));

        if(d<=m) sum++;

        else continue;
    }

    printf("%d",sum);

return 0;
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c; cin >> a >> b >> c; 
    if(a+b+c >= 22) OUT("bust");
    else OUT("win");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
typedef pair<int, int>P;
typedef pair<P, int> PP;
#define int long long

int a[10001], b[10001];

signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int j = 0; j < n; j++)cin >> b[j];

	int ps = 0, ms= 0;
	for (int i = 0; i < n; i++) {
		int c = b[i] - a[i];
		if (c>0)ps+=(c/2*2);
		else ms+=c;
	}
	if (ps*-1 > 2 * ms)puts("No");
	else puts("Yes");
}

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

typedef pair<int, int> PII;

const int MAX_N = 110;
const int MAX_H = 25;
const int INF = 1e9;

struct edge{
  int to, cost, hour, r;
  edge(int to, int cost, int hour, int r):
    to(to), cost(cost), hour(hour), r(r){}
};

struct State{
  int v, hour, cost;
  State(int v, int hour, int cost):
    v(v), hour(hour), cost(cost){}
};

int N, M, H, K;
vector<edge> G[MAX_N];
vector<PII> V;
int S, T, P;
int money[(1<<8)];
int dp[MAX_H][MAX_N];
int ans;

void init(){
  for(int i = 0 ; i < MAX_N ; i++) G[i].clear();
  V.clear();
  fill(money, money+(1<<8), INF);
}

int solve(int bit){
  for(int i = 0 ; i < MAX_H ; i++)
    for(int j = 0 ; j < MAX_N ; j++) dp[i][j] = INF;

  queue<State> que;
  que.push(State(S, 0, 0));  
  
  dp[0][S] = 0;
  
  int res = INF;
  
  while(!que.empty()){
    State q = que.front(); que.pop();
    
    if(ans < q.cost) continue;
    if(res < q.cost) continue;
    
    if(q.v == T){
      res = min(res, q.cost);
    }
    
    int v = q.v;
    for(int i = 0 ; i < (int)G[v].size() ; i++){

      int r = G[v][i].r;
      int nexv = G[v][i].to;
      int nexh = q.hour + G[v][i].hour;      
      int nexc;
      
      nexc = q.cost + G[v][i].cost;
      if((bit>>r) & 1) nexc = q.cost;
      
      if(nexh > H) continue;
      
      if(dp[nexh][nexv] > nexc){     
	dp[nexh][nexv] = nexc;
	
	que.push(State(nexv, nexh, nexc));
      }
    }    
  }
  return res;
}

void rec(int bit, int cost){
  if(money[bit] <= cost) return;
  money[bit] = cost;
  for(int i = 0 ; i < (int)V.size() ; i++){
    int t = bit | V[i].first;
    if(t == bit) continue;
    rec(t, cost + V[i].second);
  }
}

int main(){
  while(cin >> N >> M >> H >> K, N|M|H|K){
    init();
    
    int from, to, cost, hour, r;
    for(int i = 0 ; i < M ; i++){
      cin >> from >> to >> cost >> hour >> r;
      from--, to--, r--;
      G[from].push_back(edge(to, cost, hour, r));
      G[to].push_back(edge(from, cost, hour, r));
    }
    
    cin >> S >> T;
    S--, T--;
    cin >> P;
    
    for(int i = 0 ; i < P ; i++){
      int l, d;
      cin >> l >> d;
      int k;
      int bit = 0;
      for(int j = 0 ; j < l ; j++){
	cin >> k;
	k--;
	bit += (1<<k);
      }      
      V.push_back(PII(bit, d));
    }
    
    rec(0, 0);
    
    ans = INF;
    for(int i = 0 ; i < (1<<K) ; i++){
      if(money[i] == INF) continue;
      ans = min(ans, solve(i) + money[i]);
    }
    
    cout << (ans == INF ? -1 : ans) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

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

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

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

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int n; cin>>n; COUT(n%2==0?n:2*n);
}













Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>


using namespace std;

int main(){
    int n, z, w;
    scanf("%d %d %d", &n, &z, &w);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    if (n == 1) {
        int s;
        if (a[n-1] - w > 0) s = a[n-1] - w;
        else s = w - a[n-1];
        printf("%d\n", s);
    }else{
        int ans = 0;
        int s, t;
        if (a[n-1] - w > 0) s = a[n-1] - w;
        else s = w - a[n-1];
        if (a[n-1] - a[n-2] > 0) t = a[n-1] - a[n-2];
        else t = a[n-2] - a[n-1];
        ans = max(s, t);
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 256
N = int(input())
S = input()

cand = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
    for d in range(1, (N - i + 1) // 2):
        if S[i:i + 2 * d + 1:d] in cand:
            ans -= 1

print(ans)

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

int main(){
    int N=read();
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
        if(i*j==N){
            puts("Yes");
            return 0;
        }
    puts("No");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int k, n;
	cin >> n >> k;
	int tmp;
	for (int i = 0; i < n; i++)cin >> tmp;
	tmp = 0;
	for (int i = 0; i < n - 1; i += k - 1)
		tmp++;
	cout << tmp << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    string str;
    cin >> str;
    int r = 0, b = 0;
    REP(i, str.length()) {
        if(str[i] == '0')
            r++;
        if(str[i] == '1')
            b++;
    }
    cout << min(r, b) * 2;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main(){

	int n, a, b, c;

	cin >> n;

	while (n--){
		cin >> a >> b >> c;

		if (a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}

	}



	return 0;
}

Measured memory_bytes: 1152
H, W = gets.split.map &:to_i
a = []
a << ('#' * (W + 2)).to_s
H.times.map do
  a << '#' + gets.chomp + '#'
end
a << ('#' * (W + 2)).to_s
(H+2).times do |i|
  puts a[i]
end

Measured memory_bytes: 14380
#include <iostream>
 
using namespace std;
 
int main()
{
    long long int n;
    cin >> n;
    long long int a[n+3]={0},b[n+3],i,x,sum=0,y;
    for(i=1;i<=n;i++)
        {
            cin >> x;
            b[i]=x;
            a[x]++;
        }
   for(i=1;i<=n;i++)
        {
            if(a[i]!=0)
                sum=sum+((a[i]-1)*a[i])/2;
        }
    
    for(i=1;i<=n;i++)
        {   
            x=a[b[i]]-1;
            y=sum-(((a[b[i]]-1)*a[b[i]])/2)+((x*(x-1))/2);
            cout << y << "\n";
        }
 
    return 0;
}

Measured memory_bytes: 5760
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, x;
    cin >> n;
    vi monster;
    vi hero;
    for(int i = 0; i < (n+1); i++){
        cin >> x;
        monster.pb(x);
    }
    for(int i = 0; i < n; i++){
        cin >> x;
        hero.pb(x);
    }
    ll sum = 0;
    for(int i = 0; i < n; i++){
        if(monster[i]>=hero[i]){
            sum+=hero[i];
        }
        else{
            sum+=monster[i];
            if(monster[i+1]-hero[i]+monster[i]>=0){
                monster[i+1]-=hero[i]-monster[i];
                sum+=hero[i]-monster[i];
            }
            else{
                sum+=monster[i+1];
                monster[i+1] = 0;
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 1400