akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

vector<ll> vx;
vector<ll> vy;
vector<ll> vc;
ll mn;

void f(vector<ll> &v1, vector<ll> &v2, ll p){
  ll index2 = 0;
  rep(i,0,v1.sz){
    while(index2<v2.sz){
      if(v1[i]<v2[index2])break;
      index2++;
    }
    if(index2==v2.sz)break;
    mn = min(mn,abs(v1[i]-v2[index2])*p);
  }
}

void f1(){
  vector<pair<ll,ll> > v1;
  vector<pair<ll,ll> > v3;
  set<ll> se; 
  rep(i,0,vx.sz){
    if(vc[i]==1){
      v1.pb(mp(vx[i],vy[i]));
      se.insert(vx[i]);
    }
    if(vc[i]==3){
      v3.pb(mp(vx[i],vy[i]));
      se.insert(vx[i]);
    }
  }
  vector<ll> vv(all(se));
  v1.pb(mp(200010,-1));
  v3.pb(mp(200010,-1));
  sort(all(v1));
  sort(all(v3));
  ll index1 = 0;
  ll index3 = 0;
  rep(i,0,vv.sz){
    vector<ll> va,vb;
    while(v1[index1].fi==vv[i]){
      va.pb(v1[index1].se);
      index1++;
    }
    while(v3[index3].fi==vv[i]){
      vb.pb(v3[index3].se);
      index3++;
    }
    if(va.sz==0||vb.sz==0)continue;
    f(vb,va,5);
  }
}

void f2(){
  vector<pair<ll,ll> > v1;
  vector<pair<ll,ll> > v3;
  set<ll> se; 
  rep(i,0,vx.sz){
    if(vc[i]==2){
      v1.pb(mp(vy[i]-vx[i],vx[i]));
      se.insert(vy[i]-vx[i]);
    }
    if(vc[i]==3){
      v3.pb(mp(vy[i]-vx[i],vx[i]));
      se.insert(vy[i]-vx[i]);
    }
  }
  vector<ll> vv(all(se));
  v1.pb(mp(400010,-1));
  v3.pb(mp(400010,-1));
  sort(all(v1));
  sort(all(v3));
  ll index1 = 0;
  ll index3 = 0;
  rep(i,0,vv.sz){
    vector<ll> va,vb;
    while(v1[index1].fi==vv[i]){
      va.pb(v1[index1].se);
      index1++;
    }
    while(v3[index3].fi==vv[i]){
      vb.pb(v3[index3].se);
      index3++;
    }
    if(va.sz==0||vb.sz==0)continue;
    f(vb,va,10);
  }
}

int main(){
  mn = 1000000000000000000LL;
  ll n;
  cin>>n;
  rep(i,0,n){
    ll a,b;
    char c;
    cin>>a>>b>>c;
    vx.pb(a);
    vy.pb(b);
    if(c=='R'){
      vc.pb(0);
    }
    if(c=='D'){
      vc.pb(1);
    }
    if(c=='L'){
      vc.pb(2);
    }
    if(c=='U'){
      vc.pb(3);
    }
  }
  rep(i,0,4){
    rep(j,0,vx.sz){
      ll x1 = vx[j];
      ll y1 = vy[j];
      ll c1 = vc[j];
      ll x2 = y1;
      ll y2 = -x1;
      ll c2 = (c1+1)%4;
      vx[j] = x2;
      vy[j] = y2;
      vc[j] = c2;
    }
    f1();
    f2();
  }
  if(mn==1000000000000000000LL){
    cout << "SAFE" << endl;
  }
  else{
    cout << mn << endl;
  }
  return 0;
}

Measured memory_bytes: 22788
import Control.Monad
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  rows <- replicateM n $ (map read . words) <$> getLine :: IO [[Int]]
  putStrLn $ if solve (0, 0, 0) rows then "Yes" else "No"


solve :: (Int, Int, Int) -> [[Int]] -> Bool
solve _ [] = True
solve (x0, y0, t0) ([t, x, y]:rows) =
  let d = abs (x0 - x) + abs (y0 - y)
      dt = t - t0
      c = (d < dt && (dt - d) `mod` 2 == 0)
  in (d == dt || c) && solve (x, y, t) rows


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

#define task "B"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Variables
int n,a[53],cnt;
//
// Function

