akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define debug(x)         cout << '>' << #x << ':' << x << endl;
// #define int               long long
// #define ld               long double
#define endl "\n";
#define lb lower_bound
#define ub upper_bound
const int mod = 1000000007;
using namespace std;
// const int N = 1e5 + 5; 
// int n;
// int a[N];

int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

int x,n ; vi v; cin >> x >> n;
for(int i = 0; i<n; i++){
	int a; cin >>a;
	v.pb(a);
}

sort(all(v));
auto it = std::find (all(v), x);
bool flag = false;
if(n != 0 && it != v.end()){

for(int i = 1; i <= 101; i++){
 it = std::find (all(v), x-i);
 if(it == v.end()){
    cout << x-i << endl;
    flag = true;
    // return 0;
    break;
 } 
 // i++;
it = std::find (all(v), x+i);
 if(it == v.end()){
    cout << x+i << endl;
    // return 0;
    flag = true;
    break;
 } 
 // j++;


}
}

if(!(flag)){
	cout << x << endl;
}


return 0;
}

Measured memory_bytes: 3664
#include <iostream>
typedef long long ll;
using namespace std;

ll dp[1000010], mod=1000000007;

int main(void){
    int N, H, D;
    cin >> N >> H >> D;
    ll mult=0;
    dp[0]=1;
    for(int i=1; i<=N; ++i){
        (dp[0] *= i) %= mod;
        (mult += dp[0]) %= mod;
    }
    ll sum=dp[0];
    for(int i=1; i<H; ++i){
        dp[i]=(sum*mult)%mod;
        if(i>=D) (sum += mod-dp[i-D]) %= mod;
        (sum += dp[i]) %= mod;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

int h[202020];
ll dp[202020];
int N, K;

ll rec(int i){
    if(dp[i] < LINF) return dp[i];
    if(i <= 0) return 0;

    ll res = INF;
    for(int k=1;k<=K;k++){
        if(i - k >= 0) chmin(res, rec(i-k) + abs(h[i] - h[i-k]));
    }

    return dp[i] = res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP(i,N) cin >> h[i];
    REP(i,N) dp[i] = LINF;

    cout << rec(N-1) << endl;
}


Measured memory_bytes: 6144
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w==0 && h==0) break;
			
			String s;
			int t;
			int d = 0;
			int x = 0;
			int y = 0;
			char c;
			while(true){
				s = sc.next();
				c = s.charAt(0);
				if(c=='S'){
					System.out.println((x+1) + " " + (y+1));
					break;
				}else if(c=='R'){
					d++;
					if(d==4) d=0;
				}else if(c=='L'){
					d--;
					if(d==-1) d=3;
				}else if((c=='F' && d==0) || (c=='B' && d==2)){
					t = sc.nextInt();
					y += t;
					if(y>h-1) y=h-1;
				}else if((c=='F' && d==1) || (c=='B' && d==3)){
					t = sc.nextInt();
					x += t;
					if(x>w-1) x=w-1;
				}else if((c=='F' && d==2) || (c=='B' && d==0)){
					t = sc.nextInt();
					y -= t;
					if(y<0) y=0;
				}else if((c=='F' && d==3) || (c=='B' && d==1)){
					t = sc.nextInt();
					x -= t;
					if(x<0) x=0;
				}	
			}
			
		}
	}	
}

Measured memory_bytes: 25848
#include <bits/stdc++.h>
using namespace std;
int read();
int n, S;
struct P {
    long long p;
    int x;
    bool operator<(P a) { return p == a.p ? x > a.x : p < a.p; }
};
vector<P> st[2];

long long res;

