akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define loop(i,a,b) for (int i=a; i<b; ++i)
using ll = long long;
const int mod = 998244353;
typedef pair<int , int> pairs;
typedef complex<ll> G;

const int N = 2e5 + 5;

int power(int a,int b){
    if(!b)
        return 1;
    int c=power(a,b/2);
    c=(1LL*c*c)%mod;
    if(b%2)
        c=(1LL*c*a)%mod;
    return c;
}


vector<int>adj[N];
vector<int>ans(N+1, 0);
void dfs(int s, int e) {
    ans[s] = 1;
    for(auto u : adj[s]) {
        if(u == e)continue;
        dfs(u, s );
        ans[s] += ans[u];
    }
}
void done() {

    int n;
    cin >> n;
    for(int i = 0;i < n-1;++i) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }
    dfs(1, 0);
    for(int i = 1;i < n+1;++i) {
        cout << ans[i] << " ";
    }


}

/*string solve_palindrome(const string& s)
{
    string a = s;
    reverse(a.begin(), a.end());
    //a = s + "#" + a;
    int c = 0;
    for (int i = 1; i < (int)a.size(); i++)
    {
        while (c != 0 && a[c] != a[i])
            c = pref[c - 1];
        if (a[c] == a[i])
            c++;
        pref[i] = c;
    }
    return s.substr(0, c);
}
*/


void solve()
{
    int n;
    cin >> n;
    vector<int>a(n);
    int d = 1e9 +1;
    for(int &c : a) {
        cin >> c;
        d = min(d, c);
    }
    bool ok = 1;
    for(int i = 1;i < n;++i)
        if(a[i - 1] > a[i])ok = 0;
    if(ok) {
        cout << "YES\n" << '\n';
        return;
    }


}

void another() {
    int n , m, q;
    cin >> n >> m >> q;
    vector<pairs> sx(n, {0, 0}), sy(m, {0, 0});
    for(int i = 0;i < n;++i) {
        sx[i].second = i;
    }
    for(int i = 0;i < m;++i) {
        sy[i].second = i;
    }
    set<pairs>a;
    for(int i = 0;i < q;++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        ++sx[x].first;
        ++sy[y].first;
        a.insert({x, y});
    }
    sort(sx.rbegin(), sx.rend());
    sort(sy.rbegin(), sy.rend());
    int ans = 0;
    for(const auto& x : sx) {
        for(const auto& y : sy) {
            int d = a.count(make_pair(x.second, y.second));
            ans = max(ans, x.first + y.first - d);
            if(d == 0)break;
        }
    }
    cout << ans << '\n';






}
void test_case() {
    int t;
    cin >> t;
    while(t--)another();
}
int main() {

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

    another();
}


Measured memory_bytes: 27468
/**
 * @author yuichirw
 *
 */
import java.util.*;
public class Main {
	
	static int		n;
	static int[][] 	mat;
	static Scanner 	sc = new Scanner(System.in);
	
	static boolean read() {
		n = sc.nextInt();
		if(n == 0) return false;
		mat = new int[n+1][n+1];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				mat[i][j] = sc.nextInt();
			}
		}
		return true;
	}
	
	static void solve() {
		int sum;
		for(int i = 0; i < n; i++) {
			sum = 0;
			for(int j = 0; j < n; j++) {
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		
		for(int j = 0; j < n; j++) {
			sum = 0;
			for(int i = 0; i < n; i++) {
				sum += mat[i][j];
			}
			mat[n][j] = sum;
		}
		
		sum = 0;
		for(int i = 0; i < n; i++) {
			sum += mat[i][n];
		}
		mat[n][n] = sum;
		
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n; j++) {
				System.out.printf("%5d", mat[i][j]);
			}
			System.out.printf("\n");
		}
	}
	
	public static void main(String[] args) {
		while(read()) {
			solve();
		}
	}

}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