//

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i,1,n)
	{
	    cin >> a[i];
	    if (a[i]!=i) cnt++;
	}
	if (cnt>2) cout << "NO";
	else cout << "YES";
}


Measured memory_bytes: 256
H, W = [int(item) for item in input().split()]
n = int(input())
a = [int(item) for item in input().split()]

arr = [["."] * W for _ in range(H)]
w, h = 0, 0
direction = 0
for c, item in enumerate(a):
    for i in range(item):
        arr[h][w] = c + 1
        if direction == 0 and w < W-1:
            w += 1
        elif direction == 0 and w == W-1:
            h += 1
            direction = 1
        elif direction == 1 and w > 0:
            w -= 1
        elif direction == 1 and w == 0:
            h += 1
            direction = 0

for line in arr:
    for c in line:
        print(c, end=" ")
    print("")
print("")

Measured memory_bytes: 3916
num = input()
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[3])

if a+b+c+d==7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a+b+c-d==7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a+b-c+d==7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a-b+c+d==7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a+b-c-d==7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")
elif a-b+c-d==7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a-b-c+d==7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a-b-c-d==7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define X first
#define Y second
#define pii pair<int, int>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define REP(i, y) rep(i, 0, y - 1)
#define pb push_back
#define mp make_pair
using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
string ch;
int vis[100];
int main()
{
	ll ans = 0;
	cin >> ch;
	int n = ch.size();
	ans = 1ll * n * (n + 1) / 2;
	rep(i, 0, n - 1) vis[ch[i] - 'a'] ++;
	rep(i, 0, 25) ans -= 1ll * vis[i] * (vis[i] + 1) / 2;
	cout << ans + 1;
	return 0;
}



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