int main() {
    n = read(), S = read();
    for (int i = 1, x; i <= n; ++i)
        x = read(), st[x > S].push_back((P){read(), x});
    if (!st[0].size()) return printf("%lld\n", st[1].back().x - S), 0;
    if (!st[1].size()) return printf("%lld\n", S - st[0].front().x), 0;
    reverse(st[0].begin(), st[0].end());
    int now = st[st[1].back() < st[0].back()].back().x;
    while (st[0].size() && st[1].size()) {
        int t = st[1].back() < st[0].back();
        res += abs(now - st[t ^ 1].back().x), now = st[t ^ 1].back().x;
        st[t ^ 1].back().p += st[t].back().p, st[t].pop_back();
    }
    printf("%lld\n", res += abs(S - now));
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

Measured memory_bytes: 6644
#include<iostream>
#include<string>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	if (A > 8 || B > 8) {
		cout << ":(" << endl;
	}
	else {
		cout <<"Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

using namespace std;

int main(void)
{
    long long A, B, C, D, C1, D1, r, i, x, y, z, tmp;

    cin >> A >> B >> C >> D;

    C1 = C;
    D1 = D;

    if(C1 < D1){
        tmp = C1;
        C1 = D1;
        D1 = tmp;
    }

    r = C1 % D1;
    while(r!=0){
        C1 = D1;
        D1 = r;
        r = C1 % D1;
    }

    r = C * D / D1;

    x = B/C - A/C + 1;
    y = B/D - A/D + 1;
    z = B/r - A/r + 1;

    if(A%C!=0) x--;
    if(A%D!=0) y--;
    if(A%r!=0) z--;

    cout << (B-A+1) - (x+y-z) << endl;

    return 0;
}

Measured memory_bytes: 256
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
 
int main() {
  ioso
  #ifndef ONLINE_JUDGE
  //ffe
  #endif
  ll n; cin >> n;
  //string s = "";
  vector<int> s;
  while(n>1) {
    int k = n%26;
    s.push_back(k);
    n /= 26;
    if(k==0) {n-=1;}
  }
  if(n!=0) {s.push_back(n);}

  reverse(s.begin(),s.end());

  string ans = "";

  for(int i=0;i<s.size();i++) {
    if(s[i]==0) {
      ans += 'z';
    }

    else {
      ans += (char)('a'+(s[i]-1));
    }
  }

  cout << ans << endl;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 1e6 + 5;
const int inf = 1e16 + 2;


void solve(int Case) {
    int n;
    cin >> n;
    cout << (((1000 - n % 1000) == 1000) ? 0LL : (1000 - (n % 1000))) << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case ++);
    }
    return 0;
}
 



Measured memory_bytes: 3512
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int main(){
  ll n;
  cin>>n;
  ll a[n];
  rep(i,n){
    cin>>a[i];
  }
  map<ll,ll> mp1,mp2,mp3;
  rep(i,n){
    mp1[i+a[i]]++; mp1[i-a[i]]++;
    mp2[i+a[i]]++; mp3[i-a[i]]++;
  }
  ll x=0,y=0,z=0;
  for(auto p:mp1){
    x+=p.second*(p.second-1)/2;
  }
  for(auto p:mp2){
    y+=p.second*(p.second-1)/2;
  }
  for(auto p:mp3){
    z+=p.second*(p.second-1)/2;
  }
  cout<<x-y-z;
}


Measured memory_bytes: 50940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main(void) {

  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if( s < t ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int m,n,o,i,j,k;
    //float f,g,h;
    //char c,d;
    //string a;
    cin>>m>>n>>o;
    //cin>>m>>c>>n>>d>>i;
    //cin>>f>>g;
    //cin>>c;
    cout<<o/m*n;
    return 0;
}


Measured memory_bytes: 888
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };


const int N=200001;

void solve()
{
    int x;
    cin>>x;
    int ans=1000*((int)x/500);
    x=x%500;
    ans=ans+5*((int)x/5);
    cout<<ans<<endl;
    
}



int32_t main()
{
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
   // cin>>t;
    
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  map<int,int> memo{};
  rep(i,n){
    int buf=memo[i];
    memo[a[i]]++;
  }
  int res=0;
  for (auto it=memo.begin();it!=memo.end();++it){
    int value=it->second;
    int key=it->first;
    if(value!=key){
      if(value>key)res+=value-key;
      else res+=value;
    }
    //cout<<key<<value<<endl;
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 13056
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;
 
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))
 
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg
 
typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<Int, Int> PLL;
typedef pair<double, double> PDD;
typedef complex<double> base;
 
const int INF = 1000000000;
const int MAX = 1007;
const int MAX2 = 50007;
const int ADD = 1000000;
const int MAXD = 256;
const int BASE = 1000000000;
const int MOD = 1000000007;

int n, m, q;
int T[MAX];
char S[MAX][MAX];
int W[MAX];
int G[MAX][MAX][4];
int D[MAX][MAX];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

bool OK1(int x, int y)
{
	return (x >= 0 && y >= 0 && x < n && y < m);
}

bool OK2(int x, int y)
{
	return (x >= 0 && y >= 0 && x <= n && y <= m);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("distance.in",  "r", stdin);
	//freopen("distance.out", "w", stdout);
	//freopen("out.txt" , "w" , stdout);
	
	cin >> m >> n >> q;
	int sx, sy, fx, fy;
	cin >> sy >> sx >> fy >> fx;
	
	FOR (i,0,q)
	{
		int x, y;
		scanf("%d %d", &y, &x);
		scanf("%d %s", &T[i], S[i]);
		int len = strlen(S[i]);
		FOR (j,0,len)
		{
			char c = S[i][j];
			if (c == 'L')
				W[j] = 3;
			else
			if (c == 'R')
				W[j] = 1;
			else
			if (c == 'D')
				W[j] = 2;
			else
				W[j] = 0;
		}
		FOR (it,0,T[i])
		{
			FOR (j,0,len)
			{
				int xx = x+dx[W[j]], yy = y+dy[W[j]];
				if (!OK1(xx, yy))
					continue;
				G[x][y][W[j]] ++;
				G[xx][yy][(W[j]+2)%4] ++;
				x = xx;
				y = yy;
			}
		}
	}
	
	FOR (i,0,n+1)
		FOR (j,0,m+1)
			D[i][j] = INF;
	D[sx][sy] = 0;
	priority_queue<pair<int, PII> > Q;
	Q.push(MP(0, MP(sx, sy)));
	
	while (!Q.empty())
	{
		pair<int, PII> p = Q.top();
		int val = -p.first;
		int x = p.second.first;
		int y = p.second.second;
		Q.pop();
		if (D[x][y] < val)
			continue;
		FOR (d,0,4)
		{
			int xx = x+dx[d];
			int yy = y+dy[d];
			if (!OK2(xx, yy))
				continue;
			int add = 0;
			if (d == 1)
				add = G[x][y][0];
			else
			if (d == 2)
				add = G[x][y][3];
			else
			if (d == 0)
				add = G[x-1][y-1][1];
			else
				add = G[x-1][y-1][2];
			if (D[xx][yy] > val + add)
			{
				D[xx][yy] = val + add;
				Q.push(MP(-D[xx][yy], MP(xx, yy)));
			}
		}
	}
	
	int res = D[fx][fy];
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 18792
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;

int abs(int i) {
	if( i < 0 ) return -i;
	return i;
}

int max(int p, int q) {
	if( q > p ) return q;
	return p;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
 
 
	while (1){
		int w, d;
		cin >> w >> d;
		if( w == 0 && d == 0 ) break;
		int h[2][21];
		for(int i = 0; i < 21 * 2; i++)
			h[ i / 21 ][ i % 21 ] = 0;
		for(int i = 0; i < w; i++) {
			int tmp;
			cin >> tmp;
			h[0][tmp] ++;
		}
		for(int i = 0; i < d; i++) {
			int tmp;
			cin >> tmp;
			h[1][tmp] ++;
		}
		int ans = 0;
		for(int i = 1; i < 21; i++) {
			ans += max( h[0][i], h[1][i] ) * i;
		}
		cout << ans << endl;


	}
 
	//while (1){}
	return 0;
}

Measured memory_bytes: 1160
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j+= 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    int x = 0, cnt = 1;
    for (int i = 0; i < N; i++) {
        x += L[i];
        if (x <= X) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
ll n, m, a[10];
string str[10010], test[10];
map<ll, ll> mp;
map<ll, string> np;
bool jud[10010], h[10];
int main(void)
{
	mp[1] = 2, mp[2] = 5, mp[3] = 5, mp[4] = 4;
	mp[5] = 5, mp[6] = 6, mp[7] = 3, mp[8] = 7;
	mp[9] = 6;
	np[1] = "1", np[2] = "2", np[3] = "3", np[4] = "4", np[5] = "5";
	np[6] = "6", np[7] = "7", np[8] = "8", np[9] = "9";
	jud[0] = true;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) cin >> a[i];
	for (ll i = 2; i <= n; i++)
	{
      	for (int j = 0; j < m; j++) h[j] = false;
		for (ll j = 0; j < m; j++)
		{
			if (i < mp[a[j]]) continue;
			if (!jud[i - mp[a[j]]]) continue;
			h[j] = true;
			test[j] = str[i - mp[a[j]]] + np[a[j]];
		}
		ll len = 0, num = -1;
		for (ll j = 0; j < m; j++)
		{
			if (!h[j]) continue;
			if (test[j].length() > len)
			{
				len = test[j].length();
				num = j;
			}
			else if (test[j].length() == len)
			{
				if (test[j] > test[num])
				{
					num = j;
				}
			}
		}
		if (num == -1) continue;
		str[i] = test[num];
		jud[i] = true;
	}
	for (ll i = 0; i < str[n].length(); i++) cout << str[n][i];
	cout << endl;
}


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

int main () {
	
	int x;
	cin >> x;
	
	int ans = 0;
	ans += x / 500 * 1000;
	x = x % 500;
	ans += x / 5 * 5;
	x = x % 5;
	cout << ans << endl;
	
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int A[1111];

signed main(){
    cin>>N>>K;
    rep(i,N)cin>>A[i];

    vint X;
    rep(i,N){
        int sum=0;
        for(int j=i+1;j<=N;j++){
            sum+=A[j-1];
            X.pb(sum);
        }
    }

    int ans=0;
    for(int i=50;i>=0;i--){
        int v=ans+(1ll<<i);
        int num=0;
        rep(j,X.size())if((X[j]&v)==v)num++;
        if(num>=K)ans=v;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6128
a = [int(i) for i in input().split()]
list = []

for i in range(a[0]):
    list.append([])

for i in range(a[1]):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        list[cmd[1]].append(cmd[2])

    elif cmd[0] == 1:
        maped = map(str, list[cmd[1]])
        output = " ".join(maped)
        print(output)

    elif cmd[0] == 2:
        list[cmd[1]] = []



Measured memory_bytes: 60472
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#define MaxN 100000+100
using namespace std;
int point[MaxN][2];
vector<int>Ve[MaxN];
void DFS(int Point,int jo)
{
    if(point[Point][jo]==1)
        return ;
    point[Point][jo]=1;
    for(int i=0;i<Ve[Point].size();i++)
        DFS(Ve[Point][i],1-jo);
}
int main()
{
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        Ve[a].push_back(b);
        Ve[b].push_back(a);
    }
    DFS(1,1);
    long long a,b,c;
    a=b=c=0;
    for(int i=1;i<=N;i++)
    {
        if(point[i][0] && point[i][1])
            c++;
        else
            if(point[i][0])
                a++;
            else
                b++;
    }
    if(c==0)
        printf("%lld\n",a*b-M);
    else
        printf("%lld\n",c*(c-1)/2-M);
    return 0;
}


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

int n, m;
long int ans = 0;
vector< pair<long int, int> > p(100000);

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

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        p.at(i) = make_pair(a,b);
    }

    sort(p.begin(), p.begin() + n);

    int count = 0;

    for (int i = 0; i < n; ++i)
    {
        if (count + p.at(i).second < m)
        {
            count += p.at(i).second;
            ans += p.at(i).first*p.at(i).second;
        } else {
            ans += p.at(i).first*(m-count);
            break;
        }
    }

    cout << ans << endl;
}

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

int main(){
    int n;

    while(cin >> n,n){
        vector<int> m(n);
        int set[100][100]={{}};
        for(int i=0;i<n;i++){
            cin >> m[i];
            for(int j=0;j<m[i];j++){
                int p;
                cin >> p;
                set[i][p]=1;
            }
        }

        int k;
        cin >> k;
        vector<int> l(k);
        for(int i=0;i<k;i++){
            cin >> l[i];
        }

        int frg=0;
        for(int i=0;i<n;i++){
            int sfrg=1;
            for(int j=0;j<k;j++){
                sfrg*=set[i][l[j]];
            }
            if(sfrg==1){
                if(frg==0)frg=i+1;
                else frg=-1;
            }
        }
        if(frg>0)cout << frg << endl;
        else cout << -1 << endl;
    }
    return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    ll a, b, c, K;
    cin >> a >> b >> c >> K;

    if(a >= K) {
        cout << min(a,K) << endl;
    } else {
        ll left = K-a;
        if(left <= b) {
            cout << a << endl;
        } else {
            cout << min(a,K) - (left-b) << endl;
        }
    }
    return 0;
}
/** atcoder **/


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

//AGC007-A-Shik and Stone
//http://agc007.contest.atcoder.jp/tasks/agc007_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4 5");
            WillReturn.Add("##...");
            WillReturn.Add(".##..");
            WillReturn.Add("..##.");
            WillReturn.Add("...##");
            //Possible
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 3");
            WillReturn.Add("###");
            WillReturn.Add("..#");
            WillReturn.Add("###");
            WillReturn.Add("#..");
            WillReturn.Add("###");
            //Impossible
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("4 5");
            WillReturn.Add("##...");
            WillReturn.Add(".###.");
            WillReturn.Add(".###.");
            WillReturn.Add("...##");
            //Impossible
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int H = wkArr[0], W = wkArr[1];
        int UB_X = W - 1, UB_Y = H - 1;

        char[,] BanArr = new char[UB_X + 1, UB_Y + 1];

        for (int Y = 0; Y <= UB_Y; Y++) {
            for (int X = 0; X <= UB_X; X++) {
                BanArr[X, Y] = InputList[Y + 1][X];
            }
        }
        int SharpCnt = BanArr.Cast<char>().Count(A => A == '#');

        int CurrX = 0, CurrY = 0;
        bool[,] IsVisitedArr = new bool[UB_X + 1, UB_Y + 1];

        while (true) {
            IsVisitedArr[CurrX, CurrY] = true;

            //クリア判定
            if (CurrX == UB_X && CurrY == UB_Y) {
                if (IsVisitedArr.Cast<bool>().Count(A => A) == SharpCnt) {
                    Console.WriteLine("Possible");
                }
                else Console.WriteLine("Impossible");
                return;
            }

            bool CanMoveShita = false; //下に移動可能か？
            bool CanMoveMigi = false; //右に移動可能か？

            if (CurrY < UB_Y && BanArr[CurrX, CurrY + 1] == '#') CanMoveShita = true;
            if (CurrX < UB_X && BanArr[CurrX + 1, CurrY] == '#') CanMoveMigi = true;

            if (CanMoveShita && CanMoveMigi) {
                break;
            }
            else if (CanMoveShita) {
                CurrY++; continue;
            }
            else if (CanMoveMigi) {
                CurrX++; continue;
            }
            else break;
        }
        Console.WriteLine("Impossible");
    }
}


