akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
#define A first
#define B second
#define pb push_back
void chmax(int &a, int b) { a = (a > b ? a : b); }
void chmin(int &a, int b) { a = (a < b ? a : b); }

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++) cin >> A[i];
    int ans = A[0];
    for(int i = 0;i < N;i++) ans = __gcd(ans, A[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int,int>>v(n);
  rep(i,n)cin >> v[i].second >> v[i].first;
  sort(v.begin(),v.end());
  int now = 0;
  bool ans = true;
  rep(i,n){
    now += v[i].second;
    if(now > v[i].first)ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
} 

Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int id,left,right;
      String[] words;
      Tree tree = new Tree(n);

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        id = Integer.parseInt(words[k++]);
        left  = Integer.parseInt(words[k++]);
        right = Integer.parseInt(words[k++]);

        tree.nodeInit(id,left,right);
      }

      tree.dispRoundPath(tree.getTreeRoot());
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final int NIL = -1;
  BTreeNode[] node;
  StringBuilder buf;

  public Tree(int size) {
    node = new BTreeNode[size];
    for (int i=0; i < size; i++) {
      node[i] = new BTreeNode();
    }
    buf = new StringBuilder(size*3);
  }

  void nodeInit(int id, int left, int right) {
    node[id].id = id;
    node[id].left = left;
    node[id].right = right;
    setParent(id);
  }
  int getTreeRoot() {
    int root=0;

    for (BTreeNode e : node) {
      if(e.parent == Tree.NIL)
        root = e.id;
    }

    return root;
  }
  void setParent(int id) {
    if(node[id].left != Tree.NIL)
      node[ node[id].left ].parent = id;
    if(node[id].right != Tree.NIL)
      node[ node[id].right ].parent = id;
  }

  void preParse(int u) {
    if(u != NIL){
      buf.append(" ").append(u);
      preParse(node[u].left);
      preParse(node[u].right);
    }
  }
  void inParse(int u) {
    if(u != NIL) {
      inParse(node[u].left);
      buf.append(" ").append(u);
      inParse(node[u].right);
    }
  }
  void postParse(int u) {
    if(u != NIL) {
      postParse(node[u].left);
      postParse(node[u].right);
      buf.append(" ").append(u);
    }
  }

  void dispRoundPath(int root) {

    buf.append("Preorder\n");
    preParse(root);
    buf.append("\n")
      .append("Inorder\n");
    inParse(root);
    buf.append("\n")
      .append("Postorder\n");
    postParse(root);
    buf.append("\n");

    System.out.print(buf);
  }
}

class BTreeNode {
  int id,parent,left,right;

  public BTreeNode() {
    this.id =
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }
}


Measured memory_bytes: 24292
#include <cstdio>

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  int div=1<<M;
  double res=0.0;
  double p=1.0/div, acc=p;
  for (int i=1; i<=888; ++i) {
    res += i * acc;
    acc *= (1.0-p);
  }

  printf("%d\n", int((1900*M+100*(N-M))*res+1e-5));
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int tree[20000000];
int N = 0;

void maxHeapify(int i) {
	int l = i * 2 + 1;
	int r = i * 2 + 2;
	int largest = i;
	if (l < N && tree[l] > tree[largest]) largest = l;
	if (r < N && tree[r] > tree[largest]) largest = r;

	if (largest != i) {
		int temp = tree[i];
		tree[i] = tree[largest];
		tree[largest] = temp;
		maxHeapify(largest);
	}
}

void insert(int i) {
	if (i == 0) return;
	int parent = (i - 1) / 2;
	if (tree[parent] < tree[i]) {
		int temp = tree[parent];
		tree[parent] = tree[i];
		tree[i] = temp;
		insert(parent);
	}
}

int main(int argc, char const *argv[]) {
	string s;
	do {
		cin >> s;
		if (s == "insert") {
			int value;
			cin >> value;
			tree[N] = value;
			insert(N);
			N++;
		} else if (s == "extract"){
			int value = tree[0];
			tree[0] = tree[N - 1];
			N--;
			maxHeapify(0);
			cout << value << endl;
		}
	} while(s != "end");

	return 0;
}

Measured memory_bytes: 5296
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int DP[105][5][2];