ll dp[1010][1010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W; cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    dp[0][0] = 1;
    rep(y, H) rep(x, W) {
        if (y + 1 < H and A[y+1][x] != '#') {
            dp[y+1][x] += dp[y][x];
            dp[y+1][x] %= mod;
        }
        if (x + 1 < W and A[y][x+1] != '#') {
            dp[y][x+1] += dp[y][x];
            dp[y][x+1] %= mod;
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

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

typedef struct a{
  int d,p;
}A;

int main(void)
{
  int i,j;
  int n,m;
  A kukan[10000],tmp;
  int s;

  while(1){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0)break;
    
    for(i=0;i<n;i++)scanf("%d %d",&kukan[i].d,&kukan[i].p);

    for(i=0;i<n-1;i++){
      for(j=i;j<n;j++){
	if(kukan[i].p<kukan[j].p){
	  tmp = kukan[i];
	  kukan[i] = kukan[j];
	  kukan[j] = tmp;
	}
      }
    }

    for(i=0;i<n;i++){
      if(kukan[i].d<m){
	m -= kukan[i].d;
	kukan[i].d = 0;
      }else{
	kukan[i].d -= m;
	m = 0;
      }
      if(!m)break;
    }

    s = 0;
    for(i=0;i<n;i++)s += kukan[i].d * kukan[i].p;
    printf("%d\n",s);

  }
  return 0;
}

Measured memory_bytes: 492
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mul(n) n<<1 //multiply by 2;
#define di(n) n>>1 //division by 2;
#define powof2(n) 1<<n //finding power of 2
#define ans(n) (n&(n-1)==0) //check if number is power of 2;
#define statusofxbit(n,x) (n&(1<<x-1)==0) //get the status of xth bit from the right;
#define setthexthbit(n,x) n|(1<<x-1)
#define togglexthbit(n,x) n^(1<<x-1)
#define equalno(a,b) if(a^b==0) cout<<1<<endl; else cout<<0<<endl;
#define xortwotogetthird c=a^b
#define resettherightmostsetbit(n) n&(n-1) 
#define Bitlength(n) len=0; while(n){len+=1;n>>=1;};
#define noofsetbits(n) __builtin_popcount(n);
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    //cin >> t;
    while (t--) {
      int a,b;
      cin>>a>>b;
      if(a<=b){
        cout<<"unsafe"<<endl;
      }  
      else if(a>b){
        cout<<"safe"<<endl;
      }
        
    }
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int a,b,c,ans;
  cin >> a >> b >> c;

  ans = min(c,b/a);

  cout << ans << endl;
  
  return 0;
}


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

int main() {
    int n;
    scanf("%d", &n);
    if(n % 1000 == 0) {
        printf("0\n");
    }
    else {
        printf("%d\n", 1000 - (n % 1000));
    }
    return 0;
}

Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 1e5 + 50;

int tab[N];
int a[N], b[N], n, tot = 0;
int buc[N];

namespace Dsu {
  int fa[N], countLinks;
  inline void Init() {
    memset(fa, 0, sizeof fa); countLinks = 0;
  }
  inline int getf(int x) {
    return fa[x] ? fa[x] = getf(fa[x]) : x;
  }
  inline void U(int x, int y) {
    x = getf(x); y = getf(y);
    if (x != y) {
      fa[x] = y; countLinks ++;
    }
  }
}
using namespace Dsu;

vector <int> rec[N];

int cnt[N];
bool vv[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++) {
    scanf("%d", &a[i]); tot ^= a[i]; tab[i] = a[i];
  }
  for (int i = 1; i <= n; i ++) scanf("%d", &b[i]);
  tab[n + 1] = tot;
  sort(tab + 1, tab + n + 2);
  tot = lower_bound(tab + 1, tab + n + 2, tot) - tab;
  buc[tot] ++;
  for (int i = 1; i <= n; i ++) {
    a[i] = lower_bound(tab + 1, tab + n + 2, a[i]) - tab;
    int lb = b[i];
    b[i] = lower_bound(tab + 1, tab + n + 2, b[i]) - tab;
    if (lb != tab[b[i]]) {
      puts("-1"); return 0;
    }
    buc[a[i]] ++; buc[b[i]] --;
    if (a[i] != b[i]) {
      rec[a[i]].push_back(i);
      rec[b[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n + 1; i ++)
    if (buc[i] < 0) {
      puts("-1"); return 0;
    }
  for (int i = 1; i <= n + 1; i ++)
    if (rec[i].size()) {
      for (int j = 1; j < (int)rec[i].size(); j ++)
        U(rec[i][0], rec[i][j]);
    }
  for (int i = 1; i <= n; i ++) {
    cnt[getf(i)] ++;
    if (b[i] == tot) vv[getf(i)] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i ++)
    if (a[i] != b[i] && i == getf(i)) ans += cnt[i] - vv[i] + 1;
  printf("%d\n", ans);
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
int n,m;
vector<LL> a;
vector<pair<int,LL>> v;

int main(){
  cin>>n>>m;
  REP(i,n){
    LL tmp;
    cin>>tmp;
    a.push_back(tmp);
  }
  sort(ALL(a));
  REP(i,m){
    pair<int,LL> p;
    cin>>p.first>>p.second;
    v.push_back(p);
  }
  sort(ALL(v),[](pair<int,LL> p1,pair<int,LL> p2){return p1.second > p2.second;});
  int ind=0,ind_in;
  LL ret = 0;
  bool brk=false;
  REP(i,v.size()){
    ind_in = ind;
    FOR(j,ind,min(n,ind+v[i].first)){
      if(a[j] < v[i].second){
	ret += v[i].second;
	ind_in++;
      }else{
	brk=true;
	break;
      }
    }
    ind = ind_in;
    if(brk)break;
  }
  FOR(i,ind,n){
    ret += a[i];
  }
  
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
typedef long long ll;

struct UnionFind {
private:
    int n;
    vector<int> r, p; //r means "rank", p means "parent"
    
public:
    UnionFind() = delete;
    UnionFind(int sz) : n(sz), r(sz, 1), p(sz, 0){
        iota(p.begin(), p.end(), 0);
    }// set data as parent[i] = i
    
    int find(int x) {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }// find and return parents

    bool same(int x, int y) {
        return find(x) == find(y);
    }// if node x and y is same root or not

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(r[x] < r[y]) swap(x, y);
        r[x] += r[y];
        p[y] = x;
    }// unite different trees

    int size(int x) {
        return r[find(x)];
    }// return tree's hegiht
};

int main(){
  int n, q;
  
  cin >> n >> q;
  
  UnionFind uf(n);
  
  for(int i = 0; i < q; i++){
    int c, x, y;
    
    cin >> c >> x >> y;
    
    if(c == 1) cout << uf.same(x, y) << "\n";
    else uf.unite(x, y);
  }
  cout << flush;
  
  return 0;
}



Measured memory_bytes: 3172
include Math

class KochPoint
  attr_reader :x, :y
  
  def initialize(x,y)
    @x = x
    @y = y
  end
  
  def rot60
    return KochPoint.new( @x*cos(PI*60.0/180.0) - @y*sin(PI*60.0/180.0),
                          @x*sin(PI*60.0/180.0) + @y*cos(PI*60.0/180.0) )
  end
  
  def +(p)
    return KochPoint.new( @x + p.x, @y + p.y)
  end
  def -(p)
    return KochPoint.new( @x - p.x, @y - p.y)
  end
  def *(n)
    return KochPoint.new( @x*n,  @y*n)
  end
  def /(n)
    return KochPoint.new( @x/n,  @y/n)
  end
  
  def printp
    printf("%.8f %.8f\n", @x, @y)
  end
end

def koch_point(p1, p2, n)
  
  return if n==0
  
  s = (p1*2 + p2)/3
  t = (p1+p2*2)/3
  u = (t-s).rot60+s
  
  koch_point(p1,s,n-1)
  # print "s #{n} "
  s.printp
  koch_point(s,u,n-1)
  # print "u #{n} "
  u.printp
  koch_point(u,t,n-1)
  # print "t #{n} "
  t.printp
  koch_point(t,p2,n-1)
end


n = STDIN.gets.to_i

p1 = KochPoint.new( 0.0, 0.0)
p2 = KochPoint.new( 100.0, 0.0)

p1.printp
koch_point(p1,p2,n)
p2.printp

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    bool flag = 0;
    rep(i, s.size())
    {
        if (i % 2 == 0 && s[i] == 'L')
            flag = 1;
        if (i % 2 == 1 && s[i] == 'R')
            flag = 1;
    }

    flag == 0 ? OP("Yes") : OP("No");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){

    int a[10];
    for(int i=0;i<10;i++)
        scanf("%d",&a[i]);
    int b[3]={0};
    for(int i=0;i<3;i++)
    {
        int t;
        for(int j=0;j<10;j++)
        {
            if(a[j]>b[i])
            {
                b[i]=a[j];
                t=j;
            }
        }
        a[t]=0;
    }
    for(int i=0;i<3;i++)
        printf("%d\n",b[i]);

    return 0;
}



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

ll euq_gcd(ll a, ll b) {return b ? euq_gcd(b, a%b) : a;}

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

    vector<ll> L(N), R(N+2);
    L[0] = R[N+1] = 0;
    for(ll i=1; i<N; i++) {
        L[i] = euq_gcd(L[i-1], A[i]);
        R[N+1-i] = euq_gcd(R[N+2-i], A[N+1-i]);
    }

    ll max = -1;
    for(ll i=1; i<=N; i++) {
        ll temp = euq_gcd(L[i-1], R[i+1]);
        if(temp > max) max = temp;
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	int ans = 1 << 30;
	for (int i = 0; i <= N; i++) {
		int cnt = 0;
		int x = i;
		while (x) {
			cnt += x % 6;
			x /= 6;
		}
		x = N - i;
		while (x) {
			cnt += x % 9;
			x /= 9;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

cnt = 0
for i in range(n):
    s = 0
    a = list(map(int, input().split()))
    for j in range(m):
        s += a[j] * b[j]
    if s + c > 0:
        cnt+=1

print(cnt)


Measured memory_bytes: 38384
//105
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    if(N%K == 0){
        cout << 0 << endl;        
    }else{
        cout << 1 << endl;        
    }
}


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

int main() {
  int N, R;
  cin >> N >> R;
  
  if(N >= 10) cout << R << endl;
  else cout << R + (100*(10-N)) << endl;
  return 0;
}




Measured memory_bytes: 3588
#include<stdio.h>
int main(){
    char b,pair;
    scanf("%c",&b);
    if(b=='A')pair='T';
    if(b=='T')pair='A';
    if(b=='C')pair='G';
    if(b=='G')pair='C';
    printf("%c\n",pair);
    return 0;
}

Measured memory_bytes: 128
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	bool a;
	cin >> a;
	cout << !a << endl;
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 3612
# https://atcoder.jp/contests/abc161/tasks/abc161_d
from collections import deque

numbers = deque([i for i in range(1, 10)])
K = int(input())
k = 0
ans = 0

while K != k:
    n = numbers.popleft()
    if n % 10 == 0:
        numbers.append(n * 10)
        numbers.append(n * 10 + 1)
    elif n % 10 == 9:
        numbers.append(n * 10 + 8)
        numbers.append(n * 10 + 9)
    else:
        d = n % 10
        numbers.append(n * 10 + d - 1)
        numbers.append(n * 10 + d)
        numbers.append(n * 10 + d + 1)

    k += 1
    ans = n

print(ans)


Measured memory_bytes: 40944
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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; }

int main() {
    int N;
    cin >> N;
    int abc[N][3];
    rep(i, N) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    ll dp[N+10][3]; // dp[i][j]: i日目までで、i日目でj番目を選んだ時のマキシマムザ幸福
    rep(i, N+10){
        rep(j, 3) dp[i][j] = 0;
    }
    rep(i, N){
        rep(j, 3) {
            rep(k, 3){
                if (j==k) continue;
                chmax(dp[i+1][k], dp[i][j] + abc[i][k]);
            }
        }
    }
    ll ans = 0;
    rep(i, 3) chmax(ans, dp[N][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3712
import collections

def distances(n,x,y):
    for i in range(1, int(n)):
        for j in range(i+1, int(n)+1):
            yield min(abs(i-j), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)

n, x, y = map(int, input().split())

c = collections.Counter(distances(n,x,y))

for i in range(1,n):
    print(c[i])

Measured memory_bytes: 3956
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Sushi[] sushis = new Sushi[n];
        for(int i = 0; i < n; i++) {
            sushis[i] = new Sushi(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(sushis, (a, b) -> b.deliciousness - a.deliciousness);
        Stack<Sushi> extra = new Stack<>();
        HashSet<Integer> tasteSet = new HashSet<>();
        long tasteCount = 0;
        long totalDeliciousness = 0;
        for(int i = 0; i < k; i++) {
            Sushi s = sushis[i];
            if(!tasteSet.contains(s.taste)) {
                tasteSet.add(s.taste);
                tasteCount++;
            } else {
                extra.push(s);
            }
            totalDeliciousness += s.deliciousness;
        }
        long satisfaction = totalDeliciousness + (tasteCount * tasteCount);
        for(int i = k; i < n && extra.size() > 0; i++) {
            Sushi s = sushis[i];
            if(!tasteSet.contains(s.taste)) {
                tasteCount++;
                tasteSet.add(s.taste);
                totalDeliciousness -= extra.pop().deliciousness;
                totalDeliciousness += s.deliciousness;
                satisfaction = Math.max(satisfaction, totalDeliciousness + (tasteCount * tasteCount));
            }
        }
        System.out.println(satisfaction);
    }

    private static class Sushi {
        int taste;
        int deliciousness;
        Sushi(int t, int d) {
            taste = t;
            deliciousness = d;
        }
    }
}


Measured memory_bytes: 96124
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

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

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N;
	cin >> N;

	deque<int> deq;
	for (int i = 0; i < N; i++) {

		int a;
		cin >> a;
		if (i & 1) deq.emplace_back(a);
		else deq.emplace_front(a);

	}

	while (!deq.empty()) {

		if (N & 1) {
			cout << deq.front() << " ";
			deq.pop_front();
		}
		else {
			cout << deq.back() << " ";
			deq.pop_back();
		}
	
	}

	return 0;
}

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

int selectionSort(vector<int>& A, int N) {
  int cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    int minJ = i;
    for (int j = i + 1; j < N; j++) {
      if (A[j] < A[minJ]) {
        minJ = j;
      }
    }
    if (i != minJ) {
      swap(A[i], A[minJ]);
      cnt++;
    }
  }
  return cnt;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int cnt = selectionSort(A, N);
  cout << A.at(0);
  for (int i = 1; i < N; i++) cout << ' ' << A.at(i);
  cout << endl;
  cout << cnt << endl;
}



Measured memory_bytes: 3088
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    a,b,c=pin()
    #from math import sqrt
    #cond =(c-a-b)>sqrt(a*b)*2
    #if c<=a+b:"No"
    cond=0
    t=c-(a+b)
    if t>0 and t**2-4*(a*b)>0:
        cond=1
    print(["No","Yes"][cond])

"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3 9"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 3 10"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 51564
#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0)
using namespace std;
ll MOD = pow(10, 9) + 7;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535

int main()
{
	fastio;
	ll n, k;
	cin >> n >> k;
	vector<ll> a;
	vector<ll> wt(n, 0), vr(n, 0);
	for (ll i = 0; i < n; i++)
	{
		ll cd;
		cin >> cd;
		for (ll j = 0; j < a.size(); j++)
		{
			if (a[j] > cd)
				wt[j]++;
		}
		a.PB(cd);
	}
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j < n; j++)
		{
			if (a[j] < a[i])
				vr[i]++;
		}
	}
	ll ans = 0;
	for (auto itr : wt)
	{
		ans = (ans + (itr * k) % MOD) % MOD;
	}
	for (auto itr : vr)
	{
		ans = (ans + (itr * ((k) * (k - 1) / 2 % MOD)) % MOD) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;


int main()
{

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

	ll N, X, M; cin >> N >> X >> M;
	map<ll, ll> mp;
	vector<ll> a(M + 1);
	a[0] = X;
	mp[a[0]] = 0;
	for (ll i = 1; i <= M; i++) {
		a[i] = a[i - 1] * a[i - 1] % M;
		if (mp.find(a[i]) != mp.end()) {
			ll idx = mp[a[i]];
			ll len = i - idx;
			ll sum = 0;
			for (int j = idx; j < i; j++) sum += a[j];
			ll res = 0; for (int j = 0; j < idx; j++) res += a[j];
			N -= idx;
			res += sum * (N / len);
			for (int j = 0; j < N % len; j++) res += a[idx + j];
			cout << res << endl;
			return 0;
		}
		else {
			mp[a[i]] = i;
		}
	}
	ll res = 0; for (int i = 0; i < N; i++) res += a[i];
	cout << res << endl;
	return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int64_t> A(N);
  for (int i=0; i<N; i++){
    cin >> A.at(i);
    if (A.at(i) == 0){
      cout << 0 << endl;
      return 0;;
    }
  }
  
    int64_t ans=1;
  	for (int i=0; i<N; i++){
      if(A.at(i) <= 1000000000000000000/ans){
        ans *= A.at(i);
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  cout << ans << endl;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator^(int b) {mint res = 1;while(b > 0) {if(b&1) {res = (res*(*this));}*this=(*this)*(*this);b>>=1;} return res;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
typedef vector<mint> vm;
typedef vector<vm> vvm;
  
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vi cnt(26,0);
  rep(i,N) {
    cnt[s[i]-'a']++;
  }
  mint ans = 1;
  rep(i,26) {
    ans *= cnt[i]+1;
  }
  ans -= 1;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 512
N = int(input())
flag = 0
ans = 0
A = input()
for i in range(N*2)[::2]:
	if A[i] == "G":
		flag |= 1
	if A[i] == "P":
		flag |= 1 << 1
	if A[i] == "W":
		flag |= 1 << 2
	if A[i] == "Y":
		flag |= 1 << 3

for i in range(4):
	if flag & 1 << i:
		ans+=1
if ans == 4:
	print("Four")
else:
	print("Three")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void){
    string S;
    int N, sum = 0;
    
    cin >> S;
    
    istringstream ss = istringstream(S);
    ss >> N;
    
    for ( int i = 0; i < S.size(); i++) {
        string c = S.substr(i,1);
        sum += stoi(c);
        //cout << S.substr(i,1) << endl;
    }
    
    //cout << N <<  " " << sum << endl;
    
    if ( N%sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


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

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

using namespace std;
using ll = long long;

int main(void){
    string s;
    cin >> s;
    int lens = s.length();
    char val;
    vector<int> kouho;
    rep(i, lens){
        val = s[i];
        vector<int> valpos;
        vector<int> temp;
        rep(j, lens) if(s[j] == val) valpos.push_back(j);
        int valpossize = valpos.size();
        rep(j, valpossize){
            if(j == 0) temp.push_back(valpos[0]);
            else{
                temp.push_back(valpos[j]-valpos[j-1]-1);
            }
        }
        temp.push_back(lens - valpos[valpos.size()-1] - 1);
        kouho.push_back(*max_element(temp.begin(), temp.end()));
    }
    cout << *min_element(kouho.begin(), kouho.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n, k, q;
    cin >> n >> k >> q;

    vector<ll> a(q);
    vector<ll> point(n,0);
    for(int i = 0; i < q; i++){
        cin >> a[i];
        point[a[i]-1]++;
    }

    for(int i = 0; i < n; i++){
        ll p = k - (q-point[i]);
        if(p>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;

}


Measured memory_bytes: 2176
using System;

class Program
{
    const long inf = (long)1e11;

    static void Main(string[] args)
    {
        var nw = Console.ReadLine().Split();
        var n = int.Parse(nw[0]);
        var W = int.Parse(nw[1]);

        var w = new int[n];
        var v = new int[n];
        var v_sum = 0;
        for (int i = 0; i < n; i++)
        {
            var wv = Console.ReadLine().Split();
            w[i] = int.Parse(wv[0]);
            v[i] = int.Parse(wv[1]);
            v_sum += v[i];
        }

        var dp = new long[n + 1, v_sum + 1];
        for (int i = 0; i <= n; i++)
            for (int j = 1; j <= v_sum; j++)
                dp[i, j] = inf;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= v_sum; j++)
            {
                if (v[i] <= j)
                {
                    dp[i + 1, j] = Math.Min(
                        dp[i, j],
                        dp[i, j - v[i]] + w[i]);
                }
                else
                {
                    dp[i + 1, j] = Math.Min(
                        dp[i, j],
                        w[i]);
                }
            }
        }

        var ans = 0;
        for (; ans <= v_sum; ans++)
        {
            if (W < dp[n, ans]) break;
        }

        Console.WriteLine(ans - 1);
    }
}


Measured memory_bytes: 89056
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; 
	while (cin >> n, n) {
		vector<string> reply(n);
		vector<int> dot_cnt(n,0);
		for (int i = 0; i < n;i++) {
			cin >> reply[i];
			for (int j = 0; j < reply[i].length();j++) {
				if (reply[i][j] == '.')dot_cnt[i]++;
				else break;
			}
		}
		for (int i = 1; i < n;i++) {
			reply[i][dot_cnt[i] - 1] = '+';
			for (int j = i + 1;j < n;j++) {
				if (dot_cnt[i] > dot_cnt[j])break;
				if (dot_cnt[i] == dot_cnt[j]) {
					for (int k = i + 1; k < j; k++) {
						reply[k][dot_cnt[i] - 1] = '|';
					}
					break;
				}
			}
		}
		for (int i = 0; i < n;i++) {
			for (int j = 0; j < reply[i].length();j++) {
				if (reply[i][j] == '.' && j < dot_cnt[i])cout << " ";
				else cout << reply[i][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3492
a,b = map(int,raw_input().split())
if a > 0 and b > 0 :
    print 'Positive'
elif (a <= 0 and b >=0) :
    print 'Zero'
else :
    if b == 0 :
        print 'Zero'
    else :
        if (b-a+1)%2 == 0 :
            print 'Positive'
        else :
            print 'Negative'                


Measured memory_bytes: 2568
from sys import stdin

n,y = [int(x) for x in stdin.readline().rstrip().split()]

num = y//1000
saitei = num//10

if saitei > n:
    print(-1,-1,-1)
    exit()

for i in range(n+1):
    for j in range(n+1-i):
        if i*10+j*5+(n-i-j) == num:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3064
#include<stdio.h>                                                                               
int main(){                                                                                     
    int N,L,sum = 0,less = 10000,less_n;                                                        
    int taste[200];                                                                             
    int div[200];                                                                               
                                                                                                
    scanf("%d%d",&N,&L);                                                                        
                                                                                                
    for(int i = 1;i <= N;i++){                                                                  
        taste[i-1] = L + i - 1;                                                                 
    }                                                                                           
                                                                                                
    for(int i = 0;i < N; i++){                                                                  
        div[i] = (0 - taste[i])*(0 - taste[i]);                                                 
        //絶対値の2乗                                                                           
                                                                                                
        //差が最小のものを選ぶ                                                                  
        if(less > div[i]){                                                                      
            less = div[i];                                                                      
            less_n = i;                                                                         
        }                                                                                       
    }                                                                                           
                                                                                                
    for(int i = 0; i < N; i++){                                                                 
        if(i != less_n){                                                                        
            sum+=taste[i];                                                                      
        }                                                                                       
    }                                                                                           
    printf("%d\n",sum);                                                                         
    return 0;                                                                                   
}      

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		
		System.out.println((T - T % A) / A * B);
	}
}


Measured memory_bytes: 22356
#include<stdio.h>

int main(void)
{
	double weight;

	while(scanf("%lf", &weight) != EOF)
	{
		if(!(weight > 48.0))
		{
			printf("light fly\n");
		}
		else if(!(weight > 51.0))
		{
			printf("fly\n");
		}
		else if(!(weight > 54.0))
		{
			printf("bantam\n");
		}
		else if(!(weight > 57.0))
		{
			printf("feather\n");
		}
		else if(!(weight > 60.0))
		{
			printf("light\n");
		}
		else if(!(weight > 64.0))
		{
			printf("light welter\n");
		}
		else if(!(weight > 69.0))
		{
			printf("welter\n");
		}
		else if(!(weight > 75.0))
		{
			printf("light middle\n");
		}
		else if(!(weight > 81.0))
		{
			printf("middle\n");
		}
		else if(!(weight > 91.0))
		{
			printf("light heavy\n");
		}
		else
		{
			printf("heavy\n");
		}
	}

	return 0;
}

Measured memory_bytes: 608
from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])

Measured memory_bytes: 8612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>

#define REP(i, n) for(int i=0;i<n;i++)
#define ll long long
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;

int main(){

  int n;
  vector<int> v;

  scanf("%d", &n);
  REP(i, n){
    int t;
    scanf("%d", &t);
    v.pb(t);
  }

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

  long long res = 1;
  if(n % 2 != 0){
    int last_num = 0;
    REP(i, n){
      if(i == 0){
        if(v[0] != 0){
          printf("0\n");
          return 0;
        }
      }else{
        if(v[i] == last_num + 2 && v[i] == v[i + 1]){
          last_num = v[i];
          i++;
        }else{
          printf("0\n");
          return 0;
        }
      }
    }
  }else{
    int last_num;
    REP(i, n){
      if(i == 0){
        if(v[i] == 1 && v[i + 1] == 1){
          last_num = 1;
          i++;
        }else{
          printf("0\n");
          return 0;
        }
      }else{
        if(v[i] == last_num + 2 && v[i] == v[i + 1]){
          last_num = v[i];
          i++;
        }else{
          printf("0\n");
          return 0;
        }
      }
    }
  }

  REP(i,n / 2){
    res *= 2;
    res = res % 1000000007;
  }

  printf("%lld\n", res);


  return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K, N;
    cin >> K >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int max = 0;
    for(int i = 0; i < N; i++){
        int dif;
        if(i != N - 1){
            dif = a.at(i + 1) - a.at(i);
        }else{
            dif = a.at(0) + K - a.at(i);
        }
        if(dif > max){
            max = dif;
        }
    }
    cout << K - max << endl;
    return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append(a)
	b_list.append(b)
c_list = []
d_list = []
for i in range(m):
	c, d = map(int, input().split())
	c_list.append(c)
	d_list.append(d)
for i, x1 in enumerate(a_list):
	y1 = b_list[i]
	v_list = []
	for j, x2 in enumerate(c_list):
		y2 = d_list[j]
		v_list.append(abs(x1 - x2) + abs(y1 - y2))
	print(v_list.index(min(v_list)) + 1)


Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
#define N 100055
#define ll long long
int n,k,ar[N],dp[N];

int solve(int kk) {
    if( kk == 0)
        return 0;

    int &ret = dp[kk];
    if(~ret)
        return ret;

    int res = 0;
    for(int i=1; i<=n; ++i) {
        if(kk-ar[i] >= 0)
            res = max(res, 1^solve(kk-ar[i]));
        if(res)
            break;
    }
    return ret = res;
}

int main() {

    memset(dp,-1,sizeof dp);
    scanf("%d%d",&n,&k);
    for(int i=1; i<=n; ++i) {
        scanf("%d",&ar[i]);
    }

    cout << (solve(k)? "First":"Second");

    return 0;
}


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

namespace _0069
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {

                int vLineCnt = RInt();
                if (vLineCnt == 0) return;

                int start = RInt();
                int goal = RInt();

                int n = RInt();

                int[,] map = new int[n, vLineCnt + 1];
                for (int i = 0 ; i < n ; i++)
                {
                    string line = RSt();
                    for (int j = 1 ; j < vLineCnt ; j++)
                    {
                        map[i, j] = int.Parse(line[j - 1].ToString());
                    }
                }

                if (CanReachGoal(map, start, goal)) Console.WriteLine(0);
                else Console.WriteLine(CanReachGoalAddOneLine(map, start, goal));

            }

        }

        private static string CanReachGoalAddOneLine(int[,] map, int start, int goal)
        {
            for (int i = 0 ; i < map.GetLength(0) ; i++)
            {
                for (int j = 1 ; j < map.GetLength(1) - 1 ; j++)
                {
                    if (map[i, j] == 0 && map[i, j - 1] == 0 && map[i, j + 1] == 0)
                    {
                        map[i, j] = 1;
                        if(CanReachGoal(map, start, goal)) return (i + 1).ToString() + " " + j.ToString();
                        map[i, j] = 0;
                    }
                }
            }

            return "1";
        }

        private static bool CanReachGoal(int[,] map, int start, int goal)
        {
            int cur = start;
            for (int i = 0 ; i < map.GetLength(0) ; i++)
            {
                if (map[i, cur - 1] == 1) cur--;
                else if (map[i, cur] == 1) cur++;
            }
            return cur == goal ? true : false;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 17872
using System;
using System.Collections.Generic;
using System.Linq;

namespace AGC032A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long[] NN = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            long N = NN[0];
            long[] B = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            long[] Rev = new long[N];
            List<long> BB = B.ToList();

            for (int i = 0; i < N; i++)
            {
                int stat = -1;
                for (int j = 0; j < BB.Count; j++)
                {
                    if (j + 1 == BB[j])
                    {
                        stat = Math.Max(stat, j);
                    }
                }

                if (stat == -1)
                {
                    Console.WriteLine(-1);
                    return;
                }

                Rev[i] = stat;
                BB.RemoveAt(stat);
            }

            Array.Reverse(Rev);
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(Rev[i] + 1);
            }
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int H, N;
	cin >> H >> N;
	vector<P> vec(N);
	rep( i, 0, N ){
		int a, b;
		cin >> a >> b;
		vec[i] = P(a, b);
	}
	vector<int> dp(H+1, k_mod);
	dp[0] = 0;
	rep(i,0,N){
		rep(h,vec[i].first,H+vec[i].first){
			chmin(dp[min(H, h)], dp[h-vec[i].first] + vec[i].second);
		}
	}
	cout << dp[H] << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

int main() {
    int n, total;
    cin >> n >> total;

    int x = -1, y = -1, z = -1;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n - i; j++){
            if (i * 10000 + j * 5000 + (n - i - j) * 1000 == total){
                x = i;
                y = j;
                z = n - i - j;
                break;
            }
        }
    }
    cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256