akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }



int main() {  
   int n; cin >> n;
   vector<ll> A(n+1); rep(i, n+1) cin >> A[i];

   ll min_max[100100][2]; //0:min, 1:max
   min_max[n][0] = min_max[n][1] = A[n];
   for(int i=n-1; i>=0; i--){
       min_max[i][0] = min_max[i+1][0]/2 + min_max[i+1][0]%2 + A[i];
       min_max[i][1] = min_max[i+1][1] + A[i];
   }/*
   rep(i, n+1){
       cout << min_max[i][0] << " " << min_max[i][1] << ln;
   }*/
   if(min_max[0][0] > 1 || min_max[0][1] < 1) cout << -1 << ln;
   else{
        ll cnt[100100];cnt[0] = 1; 
        for(int i=1; i<=n; i++){
            cnt[i] = min((cnt[i-1]-A[i-1])*2, min_max[i][1]);
        }
        
        ll sum = 0;
        rep(i, n+1) sum += cnt[i]; 
        cout << sum << ln;
    }
}

Measured memory_bytes: 6436
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	int ans = 10000, t = (s[0] - '0') * 10 + (s[1] - '0');
	for (int i = 2; i < s.length(); i++) {
		t = (t % 100) * 10 + (s[i] - '0');
		ans = min(ans, abs(753 - t));
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import numpy as np
def solve(n, k, a, f):
    a = sorted(a)
    f = sorted(f)[::-1]
    a = np.asarray(a, dtype=int)
    f = np.asarray(f, dtype=int)
    total = np.sum(a)
    l = -1
    r = np.max(a*f)
    while r - l > 1:
        th = (l + r) // 2
        cost = total - np.minimum(a, th // f).sum()
        if cost <= k:
            r = th
        else:
            l = th
    return r

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
print(solve(n, k, a, f))

Measured memory_bytes: 43600
/**
 *    author:  math2do
 *    created: 18.01.2020 13:20:32
**/

#include <bits/stdc++.h>

using namespace std;

const long long pinf = (1ULL << 61) - 1;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("D_knapsack_II.in", "rt", stdin);
  #endif
  int n, W;
  cin >> n >> W;
  vector <int> w(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  int sum = accumulate(v.begin(), v.end(), 0);
  vector <long long> dp(sum + 1, pinf);

  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = sum - v[i]; j >= 0; j--) {
      dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    } 
  }

  int ans = 0;
  for (int i = 0; i <= sum; i++) {
    if (dp[i] <= W) {
      ans = max(ans, i);
    } 
  }                      

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
public class Main {
    public static void main(String []args){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task=new Task();
        task.solve(1,in,out);
        out.close();
    }
    static class Task{
        int n,h;
        HashMap<Integer,Boolean> hashMap = new HashMap<>();
        public void solve(int testNumber,InputReader in,PrintWriter out){
            h=0;
            n=in.nextInt();
            for(int i=0;i<n;i++){
                int a;
                a=in.nextInt();
                if(hashMap.containsKey(a)){
                    h--;
                    hashMap.remove(a);
                } else {
                    h++;
                    hashMap.put(a,false);
                }
            }
            out.println(h);
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public long nextLong(){return Long.parseLong(next());}
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int ans,n;

void func(ll x,int counter){
    if(x>n)return;
    if(counter==7)ans++;
    func(x*10+3,counter|4);
    func(x*10+5,counter|2);
    func(x*10+7,counter|1);
}

vint allcount(1000000);

int main(){
    int n;
    string s;
    cin>>n>>s;
    int num=0;
    rep(i,n){
        if(s[i]=='.'){
            num++;
        }
        allcount[i]=num;
    }
    int minnum=allcount[n-1];
    rep(i,n){
        int num=i+1-allcount[i]+(allcount[n-1]-allcount[i]);
        chmin(minnum,num);
    }
    cout<<minnum<<endl;
}

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

int main(){
  int dp[1401][1401]={0},min,max,a,w,h;
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>a;
      if(a==0)dp[i][j]=-1;
    }
  }
  max=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(dp[i][j]==-1){
	min=dp[i-1][j];
	if(min>dp[i-1][j-1])min=dp[i-1][j-1];
	
	if(min>dp[i][j-1])min=dp[i][j-1];
	dp[i][j]=min+1;
	if(dp[i][j]>max)max=dp[i][j];
      }
    }
  }
  cout<<max*max<<endl;
  return 0;
}

