akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  int q;
  cin >> s >> q;
  deque<char> que;
  rep(i,sz(s)) que.push_back(s[i]);
  int flag = 0;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 1) flag = (flag + 1) % 2;
    else {
      int f;
      char c;
      cin >> f >> c;
      f = f - 1 + flag;
      f %= 2;
      if(f == 0) que.push_front(c);
      else que.push_back(c);
    }
  }
  while(sz(que)) {
    char ans;
    if(flag == 0) {
      ans = que.front();
      que.pop_front();
    }
    else {
      ans = que.back();
      que.pop_back();
    }
    cout << ans;
  }
  cout << endl;
}

Measured memory_bytes: 976
// ITP1_6_C
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    vector<vector<vector<int>>> a(4,vector<vector<int>>(3,vector<int>(10,0)));
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        a[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" "<<a[i][j][k];
            }
            cout<<endl;
        }
        if(i!=3){
            for(int j=0;j<20;j++){
                cout<<"#";
            }
            cout<<endl;
        }
    }
    return 0;    
}


Measured memory_bytes: 3120
import java.util.*; 

public class Main {
	
	void run() {
		Scanner sc = new Scanner(System.in);
		System.out.println(factrical(sc.nextInt()));
	}
	
	long factrical(long x) {
		if (x == 0)
			return 1;
		else return x * factrical(x-1);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 11000
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  char x,y; cin>>x>>y;
	if(x<y) cout<<'<'<<endl;
	else if(x==y) cout<<'='<<endl;
	else cout<<'>'<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define amax(a, b) a = max(a, b)

int main() {
    int n;
    cin >> n;
    int a[n]; for (auto &ai:a) cin >> ai;
    ll dp[n+1];
    fill(dp, dp + n+1, 0ll);
    dp[0] = 1000;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            amax(dp[j+1], dp[i] / a[i] * a[j] + dp[i] % a[i]);
        }
        amax(dp[i+1], dp[i]);
    }
    cout << dp[n] << '\n';
    return 0;
}

Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))  # よしなにpaddingすることで終端処理を楽に

# print(S)
while len(S) > 10:
    end3 = ''.join([S[6], S[5], S[4], S[3], S[2], S[1], S[0]])
    # print(end3)
    if end3[2:] == 'dream':
        num_pop = 5
    elif end3 == 'dreamer':
        num_pop = 7
    elif end3[2:] == 'erase':
        num_pop = 5
    elif end3[1:] == 'eraser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()

# print(S)
if len(S) == 10:
    print('YES')
