akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <cmath>
    #include <iomanip>
    #include <queue>
    #include <unordered_map>
    #include <unordered_set>
    #include <bitset>
    #include <cassert>
    #include <cstring>
    #include <climits>
     
    using namespace std;
     
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define rep(i, n) FOR(i, 0, n)
    #define SORT(c) sort((c).begin(), (c).end())
    #define mp make_pair
    #define fi first
    #define se second
    #define pb push_back
     
    typedef long long ll;
    typedef pair<int, int> P;
    typedef vector<int> V;
    typedef map<int, int> M;
     
    constexpr ll INF = 1e18;
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = 3.14159265358979323846;
    constexpr int di[] = {0, 0, 1, -1};
    constexpr int dj[] = {1, -1, 0, 0};
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n, m;
        cin >> n >> m;
        int x[112345], c[112345] = {};
        rep(i, m) cin >> x[i];
        if(n>=m||m==1)
            cout << 0 << endl;
            else{
                sort(x, x + m);
                for (int i = 0; i < m - 1; i++){
                    c[i] = x[i + 1] - x[i];
                }
                sort(c, c + (m - 1));
                ll sum = 0;
                for (int i = 0; i < m - n; i++)
                {
                    sum += c[i];
                }
                cout << sum << endl;
                return 0;
            }
    }

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

#define LEN 100000

int compare(const void *a, const void *b);

int main(void) {

    int i;
    int n;
    int d[LEN];

    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &d[i]);
    }

    qsort(d, n, sizeof(int), compare);
    printf("%d\n", d[n/2]-d[n/2-1]);

    return 0;
}

int compare(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int dw_box[4] = {1, 0, -1, 0};
int dh_box[4] = {0, -1, 0, 1};

vector<vector<int>> minim;
int h, w;
int dh, dw;

bool isvalid(int H, int W, int cost) {
  return H >= 0 && H < h && W >= 0 && W < w && minim[H][W] != -1 && cost < minim[H][W];
}

int main(){
    cin >> h >> w;
    int ch, cw;
    cin >> ch >> cw;
    ch--;
    cw--;
    cin >> dh >> dw;
    dh--;
    dw--;
    rep(i, h){
        string x;
        cin >> x;
        vector<int> tmpa(w, INT32_MAX);
        rep(j, w){
            if(x[j]=='#'){
                tmpa[j] = -1;
            }
        }
        minim.push_back(tmpa);
    }

    minim[ch][cw] = 0;
    deque<P> dq;
    dq.push_front(make_pair(ch, cw));


    while(!dq.empty()){
        P now = dq.front();
        dq.pop_front();

        rep(i, 4){
            int H = now.first + dh_box[i], W = now.second + dw_box[i];
            if(isvalid(H, W, minim[now.first][now.second])){
                P p = make_pair(H, W);
                minim[H][W] = minim[now.first][now.second];
                dq.push_front(p);
            }
        }

        rep2(i, -2, 3){
            rep2(j, -2, 3){
                int H = now.first + i, W = now.second + j;
                if (isvalid(H, W, minim[now.first][now.second] + 1)) {
                    P p = make_pair(H, W);
                    minim[H][W] = minim[now.first][now.second] + 1;
                    dq.push_back(p);
                }
            }
        }
    }

    if(minim[dh][dw]==INT32_MAX){
        minim[dh][dw] = -1;
    }
    cout << minim[dh][dw] << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  int64_t ans = 1;
  for(int i = 1; i <= N; i++){
    ans *= i;
    if(ans > 1000000007) ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int k, s, res = 0;
    cin >> k >> s;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            if (s - x - y >= 0 && s - x - y <= k) res++;
        }
    }
    cout << res << endl;
}


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