int main() {
  string S;
  int K;
  cin>>S>>K;
  DP[0][1][0] = 1;
  DP[0][1][1] = S[0]-'1';
  for(int i=1;i<S.size();++i) {
    for(int j=0;j<=3;++j) {
      if(S[i]=='0') {
        if(j-1>=0) DP[i][j][1] = DP[i-1][j][1] + DP[i-1][j-1][1]*9;
        else DP[i][j][1] = DP[i-1][j][1];
        DP[i][j][0] = DP[i-1][j][0];
      }
      else {
        if(j-1>=0) DP[i][j][1] = DP[i-1][j][1] + DP[i-1][j-1][1]*9 + DP[i-1][j][0] + DP[i-1][j-1][0]*(S[i]-'1');
        else DP[i][j][1] = DP[i-1][j][1] + DP[i-1][j][0];
        if(j-1>=0) DP[i][j][0] = DP[i-1][j-1][0];
      }
    }
    DP[i][1][1] += 9;
  }
  cout<<DP[S.size()-1][K][1]+DP[S.size()-1][K][0]<<endl;
}



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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    string S[N]; rep(i, N) cin >> S[i];
    int ans = 0;
    /*
    for(int A = 0; A < N; A++){
        for(int B = 0; B < N; B++){
            bool ok = true;
            for(int j = 0; j < N; j++){
                int r = (j+B-A) % N, c = (A-B) % N;
                if(r < 0) r += N; if(c < 0) c += N;
                if(S[0][j] != S[r][c]){
                    ok = false;
                    //cout << A << " " <<  B  << " " << j << endl;
                }
            }
            if(ok) ans++;
        }
    }
    */
   for(int B = 0; B < N; B++){
       bool ok = true;
       for(int i = 0; i < N; i++){
           for(int j = 0; j < N; j++){
               int r = (j+B) % N, c = (i-B) % N;
               if(r < 0) r+=N; if(c < 0) c+=N;
               if(S[i][j] != S[r][c]) ok = false;
           }
       }
       if(ok) ans++;
   }
    cout << ans*N << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int n,a;
    cin >> n >> a;
    n%=500;
    if(n<=a){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  } 

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

t = [0]* (n+1)
x = [0]* (n+1)
y = [0]* (n+1)
for i in range(1,n+1):
    t[i], x[i],y[i] = map(int, input().split())

for i in range(1,n+1):
    dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1])
    if dist > t[i] -t[i-1] or dist % 2 !=  (t[i] -t[i-1])%2:
        print('No')
        exit()

print('Yes')

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> candi_a(n);
  vector<int> candi_b(n);
  for(int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
    if(a.at(i) == 1) {
      candi_a.at(b.at(i)-1) = 1;
    }
    if(b.at(i) == n) {
      candi_b.at(a.at(i)-1) = 1;
    }
  }
    
  for(int i = 0; i < n; i++) {
    if(candi_a.at(i) == 1 && candi_b.at(i) == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    } 
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int N, D;
    cin >> N >> D;

    vector<vector<int>> X(N);
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        X[i].resize(D);
        for (int j = 0; j < D; ++j) cin >> X[i][j];

        for (int j = 0; j < i; ++j) {
            int squared_norm = 0;
            for (int k = 0; k < D; ++k) {
                squared_norm += (X[j][k] - X[i][k]) * (X[j][k] - X[i][k]);
            }

            double intpart;
            if (modf(sqrt(squared_norm), &intpart) == 0.0) ++ans;
        }
    }

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