else:
    print('NO')


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

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

    if (A > B) {
        cout << A + (A - 1) << endl;
    } else if (A == B) {
        cout << A + B << endl;
    } else {
        cout << B + (B - 1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

struct processtime {
	char name[11];
	int time;
};

int main(){
	int n , q;
	int i;
	int rest;
	int time=0;
	queue<processtime> qu;
	cin >> n >> q;
	processtime* p = new processtime [n];
	processtime tmp;
	for(i=0;i<n ;++i){
		cin >> p[i].name >> p[i].time;
		qu.push(p[i]);
	}
	while(!qu.empty()){
		tmp=qu.front();
		qu.pop();
		rest=tmp.time-q;
		if(rest>0){
		time+=q;
		tmp.time=rest;
		qu.push(tmp);
		} else {
			time+=q+rest;
			cout << tmp.name << " " << time << endl;
		}	 
	}
	return 0; 
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;

    vll s(n), t(m);
    rep(i, 0, n) { cin >> s[i]; }
    rep(i, 0, m) { cin >> t[i]; }

    vll cols(m, 0);
    rep(i, 0, n) {
        ll sum = 0;
        rep(j, 0, m) {
            ll d = (s[i] == t[j]) ? (1 + sum) % MOD : 0;
            sum = (sum + cols[j]) % MOD;
            cols[j] = (cols[j] + d) % MOD;
        }
    }

    ll ans = 1;
    rep(i, 0, m) { ans = (ans + cols[i]) % MOD; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define MAX_W 50;
#define MAX_H 50;
ll N;
int W, H;
vector<ll> A;
vector<vector<int>> fields;
vector<vector<bool>> seen;

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

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

void dfs(int x, int y) {
  seen[y][x] = true;

  for (int i = 0; i < 8; i++) {
    if (x + dx[i] < 0 || x + dx[i] >= W || y + dy[i] < 0 || y + dy[i] >= H) continue;
    if (seen[y+dy[i]][x+dx[i]]) continue;
    if (fields[y + dy[i]][x + dx[i]]) dfs(x+dx[i], y+dy[i]);
  }
}

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

  // Start Loop
  while(true){
    cin >> W >> H;
    if (!(W || H)) break;
    fields.resize(H);
    seen.resize(H);
    rep(j, H) {
      fields[j].resize(W);
      seen[j].resize(W, false);
      rep(i, W) {
        cin >> fields[j][i]; 
      }
    }
    ll count = 0; 
    rep(j, H) {
      rep(i, W) {
        if (fields[j][i] && !seen[j][i]) {
          dfs(i, j);
          count++;
        }
      }
    }
    cout << count << endl;
    fields.clear();
    seen.clear();
  }
  // End Loop
  return 0;
}



Measured memory_bytes: 3212
(defun dfs (graph v n visited)
  (let ((all-visited-p t))
    (dotimes (i n)
      (if (null (aref visited i))
          (setf all-visited-p nil)))
    (if all-visited-p
        1
        (let ((res 0))
          (dotimes (i n)
            (if (and (aref graph v i)
                     (null (aref visited i)))
                (setf (aref visited i) t
                      res (+ res (dfs graph i n visited))
                      (aref visited i) nil)))
          res))))

(let* ((n (read))
       (m (read))
       (graph (make-array `(,n ,n) :initial-element nil))
       (visited (make-array n :initial-element nil)))
  (dotimes (i m)
    (let ((a (1- (read)))
          (b (1- (read))))
      (setf (aref graph a b) t
            (aref graph b a) t)))
  (setf (aref visited 0) t)
  (format t "~A~%" (dfs graph 0 n visited)))

Measured memory_bytes: 18912
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int i, mlen = 0, mdeta = 0, deta = 0, len = 0, leni,j, detai;
  string str;
  vector<string> data;

  while(cin >> str) data.push_back(str);

  rep(i,data.size()){
    deta = 0;
    rep(j,data.size()){
      if(data[i] == data[j]) deta++;
      len = data[i].size();
      if(mlen < len){
        mlen = len;
        leni = i;
      }
      if(mdeta < deta){
        mdeta = deta;
        detai = i;
      }
    }
  }

  cout << data[detai] << " " << data[leni] << endl;

  return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())
a = list(map(int,input().split()))
inv = lambda w:sum([sum([a[i]>a[j] for j in range(i+1,n)]) for i in range(n-1)])
inv1 = lambda w:sum([sum([a[i]==a[j] for j in range(i+1,n)]) for i in range(n-1)])
ans1 = inv(a)
ans3 = inv1(a)
ans2 = (n*(n-1))//2 - ans1 - ans3
print((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7))

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

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  
  
  if ( op == "+" ) {
    a += b;
  }
  else{
    a -= b;
  }
    cout << a << endl;
    
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>

using namespace std;

class UnionFind {
  public:

    // 各頂点iの親を表すリスト
    // 親は-(要素数)に設定する
    vector<int> parent;

    UnionFind(int N) {
      parent = vector<int>(N, -1);
    }

    // Aの親を返す
    int root(int A) {
      if (parent[A] < 0) {
        return A;
      }
      else {
        // Aの親を更新することができる
        return parent[A] = root(parent[A]);
      }
    }

    // Aの所属するグループの大きさ
    int size(int A) {
      return -parent[root(A)]; // Aの親
    }

    // A, Bを同じグループにする。
    bool connect(int A, int B) {
      int parentA = root(A);
      int parentB = root(B);

      // AとBがそもそも同じグループ
      if (parentA == parentB) {
        return false;
      }

      // AとBが違うグループならば、どちらかに合体する
      // parentA < parentBの気持ち
      if (size(parentA) > size(parentB)) {
        swap(parentA, parentB);
      }

      // バグがありそう
      int sizeA = size(parentA);
      parent[parentA] = parentB;
      parent[parentB] = -(sizeA + size(parentB));

      return true;
    }
};

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

  int N, M;
  cin >> N >> M;

  int a[M], b[M];
  for (int i = M - 1; i >= 0; i--) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  vector<long> ans = vector<long>(M);
  ans[0] = (long) N * (N - 1) / 2;

  UnionFind uni = UnionFind(N);

  for (int i = 0; i < M - 1; i++) {
    if (uni.root(a[i]) != uni.root(b[i])) {
      // a[i], b[i]は違うグループ
      ans[i + 1] = ans[i] - (long)(uni.size(a[i]) * uni.size(b[i]));
      // cout << ans[i + 1] << ", " << ans[i] << endl;
      uni.connect(a[i], b[i]);
    }
    else {
      ans[i + 1] = ans[i];
    }
  }

  for (int i = M - 1; i >= 0; i--) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
  string a;
  cin>>a;
  int miss=0;
  for(int i=0;i<a.size()/2;i++){
    if(a[i]!=a[a.size()-1-i]){
      miss++;
    }
  }
  cout<<miss<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>

using namespace std;
  
int x[8], y[8];

double dist(int a, int b){
  return sqrt(pow((x[a] - x[b]), 2) + pow((y[a] - y[b]), 2));
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  double ret = 0;
  vector<vector<double>> d(n, vector<double>(n)); //distance A to B

  vector<int> path(n); // 初期順列
  for(int i = 0; i < n; i++) path[i] = i;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = dist(i, j);
      }
    }
  }

  vector<double> route;
  do {
    double tmp_route = 0;
    for(int i = 0; i < n-1; i++) {
      tmp_route += d[path[i]][path[i+1]];
    }
    route.push_back(tmp_route);
  } while(next_permutation(path.begin(), path.end()));

  cout << fixed << setprecision(7) \
      << accumulate(route.begin(), route.end(), 0.0)/route.size() << endl;

  return 0;
}


Measured memory_bytes: 3940
#%%time
mod=10**9+7
s=input()


#p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=[0 for i in range(13)]
d[0]=1
keep=[0 for _ in range(13)]
mul=1
cal=0
for v in rev:
    #print(i+num+1)
    if v=="?":
        t_d=[0 for _ in range(13)]
        #print("i,tmp:",i+num+1,",",tmp)
        for k in range(0,13):
            for j in range(0,10):
                t_d[(mul*j+k)%13]+=d[k]
            t_d[k]%=mod
        d=t_d
    else:
        cal+=mul*int(v)%13
    mul*=10
    mul%=13
        #print(t_d)
cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])



Measured memory_bytes: 44652
import java.util.*;

public class Main {
  private static int gcd(int p, int q) {
    if(p % q == 0)return q;
    return gcd(q, p % q);
  }
  
  private static long solve(int n) {
    long result = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i == j && j == k) {
            result += i;
          } else {
            result += gcd(gcd(i, j), k);
          }
        }
      }
    }
    return result;
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(solve(sc.nextInt()));
    sc.close();
  }
}



Measured memory_bytes: 35752
n=int(input())
a_1=list(map(int,input().split()))
a_2=list(map(int,input().split()))

#累積和を取る(O(n))
a_1_sum=[0]
a_2_sum=[0]
a_1_tmp=0
a_2_tmp=0

for i in range(n):
    a_1_tmp+=a_1[i]
    a_1_sum.append(a_1_tmp)
    a_2_tmp+=a_2[i]
    a_2_sum.append(a_2_tmp)
    
#クエリ(O(n))
k=100*100+100#kは通らないところのアメの和

for i in range(1,n+1):
    #a_2行でi列目より左の和 a_2_sum[i-1]
    #a_1行でi列目より右の和 a_1_sum[-1]-a_1_sum[i]
    k=min(k,a_2_sum[i-1]+a_1_sum[-1]-a_1_sum[i])
    
ans=a_1_sum[-1]+a_2_sum[-1]-k

print(ans)

Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>

using namespace std;
using ld = long double;

int main() {
    int N;
    cin >> N;

    ld ans = 0;
    for (int i = 0; i < N; ++i) {
        ld x;
        string u;
        cin >> x >> u;
        ans += x * (u == "JPY" ? 1 : 380000);
    }

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
using namespace std;

int n;
int t[100002][3];
int dp[100002][4];

int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i ++) {
      for (int j = 0; j < 3; j++) {
        cin >> t[i][j];
      }
    }

    memset(dp, -1, sizeof(dp));

    dp[0][3] = 0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 4; j++) {
        if (dp[i][j] == -1) continue;

        for (int nj = 0; nj < 3; nj++) {
          if (j == nj) continue;
          dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + t[i][nj]);
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < 3; i++) {
      ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

Modint<998244353> dp[3005][3005][3];

void solve()
{
	ll n, s;
	cin >> n >> s;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	const ll m=998244353;
	for (ll i = 0; i < n;++i)
	{
		rep(j,s+1){
			if(j-a[i]>=0){
				Modint<m> x=2, y=2;
				x=x.pow(i);
				y=y.pow(n-i-1);
				dp[i + 1][j][1] += dp[i][j - a[i]][0]*x;
				dp[i + 1][j][1] += dp[i][j - a[i]][1];
				dp[i + 1][j][2] += dp[i][j - a[i]][1] * y;
				dp[i + 1][j][2] += dp[i][j - a[i]][0]* x*y;
			}
			dp[i + 1][j][0] += dp[i][j][0];
			dp[i + 1][j][1] += dp[i][j][1]*2;
			dp[i + 1][j][2] += dp[i][j][2];
		}
	}
	cout << dp[n][s][2];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 109476
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#pragma warning(disable : 4996)

#define MAX_N 100
#define MAX_W 10000

int DP[MAX_N+1][MAX_W+1];
int N, W;

int max(int a, int b) {
	if (a > b) return a;
	return b;
}

int main(void) {
	scanf("%d %d", &N, &W);
	for (int i = 1; i <= N; ++i) {
		int v, w;
		scanf("%d %d", &v, &w);

		for (int j = 1; j <= W; ++j) {
			if (j >= w) {
				DP[i][j] = max(max(DP[i - 1][j-w] + v, DP[i - 1][j]), DP[i][j - 1]);
			}
			else {
				DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
			}
		}

	}
	printf("%d\n", DP[N][W]);
	return 0;
}



Measured memory_bytes: 6604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "



int main(){
    int n,x;cin>>n>>x;
    int d=0;
    int ans = 0;
    do{
        int l ;cin>>l;
        d+=l;
        ans++;
    }while(d<=x&&ans<=n);

    co(ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vl s(n), t(n), x(n);
    deque<tuple<ll, ll, ll>> events;
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> t[i] >> x[i];
        events.emplace_back(s[i] - x[i], 1, x[i]);
        events.emplace_back(t[i] - x[i], -1, x[i]);
    }
    sort(events.begin(), events.end());
    vl d(q);
    for (int i = 0; i < q; ++i) {
        cin >> d[i];
    }
    ll time = 0;
    set<ll> stop;
    for (int i = 0; i < q; ++i) {
        while (true) {
            if (events.empty())
                break;
            auto e = events.front();
            if (get<0>(e) <= d[i]) {
                ll flag = get<1>(e);
                if (flag == 1) {
                    stop.insert(get<2>(e));
                } else {
                    stop.erase(get<2>(e));
                }
                events.pop_front();
            } else {
                break;
            }
        }
        if (stop.empty())
            cout << -1 << "\n";
        else
            cout << *stop.begin() << "\n";
    }

    return 0;
}

Measured memory_bytes: 22032
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int inf = 1e9;

template <class T>
istream& operator>>(istream& ss, vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss >> v[i];
    return ss;
}

template <class T> 
ostream& operator<<(ostream& ss, const vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
    return ss;
}

void solve(){
    string s, t;
    cin >> s >> t;
    if (t.substr(0, s.size()) == s) cout << "Yes";
    else cout << "No";
}

int main(){
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main(){
int n;
int a[100001]={0};
cin>>n;
int ans=0;
int s=0;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
a[0]=a[1];
for(int i=1;i<=n+1;i++){
	if(a[i]==a[i-1])s++;
	else {
		if(s%2==1)ans++;
		s=1;
	}
}
cout<<ans;
}


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

using namespace std;
using ll = long long;

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

int main(){
    int a,b;
    char str;
    cin >> a >> str >> b;
    if(str == '+'){
        cout << a + b << endl;
    }else if(str == '-'){
        cout << a - b << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int top,S[1000];
void push(int x){
    S[++top]=x;
}
int pop(){
    top--;
    return S[top+1];
}

int main(){
    
    int a,b;
    top=0;
    char s[100];
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }
        else if(s[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }
        else{
            push(atoi(s));
        }
    }
    cout<<pop()<<endl;
    return 0;
}


Measured memory_bytes: 3244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      int num;
      int result;
      int primeMax;
      List<Integer> prime = new ArrayList<>(); 
      while(true) {

        if( ((line = br.readLine()) == null) || line.isEmpty() ) break;

        num = Integer.parseInt(line);
        if( num == 0 || num == 1) {
          result = 0;
          System.out.println(result);
          continue;
        }
        
        result = 0;
        prime.add(2);
        primeMax = 2;
        result += 1;

        for ( int i = 3; i <= num; i+=2 ) {
          if( isPrime(i,prime) ) {
            if( i > primeMax ) prime.add(i);
            result += 1;
          }
        }
        System.out.println(result);
      }
    }
  }

  public static boolean isPrime(int num,List<Integer> prime) {
    int k = Double.valueOf( Math.sqrt(num) ).intValue();
    for(Integer i: prime) {
      if ( num % i == 0 ) return false;
      if ( i > k ) return true;
    }
    return true;
  }
}


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

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    queue<char> Acard;
    queue<char> Bcard;
    queue<char> Ccard;

    rep(i, A.size()) Acard.push(A[i]);
    rep(i, B.size()) Bcard.push(B[i]);
    rep(i, C.size()) Ccard.push(C[i]);

    char turn = Acard.front();
    Acard.pop();

    char winner;
    bool end = false;
    while(end == false) {
        if(turn == 'a') {
            if(Acard.empty()) {
            winner = 'A';
            end = true;
            break;
            }
            turn = Acard.front();
            Acard.pop();
        }
        else if(turn == 'b') {
            if(Bcard.empty()) {
            winner = 'B';
            end = true;
            break;
            }
            turn = Bcard.front();
            Bcard.pop();
        }
        else if(turn == 'c') {
            if(Ccard.empty()) {
            winner = 'C';
            end = true;
            break;
            }
            turn = Ccard.front();
            Ccard.pop();
        }
    }

    cout << winner << endl;
}

Measured memory_bytes: 3668
N = int(input())
A = [int(input()) for _ in range(N)]

M = max(A)
M_index = A.index(M)
sub_M = 0
for i in range(N):
  if i != M_index: sub_M = max(sub_M, A[i])

for i in range(N):
  if i == M_index: print(sub_M)
  else: print(M)

Measured memory_bytes: 16908
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAXN 100010
#define INF 10000000000L
int n, length = 1;
long long a[MAXN];
long long dp[MAXN]; // dp[i]はi個の増加部分列が作れる時、その部分列の末尾の項の最小値を示す
int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = INF;
    }
    dp[0] = a[0];
    for (int i = 1; i < n; i++) {
        if (dp[length-1] < a[i]) {
            dp[length++] = a[i];
        } else {
            // a[i]がdp[i]のどこに収まるのかを二分探索する
            int h = length - 1, l = 0, m;
            while (h > l) {
                m = (h+l) / 2;
                if (a[i] <= dp[m]) h = m;
                else if (a[i] > dp[m]) l = m+1;
            }
            dp[l] = a[i];
        }
    }
    cout << length << endl;
    return 0;
}

Measured memory_bytes: 2728
#include <iostream>
#include <stdlib.h>
#include <math.h>

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

using namespace std;

int main() {
	int N, W;
	int w[100], v[100];
	cin >> N >> W;

	int vMax = 0;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
		vMax += v[i];
	}

	int *dp[100];//dp[x][y]は、品物xまでの中から選んで、価値の合計がyになるための最小の重さ
	for (int i = 0; i < N; i++) {
		dp[i] = new int[vMax + 1];
		dp[i][0] = 0;
	}

	for (int x = 0; x < N; x++) {
		int weight = w[x];
		int value = v[x];
		if (x == 0) {
			for (int i = 0; i <= vMax; i++) {
				dp[x][i] = W + 10000;
				if (i == 0) {
					dp[x][i] = 0;
				}
				if (i == value) {
					dp[x][i] = weight;
				}
			}
			continue;
		}
		for (int i = 0; i <= vMax; i++) {
			if (i - value < 0 || dp[x - 1][i - value] + weight > W) {
				dp[x][i] = dp[x - 1][i];
				continue;
			}
			dp[x][i] = min(dp[x - 1][i - value] + weight, dp[x - 1][i]);
		}
	}

	for (int i = vMax; i >= 0; i--) {
		if (dp[N - 1][i] <= W) {
			cout << i;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    while (cin >> s, s != "-") {
        int n; cin >> n;
        for (int i = 0; i < n; i++) {
            int start; cin >> start;
            s = s.substr(start) + s.substr(0, start);
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,M,i;
  cin>>N;
  M=N*2;
  string A,B,C;
  string a,b,c;
  cin>>A>>B>>C;
  for(i=0;i<N;i++){
    a=A.substr(i,1);
    b=B.substr(i,1);
    c=C.substr(i,1);
  if(a==b){
  M--;
  }
   if(a==c){
  M--;
  }
    if(c==b){
  M--;
  }
     if(a==b&&a==c){
  M++;
  }
  }
  cout<<M<<endl;
}

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


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

  ll N,W;
  cin >> N >> W;
  ll w[N],v[N];
  rep(i,N) cin >> w[i] >> v[i];
  //i個目までで価値がvの時の重さの最小値
  ll v_max=1e5+1;
  ll dp[N][v_max];
  rep(i,v_max) dp[0][i]=INT_MAX;
  dp[0][v[0]]=w[0];
  dp[0][0]=0;
  rep1(i,N-1){
    rep(j,v_max){
      if(j-v[i]>=0){
	dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
      }
      else{
	dp[i][j]=dp[i-1][j];
      }
    }
  }
  for(int i=v_max-1;i>=0;i--){
    //    cout << dp[N-1][i] << endl;
    if(dp[N-1][i]<=W){
      cout << i << endl;
      return 0;
    }
    if(i==0){
      cout << 0 << endl;
    }
  }
  
  return 0;
    

}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = inf;
    if(x <= y)ans = min(ans, y-x);
    if(-x <= y)ans = min(ans, y+x+1);
    if(x <= -y)ans = min(ans, -y-x+1);
    if(-x <= -y)ans = min(ans, -y+x+2);
    cout << ans << endl;
}   

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long double n, k, win = 0;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int x = i;
        long double chance = 1 / n;
        while(x < k){
            x <<= 1;
            chance /= (long double)2;
        }
        win += chance;
    }
    cout << setprecision(15) << win << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	cin>>n;
	map<int, int> mp;
	REP(i, n){
		cin>>a;
		++mp[a];
	}
	int ans=0;
	for(auto i=mp.begin(); i!=mp.end(); ++i){
		ans+= i->first<=i->second ? i->second-i->first : i->second;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x , y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(all(a));
  int ans = 0;
  for(int i = 0; i + 1 < n; i++) {
    for(int j = i + 1; j < n ; j++) {
      int l = lower_bound(all(a) , a[i] + a[j]) - a.begin();
      ans += l - j - 1;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define FOR(i, b, e) for ( int i = b; i <= e; i++ )
#define rep(i, n) for ( int i = 0; i < (int)n; i++)
#define MAX 10

int cnt, H, W, limit, maxw;
int T[MAX][MAX], K[MAX][MAX], C[MAX][MAX], X[MAX][MAX];
vector<pair<int, int> > v;

int MD(){
  int sum = 0;
  rep(i, H) rep(j, W){
    if ( C[i][j] && X[i][j] == 0 ) sum++;
  }
  return sum/(maxw*maxw);
}

bool dfs(int pos, int cost){
  bool solved = true;
  rep(i, H) rep(j, W) if ( C[i][j] && X[i][j] == 0 ) solved = false;
  if ( solved ) return true;
  if ( pos >= v.size() ) return false;
  if ( cost + MD() >= limit ) return false;

  for ( int i = v[pos].first+1; i < H; i++ ) rep(j, W){
      if ( C[i][j] && X[i][j] == 0 ) return false;
    }

  int tmp[MAX][MAX];

  if ( dfs(pos+1, cost) ) return true;

  rep(i, H) rep(j, W) tmp[i][j] = X[i][j];
  int pi = v[pos].first;
  int pj = v[pos].second;
  int w = T[pi][pj];
  FOR(y, pi-w+1, pi) FOR(x, pj-w+1, pj) X[y][x]++;

  if ( dfs(pos+1, cost+1) ) return true;
  rep(i, H) rep(j, W) X[i][j] = tmp[i][j];

  return false;
}

int idp(){
  if ( maxw == 0 ) return 0;
  for ( limit = MD(); limit < 100; limit++){
    if ( dfs(0, 0) ) return limit;
  }
}

void compute(){

  bool U[MAX][MAX], V[MAX][MAX];

  rep(i, H) rep(j, W) U[i][j] = true;
  rep(i, H) rep(j, W) V[i][j] = false;
  rep(i, H) rep(j, W) T[i][j] = K[i][j] = X[i][j] = 0;
  rep(i, H) T[i][0] = (C[i][0])?1:0;
  rep(j, W) T[0][j] = (C[0][j])?1:0;

  FOR(i, 1, H-1) FOR(j, 1, W-1){
    if ( C[i][j] ){
      T[i][j] = min(T[i-1][j-1], min(T[i-1][j], T[i][j-1])) +1;
    } else T[i][j] = 0;
  }

  rep(i, H) rep(j, W){
    int w = T[i][j];
    FOR(pi, i-(w-1), i) FOR(pj, j-(w-1), j) {
      if ( i == pi && j == pj ) continue;
      int l = max(i-pi, j-pj);
      if ( w-l >= T[pi][pj] ) U[pi][pj] = false;
    }
  }

  rep(i, H) rep(j, W){
    if ( U[i][j] && T[i][j] ){
      FOR(y, i-T[i][j]+1, i) FOR(x, j-T[i][j]+1, j) K[y][x]++;
    }
  }

  v.clear();
  rep(i, H) rep(j, W){
    if ( U[i][j] && T[i][j] ){
      bool f = false;
      FOR(y, i-T[i][j]+1, i) FOR(x, j-T[i][j]+1, j){
	if ( K[y][x] == 1 ) f = true;
      }
      if ( f ){
	FOR(y, i-T[i][j]+1, i) FOR(x, j-T[i][j]+1, j) X[y][x]++;
	cnt++;
	T[i][j] = 0;
      }
    }
  }
  maxw = 0;
  rep(i, H) rep(j, W){
    if ( T[i][j] > 0 && U[i][j]){
      maxw = max(maxw, T[i][j]);
      v.push_back(make_pair(i, j));
    }
  }

  reverse(v.begin(), v.end());
}

main(){
  while( cin >> W >> H ){
    if ( W == 0 && H == 0 ) break;
    rep(i, H) rep(j, W) cin >> C[i][j];
    cnt = 0;
    compute();
    cout << idp() + cnt << endl;
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(string S)
        {
            for (int i = 0; i < S.Length; ++i)
            {
                if (i % 2 == 0)
                {
                    if (S[i] == 'L') { return false; }
                }
                else
                {
                    if (S[i] == 'R') { return false; }
                }
            }
            return true;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Read()) ? "Yes" : "No");
        }
    }
}


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

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

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    ll a, b, c; cin >> a >> b >> c;
    long double sa = sqrtl(1.0 * a), sb = sqrtl(1.0 * b), sc = sqrtl(1.0 * c);
    if(sa + sb < sc && a * b * 4LL < (c - a - b) * (c - a - b)) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
///
// File:  2781.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 29 19:30:51 2017
//

#include <cstdint>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

uint32_t wfs(vector<string> map, int32_t y, int32_t x)
{
  vector<vector<int32_t>> visited(map.size(), vector<int32_t>(map[0].size(), -1));
  visited[y][x] = 0;
  queue<pair<int32_t, int32_t>> q;
  q.push({y, x});

  while (!q.empty()) {
    pair<int32_t, int32_t> p = q.front();
    q.pop();

    vector<pair<int32_t, int32_t>> ds = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    for (auto d : ds) {
      int32_t y2 = p.first + d.first;
      int32_t x2 = p.second + d.second;
      if (0 <= y2 && y2 < (int32_t)map.size() && 0 <= x2 && x2 < (int32_t)map[0].size() && (visited[y2][x2] == -1)) {
        if (map[y2][x2] == '#' || map[y2][x2] == '$') continue;
        visited[y2][x2] = visited[p.first][p.second] + 1;
        q.push({y2, x2});
      }
    }
  }

  for (uint32_t i = 0; i < map.size(); i++) {
    for (uint32_t j = 0; j < map[0].size(); j++) {
      if (map[i][j] == '%') {
        return visited[i][j];
      }
    }
  }
}

int32_t main()
{
  uint32_t H, W;
  cin >> H >> W;
  vector<string> map;
  for (uint32_t i = 0; i < H; i++) {
    string line;
    cin >> line;
    map.push_back(line);
  }

  uint32_t princess;
  uint32_t soldier = UINT32_MAX;
  for (uint32_t y = 0; y < H; y++) {
    for (uint32_t x = 0; x < W; x++) {
      if (map[y][x] == '@') {
        princess = wfs(map, y, x);
      } else if (map[y][x] == '$') {
        soldier = min(soldier, wfs(map, y, x));
      }
    }
  }

  if (princess < soldier) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3332
#include <stdio.h>
#include <string.h>
 
int main() {
	int k = 0;
	char s[110], t[110]={0}, u[] = "...";
	int len;
 
	scanf("%d%s", &k,s);
	//scanf("%s", s);
	len = strlen(s); 
		if (len > k) {
			for (int i = 0; i < k; i++)t[i] = s[i];
			strcat(t, u);
			printf("%s", t);
		}
	if (len <= k) printf("%s", s);
 
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}
#define NUM_MAX 100000
#define BUF_MAX (NUM_MAX+50)

int main(void) {
    static char str[NUM_MAX];
    get_str(str, BUF_MAX);
    int len = strlen(str);
    int i;
    static int map[2];
    for(i = 0; i < len; i++) {
        map[str[i]-'0']++;
    }
    printf("%d\n",len-abs(map[0]-map[1]));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
signed main(){
	string s;
	cin>>s;
	int tot=0;
	for(int i=s.size()-1;i>=0;--i){
		int a=58-signed(s[i]);
		int b=signed(s[i])-48;
		if(b<a)
			tot+=b;
		else if(b==a)
			if(i==0||s[i-1]<'5')
				tot+=b;
			else
				++b;
		if(b>a){
			tot+=a;
			int j=i-1;
			while(j>=0&&s[j]=='9'){
				s[j]='0';
				--j;
			}
			if(j>=0)
				++s[j];
			else{
				s='1'+s;
				++i;
			}
		}
	}
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 2308
import sys
input = sys.stdin.readline
 
def main():
    N, K = list(map(int, input().split()))
 
    ans = 0
    for i in range(1, N+1):
        t = 0
        while i < K:
            i *= 2
            t += 1
 
        ans += 0.5 ** t
 
    print(ans * (1 / N))
 
 
if __name__ == '__main__':
    main()

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

int  main()
{
	long n; cin >> n;
	long sum = 0;
	vector<long> v(n);
	long total = 0;
	rep(i, n)
	{
		cin >> v[i];
		total += v[i];
	}
	priority_queue<long, vector<long>, greater<long> > q;
	rep(i, n - 1)
	{
		sum += v[i];
		q.push(labs(sum - (total-sum)) );
		// cout << labs(sum - (total-sum)) << endl;
	}
	cout << q.top() << endl;
	return (0);
}


Measured memory_bytes: 3956
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    ll n,k;
    cin >> n >> k;
    n %= k;
    cout << min(n,k-n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r, c, n[100][100], wsum, hsum[100] = {}, asum = 0;
    cin >> r >> c;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin >> n[i][j];
        }
    }
    for(int i=0;i<r;i++){
        wsum = 0;
        for(int j=0;j<c;j++){
            cout << n[i][j] << " ";
            wsum += n[i][j];
            hsum[j] += n[i][j];
        }
        cout << wsum << endl;
        asum += wsum;
    }
    for(int i=0;i<c;i++){
        cout << hsum[i] << " ";
    }
    cout << asum << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll MOD = (ll)1e9 + 7;
const ll mxN = 200200;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout.precision(20);
	cout << fixed;
	string a,b;	cin>>a>>b;
	puts(b.substr(0,a.length())==a ? "Yes":"No");	

}


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

#define MOD 1000000007
int main() {
    int n, i, t, s = 1;
    cin >> n;
    vector<int> a(n,0);
    for (i = n-1; i >= 0; i-=2) {
        a[i] = 2;
        if (i != 0) s = (s*2)%MOD;
    }
    if (n%2 == 1) a[0] = 1;
    for (i = 0; i < n; i++) {
        cin >> t;
        a[t]--;
        if (a[t] < 0) {
            cout << 0;
            return 0;
        }
    }

    cout << s;

    return 0;
}

Measured memory_bytes: 764