Measured memory_bytes: 2904
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int A, B;
        static string S;
        
        public static void Input()
        {
            var cin = new Solve();

            var input = cin.SplitReader();
            A = input[0];
            B = input[1];
            S = Console.ReadLine();
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            string ans = "Yes";
            for(var i = 0; i < S.Length; i++)
            {
                if (i == A)
                {
                    if (S[i] != '-')
                    {
                        ans = "No";
                        break;
                    }
                }
                else
                {
                    if (S[i] - '0' < 0 || S[i] - '0' > 9)
                    {
                        ans = "No";
                        break;
                    }
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
const int N=300005;
int n,m;
struct BIT{
	int c[N];
	inline int lowbit(int x){return x&(-x);};
	inline void update(int x,int y){
		for (;x<=m+2;x+=lowbit(x)) c[x]+=y;
	}
	inline int query(int x){
		int ans=0;for (;x;x-=lowbit(x)) ans+=c[x];return ans;
	}
}T;
struct Node{
	int l,r;
}a[N];
inline bool cmp(Node a,Node b){
	return a.r-a.l<b.r-b.l;
}
int main (){
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf ("%d%d",&a[i].l,&a[i].r),a[i].l+=2,a[i].r+=2;
	sort(a+1,a+n+1,cmp);
	for (int d=1,now=1;d<=m;d++){
		for (;now<=n;now++)
			if (a[now].r-a[now].l+1<d)
				T.update(a[now].l,1),T.update(a[now].r+1,-1);
			else break;
		int ans=n-now+1;
		for (int i=0;i<=m;i+=d)
			ans+=T.query(i+2);
		printf ("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	}
}

Measured memory_bytes: 100728
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(long long N, std::string S){
  bool ans = (N%2==0LL);
  if(!ans){
    yn(false); return;
  }
  rep(i,N/2){
    ans &= (S[i]==S[i+N/2]);
  }
  yn(ans);
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


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

int main(){
    int coin_d, coin_b, norma,day;
    scanf("%d %d %d",&coin_d,&coin_b,&norma);
    day = (norma/(coin_d*7+coin_b))*7;
    if((norma%(coin_d*7+coin_b))/coin_d >= 7){
        day = day+7;
    }else if((norma%(coin_d*7+coin_b))%coin_d > 0){
        day = day + (norma%(coin_d*7+coin_b))/coin_d + 1;
    }else{
        day = day + (norma%(coin_d*7+coin_b))/coin_d;
    }
    cout << day << endl;
    return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>
int main(){
	char s[19];
	int i,n=18;
	scanf("%s",s);
	for(i = 0;i <= n;i++){
		if(i == 5|| i == 13){
			printf(" ");
			i = i + 1;
			}
		printf("%c",s[i]);
		}
	printf("\n");
	return 0;
	}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
using namespace std;

void print() { std::cout << std::endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if(sizeof...(tail) != 0)
        std::cout << " ";
    print(std::forward<Tail>(tail)...);
}

template <class T> void print(std::vector<T> &vec) {
    for(auto &a : vec) {
        std::cout << a;
        if(&a != &vec.back())
            std::cout << " ";
    }
    std::cout << std::endl;
}

template <class T> void print(std::vector<std::vector<T>> &df) {
    for(auto &vec : df) {
        print(vec);
    }
}

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

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

    std::vector<int> acopy = a;
    boost::sort(acopy);
    int max = *(acopy.end() - 1);
    int nextMax = *(acopy.end() - 2);

    for(int i = 0; i < n; i++) {
        if(a[i] == max) {
            print(nextMax);
        } else {
            print(max);
        }
    }

    return 0;
}

Measured memory_bytes: 3200
n,d=map(int,input().split())
x=[0]+list(map(int,input().split()))
N=n+1
y=list(range(N))
#print(x)
#print(y)
while d:
  if d&1:
    y=[x[y[i]] for i in range(N)]
  x=[x[x[i]] for i in range(N)]
  d>>=1
res=[0]*N
#print(x)
print(y[1])


Measured memory_bytes: 220684
from heapq import *
Q = int(input())
L, R = [], []
ans = 0
for _ in range(Q):
    a = [int(a) for a in input().split()]
    if a[0] == 1:
        ans += a[2]
        if len(L) == 0 or a[1] <= -L[0]:
            heappush(L, -a[1])
            ans += -L[0] - a[1]
        else:
            heappush(R, a[1])
            ans += a[1] + L[0]
        if len(R) > len(L):
            ans -= R[0] + L[0]
            heappush(L, -heappop(R))
        elif len(L) - len(R) >= 2:
            heappush(R, -heappop(L))
    else:
        print(-L[0], ans)


Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	int ans;
	if(A == B)ans = C;
	else if(A == C)ans = B;
	else ans = A;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


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

	if(N>=1000){
		printf("ABD\n");
	}else{
		printf("ABC\n");
	}

	return 0;
}


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

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD=1e9+7;
 ll binpow(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
void solve(){
   ll n;
   cin >> n;
   map<int,int> mp;
   for(int i=0;i<n;i++){
      int a;
      cin >> a;
      mp[a]++;
   }
   if(n%2==1){
     if(mp[0]!=1){cout << 0;return;}
      for(int i=2;i<=n;i+=2){
          if(mp[i]!=2){cout << 0;return;}
      }
      cout << binpow(2LL,n/2);
   }
   else{
     for(int i=1;i<=n;i+=2){
       if(mp[i]!=2){cout << 0;return;}
     }
     cout << binpow(2LL,n/2);
   }
}


int main(){
  IOS
     solve();
}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid


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

int main()
{
ll p,q,r;
cin>>p>>q>>r;
cout<<min(min(p+q,q+r),r+p)<<endl;
return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	int r;
	cin>>r;
	cout<<r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    int n = int.Parse(Console.ReadLine());
	    if(n%2 == 0) Console.WriteLine((n/2)*(n/2));
	    else Console.WriteLine((n/2+1)*(n/2));
	    
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
#include<stdio.h>
#include<complex>
using namespace std;

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

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

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	
	auto haveOne = [&] {
		int ret = 0;
		for (auto x : a) {
			if (x == 1)ret = 1;
		}
		return ret;
	};
	if (!haveOne()) {
		cout << -1 << endl;
		return;
	}

	int count = 1;
	rep(i, n) {
		if (a[i] == count) {
			count++;
		}
	}
	count--;
	int ans = n - count;
	cout << ans << endl;
	return;
}


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

Measured memory_bytes: 1024
N,M = map(int,input().split())
box = [0]*N
cor = 0
fal = 0

for i in range(M):
  p,s = input().split()
  p = int(p)
  s = str(s)
  
  if s == "WA":
    if box[p-1] != -1:
      box[p-1] += 1
  else:
    if box[p-1] != -1:
      cor += 1
      fal += box[p-1]
      box[p-1] = -1

print(cor,fal)
     

Measured memory_bytes: 3828
S = input()
dp = [0] * len(S)
dp[0] = 1
dp[1] = 1 if S[0] == S[1] else 2
for i in range(2, len(S)):
    if S[i] != S[i - 1]:
        dp[i] = dp[i - 1] + 1  # ここは自明
    else:
        dp[i] = dp[i - 3] + 2
print(dp[-1])


Measured memory_bytes: 11240
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];
        int[] c = new int[9];
        long sum = 0;
        for(int i=0; i<N; i++) {
            a[i] = Integer.parseInt(sc.next());
            if(a[i] < 3200) c[(int)(a[i]/400)]++;
            else c[8]++;
        }
       
        int count = 0;
        for(int i=0; i<8; i++) {
            if(c[i] > 0) count++;
        }
        int ansmin = 1;
        int maxans = count + c[8];
        if(count > 0) ansmin = count;
        System.out.println(ansmin+" "+maxans);
        
    }   
}


Measured memory_bytes: 21716
#include <stdio.h>
int main(void)
{
    int r,c,hairetu[100][100],i,j,l=0,m=0,o=0;
 
    scanf("%d %d",&r,&c);
 
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            scanf("%d",&hairetu[i][j]); 
        }
 
    }
 
 
 
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            l = l + hairetu[i][j];
 
            printf("%d ",hairetu[i][j]);
 
            if(j == c-1 )
            {
                printf("%d\n",l);
 
                o = o + l;
                l = 0;
            }
 
             
             
        }
     
         
    }
 
    for(j=0;j<c;j++)
    {
        for(i=0;i<r;i++)
        {
            m = m + hairetu[i][j] ;
        }
     
        printf("%d ",m);
         
        m = 0;
 
         
    } 
 
 
 
 
    printf("%d\n",o);
 
    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b; }