Measured memory_bytes: 256
// https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    int ans = 1e15;
    // 0番目の先頭は必ず見えるので、高さを変えない
    REP(mask, 1LL << (N - 1)) {
        int cnt = __builtin_popcount(mask);
        if (cnt != K - 1) {
            continue;
        }
        int sum = 0, border = A[0];
        REP(i, N - 1) {
            if (mask bitand (1LL << i)) {
                if (border < A[i + 1]) {
                    border = A[i + 1];
                } else {
                    sum += border + 1 - A[i + 1];
                    border++;
                }
            } else {
                border = max(border, A[i + 1] + 1);
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int a[3], maxi;
	if(scanf("%d %d %d", &a[0], &a[1], &a[2]));
	if(a[0] > a[1])
	{
		if(a[0] > a[2]) maxi = 0;
		else maxi = 2;
	} else {
		if(a[1] > a[2]) maxi = 1;
		else maxi = 2;
	}
	printf("%d\n", a[maxi] * 10 + a[0] + a[1] + a[2] - a[maxi]);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int H, W;

char mp[505][505], A[505][505], B[505][505];

int main() {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= H; ++i)
    scanf("%s", mp[i] + 1);
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      A[i][j] = B[i][j] = '.';
  for (int i = 1; i <= H; ++i) {
    A[i][1] = '#', B[i][W] = '#';
    if (i & 1) {
      for (int j = 2; j < W; ++j) A[i][j] = '#';
    } else {
      for (int j = 2; j < W; ++j) B[i][j] = '#';
    }
  }

  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      if (mp[i][j] == '#') {
	if (!(i & 1)) A[i][j] = '#';
	else B[i][j] = '#';
      }

  for (int i = 1; i <= H; ++i)
    printf("%s\n", A[i] + 1);
  puts("");
  for (int i = 1; i <= H; ++i)
    printf("%s\n", B[i] + 1);
  
  return 0;
}

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;

    for(int i =0; i <= a; i++) {
        for(int j =0; j <= b; j++) {
            for(int k =0; k <= c; k++) {
                int sum =0;
                sum += i*500+j*100+k*50;
                if(sum == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
    ll n;
  cin>>n;
  double a,b;
  a=double(double(n*100)/108);
  b=double(double((n+1)*100)/108);
  //cout<<a<<" "<<b<<endl;
  double x,x1;
  x=(n*100)/108;
  x1=((n+1)*100)/108;
 // cout<<x<<" "<<x1<<endl;
  if(a<=x&&x<b)cout<<x<<endl;
  else if(a<=x1&&x1<b)cout<<x1<<endl;
  else cout<<":("<<endl;
}



Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	vi in(90);
	in[0]=2;in[1]=1;
	rep(i,88)in[i+2]=in[i+1]+in[i];
	int a;cin>>a;
	cout<<in[a]<<endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll h,w;cin>>h>>w;
  string s[h];
  for(ll i=0;i<h;i++)cin>>s[i];
  bool used[h][w];
  for(ll i=0;i<h;i++)for(ll j=0;j<w;j++)used[i][j]=false;
  ll ans=0;
  ll dx[4]={-1,1,0,0};
  ll dy[4]={0,0,-1,1};
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      if(s[i][j]=='.'||used[i][j]==true)continue;
      ll c=0;
      ll d=0;
      queue<pair<ll,ll>> q;
      q.push(make_pair(i,j));
      used[i][j]=true;
      while(q.size()>0){
        pair<ll,ll> p=q.front();q.pop();
        ll pf=p.first,ps=p.second;
        //cout<<pf<<" "<<ps<<endl;
        if(s[pf][ps]=='#')c++;
        else d++;
        for(ll k=0;k<4;k++){
          ll in=pf+dy[k],jn=ps+dx[k];
          if(in<0||in>=h||jn<0||jn>=w||used[in][jn]==true)continue;
          if(s[pf][ps]==s[in][jn])continue;
          q.push(make_pair(in,jn));
          used[in][jn]=true;
        }
      }
      ans+=c*d;
      //cout<<c<<" "<<d<<endl;
    }
  }
  cout<<ans<<endl;
}
          

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*** 0026 */
public class Main {

	/*** 紙 */
	private static int[][] paper;
	/*** インク滴「小」,「中」,「大」 */
	private static final int S = 1, M = 2, L = 3;
	/*** 文字型入力ストリーム（標準入力） */
	private static BufferedReader br;
	/*** 拡大する大きさ */
	private static int plus = 2;
	/*** 通常の紙の大きさ */
	private static int normal = 10;
	/*** 列, 行, インク滴の大きさ, 色のついていない部分, 最も色の濃い部分 */
	private static int x, y, size, blindNum, max;
	/*** 入力行 */
	private static String line;

	/*** 初期化 */
	static {
		int extention = normal + plus * plus; // 縦横ともに紙のサイズを拡大する（計算しやすくするため）
		paper = new int[extention][extention];
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * メインメソッド
	 */
	public static void main(String[] args) throws IOException {

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			setInput(line); // 入力行を設定する
		}
		calcu(); // 計算する
		System.out.println(blindNum + "\n" + max);
	}

	/**
	 * 入力行の設定を設定する
	 */
	private static void setInput(String line) {
		StringTokenizer st = new StringTokenizer(line, ","); // カンマごとに分ける
		x = Integer.parseInt(st.nextToken()) + plus; // 紙を拡大した分マスを大きくする
		y = Integer.parseInt(st.nextToken()) + plus; // 紙を拡大した分マスを大きくする
		size = Integer.parseInt(st.nextToken());
		set(); // インク滴を設定
	}

	/**
	 * 色のついていない部分のマス目の個数と１番濃いマス目の濃さを計算する。
	 */
	private static void calcu() {
		for (x = plus; x < normal + plus; x++) {
			for (y = plus; y < normal + plus; y++) {
				if (paper[x][y] == 0) // 色のついていない部分かどうか
					blindNum++;
				if (max < paper[x][y]) // １番濃いマス目かどうか
					max = paper[x][y];
			}
		}
	}

	/**
	 * 入力値に対応する場所にインキ滴を設定する
	 */
	private static void set() {
		paper[x][y]++;
		if (size >= S) {
			paper[x - 1][y]++;
			paper[x + 1][y]++;
			paper[x][y - 1]++;
			paper[x][y + 1]++;
		}
		if (size >= M) {
			paper[x - 1][y - 1]++;
			paper[x - 1][y + 1]++;
			paper[x + 1][y - 1]++;
			paper[x + 1][y + 1]++;
		}
		if (size >= L) {
			paper[x - 2][y]++;
			paper[x + 2][y]++;
			paper[x][y - 2]++;
			paper[x][y + 2]++;
		}
	}
}

Measured memory_bytes: 17000
n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(min(42, k)):
    nex = [0]*n
    for i, v in enumerate(current):
        l = max(0, i-v)
        r = min(n-1, i+v)
        nex[l] += 1
        if r+1 < n:
            nex[r+1] -= 1
    for i in range(1, n):
        nex[i] += nex[i-1]
    current = nex

print(*current)

Measured memory_bytes: 155496
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

using P = pair<int, int>;

int n, m, d[100009];
V<P> G[100009];
set<int> s[100009];

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

    cin >> n >> m;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    fill(ALL(d), mod);
    priority_queue<P> que;
    que.emplace(d[1] = 0, 1);
    while(!que.empty()) {
        int now = que.top().second;
        int cost = -que.top().first;
        que.pop();
        if(d[now] < cost) continue;
        for(P e : G[now]) {
            int dist = d[now];
            if(!s[now].count(e.second)) dist++;
            if(chmin(d[e.first], dist)) {
                s[e.first].clear();
                que.emplace(-d[e.first], e.first);
            }
            if(dist == d[e.first]) s[e.first].insert(e.second);
        }
    }
    cout << (d[n] == mod ? -1 : d[n]) << endl;

    return 0;
}

Measured memory_bytes: 23412
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	int c[100002] = {};
	for(int i=0; i<N; i++){
		int a;
		cin >> a;
		c[a-1]++;
		c[a]++;
		c[a+1]++;
	}
	int ans = 0;
	for(int i=0; i<100002; i++){
		ans = max(ans, c[i]);
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    vector<int> cnt(n + 1);
    rep (i, n) {
        FOR (j, i + 1, n) {
            int dist = abs(j - i);
            int bridge = min(abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1);
            dist = min(dist, bridge);
            cnt[dist]++;
        }
    }
    rep (i, n - 1) cout << cnt[i + 1] << endl;
    
    return 0;
}



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

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

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

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

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

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

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

ll gcd(ll a, ll b){
    ll tmp;
    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
    while(b != 0){
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

int main(void){
    ll a, b;
    ll g, g2, count=1;
    cin >> a >> b;

    g = gcd(a,b);
    g2 = g;
    for(ll i = 2; i * i <= g; i++){
        bool flag = false;
        while(g2 % i == 0){
            flag = true;
            g2 /= i;
        }
        if(flag){
            count++;
        }
    }
    if(g2 != 1){
        count++;
    }
    cout << count << endl;
}

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

namespace ABC096B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = aaa[0];
            var X = aaa[1];
            var list = new List<int>();

            for(var i=0; i<N; i++)
            {
                list.Add(int.Parse(Console.ReadLine()));
            }

            var sum = X - list.Sum();
            Console.WriteLine(sum / list.Min() + N);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
  int n;
  int h[100000];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> h[i];
  }
  int dp[100000];
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for(int i = 2;i < n;i++){
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int cnt = 0;
    for (int i=0; i<3; i++) {
      if (s.charAt(i) == 'o') cnt++;
    }
    System.out.println(700+100*cnt);
  }
}

Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll cost[2000][2001];

int main(){
    int N;
    ll x;
    cin >> N >> x;
    vll A(N);
    rep(i, N)scanf("%lld", &A[i]);

    ll ans = LLONG_MAX;
    
    rep(i, N){
        cost[i][0] = A[i];
        for(int j = 1; j <= N - 1; ++j){
            int k = (i - j + N) % N;
            cost[i][j] = A[k];
        }
    }

    rep(i, N)rep(j, N-1)smin(cost[i][j+1], cost[i][j]);

    rep(j, N){
        ll val = j*x;
        rep(i, N){
            val += cost[i][j];
        }
        smin(ans, val);
    }
    cout << ans << endl;
}

Measured memory_bytes: 31488
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 055 Restaurant a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  int N;
  cin >> N;
  cout << ((N * 800) - (N/15)*200) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   int n,k;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   ll sum =0;
   for(int i=0;i<k;i++)
    sum+= a[i];
   cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
    h, w, m = map(int,input().split()) 
    h_lis = [0] * (h+1)
    w_lis = [0] * (w+1)
    bombs = set([tuple(map(int,input().split())) for i in range(m)])
    for hh, ww in bombs:
        h_lis[hh] += 1
        w_lis[ww] += 1
    max_h = max(h_lis)
    max_w = max(w_lis)
    h_max_index = [i for i, h in enumerate(h_lis) if h == max_h]
    w_max_index = [i for i, w in enumerate(w_lis) if w == max_w]
    for h_i in h_max_index:
        for w_i in w_max_index:
            if not (h_i, w_i) in bombs:
                print(h_lis[h_i] + w_lis[w_i])
                sys.exit()
    else:
        print(h_lis[h_i] + w_lis[w_i] - 1)

if __name__=='__main__':
    main()

Measured memory_bytes: 190560
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int N,M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  for(int i=0; i < N; i++)
      cin >> A[i];
  for(int i=0; i < M; i++)
      cin >> B[i];
  int ok = 0;
  for(int k=0; k < N-M+1; k++){
    for(int l=0; l < N-M+1; l++){
      for(int i=k; i < k+M; i++){
        for(int j=l; j < l+M; j++){
          if(A[i][j] == B[i-k][j-l])
	    ok += 1;
	  else{
	    ok = 0;
	    break;
	  }
	}
	if(ok == 0) break;
      }
      if(ok == M*M) break;
    }
    if(ok == M*M) break;
  }
  if(ok == M*M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>

#define PI acos(-1)
#define INF 0x3f3f3f3f
#define SCD(a) scanf("%d",&a)
#define SCL(a) scanf("%lld", &a)
#define SCLL(a,b) scanf("%lld%lld", &a, &b)
#define SCDD(a,b) scanf("%d%d",&a,&b)
#define SCF(a) scanf("%lf",&a)
#define PTD(a) printf("%d", a)
#define PTL(a) printf("%lld", a)
#define PTLE(a) printf("%lld\n", a)
#define PTDE(a) printf("%d\n",a)
#define MST(a,b) memset(a, b, sizeof(a))
#define FOR(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define ll long long

using namespace std;
const int D = 20;
const int L = 1e5 + D;
int n, m, T;
int ans;
int a[L];
vector<int> v;

void solve()
{
    int i,  t;
    for(i=0; i<n; i++){
        SCD(t);
        v.push_back(t);
    }
    sort(v.begin(), v.end());
    ans = 0;
    for(i=1; i<v.size(); i++)
        a[i] = v[i] - v[i-1] - 1 ;
    for(i=2; i<v.size(); i++){
        ans += max(a[i], a[i]);

    }

    PTDE(ans);
}


int main()
{
    int i ,j ,t;
    int x, y, z;
    ans = 0;
    SCDD(x, y);
    SCD(z);
    i = 1;
    ans = (x - z)/(y + z);
    PTDE(ans);
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

/*


*/


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int N, M, R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];

void dfs(int c, int las, int dist){
    if(c == R+1){
        if(res > dist) res = dist;
        return ;
    }
    for(int i = 1; i <= R; i++){
        if(!used[i]){
            used[i] = true;
            if(las == -1) dfs(c+1, i, 0);
            else dfs(c+1, i, dist+d[r[las]][r[i]]);
            used[i] = false;
        }
    }
}

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

    scanf("%d%d%d", &N, &M, &R);
    for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) if(i != j) d[i][j] = INF;
    for(int i = 1; i <= R; i++) scanf("%d", &r[i]);
    for(int i = 1; i <= M; i++){
        scanf("%d%d%d", &A, &B, &C);
        if(d[A][B] > C) d[A][B] = d[B][A] = C;
    }
    for(int k = 1; k <= N; k++){
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N; j++){
                if(d[i][j] > d[i][k]+d[k][j]) d[i][j] = d[i][k]+d[k][j];
            }
        }
    }
    res = INF;
    dfs(1, -1, 0);
    printf("%d\n", res);

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    while (N--) {
        int x, y, b, p;
        cin >> x >> y >> b >> p;
        int sum = x * b + y * p;
        if (b >= 5 && p >= 2) sum = sum * 8 / 10;
        else {
            int tmp = x * max(b, 5) + y * max(p, 2);
            tmp = tmp * 8 / 10;
            sum = min(tmp, sum);
        }
        cout << sum << endl;
    }

    return 0;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,k;
        cin>>n>>k;int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        int ans = 0;
        for(int i=0;i<k;i++)ans+=a[i];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>