int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int s; cin >> s;
    unordered_set<int> seen;
    for(int i = 1; true; ++i) {
        if(seen.find(s) != seen.end()) {
            cout << i << endl;
            break;
        }

        seen.insert(s);
        if(s%2) {
            s = 3*s + 1;
        } else {
            s = s/2;
        }
    }
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Main {
    int N;
    String S;
    int solve(){
        String[] ss = S.split("ABC");
        int c = 0;
        for(String s : ss){
            c += s.length();
        }

        return (N - c)/3;
    }

    public void _main() throws Exception {
        //System.setIn(new FileInputStream("/home/zxt/workspace/contest/inputs/b.in"));
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        N = Integer.parseInt(in.readLine());
        S = in.readLine();
        System.out.println(solve());
    }

    public static void main(String[] args) throws Exception {
        Main s = new Main();
        s._main();
    }
}

Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define sec second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  string s,t,u;
  cin >> s >> t >> u;
  
  cout << "A" << t[0] << "C" << endl;

  return 0;
}

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

int main(void) {
    int h, w, k;
    int result = 0;
    std::cin >> h >> w >> k;
    char cell[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> cell[i][j];
        }
    }
    for (int i = 0; i < std::pow(2, h); i++) {
        for (int j = 0; j < std::pow(2, w); j++) {
            int hi = i;

            int count = 0;
            for (int a = 0; a < h; a++) {
                int wj = j;
                for (int b = 0; b < w; b++) {
                    if (cell[a][b] == '#' && wj % 2 == 0 && hi % 2 == 0) {
                        count++;
                    }
                    wj = (wj - wj % 2) / 2;
                }
                hi = (hi - hi % 2) / 2;
            }
            if (count == k) {
                result++;
            }
        }
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 3960
#include  <cstdio>
#include <iostream>

using namespace std;
int main()
{
    int a, b, c;
    while(cin >> a >> b >> c)
    {
        if(a == b && b == c)
            cout << 1 << endl;
        else if(a == b && b != c || a != b && b == c || a != b && a == c)
            cout << 2 << endl;
        else
            cout << 3 << endl;
    }


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, max = 0;
    cin >> N;
    vector<int> A(N);
    for (auto& i : A) {
        cin >> i;
        if (i > max) max = i;
    }
    vector<int> B(A);
    sort(B.begin(), B.end(), greater<int>());
    for (int i : A) cout << B[i == B[0] ? 1 : 0] << endl;
}

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

int main() {

    int N;
    cin >> N;
    int h = 0;
    int until_max = 0;
    for (int i = 0; i < N; i++){
        cin >> h;
        if (h > until_max){
            until_max = h;
        }
        if (until_max > h + 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int S,T,i;
  S=T=0;
  for(int j=0;j<4;++j){
    cin>>i;S+=i;
  }
  for(int j=0;j<4;++j){
    cin>>i;T+=i;
  }
  cout<<((S>T)?S:T)<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c, d, e = 0;
	cin >> a >> b;
	int test[31] = { 0 };
	for (int h = 1; h <= a; h++) {
		cin >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			test[d] += 1;
		}
	}
	for (int k = 1; k <= b; k++) {
		if (test[k] == a) {
			e++;
		}
	}
	cout << e << endl;
	cin >> e;
}

Measured memory_bytes: 256
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
string s[200000+1];
int n;
vector<pair<int,string> > v;
bool cmp(pair<int,string> A,pair<int,string> B){
	if(A.FIR!=B.FIR) return A.FIR>B.FIR;
	return A<B;
}
int main(){
	fastio;
	cin>>n;
	 rb(i,1,n){
	 	cin>>s[i];
	 }
	sort(s+1,s+1+n);
	s[0]="&&";
	rb(i,1,n)
	{
		if(s[i]!=s[i-1]){
			v.PB(II(1,s[i]));
		}
		else{
			v[v.size()-1].FIR++;
		}
	}
	sort(ALL(v),cmp);
	int res=v[0].FIR;
	for(auto it:v){
		if(it.FIR==res){
			cout<<it.SEC<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 16880
def lcs(x, y):
    a = len(x)
    b = len(y)
    c1 = [0] * (b + 1)
    for i in range(a):
        e1 = x[i]
        c2 = c1[:]
        for j in range(b):
            if e1 == y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]
     
n = int(input().rstrip())
ret = []
for i in range(n):
    s1 = input().rstrip()
    s2 = input().rstrip()
    ret.append(lcs(s1, s2))
print(*ret, sep="\n")


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> H(N);
  for (ll i=0 ; i<N; i++){
    cin >> H[i];
  }

  sort(H.begin(), H.end(),greater<int>());

  ll ans=0;

  for (ll i=K ; i<N; i++){
    ans+=H[i];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define mx 1000002
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int a[2000005];
int32_t main() {	
	int n,k,i;
	int ans=mod;
	cin>>n>>k;
	for(i=1;i<=k;i++)cin>>a[i];
	for(i=2;i<=k;i++)
		ans=min(ans,n-a[i]+a[i-1]);
	ans=min(ans,n-(n+a[1]%n-a[k]));
	 // cout<<"dist is "<<n-(n+a[0]%n-a[k])<<"\n";
	cout<<ans;
}	

Measured memory_bytes: 1792
w,h,n=map(int,input().split())
cx = [0,w]
cy = [0,h]
for _ in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        if cx[0] < x:
            cx[0] = x
    if a == 2:
        if cx[1] > x:
            cx[1] = x
    if a == 3:
        if cy[0] < y:
            cy[0] = y
    if a == 4:
        if cy[1] > y:
            cy[1] = y

if cx[0] >= cx[1] or cy[0] >= cy[1]:
    print(0)
else:
    print((cx[1]-cx[0])*(cy[1]-cy[0]))



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

int main() {
	static long long N, A[200000], SUM = 0, ANS = 1000000000000000;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], SUM += A[i];
	long long Cur = 0;
	for (int i = 0; i < N; i++) {
		ANS = min(ANS, abs(SUM - Cur * 2));
		Cur += A[i];
	}
	cout << ANS << endl;
}

Measured memory_bytes: 1792
/* Complete Binary Tree */
#include <stdio.h>
#define MAX 250

int main()
{
    int n, i, a[MAX];

    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }

    for(i=0; i<n; i++){
        printf("node %d: key = %d, ", i+1, a[i]);

        if(i){
            printf("parent key = %d, ", a[(i+1)/2-1]);
        }
        if(2*i+1 < n){
            printf("left key = %d, ", a[2*i+1]);
        }
        if(2*i+2 < n){
            printf("right key = %d, ", a[2*i+2]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int dp[1000][1000];

int main(){
    while(true){
	vector< pair<int,int> > hr;
	int n,m;
	cin >> n;
	if(n == 0) break;
	REP(i,n){
	    int h,r;
	    cin >> h >> r;
	    hr.PB( pair<int,int>(h,r) );
	}
	cin >> m;
	REP(i,m){
	    int h,r;
	    cin >> h >> r;
	    hr.PB( pair<int,int>(h,r) );
	}
	n += m;
	int ans = 0;
	sort(ALL(hr));
	memset(dp,-1,sizeof(dp));
	dp[0][0] = 0;
	REP(i,n){
	    for(int j=0;j<hr[i].first;j++){
		for(int k=0;k<hr[i].second;k++){
		    if(dp[j][k] >= 0)
			dp[hr[i].first][hr[i].second] = max(dp[hr[i].first][hr[i].second], dp[j][k] + 1);
		}
	    }
	}
	REP(i,1000)REP(j,1000) ans = max(ans,dp[i][j]);
	cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5116
#include<cstdio>
using namespace std;
int main()
{

int n,fi,se,th,fo,x1,x2,y1,y2,z1,z2,w1,w2;
while(true)
{
scanf("%d",&n);
if(n==0)break;
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
fi=x1*x2+(-1)*(y1*y2)+(-1)*(z1*z2)+(-1)*(w1*w2);
se=x1*y2+y1*x2+z1*w2+(-1)*w1*z2;

th=x1*z2+(-1)*(y1*w2)+z1*x2+w1*y2;
fo=x1*w2+y1*z2+(-1)*(z1*y2)+w1*x2;

printf("%d %d %d %d\n",fi,se,th,fo);
}
}
return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define mod 1000000007
using namespace std;

ll ipow(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    } 
    return result; 
} 

int main(){
	fio
	ll n,k;
	cin>>n>>k;
	set<ll>s;
	while(k--){
		ll d;
		cin>>d;
		ll a[d];
		for(ll i=0;i<d;i++){
			cin>>a[i];
			s.insert(a[i]);
		}
		
	}
	ll c=0;
	for(ll i=1;i<=n;i++){
		if(s.find(i)==s.end())
		c++;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3644
import bisect

def main():
    n, m = map(int, input().split())
    cities = []
    bucket = [[] for _ in range(n + 1)]

    for _ in range(m):
        p, y = map(int, input().split())
        bucket[p].append(y)
        cities.append((p, y))

    for i in range(1, n + 1):
        bucket[i].sort()

    for p, y in cities:
        n = bisect.bisect_left(bucket[p], y) + 1
        print('%06d%06d' % (p, n))

main()



Measured memory_bytes: 29768
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
//

struct DSU {
    int n;
    vi parent, sz;

    DSU(int n) {
        this->n = n;
        parent.assign(n+1, 0);
        sz.assign(n+1, 1);

        for(int i=0;i<=n;i++)
            parent[i] = i;
    }

    int find(int v) {
        if(v==parent[v])
            return v;
        return parent[v]=find(parent[v]);
    }

    void join(int a, int b) {
        // cout << "join " << a << " " << b << endl;
        a = find(a);
        b = find(b);
        if(a!=b) {
            if(sz[a]<sz[b])
                swap(a, b);

            parent[b]=a;
            sz[a]+=sz[b];
        }
    }

    int size(int v) {
        return sz[find(v)];
    }
};

int m, n;
bool bounded(int x, int y) {
    if(x < 0 or y < 0 or x >= m or y >= n)
        return false;
    return true;
}

int toidx(int i, int j) {
    return i*m + j;
}


int main() {
    sws;
    int n, m;
    cin >> n >> m;

    DSU dsu = DSU(n+1);

    forn(i, m) {
        int a, b;
        cin >> a >> b;

        dsu.join(a, b);
    }

    int res = 0;
    forne(i, 1, n) {
        res = max(res, dsu.size(dsu.find(i)));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4748
A,B,C,D = map(int,input().split())
i = 0
while True:
    if i % 2 == 0:
        C -= B
        if C <= 0:
            break
    else:
        A -= D
        if A <= 0:
            break
    i += 1
if i % 2 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9116
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))
print()

Measured memory_bytes: 15588
#include<stdio.h>

int main()
{
  long long n,i,a,min,max,sum;
  sum=0;
  min=1000000;
  max=-1000000;

  scanf("%lld",&n);

    for(i=0;i<n;i++){
       scanf("%lld",&a); 
         sum=sum+a;
          if(max<a) {max=a;}
          if(min>a) {min=a;}

}

printf("%lld %lld %lld\n", min,max,sum);
return 0;
}




Measured memory_bytes: 2112
n,a, b = map(int, input().split( ))
if (a-b)%2==0:
    print(abs(a-b)//2)
    exit()

if a<b:
    a,b = b,a
ans1 = b-1+(a-b+1)//2
ans2 = (n-a) + (n-(b+n-a)+1)//2

print(min(ans1,ans2))

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

int main(){
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double vecx=x2-x1;
	double vecy=y2-y1;
	double norm=sqrt(vecx*vecx + vecy*vecy);
	double vx=vecx/norm;
	double vy=vecy/norm;
	double vx90=-vy;
	double vy90=vx;
	double x3,y3,x4,y4;
	x3=x2+vx90*norm;
	y3=y2+vy90*norm;
	x4=x1+vx90*norm;
	y4=y1+vy90*norm;
	cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
//#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
  	
    
    int x=0;
    int ans=1,y=0;
  	if(a[0]!=0)ans=0;
  	sort(a,a+n);  
  for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            if(a[i]-a[i-1]!=1)ans=0;
          	x=i-y;
            y=i;
        }
      	
        ans*=(x);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 1024
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto a = readln.split.to!(int[]);

  int[int] b;
  foreach (ai; a) ++b[ai];

  auto c = b.values;
  c.sort!"a > b";

  foreach (ref ci; c) {
    if (ci < 3) break;
    ci = ci % 2 == 0 ? 2 : 1;
  }

  c.sort!"a > b";
  foreach (ref d; c.chunks(2)) {
    if (d.length == 1 || d[0] == 1 && d[1] == 1) break;
    --d[0];
    --d[1];
  }

  writeln(c.sum);
}


Measured memory_bytes: 9148
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    ll cnt=0;
    int rm=n/r,gm=n/g;
    for(int i=0; i<=rm; ++i){
        //G,Bが0個
        if( (i*r) == n){
            cnt++;
            continue;
        }
        for(int j=0; j<=gm; ++j){
            //Bが0個
            if( (i*r+j*g) == n){
                cnt++;
                continue;
            }
            //Bを取る場合
            else if( ((n-(i*r+j*g))%b) == 0 && (n-(i*r+j*g) > 0) ){
                cnt++;
                continue;
            }
        }
    }
    cout << cnt << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    vector<int> A(N),B(N);
    rep(i,0,N)A[i] = B[N-i-1] = (i+1) * 30000;
    rep(i,0,N){
        B[V[i] - 1] += i;
    }
    rep(i,0,N)cout << A[i] << " \n"[i==N-1];
    rep(i,0,N)cout << B[i] << " \n"[i==N-1];
}

Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -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; }

string S;

int main() {
    cin >> S;
    int N = S.size();
    REP (i, N / 2) {
        if (S[i] != S[N - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    REP (i, N / 2 / 2) {
        if (S[i] != S[N/2 - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    REP (i, N / 2 / 2) {
        if (S[i + N/2 + 1] != S[N - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
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 powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","w",stdout);
    int x;
    cin >> x;
    if (x >= 30)
    {
        printf("Yes\n");
    } else
    {
        printf("No\n");
    }
    return 0;
}




Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int L = sc.nextInt();
			if(L == 0)break;
			
			int count = 0;
			int sum = 0;
			int a = 0;
			boolean is = true;
			while(count < 12){
				sum += sc.nextInt() - sc.nextInt();
				count++;
				if(L <= sum && is){
					a = count;
					is = false;
				}
			}
			if(L <= sum)System.out.println(a);
			else System.out.println("NA");
		}
	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL N, M;
bool isbi(int u, VI& col, VVI& G){
  for(int to: G[u]){
	if(col[to] < 0){
	  col[to] = 1 ^ col[u];
	  if(!isbi(to, col, G)) return false;
	}
	else{
	  if(col[u] == col[to])
		return false;
	}
  }
  return true;
}

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

  cin >> N >> M;
  VVI G(N);
  REP(i,M){
	int u, v;
	cin >> u >> v;
	--u;
	--v;
	G[u].PB(v);
	G[v].PB(u);
  }

  VI col(N, -1);
  col[0] = 0;
  if(!isbi(0, col, G)){
	cout << N * (N-1) / 2 - M << endl;
  }
  else{
	VL num(2);
	REP(i,N) num[col[i]]++;
	cout << num[0] * num[1] - M << endl;
  }
  

  return 0;
}


Measured memory_bytes: 6528
S = gets.chomp

ans = 0
c = 0
mods = [0] * 2019
mods[0] = 1
d = 1
S.chars.reverse.each do |s|
    c = (c + s.to_i * d) % 2019
    d *= 10
    d %= 2019
    ans += mods[c]
    mods[c] += 1
end

p ans

Measured memory_bytes: 26368
N,M = map(int,input().split())
l = []
for i in range(N):
  l.append(list(map(int,input().split())))

ans = 0
for i in range(2**3):
  bs = format(i,"03b")
  lsum = []
  for j in range(N):
    lsum.append(sum([l[j][_]*(2*int(bs[_])-1) for _ in range(3)]))
  lsum.sort(reverse=True)
  ans = max(ans,sum(lsum[:M]))
print(ans)  

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int x[200000];
int z[200000];
int len=0;
int main()
{
    int n,i,s=0,mark;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x[i]);
    }
    for(i=n; i>0; i--)
    {
        s=0;
        mark=i;
        while(mark<=n)
        {
            s+=z[mark];
            mark+=i;
        }
        if(s%2!=x[i])
        {
            z[i]=1;
            len++;
        }
    }
    printf("%d\n",len);
    for(i=1; i<=n; i++)
        if(z[i])
        printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long mod = 1e9 + 7;

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<int> occs(26);
	for (int i = 0; i < n; ++i) {
		++occs[s[i] - 'a'];
	}

	long long ans = 1;
	for (int i = 0; i < 26; ++i) {
		ans *= (occs[i] + 1);
		ans %= mod;
	}

	cout << ans - 1 << "\n";

	return 0;

}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int N, M, Q;
vector<int> a, b, c, d;
long long ans;
long long res, res2;
vector<int> num;
long long dfs(int i, int u){
    long long t2 = 0;
    if(u == N){
        long long t = 0;
        for(int j = 0; j < Q; j++){
            if(num[b[j] -1] -  num[a[j] - 1] == c[j]) t += d[j];
        }
        return t;
    }
    num[u] = i;
    for(int j = 0; j  + i <= M; j++){
        t2 = max(t2, dfs(i+j, u + 1));
    }
    return t2;
}
int main(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ans = 0;
    num.resize(N);
    for(int i = 1; i <= M; i++){
        ans = max(ans, dfs(i, 0));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
while True:
  m,f,r = map(int,input().split())
  if m+f+r == -3:
    break;
  if m==-1 or f==-1:
    print('F')
  elif m+f >= 80:
    print('A')
  elif 65 <= m+f < 80:
    print('B')
  elif 50 <= m+f < 65:
    print('C')
  elif 30 <= m+f <50:
    print('C' if r>=50 else 'D')
  else:
    print('F')


Measured memory_bytes: 5592
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    vector<int> a(3);
    for(int i=0; i<3; i++ ) cin >> a[i];
    sort(a.begin(),a.end());
    int ans=0;
    ans+=a[2]-a[1];
    if((a[1]-a[0])%2==0){
        cout << ans+(a[1]-a[0])/2 << endl;
    }
    else{
        cout << ans+(a[1]-a[0])/2+2 << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

void add(vector<ll>& c1, vector<ll>& c0, int l, int r, int s) {
  if (l <= r) {
    c1[l] += 1;
    c1[r + 1] -= 1;
    c0[l] += s - l;
    c0[r + 1] -= s - l;
  }
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      --a[i];
    }
    vector<ll> c1(m + 1, 0), c0(m + 1, 0);
    ll cost = 0;
    for (int i = 0; i + 1 < n; i++) {
      if (a[i] < a[i + 1]) {
        cost += a[i + 1] - a[i];
        add(c1, c0, a[i] + 1, a[i + 1], 0);
      } else {
        cost += m + a[i + 1] - a[i];
        add(c1, c0, a[i] + 1, m - 1, 0);
        add(c1, c0, 0, a[i + 1], m - a[i] - 1);
      }
    }
    for (int i = 1; i < m; i++) {
      c1[i] += c1[i - 1];
      c0[i] += c0[i - 1];
    }
    ll mx = 0;
    for (int i = 0; i < m; i++) {
      mx = max(mx, c1[i] * i + c0[i]);
    }
    cout << cost - mx << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
auto random_address = [] { char *p = new char; delete p; return sll(p); };
const sll SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);

ve<ll> vec;
void primefactor(ll n)
{
    ll b=1;
    while (n % 2 == 0)  
    {  
        b*=2ll;
        n = n/2;  
    }  
    if(b>1)
        vec.pb(b);
    b=0;
    for (ll i = 3; i*i <= n; i = i + 2)  
    {   
        b=1;
        while (n % i == 0)  
        {  
            b*=i;
            n = n/i;  
        }  
        if(b>1)
            vec.pb(b);
    }  
    if (n > 2)  
        vec.pb(n);
}

ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool fs(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}

int main()
{
    FAST;
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    n=2ll*n;
    primefactor(n);
    ll m=(ll)vec.size(),ans=n;
    if((n/2ll)%2==1)
        ans=(n/2ll)-1;
    for(ll i=0;i<(1ll<<m);i++)
    {
        ll a=1,b=1;
        for(ll j=0;j<m;j++)
        {
            if((i>>j)&1)
                a*=vec[j];
            else
                b*=vec[j];
        }
        ll x=0,y=0,g=0;
        bool bb=fs(a,(-1ll)*b,1,x,y,g);
        if(x==0 || y==0)
        {
            x+=b;
            y+=a;
        }
        if(x<0 && y<0)
        {
            x=(-1ll)*x;
            y=(-1ll)*y;
            ll k1=max(ceil(x/(ld)b),ceil(y/(ld)a));
            x=(k1*b)-x;
            y=(k1*a)-y;
        }
        ans=min(ans,b*y);
    }
    cout<<ans;
    subt;
    return 0;
}


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

int calc(std::vector<std::vector<int>> &a, int m, int n) {
  int sum = 0, hn = a.size(), wn = a.at(0).size();
  for (int i = 0; i < hn; ++i) {
    for (int j = 0; j < wn; ++j) {
      int d = std::min(std::abs(i - m), std::abs(j - n));
      sum += d * a.at(i).at(j);
    }
  }
  return sum;
}

int solve(std::vector<std::vector<int>> &a) {
  int ans = 100 * 25 * 25*25, hn = a.size(), wn = a.at(0).size();
  for (int i = 0; i < hn; ++i) {
    for (int j = 0; j < wn; ++j) {
      ans = std::min(ans, calc(a, i, j));
    }
  }
  return ans;
}

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::vector<int>> a(h, std::vector<int>(w, 0));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      std::cin >> a.at(i).at(j);
    }
  }
  std::cout << solve(a) << std::endl;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int count = 0;
  cin >> s ;
  for(int i = 0;i < 3;i ++){
    if(s.at(i) == '1'){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3604
import sys
N = int(input().strip())
lines = sorted([list(map(int, line.strip().split())) for line in sys.stdin], key=lambda x:x[1])
now_time = 0
for l in lines:
  now_time += l[0]
  if now_time > l[1]:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 55260
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void change(char words[]){
	int len,i;
	len=strlen(words);
	for(i=0;i<len;i++){
		if(isupper(words[i])){
			words[i]=tolower(words[i]);
		}
	}
}
int main(){
	char W[11],T[100100];
	int i,cnt=0;
	scanf("%s",W);
	change(W);
	for(;;){
		scanf("%s",T);
		if(strcmp(T,"END_OF_TEXT")==0)break;
		change(T);
		if(strcmp(T,W)==0)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 1776
#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;

const int MAX_N=2000,MAX_G=10;
int N,K;
pair<int,int> book[MAX_N];	//first=G,second=C
int genre[MAX_G+1];
int genre2[MAX_G+1];	//????????????????????£???????????¬??????????????????
int table[MAX_G+1][MAX_N+1];
int dp[MAX_G+1][MAX_N+1];

void solve();

int main(){
	scanf("%d %d",&N,&K);
	for (int i=0;i<N;i++){
		int C,G;
		scanf("%d %d",&C,&G);
		book[i]=make_pair(G,C);
	}
	solve();
	return 0;
}

void solve(){
	sort(book,book+N);
	//table??????????????????
	int i,j,k;
	for (i=0;i<N;i++){
		genre2[book[i].first]++;
	}
	genre[1]=genre2[1];
	for (i=2;i<=MAX_G;i++){
		genre[i]=genre[i-1]+genre2[i];
	}
	for (i=1;i<=MAX_G;i++){
		for (j=genre[i]-1;j>=genre[i-1];--j){
			table[i][genre[i]-j]=table[i][genre[i]-j-1]+book[j].second;
		}
	}
	for (i=0;i<MAX_G;i++){
		//?????¨???????£?????????¨??????????????????
		for (j=2;j<=genre2[i+1];j++){
			table[i+1][j]+=j*(j-1);
		}
	}
	//???????¨?????????§?§£????±???????
	for (i=0;i<MAX_G;i++){
		for (j=0;j<=K;j++){
			for (k=0;k<=genre2[i+1] && j+k<=K;k++){
				dp[(i+1)][j+k]=max(dp[(i+1)][j+k],dp[i][j]+table[(i+1)][k]);
			}
		}
	}
	printf("%d\n",dp[MAX_G][K]);
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<bool> rate(8, false);
  int free = 0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i] < 400)
      rate[0] = true;
    else if(A[i] < 800)
      rate[1] = true;
    else if(A[i] < 1200)
      rate[2] = true;
    else if(A[i] < 1600)
      rate[3] = true;
    else if(A[i] < 2000)
      rate[4] = true;
    else if(A[i] < 2400)
      rate[5] = true;
    else if(A[i] < 2800)
      rate[6] = true;
    else if(A[i] < 3200)
      rate[7] = true;
    else
      free++;
  }
  int ans = 0;
  for(int i=0; i<8; i++)
    if(rate[i])
      ans++;
  cout << max(ans, 1) << ' ' << ans+free << endl;
  return 0;
}

Measured memory_bytes: 256
S=io.read()
T=io.read()
local s=#S
local t=#T
local res=false
local q=0
local news
local ans
while s>=t do
    if string.sub(S,s,s)=="?" or string.sub(S,s,s)==string.sub(T,t,t) then
        t=t-1
        if t==0 then
            q=s
            res=true
            news=string.sub(S,1,q-1)..T..string.sub(S,q+#T,#S)
            ans=string.gsub(news,"?","a")
            print(ans)
        end
        if string.sub(S,s-1,s-1)~="?" and string.sub(S,s-1,s-1)~=string.sub(T,t,t) then
      		s=s+#T-t-1
            t=#T
        end
    end
    s=s-1
    if res==true then
        break
    end
end
if res==false then
    print("UNRESTORABLE")
end

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong mask[20];

llong n;
llong a[20];
llong y[20][20];
llong x[20][20];
llong ans = 0;

int main() {
    mask[1] = 1;
    for (llong i = 2; i < 20; i++) {
        mask[i] = mask[i - 1] * 2;
    }

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

        for (int j = 0; j < a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    for (llong i = 0; i < (1 << n); i++) {
        llong k = i;
        llong cnt = 0;
        llong b = 0;
        bool valid = true;

        while (k > 0) {
            if (k & 1) {
                for (llong j = 0; j < a[cnt]; j++) {
                    if ((i & mask[x[cnt][j]]) &&  !y[cnt][j]) {
                        valid = false;
                    }
                    else if (!(i & mask[x[cnt][j]]) && y[cnt][j]) {
                        valid = false;
                    }
                }
                b++;
            }

            cnt++;
            k >>= 1;
        }

        if (valid) ans = max(ans, b);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

signed main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif
	/************************************/
	
	int n; cin>>n;
	string s; cin>>s;
	int ans = 0;
	for(int i=1; i<n; i++)
		ans += s[i] != s[i-1];
	cout<<ans+1<<"\n";
	
	
}

Measured memory_bytes: 512
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,Q,i;cin>>n>>Q;
	string s;cin>>s;
	s.pub('#');
	s.ins(s.begin(),'#');
	vector<pair<char,char>>ma(Q);
	for(i=0;i<Q;i++){
		char c,d;cin>>c>>d;
		ma[i]=mp(c,d);
	}
	int bmin=0,bmax=n+1,ans=n;
	while(bmax-bmin>1){
		int bgen=(bmin+bmax)/2,x=bgen;
		for(auto it:ma){
			if(s[x]==it.fir){
				if(it.sec=='L'){x--;}
				else{x++;}
			}
		}
		if(x==0){bmin=bgen;}
		else{bmax=bgen;}
	}
	ans-=bmin;
	bmin=0;bmax=n+1;
	while(bmax-bmin>1){
		int bgen=(bmin+bmax)/2,x=bgen;
		for(auto it:ma){
			if(s[x]==it.fir){
				if(it.sec=='L'){x--;}
				else{x++;}
			}
		}
		if(x==n+1){bmax=bgen;}
		else{bmin=bgen;}
	}
	ans-=n+1-bmax;
	maxeq(ans,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int k,n;
int main()
{
	scanf("%d",&k);
	if(k<=500)
	{
		printf("%d\n",k);
		for(int i=1;i<=k;i++)
		{
			for(int j=1;j<=k;j++)printf("%d ",i);
			puts("");
		}
		return 0;
	}
	n=(k+3)/4*2;
	cout<<n<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int r=(i+j)%n;
			if(i%2)r+=n;
			if(r>=k)r-=n;
			printf("%d ",r+1);
		}
		puts("");
	}
}

Measured memory_bytes: 1152