inline void solve(){
    ll a, b, c, d;

    cin >> a >> b >> c >> d;
    a--;
    ll ax = 0, bx = 0;
    ax = a - a/c - a/d + a/lcm(c,d) ;
    bx = b - b/c - b/d + b/lcm(c,d) ;

    cout<< bx - ax fin;
     
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


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

using namespace std;

int main() {

	long a, b;
	cin >> a >> b;

	if (a == 1) { a = 14; }
	if (b == 1) { b = 14; }
	cout << (a>b? "Alice" : a==b? "Draw" : "Bob") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d[5], in[5];
int main() {
  for(int i = 1; i < 4; i++) {
    int a, b; cin >> a >> b;
    in[a]++, in[b]++;
  }
  for(int i = 1; i <= 4; i++) {
    d[in[i]]++;
  }
  if(d[2] == 2 and d[1] == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll nCr(int n, int r){
  ll num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<int,int> M;
    for(int a : A) M[a]++;
    ll ans = 0;
    for(auto p : M){
        ans += nCr(p.se, 2);
    }
    for(int a : A){
        cout << ans - nCr(M[a], 2) + nCr(M[a] -1, 2) << endl;
    }
}

Measured memory_bytes: 9808
h,w = map(int,input().split())

a = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a[i] = list(input())

#print(a)

for i in range(h):
    for j in range(w):
        if(a[i][j] == "#"):
            continue
        else:
            cnt = 0
            for k in [-1,0,1]:
                for l in [-1,0,1]:
                    if(k == 0 and l == 0):
                        continue
                    else:
                        x = i + k
                        y = j + l 
                        if(0<= x < h and 0<= y < w and a[x][y] == "#"):
                            cnt += 1
            
            a[i][j] = str(cnt)


#print(a)

for i in range(h):
    ans = ''.join(a[i])
    print(ans)


Measured memory_bytes: 9096
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

min_ac1 = 1000
min_ac2 = 1000
for i in range(2 ** d):
    points = 0
    ac = 0
    for j in range(d):
        if ((i >> j) & 1) == 1:
            points += pc[j][0] * 100 * (j + 1) + pc[j][1]
            ac += pc[j][0]
    if points < g:
        l = "{:010b}".format(i)
        l = l[10-d:]
        for k in range(d):
            if l[k] == "0":
                tmp = k
                break
        tmp = -(tmp - d)
        if (g - points + tmp * 100 - 1) // (tmp * 100) < pc[tmp - 1][0]:
            tmp_ac = ac + (g - points + tmp * 100 - 1) // (tmp * 100)
            if tmp_ac < min_ac1:
                min_ac1 = tmp_ac
    if points >= g:
        if ac < min_ac2:
            min_ac2 = ac
    #print(bin(i), ac, points, min_ac1, min_ac2)
print(min(min_ac1, min_ac2))

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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[][][] info = new int[4][3][10];
        
        int num = Integer.parseInt(br.readLine());
        
        //data input
        for(int i = 0; i < num; i++){
            String[] input = br.readLine().split(" ");
            int b = Integer.valueOf(input[0])-1;
            int f = Integer.valueOf(input[1])-1;
            int r = Integer.valueOf(input[2])-1;
            int v = Integer.valueOf(input[3]);
            info[b][f][r] += v;
        }

        //data output
        StringBuilder sb = new StringBuilder();
        for(int b = 0; b < 4; b++){
            for(int f = 0; f < 3; f++){
                for(int r = 0; r < 10; r++){
                    sb.append(" " + info[b][f][r]);
                }
                sb.append("\n");
            }
            if(b != 3)  sb.append("####################\n");
        }

        System.out.print(sb);
    }
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    cout  << min(n, k) * x + max(n-k, 0)* y << endl;
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256