using namespace std;

typedef long long ll;

#define drobucs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
	drobucs;

	string s;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad";
	}
	else {
		cout << "Good";
	}
		return 0;
}
		

Measured memory_bytes: 256
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int a[55];
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n;
    ll ans;
    while(cin>>n){
        memset(a,0,sizeof(a));
        ans=0LL;
        for(int i=1;i<=n;i++) scanf("%d",a+i);
        for(int i=1;i<=n-1;i++) for(int j=i+1;j<=n;j++) ans+=a[i]*a[j];
        cout<<ans<<endl;
    }
	return 0;
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int x;

signed main() {
    cin >> x;
    cout << x/500*1000 + (x%500)/5*5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

    std::vector A(N, 0);
    for (int i = 0; i < N - 1; i++) {
        int a; std::cin >> a;
        A[a - 1]++;
    }

    for (int i = 0; i < N; i++) {
        std::cout << A[i] << '\n';
    }
}

Measured memory_bytes: 4044
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;



int main() {
    int n;
    cin >> n;
    int nowx = 0, nowy = 0;
    int nowt = 0;
    bool result = true;
    for (int i = 0; i < n; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        int usetime = t - nowt;
        int movex = x - nowx, movey = y - nowy;


        int diff = usetime - abs(movex) - abs(movey);
        if (diff < 0 || diff % 2) {
            result = false;
        }

        nowt = t;
        nowx = x;
        nowy = y;

    }
    cout << (result ? "Yes" : "No") << endl;
    

    return 0;
}

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

