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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin());
#define io() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
	io();
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(all(v));
	if(v[0] == v[1]){
		cout << (v[1] != v[2] ? "Yes" : "No") << '\n';
	}else if(v[1] == v[2]){
		cout << (v[0] != v[1] ? "Yes" : "No") << '\n';
	}else{
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int M = scan.nextInt();
    int A[] = new int[N];
    int sum = 0;
    for(int i=0; i<N; i++) {
      A[i] = scan.nextInt();
      sum += A[i];
    }
    scan.close();

    Arrays.sort(A);

    if((double)A[N-M]/sum < (double)1/(4*M)) {
      System.out.println("No");
    }
    else {
      System.out.println("Yes");
    }
  }
}

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

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 [キャプチャ](パラメータ){ 処理 }  */
 

int main(){
    int n; cin >> n;
    vector<pair<string, int>> a(n);
    rep(i,n) {
        string s; cin >> s;
        int t; cin >> t;
        a[i] = make_pair(s, t);
        
    }
    string x; cin >> x;
    int ans = 0;
    bool flag = false;
    rep(i,n){
        
        if(flag){
            ans += a[i].second;
        }
        if(a[i].first == x) flag = true;
    }
    
    cout << ans << endl;
    
    
}




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(int i=0; i<(N); i++)
#define INF 1000100
typedef pair<int, int> P;
using Graph = vector<vector<int>>;

int h, w;



