akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define INF 1000000000

signed main()
{
    int H, N; cin >> H >> N;
    vi A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vi dp(H+1, INF);
    dp[0] = 0;
    rep(i, N) {
        rep(j, H+1) {
            if (dp[j] != INF) {
                int dmg = min(H, j + A[i]);
                chmin(dp[dmg], dp[j] + B[i]);
            }
        }
    }

    // rep(j,H+1) {
    //     cout << dp[j] << " ";
    // }
    // cout << endl;

    cout << dp[H] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int n, a[100005], b[100005];
int hs[100005], he[100005];
int main(){
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++) scanf("%d",&b[i]);
	for(int i=1; i<=n; i++){
		if(a[i] != a[i-1]){
			hs[i] = he[i] = a[i];
		}
		else{
			hs[i] = 1;
			he[i] = a[i];
		}
	}
	for(int i=n; i; i--){
		if(b[i] != b[i+1]){
			if(max(hs[i], b[i]) > min(he[i], b[i])){
				puts("0");
				return 0;
			}
			hs[i] = he[i] = b[i];
		}
		else{
			he[i] = min(he[i], b[i]);
		}
	}
	lint ret = 1;
	for(int i=1; i<=n; i++){
		if(hs[i] > he[i]) ret = 0;
		ret *= he[i] - hs[i] + 1;
		ret %= 1000000007;
	}
	cout << ret;
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>
using namespace std;
int n,m;
int a[100000];
map<int,int> mp;
long long ans;
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i)a[i]+=a[i-1];
        a[i]%=m;
        ans+=mp[a[i]];
        mp[a[i]]++;
        if(a[i]==0)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3584
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        
        int y = sc.nextInt();
        
        int a[]={1,3,5,7,8,10,12};
        int b[]={4,6,9,11};
        
        int count =0;
        for(int i=0;i<a.length;i++){
            if(x==a[i]){
                for(int j=0;j<a.length;j++){
                    if(y ==a[j]){
                        System.out.println("Yes");
                        count +=1;
                    }
                }
            }
        }
        for(int i=0;i<b.length;i++){
            if(x==b[i]){
                
                
                for(int j=0;j<b.length;j++){
                    if(y ==b[j]){
                        System.out.println("Yes");
                        count +=1;
                    }
                }
            }
        }
        if(x==2 && y==2){
            System.out.println("Yes");
            count +=1;
        }
        if(count != 1){
            System.out.println("No");
        }
        
        
    }
}

Measured memory_bytes: 35640
//kkc
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <math.h> 
#include <stdio.h> 
#define ll long  long
#define ld long double
#define vi vector <ll>
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define FOR(i, a, b)    for(int i=a; i<b; i++)
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
/*

*/


void solve(){
    string s, t;
    cin>>s>>t;
    int flag = 0;
    int ans = t.length(), cnt;
    FOR(i,0,s.length()-t.length()+1){
        cnt = 0;
        FOR(j,0,t.length()){
            if(t[j]!=s[i+j]){
                cnt++;
            }
            

        }
        // cout<<cnt<<endl;
        ans =min(ans, cnt);

        
    }
    cout<<ans<<endl;
    
}



int main(){
    fastio
    int t=1;
    // cin>>t;
    
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout); 
    while(t--){  
        solve();
    }return 0;
}

Measured memory_bytes: 3648
IMPLICIT NONE
INTEGER :: N, I
CHARACTER,DIMENSION(100) :: C
LOGICAL :: P = .false. , W = .false. , G = .false. , Y = .false.

READ*, N
READ*, C(1:N)

DO I = 1, N   
    IF ( C(I) == "P") THEN
        P = .true.
    ELSE IF (C(I) == "W") THEN
        W = .true.
    ELSE IF (C(I) == "G") THEN
        G = .true.
    ELSE IF (C(I) == "Y") THEN
        Y = .true.
    END IF
END DO

IF (P .AND. W .AND. G .AND. Y) THEN
    PRINT*, "Four"
ELSE
    PRINT*, "Three"
END IF
 
END

Measured memory_bytes: 2636
#include<stdio.h>
int main(){
 int a,b;
  char c;
  scanf("%d %c %d",&a,&c,&b);
  if(c=='+'){
   printf("%d\n",a+b); 
  }else{
    printf("%d\n",a-b);
    
  }
 
 return 0; 
}

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

#define MAX 200002

int n;
vector<int> p;

vector<int> v[MAX]; 
vector<int> rv[MAX];

int outt[MAX];