int main(){
    int ans=0,sum=0;
    int n,m;
    
    string s;
    cin >>n>>s;

    stack<char> st;

    for (int i = 0; i < n; i++){
        if(s[i]==')' && !st.empty()){
            
            if(st.top()=='(')st.pop();
            else st.push(s[i]);

        }else{
            st.push(s[i]);
        }
    }
    
    while (!st.empty()){
        if(st.top()==')'){
            s = "(" + s;
        }else{
            s = s + ")";
        }
        st.pop();
    }
    


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << s << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
/*
  AOJ 1248
  Title:The Balance
  @kankichi573
*/
#include <stdio.h>
#define MAX 99999999

main()
{
  int A,B,D,both,left,ax,flag,i,j,ans_a,ans_b;
  while(scanf("%d%d%d",&A,&B,&D) && (A||B||D))
    {
      for(ax=MAX,flag=i=0;flag==0;i++)
	for(j=0;j<=i;j++)
	  {
	    both=A*j-B*(i-j);
	    left=A*j+B*(i-j);
	    if(left==D||both==D||both==-D)
	      {
		flag=1;
		if(ax>left)
		  {
		    ax=left;
		    ans_a=j;
		    ans_b=i-j;
		  }
	      }
	  }
	  printf("%d %d\n",ans_a,ans_b);
    }
  return(0);
}

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

int main(){

 
  ll N,M;
 
  cin>>N>>M;
  
  ll H[N+1];
  ll G[N+1];
  
  for(int i=1;i<N+1;i++){

    cin>>H[i];
    G[i]=1;
    
  }
  
  rep(i,M){

    int k1,k2;
    cin>>k1>>k2;
    if(H[k1]>H[k2])G[k2]=0;
    else if(H[k1]<H[k2])G[k1]=0;
    else {G[k1]=0;G[k2]=0;}

  }
  
  
  ll count=0;
  for(int i=1;i<N+1;i++){

    if(G[i]==1)count++;
    
  }
  cout<<count<<endl;
  
}


Measured memory_bytes: 5192
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, M;
	cin >> N >> M;
	VLL H(N);
	for (LL n = 0; n < N; n++)cin >> H[n];
	vector<bool> isGood(N,true);
	for (LL m = 0; m < M; m++) {
		LL a, b;
		cin >> a >> b;
		a--; b--;
		if (H[a] >= H[b])isGood[b] = false;
		if (H[a] <= H[b])isGood[a] = false;
	}
	LL ans = 0;
	for (LL n = 0; n < N; n++) {
		if (isGood[n])ans++;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a,c,m,n,o=0,ans=0;
    cin>>n>>m>>c;
    ll b[m];
    for (ll i=0; i<m; i++) {
        cin>>b[i];
    }
    for (ll i=0; i<n; i++) {
        ans=0;
        for (ll j=0; j<m; j++) {
            cin>>a;
            ans+=a*b[j];
        }
        if (ans>-c) {
            o+=1;
        }
    }
    cout<<o<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e6 + 1;
bool taken[N];

bool cmp(pair<int, int> a, pair<int, int> b) {
	if(a.second == b.second)
		return a.first > b.first;
	return a.second < b.second;
}

bool cmp2(pair<int, int> a, pair<int, int> b) {
	if(a.first - a.second == b.first - a.second)
		return a.second < b.second;
	return a.first - a.second > b.first - a.second;
//	if(a.second == b.second)
//		return a.first > b.first;
//	return a.second > b.second;
}

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int n;
	cin >> n;
	string str;
	int open = 0, closed = 0;
	vector<pair<int, int>> vec;
	for (int i = 0; i < n; ++i) {
		cin >> str;
		int cnt = 0, minus = 0;
		for (int i = 0; i < (int)str.size(); ++i) {
			if(str[i] == '(')
				++cnt;
			else
				--cnt;
			if(cnt < 0)
				++minus, cnt = 0;
		}
		if(minus) {
			if(cnt)
				vec.push_back({cnt, minus});
			else
				closed += abs(minus);
		} else {
			open += cnt;
		}
	}
	int total = open;
	sort(vec.begin(), vec.end(), cmp);
	for (int i = 0; i < (int)vec.size(); ++i) {
		if(vec[i].second > vec[i].first) continue;
		if(total >= vec[i].second) {
			total -= vec[i].second;
			total += vec[i].first;
			taken[i] = 1;
		}
	}
	vector<pair<int, int>> vv;
	for (int i = 0; i < (int)vec.size(); ++i) {
		if(taken[i]) continue;
		vv.push_back(vec[i]);
	}
	sort(vv.begin(), vv.end(), cmp2);
	for (int i = 0; i < (int)vv.size(); ++i) {
		total -= vv[i].second;
		if(total < 0) {
			cout << "No";
			return 0;
		}
		total += vv[i].first;
	}
	total -= closed;
	if(total == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

int x;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("test.txt", "r", stdin);
    int ans = 0;
    FOR(i,0,3) {
        ans *= 10;
        cin >> x;
        ans += x;
    }
    cout << (ans % 4 ? "NO" : "YES");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String str = sc.nextLine();
		int q = sc.nextInt();
		String dammy = sc.nextLine();

//		System.out.println(dammy);
//
//		System.out.println(str);

		for (int i=0; i<q; i++) {

			String[] line = sc.nextLine().split(" ");

//			System.out.print(line[0]);
//			System.out.print(line[1]);
//			System.out.println(line[2]);

			int a = Integer.parseInt(line[1]);
			int b = Integer.parseInt(line[2]);

			switch ( line[0] ) {
			case "print":
				System.out.println(str.substring(a, b+1));
				break;

			case "reverse":
				String str1 = str.substring(0, a);
				String str2 = str.substring(a, b+1);
				String str3 = str.substring(b+1);

				char[] str2array = str2.toCharArray();

//				System.out.println(str1);
//				System.out.println(str2);
//				System.out.println(str3);

				str = str1;

//				System.out.println(str);

				for (int j = str2array.length - 1; j >= 0 ; j--) {
					str += String.valueOf( str2array[j] );

//					System.out.println(str);

				}
				str += str3;

//				System.out.println(str);

				break;

			case "replace":
				String p = line[3];
				String str11 = str.substring(0, a);
				String str22 = str.substring(b+1);

				str = str11 + p + str22;

//				System.out.println(str);

				break;
			}

		}
	}

}

Measured memory_bytes: 59480
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define push push_back
#define solve(a) ((a) ? "Possible" : "Impossible ")
    typedef vector<long long>
        V;
typedef vector<V> VV;
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;}
const long long INFLL = 1LL<<61;
const int INF = 1<<30;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string>a(h+1,"");
    bool ans=false;
    int c=0;
    rep(i,h){
        cin>>a[i];
        rep(j,w){
            if(a[i][j]=='#'){
                c++;
            }
        }
    }
   // cout<<c<<endl;
    cout<<solve(c==h+w-1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll k; cin >> k;
    vl a(k);
    rep(i,k) cin >> a[i];
    if(a[k-1] != 2){
        puts("-1");
        return 0;
    }
    P p = make_pair(a[k-1],2*a[k-1]-1);
    ll left,right;
    for(ll i=k-2; i>=0; i--){
        ll q = (p.first-1) / a[i];
        ll r = p.second / a[i];
        left = a[i] + q * a[i];
        right = a[i] * r;
        if(p.second < left){
            puts("-1");
            return 0;
        }
        p = make_pair(left, right + a[i] - 1);
        //cout << p.first << " " << p.second << endl;
    }
    cout << p.first << " " << p.second << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

bool check(vll &af, vll f, ll p, ll &k, ll N) {
	vll taf;
	ll tk = k;
	copy(af.begin(), af.end(), back_inserter(taf));

	for (ll i = 0; i < N; i++) {
		ll nk = 0;
		if(taf[i] > p){
			nk = (taf[i] - p + f[i] - 1) / f[i];
		}
		taf[i] -= f[i] * nk;
		tk -= nk;
	}
	if (tk < 0) {
		return false;
	}
	else {
		k = tk;
		af = taf;
		return true;
	}
}

int main() {
	ll i, j;
	ll N, K;
	cin >> N >> K;
	vll A(N);
	vll F(N);
	for (auto& e : A)cin >> e;
	for (auto& e : F)cin >> e;

	sort(A.begin(), A.end());
	sort(F.begin(), F.end());

	vll AF(N);
	ll maxaf = 0;
	for (i = 0; i < N; i++) {
		AF[i] = A[N - 1 - i] * F[i];
		maxaf= max(maxaf, AF[i]);
	}
	ll emin = 0;
	ll emax = maxaf;
	ll bp = emin + (emax - emin)/ 2;
	while (1) {
		bool res = check(AF, F, bp, K, N);
		if (res) {
			emax = bp;
			bp = emin + (emax - emin) / 2;
		}
		else {
			emin = bp + 1;
			bp = emin + (emax - emin) / 2;
		}
		if (emax == emin) {
			cout << emax << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 10752
#cording: utf-8

N = int(input())
p = []
for i in range(N):
    p.append(int(input()))

max_val = max(p)
max_ind = p.index(max_val)
p[max_ind] = p[max_ind]/2

sum = 0
for i in range(len(p)):
    sum += p[i]

print(int(sum))


Measured memory_bytes: 3060