int main(){
    cin >> h >> w;
    vector<vector<char>> maze(h, vector<char>(w));
    vector<vector<int>> dist(h, vector<int>(w));
    queue<P> que;
    
    int ans=-1, dx[4] = {0,0,-1,1}, dy[4] = {1,-1,0,0};
    REP(i, h){
        REP(j, w){
            cin >> maze[i][j];
            if(maze[i][j] == '.')dist[i][j] = INF;
            else{
                dist[i][j] = 0;
                que.push(P(i,j));
            }
        }
    }

    while(que.size()){
        P p = que.front();
        que.pop();
        ans = dist[p.first][p.second];
        REP(i,4){
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' && dist[nx][ny] == INF){
                que.push(P(nx, ny));
                dist[nx][ny] = ans+1;
            }
        }
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N, tmpInt;
	double tmp = 0, answer;
	cin >> N;
	for (int count = 0; count < N; count++)
	{
		cin >> tmpInt;
		tmp += 1 / (double)tmpInt;
	}
	answer = 1 / tmp;
	cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int x=800*n; // 1食毎に800円も払う
    int y=(n/15)*200;  // 15食毎に200もらえる
    cout<<x-y<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int A, B;
//---------------------------------------------------------------------------------------------------
#define yes "Yes"
#define no "No"
string solve() {
    rep(C, 1, 4) if ((A * B * C) % 2 == 1) return yes;
    return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;
    cout << solve() << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x = I()
    t = x // 100
    u = x % 100
    if u <= t * 5:
        return 1

    return 0


print(main())





Measured memory_bytes: 6220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	int max = *max_element(L.begin(), L.end());
	int sum = accumulate(L.begin(), L.end(), 0);
	if (max < sum - max) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    int mn = min(c, b);
    ans += 2 * mn;
    b -= mn, c -= mn;
    mn = min(a, c);
    ans += mn;
    c -= mn;
    if (c > 0) {
        ans++;
    }
    if (b > 0) {
        ans += b;
    }
    cout << ans << "\n";
}

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

int main()
{
    long long int n,b,c,k,d;
    unsigned long long int sum=0;

    cin>>n>>k>>d;
    //sum = k*d;
    if(n>=0){
    b = n/d;
    if(b<=k){
    c = n - (d*b);
    //cout<<c<<endl;
    k-=b;
    sum=k%2;
    //cout<<sum<<endl;
    }
    else{
    c = n - (d*k);
    k-=k;
    }
    //cout<<sum<<endl;
    if(sum==1){c = min(abs(c-d),(c+d));}


    cout<<c<<endl;
    }

    else{
    b = abs(n)/d;

    if(b<=k){
    c = n + (d*b);
    //cout<<c<<endl;
    k-=b;
    sum=k%2;
    //cout<<sum<<endl;
    }
    else if(n<0){
    c = n + (d*k);
    k-=k;
    }
    //cout<<sum<<endl;
    if(sum==1){c = min(abs(c-d),abs(c+d));}


    cout<<abs(c)<<endl;
    }


    return 0;
}





Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

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

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    int n;
    cin >> n;
    int sum = 0;
    bitset<(int)4e6 + 5> dp;
    dp[0] = 1;
    REP(i, n){
        int a;
        cin >> a;
        sum += a;
        dp |= dp << a;
    }
    int center = ceil(sum / 2.0);
    for(int i = center; i < 4e6 + 5; i++){
        if(dp[i]){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <map>

size_t achieve(const std::vector<std::vector<int>>& bingo,
               const std::map<int, size_t>& nth, size_t u) {

  size_t n = bingo.size();
  std::vector<std::vector<size_t>> a(n, std::vector<size_t>(n, -1));
  for (size_t i = 0; i < n; ++i)
    for (size_t j = 0; j < n; ++j) {
      auto it = nth.find(bingo[i][j]);
      if (it == nth.end()) continue;
      a[i][j] = it->second;
    }

  // for (size_t i = 0; i < n; ++i)
  //   for (size_t j = 0; j < n; ++j)
  //     fprintf(stderr, "%jd%c", a[i][j], j+1<n? ' ':'\n');

  std::vector<size_t> res;
  res.reserve(2*n+2);
  for (size_t i = 0; i < n; ++i) {
    res.push_back(*std::max_element(a[i].begin(), a[i].end()));

    size_t cur = 0;
    for (size_t j = 0; j < n; ++j)
      cur = std::max(cur, a[j][i]);

    res.push_back(cur);
  }

  size_t d0 = 0;
  size_t d1 = 0;
  for (size_t i = 0; i < n; ++i) {
    d0 = std::max(d0, a[i][i]);
    d1 = std::max(d1, a[i][n-i-1]);
  }
  res.push_back(d0);
  res.push_back(d1);

  if (n == 1) res.resize(1);  // ???

  --u;
  if (res.size() <= u) return -1;

  // for (size_t i = 0; i < res.size(); ++i)
  //   fprintf(stderr, "%zd%c", res[i], i+1<res.size()? ' ':'\n');
  std::sort(res.begin(), res.end());
  // for (size_t i = 0; i < res.size(); ++i)
  //   fprintf(stderr, "%zd%c", res[i], i+1<res.size()? ' ':'\n');

  return res[u];
}

int main() {
  size_t n, m;
  size_t u, v;
  scanf("%zu %zu %zu %zu", &n, &u, &v, &m);

  std::vector<std::vector<int>> usagi(n, std::vector<int>(n));
  auto neko = usagi;

  for (size_t i = 0; i < n; ++i)
    for (size_t j = 0; j < n; ++j)
      scanf("%d", &usagi[i][j]);

  for (size_t i = 0; i < n; ++i)
    for (size_t j = 0; j < n; ++j)
      scanf("%d", &neko[i][j]);

  std::map<int, size_t> nth;
  for (size_t i = 0; i < m; ++i) {
    int d;
    scanf("%d", &d);
    nth[d] = i;
  }

  size_t pyon = achieve(usagi, nth, u);
  size_t nyan = achieve(neko, nth, v);

  if (pyon < nyan) {
    puts("USAGI");
  } else if (pyon > nyan) {
    puts("NEKO");
  } else {
    puts("DRAW");
  }
}



Measured memory_bytes: 7184
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair <int, int> pii;

const int INF=0x3f3f3f3f;

int n;
char str[100005];

int f(int k) {
    if (n-k>=k-1) return 1;
    char ch='2';
    for (int i=n-k; i<k; ++i) {
        if (ch!='2' && str[i]!=ch) return 0;
        ch=str[i];
    }
    return 1;
}

int main() {
    scanf("%s", str);
    n=strlen(str);
    int lo=1, hi=n, sol=1, mid;
    while (lo<=hi) {
        mid=(lo+hi)/2;
        //printf("%d %d %d\n", lo, hi, mid);
        if (f(mid)) {
            sol=max(mid, sol);
            lo=mid+1;
        }
        else {
            hi=mid-1;
        }
    }
    printf("%d", sol);
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

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

int r0(int a){
		if(a<0)return 0;
		else return a;
}

int main(){
		int a,b,c,x,y;
		scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
		long ans=a*x+b*y;
		ans=min(ans,2*x*c+r0(y-x)*b);
		ans=min(ans,r0(x-y)*a+2*y*c);
		printf("%ld\n",ans);
		return 0;
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N, M; cin >> N >> M;
    vector<ll> H(N);
    vector<pair<ll, ll>> road(M);
    rep(i, 0, N) {
        cin >> H[i];
    }
    rep(i, 0, M) {
        ll a, b;
        cin >> a >> b;
        road[i] = make_pair(a-1,b-1);
    }

    vector<bool> suc(N, true);
    rep(i, 0, M) {
        if (H[road[i].first] == H[road[i].second]) {
            suc[road[i].first] = false;
            suc[road[i].second] = false;
        }
        else if (H[road[i].first] >= H[road[i].second])  suc[road[i].second] = false;
        else if (H[road[i].first] < H[road[i].second])  suc[road[i].first] = false;
    }
    ll count = 0;
    rep(i, 0, N) {
        if (suc[i]) count++;
    }
    cout << count << endl;
}

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

using namespace std;

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

  vector<int> v;
  for (int i = 0; i < N; i++) {
    int x;
    scanf("%d", &x);

    v.push_back(x);
  }
  sort(v.begin(), v.end());

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    ans *= __gcd(i, v[i]);
    ans %= 998244353;
  }

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

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastio;
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)
        cout << c;
    else if (a == c)
        cout << b;
    else
        cout << a;
    cout << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;

string s, t;
vector<int> dict[30];
long long ans;

long long search(char t) {
	long long x;
	long long y = 0;
	x = ans % s.length();
	if (dict[(int)t - 97][0] > x) {
		return dict[(int)t - 97][0] - x + y;
	}
	else if (dict[(int)t - 97][dict[(int)t - 97].size() - 1] <= x) {
		y = s.length() - x;
		x = 0;
		if (dict[(int)t - 97][0] > x) {
			return dict[(int)t - 97][0] + y;
		}
	}



	long long ub = dict[(int)t - 97].size() - 1;
	long long lb = 0;
	long long mid = (ub + lb) / 2;

	while (ub - lb > 1) {
		if (dict[(int)t - 97][mid] > x) {
			ub = mid;
		}
		else {
			lb = mid;
		}
		mid = (ub + lb) / 2;
	}
	return dict[(int)t - 97][ub] - x + y;

}

int main() {

	cin >> s >> t;

	ans = 0;

	for (int i = 0; i < s.length(); i++) {
		dict[(int)s[i] - 97].push_back(i + 1);
	}

	for (int i = 0; i < t.length(); i++) {
		if (dict[(int)t[i] - 97].empty()) {
			ans = -1;
			break;
		}
		else if (dict[(int)t[i] - 97].size() == 1) {
			long long x;
			x = ans % s.length();
			if (dict[(int)t[i] - 97][0] > x) {
				x = dict[(int)t[i] - 97][0] - x;
				ans += x;
			}
			else {
				ans += (s.length() - x) + dict[(int)t[i] - 97][0];
			}
		}
		else {
			ans += search(t[i]);
		}
		//cout << ans << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  string s = stin();
  string sub_s = stin();
  bool restorable = false;

  // 後ろからsubstring(sub_s)が入るかどうか探索
  for(int i = s.size()-sub_s.size(); i >= 0; --i) {
    bool restorable_sub = true;
    for(int j = 0; j < sub_s.size(); ++j) {
      if(s[i+j] == '?') continue; // '?'の部分はどんな文字列でも入れられるのでスキップ
      if(s[i+j] == sub_s[j]) continue;  // 元々同じ文字の部分はスキップ
      else {  // '?'でないかつ違う文字列が入っている時
        restorable_sub = false; // substringが入らない
        break;  // この範囲の探索終了
      }
    }
    
    if(restorable_sub) {
      // substringが入るとき、'?'ごとsubstringに置き換え
      for(int j = 0; j < sub_s.size(); ++j) {
        s[i+j] = sub_s[j];
      }
      restorable = true;
      break;
    }
  }

  // substringがどこにも入らなかった時
  if(!restorable) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  // substringで置き換えたところ以外は'a'で埋める（辞書順で最も若い文字列を作る）
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '?') cout << 'a';
    else cout << s[i];
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    sort(a,a+n);
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;j<n;j++){
                long lb=j, ub=n+1;
                
                while(ub-lb>1){
                    long mid=(lb+ub)/2;
                    if(a[i]+a[j]>a[mid] && a[i]+a[mid]>a[j] && a[mid]+a[j]>a[i]){
                        lb=mid;
                    }
                    else{
                         ub=mid;
                    }
                }
            ans+=lb-j;
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 256
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys
import math


def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


def main():
    a, b = _ia()
    for i in range(1010):
        xa = math.floor(i * 0.08)
        xb = math.floor(i * .1)
        if xa == a and xb == b:
            return i
    return -1


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <cstdio>
#include <tr1/unordered_set>

using namespace std;
typedef unsigned long long ULL;
const ULL SALT = 1000000009ULL;

ULL modpow(ULL a, ULL x) {
    if(x == 0) return 1;
    if(x == 1) return a;
    ULL half = modpow(a, x/2);
    ULL rem = (x%2 == 1) ? a : 1;
    return half*half*rem;
}

int N, M;
char buf[300001];
ULL char_hash[300001];
int main() {
    scanf("%d %d", &N, &M);
    scanf("%s", buf);
    ULL base = 1;
    for(int i = 0; i < N; ++i) {
        char_hash[i] = buf[i] * base;
        base *= SALT;
    }
    int l = 0, r = 0;
    ULL hash = buf[0];
    tr1::unordered_set<ULL> seen;
    while(M--) {
        char cmdbuf[10];
        scanf("%s", cmdbuf);
        string cmd(cmdbuf);
        if(cmd == "R++") {
            hash += char_hash[++r];
        } else if(cmd == "R--") {
            hash -= char_hash[r--];
        } else if(cmd == "L++") {
            hash -= char_hash[l++];
        } else if(cmd == "L--") {
            hash += char_hash[--l];
        }
        seen.insert(hash * modpow(SALT, N-l));
    }
    cout << seen.size() << endl;
    return 0;
}

Measured memory_bytes: 17880
#include <stdio.h>

int calc(int y,int m,int d){

  int i,yd,md;
  
  yd = (y-1)*195 + (y-1)/3*5;
 
 if(y%3==0)
   md = 20*(m-1);
 else{
   if (m%2==1) md = (m/2)*39;
   else md = 20 + ((m/2)-1)*39;
}
 
 return (yd + md + d);
}

int main(void){

  int aniv;
  int n;
  int y,m,d;
  int day[100];
  int i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d %d",&y,&m,&d);
    day[i] = calc (1000,1,1) - calc(y,m,d);
  }

  for(i=0;i<n;i++)
    printf("%d\n",day[i]);

  return 0;
}

Measured memory_bytes: 1024
A,B,C,D = map(int,input().split())

def gcd(a,b):
    while(a%b!=0):
        a,b = b,a%b
    return(b)

def lcm(a,b):
    return(a*b//gcd(a,b))

print(B-(A-1)-((B//C+B//D-B//lcm(C,D))-((A-1)//C+((A-1)//D-(A-1)//lcm(C,D)))))
   

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main(){
    string s1,s2;
    cin>>s1;
    cin>>s2;
    LL n=s1.length();
    LL m=s2.length();
    LL dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    LL len=dp[n][m];
    
    char arr[len];
    LL i=n;
    LL j=m;
    LL idx=len-1;
    while(i>0&&j>0){
        if(s1[i-1]==s2[j-1]){
            arr[idx]=s1[i-1];
            idx--;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    
    for(LL i=0;i<len;i++){
        cout<<arr[i];
    }
}

Measured memory_bytes: 70656
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[][] g = new int[15][15];
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                g[i][j] = -1;
            }
        }

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            for (int j = 0; j < a; j++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                x--;
                g[i][x] = y;
            }
        }

        int ans = 0;
        for (int i = 0; i < (1<<n); i++) {
            int[] d = new int[n];
            for (int j = 0; j < n; j++) {
                d[j] = 0;
                if((i>>j & 1) == 1) {
                    d[j] = 1;
                }
            }
            boolean ok = true;
            for (int j = 0; j < n; j++) {
                if (d[j] == 1) {
                    for(int k = 0; k < n; k++) {
                        if (g[j][k] == -1) continue;
                        if (g[j][k] != d[k]) ok = false;
                    }
                }
            } 
            if (ok) ans = Math.max(ans,Integer.bitCount(i));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25212
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	vector <int>array;
	int answer=0;
	int n;
	int input;
	cin >> n;
	for(int i= 0;i<n;i++){
		cin >> input;
		array.push_back(input);
	}
	sort(array.begin(),array.end());
	
	int before = -1;
	for(int i=0;i<n;i++){
		if(before == array[i]){
//			i++;
			before = -1;
			answer--;
		}else{
			before = array[i];
			answer++;
		}
//		before = array[i];
	}
	
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 892
import numpy as np
N=int(input())
AB=np.empty((N,2))
sum=np.empty(N)

for i in range(N):
    AB[i]=list(map(int,input().split()))
    sum[i]=AB[i][0]+AB[i][1]
lis = np.argsort(sum)
taka=0
aoki=0
for i in lis:
    if N%2==0:
        if i%2!=0:
            taka+=AB[lis[i]][0]
        else:
            aoki+=AB[lis[i]][1]
    else:
        if i%2==0:
            taka+=AB[lis[i]][0]
        else:
            aoki+=AB[lis[i]][1]

print(int(taka-aoki))


Measured memory_bytes: 17640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,k,x,y ;
		n = sc.nextInt();
		k = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();

		if(n > k) {
		System.out.println((k*x)+((n-k)*y));
		}else{
			System.out.println(n*x);
		}

	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		String[] str = new String[h];
		char[][] chararray = new char[h][w];

		for (int i = 0; i < h; i++) {
			chararray[i] = scanner.next().toCharArray();
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int count = 0;
				if (chararray[i][j] == '#') {
					System.out.print("#");
				} else {
					if (i - 1 >= 0) {
						if (j - 1 >= 0) {
							if (chararray[i - 1][j - 1] == '#') {
								count++;
							}
						}
						if (j + 1 < w) {
							if (chararray[i - 1][j + 1] == '#') {
								count++;
							}
						}
						if (chararray[i - 1][j] == '#') {
							count++;
						}
					}
					if (i + 1 < h) {
						if (j - 1 >= 0) {
							if (chararray[i + 1][j - 1] == '#') {
								count++;
							}
						}
						if (j + 1 < w) {
							if (chararray[i + 1][j + 1] == '#') {
								count++;
							}
						}
						if (chararray[i + 1][j] == '#') {
							count++;
						}
					}

					if(j -1 >= 0){
						if (chararray[i][j-1] == '#') {
							count++;
						}
					}
					if(j + 1 < w){
						if (chararray[i][j+1] == '#') {
							count++;
						}
					}
					System.out.print(count);
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 23124
// CPP program to print the Kth prime greater than N 
#include <bits/stdc++.h> 
using namespace std; 

// set the MAX_SIZE of the array to 10^6 
const int MAX_SIZE = 1e6; 

// initialize the prime array 
bool prime[MAX_SIZE + 1]; 

void sieve() 
{ 

	// set all numbers as prime for time being 
	memset(prime, true, sizeof(prime)); 

	for (int p = 2; p * p <= MAX_SIZE; p++) { 

		// if prime[p] is not changed, then it is a prime 
		if (prime[p] == true) { 

			// update all multiples of p 
			for (int i = p * p; i <= MAX_SIZE; i += p) 
				prime[i] = false; 
		} 
	} 
} 
// Function to find the kth prime greater than n 
int kthPrimeGreaterThanN(int n, int k) 
{ 

	int res = -1; 
	// looping through the numbers greater than n 
	for (int i = n + 1; i < MAX_SIZE; i++) { 

		// decrement k if i is prime 
		if (prime[i] == true) 
			k--; 

		// store the kth prime greater than n 
		if (k == 0) { 
			res = i; 
			break; 
		} 
	} 

	return res; 
} 

// Driver code 
int main() 
{ 

	sieve(); 
	int n;
	cin>>n;
	n = n-1;
	// int n = 19, k = 1; 

	// Print the kth prime number greater than n 
	cout << kthPrimeGreaterThanN(n, 1); 
	return 0; 
} 


Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<vector>
using namespace std;

double ManhattanDistance(vector<int> x, vector<int> y){
	double d = 0;
	for(int i = 0; i < x.size(); i++) d += abs( x[i] - y[i] );
	return d;
}

double EuclidDistance(vector<int> x, vector<int> y){
	double D = 0;
	for(int i = 0; i < x.size(); i++) D += (x[i] - y[i]) * (x[i] - y[i]);
	return sqrt(D);
}

double CubeRootDistance(vector<int> x, vector<int> y){
	double D = 0;
	for(int i = 0; i < x.size(); i++) D += abs( (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]) );
	return pow(D, 1.0 / 3.0);
}

double ChebyshevDistance(vector<int> x, vector<int> y){
	double d = abs( x[0] - y[0] );
	for(int i = 1; i < x.size(); i++) if( abs( x[i] - y[i] ) > d ) d = abs( x[i] - y[i] );
	return d;
}

vector<int> Enter(int n){
	vector<int> z;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		z.push_back(a);
	}
	return z;
}

int main(){
	int n;
	cin >> n;
	vector<int> x = Enter(n);
	vector<int> y = Enter(n);
	cout << fixed << setprecision(6) 
	     << ManhattanDistance(x, y) << endl 
	     << EuclidDistance(x, y) << endl 
	     << CubeRootDistance(x, y) << endl 
	     << ChebyshevDistance(x, y) << endl;
	return 0;
}

Measured memory_bytes: 1336
#include <stdio.h>

int main(void){
    
    int a = 0;
    int b = 0;
    
    scanf("%d %d",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 1008
open System

let R() = Console.ReadLine().Split() |> Array.map int

let f (k: int) (n: int) (a: int list): int =
    let a' = let h = List.last a - k in h :: a 
    List.pairwise a' 
    |> List.map(fun (l,r) -> k - r + l)
    |> List.min 

let K, N = let t = R() in t.[0], t.[1]
let A = R()

f K N (List.ofArray A)
|> printfn "%i"


Measured memory_bytes: 70172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
	ll n,m;
	cin>>n>>m;
	ll ans;
	ll k;
	if(m>=2*n+4){
		k=(m-2*n)/4;
		n+=k;
		m-=2*k;
	}
	ans=min(m/2,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N;
    cin >> N;
    vector<pair<string, int> > data(N);
    vl a(N);
    rep(i, 0, N) {
        cin >> data[i].first;
        cin >> data[i].second;
    }
    string last; cin >> last;
    bool flag = false;
    int ans = 0;
    rep(i, 0, N) {
        if (flag) {
            ans += data[i].second;
        }
        if (last == data[i].first) {
            flag = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) puts("A");
	else puts("B");
	return 0;
}

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

using i64 = int64_t;

constexpr i64 INF = 1e12;

struct Node{
    i64 n, m, cost;
    bool operator<(const Node &obj)const{
        return cost > obj.cost;
    }
};

i64 mini[1003][1003]={0};

int main(){
    int n, m;
    cin >> n >> m;
    vector<i64> d;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        d.push_back(tmp);
    }
    vector<i64> c;
    for(int i=0;i<m;++i){
        i64 tmp;
        cin >> tmp;
        c.push_back(tmp);
    }

    for(int i=0;i<=n;++i){
        for(int j=0;j<=m;++j){
            mini[i][j] = INF;
        }
    }

    mini[0][0] = 0;
    priority_queue<Node> que;
    que.push((Node){0, 0, 0});
    while(!que.empty()){
        Node curr = que.top(); que.pop();
        if(curr.n == n){
            cout << curr.cost << endl;
            break;
        }
        if(curr.m + 1 <= m){
            i64 cost = curr.cost;
            if(mini[curr.n][curr.m+1] > cost){
                mini[curr.n][curr.m+1] = cost;
                que.push((Node){curr.n, curr.m+1, cost});
            }
            cost += d[curr.n] * c[curr.m];
            if(mini[curr.n+1][curr.m+1] > cost){
                mini[curr.n+1][curr.m+1] = cost;
                que.push((Node){curr.n+1, curr.m+1, cost});
            }
        }
    }

    return 0;
}



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

int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;

    int ans = 0;
    while (n > 0) {
        n /= k;
        ++ans;
    }

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


Measured memory_bytes: 3552
#include<stdio.h>
     
 int main(){
 int a,b,c,d,sum,max;
 scanf("%d %d %d",&a,&b,&c);
 
    sum=a+b+c;
    max=a;
      if(b>max)max=b;
        if(c>max)max=c;
         d=(max*3)-sum;
      if(d%2)d+=3;
        printf("%d",(d/2));
}

Measured memory_bytes: 128
#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 = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(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, t; cin >> n >> t;
   vector<ll> A(n);
   priority_queue<pll, vector<pll>> que;
   rep(i, n){
       cin >> A[i];
       que.push({A[i], i});
   }
   vector<ll> sell(n); int index = 0;
   while(index < n && !que.empty()){
       auto p = que.top(); que.pop();
       int a = p.first, i = p.second;
       while(index < i){
           sell[index] = a;
           index++;
       }
   }
   int mx = -1, cnt = 0;
   rep(i, n){
       ll score = max(0LL, sell[i] - A[i]);
       if(score > mx){
           mx = score;
           cnt = 1;
       }else if(score == mx) cnt++;
   }
   cout << cnt << ln;

}


Measured memory_bytes: 6400
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
bs = Array.new(n+1,0)
cnt = 0
ans = []
(1..n).reverse_each do |i|
  sum = 0
  j = i
  loop do
    i += j
    break if i > n
    sum += bs[i]
  end
  if as[j-1] != sum % 2
    bs[j] = 1
    cnt += 1
    ans << j
  else
    bs[j] = 0
  end
end
puts cnt
puts ans.sort.join(" ") if !ans.empty?

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

double o[3111];
double l[3111][3333];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
char r[2222][1111];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}


double f(int n,int m)
{
    if(m==0) return 1;
    if(n==0) return 0;
    if(l[n][m]>=0) return l[n][m];
    return l[n][m]=(f(n-1,m-1)*o[n]+f(n-1,m)*(1-o[n]));
}

int main()
{
    memset(l,-1,sizeof(l));
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%lf",&o[t]);
    printf("%.9lf",f(a,a/2+1));
}





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

int main(){
    int n;
    cin >> n;
    vector <ll> a(n);
    rep(i,n){
        cin >> a[i];
    }

    int go=0;
    
    rep(i,n){
        if(a[n-2-i]<a[n-1-i]){
            go=n-1-i;
            break;
        }
        if(i==(n-2)){
            go=0;
            break;
        }
    }

    //cout << go << endl;

    ll m=1000;

    vector <int> t;
    //int s;
    //s=a[0];
    int h;
    ll ka=0;

    rep(i,n-1){
        if(a[i]<a[i+1]){
            h=1;
            ka=1000/a[0];
            m-=ka*a[0];
            break;
        }
        else if(a[i]>a[i+1]){
            h=-1;
            break;
        }
        if(i==(n-2)){
            h=1;
        }

    }

    /*if(a[0]<a[1]){
        h=1;
        ka=1000/a[0];
        m-=ka*a[0];
    }
    else{
        h=-1;
    }*/
    
    rep(i,n){
        //cout << m << " " << ka<< endl;
        if(i==go){
            m+=ka*a[go];
            break;
        }
        if(h==1){
            if(a[i+1]<a[i]){
                
                m+=ka*a[i];
                ka=0;
                h=0;
            }
        }
        else{
            if(a[i+1]>a[i]){
                ka=m/a[i];
                m-=(m/a[i])*a[i];
                h=1;
            }
        }
    }

    cout << m << endl;
    

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    int sum=0;
    int A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N,greater<int>());
    rep(i,N){
        if(K){
            K--;
        } else {
            sum+=A[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	int h[100];
	rep(i, 0, 100)h[i] = 0;
	int a[100][100];
	rep(i, 0, n) {
		int k;
		cin >> k;
		rep(j, 0, k) {
			cin >> a[i][j];
			h[a[i][j]]++;
		}
	}
	rep(i, 1, m + 1)if (h[i] == n)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
import fractions
N, M = map(int, input().split())
S = input()
T = input()
f = fractions.gcd(N, M)
flag = True
for i in range(f):
    if S[i*N//f] != T[i*M//f]:
        flag = False
        break
print([-1,N*M//f][flag])

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

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

void warshal_floyd(vvi& G) {
    int v = G.size();
    rep(i, 0, v) { G[i][i] = 0; }
    rep(k, 0, v) {
        rep(i, 0, v) {
            if (G[i][k] == INT_MAX) { continue; }
            rep(j, 0, v) {
                if (G[k][j] == INT_MAX) { continue; }
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
}

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

    int v, e;
    cin >> v >> e;

    vvi G(v, vi(v, INT_MAX));
    rep(i, 0, e) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }
    warshal_floyd(G);

    rep(i, 0, v) {
        if (G[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i, 0, v) {
        rep(j, 0, v) {
            if (G[i][j] == INT_MAX) {
                cout << "INF";
            } else {
                cout << G[i][j];
            }
            if (j != v - 1) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }

    return 0;
}


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

using namespace std;
#define inf 100000000000000LL
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 3e3 + 3;

ll dp[maxn][maxn][2];
ll a[maxn];

const ll invalid = -inf;

ll solve(int awal, int akhir, int id) {
	if(awal > akhir){return 0;}
	if(dp[awal][akhir][id] != invalid){return dp[awal][akhir][id];}
	if(id == 0){
		return dp[awal][akhir][id] = max(a[awal] + solve(awal+1, akhir, 1-id), a[akhir] + solve(awal, akhir-1, 1 - id));
	}else{
		return dp[awal][akhir][id] = min(-a[awal] + solve(awal+1, akhir, 1-id), -a[akhir] + solve(awal, akhir-1, 1 - id));
	}
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(i=0;i<maxn;i++){
		for(j=0;j<maxn;j++){
			for(int k=0;k<2;k++){
				dp[i][j][k] = invalid;
			}
		}
	}

	printf("%lld\n",solve(0, n-1, 0));

	return 0;
};

Measured memory_bytes: 141440
#include<stdio.h>

int A[1500];

void maker() {
	int i, j, k;
	for (i = 1,k=0; i <= 10000; i++) {
		for (j = 2; j < i/2+1; j++) {
			if (i%j == 0)  break;
		}
		if (j >= (i/2+1)) A[k] = i,k++;
	}
}

int judge(int a) {
	int i;
	int j = 0;
	for (i = 1; i < 1231; i++) {
		if (a == A[i]) { j = 1; break; }
		if (a < A[i]) { break; }
	}
	return j;
}


int main() {
	int i,j,k;
	int n;
	int res;
	maker();

	while (scanf("%d", &n) != EOF) {
		res = 0;
		for (i = 1, j = n; i <= n; i++, j--) {
			if (judge(i) && judge(j)) res++;
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 2044
/**
*    author:  yuya1234
*    created: 16.07.2020 16:09:33
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long double eps = 1.0E-14;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>T lcm(T a,T b){return gcd(a,b)*(a/gcd(a,b))*(b/gcd(a,b));}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  string s;
  cin>>s;

  int ans=0;
  REP(i,SZ(s)-1)
  {
    if(s[i]!=s[i+1])ans++;
  }

  cout<<ans<<endl;

  return 0;
}

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

int main()
{
    string a,b,c;
    cin >> a >> b >> c;

    int flag = 0;
    if(a[a.length()-1] != b[0]) flag = 1;
    if(b[b.length()-1] != c[0]) flag = 1;

    cout << (flag == 0 ? "YES" : "NO") << endl;

    return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int f[109][10];
int p[109][10];

int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < 10; j++) {
         cin >> f[i][j];
      }
   }
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < 11; j++) {
         cin >> p[i][j];
      }
   }

   int ans = -2e9+7;
   for (int mask = 1; mask < (1<<10); mask++) {
      int sum = 0;
      for (int i = 0; i < n; i++) {
         int cnt = 0;
         for (int j = 0; j < 10; j++) {
            if ( (mask >> j) & f[i][9-j] ) {
               cnt++;
            }
         }
         sum += p[i][cnt];
      }
      ans = max(ans, sum);
   }

   cout << ans << endl;

   return 0;
}

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

int a, b, x;
int main() {
	cin >> a >> b >> x;

	if (a > x) {
		cout << "NO" << endl;
		return 0;
	}
	else {
		if (x - a >= b) {
			cout << "NO" << endl;
			return 0;
		}
		else {
			cout << "YES" << endl;
			return 0;
		}
	}

}

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

int main()
{

    int n, m;
    scanf("%d%d", &n, &m);
    int ara_n[51][2], ara_m[51][2];
    for(int i = 0; i < n; i++)scanf("%d%d", &ara_n[i][0], &ara_n[i][1]);
    for(int i = 0; i < m; i++)scanf("%d%d", &ara_m[i][0], &ara_m[i][1]);
    for(int i = 0; i < n; i++)
    {
        int x = ara_n[i][0], y = ara_n[i][1], d = INT_MAX, p = -1;
        for(int j = 0; j < m; j++)
        {
            int xx = ara_m[j][0], yy = ara_m[j][1];
            int dd = abs(x-xx)+abs(y-yy);
            if(dd < d)
            {
                d = dd;
                p = j+1;
            }
        }
        printf("%d\n", p);
    }
    return 0;

}


Measured memory_bytes: 256