set<int> ss;
bool bfs(int t,vector<int> &val){
	queue<int> q;
	q.push(t);
	while (!q.empty()){
		int b = q.front();
		q.pop();
		if (val[b] <0){
			ss.clear();
			for (int j = 0; j < v[b].size(); j++){
				ss.insert(val[v[b][j]]);
			}
			int w = 0;
			while (ss.count(w)){
				w++;
			}
			val[b] = w;
		}
		for (int j = 0; j < rv[b].size(); j++){
			int go = rv[b][j];
			if (val[go] == -1){
				val[go] = -2;
				q.push(go);
			}
		}
	}
	ss.clear();
	for (int j = 0; j < v[t].size(); j++){
		ss.insert(val[v[t][j]]);
	}
	int w = 0;
	while (ss.count(w))w++;
	if (w == val[t]){
		return true;
	}
	return false;
}
vector<int> val;
set<int> tmp;
vector<int> cop;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		a--;
		rv[i].push_back(a);
		v[a].push_back(i);
		outt[a]++;
	}
	queue<int> q;
	val.assign(n, -1);
	for (int i = 0; i < n; i++){
		if (outt[i] == 0){
			q.push(i);
			val[i] = 0;
		}
	}
	while (!q.empty()){
		int b = q.front();
		q.pop();
		tmp.clear();
		for (int i = 0; i < v[b].size(); i++){
			tmp.insert(val[v[b][i]]);
		}
		int w = 0;
		while (tmp.count(w)){
			w++;
		}
		val[b] = w;
		for (int i = 0; i < rv[b].size(); i++){
			outt[rv[b][i]]--;
			if (outt[rv[b][i]] == 0){
				q.push(rv[b][i]);
			}
		}
	}
	bool ans = false;
	for (int i = 0; i < n; i++){
		if (val[i] == -1){
			tmp.clear();
			for (int j = 0; j < v[i].size(); j++){
				if (val[v[i][j]] != -1){
					tmp.insert(val[v[i][j]]);
				}
			}
			int w = 0;
			while (tmp.count(w)){
				w++;
			}
			vector<int> k;
			k.push_back(w);
			w++;
			while (tmp.count(w)){
				w++;
			}
			k.push_back(w);
			cop = val;
			cop[i] = k[0];
			ans|=bfs(i,cop);
			cop = val;
			cop[i] = k[1];
			ans|=bfs(i,cop);
			break;
		}
	}
	if (ans){
		puts("POSSIBLE");
	}
	else{
		puts("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}


int main(){
	IOS;
	cout.precision(30) ;
	int n ; cin >> n ;
	vll a(n) ; for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	sort(a.begin() , a.end()) ;
	ll gcd = 0 ;
	for(int i = 0 ; i < n ; i++) gcd = __gcd(a[i] , gcd) ;
	cout << gcd << endl ;
	return 0;
}


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

#define EPSILON 1e-6
#define ll long long

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  string s;
  cin >> s;
  int c1 = 0;
  int c2 = 0;

  for (int i=0; i<n; i++) {
    if (s[i] == 'R') c1++;
    else c2++;
  }

  if (c1 > c2) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
s = input()
N = len(s)
for i in range(N-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    if i<N-2 and s[i]==s[i+2]:
        print(i+1,i+3)
        break
else:
    print(-1,-1)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
  int W,H,x,y,r=0;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if (W >= x+r && x-r >= 0){if (H >= y+r && y-r >= 0)printf("Yes\n");
                else printf("No\n");}
    
      else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define vll vector<ll>
#define endl "\n"
const ll maxn = 2e5+2;

int main()
{
    fastio;
    ll i, j, k, n, m, t;

    cin>>n;

    cout<<n+(n*n)+(n*n*n)<<endl;


        
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>

struct Node
{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL)
    {
        root = z;
    }
    else
    {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

Node *find(int k)
{
    Node *x = root;
    while (x != NIL && k != x->key)
    {
        if (k < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    return x;
}

void inorder(Node *u)
{
    if (u == NIL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main()
{
    int n, i, x;
    std::string com;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        std::cin >> com;
        if (com == "insert")
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if (com == "find")
        {
            scanf("%d", &x);
            if (find(x) != NIL)
            {
                printf("yes");
            }
            else
            {
                printf("no");
            }
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 22092
#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;

int n, dp[MAXN];

int main() {
    scanf("%d", &n); memset(dp, 0x3f, sizeof(dp)); dp[0] = 0;
    for (register int i = 1; i <= n; ++i)
        dp[i] = min(dp[i], dp[i - 1] + 1);
    for (register int i = 6; i <= n; i *= 6)
        for (register int j = i; j <= n; ++j)
            dp[j] = min(dp[j], dp[j - i] + 1);
    for (register int i = 9; i <= n; i *= 9)
        for (register int j = i; j <= n; ++j)
            dp[j] = min(dp[j], dp[j - i] + 1);
    printf("%d", dp[n]);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <vector>
#include <climits>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
using namespace std; 
#define Endl '\n'
int main()
{
    int n;
    cin>>n;
    if (n%2==0)
    {
        cout<<n/2;
    }
    else
        cout<<n/2+1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const i64 MOD = 1000000007;
const i64 INF = 2e15;

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

    for (int i = x-k+1; i <= k + x - 1; i++) cout << i << " ";
    cout << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int C,D,W,X;
int E[15][30],F[15][30];

int dp[31][51][6];
int dfs(int day, int cost, int x)
{
    if(dp[day][cost][x]>=0) return dp[day][cost][x];
    if(day==D) return 0;

    int ret=0;

    // ??????????????????
    ret=max(ret,dfs(day+1,cost,x));

    rep(place,C)
    {
        if(E[place][day]==0) continue;

        // 1????????????
        if(cost+F[place][day]<=W) ret=max(ret,dfs(day+1,cost+F[place][day],x)+E[place][day]);

        // ?????°????????????
        if(x==X) continue;

        int tcost=cost+F[place][day];
        int tE=E[place][day];
        int now=place-1;
        while(now>=0)
        {
            if(E[now][day]==0) break;
            if(tcost+F[now][day]>W) break;

            tcost+=F[now][day];
            tE+=E[now][day];
            ret=max(ret,dfs(day+1,tcost,x+1)+tE);

            --now;
        }

        tcost=cost+F[place][day];
        tE=E[place][day];
        now=place+1;
        while(now<C)
        {
            if(E[now][day]==0) break;
            if(tcost+F[now][day]>W) break;

            tcost+=F[now][day];
            tE+=E[now][day];
            ret=max(ret,dfs(day+1,tcost,x+1)+tE);
            ++now;
        }
    }

    dp[day][cost][x]=ret;
    return ret;
}

int main()
{
    while(scanf(" %d %d %d %d",&C,&D,&W,&X),C)
    {
        rep(i,C)rep(j,D) scanf(" %d", &E[i][j]);
        rep(i,C)rep(j,D) scanf(" %d", &F[i][j]);

        memset(dp,-1,sizeof(dp));
        int ans=0;
        ans=max(ans,dfs(0,0,0));
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> st;
string s;
int n;
inline void work(int i,int j)
{
	string ss;
	if (j==s.size()-i) ss=s.substr(i);
	else ss=s.substr(i,j);
	if (!count(st.begin(),st.end(),ss)) st.push_back(ss);
}
int main()
{
	cin >>s;
	cin >>n;
	for (int i=0;i<s.size();i++)
	{
		for (int j=1;j<=s.size()-i && j<=5;j++)
		{
			work(i,j);
		}
	}
	sort(st.begin(),st.end());
	st.erase(unique(st.begin(),st.end()),st.end());
	cout <<st[n-1];
	return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   int n;
   string s;
   cin >> n;
   cout << n/3 << endl;

   return 0;
}

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

int main() {
    int k;
    string s;
    cin >> k;
    cin >> s;

    string ans = "";

    if(k < s.length()){
        for(int i=0; i<k; i++){
            ans += s[i];
        }
        ans += "...";
        cout << ans << endl;
    }
    else cout << s << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if((A==B) && (A!=C)){
		cout << "Yes" << endl;
	} else if((A==C) && (A!=B)){
		cout << "Yes" << endl;
	} else if((B==C) && (A!=B)){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr LL MOD = 998244353;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

LL dfs(int n, int blue, VI &ru, VVLL &memo) {
    if (n <= 0 || blue < 0) return 0;
    //cout << n << " " << blue << " " << ru[min((int)ru.size()-1,n)] << " " << memo[n][blue] << endl;
    if (memo[n][blue] > -1) return memo[n][blue];
    if (n < blue) return memo[n][blue] = 0;
    if (n <= ru.size()) {
        if (blue > ru[n-1]) return memo[n][blue] = 0;
        if (n - blue > 2 * n - ru[n-1]) return memo[n][blue] = 0;
    } else {
        int maxb = ru[ru.size()-1];
        if (blue > maxb) return memo[n][blue] = 0;
        if (n - blue > 2 * ru.size() - maxb) return memo[n][blue] = 0;
    }
    if (n == 1) return 1;
    return memo[n][blue] = (dfs(n-1, blue - 1, ru, memo) + dfs(n-1, blue, ru, memo)) % MOD;
}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    VI ru(n);
    ru[0] = s[0] - '0';
    REP(i,1,n) ru[i] = ru[i-1] + s[i] - '0';
    VVLL memo(2*n+1, VLL(2*n+1, -1));
    cout << dfs(2*n,ru[n-1],ru,memo) << endl;
}

int main() {
    solve();
    
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  
  vector<int> c[100005];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  
  queue<int> q;
  vector<int> p(n,-1);
  
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : c[v]) {
      if (p[u] != -1) continue;
      p[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl;
  rep(i,n) {
    if (i==0) continue;
    cout << p[i] + 1 << endl;
  }
}

Measured memory_bytes: 11696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n){
    string s;
    cin >> s;
    sort(all(s));
    mp[s]++;
  }
  long long ans = 0;
  for (auto &p : mp){
    int s = p.second;
    ans += (long long)s * (s - 1) / 2;
  }

  //string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  int cnt = 0;


  cout << ans << endl;
}

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

int main(){
    int N;
    long long M;
    cin >> N >> M;
    long long MOD = 1000000007;
    int a[20];
    int i = 0;
    long long j = 2;
    while(j*j <= M){
        if(M%j == 0){
            int count = 0;
            while(M%j == 0){
                M /= j;
                count++;
            }
            a[i] = count;
            i++;
        }
        j++;
    }
    if(M != 1){
        a[i] = 1;
        i++;
    }
    long long r[50];
    long long p[50][50];
    rep2(k, 1, 50){
        p[k][1] = k;
        rep2(l, 2, 50){
            p[k][l] = (p[k][l-1] * p[k][l-1]) % MOD;
        }
        long long x = MOD-2;
        long long res = 1;
        int cnt = 1;
        while(x > 0){
            if(x%2 == 1){
                res *= p[k][cnt];
                res %= MOD;
                x -= 1;
            }
            x /= 2;
            cnt++;
        }
        r[k] = res;
    }
    long long ans = 1;
    rep(c, i){
        rep2(d, 1, a[c]+1){
            ans *= (N+a[c]-d);
            ans %= MOD;
            ans *= r[d];
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
//const int inf=1000000007;
const int MOD=1000000007;
int n,k;
struct Nums{
    long long n;
    vector<long long> kaijo;
    Nums(int N){
        n=N;
        kaijo.push_back(1);
        for(long long i=1;i<=n;i++){
            kaijo.push_back((kaijo[i-1]*i)%MOD);
        }
    }
    long myPow(long x, long n, long m){
        if(n == 0)
            return 1;
        if(n % 2 == 0)
            return myPow(x * x % m, n / 2, m);
        else
            return x * myPow(x, n - 1, m) % m;
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    long long comb(long long N,long long K,long long rest){
        long long res=kaijo[N]*modinv(kaijo[K],rest)%rest;
        res*=modinv(kaijo[N-K],rest);
        res%=rest;
        return res;
    }
};

signed main(){
  cin>>n>>k;
  int res=1;
  Nums lib(n+5);
  int sup=0;
  int inf=0;
  int num=0;
  int cur=n;
  int inf_last=0;
  rep1(i,n){
    sup+=cur;
    cur--;
    inf+=inf_last;
    inf_last++;
    if(i>=k)res+=sup-inf+1;
  }
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 5276
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

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

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}


int main() {
    int k;
    cin >> k;
    cout << (k / 2) * ( k % 2 == 0 ? (k / 2) : (k / 2 + 1)) << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<ll>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define possible(n) cout<<((n)?"possible":"impossible")<<endl
#define Possible(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    string s,t;
    cin>>s>>t;
    REP(i,sz(s)){
        bool flag=true;
        REP(j,sz(s)){
            if(s[j]!=t[(j+i)%sz(s)]){flag=false;break;}
        }
        if(flag){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
int main()
{
	int H,W,i,j;
	for(;scanf("%d%d",&H,&W),W;puts(""))
		for(i=0;i<H;i++)
			for(j=0;j<W;j++)
				printf("%c%s",!((i%2+j%2)%2)?'#':'.',j==W-1?"\n":"");
	return 0;
}

Measured memory_bytes: 612
package main

import (
  "fmt"
  "strconv"
)

// argument type must be []rune, not string.
func substr(rs []rune, l, r int) string {
  if l < 0 {l = 0}
  if r > len(rs) {r = len(rs)}
  if l >= r {return ""}
  return string(rs[l:r])
}

func main() {
  var a, b int 
  var s string 
  fmt.Scan(&a, &b, &s)
  ans := "Yes"
  if s[a] == '-' {
    rs := []rune(s)
    if _, err := strconv.Atoi(substr(rs, 0, a)); err != nil {
      ans = "No"
    } else if _, err := strconv.Atoi(substr(rs, a+1, a+b+1)); err != nil {
      ans = "No"
    }
  } else {
    ans = "No"
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


bool possible[3005];


int main(){

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

    int a, b, c, d, e, f;
    cin>>a>>b>>c>>d>>e>>f;

    for(int i=0;i<=3000;i++)
    	for(int j=0;j<=3000;j++)
    		if(i*c+j*d <= 3000)
    			possible[i*c+j*d] = true;

    int w = 0, s = 0;
    for(int i=0;i<=30;i++)
    	for(int j=0;j<=30;j++){
    		int water = i*100*a + j*100*b;
// if(water != 100)	continue;
    		if(water > f)	continue;
    		int maxsugar = min(f - water, (i*a + j*b) * e), actual = 0;
    		for(int k=maxsugar;k>=1;k--)
    			if(possible[k]){
    				actual = k;	break;
    			}
// cout<<maxsugar<<" "<<actual<<endl;

    		if(actual*w >= s*(water+actual)){
    			s = actual;
    			w = water + actual;
    		}
    	}


   	cout<<w<<" "<<s;
    return 0;
}







 




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

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;
#define MAXN 100000
#define MOD 1000000007
int expmod(int n, int p) {
	if(p == 0) return 1;
	int r = expmod(n, p >> 1);
	r = 1LL * r * r % MOD;
	return p & 1 ? 1LL * n * r % MOD : r;
}
int fm[MAXN + 1];
int C(int n, int k) {
	if(n - k < 0) return 0;
	return 1LL * fm[n] * expmod(1LL * fm[k] * fm[n - k] % MOD, MOD - 2) % MOD;
}
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	fm[0] = 1;
	for(int i = 1; i <= n; ++i) fm[i] = 1LL * fm[i - 1] * i % MOD;
	vi x(n);
	for(int& a : x) cin >> a;
	sort(all(x));
	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans = (ans + 1LL * x[i] * (C(i, k - 1) - C(n - i - 1, k - 1))) % MOD;
	cout << (1LL * ans + MOD) % MOD << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

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



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

int main(){
    int N,T,A,H[1010];
    cin >> N>>T>>A;
    for(int i=0;i<N;i++) cin >> H[i];
    
    int min=100000000,c,ans;
    for(int i=0;i<N;i++){
        if((A*1000-T*1000+H[i]*6)>0) c=A*1000-T*1000+H[i]*6;
        else c=-A*1000+T*1000-H[i]*6;

        if(c<min) {
            ans=i+1;
            min=c;
        }
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.util.*
import kotlin.math.max

fun main() = abc175e()

@OptIn(ExperimentalStdlibApi::class)
fun abc175e() = SimpleFastIOWithToken_abc175e().exec {
    val (rows, cols, k) = List(3) { readInt() }
    val items = List(k) { List(3) { readInt() } }

    val grid = Array(rows) { LongArray(cols) }
    items.forEach { (r, c, v) ->
        grid[r - 1][c - 1] = v.toLong()
    }

    val dp = Array(rows) { Array(cols) { LongArray(4) } }

    for (y in 0 until rows) for (x in 0 until cols) {
        for (took in 0..3) {
            when (took) {
                3 -> {
                    if (y + 1 < rows) dp[y + 1][x][0] = max(dp[y + 1][x][0], dp[y][x][3])
                    if (x + 1 < cols) dp[y][x + 1][3] = max(dp[y][x + 1][3], dp[y][x][3])
                }
                else -> {
                    if (y + 1 < rows) {
                        dp[y + 1][x][0] = max(dp[y + 1][x][0], dp[y][x][took] + grid[y][x])
                    }
                    if (x + 1 < cols) {
                        if (grid[y][x] > 0) dp[y][x + 1][took + 1] =
                            max(dp[y][x + 1][took + 1], dp[y][x][took] + grid[y][x])
                        dp[y][x + 1][took] = max(dp[y][x + 1][took], dp[y][x][took])
                    }
                }
            }
        }
    }

    dp[rows - 1][cols - 1][3] =
        max(dp[rows - 1][cols - 1][3], dp[rows - 1][cols - 1].dropLast(1).max()!! + grid[rows - 1][cols - 1])

    val answer = dp.last().last().max()!!

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175e(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175e.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 742024
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
void solve(){
	
}
int main() {
	int a,b;
	cin>>b>>a;
	if(a>=b){
		cout<<"unsafe";
	}
	else
	cout<<"safe";
	return 0;
}

Measured memory_bytes: 3636
from collections import deque

O=deque(list(input()))
E=deque(list(input()))
N=max(len(O),len(E))
#print(O)
#print(E)

ans=[]
for i in range(N):
  if len(O):
    ans.append(O.popleft())
  if len(E):
    ans.append(E.popleft())
print("".join(ans))

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

using namespace std;

typedef long long ll;

const int N=1e6+5,M=1e3+7,mod=1e9+7;

int dx[]={0,1,-1,0},
    dy[]={1,0,0,-1};
              
char s[N];

int a[N],n,m,k,tc,ans,d;

int main() {
    string s;
    cin >> s;
    if (s=="SAT"){
        ans=1;
    }
    else if (s=="MON"){
        ans=6;

    }
    else if (s=="TUE"){
        ans=5;
    }
    else if (s=="WED"){
        ans=4;
    }
    else if (s=="THU"){
        ans=3;
    }
    else if (s=="FRI"){
        ans=2;
    }
    else
        ans=7;
    printf("%d\n",ans);

}

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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))

int n;
int a[110];
ll dp[100][21];

int main() {
    cin >> n;
    rep(i,n) scanf("%d", a+i);

    ZERO(dp);
    dp[0][a[0]] = 1;
    FOR(i,1,n+1) {
        rep(j,21) {
            if(j+a[i] <= 20)
                dp[i][j + a[i]] += dp[i-1][j];
            if(j-a[i] >= 0)
                dp[i][j - a[i]] += dp[i-1][j];
        }
    }

    cout << dp[n-1][a[n]] << "\n";

    return 0;
}

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

int main()
{
	std::string S;
	std::cin >> S;
	auto result = "WA";
	if (S[0] == 'A') {
		int C = 0;
		bool b = true;
		int n = static_cast<int>(S.length());
		for (int i = 1; i < n; ++i) {
			if (2 <= i && i < n - 1 && S[i] == 'C') {
				C++;
			}
			else {
				b &= 'a' <= S[i] && S[i] <= 'z';
			}
		}
		if (C == 1 && b) {
			result = "AC";
		}
	}
	std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>

int top, S[1000];

void push(int x)
{
	S[++top] = x;
}

int pop()
{
	top--;
	return S[top + 1];
}

int main()
{
	using namespace std;

	int foo, bar;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '+')
		{
			foo = pop();
			bar = pop();
			push(foo + bar);
		}
		else if (s[0] == '-')
		{
			bar = pop();
			foo = pop();
			push(foo - bar);
		}
		else if (s[0] == '*')
		{
			foo = pop();
			bar = pop();
			push(foo * bar);
		}
		else
		{
			push(stoi(s));
		}
	}

	printf("%d\n", pop());
}

Measured memory_bytes: 2756
# -*- coding: utf-8 -*-

n = int(input())
d = sorted(list(map(int, input().split())))

h1 = int(n/2-1)
h2 = int(n/2)
if d[h1] == d[h2]:
    print(0)
else:
    print(d[h2]-d[h1])

Measured memory_bytes: 14428
N,M = map(int,input().split())
count = (N-2)*(M-2)

if N == 1 and M == 1:
    count = 1
elif N==2 or M == 2:
    count = 0
elif N == 1 and M >= 3:
    count = M-2
elif M== 1 and N >= 3:
    count = N-2
    
print(count)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int l1,l2,l3,ans1,ans2;
  char a;
  ans1 = 0; ans2 = 0;
  while(cin >> l1 >>a >>l2 >>a>>l3){
    if(l1 == l2)
      ans2++;
    if(l1*l1 + l2*l2 == l3*l3)
      ans1++;
  }
  cout << ans1 << endl << ans2 << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] a = new int[3];
		Scanner sc = new Scanner(System.in);
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		sc.close();

		int c5=0,c7=0;
		for(int i=0;i<3;i++){
			if(a[i]==5){
				c5++;
			}else if(a[i]==7){
				c7++;
			}else{
				System.out.println("NO");
				return;
			}
		}
		if(c5==2&&c7==1){
			System.out.println("YES");
			return;
		}else{
			System.out.println("NO");
			return;
		}
	}

}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] m=new int[10];
		for(int i=0; i<10; i++){
			m[i]=sc.nextInt();
		}
		Arrays.sort(m);
		for(int i=9; i>=7; i--){
			System.out.println(m[i]);
		}
	}

}

Measured memory_bytes: 26424
//Name: Train
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * stringでシミュレーションする。
 *
 * オーダーは O(|S|^2)。
 */
#include <iostream>
#include <string>

using namespace std;

bool solve(bool first) {
    string s;
    cin >> s;

    string res;
    res += s[0];
    string::iterator it = begin(res);
    for(int i = 2; i < s.size(); i += 3) {
        bool top = false;
        if(s[i] == '>') {
            ++it;
        } else if(s[i] == '-') {
            if(it == begin(res)) top = true;
            else --it;
        }
        if(top || it == end(res)) {
            it = res.insert(it, s[i+1]);
        }
    }
    cout << res << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    int N;
    cin >> N;
    while(N-- && solve(first)) {
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N =  1e5 + 10;
 
struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int fact[N], inv[N];

struct COMB{
  
  COMB() {};

  int add(int a, int b, int m = MOD){
    a += b;
    if (a >= m)
      a -= m;
    return a;
  }
   
  int mul(int a, int b, int m = MOD){
    return (a * 1ll * b) % m;
  } 
  int powermod(int a, int b, int m = MOD){
    int res = 1ll;
    while (b){
      if (b & 1) res = res * a % m;
      a = a * a % m, b >>= 1;
    }
    return res;
  }

  int modinv(int a){
    return powermod(a, MOD - 2);
  }

  void init_fact(int n, int m = MOD){
    fact[0] = 1, fact[1] = 1;
    for (int i = 2; i <= n; i++){
      fact[i] = fact[i - 1] * i ;
      fact[i] %= m;
    }
    inv[n - 1] = modinv(fact[n - 1]);
    for (int i = n - 2; i >= 0; --i){
      inv[i] = inv[i + 1] * (i + 1);
      inv[i] %= m;
    }
  }

  int fast_nCr(int n, int r, int m = MOD){
    int res = 1ll;
    if (r > n - r) r = n - r;
    for (int i = 0; i < r; i++){
      res = res * (n - i) % m;
      res *= modinv(i + 1);
      res %= m;
    }
    return res;
  }

  int nCr(int n, int r, int m = MOD){
    if (r > n) return 0;
    int num = fact[n];
    num *= inv[r];
    num %= m;
    num *= inv[n - r];
    num %= m;
    return num;
  }
};

int32_t main(){
 COMB node;
 int n, a, b;
 cin >> n >> a >> b;
 int ret = node.powermod(2, n);
 ret %= MOD, ret -= 1;
 ret = (ret - node.fast_nCr(n, a) + MOD) % MOD;
 ret = (ret - node.fast_nCr(n, b) + MOD) % MOD;
 cout << ret << endl;
}

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

Int n,m;
Int re[11][11];
Int wi[11],ls[11];
Int ans;
void dfs(Int y,Int x){
  //cout<<y<<" "<<x<<endl;
  if(y+1==n){
    Int flg=1;
    for(Int i=0;i<n;i++)
      flg&=wi[i]==ls[i];
    
    if(0){
      for(Int i=0;i<n;i++)
	cout<<i<<":"<<wi[i]<<" "<<ls[i]<<endl;
      cout<<flg<<endl;
    }
    
    ans+=flg;
    return;
  }
  Int ny=y+(x+1)/n,nx=(x+1)%n;
  while(nx<=ny) nx++;
  
  if(~re[y][x]){
    dfs(ny,nx);
    return;
  }
  {  
    wi[x]++;
    ls[y]++;
    if(wi[x]<=n/2&&ls[y]<=n/2) dfs(ny,nx);
    wi[x]--;
    ls[y]--;    
  }
  {  
    wi[y]++;
    ls[x]++;
    if(wi[y]<=n/2&&ls[x]<=n/2) dfs(ny,nx);
    wi[y]--;
    ls[x]--;    
  }
}

signed main(){
  while(cin>>n,n){    
    memset(re,-1,sizeof(re));
    memset(wi,0,sizeof(wi));
    memset(ls,0,sizeof(ls));
    cin>>m;
    for(Int i=0;i<m;i++){
      Int x,y;
      cin>>x>>y;
      x--;y--;
      re[x][y]=1;
      re[y][x]=0;
      wi[x]++;
      ls[y]++;
    }
    for(Int i=0;i<n;i++) re[i][i]=2;
    ans=0;
    dfs(0,1);
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
package main

import "fmt"

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func min(a,b int)int{
	if(a>b){
		return b
	}
	return a
}

func main(){
	var N,K int;
	fmt.Scan(&N,&K);
// 	hm := make(map[int]bool)
// 	for{
// 		if(!hm[N]){
// 			hm[N]=true;
// 			N = Abs(N-K)
// 		}else{
// 			break;
// 		}
// 	}
// 	var mini int;
// 	mini=999999999
// 	for k:= range hm{
// 		mini=min(mini,k)
// 	}
// 	fmt.Println(mini)
// }
	var x int;
	x=N%K;
	x=min(Abs(x-K),x);
	fmt.Println(x)
}

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

signed main(void){
  
  int V,E; cin >> V >> E;
  
  if( E % 2 == 1 ){
    cout << -1 << endl; return 0;
  }
  //以下、適切に配置すれば可能な場合
  
  vector<vector<int>> to(V);
  
  for(int i = 0; i < E; i++){ 
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  
  vector<pair<int,int>> depth(V);
  for(int i = 0; i < V; i++){ depth[i] = {-1,i};} //第二成分はノード番号
   
  depth[0].first = 0;
  queue<int> Q; Q.push(0);
  
  while(!Q.empty()){ //BFSの要領で0を基準に木としての深さをマーク
    int p = Q.front(); Q.pop();
    for(auto u : to[p]){ 
      if( depth[u].first != -1 ){ //すでに記録済み
        continue;
      }
      depth[u].first = depth[p].first+1;
      Q.push(u);
    }
  }
  
  vector<bool> used(V,false);
  vector<bool> even(V,true);
  
  vector<pair<int,int>> ans;
  
  //次に、depthが深いノードから順次向きを決めて行く
  
  sort(depth.rbegin(),depth.rend());
  
  for(int i = 0; i < V; i++){ 
    int p = depth[i].second;
    for(auto u : to[p] ){ 
      if(used[u]){ continue;} //すでにuから伸びる辺の向きは全て決め終わってしまった場合
      
      if(even[p]){ //pの出次数が偶数↪︎uからpに向けて向きをつける
        ans.push_back({u,p});
        even[u] = !even[u];
      }
      else{ // pからuに向きをつける
        ans.push_back({p,u});
        even[p] = !even[p];
      }
      
    }//for-auto
    
    used[p] = true;
  }//for-i
  
  for(auto ne : ans){ cout << ne.first+1 << " " << ne.second+1 << endl;}
  
  return 0;
}    

Measured memory_bytes: 10736
#include<stdio.h>
int main(void)
{
	int n, k, i;
	scanf("%d",&n);
	char s[n+1];
	scanf("%s",&s);
	scanf("%d",&k);
	for(i=0;i<n;i++){
		if(s[k-1]!=s[i]){
			s[i]='*';
		}
	}
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  // 入力
  int N, M;
  cin >> N >> M;

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

  sort(A.begin(), A.end(),std::greater<int>());

  string result = "Yes";
  if( double(A[M-1]) < double(sum)/double(4*M)) {
    result = "No";
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class ALDS1_2C
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] sArr = Console.ReadLine().Split(' ');
            string[] arr1 = new string[n];
            sArr.CopyTo(arr1, 0);
            BubbleSort(arr1, n);
            WriteArr(arr1);
            WriteStableOrNot(sArr, arr1);

            string[] arr2 = new string[n];
            sArr.CopyTo(arr2, 0);
            SelectionSort(arr2, n);
            WriteArr(arr2);
            WriteStableOrNot(sArr, arr2);

            Console.ReadLine();
        }

        static int GetNumber(string _s)
        {
            return int.Parse(_s.Substring(1, 1));
        }

        static void WriteStableOrNot(string[] _arr1, string[] _arr2)
        {
            if (IsStableSort(_arr1, _arr2))
            {
                Console.WriteLine("Stable");
            }
            else
            {
                Console.WriteLine("Not stable");
            }
        }

        static void Swap<T>(T[] _arr, int _i, int _j)
        {
            T tmp = _arr[_i];
            _arr[_i] = _arr[_j];
            _arr[_j] = tmp;
        }

        static bool IsStableSort(string[] _orig, string[] _sorted)
        {
            for (int i = 1; i < _sorted.Length; i++)
            {
                if (GetNumber(_sorted[i - 1]) == GetNumber(_sorted[i]))
                {
                    if (Array.IndexOf(_orig, _sorted[i - 1]) > Array.IndexOf(_orig, _sorted[i]))
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        static void BubbleSort(string[] _arr, int _n)
        {
            for (int i = 0; i < _n; i++)
            {
                for (int j = _n - 1; j > i; j--)
                {
                    if (GetNumber(_arr[j]) < GetNumber(_arr[j - 1]))
                    {
                        Swap(_arr, j, j - 1);
                    }
                }
            }
        }

        static void SelectionSort(string[] _arr, int _n)
        {
            for (int i = 0; i < _n; i++)
            {
                int minj = i;
                for (int j = i; j < _n; j++)
                {
                    if (GetNumber(_arr[j]) < GetNumber(_arr[minj]))
                    {
                        minj = j;
                    }
                }

                Swap(_arr, i, minj);
            }
        }

        static void WriteArr<T>(T[] _arr)
        {
            int len = _arr.Length;
            if (len > 0)
            {
                Console.Write(_arr[0]);
            }

            if (len > 1)
            {
                for (int i = 1; i < len; i++)
                {
                    Console.Write(string.Format(" {0}", _arr[i]));
                }
            }
            Console.Write("\r\n");
        }
    }
}

Measured memory_bytes: 8976