int main() {
char a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  if(a==f&&b==e&&c==d){
    cout<<"YES"<<endl;}
    else
      cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int p[12] = {9*9*9*9*9, 9*9*9*9, 9*9*9, 81, 9, 6*6*6*6*6*6, 6*6*6*6*6, 6*6*6*6, 6*6*6, 36, 6, 1};
int dp[112345];

int main() {
	int N;
	cin >> N;
	
	fill(dp, dp + N + 1, INF);
	dp[0] = 0;
	REP(i, N) REP(j, 12) {
		if (i + p[j] <= N) chmin(dp[i + p[j]], dp[i] + 1);
	}
	
	cout << dp[N] << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x,n) cout << fixed << setprecision(n) << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ld,W);
  IN(ld,H);
  IN(ld,x);
  IN(ld,y);
  if(W == 0 || H == 0){
    cout << 0.0000000000 << " " << 0 << endl;
    return 0;
  }
  cout << fixed << setprecision(10) << (ld)(W*H/2) << " ";
  if(W == x*2 && H == y*2){
    OUT(1);
  }else{
    OUT(0);
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

long int gcd(long int a, long int b) {
  long int t;    // �⏕�ϐ�
  while ( b != 0 ) {          // ������0�ɂȂ�܂�
    t = a%b; a = b; b = t;    // �������]�ɒu��������
  }
  return a;                   // ������0�ɂȂ����Ƃ��̈����GCD
}

long int 
main(){
	 long int A,B,i;
	 long int cnt=0;
	long int K;
	scanf("%ld %ld",&A,&B);

	long int tmp;
	if(B>A){tmp = A;
			A=B;
			B=tmp;
	}
	
	if(B==1){
		printf("1\n");return 0;
	}
	long int bb,j;
	bb = gcd(A,B);
	long int ans =1;
	for(i=2;i*i<=(bb);i++){
		if(bb%i == 0){
			ans++;
			while(bb%i==0){
				bb = bb/i;
			}
		}
	}
	if(bb>1)ans++;
	
	printf("%ld\n",ans);
 return 0;
}

Measured memory_bytes: 128
N = int(input())
qs = [tuple(map(int,input().split())) for i in range(N)]
parity = sum(qs[0])%2
for x,y in qs[1:]:
    if (x+y)%2 != parity:
        print(-1)
        exit()

arms = [1]
if not parity:
    arms.append(1)
while arms[-1] < 2*10**9:
    arms.append(arms[-1] * 2)
arms.reverse()

dirs = {'L':(1,0), 'R':(-1,0), 'D':(0,1), 'U':(0,-1)}
ans = []
for x,y in qs:
    command = ''
    for a in arms:
        dist = abs(x) + abs(y)
        best_c = None
        best_gain = -10**10
        for c,(dx,dy) in dirs.items():
            newdist = abs(x+ dx*a) + abs(y+ dy*a)
            gain = dist - newdist
            if gain > best_gain:
                best_gain = gain
                best_c = c
        command += best_c
        dx,dy = dirs[best_c]
        x += dx*a
        y += dy*a
    ans.append(command)

print(len(arms))
print(*arms)
print(*ans, sep='\n')

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long longz


int main(){
    int a , b , c ,d;
    cin >>a >>b>>c>>d;
    int cnt2=0,cnt1=0;
    for(int i=0;i<=100;i++){
        if(i>max(a,c))
            cnt1++;
        if(i==min(b,d))
            break;
    }
    cout<<cnt1<<endl;


}



Measured memory_bytes: 256
#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 tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n;cin>>n;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    int cnt=0;
    for(int i=1;i<(n-1);i++)
    {
        int val1=arr[i-1];
        int val2=arr[i];
        int val3=arr[i+1];

        int mini=min(min(val1,val2),val3);
        int maxi=max(max(val1,val2),val3);
        if(val2!=mini and val2!=maxi)
            cnt++;

    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include <stdio.h>

int car3(int x);


int main(void) {
    
    int input;
    
    do {
        scanf("%d", &input);
    } while( input < 1 || input > 100 );
    
    printf("%d\n", car3(input));
}

int car3(int x) {
    if (x < 1 || x > 100) {
        printf("valid number... : %d\n", x);
    }
    
    return x * x * x;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int n;  cin >> n;
  ll ans=0;

  for (int i=1; i<=n; ++i) {
    int j = i;
    while (j <= n) {
      //++v[j-1];
      ans += j;
      j += i;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
  int r,g,b;
  int rgb;
  
  scanf("%d %d %d",&r,&g,&b);
  
  rgb = r * 100 + g * 10 + b;
  
  if(rgb % 4 == 0)
  {
    printf("YES");
  }
  else
  {
    printf("NO");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

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

    int cnt = 0;
    while(a >= b){
        cnt++;
        b *= 2;
    }

    while(b >= c){
        cnt++;
        c *= 2;
    }
    
    if(cnt <= k){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}


int p(int n){
	if( n < 2 ) return 0;
	for(int i = 2 ; i * i <= n ; i++)
		if( n % i == 0 ) return false;
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	while(cin >> n && n){
		while( !p(n) || !p(n-2) ) n--;
		cout << n-2 << " " << n << endl;
	}
}

Measured memory_bytes: 904
import math
a, b, x = map(int, input().split())

side = x / a


if side <= a * b / 2:
    # only sankaku
    x = 2 * side / b
    rad = math.atan2(b, x)


else:
    y = (-2*side + 2* a*b)/a
    rad = math.atan2(y, a)


deg = math.degrees(rad)
print(deg)


Measured memory_bytes: 38384
#include <bits/stdc++.h> // only for GCC
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int num[10][7] = {{0,1,1,1,1,1,1},{0,0,0,0,1,1,0},{1,0,1,1,0,1,1},{1,0,0,1,1,1,1},{1,1,0,0,1,1,0},{1,1,0,1,1,0,1},{1,1,1,1,1,0,1},{0,1,0,0,1,1,1},{1,1,1,1,1,1,1},{1,1,0,1,1,1,1}};

int main() {
  int n;

  while(cin >> n, n != -1) {
    int bnum;
    REP(i, n) {
      int nnum;
      cin >> nnum;
      if(i == 0) {
	REP(j, 7) cout << num[nnum][j];
      }
      else {
	REP(j, 7) {
	  if(num[nnum][j] != num[bnum][j]) cout << 1;
	  else cout << 0;
	}
      }
      cout << endl;
      bnum = nnum;
    }
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 998244353;

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  vector< vector< vector< vector<ll> > > > dp(3, vector< vector< vector<ll> > >(d+1, vector< vector<ll> >(3, vector<ll>(3, 0))));
  dp[a%3][b][0][0] = 1;

  for (int i = a; i <= c; ++i) {
    int cur = i % 3;
    int prv = (cur + 2) % 3;
    for (int j = b; j <= d; ++j) {
      dp[cur][j][0][1] = (i-1) * (dp[cur][j-1][0][0] + dp[cur][j-1][0][1] + dp[cur][j-1][0][2]);
      dp[cur][j][0][1] %= MOD;
      dp[cur][j][1][0] = (j-1) * (dp[prv][j][0][0] + dp[prv][j][1][0] + dp[prv][j][2][0]);
      dp[cur][j][1][0] %= MOD;

      dp[cur][j][1][1] = max((j-1) * (dp[prv][j][0][1] + dp[prv][j][1][1] + dp[prv][j][2][1]), (i-1) * (dp[cur][j-1][1][0] + dp[cur][j-1][1][1] + dp[cur][j-1][1][2]))
	+ (dp[prv][j][0][0] + dp[prv][j][1][0] + dp[prv][j][2][0]) +  (dp[cur][j-1][0][0] + dp[cur][j-1][0][1] + dp[cur][j-1][0][2]);
      dp[cur][j][1][1] %= MOD;
      dp[cur][j][1][2] = dp[prv][j][0][1] + dp[prv][j][1][1] + j * dp[prv][j][1][2] + dp[prv][j][2][1] + j * dp[prv][j][2][2];
      dp[cur][j][1][2] %= MOD;
      dp[cur][j][2][1] = dp[cur][j-1][1][0] + dp[cur][j-1][1][1] + dp[cur][j-1][1][2] + i * dp[cur][j-1][2][1] + i * dp[cur][j-1][2][2];
      dp[cur][j][2][1] %= MOD;
    }
    for (int j = b; j <= d; ++j) {
      rep(x,3) {
	rep(y, 3){
	  dp[prv][j][x][y] = 0;
	}
      }
    }
  }   

  ll ans = 0;
  rep(i, 3) rep(j, 3) ans += dp[c%3][d][i][j];
  cout << ans % MOD << endl;
  return 0;
}


Measured memory_bytes: 5660
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
    double h,a;
    cin>>h>>a;
    double ans=ceil((double)h/a);
    cout<<ans<<endl;
}

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

int sum[103],n;
int main()
{
	scanf("%d", &n);
	for (int i=1;i<=n;++i)
	{
		scanf("%d", &sum[i]);
		sum[i]+=sum[i-1];
	}
	int ans=sum[n];
	for (int i=0;i<=n;++i)
	{
		ans=min(ans,abs(sum[n]-sum[i]*2));
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
    while(1){
        ll n; cin>>n;
        if(n == 0) return 0;
        vector<ll> p(n), j(n-1);
        ll sum = 0;
        for(int i=0; i<n; i++){
            cin>>p[i];
            sum += p[i];
        }
        ll ans = sum * n;

        for(int i=0; i<n-1; i++) cin>>j[i];

        sort(j.begin(), j.end(), greater<ll>());

        for(int i=0; i<n-1; i++){
            sum += j[i];
            ans = max(ans, sum * (n - i - 1));
        }

        cout << ans << endl;
    }
}


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

signed main(){

//	vector<int> a(n);

  int n;
 
  cin >> n;

  int cnt=0;

  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j == n){
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }

  cout << "No" << endl;
}

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






int N, M, A[11];
int need[] = { 0, 2,5,5,4,5,6,3,7,6 };
using vi = vector<int>;
#define init vi(10, 0)
//---------------------------------------------------------------------------------------------------
bool comp(vi a, vi b) {
    int sm1 = 0;
    fore(i, a) sm1 += i;

    int sm2 = 0;
    fore(i, b) sm2 += i;

    if (sm1 != sm2) return sm1 < sm2;

    rrep(i, 9, 0) if (a[i] != b[i]) return a[i] < b[i];
}
//---------------------------------------------------------------------------------------------------
string solve() {
    vector<int> ans = init;

    rep(a1, 0, 10) rep(a2, 0, 10) rep(a3, 0, 10) rep(a4, 0, 10) rep(a5, 0, 10) rep(a6, 0, 10) rep(r, 1, 10) {
        int cst = need[a1] + need[a2] + need[a3] + need[a4] + need[a5] + need[a6];
        int d = N - cst;

        if (d < 0) continue;

        if (A[a1] == 0) continue;
        if (A[a2] == 0) continue;
        if (A[a3] == 0) continue;
        if (A[a4] == 0) continue;
        if (A[a5] == 0) continue;
        if (A[a6] == 0) continue;
        if (A[r] == 0) continue;

        vi cand(10, 0);
        if(0 < a1) cand[a1]++;
        if (0 < a2) cand[a2]++;
        if (0 < a3) cand[a3]++;
        if (0 < a4) cand[a4]++;
        if (0 < a5) cand[a5]++;
        if (0 < a6) cand[a6]++;

        if (0 < d % need[r]) continue;
        cand[r] += d / need[r];

        if (comp(ans, cand)) {
            ans = cand;
        }
    }

    string res = "";
    rrep(i, 9, 1) {
        rep(j, 0, ans[i]) res += char('0' + i);
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    A[0] = 1;
    rep(i, 0, M) {
        int a; cin >> a;
        A[a] = 1;
    }
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, M;
vector<ll> A, B;
set<ll> searched;
map<ll, ll> mp;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    B.resize(M);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    sort(A.begin(), A.end());
    ll ans = 0;
    for(int i = 0; i < N; i++) ans += A[i];
    ans *= M;
    for(int i = 0; i < M; i++) {
        ll mod = B[i];
        if(searched.find(mod) != searched.end()) {
            ans -= mp[mod];
            continue;
        }
        searched.insert(mod);
        ll nowval = 0;
        for(ll j = 1; j * mod <= A.back(); j++) {
            auto itr = lower_bound(A.begin(), A.end(), j * mod);
            ll factor = distance(itr, A.end());
            //cerr << mod << " " << j << " " << factor << endl;
            nowval += factor;
        }
        mp[mod] = nowval * mod;
        ans -= nowval * mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 27424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> v, a(n);
    vector<vector<int>> c(h, vector<int>(w));
    rep(i, n) cin >> a[i];
    rep(i, n)
    {
        rep(j, a[i])
            v.push_back(i + 1);
    }
    rep(i, h)
    {
        if (i % 2 == 0)
        {
            rep(j, w)
            {
                int x = v.back();
                v.pop_back();
                c[i][j] = x;
            }
        }
        else
        {
            rep(j, w)
            {
                int x = v.back();
                v.pop_back();
                c[i][w - 1 - j] = x;
            }
        }
    }
    rep(i, h)
    {
        rep(j, w)
        {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    int B,W;cin>>B>>W;
    ll S=0,T=0;
    
    for(int i=0;i<B+W;i++){
        cout<<(T+(2*mod-S-T+1)%mod*rui(2,mod-2)%mod)%mod<<endl;
        if(i-(B-1)<=W) S+=comb(i,B-1)*rui(2,mod-2)%mod*rui(rui(2,mod-2),i);
        if(i-(W-1)<=B) T+=comb(i,W-1)*rui(2,mod-2)%mod*rui(rui(2,mod-2),i);
        
        S%=mod;
        T%=mod;
    }
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
const int maxN=52;
bool a[maxN][maxN],b[maxN][maxN];
int n,m;
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++){
      char c;
      cin>>c;
      if(c=='#')a[i][j]=true;
    }
  for(int i=0;i<m;i++)for(int j=0;j<m;j++){
      char c;
      cin>>c;
      if(c=='#')b[i][j]=true;
    }
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      bool f=true;
      for(int k=i;k<i+m;k++){
	for(int l=j;l<j+m;l++){
	  if(a[k][l]!=b[k-i][l-j])f=false;
	}
      }
      if(f){
	cout<<"Yes"<<endl;
	return 0;
      }
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	int W[N];
	for(int i=0;i<N;i++){
		cin >> W[i];
	}
	int SUM = 0;
	for(int i=0;i<N;i++){
		SUM += W[i];
	}
	int s1 = 0, MIN = 1000000000;
	for(int i=0;i<N-1;i++){
		s1 += W[i];
		MIN = min(abs(SUM - 2 * s1), MIN);
	}
	cout << MIN << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, x;
    cin >> n >> x;
    int dis = 0;
    int ans = 0;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    for(int i = 0; i < n; i++){
        if(dis + l[i] > x) break;
        dis += l[i];
        ans += 1;
       
    }
    cout << ans+1;
}


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

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        
        int A[] = new int[3];
        A[0] = sc.nextInt();
        A[1] = sc.nextInt();
        A[2] = sc.nextInt();
        
        Arrays.sort(A);
        
        int sum = 0;
        sum = Math.abs(A[1]-A[0]);
        sum += Math.abs(A[2]-A[1]);
        
        System.out.println(sum);
        
    }
    
}


Measured memory_bytes: 23764
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()
for i in range(N):
    A[i] -= i+1
A.sort()

x = (A[N//2]+A[(N-1)//2])//2
print(sum(abs(A[i]-x) for i in range(N)))


Measured memory_bytes: 104164
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S;
	cin >> S;
	int N = S.size();
	int MOD = 1000000007;
	vector<vector<ll>> dp(N + 1,vector<ll>(4));
	for (int i = N;i >= 0;i--) {
		for (int j = 3;j >= 0;j--) {
			if (i == N) {
				dp[i][j] = (j == 3 ? 1 : 0);
			}
			else {
				dp[i][j] = dp[i + 1][j] * (S[i] == '?' ? 3 : 1);
				if (j < 3 && (S[i] == '?' || S[i] == "ABC"[j])) {
					dp[i][j] += dp[i + 1][j + 1];
				}
			}
			dp[i][j] %= MOD;
		}
	}
	cout << dp[0][0] << "\n";

	return 0;
}

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;

    int count[n] = {};

    for(int i = 0; i < q; i++) {
        int a;
        cin >> a;
        count[a - 1]++;
    }

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


    return 0;
}

Measured memory_bytes: 1024
N,A = map(int, input().split())
X = list(map(int,input().split()))

max_x = max(X)
Y = []
for x in X:
    Y.append(x - A)

dp=[[0 for t in range(60*60*2)] for j in range(60)]
#dp[j番目までの変数から0枚以上選んでy_iの合計を][t-NXにする] = 総数

#dp[0][N*max_x] = 1
for j in range(N+1):
    for t in range(2*N*max_x+1):
        if j == 0 and t == N*max_x:
            dp[j][t] = 1
        else:
            if j>=1 and (t-Y[j-1] < 0 or t - Y[j-1] > 2*N*max_x):
                dp[j][t] = dp[j-1][t]
            elif j>=1 and 0<= t-Y[j-1] <=2*N*max_x:
                dp[j][t] = dp[j-1][t] + dp[j-1][t-Y[j-1]]
            else:
                dp[j][t] = 0
print(dp[N][N*max_x]-1)



# dp=[[[0 for s in range(60*60)] for k in range(60)] for j in range(60)]
# for s in range(60*60):
#     dp[0][0][s]=0
# #dp[j番目までの変数から][k個選んで][合計がs] = になる総数
# for j in range(N+1):
#     for k in range(N+1):
#         for s in range(N*k+1):
#             if j == 0 and k == 0 and s == 0:
#                 dp[j][k][s] = 1
#             else:
#                 if j >= 1 and s < X[j-1]:
#                     dp[j][k][s] = dp[j-1][k][s]
#                 elif j >= 1 and  k >= 1 and s>=X[j-1]:
#                     dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j-1]]
#                 else:
#                     dp[j][k][s] = 0

# print(dp[0][0][6])
# ans = 0
# for k in range(N+1):
#     ans += dp[N][k][k*A]
# print('ans = ',ans)

# import itertools
# N,A = map(int, input().split())
# X = map(int,input().split())

# ans = 0
# X = sorted(X)
# for n in range(1,N+1):
#     tmp = []
#     tmp = list(itertools.combinations(X,n))
#     tmp_sum = []

#     for i in range(len(tmp)):
#         tmp_sum.append(sum(tmp[i]))
#     ans += tmp_sum.count(A*n)
#     if tmp_sum[0] > A*n:
#         break

# print(ans)


Measured memory_bytes: 8692
#include <iostream>
#include <algorithm>

using namespace std;

long long L, R;

int main(){
    cin >> L >> R;

    int ans = 2019;
    for(long long i = L; i < R; i++){
        for(long long j = i + 1; j <= R; j++){
            ans = min(((i % 2019) * (j % 2019)) % 2019, (long long)ans);
            if(ans == 0){
                break;
            }
        }
        if(ans == 0){
            break;
        }
    }

    cout << ans << endl;


    return 0;
}

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

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd() {
    
    for ( int k= 0; k<n; k++ ){
        
        for ( int i= 0; i< n; i++ ) {
            
            if ( d[i][k] == INFTY ) {
                
                continue;
                
            }
            
            for ( int j= 0; j<n; j++ ) {
                
                if ( d[k][j] == INFTY ) {
                    
                    continue;
                    
                }
                
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                
            }
            
        }
        
    }
    
}


int main() {
    
    int e, u, v, c;
    
    cin >> n >> e;
    
    for ( int i= 0; i< n; i++ ) {
        
        for( int j= 0; j<n; j++ ) {
            
            d[i][j]=((i== j) ? 0 : INFTY );
            
        }
        
    }

    for ( int i= 0; i<e; i++ ) {
        
        cin >> u >> v >> c;
        
        d[u][v] = c;
        
    }

    floyd();
    
    bool negative = false;
    
    for ( int i= 0;i<n; i++ ) {
        
        if ( d[i][i]< 0 ) {
            
            negative = true;
            
        }
        
    }
    
    if ( negative ) {
        
        cout << "NEGATIVE CYCLE" << endl;
        
    } else {
        
        for ( int i= 0; i<n; i++ ) {
            
            for ( int j= 0;j<n;j++ ) {
                
                if ( j ) {
                    
                    cout <<" ";
                    
                }
                
                if ( d[i][j] == INFTY ) {
                    
                    cout << "INF";
                    
                } else {
                    
                    cout << d[i][j];
                    
                }
                
            }
            
            cout << endl;
            
        }
        
    }
    
    return 0;
    
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll mod=1000000007;

int main(){
    ll A, B, C, N;
    cin >> N;

    ll count = 0;
    for(ll i=1; i<=N; i++) {
        ll x = N/i;
        if(N % i== 0) x--;
        count += x;
    }
    cout << count << endl;
}

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

int main(){
    int64_t W,H;
    cin>>W>>H;
    vector<pair<int64_t,int>> E;
    for(int i=0;i<W;i++){
        int64_t p;
        cin>>p;
        E.emplace_back(p,0);
    }
    for(int i=0;i<H;i++){
        int64_t q;
        cin>>q;
        E.emplace_back(q,1);
    }
    sort(E.begin(),E.end());
    int64_t w=0,h=0,ans=0;
    for(int i=0;i<W+H;i++){
        auto e=E[i];
        if(!e.second){
            w++;
            ans+=((H+1)-h)*e.first;
        }else{
            h++;
            ans+=((W+1)-w)*e.first;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5096
row, col = map(int, raw_input().split())

mat = []
for i in range(row):
    line = map(int, raw_input().split())
    mat.append(line + [sum(line)])

row2 = [0 for i in range(col+1)]
for i in range(col+1):
    for j in range(row):
        row2[i] += mat[j][i]
mat.append(row2)
for i in mat:
    print " ".join(map(str,i))

Measured memory_bytes: 6456
#include <cstdio>
#include <unordered_map>
#include <vector>

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

using namespace std;

int64_t comb(int64_t n) { return (n > 1) ? (n * (n - 1)) / 2 : 0; }

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

  auto avec = vector<int>(n);
  for (auto &x : avec) {
    scanf("%d", &x);
  }

  auto arr = vector<int>(n + 1, 0);
  for (const auto &x : avec) {
    arr[x]++;
  }

  int64_t sum = 0;
  for (const auto &x : arr) {
    sum += comb(x);
  }

  auto memo = unordered_map<int, int64_t>();

  for (const auto &x : avec) {
    if (memo.find(x) == memo.end()) {
      auto n = arr[x];
      auto result = sum - (n - 1);
      memo[x] = result;
    }

    printf("%ld\n", memo[x]);
  }

  return 0;
}


Measured memory_bytes: 10148
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

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


Measured memory_bytes: 256
k=int(input())
a=list(range(1, 10))
b=[]
n=int(len(a))
x=k
while x>n:
  x-=n
  for i in range(n):
    for l in range(3):
      c=(a[i]%10)-1+l
      if 0<=c<=9:
        a.append((a[i]*10)+c)
  del a[0:n]
print(a[x-1])

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

int main(){
    int n;
    cin >>n;
    int l[2*n];
    for(int i=0;i<2*n;i++){
      cin >>l[i];
    }
    sort(l,l+2*n);
    int sum=0;
    for(int i=0; i<n; i++){
      sum+=min(l[2*i],l[2*i+1]);
    }
    cout <<sum<<endl;
  }


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int pi[12*maxn],m,n;
string buf;
int prefix_function(const string &s,const string &t) {
    ///search t on s
    m=(int)t.length();
    n =(int)t.length()+(int)s.length()+1;
    buf=t+'#'+s;
    pi[0]=0;
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && buf[i] != buf[j])
            j = pi[j-1];
        if (buf[i] == buf[j])
            j++;
        pi[i] = j;
    }
    int ma=-1;
    for(int i=n-1;i>m;i--){
        pi[i]=(pi[i]==m?1:0);
        if(i+m<n&&pi[i]==1){
            pi[i]+=pi[i+m];
        }
        ma=max(ma,pi[i]);
    }
    return ma;
}
string s,t,a,ss,tt;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>ss>>t;
    s=ss;
    while((int)s.length()<=(int)t.length()+(int)ss.length()){
        s+=ss;
    }
    s+=ss;
    int c=prefix_function(s,t);
    if(c==-1){
       return cout<<"0",0;
    }
    s+=s;
    int cc=prefix_function(s,t);
    if(cc==c){
        return cout<<cc,0;
    }
    else{
        return cout<<-1,0;
    }
}
/*
    Good Luck
        -Lci70121
*/


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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int W, H, N;
    cin >> W >> H >> N;

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

    int x1 = 0, x2 = W, y1 = 0, y2 = H;
    for (int i = 0; i < N; i++) {
        switch (a[i]) {
            case 1:
                if (x[i] > x1) x1 = x[i];
                break;
            case 2:
                if (x[i] < x2) x2 = x[i];
                break;
            case 3:
                if (y[i] > y1) y1 = y[i];
                break;
            case 4:
                if (y[i] < y2) y2 = y[i];
                break;
        }
    }

    if (x1 >= x2 || y1 >= y2) {
        cout << 0 << endl;
    } else {
        cout << (x2-x1)*(y2-y1) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    bool flag=true;
    int cnt=0;
    bool le=false;
    bool ri=false;
    for(int i=0;i<n;i++){
      string s;cin>>s;
      if(s=="lu"){
	le=true;
	if(flag&&ri){cnt++;flag=false;}
      }else if(s=="ru"){
	ri=true;
	if(flag&&le){cnt++;flag=false;}
      }else if(s=="ld"){
	le=false;
	if((!flag)&&(!ri)){cnt++;flag=true;}
      }else{
	ri=false;
	if((!flag)&&(!le)){cnt++;flag=true;}
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}



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

int main(){
    int k;
    cin >> k;
    int ans;
    if(!(k%2)){
        ans = k/2*k/2;
    }
    else{
        ans = k/2*(k/2+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n){
		cin>>a[i];
	}
	ll ans=0;
	rep(i,n){
		rep(j,n){
			if(i!=j){
				ans+=a[i]*a[j];
			}
		}
	}
	cout<<ans/2;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    if(K!=1){
        printf("%d\n", N-K);
    }else{
        printf("%d\n", 0);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)
bool s[114514];
int in[114514],r[114514];
int main(){
	FOR(i, 2, 110000) {
		bool a = false;
		for (int j = 2; j <= sqrt(i); j++) {
			if (i % j == 0)a = true;
		}
		if (!a) s[i] = true;
	}
	REP(i, 110000) if (s[i] and s[(i + 1) / 2])in[i]++;
	REPO(i, 110000) r[i] += in[i] + r[i - 1];
	int N;
	cin >> N;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		cout << r[b] - r[a - 1] << endl;
	}

}

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

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint f(int n) {
  if (n == 0) return 1;

  mint x = f(n / 2);
  x *= x;

  if (n % 2 == 1) x *= 2;
  return x;
}

mint comb(int n, int k) {
  mint x = 1, y = 1;
  rep(i, k) {
    x *= n - i;
    y *= i + 1;
  }

  return x / y;
}

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

  mint ans = f(n) - 1 - comb(n, a) - comb(n, b);

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

Measured memory_bytes: 256