akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef pair< int , int > Pi;
#define INF (1 << 25)
#define fr first
#define sc second
int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};
int main(){
  int n,m,x,y,MUKI;
  while(cin >> n >> m && n){
    x = 1 , y = 1 , MUKI = 0;
    while(true){
      if( x > m ) x = m;
      if( x < 1 ) x = 1;
      if( y > n ) y = n;
      if( y < 1 ) y = 1;
      string str;
      int n;
      cin >> str;
      if(str == "FORWARD"){
        cin >> n;
        x += dx[MUKI] * n , y += dy[MUKI] * n;
      }else if(str == "BACKWARD"){
        cin >> n;
        x -= dx[MUKI] * n , y -= dy[MUKI] * n;
      }else if(str == "RIGHT") MUKI = ( MUKI + 1 ) % 4;
      else if(str == "LEFT") MUKI = ( MUKI - 1 + 4 ) % 4;
      else break;
      //  cout << y << x;
    }
    cout << y << " " << x << endl;
  }
}

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  while(1){
    int N,A,B,C,X;
    cin>>N>>A>>B>>C>>X;
    if(!(A|B|N|C|X))return;
    vector<int> Y(N);
    rep(i,N) cin >> Y[i];
    int idx=0;
    if(X==Y[idx])idx++;
    rep(i,10001){
      if(idx==N){cout<<i<<endl;goto END;}
      X=(A*X+B)%C;
      if(X==Y[idx])idx++;
    }
    cout<<-1<<endl;
    END:;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3124
loop do
	sizes = $<.gets.split.map(&:to_i)
	break if sizes.map(&:zero?).inject(&:&)

	a, b = sizes.sort
	l = (a ** 2 + b ** 2) ** 0.5 / 2
	$<.gets.to_i.times do
		puts l < $<.gets.to_i ? 'OK' : 'NA'
	end
end

Measured memory_bytes: 6160
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B>=C) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
  char S[4];
  scanf("%s", S);

  if(S[0] == S[1] && S[1] == S[2] && S[2] == S[3])   //文字が1種類
    cout << "No" << endl;
  else if(S[0] == S[1]){              //以降文字2種類
    if(S[2] == S[3])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else if(S[0] == S[2]){
    if(S[1] == S[3])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else if(S[0] == S[3]){
    if(S[1] == S[2])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else
    cout << "No" << endl;

  return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x = x->left;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u = u->left;
    else u = u->right;
  }
  return u;
}
/*
Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



  }*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct 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;
}

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


int main(){
  int n, i, x;
  char com[20];
  Node T;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      T = treeSearch(root, x);
      if ( T != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }// else if ( com[0] == 'd' ){
    //scanf("%d", &x->key);
      //  treeDelete(treeSearch(root, x));
    // }
  }

  return 0;
}

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

using namespace std;

typedef pair<int,pair<int,int>> pairpair;

int main() {
    cin.sync_with_stdio(false);

    int n;
    cin >> n;

    vector<pairpair> v;
    v.reserve(n);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.emplace_back(x, pair<int,int>(i, 0));
    }

    sort(v.begin(), v.end(), [](const pairpair &a, const pairpair &b) {
        return a.first < b.first;
    });

    for (int i = 0; i < n; i++) {
        if (i < n / 2) {
            v[i].second.second = v[n/2].first;
        } else {
            v[i].second.second = v[n/2 - 1].first;
        }
    }

    sort(v.begin(), v.end(), [](const pair<int,pair<int,int> > &a, const pair<int,pair<int,int> > &b) {
        return a.second.first < b.second.first;
    });

    for (auto x: v) {
        cout << x.second.second << endl;
    }

    return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
const int maxn=2005;
struct que{
	int id,data;
	bool operator <(que i)const{
		return data<i.data;
	}
};
struct Edge{
	int to,nxt;
}e[maxn*maxn];
int n,sum=0;
int cnt=0;
int head[maxn];
int a[maxn];
int rd[maxn];
int ans[maxn];
bool g[maxn][maxn],vis[maxn];
vector<int>p[maxn];
priority_queue<que>q;
void add(int u,int v){
	rd[v]++;
	e[cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt++;
}
void dfs(int x){
	vis[x]=1;
	p[cnt].push_back(a[x]);
	for(int i=1;i<=n;i++){
		if(vis[i]||(!g[x][i]))continue;
		add(x,i);
		dfs(i);
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(__gcd(a[i],a[j])>1)
				g[i][j]=g[j][i]=1;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cnt++;
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++){
		if(!rd[i]){
			que u;
			u.id=i;u.data=a[i];
			q.push(u);
		}
	}
	while(!q.empty()){
		int k=q.top().id;
		printf("%d ",a[k]);
		q.pop();
		for(int i=head[k];i!=-1;i=e[i].nxt){
			int tmp=e[i].to;
			rd[tmp]--;
			if(!rd[tmp]){
				que o;
				o.id=tmp;o.data=a[tmp];
				q.push(o);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4608
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };


// Code from Here -------------------------------------------------------------------------------

void solver(){
	int n;
	cin >> n;
	map<string,int> mp;
	for(int i=0; i<n; i++){
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << "AC" << " x " << mp["AC"] << endl;
	cout << "WA" << " x " << mp["WA"] << endl;
	cout << "TLE" << " x " << mp["TLE"] << endl;
	cout << "RE" <<  " x " <<mp["RE"] << endl;
}

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t=1;
	// cin >> t;
	while(t--)solver();

	return 0;
}  


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

namespace Project
{
	class Card
	{
		public char mark;
		public int num;
		public Card() { }
		public Card(char mark, int num)
		{
			this.mark = mark;
			this.num = num;
		}
	}

	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			Card[] cards = new Card[n];
			Card[] ccards = new Card[n];
			for (int i = 0; i < n; i++)
			{
				string[] s = Console.ReadLine().Split(' ');
				cards[i] = new Card(s[0][0], int.Parse(s[1]));
				ccards[i] = new Card(s[0][0], int.Parse(s[1]));
			}
			ccards = ccards.OrderBy(a => a.num).ToArray();
//			MergeSort(ccards, 0, n);
			var sb = new StringBuilder();
			for (int i = 0; i < n; i++)
			{
				sb.Append(ccards[i].mark);
				sb.Append(":");
				sb.Append(ccards[i].num);
				if (i != n - 1)
					sb.Append(" ");
			}
			string s1 = sb.ToString();
			QuickSort(cards, 0, n - 1);
			sb = new StringBuilder();
			for (int i = 0; i < n; i++)
			{
				sb.Append(cards[i].mark);
				sb.Append(":");
				sb.Append(cards[i].num);
				if (i != n - 1)
					sb.Append(" ");
			}
			string s2 = sb.ToString();
			if (s1 == s2)
				Console.WriteLine("Stable");
			else
				Console.WriteLine("Not stable");
			foreach (Card x in cards)
			{
				Console.WriteLine("{0} {1}", x.mark, x.num);
			}
		}

		public static int Partition(Card[] c, int p, int r)
		{
			Card tmp = new Card();
			int x = c[r].num;
			int i = p - 1;
			for (int j = p; j < r; j++)
			{
				if (c[j].num <= x)
				{
					i++;
					tmp.mark = c[i].mark;
					tmp.num = c[i].num;
					c[i].mark = c[j].mark;
					c[i].num = c[j].num;
					c[j].mark = tmp.mark;
					c[j].num = tmp.num;
				}
			}
			tmp.mark = c[i + 1].mark;
			tmp.num = c[i + 1].num;
			c[i + 1].mark = c[r].mark;
			c[i + 1].num = c[r].num;
			c[r].mark = tmp.mark;
			c[r].num = tmp.num;
			return i + 1;
		}

		public static void QuickSort(Card[] c, int p, int r)
		{
			if (p < r)
			{
				int q = Partition(c, p, r);
				QuickSort(c, p, q - 1);
				QuickSort(c, q + 1, r);
			}
		}

		public static void MergeSort(Card[] a, int left, int right)
		{
			if (left + 1 < right)
			{
				int mid = (left + right) / 2;
				MergeSort(a, left, mid);
				MergeSort(a, mid, right);
				Merge(a, left, mid, right);
			}
		}
		public static void Merge(Card[] a, int left, int mid, int right)
		{
			int n1 = mid - left;
			int n2 = right - mid;
			Card[] L = new Card[n1 + 1];
			Card[] R = new Card[n2 + 1];
			for (int l = 0; l < n1; l++)
			{
				L[l] = new Card(a[left + l].mark, a[left + l].num);
			}
			for (int l = 0; l < n2; l++)
			{
				R[l] = new Card(a[mid + l].mark, a[mid + l].num);
			}
			L[n1] = new Card(' ', int.MaxValue);
			R[n2] = new Card(' ', int.MaxValue);
			int i = 0, j = 0;
			for (int k = left; k < right; k++)
			{
				if (L[i].num <= R[j].num)
				{
					a[k].mark = L[i].mark;
					a[k].num = L[i].num;
					i++;
				}
				else
				{
					a[k].mark = R[j].mark;
					a[k].num = R[j].num;
					j++;
				}
			}
		}
	}
}

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

int main(){
    
    // 1. 入力情報.
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    
    // 2. 新聞X, Y の 両方購読している人数の最大, 最小は？
    int X = min(A, B);
    int Y = max(0, A + B - N);
    
    // 3. 出力.
    printf("%d %d\n", X, Y);
    return 0;
    
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 1005

int n, m, k;
int f[maxn][maxn];
string s[maxn];
int dr[4] = {0, 1, 0, -1};
int dc[4] = {1, 0, -1, 0};
II que[maxn * maxn];
int count(int x){
	if(x == 0) return 0;
	return (x - 1) / k + 1;
}

int cal(int r, int c){
	int A = min(count(r), count(n - 1 - r));
	int B = min(count(c), count(m - 1 - c));
	return min(A, B);
}

bool inside(int r, int c){
	return r >= 0 && r < n && c >= 0 && c < m;
}

int main()
{
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m >> k;

	Rep(i, n) cin >> s[i];
	ms(f, -1);

	int size = 0;
	Rep(i, n) Rep(j, m) if(s[i][j] == 'S'){
//		cout << i << " " << j << endl;
		f[i][j] = 0;
		que[size++] = mp(i, j);
	}

	int res = inf;
	Rep(run, size){
		int r = que[run].fi, c = que[run].se;
//		cout << r << " " << c << " " << f[r][c] << endl;
		int ret = count(f[r][c]) + cal(r, c);
		if(run == 0) ret++;
		res = min(res, ret);
		Rep(h, 4){
			int rr = r + dr[h], cc = c + dc[h];
			if(inside(rr, cc) && s[rr][cc] == '.' && f[rr][cc] == -1){
				f[rr][cc] = f[r][c] + 1;
				que[size++] = mp(rr, cc);
			}
		}
	}

	cout << res << endl;

  return 0;
}


Measured memory_bytes: 12800
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    T = input()[:-1]

    ans = ""
    for i in range(len(T)):
        if T[i] == "?":
            ans += "D"
        else:
            ans += T[i]
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10628
import java.util.*;

public class Main {
  public static void main(String[] args) {    
	Scanner sc = new Scanner(System.in);
    String[] str = sc.nextLine().split("");
    int count = 0;
    for(String e : str) {
      if(e.equals("1")) {
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
X,K,D=list(map(int, input().split()))
X=abs(X)
if X-K*D>0:
    print(X-K*D)
    exit()
L=[]
if K%2==0:
    L.append(X%(2*D))
    L.append(2*D-X%(2*D))
    print(min(L))
    exit()
if K%2==1:
    L.append((X+D)%(2*D))
    L.append(2*D-(X+D)%(2*D))
    print(min(L))
    exit()

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

int main() {
  string s;
  cin >> s;
  long ans = 0;
  long n = s.length();
  for (int bit = 0; bit < (1 << n - 1); bit++) {
    string save = {s[0]};
    for(int i = 0; i < n - 1; i++) {
      if (bit & (1 << i)) {
        ans += stoll(save);
        save = {s[i+1]};
      } else {
        save += s[i+1];
      }
    }
    ans += stoll(save);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	string s,t;
	cin>>s>>t;
	bool flag=1;
	rep(i,s.size()){
		if(s[i]!=t[i])flag=0;
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3572
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[1]*(n+1)
dp[0]=1
dp[1]=1
for i in range(m):
  if a[i]==1:
    dp[1]=0
  else:
    dp[a[i]]=0
for i in range(2,n+1):
  if dp[i]:
    dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%(10**9+7))

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N, M;
vector<int> H;
vector<int> graph[MAX_N];

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

    cin >> N >> M;
    H.resize(N);
    REP(i, N) {
        cin >> H[i];
    }
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int ans = 0;
    vector<bool> isGood(N, true);
    REP(i, N) {
        if(!isGood[i]) { continue; }
        for (auto &node : graph[i]) {
            if(H[i] <= H[node]) {
                isGood[i] = false;
                break;
            }
            else {
                isGood[node] = false;
            }
        }
        if(isGood[i]) { ans++; }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    ll aa, bb;
    cin >> n >> aa >> bb;
    vector<int> a(n);
    rep(i,0,n) {
        cin >> a[i];
        --a[i];
    }
    vector<ll> dp(n);
    rep(i,0,n) {
        vector<ll> next(n);
        rep(j,0,n) if(j!=a[i]) {
            next[j] = dp[j];
            if(a[i]<j) next[j]+=bb;
            else next[j]+=aa;
        }
        ll best = LLONG_MAX;
        rep(j,0,a[i]+1) best = min(best, dp[j]);
        next[a[i]] = best;
        swap(next,dp);
    }
    ll best = LLONG_MAX;
    rep(i,0,n) best =min(best,dp[i]);
    cout<<best<<"\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define res register int
using namespace std;
int n,m;
inline int read()
{
  int X=0,w=0;
  char ch=0;
  while(!isdigit(ch))
  {
    w|=ch=='-';
    ch=getchar();
  }
  while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  return w?-X:X;
}
int main()
{
  n=read(),m=read();
  vector<int> sz(n, 1);
  vector<uint8_t> c(n);
  c[0] = 1;
  for (res i = 0; i < m; i++)
  {
    res x=read(),y=read();
    x--;
    y--;
    c[y] |= c[x];
    sz[x]--;
    sz[y]++;
    if (sz[x] == 0)
      c[x] = 0;
  }
  int ans = 0;
  for (res i = 0; i < n; i++)
    if(c[i])
      ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int mx=-1000000000;
	int b;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>mx){
			mx=a[i];
			b=i;
		}
	}
	int sum=0;
	for(int i=0;i<n;i++){
		if(i!=b){
			sum+=a[i];
		}
		else{
			sum+=a[i]/2;
		}
	}
	cout<<sum;
}

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

typedef long long ll;
const int maxn=1e2+10;
int a,b;
char s[maxn][maxn];

int main(){
	cin>>a>>b;
	for(int i=1;i<=50;++i)
		for(int j=1;j<=100;++j)
			s[i][j]='.';
	for(int i=51;i<=100;++i)
		for(int j=1;j<=100;++j)
			s[i][j]='#';
	--a;--b;
	for(int i=1;i<=50&&b;i+=2)
		for(int j=1;j<=100&&b;j+=2)
			s[i][j]='#',--b;
	for(int i=100;i>=51&&a;i-=2)
		for(int j=1;j<=100&&a;j+=2)
			s[i][j]='.',--a;
	cout<<100<<' '<<100<<endl;
	for(int i=1;i<=100;++i)
		cout<<(s[i]+1)<<endl;
	return 0;
}

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

int main()
{
    int n, m, ans;
    cin >> n >> m;
    if(n == m){
        ans = 1900*m*pow(2,m);
    }else{
        ans = (1900*m + 100*(n-m))*pow(2,m);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    int min_n = min(a,b);
    int n = max(a,b);
    int i;
    for(i = 0;i < n;++i){
        cout << min_n;
    }
    cout << endl;
    return 0;
}

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll k,n;
    cin >> n >> k;
    if(n > k){
        n %= k;
    }
    if(n > k/2){
        n = k - n;
    }
    cout << n << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int n;
  while(cin >> str){
    if(str=="-") break;
    cin >> n;
    for(int i=0,h;i<n;i++){
      cin >> h;
      string cat = str.substr(0,h);
      str.erase(0,h);
      str+=cat;
    }
    cout << str << endl;
  }
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int m, n;
string a[100010], b[100010];
bool f = 0;

int main(){
	cin >> n >> m;
	REP(i, n){
		cin >> a[i];
	}
	REP(i, m){
		cin >> b[i];
	}
	REP(i, n - m + 1){
		REP(j, n - m + 1){
			bool g = 1;
			REP(k, m){
				REP(l, m){
					if (a[i + k][j + l] != b[k][l])g = 0;
				}
			}
			f |= g;
		}
	}
	if (f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#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 print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[10010], b[10010];
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];
    bool ok = true;
    ll cnt1 = 0;
    ll diff = 0;
    rep(i,0,N){
        diff += b[i] - a[i];
    }
    if(diff < 0){
        ok = false;
    }
    rep(i,0,N){
        if(b[i] < a[i]){
            cnt1 += (a[i] - b[i]);
            b[i] = a[i];
        }else if((b[i] - a[i]) % 2 == 1){
            cnt1++;
            b[i]++;
        }
    }
    if(cnt1 > diff){
        ok = false;
    }
    ll cnt2 = 0;
    rep(i,0,N){
        cnt2 += (b[i] - a[i]) / 2;
    }
    if(cnt2 > diff){
        ok = false;
    }
    if(diff - cnt1 != (diff - cnt2) * 2) ok = false;
    if(ok){
        print("Yes");
    }else{
        print("No");
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() {
    fastio
    string s;
    cin>>s;
    int n = s.length();
    if(s == "RRR") {
        cout<<"3"<<endl;
    }    
    else if(s=="RRS" || s=="SRR") {
        cout<<"2"<<endl;
    }
    else if(s=="SSS"){
        cout<<"0"<<endl;
    }
    else 
        cout<<"1"<<endl;
    
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main( void )
{
	int n, m;
	while ( cin >> m >> n )
	{
		int answer = 0;
		for ( int i = m; i <= n; i++ )
		{
			int h = i;
			while ( h % 2 == 0 ) h /= 2;
			while ( h % 3 == 0 ) h /= 3;
			while ( h % 5 == 0 ) h /= 5;
			if ( h == 1 ) answer++;
		}
		cout << answer << endl;
	}
	return 0;
}

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

int main() {
	// your code goes here
	int p,q,r;
	cin>>p>>q>>r;
	if(p<=q && q<=r){
		cout<<p<<" "<<q<<" "<<r<<endl;
	}
	else if(p<=r && r<=q){
		cout<<p<<" "<<r<<" "<<q<<endl;
	}
	else if(q<=p && p<=r){
		cout<<q<<" "<<p<<" "<<r<<endl;
	}
    else if(q<=r && r<=p){
		cout<<q<<" "<<r<<" "<<p<<endl;
	}
	else if(r<=p && p<=q){
		cout<<r<<" "<<p<<" "<<q<<endl;
	}
	else if(r<=q && q<=p){
		cout<<r<<" "<<q<<" "<<p<<endl;
	}
}

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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

int main() {
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  vector<vector<int>> d(n, vector<int>(n,1));
  REP(i,n) REP(j,n) cin >> a[i][j];
  REP(k,n) REP(i,n) REP(j,n) {
    if (i == j || j == k || k == i) continue;
    int b = a[i][k] + a[k][j];
    if (a[i][j] > b) {
      cout << -1 << endl;
      return 0;
    } else if (a[i][j] == b) {
      d[i][j] = 0;
    }
  }

  ll ans = 0;
  REP(i,n) REP(j,n) {
    ans += d[i][j] ? a[i][j] : 0;
  }
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int main()
{
	int a, b, c, sum;
	cin >> a >> b >> c;
	if(a >= b && a >= c) sum = b+c;
	else if(b >= a && b >= c) sum = a+c;
	else sum = a+b;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		while(input.hasNext()){
			int A = input.nextInt();
			int B = input.nextInt();
			int C = input.nextInt();
			int D = input.nextInt();
			if(A > D || C > B){
				System.out.println("0");
			} else {
				System.out.println(Math.min(B, D) - Math.max(A, C));
			}
		}
	}
  
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int);

int main() {
    clue();
    return 0;
}
int clue() {
    int n;
    cin>>n;
    for(int i=n;;++i) {
        if(check(i)) {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}
bool check(int n) {
    if(n>=2 && n<=29) {
        if(n==2 || n==3 || n==5 || n==7 || n==11 || n==13 ||n==17 || n==19 || n==23 || n==29) {
            return true;
        }
        return false;
    }
    else {
        for(int i=2;i<=sqrt(n);++i) {
            if(n%i==0) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        boolean ac = true;
        
        if(s.charAt(0) != 'A') ac = false;
        
        int c = 0;
        int index = 0;
        for(int i = 2; i <= s.length()-2; i++){
            if(s.charAt(i) == 'C'){
                c++;
                index = i;
            }
        }
        if(c != 1) ac = false;
        
        for(int i = 1; i < s.length(); i++){
            if(i == index) continue;
            if(!('a' <= s.charAt(i) && s.charAt(i) <= 'z')){
                ac = false;
            }
        }
        
        if(ac){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}

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

int main(){
    int P = 0, p = 0, h = 0;
    string str;
    cin >> str;
    int a = str.length();
    
    int Area[a], Left[a+1], Right[a+1], Puddle[a/2+1];
    Left[0] = 0; Right[a] = 0; Puddle[0] = 0;
    int l = 1, L = 0, r = a-1, R = 0;
    for (int i = 0; i < a; i++) {
        if (str[i] == '/') { if (L < 0) L++; }
        else if (str[i] != '_') L--;
        if (L < 0) Left[l] = 1;
        else Left[l] = 0;
        l++;
    }
    for (int i = a-1; i >= 0; i--) {
        if (str[i] == '/') R--;
        else if (R < 0 && str[i] != '_') R++;
        if (R < 0) Right[r] = 1;
        else Right[r] = 0;
        r--;
    }
    for (int j = 0; j <= a; j++) {
        if (Left[j] == 0 || Right[j] == 0) {
            if (P != 0) { P++; Puddle[0] += P; Puddle[p+1] = P; p++; P = 0; h = 0; }
        }
        else {
            if (str[j-1] == '/') { P += 2*(h-1) + 1; h--; }
            else if (str[j-1] == '_') { P += 2*h; }
            else { P += 2*h + 1; h++; }
        }
    }
    
    cout << Puddle[0]/2 << endl;
    if (p == 0) cout << p << endl;
    else {
        cout << p << " ";
        for (int i = 1; i <= p; i++) {
            cout << Puddle[i]/2;
            if (i == p) cout << endl;
            else cout << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3432
#include<stdio.h>

#define S 500000
#define N1 -2000000000
#define N2 2000000000

void maxHeapify(int );
void buildMaxHeap(void);
void Print(void);

int A[S],n;

main(){ 
  int i;

  scanf("%d",&n);
  if(S < n) return 0;

  for(i=1;i <= n;i++){
    scanf("%d",&A[i]);
     if(A[i] < N1 || N2 < A[i]) return 0;
  }
  
  buildMaxHeap();

  Print();
  printf("\n");

  return 0;
}

void maxHeapify(int i){
  
  int l =0;
  int r = 0;
  int largest =i;
  int a = 0;
  int b = 0;
  
  if(2*i >0 && 2*i <= n) l = 2*i;
  if((2*i+1) <= n) r = 2*i+1;
  
  if(l <= n && A[l] > A[i] && l > 0) largest = l;
  if(r <= n && A[r] > A[largest] && r >0) largest = r;

  if(largest != i){
    a = A[i];
    b = A[largest];
    A[i] = b;
    A[largest] = a;
    
    maxHeapify(largest);
  }
}

void buildMaxHeap(void){

  int i;
  for(i=n/2; i >= 1;i--){
    maxHeapify(i);
  }
}


void Print(void){
  int i;
  
  for(i=1;i <= n;i++){
    printf(" %d",A[i]);
  }
}

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

int main(){
	double a;
	
	while(cin >> a){
		double s = a, prev = a;
		for(int i=2; i<=10; i++){
			if(i%2 == 0){
				prev *= 2;
				s+=prev;
			}else{
				prev /= 3;
				s+=prev;
			}
		}
		printf("%.8f\n",s);
	}
	return 0;
}
				

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w;
  cin >> h >> w;
  REP(i,h){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

int N, x, y;
vector< pair<int, int> > xdist;
vector< pair<int, int> > ydist;
vector< pair< int, pair<int, int> > > edge;

/*==================================================*/
const int MAX_N = 100010;
struct UnionFind{
  int par[MAX_N];
  int deph[MAX_N];
  UnionFind(int n){
    fill(par, par + MAX_N, -1);
    for(int i=0; i<n; i++){
      par[i] = i;
      deph[i] = 0;
    }
  }
  int find(int x){
    if(par[x] == x){
      return x;
    }else{
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(deph[x] < deph[y]){
      par[x] = par[y];
    }else{
      par[y] = par[x];
      if(deph[x] == deph[y]) deph[x]++;
    }
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
};
/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>x>>y;
        xdist.push_back(make_pair(x, i));
        ydist.push_back(make_pair(y, i));
    }
    sort(xdist.begin(), xdist.end());
    sort(ydist.begin(), ydist.end());

    REP(i,0,N-1){
        edge.push_back(make_pair(xdist[i+1].F - xdist[i].F, make_pair(xdist[i].S, xdist[i+1].S)));
        edge.push_back(make_pair(ydist[i+1].F - ydist[i].F, make_pair(ydist[i].S, ydist[i+1].S)));
    }
    sort(edge.begin(), edge.end());

    // REP(i,0,edge.size()){
    //     cout<<edge[i].F<<": "<<edge[i].S.F<<", "<<edge[i].S.S<<endl;
    // }

    long long ans = 0;

    UnionFind uf(N);
    REP(i,0,edge.size()){
        int n0 = edge[i].S.F;
        int n1 = edge[i].S.S;
        if(!uf.same(n0, n1)){
            ans += (long long)edge[i].F;
            uf.unite(n0, n1);
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int n=0;
  cin>>n;
  vi vec(n);
  rep(i,0,n){
    cin>>vec.at(i);
  }
  ll wa=0;
  int max=vec.at(0);
  
  rep(i,0,n){
    if(max>vec.at(i)){
      wa+=max-vec.at(i);
    }else{
      max=vec.at(i);
    }
  }
  cout<<wa;
}

Measured memory_bytes: 3916
def resolve():
    k=int(input())
    s = str(input())
    n=len(s)
    if n<=k:
        a = str(''.join([x.strip() for x in s.split(',')]))
        print(a)
    else:
        t = s[:k]+"..."
        a = str(''.join([x.strip() for x in t.split(',')]))
        print(a)
resolve()

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

int main(){
  int N; cin >> N;
  vector<vector<int>> edge(N,vector<int>());
  for(int i=0; i<N-1; i++){
    int a,b; cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  
  // 0からN-1の最短を求める
  // 初めに求めたルートで息の根を止めるのが最適
  // その後埋めていき生き残ったほうが勝ち
  
  vector<int> pre(N,-1);
  queue<int> q;
  q.push(0);
  pre[0]=0;
  while(!q.empty()){
    int a=q.front(); q.pop();
    for(int x:edge[a]){
      if(pre[x]<0){
        q.push(x);
        pre[x]=a;
      }
    }
  }
  vector<int> route={N-1};
  for(int i=0; i<N; i++){
    route.push_back(pre[route[i]]);
    if(pre[route[i]]==0) break;
  }
  reverse(route.begin(),route.end());
  
  vector<int> color(N,-1);
  // 0 黒 1 白
  queue<int> q0;
  queue<int> q1;
  for(int i=0; i<(int)route.size(); i++){
    if(i%2==0){
      color[route[i/2]]=0;
      q0.push(route[i/2]);
    }else{
      color[route[route.size()-1-i/2]]=1;
      q1.push(route[route.size()-1-i/2]);
    }
  }
  while(!q0.empty()){
    int a=q0.front(); q0.pop();
    for(int x:edge[a]){
      if(color[x]<0){
        color[x]=0;
        q0.push(x);
      }
    }
  }
  while(!q1.empty()){
    int a=q1.front(); q1.pop();
    for(int x:edge[a]){
      if(color[x]<0){
        color[x]=1;
        q1.push(x);
      }
    }
  }
  int c0=0,c1=0;
  for(int i=0; i<N; i++){
    if(color[i]==0) c0++;
    else c1++;
  }
  if(c0>c1) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

Measured memory_bytes: 10344
#include<stdio.h>

int main(){

        int a[20][20],b[20],n,m,c,cnt,sum;

        scanf("%d %d %d",&n,&m,&c);

    
        for(int k = 0 ; k < m ; k++ )
                scanf("%d",&b[k]);

        for(int i = 0 ; i < n ;i++){
    
                sum = c;  
    
                for(int j = 0 ; j < m ; j++ ){
                        scanf("%d",&a[i][j]);
                        sum += a[i][j]*b[j];
                }   
    
                if(sum > 0 ) 
                        cnt++;

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

        return 0 ; 

}

Measured memory_bytes: 1708
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a[3];
    rep(i, 3) cin >> a[i];
    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
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int[] d=new int[N];
		int K;
		
		for(int i=0;i<N;i++) {
			d[i]=sc.nextInt();
		}
		
		Arrays.sort(d);
		
		if(d[(N/2)-1]==d[N/2]) {
			K=0;
		}
		else{
			K=d[N/2]-d[(N/2)-1];
		}
		
		System.out.println(K);
		
		sc.close();
	}
}


Measured memory_bytes: 50604
#include <stdio.h>

int main(void)
{
	int n,i,b,f,r,v,room[4][3][10] = { 0 };

	scanf("%d\n", &n);

	for (i = 0; i < n; i++, room[b-1][f-1][r-1] += v)
		scanf("%d %d %d %d", &b, &f, &r, &v);

	for (b = 0; b < 4; b++) {
		for (f = 0; f < 3; f++) {
			for (r = 0; r < 10; r++) {
				putchar(' ');
				printf("%d", room[b][f][r]);
			}
			putchar('\n');
		}
		if (3 - b) {
			for (i = 0; i < 20; i++)
				putchar('#');
			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int S=5005,N=2*S;
int st[N],ch[N][30],fa[N],len[N],tot=1,last=1,k;
char str[S];
void build(int c,int id)
{
	int np=++tot,p=last;
	for(;p&&!ch[p][c];p=fa[p])	ch[p][c]=np;
	if(!p)	fa[np]=1;
	else
	{
		int q=ch[p][c];
		if(len[p]+1==len[q])	fa[np]=q;
		else
		{
			int nq=++tot;len[nq]=len[p]+1;
			memcpy(ch[nq],ch[q],sizeof(ch[q]));fa[nq]=fa[q];
			fa[np]=fa[q]=nq;
			for(;p&&ch[p][c]==q;p=fa[p])	ch[p][c]=nq;
		}
	}
	len[np]=id;last=np;
}
void gg()
{
	for(int i=1;i<=st[0];i++)	putchar(st[i]+'a');
	exit(0);
}
void dfs(int x)
{
	k--;
	if(!k)	gg();
	for(int i=0;i<26;i++)
		if(ch[x][i])
		{
			st[++st[0]]=i;
			dfs(ch[x][i]);
			st[0]--;
		}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",str+1);
	k=ri()+1;
	int len=strlen(str+1),i;
	for(i=1;i<=len;i++)	build(str[i]-'a',i);
	dfs(1);
	return 0;
}
/*
atcoderandatcodeer
5



*/


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i=0,x;
		while(true) {
			x=scan.nextInt();
			if(x==0)break;
			i++;
			System.out.println("Case "+i+": "+x);
		}
		scan.close();
	}

}



Measured memory_bytes: 40700
n = int(input())
s = input()
n_left = 0
ans = s
for i in range(n):
    if s[i] == "(":
        n_left += 1
    elif s[i] == ")":
        if n_left > 0:
            n_left -= 1
        else:
            ans = "(" + ans
for i in range(n_left):
    ans += ")"
print(ans)


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

void solve()
{
    int m,n  ;
    cin>>m>>n ;

    vector<int> v(n) ;
    
    for(int i=0;i<n;i++){
        cin>>v[i] ;
    }

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

    priority_queue<int> q ;

    if(n>1){
        for(int i=1;i<n;i++)
        {

            int temp=v[i]-v[i-1] ;
            q.push(temp) ;
        }
    }

    int x=v[n-1]-v[0] ;

    if(n>1){
        for(int i=0;i<min(n-1,m-1);i++)
        {
            int t=q.top() ;
            x-=t ;
            q.pop() ;
        }
    }

    cout<<x  ;
}


int main()
{

    int y ;
    y=1 ;

    while(y--)
    {
        solve() ;
    }

}


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

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

using namespace std;
using lint = long long;

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

    vector<lint> p(A), q(B), r(C);
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());

    rep(i, X) r.push_back(p[i]);
    rep(i, Y) r.push_back(q[i]);
    sort(r.begin(), r.end(), greater<>());
    cout << accumulate(r.begin(), r.begin() + X + Y, 0LL) << endl;
    return 0;
}


Measured memory_bytes: 6384
#ifndef HOME
#pragma GCC optimize "-O3"
#endif

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;

const int MX = 200 * 1000 + 7;

bool fa[MX], fb[MX], fc[MX], fd[MX];
string s;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cin >> s;
    s = "#" + s;
    fa[a] = true;
    fb[b] = true;
    for (int i = 1; i <= n; i++) {
        if (s[i] != '#') {
            fa[i] |= fa[i - 1];
            fb[i] |= fb[i - 1];
            if (i > 1) {
                fa[i] |= fa[i - 2];
                fb[i] |= fb[i - 2];
            }
        }
    }

    fc[c] = true;
    fd[d] = true;
    for (int i = n; i >= 1; i--) {
        if (s[i] != '#') {
            fc[i] |= fc[i + 1];
            fd[i] |= fd[i + 1];
            fc[i] |= fc[i + 2];
            fd[i] |= fd[i + 2];
        }
    }

    if (!fa[c] || !fb[d]) {
        cout << "No\n";
        return 0;
    }

    if (b > a && d < c) {
        bool ok = false;
        for (int i = b; i <= d; i++) {
            if (fb[i] && fa[i - 1] && fc[i + 1]) {
                ok = true;
            }
            if (fa[i] && fb[i - 1] && fd[i + 1]) {
                ok = true;
            }
        }
        if (ok) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
        return 0;
    }

    cout << "Yes\n";
    return 0;
}



Measured memory_bytes: 1304