Measured memory_bytes: 10780
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int n, m;
int path[51];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		path[a]++, path[b]++;
	}

	for (int i = 0; i < n; i++) {
		cout << path[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// finish date: 2019/1/26

#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;


int main() {
    int N, K;
    cin >> N >> K;
    vi H(N);
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end());
    reverse(H.begin(), H.end());
    ll total = 0;
    FOR(i, K, N) {
        total += H[i];
    }
    cout << total << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define unmap unordered_map
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define debug(a) cout << a << endl
using namespace std;

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

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int bignumlen = 2200;
const int Blen = 8;
const ll base = 100000000;
const int baseHash = 31;
const ld PI = acos(-1);

//Remember limit for IT, etc...
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
//If TLE let's use int instead of ll

ll n, m;

void solveProblem() {
    cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> n >> m;
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m =sc.nextInt();
		if(n==m) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
// D - Wizard in Maze
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define irp(i,s,e) for(int i=(int)(s);i>(int)(e);--i)
using PR = pair<int,int>; // <h,w>
using T3 = tuple<int,int,int>; // <h,w,gid>

int main(){
	int H,W; cin>>H>>W;
	int C[2],D[2]; cin>>C[0]>>C[1]>>D[0]>>D[1];
	C[0]--, C[1]--, D[0]--, D[1]--;
	string S[H]; rp(i,0,H) cin>>S[i];

	PR dhw[] = { //<h,w>
		      {1,0},
		{0,-1},     {0,1},
		      {-1,0},
		{2,-2},{2,-1},{2,0},{2,1},{2,2},
		{1,-2},{1,-1},      {1,1},{1,2},
		{0,-2},                   {0,2},
		{-1,-2},{-1,-1},      {-1,1},{-1,2},
		{-2,-2},{-2,-1},{-2,0},{-2,1},{-2,2}
	};

	vvi vis(H, vi(W, -1));
	deque<T3> dq;
	dq.push_back({C[0], C[1], 0});
	while(dq.size()){
		int h, w, gid; tie(h, w, gid) = dq.front(); dq.pop_front();
		if(0 <= vis[h][w] and vis[h][w] <= gid) continue;
		// if(vis[h][w] >= 0) continue;
		// if(vis[h][w] <= gid) continue;
		if(S[h][w] == '#') continue;
		vis[h][w] = gid;
		rp(i, 0, 4){
			int nx_h = h + dhw[i].first;
			int nx_w = w + dhw[i].second;
			if(nx_h < 0 || H <= nx_h) continue;
			if(nx_w < 0 || W <= nx_w) continue;
			dq.push_front({nx_h, nx_w, gid});
		}

		rp(i, 4, 24){
			int nx_h = h + dhw[i].first;
			int nx_w = w + dhw[i].second;
			if(nx_h < 0 || H <= nx_h) continue;
			if(nx_w < 0 || W <= nx_w) continue;
			dq.push_back({nx_h, nx_w, gid+1});
		}

	}

	// rp(h,0,H){
	// 	rp(w,0,W){
	// 		if(vis[h][w] < 0) cout<<"X ";
	// 		else cout<<""<<vis[h][w]<<" ";
	// 	}
	// 	puts("");
	// }
	// puts("---");

	cout<< vis[D[0]][D[1]] <<endl;
}


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

int main(void)
{
  int a[10000];

  int k=0;
  do{
    cin >> a[++k];
  } while(a[k] != 0);

  k=0;
  while(a[++k] != 0){
    cout << "Case " << k << ": " << a[k] << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>

int main(void) {
  int a,b,c;
  scanf("%d %d %d", &a,&b,&c);
  if((a==5 || a==7) && (b==5 || b==7) && (c==5 || c==7) && (a+b+c==17)) {
    printf("YES\n");
  }
  else {
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		long k = scan.nextLong();
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}
		boolean f = true;
		char result = '1';
		for (int i = 0; i < k; i++) {
			if (c[i] != '1') {
				f = false;
				result = c[i];
				break;
			}
		}
		if (f) {
			System.out.println(1);
		} else {
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if ((int)s.size()%2 != 0){
    cout << "No";  
  }
  else {
    for (int i = 0; i < s.size(); i+=2)
      if (s[i] != 'h' || s[i+1] != 'i'){
        cout << "No";
        return 0;
      }
     cout << "Yes";
  }
}


Measured memory_bytes: 256
n=int(input())
h=[int(i) for i in input().split()]
dp=[0,abs(h[1]-h[0])]

for ind in range(2,len(h)):
    a=abs(h[ind-1]-h[ind])
    b=abs(h[ind-2]-h[ind])
    if(a+dp[ind-1]>b+dp[ind-2]):
        dp.append(b+dp[ind-2])
    else:
        dp.append(a+dp[ind-1])
print(dp[len(dp)-1])

Measured memory_bytes: 13980
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import javax.sql.rowset.FilteredRowSet;
import javax.swing.BorderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.stream.events.EndDocument;
import java.math.BigInteger;
import java.time.chrono.MinguoChronology;
import java.util.Scanner;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {
      String W = in.next();
      int cnt = 0;
      while (true) {
        String T = in.next();
        if (T.equals("END_OF_TEXT")) {
          break;
        }
        
        if (T.toLowerCase().equals(W)){
          cnt++;
        }
      }
      
      out.println(cnt);
      
//      End solve()
    }
    
//  End solution
  } 
  

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    
    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }
   
    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }
    
    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken()); 
    }
    
    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }
    
    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }
    
  }
  
}

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

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

    int cnt[100010] = {};

    vector<int> c;
    c.push_back(1);
    for (int i = 6; i < 100010; i *= 6) c.push_back(i);
    for (int i = 9; i < 100010; i *= 9) c.push_back(i);
    sort(c.begin(), c.end());

    for (int i = 0; i < c.size(); i++) {
        for(int j = 0; j <= n; j++) {
            if (j + c[i] >= 100010) continue;
            if (!i) cnt[j + c[i]] = cnt[j] + 1;
            else cnt[j + c[i]] = min(cnt[j] + 1, cnt[j + c[i]]);
        }
    }
    cout << cnt[n] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int A, B, K;
  cin >> A >> B >> K;
  int k = 0;
  int I = A > B ? B : A;
  for (size_t i = I; ; i--) {
    if (A % i == 0 && B % i == 0) {
      k++;
      if (k == K) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

int main(){
  string S, T;
  cin >> S;
  cin >> T;
  
  int N = S.length();
  int M = T.length();
  
  int k = N - M + 1;
  int l = 0;
  
  while(k >= 0 ){
    for(int i = k; i < k + M; i++){
      if(S[i] != '?' && S[i] != T[i - k]){
        k -= 1;
        break;
      }
      else if(i == k + M  -1){
        for(int j = 0; j < N; j++){
          if(S[j] == '?' && (j < k || k + M <= j)){
            S[j] = 'a';
          }
          else if(S[j] == '?' && (k <= j && j < k + M)){
            S[j] = T[j - k];
          }
        }
        k = -10;
      }
    }
  }
  
  if(k != -10){
    cout << "UNRESTORABLE" << endl;
  }
  else{
    cout << S << endl;
  }
  return 0;
}
        
      

Measured memory_bytes: 256
N = int(input())
A = list(int(a) for a in input().split())
A = [0] + A + [0]

dist = [0]
for i in range(1, N+2):
    dist.append(abs(A[i]-A[i-1]))

dist_cum = [0] * (N+2)
for i in range(N+1):
    dist_cum[i+1] = dist_cum[i] + dist[i+1]

for i in range(1, N+1):
    if A[i-1] < A[i] and A[i] < A[i+1]:
        print(dist_cum[-1])
    elif A[i-1] > A[i] and A[i] > A[i+1]:
        print(dist_cum[-1])
    else:
        tmp = dist_cum[i-1]
        tmp += dist_cum[-1] - dist_cum[i+1]
        tmp += abs(A[i+1] - A[i-1])
        print(tmp)


Measured memory_bytes: 20768
S = [0] + [1 if a == "A" else 2 for a in input()]
T = [0] + [1 if a == "A" else 2 for a in input()]
for i in range(1, len(S)):
    S[i] += S[i-1]
for i in range(1, len(T)):
    T[i] += T[i-1]
for _ in range(int(input())):
    a, b, c, d = map(int, input().split())
    if (S[b] - S[a-1] - T[d] + T[c-1]) % 3 == 0:
        print("YES")
    else:
        print("NO")


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

using namespace std;

const int N = 1e5;
int dp[N + 10];
int h[N + 10];

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

    for(int i = 2; i <= n + 1; i++)
            cin >> h[i];

    for(int i = 3; i <= n + 1; i++)
    {
        if(i == 3) dp[i] = abs(h[i] - h[i - 1]);
        else dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2], abs(h[i] - h[i - 1]) + dp[i - 1]);
    }

    cout << dp[n + 1];
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a[111];
int main()
{
	int n;
	long long a,b;
	a=1,b=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		a*=3;
		int x;
		scanf("%d",&x);
		if(!(x&1))b<<=1;
	}
	printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N, a[101]={0}, i, j, k, key;
    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", &a[i]);
    }
    for(i=1; i<N+1; i++){
        printf("%d", a[0]);
        for(k=1; k<N; k++){
            printf(" %d", a[k]);
        }
        printf("\n");
        key=a[i];
        for(j=i-1; j>=0; j--){
            if(a[j]>key){
                a[j+1]=a[j];
            } else {
                a[j+1]=key;
                break;
            }
            if(j==0){
                a[0]=key;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 604
N,M=map(int,input().split())
import math
if abs(N-M)>=2:
    print(0)
elif abs(N-M)==1:
    ans=math.factorial(N)*math.factorial(M)
    print(ans%(10**9+7))
elif abs(N-M)==0:
    ans=2*math.factorial(N)*math.factorial(M)
    print((ans%(10**9+7)))


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

int main() {
  int N, i;
  cin>>N;
  i=N/1000;
  if(N-1000*i==0){
    cout<<0<<endl;
  }
  else{
  cout<<1000*(i+1)-N<<endl;
  }
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;int main(){vector<int>a(4);for(int i=0;i<4;i++)cin>>a.at(i);sort(a.begin(),a.end());if(a.at(0)==1&&a.at(1)==4&&a.at(2)==7&&a.at(3)==9)cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0;}


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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    transform (a.begin(),a.end(),a.begin(), ::toupper);
    transform (b.begin(),b.end(),b.begin(), ::toupper);
    transform (c.begin(),c.end(),c.begin(), ::toupper);
    cout << a[0] << b[0] << c[0] << endl;

    return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int s, k;
  s=S.size();
  k=0;
  for (int i=0; i<s; i++) {
    if (S.at(i)==T.at(i)) {
      k=k+1;
    }
  }
  if (k==s) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.InputStreamReader;

//PCK/Prelim:   0404:   Shiba Inu
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0404
class Main {

	public static void main(String[] args) throws Exception {
		int result = 0;

		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String[] numDog = reader.readLine().split(" ");

			for(int i=0;i<numDog.length;i++) {
				result += Integer.parseInt(numDog[i]);
			}

			System.out.println(result);

		}
	}

}


Measured memory_bytes: 24392
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_b"
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func iabs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func solve(n, k int, h []int) int {
	t := make([]int, n+k+1, n+k+1)
	for i := range t {
		t[i] = math.MaxInt64
	}
	t[0] = 0
	for i := 0; i < n; i++ {
		for j := 0; j <= k; j++ {
			if v := t[i] + iabs(h[i+j]-h[i]); v < t[i+j] {
				t[i+j] = v
			}
		}
	}
	return t[n-1]
}

func main() {
	scan := newScanner(os.Stdin)
	n, k := scan.Int(), scan.Int()
	h := make([]int, n+k+1, n+k+1)
	for i := 0; i < n; i++ {
		h[i] = scan.Int()
	}
	a := solve(n, k, h)
	fmt.Println(a)
}


Measured memory_bytes: 3940
ss, ts = input(), input()

lenS, lenT = len(ss), len(ts)

dp = [[0]*(lenT+1) for _ in range(lenS+1)]
dp[0][0] = 0
for iS, s in enumerate(ss, 1):
    for jT, t in enumerate(ts, 1):
        if s == t:
            dp[iS][jT] = dp[iS-1][jT-1] + 1
        else:
            dp[iS][jT] = max(dp[iS-1][jT], dp[iS][jT-1])

ans = ''
iS, jT = lenS, lenT
while iS*jT:
    if ss[iS-1] == ts[jT-1]:
        ans += ss[iS-1]
        iS, jT = iS-1, jT-1
    elif dp[iS-1][jT] >= dp[iS][jT-1]:
        iS -= 1
    else:
        jT -= 1

print(ans[::-1])


Measured memory_bytes: 112476
n, m = map(int, input().split())
g_o = [[] for x in range(n)]
g_i = [0] * n
for _ in range(m):
    p, c = map(int, input().split())
    g_o[p - 1].append(c - 1)
    g_i[c - 1] += 1
get_root = lambda g: [e for e in range(n) if g[e] == 0]
sor = get_root(g_i)
for node in sor:
    for i in g_o[node]:
        g_i[i] -= 1
        if g_i[i] == 0:
            sor.append(i)
dp = [0] * n
for node in sor:
    for c in g_o[node]:
        if dp[c] < dp[node] + 1:
            dp[c] = dp[node] + 1
print(max(dp))

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

using namespace std;

using ll = long long;

int main() {
    ll N;
    std::string S;
    cin >> N >> S;

    std::vector<ll> dp(N);

    dp[0] = std::count(S.cbegin() + 1, S.cend(), 'W');

    for (ll i = 1; i < N; ++i) {
        dp[i] = dp[i - 1];
        if (S[i] == 'W') { --dp[i]; }
        if (S[i - 1] == 'E') { ++dp[i]; }
    }

    cout << N - 1 - *std::max_element(dp.cbegin(), dp.cend()) << endl;

    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int h,w; cin >> h >> w;

  vector<string> g(h);
  rep(i,h) cin >> g[i];

  vector<bool> hh(h,false), ww(w,false);

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(g[i][j] == '#'){
        hh[i] = true;
        ww[j] = true;
      }
    }
  }

  for(int i = 0; i < h; i++){
    if(!hh[i]) continue;
    for(int j = 0; j < w; j++){
      if(!ww[j]) continue;
      cout << g[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	string s;
	cin>>k>>s;
	int a[2]={0},b[2]={0};
	for(int i=0;i<k;i++)
	{
		if(s[i]=='W')
			a[0]++;
		else
			a[1]++;
	}
	int u=300000005;
	for(int i=0;i<k;i++)
	{
		if(s[i]=='W')
			a[0]--;
		else
			a[1]--;
		u=min(u,a[1]+b[0]);
		if(s[i]=='W')
			b[0]++;
		else
			b[1]++;
	}
	cout<<u<<endl;
} 

Measured memory_bytes: 900
N = input()

a = list(map(int, input().split()))

#各要素を2乗する関数
def calc_sq(n):
	return n ** 2

a2 = list(map(calc_sq, a))
"""
map関数の戻り値はリストではなく、シーケンスのmapオブジェクト
なので、インデックスでアクセスしたり、ループで回したりできるが、
appendなどのlistメソッドは使用できない。
また、print関数で出力しても、カンマ区切りの要素では表示されず、
オブジェクトの型名が表示されるだけ。

だが、map関数の戻り値はシーケンスなので、
list関数を使ってlist型に変換することができる！！
"""

sum_a = sum(a)

sum_a2 = sum(a2)

cost = []
for x in range(-200, 200):
	cost.append(int(N) * x**2 - 2 * x * int(sum_a) + int(sum_a2))

print(min(cost))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	BufferSize = 1000
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func square(x int) int {
	return x * x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	x := make([]int, n)
	y := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = scanInt(sc)
		y[i] = scanInt(sc)
	}

	// nC2
	tmp := n * (n - 1) / 2
	distance := make([]float64, tmp)

	// i-j間の距離
	tmp = 0
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			distance[tmp] = math.Sqrt(float64(square(x[i]-x[j]) + square(y[i]-y[j])))
			tmp++
		}
	}

	sum := 0.0
	for i := 0; i < len(distance); i++ {
		sum += distance[i]
	}
	average := sum / float64(len(distance))

	fmt.Println(average * (float64)(n-1))
}


Measured memory_bytes: 640
import Data.List

main = do
  li <- getLine
  let [x,k,d] = map read $ words li
  print $ compute x k d

compute :: Int -> Int -> Int -> Int
compute x k d
  | k <= k0 = x1 - k * d
  | even k1 = r0
  | True    = d - r0
  where
    x1 = abs x
    (k0,r0) = divMod x1 d
    k1 = k - k0

{-
k0回移動して残りr0のところまで行ける。k= k0ならそこまでしかいけない。
残りk1回の移動が偶数ならr0、奇数なら反対側のr1で終わる。
-}

Measured memory_bytes: 3912
K = int(input())
N = 10

S = [[] for _ in range(N + 1)]
for i in range(1, 10):
    S[1].append(i)

if K < 10:
    print(S[1][K - 1])
    exit()

cnt = 9
for i in range(2, N + 1):
    for j in S[i - 1]:
        k = j % 10
        if 1 <= k <= 8:
            T = [-1, 0, 1]
        elif k == 0:
            T = [0, 1]
        else:
            T = [-1, 0]
        for t in T:
            S[i].append(j * 10 + (k + t))
            cnt += 1
            if cnt == K:
                print(S[i][-1])
                exit()


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=true;
    ll ans=0,sum=0;

    string s;
    cin>>s;
    int n=s.length();

    string s1=s.substr(0,(n-1)/2);
    string s2=s.substr((n+1)/2);

    int l=0,r=s1.length()-1;
    while(l<r){
        if(s1[l]!=s1[r]){flag=false;break;}
        ++l;
        --r;
    }

    if(s1!=s2)flag=false;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<s1<<" "<<s2<<endl;
    
    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main() {
	int n, ans = 0;
	scanf("%d", &n);
	if (n > 9)n = 9;
	ans += n;
	int k = n * (n - 1);
	if(k)ans += (k << 1) + k;
	k = 0;
	for (int i = 1; i < n-1; ++i) {
		for (int j = i + 1; j < n; ++j) 
			k += n - j;
	}
	if (k)ans += (k << 2) + (k<<1);
	printf("%d", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (S[0] == S[N-1]) {
    if (N % 2 == 0) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  } else {
    if (N % 2 == 0) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3748
from collections import Counter
n = int(input())
S = input()
Co = Counter(S).values()
ans = 1
mod = 10**9+7
for i in Co:
    #print(i)
    if i == 1:
        ans = (ans*2) % mod
    else:
        ans = (ans*(i+1)) % mod
print(ans-1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const int MAX_N = 2e5 + 5;
lint l[MAX_N], r[MAX_N], sl[MAX_N], sr[MAX_N];


int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    lint L, N; cin >> L >> N;
    for(int i=1;i<=N;i++) cin >> l[i];

    for(int i=1;i<=N;i++) r[i] = L - l[N-i+1];

    for(int i=0;i<N;i++) sl[i+1] = sl[i] + l[i+1], sr[i+1] = sr[i] + r[i+1];

    lint ans = -1;
    for(int i=1;i<=N;i++){
        lint cur;
        // 反時計回り
        cur = 2 * (sl[i+(N-i)/2]-sl[i-1]+sr[(N-i+1)/2]);
        if((N-i)%2) cur -= r[(N-i+1)/2];
        else cur -= l[i+(N-i)/2];
        ans = max(ans, cur);

        // 時計回り
        cur = 2 * (sr[i+(N-i)/2]-sr[i-1]+sl[(N-i+1)/2]);
        if((N-i)%2) cur -= l[(N-i+1)/2];
        else cur -= r[i+(N-i)/2];
        ans = max(ans, cur);
    }

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

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define maxn 3005

using namespace std;
char s[maxn],t[maxn],ans[maxn];
int n,m,cc,dp[maxn][maxn],px[maxn][maxn],py[maxn][maxn];

void dfs(int x,int y){
    if (x==0&&y==0) return;
    int xx=px[x][y],yy=py[x][y];
    if (xx<x&&yy<y) ans[++cc]=s[xx];
    dfs(xx,yy);
}

int main(){
    cin >> s >> t;
    n=strlen(s); m=strlen(t);
    for (int i=0;i<=n;i++)
    for (int j=0;j<=m;j++){
        if (!i&&!j) continue;
        dp[i][j]=-1;
        if (i>0&&dp[i][j]<dp[i-1][j]){
            px[i][j]=i-1;
            py[i][j]=j;
            dp[i][j]=dp[i-1][j];
        }
        if (j>0&&dp[i][j]<dp[i][j-1]){
            px[i][j]=i;
            py[i][j]=j-1;
            dp[i][j]=dp[i][j-1];
        }
        if (i>0&&j>0&&dp[i][j]<dp[i-1][j-1]+(s[i-1]==t[j-1])){
            px[i][j]=i-1;
            py[i][j]=j-1;
            dp[i][j]=dp[i-1][j-1]+(s[i-1]==t[j-1]);
        }
    }
    dfs(n,m);
    for (int i=cc;i;i--) printf("%c",ans[i]); puts("");
    return 0;
}


Measured memory_bytes: 105984
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define L first
#define R second

const int maxn=1e5+10;

int n,m;
vector <int> adj[maxn], ans;
bool mark[maxn];
int h[maxn], up[maxn];

void input()
{
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int fi,se;
        cin>>fi>>se;
        adj[fi].pb(se);
        adj[se].pb(fi);
    }
}

void dfs(int x, int par)
{
    int ch=0;
    bool flag=false;
    up[x]=h[x];
    mark[x]++;
    for(int i=0; i<adj[x].size(); i++)
    {
        int child=adj[x][i];
        if(!mark[child])
        {
            ch++;
            h[child]=h[x]+1;
            dfs(child, x);
            up[x]=min(up[x],up[child]);
            if(up[child]>=h[x])
                flag++;
        }
        else if(child!=par)
            up[x]=min(up[x],h[child]);
    }
    if(x==0 && ch>1)
        ans.pb(0);
    if(flag && x!=0)
        ans.pb(x);

}

void debug()
{
    cerr<<"debug starts"<<endl;
    for(int i=0; i<n; i++)
        cerr<<up[i]<<" ";
    cerr<<endl;
    cerr<<" debug ends"<<endl;
}

void output()
{
    sort(ans.begin(), ans.end());
    for(int i=0; i<ans.size(); i++)
        cout<<ans[i]<<endl;

}

int main()
{
    input();
    dfs(0,0);
    //debug();
    output();
    return 0;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
    using namespace std;
    # define LL long long
    # define int long long
    #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    # define mo 998244353
    # define pi acos(-1)
    //vector<pair<int,int>> v;
    //int x0=INT_MAX,y0=INT_MAX;
    /*int crossprod(pair<int,int> a,pair<int,int> b,pair<int,int> c)
    {
        int x1 = a.first-b.first;
        int x2 = a.first-c.first;
        int y1 = a.second-b.second;
        int y2 = a.second-c.second;
        return x1*y2 - y1*x2;
    }
    int direction(pair<int,int> a,pair<int,int> b,pair<int,int> c) {
       int val = (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
       if (val == 0)
          return 0;     //colinear
       else if(val < 0)
          return 2;    //anti-clockwise direction
          return 1;    //clockwise direction
    }*/

signed main()
{

   gok

 string s;
 cin>>s;
 if(s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes";
 else
    cout<<"No";


























	return 0;
}


Measured memory_bytes: 256
#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)

int A,B,C,ans = 0;

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

	cin >> A >> B >> C;

	ans = B + min(A+B,C);
	
	if(C > A + B){
		ans++;
	}

	cout << ans << endl;

}

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

#define DEBUG(x) cerr << #x << " = " << x << endl

struct UnionFind {
    vector<int> data;
    UnionFind(int n) : data(n, -1) { }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            data[x] += data[y], data[y] = x;
        }
    }

    int count_union() {
        int s = 0;
        for(int i = 0; i < (int)data.size(); i++) s += data[i] < 0;
        return s;
    }
};

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c) : from(f), to(t), cost(c) { }
    bool operator <(const Edge& e) const {
        return cost < e.cost;
    }
};


vector<Edge> read_edges(int M) {
    vector<Edge> res;
    for(int i = 0; i < M; i++) {
        int f, t, c;
        cin >> f >> t >> c;
        f--, t--;
        res.push_back(Edge(f, t, c));
    }
    return res;
}

vector<vector<int> > read_deadlines(int N) {
    map<int, vector<int> > H;
    for(int i = 0; i < N; i++) {
        int h; cin >> h;
        H[h].push_back(i);
    }
    vector<vector<int> > res;
    for(map<int, vector<int> >::const_iterator it = H.begin(); it != H.end(); ++it) {
        res.push_back(it->second);
    }
    return res;
}

int calc_deadline(int N, vector<vector<int> >& H, vector<Edge>& edges) {
    int r = H.size();
    UnionFind uf(N);
    set<int> island;
    for(int i = (int)H.size() - 1; i >= 0; i--) {
        for(int j = 0; j < H[i].size(); j++) {
            island.insert(H[i][j]);
        }

        for(int j = 0; j < (int)edges.size(); j++) {
            if(island.count(edges[j].from) && island.count(edges[j].to)) {
                uf.merge(edges[j].from, edges[j].to);
            }
        }

        if(uf.count_union() != N - (int)island.size() + 1) {
            r = i;
        }
    }
    return r;
}

int msp(int N, vector<vector<int> >& H, vector<Edge>& edges, int deadline) {
    int res = 0;
    UnionFind uf(N);
    set<int> island;
    for(int i = H.size() - 1; i >= deadline; i--) {
        for(int j = 0; j < H[i].size(); j++) {
            island.insert(H[i][j]);
        }
    }
    for(int i = deadline - 1; i >= 0; i--) {
        for(int j = 0; j < H[i].size(); j++) {
            island.insert(H[i][j]);
        }

        for(int j = 0; j < (int)edges.size(); j++) {
            if(uf.same(edges[j].from, edges[j].to) == false && island.count(edges[j].from) && island.count(edges[j].to)) {
                uf.merge(edges[j].from, edges[j].to);
                res += edges[j].cost;
            }
        }
    }
    return res;
}

int main() {
    for(int N, M; cin >> N >> M, N || M; ) {
        vector<vector<int> > H = read_deadlines(N);
        vector<Edge> edges = read_edges(M);
        sort(edges.begin(), edges.end());
        int dl = calc_deadline(N, H, edges);
        cout << msp(N, H, edges, dl) << endl;
    }
}

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

using namespace std;

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

Node *root, *NIL;

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

  z = (Node *)malloc(sizeof(Node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

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

  z->parent = y;

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

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

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

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

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if (com[0] == 'f') {
        scanf("%d", &x);
        Node *t = find(root, x);
        if (t != NIL) printf("yes\n");
        else printf("no\n");
    }
    else if  (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } 
    else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 22044
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){return Integer.parseInt(s.next());}

	static int n=gInt(),a=gInt(),
			v[]=IntStream.range(0,n).map(i->gInt()-a).sorted().toArray();

	static long[][]memo=new long[n][2501];
	static {
		for(int i=0;i<n;++i)
			Arrays.fill(memo[i],-1);
	}
	static long solve(int i,int j){
		if(j>0)
			return 0;
		if(i==n) {
			return j==0?1:0;
		}
		if(memo[i][-j]!=-1) {
			return memo[i][-j];
		}
		memo[i][-j]=0;
		memo[i][-j]+=solve(i+1,j+v[i]);
		memo[i][-j]+=solve(i+1,j);
		return memo[i][-j];
	}
	public static void main(String[]$){
//		System.out.println(Arrays.toString(v));
		solve(0,0);
//		for(int i=0;i<n;++i)System.out.println(Arrays.toString(memo[i]));
		System.out.println(memo[0][0]-1);
	}
}

Measured memory_bytes: 28756
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int a, b; cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int N,i,A;
	scanf("%d",&N);
	int S[N];
	for(i=0;i<N;i++){
		S[i]=0;
	}
	for(i=1;i<N;i++){
		scanf("%d",&A);
		S[A-1]=S[A-1]+1;
	}
	for(i=0;i<N;i++){
	printf("%d\n",S[i]);
	}
	return 0;
}


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
// ll mod_pow(ll x, ll n, ll mod){//x^n % mod
//     if (n == 0)
//         return 1;
//     ll res = mod_pow(x * x % mod, n / 2, mod);
//     if (n & 1)
//         res = res * x % mod;
//     return res;
// }
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N;
    cin >> S;
    int res = 0;
    int black = 0;
    int white = 0;
    for (auto c: S) {
        if (c == '.') white++;
        if (c == '#') black++;
    }
    int s_white = white;
    int s_black = black;
    res = min(white, black);
    black = 0; white = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') white++;
        if (S[i] == '#') black++;
        res = min(res, black + s_white - white);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 720
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;



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 fact(int i) {       
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      
    return a / gcd(a, b) * b ;
}
int keta(ll n) {       
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {   
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

#pragma endregion

signed main() {
    int n,m;cin >> n >> m;
    vector<string> v(n);
    rep(i, n)cin >> v[i];
    vector<string> vec(m);
    rep(i, m) cin >> vec[i];
    bool ok = false;
    rep(i, n-m+1) {
        rep(j,n-m+1) {
            ok=false;
            rep(k,m) {
                if(v[i+k].substr(j,m)!=vec[k]) {
                    ok=true;
                    break;
                }
            }
            if(ok)continue;
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 3600