akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

class UnionFind {
    vector<int> rank;
    vector<int> p;
    void link(int rx, int ry) {
        if (rx == ry) return;
        if (rank[rx] > rank[ry]) p[ry] = rx;
        else p[rx] = ry;
        if (rank[rx] == rank[ry]) rank[ry]++;
    }
public:
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
    UnionFind(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i,size) makeSet(i);
    }
    int findSet(int x) {
        if (x != p[x]) p[x] = findSet(p[x]);
        return p[x];
    }
    bool same(int x, int y) {return findSet(x) == findSet(y);}
    void unite(int x, int y) {link(findSet(x), findSet(y));}
};

int main() {
    fast_io
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind u(n);
    int x, y;
    rep(i,m) {
        cin >> x >> y;
        u.unite(x-1, y-1);
    }
    int ans = 0;
    rep(i,n) {
        if (u.same(i, p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

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

  if(n%1000 == 0) cout << "0" << endl;
  else  {
    int t = n/1000 + 1;
    int ans = 1000 * t - n;
    cout << ans << endl;
  }
}
//18.1

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n), s(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) s[i] = i+1;
    map<vector<int>, int> m;
    do{
        m[s] = m.size()+1;
    } while(next_permutation(all(s)));
    int ans = abs(m[p] - m[q]);
    cout << ans << endl;
}

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

using namespace std;

int main(){

    int n;

    scanf("%d", &n);

    int menor = 2*(1e9);
    int maior = -1;

    for(int i = 0; i < n; i++){
        int val;
        scanf("%d", &val);
        menor = min(val,menor);
        maior = max(val,maior);
    }

    printf("%d\n",maior-menor );

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int gcd(int m,int n);
int main()
{
	int a,b;
	long long sum=0;
	scanf("%d",&a);
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=a;j++)
		{
			for(int k=1;k<=a;k++)
			{
				b=gcd(i,j);
				sum+=gcd(b,k);
			}
		}
	}
	printf("%lld",sum);
}
int gcd(int m,int n)
{
	int a=0;
	if(m<n)
	{
		m=m+n;
		n=m-n;
		m=m-n;
	}
	a=n;
	for(int i=1;a!=0;i++)
	{
		a=m%n;
		if(a!=0)
		{
			m=n;
			n=a;
	    }
	}
	return n;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define ll long long int
const int mod=1e9+7;
ll fact(ll n){return (n==1 || n==0) ? 1: n * fact(n - 1);  } 

int main(){
  ll k,a,b;
  cin>>k;
  cin>>a>>b;
  ll left=a%k;
  ll right=b%k;
  if(a%k==0 || b%k==0 || (b-a+1)>=k)cout<<"OK";
  else if(left>right)cout<<"OK";
  else cout<<"NG";
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  cout << n + n * n + n * n * n << endl;
  return 0;
}

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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	string O, E;
	cin >> O >> E;

	for (int i = 0; i < O.length(); i++) {
		cout << O[i];
		if (i < E.length()) cout << E[i];
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import math

#print(math.sin(math.radians(30)))

A,B,H,M=map(int,input().split())

JI=H*30+M/2
FUN=6*M

XJI=A*math.sin(math.radians(JI))
YJI=A*math.cos(math.radians(JI))
XFUN=B*math.sin(math.radians(FUN))
YFUN=B*math.cos(math.radians(FUN))

ans=(XJI-XFUN)**2+(YJI-YFUN)**2
print(math.sqrt(ans))


Measured memory_bytes: 62440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// Vector Type.
struct V {
  double x, y;

  V(double x = 0, double y = 0) : x(x), y(y) {}

  V& operator+=(const V& v) {
    x += v.x; y += v.y;
    return *this;
  }
  V& operator+(const V& v) const { return V(*this) += v; }
  double dot(const V& v) const { return x*v.x + y*v.y; }
  double cross(const V& v) const { return x*v.y - y*v.x; }
  double norm() const { return sqrt(norm2()); }
  double norm2() const { return x*x + y*y; }
  int ort() const { // orchant
    if (y > 0) {
      return (x > 0) ? 1 : 2;
    } else {
      return (x > 0) ? 4 : 3;
    }
  }
  bool operator<(const V& v) const {
    int o = ort();
    int vo = v.ort();
    if (o != vo) { return o < vo; }
    return cross(v) > 0;
  }
};

istream& operator>>(istream& i, V& v) {
  i >> v.x >> v.y;
  return i;
}
ostream& operator<<(ostream& o, const V& v) {
  o << "(" << v.x << ", " << v.y << ")";
  return o;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vector<V> v(N);
  rep(i, N) {
    cin >> v[i];
  }

  sort(all(v));
  double ans = 0;
  rep(i, N) {
    V now(0, 0); // Start from (0, 0)
    rep(j, N) {
      now += v[(i + j) % N];
      ans = max(ans, now.norm());
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> ds(N);
  for(int i = 0; i < N; ++i) {
    cin >> ds[i];
  }
  sort(ds.begin(), ds.end());
  int ans = ds[N / 2] - ds[N / 2 - 1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**9)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))


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

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

    int na = 0, nb = 0, nc = 0;
    rep(i, S.size()) {
        if (S[i] == 'a') na++;
        else if (S[i] == 'b') nb++;
        else nc++;
    }

    string ans = "YES";
    if (abs(na-nb) > 1 || abs(nb-nc) > 1 || abs(nc-na) > 1) ans = "NO";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll comb(ll n, ll k)
{
    __int128 ans = 1;
    srep(i,n-k+1,n+1){
        ans *= i;
    }
    srep(i,1,k+1){
        ans /= i;
    }
    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    int val = 0;
    srep(i,1,471){
        if(comb(i+7,8) > K){
            K -= comb(i+6,8);
            val = i-1;
            break;
        }
        if(i == 470){
            K -= comb(i+7,8);
            val = i;
            break;
        }
    }
    vector<int> ad(val,0);
    for(int i = val; i >= 1; i--){
        ll hoge = comb(i+6,7);
        if(K >= hoge){
            ad[val-i] += K / hoge;
            K -= K / hoge * hoge;
        }
    }
    rep(i,val){
        rep(j,ad[i]){
            cout << 'F';
        }
        cout << "FESTIVAL";
    }
    cout << "\n";
    return 0;
}

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

#define endl "\n"
#define ll long long
#define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);

using namespace std;

int main() {
    ios
    ll ans = 0;
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++ i) {
        for (int j = i + 1; j < n; ++ j) {
            for (int k = j + 1; k < n; ++ k) {
                if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k] && a[i] + a[j] + a[k] - max(a[i], max(a[j], a[k])) > max(a[i], max(a[j], a[k]))) ++ ans;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;

template <typename t>
inline void print (const t & v){
    for (auto i:v){
        cout << i << " ";
    }
    cout << endl;
}

int main(){
    vector <int> v, t;
    ll n;
    cin >> n;
    
    while (n--){
        ll no;
        cin >> no;
        v.push_back(no);
    }
    n = v.size();
    while (n--){
        ll no;
        cin >> no;
        t.push_back(no);
    }


    vector <int> original=v;
    sort (original.begin(), original.end());

    ll count_T =0, count_V=0;

    do{
        //print (original);
        if ( original == t){
            break;
        }
        count_T ++;
    }while ( next_permutation(original.begin(), original.end()));
    
    sort (original.begin(), original.end());
    do{
        if ( original == v){
            break;
        }
        count_V ++;
    }while ( next_permutation(original.begin(), original.end()));


    cout << abs(count_T - count_V) << endl;
    return 0;
}


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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int tmp;
  rep(i, 5) {
    cin >> tmp;
    if (tmp == 0) {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string x;
	cin >> x;
    string ans;
    if(x[2]==x[3]&&x[4]==x[5])ans="Yes";
    else ans = "No";
      cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

s = input()
t = input()

dp = [[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(1,len(s)+1):
  for j in range(1,len(t)+1):
    if s[i-1] == t[j-1]:
      dp[i][j] = max(dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1])
    else:
      dp[i][j] = max(dp[i-1][j],dp[i][j-1])

ansl = []
cnt = dp[-1][-1]
def tami(i,j):
  global cnt
  if cnt == 0:
    return
  if s[i-1] == t[j-1]:
    cnt -= 1
    ansl.append(i-1)
  if dp[i-1][j-1]==cnt:
    tami(i-1,j-1)
  elif dp[i][j-1]==cnt:
    tami(i,j-1)
  elif dp[i-1][j]==cnt:
    tami(i-1,j)

tami(len(s),len(t))

ans = ""
for i in ansl:
  ans += s[i]
print(ans[::-1])

Measured memory_bytes: 115164
package main

import (
	"fmt"
)

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)
	cs := make([]int, n)
	as := make([][]int, n)
	for i := range cs {
		fmt.Scan(&cs[i])
		as[i] = make([]int, m)
		for j := range as[i] {
			fmt.Scan(&as[i][j])
		}
	}

	const inf = int(1e9)
	ans := inf
	for i := 0; i < 1<<uint(n); i++ {
		var cost int
		ls := make([]int, m)
		for j := 0; j < n; j++ {
			if 1<<uint(j)&i > 0 {
				cost += cs[j]
				for k := 0; k < m; k++ {
					ls[k] += as[j][k]
				}
			}
		}
		var ng bool
		for j := 0; j < m; j++ {
			if ls[j] < x {
				ng = true
			}
		}
		if !ng {
			ans = min(ans, cost)
		}
	}

	if ans == inf {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	long long ans = 0, s = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		s += a[i];
		ans += abs(a[i]);
	}

	long long t = 0;
	for (int i = 0; i < n - 1; i++)
	{
		t += a[i];
		ans =min(ans, llabs(2 * t - s));
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0){
      return false;
    }
  }
  return true;
}

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

  ll x;
  cin >> x;

  rep(i, -200, 200){
    rep(j, -200, 200){
      if(pow(i, 5) - pow(j, 5) == x){
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
const ll MOD=1000000007;



int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>> ab(N);
    rep(i,N)cin>>ab.at(i).first>>ab.at(i).second;
    sort(ab.begin(),ab.end());
    //reverse(ab.begin(),ab.end());//日数大きい順
    set<pair<int,int>> pt;
    /*rep(i,N){
        pt.insert({ab.at(i).second,i});
    }
    int pointa=0;
    ll ans=0;
    rep(i,M){
        if(pt.empty()){continue;}//アルゴリズム違う
        pair<int,int> today;
        today=*rbegin(pt);
        ans+=ab.at(today.second).second;
        pt.erase(today);
        while(pointa<N && ab.at(pointa).first>=M-i){
            pt.erase({ab.at(pointa).second,pointa});
            pointa++;
        }
    }
    cout<<ans<<endl;*/

    int pointa=0;
    ll ans=0;
    rep(i,M){
        while(pointa<N && ab.at(pointa).first<=i+1){
            pt.insert({ab.at(pointa).second,pointa});
            pointa++;
        }
        if(pt.empty()){continue;}
        pair<int,int> today;
        today=*rbegin(pt);
        ans+=ab.at(today.second).second;
        pt.erase(today);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	ll n,m; cin>>n>>m;
	vvl g(n,vl(0));
	vl ans(n);
	vector<bool> seen(n);
	rep(i,0,m){
		ll a,b; cin>>a>>b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll k=q.front(); q.pop();
		for(ll c:g[k]){
			if(seen[c])continue;
			seen[c]=true;
			ans[c]=k;
			q.push(c);
		}
	}
	cout<<"Yes"<<endl;
	rep(i,1,n)cout<<ans[i]+1<<endl;
	
	
	return 0;
}

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

int main(){
  string S;
  int64_t K;
  cin >> S >> K;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!='1'){
      cout << S.at(i) << endl;
      break;
    }else if(i+1==K){
      cout << S.at(i) << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 体力の入力
		int tairyoku = sc.nextInt();
		// 攻撃の入力
		int kougeki = sc.nextInt();
		
		int kaisu = tairyoku/kougeki;
		int tmp = tairyoku%kougeki;
		if(tmp != 0) {
			kaisu = kaisu +1;
		}
		
		System.out.println(kaisu);
		
	}
}

Measured memory_bytes: 23252
#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;
    string s, t;
    cin >> n >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    return 0;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;


int main() {
  int N, A[300002] = {}, Q;
  cin >> N;
  A[0] = 0, A[N + 1] = INF;
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector< int > vs;
  for(int i = 0; i < N + 2; i++) vs.push_back(A[i]);
  sort(begin(vs), end(vs));
  vs.erase(unique(begin(vs), end(vs)), end(vs));
  for(int i = 0; i < N + 2; i++) {
    A[i] = lower_bound(begin(vs), end(vs), A[i]) - begin(vs);
  }
  int sum = 0;
  for(int i = 1; i < N + 2; i++) {
    sum += A[i] - A[i - 1] <= 1;
  }
  cin >> Q;
  if(sum == N + 1) {
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    set< pair< int, int > > add;
    for(int z = 0; z < 2; z++) {
      add.emplace(x + z, x + z - 1);
      add.emplace(y + z, y + z - 1);
    }
    for(auto &p : add) {
      sum -= A[p.first] - A[p.second] <= 1;
    }
    swap(A[x], A[y]);
    for(auto &p : add) {
      sum += A[p.first] - A[p.second] <= 1;
    }
    if(sum == N + 1) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}



Measured memory_bytes: 6136
N,M = map(int, input().split())
MOD = 10**9+7

if abs(N - M) > 1:
    print(0)
    exit()

factorial = [1] * (max(N,M)+1)
for i in range(1,max(N,M)+1):
    factorial[i] = (factorial[i-1]*i) % MOD

if abs(N - M) == 0:
    ans = ((factorial[N]**2) * 2) % MOD
else:
    ans = (factorial[N] * factorial[M]) % MOD
print(ans)

Measured memory_bytes: 6900
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int bs(double x, double y, long l[], long r[], long w, int m) {

    int lower = 0;
    int upper = m + 1;

    while( true ) {
        int t = (lower + upper) / 2;

        if ( y < x * (r[t] - l[t]) / (w + 0.0) + l[t] ) {
            if ( y > x * (r[t-1] - l[t-1]) / (w + 0.0) + l[t-1] ) {
                return t - 1;
            } else {
                upper = t;     
            }
        } else {
            lower = t;
        }
    }
}

int main() {

    int n, m;
    long w, h, S;
    while(cin >> n >> m >> w >> h >> S && (n || m || w || h || S) ) {
        S *= 2;
        long l[m+1];
        long r[m+1];
        l[0] = 0;
        r[0] = 0;
        for(int i = 1; i <= m; i++) {
            cin >> l[i] >> r[i];
        }
        double x[n];
        double y[n];
        for(int i = 0; i < n; i++) {
            cin >> x[i] >> y[i];
        }

        long fromd_area[m+1];
        long fromu_area[m+1];
        fromd_area[0] = 0;
        fromu_area[0] = 0;
        for(int i = 1; i <= m; i++) {
            fromd_area[i] = fromd_area[i-1] + (l[i] - l[i-1] + r[i] - r[i-1]) * w;
            fromu_area[i] = fromu_area[i-1] + (l[m+1-i] - l[m-i] + r[m+1-i] - r[m-i]) * w;
        }

        int nuts[m];
        fill(nuts, nuts + m, 0);
        for(int i = 0; i < n; i++) {
            nuts[bs(x[i], y[i], l, r, w, m)] += 1;
        }

        int fromd_nuts[m+1];
        int fromu_nuts[m+1];
        fromd_nuts[0] = 0;
        fromu_nuts[0] = 0;
        for(int i = 1; i <= m; i++) {
            fromd_nuts[i] = fromd_nuts[i-1] + nuts[i-1];
            fromu_nuts[i] = fromu_nuts[i-1] + nuts[m-i];
        }

        int minnuts = n + 1;
        for(int i = 0; i < m; i++) {
            int j = lower_bound(fromu_area, fromu_area + m + 1, S - fromd_area[i]) - fromu_area;
            if (minnuts > fromd_nuts[i] + fromu_nuts[j]) {
                minnuts = fromd_nuts[i] + fromu_nuts[j];
            }
        }

        cout << minnuts << endl;

    }
     
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++) cin >> H[i];
    
    int maximum = 0;
    int count = 0;

    for (int i = 1; i < N; i++) {
        if (H[i-1] >= H[i]) count ++;
        else {
            maximum = max(count, maximum);
            count = 0;
        }
    }

    cout << max(count, maximum) << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list()
for i in range(120):
	a.append(0)
for i in range(n):
	b, f, r, v = map(int, input().split())
	a[(b - 1) * 30 + (f - 1) * 10 + (r - 1)] += v
for i in range(4):
	if i >= 1:
		print("#" * 20)
	for j in range(3):
		for k in range(10):
			print(' ', end = '')
			print(a[i * 30 + j * 10 + k], end = '')
		print()



Measured memory_bytes: 5628
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var h=new long[n+1];
		long p=0,ans=0;
		for(int i = 0;i<=n;i++) {
			p<<=1;
			p=Min(p,(long)1e15);
			if(i==0){p=1;}
			p-=a[i];
			h[i]=p;
			if(p<0){
				Console.WriteLine(-1);
				return;
			}
			ans+=a[i];
		}
		p=a[n];
		for(int i = n-1;i>=0;i--) {
			p=Min(h[i],p);
			ans+=p;
			p+=a[i];
		}
		Console.WriteLine(ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main(){
    int t = 0, n, x;
    while(1){
    cin >> n >> x;
    if(n == 0 && x == 0) break;
    ++n;
    for(int i = 1;i < n;++i){
      for(int j = 1;j < n;++j){
        for(int o = 1;o < n;++o){
         if(i + j + o == x){
         	if(i != j && i != o && j != o)
               t++;
              }
            }
          }
       }
        cout << t / 6 << endl;
        t = 0;
    } 
    return 0;
}

Measured memory_bytes: 1160
#include <utility>
#include <bitset>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ios>
#include <iomanip>
#include <sstream>
#include <climits>
#include <cmath>

using namespace std;

#ifdef USE_LOG
#define LOG(str)  cout << str << endl
#define DMP(var)  cout << #var << " = " << var << endl
#else
#define LOG(...)
#define DMP(...)
#endif

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define RFOR(v, b, e)  for (int v = (e) - 1; (b) <= v; --v)
#define REP(v, n)      FOR(v, 0, n)
#define RREP(v, n)     RFOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

typedef long long           ll;
typedef unsigned long long  ull;

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

	int N;
	cin >> N;

	vector<int> a(N);
	for (auto& v : a) cin >> v;

	sort(ALL(a), greater<int>());

	int alice = 0;
	int bob = 0;
	REP (i, N) {
		if ((i % 2) == 0) {
			alice += a[i];
		} else {
			bob += a[i];
		}
	}

	cout << (alice - bob) << endl;
}

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

int main(void){
  int x,y,i,a;
 vector<int> v;
	for(i=0; i<3; ++i){
		cin >> a;
		v.push_back(a);
	}
 sort(v.begin(),v.end());
  x=v[2]*10+v[1];
  y=v[0];
  printf("%d\n",x+y);
  
 return 0;
}

Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);

            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}

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

int main(void)
{
  int n, *list, i, holder, j;
  int swaps = 0;
  scanf(" %d", &n);
  list = (int *) malloc(sizeof(int[n]));
  for (i = 0; i < n; i++)
    scanf(" %d", list + i);
  // bubble sort
  for (i = 0; i < n; i++)
    for (j = n - 1; j > i; j--)
      if (list[j] < list[j - 1])
	{
	  swaps++;
	  holder = list[j];
	  list[j] = list[j - 1];
	  list[j - 1] = holder;
	}
  // print list and swaps
  for (i = 0; i < n; i++)
    printf("%d%s", list[i], i != n - 1 ? " " : "\n");
  printf("%d\n", swaps);
  return 0;
}



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

typedef long long int ll;
#define deb(x) cout << #x << " " << x << endl;
#define debarr(x) for (auto i : x) cout << i << " "; cout << endl;
#define debtwo(x,y) cout << #x << " " << x << ", " << #y << " " << y << endl;
#define mod 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, a, b;
  cin >> n;

  bool f = 0;
  int c = 0;
  while (n--) {
    cin >> a >> b;
    if (a == b) c++;
    else c = 0;
    if (c == 3) f = 1;
  }
  if (f) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
ll M = -1;
int main()
{
    int x[5], sum = 0;

    for (int i = 0; i < 5; i++) {
        cin >> x[i];
        sum += (x[i]+9)/10*10;
        if (M < ((x[i]+9)/10*10 - x[i])) M = (x[i]+9)/10*10 - x[i];
        
    }
    //cout << M << endl;
    cout << sum - M << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  string s;
  cin >> s;
  
  ll a, z;
  for (int i = 0; i < s.size(); i++){
    if (s[i] == 'A'){
      a = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++){
    if (s[i] == 'Z'){
      z = i;
    }
  }

  cout << z - a + 1 << endl;

  return 0;
}


Measured memory_bytes: 3752
#import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    S = str(input())
    
    def animal(x,s):
        if x[-1] == 1:
            if s == "o":
                return x[-2]
            else:
                return -1*x[-2]
        else:
            if s == "o":
                return -1*x[-2]
            else:
                return x[-2]
                
    poss = [[1,1],[1,-1],[-1,1],[-1,-1]]
    for i in range(4):
        col = poss[i]
        for j in range(N-1):
            put = animal(col,S[j+1])
            col.append(put)
        put = animal(col,S[0])
        col.append(put)
        if (col[0] == col[-2] and col[1] == col[-1]):
            l = len(col)-2
            ans = []
            for k in range(l):
                if col[k] == 1:
                    ans.append("S")
                else:
                    ans.append("W")
            print("".join(ans))
            exit()
            
    print(-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 7412
def resolve():
    inf = 2000

    a,b =map(int, input().split())
    ax = [int(x*0.08) for x in range(inf)]
    bx = [int(y*0.1) for y in range(inf)]
    aans = []
    bans = []
    for i,j in enumerate(ax):
        if j == a:
            aans.append(i)
    for i,j in enumerate(bx):
        if j == b:
            bans.append(i)
    ans_set = set(aans) & set(bans)
    if len(ans_set)!=0:
        print(min(ans_set))
    else:
        print("-1")
    
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  vector<int>ans(N,0);
  
  for(int i=N;i>=1;i--){
    int acount = a.at(i-1);
    for(int j=i+i;j<=N;j+=i){
      if(ans.at(j-1) == 1){
        acount += 1;
      }
    }
    if(acount % 2 == 1){
      ans.at(i-1) = 1;
    }
  }

  int siz = 0;
  for(int i=0;i<N;i++){
    if(ans.at(i) != 0){
      siz += 1;
    }
  }
  if(siz == 0){
    cout << 0;
  }else{
    cout << siz << endl;
    for(int i=0;i<N;i++){
      if(i > 0){
        cout << " ";
      }
      if(ans.at(i) == 1){
	      cout << i+1;
      }
    }
  }


  cout << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s,t;
		s = sc.next();
		t = sc.next();
		int a,b;
		String u;
		a = sc.nextInt();
		b = sc.nextInt();
		u = sc.next();

		if(u.equals(s)) {
			a--;
		}else if(u.equals(t)) {
			b--;
		}
		System.out.println(a + " " + b);

		sc.close();

	}

}

Measured memory_bytes: 21712
class UnionFind():
    def __init__(self, n):
        self._par = [i for i in range(n)]
        self._rnk = [0 for _ in range(n)]

    def find(self, x):
        if self._par[x] == x:
            return x
        else:
            self._par[x] = self.find(self._par[x])
            return self._par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return

        if self._rnk[x] < self._rnk[y]:
            x, y = y, x

        if self._rnk[x] == self._rnk[y]:
            self._rnk[x] += 1

        self._par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    uf.unite(x - 1, y - 1)

ans = 0
for i in range(n):
    if uf.is_same(i, p[i] - 1):
        ans += 1

print(ans)

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

int main(void) {
	int n, m;
	int i,k,ans,q,mod;
	scanf("%d%d", &n, &m);
	mod = m %n ;
	q = m / n;
	if (mod == 0) {
		printf("%d",q);
	}
	else {
		for (i = q; i > 0; i--) {
			vector<int> v(n, i);
			v[n - 1] = m - (n - 1)*i;
			if (v[n - 1] % i == 0) {
				ans = i;
				break;
			}
		}
		printf("%d",ans);
	}
	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)
typedef long long ll;


const ll MOD = (ll)998244353;
struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};
/* dp[i][j][k]: 配列をi個見て、和がjで、
右端も決まってない(0), 
右端は決まっているが左端は決まっていない(1), 
両方決まっている(2)
*/
mint dp[3010][3010][3];
int N, S;
void debug(){
    rep(k,3){
        cerr <<"["<<k << "]" << endl;
        rep(i,N+1){
            rep(j,S+1){
                cerr << dp[i][j][k] <<" ";
            }
            cerr << endl;
        }
        cerr << endl;
    }
    cerr << endl;
}
int main() {
    cin >> N >> S;
    vector<int> A(N);
    rep(i,N)cin>>A[i];
    dp[0][0][0] = 1;
    //debug();
    rep(i,N){
            rep(j,S+1){
            //from 0
            {
                //to 0  まだ始まってすらないよ！
                dp[i+1][j][0] += dp[i][j][0];
                //to 1  左側は決めるけど和をとらないよ
                dp[i+1][j][1] += dp[i][j][0];
                //      iから始めるぜ
                dp[i+1][min(S+1, j+A[i])][1] += dp[i][j][0];
                //to 2
                dp[i+1][j][2] += dp[i][j][0];
                //        iから始めた瞬間に終わるぜ
                dp[i+1][min(S+1, j+A[i])][2] += dp[i][j][0];
            }
            //from 1
            {
                //to 1  今までのやつを反映させるぜ
                dp[i+1][j][1] += dp[i][j][1];
                //      引き続き区間を伸ばすぜ    
                dp[i+1][min(S+1, j+A[i])][1] += dp[i][j][1];
                //to 2  右側を決めるけどこれ以上増やさないぜ
                dp[i+1][j][2] += dp[i][j][1];
                //      ここで使って終わるぜ
                dp[i+1][min(S+1, j+A[i])][2] += dp[i][j][1];
            }
            //from 2
            {
                //to 2 単純に反映させるぜ
                dp[i+1][j][2] += dp[i][j][2];
            }
        }
        //debug();
    }
    //debug();
    cout << dp[N][S][2] << endl;
}

Measured memory_bytes: 212608
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
//i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
//vector <i64> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    cin >> n >> k;
    vector<i64> a(n);

    for (i64 i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (i64 i = 0; i < n - k; ++i) {
        if (a[i] < a[i + k]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }

    }
  
    return 0;
}

Measured memory_bytes: 4432
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int seisu = scan.nextInt();
		int count = 1;


		Map<String,Integer> hikaku = new TreeMap<String,Integer>();

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

			String suzi = scan.next();

			if(!hikaku.containsKey(suzi)) {

				count = 0;
				hikaku.put(suzi,count);
			}else {
				count = 1;
				hikaku.put(suzi, count);
			}
		}

		System.out.println(!hikaku.containsValue(1)?"YES":"NO");

		scan.close();

	}

}


Measured memory_bytes: 78204
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 13 15:36:35 2019
ABC129D
@author: maezawa
"""

h, w = list(map(int, input().split()))
arr = [['*']*(w+2)]
for _ in range(h):
    arr.append(list('*' +input()+'*'))
arr.append(['*']*(w+2))

#result = arr[:]
#print(arr)

left = [[0]*(w+2) for _ in range(h+2)]
right = [[0]*(w+2) for _ in range(h+2)]
up = [[0]*(w+2) for _ in range(h+2)]
down = [[0]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if arr[i][j] == '#':
            left[i][j] = 0
        else:
            left[i][j] = left[i][j-1] + 1
for i in range(1, h+1):
    for j in reversed(range(1, w+1)):
        if arr[i][j] == '#':
            right[i][j] = 0
        else:
            right[i][j] = right[i][j+1] + 1
            
#print(left,sep='\n')
#print(right,sep='\n')

for j in range(1, w+1):
    for i in range(1, h+1):
        if arr[i][j] == '#':
            down[i][j] = 0
        else:
            down[i][j] = down[i-1][j] + 1
for j in range(1, w+1):
    for i in reversed(range(1, h+1)):
        if arr[i][j] == '#':
            up[i][j] = 0
        else:
            up[i][j] = up[i+1][j] + 1
            
maxlight = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if arr[i][j] == '#':
            continue
        n = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        #result[i][j] = n
        if n > maxlight:
            maxlight = n
            
print(maxlight)

Measured memory_bytes: 309512
#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>;

//#include <iostream>
//#include <string>
//using namespace std;
int main() {
	int n;
	int turi;

	cin >> n;
	turi= (n/1000+1)*1000-n;

	if (turi % 1000 !=0){
	cout << turi << endl;
	}else{
		cout << "0" << endl;
	}

}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
#define maxn (100010)
int n, m, top, s[maxn], cnt[maxn], sum[maxn];

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch == '-' ? f = -1, ch = getchar() : ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

//void sol(int x, int del) {
////	printf("X %lld %lld\n", x, del);
//	if (!x) return;
//	int pos = upper_bound(s + 1, s + top + 1, x) - s - 1; // 找到比他大的，然后-1 
////	printf("POS %lld\n", pos);
//	if (!pos) sum[1] += del, sum[x + 1] -= del;
//	else sum[pos] += (x / s[pos]) * del, sol(x % s[pos], del);
//}

void sol(int x,int del) {
//	printf("X %lld %lld\n", x, v);
	if (!x) return;
	int pos = upper_bound(s+1,s+top+1,x) - s - 1;
//	printf("TT %lld\n", t);
	if (pos == 0) sum[1] += del, sum[x+1] -= del;
	else cnt[pos] += (x / s[pos]) * del, sol(x % s[pos], del);
}

signed main() {
	n = read(), m = read();
	s[++top] = n;
	int x;
	for (int i = 1; i <= m; ++i) {
		x = read();
		while (top && s[top] >= x) --top;
		s[++top] = x;
	}
	cnt[top] = 1;
	for (int i = top; i >= 2; --i) {
		cnt[i - 1] += (s[i] / s[i - 1]) * cnt[i];
//		printf("	%lld %lld %lld\n", s[i] % s[i - 1], cnt[i], i);
		sol(s[i] % s[i - 1], cnt[i]);
	}
//	for (int i = 1; i <= top; ++i) printf("%lld\n", cnt[i]);
	sum[1] += cnt[1], sum[s[1] + 1] -= cnt[1]; // s[1]为最长长度
	for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
	for (int i = 1; i <= n; ++i) printf("%lld\n", sum[i]); 
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
int n,m;
int c[1001]; int a[1001],b[1001];int k;int dp[100000];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		for(int j=1;j<=b[i];j++){
			cin>>k;c[i]+=(1<<(k-1));
		}
	}
	for(int i=1;i<=1<<n;i++)dp[i]=100000001;
	dp[0]=0;
for(int j=1;j<=m;j++){
for(int i=0;i<(1<<n)-1;i++){        
            dp[i|c[j]]=min(dp[i|c[j]],dp[i]+a[j]);
            
        }
    }
if(dp[(1<<n)-1]!=100000001)cout<<dp[(1<<n)-1];
else cout<<"-1";
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	ll x;
	cin >> x;
	ll y = 100;
	int ans = 0;
	while (y < x) {
		y += y / 100;
		ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>

int main(void) {
    long long int n, a, b, count = 0;
    scanf("%lld %lld %lld", &n, &a, &b);
    
    long long int dif = b - a;

    if (!(dif % 2)) {
        count = dif / 2;
    } else {
        long long int totop = a - 1, tobottom = n - b;
        if (totop < tobottom) {
            count = totop + (dif - 1) / 2 + 1;
        } else {
            count = tobottom + (dif - 1) / 2 + 1;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128