akhauriyash/Code-Regression huggingface dataset:
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    string a,b;
    cin>>a>>b;
    for(i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}



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

using namespace std;

pair<int, int> problem[100005];

int main()
{
    int n, m, penalties = 0, AC = 0; cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int p;
        string condition;
        cin >> p >> condition;

        if (condition == "AC")
        {
            if (problem[p].first == 1) //Se já foi submetido
                continue;

            penalties += problem[p].second;
            AC++;
            problem[p].first = 1;
        } else if (condition == "WA")
        {
            problem[p].second++;
        }

    }

    cout << AC << " " << penalties << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

	int p1 = a * n;
	int p2 = b;

	if (p1 < p2) {
		cout << p1 << '\n';
	} else {
		cout << p2 << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	long N, K;
	long result = 0L;
	long MOD = 1000000007L;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Long.parseLong(tokens[0]);
		K = Long.parseLong(tokens[1]);
		for (long i = K; i <= N + 1; ++i) {
			long min = (long) (0 + (i - 1) * i) / 2;
			long max = (long) ((N - (i - 1) + N) * i) / 2;
			// System.out.println(i + " " + min + " " + max);
			result += max - min + 1;
			result %= MOD;
		}
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}
}


Measured memory_bytes: 32608
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

ll inverse(ll x) {
    return power(x, mod - 2, mod);
}



signed main() {
  ios::sync_with_stdio(false);
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);
  REP(i, x) {
    cin >> a[i];
  }
  REP(i, y) {
    cin >> b[i];
  }
  REP(i, z) {
    cin >> c[i];
  }
  vector<ll> ab;
  REP(i, x) {
    REP(j, y) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(all(ab), greater<ll>());
  vector<ll> ans;
  REP(i, min(k, x*y)) {
    REP(j, z) {
      ans.push_back(ab[i] + c[j]);
    }
  }
  sort(all(ans), greater<ll>());
  REP(i, k) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 43368
n = gets.to_i
hash = Hash.new(0)
check = 0
bef = gets.chomp
hash[bef] += 1
(n-1).times do
  w = gets.chomp
  hash[w] += 1
  check += 1 if bef[-1] != w[0]
  bef = w
end
hash.each do |k,v|
  check += 1 if v >= 2
end
if check > 0
  puts :No
else
  puts :Yes
end

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

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

    long long sum;
    bool is_positive;
    sum = 0;
    is_positive = true;
    long long ans1 = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
        if (is_positive)
        {
            if (sum <= 0)
            {
                ans1 += 1 - sum;
                sum = 1;
            }
        }
        else
        {
            if (sum >= 0)
            {
                ans1 += 1 + sum;
                sum = -1;
            }
        }
        is_positive ^= 1;
    }

    sum = 0;
    is_positive = false;
    long long ans2 = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
        if (is_positive)
        {
            if (sum <= 0)
            {
                ans2 += 1 - sum;
                sum = 1;
            }
        }
        else
        {
            if (sum >= 0)
            {
                ans2 += 1 + sum;
                sum = -1;
            }
        }
        is_positive ^= 1;
    }

    cout << min(ans1, ans2) << endl;
}


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

const ll mod = 2019;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    ll get() const { return 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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); return (t & 1) ? a*a*(*this) : a*a; }
    operator ll () const { return x; }
    operator string () const { return to_string(x); }
    friend istream& operator>>(istream& is, mint& a) { is>>a.x; return is; }

    // 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 { return mint(*this) /= a; }
};

int main() {
    string s;
    cin >> s;
    int N = s.size();

    mint ba(1);
    vector<mint> v(N+1);
    v[N] = mint(0);
    for (int i=N-1; i>=0; --i) {
        v[i] = mint(s[i] - '0') * ba + v[i+1];
        ba *= 10;
    }

    ll ans = 0;
    map<ll, ll> cnt;
    for (int i=0; i<=N; ++i) {
        ans += cnt[v[i]];
        cnt[v[i]] ++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5072
// ------------------------------------
// Date:2018/ 2/18
// Problem:ABC 088 _ d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)

int H, W;
// Board[H][W];
string B[50];
int vx[] = {1,-1,0,0};
int vy[] = {0,0,1,-1};

vector<vector<int>> memo(50,vector<int>(50,0));
bool state[50][50] = {false};

int solve()
{
  // queueXとqueueYのpair
  queue<pair<int,int>> q;
  q.push({0,0});
  state[0][0] = true;
  //memo[0][0] = 0;
  
  while (!q.empty()) {
    pair<int,int>tmp = q.front();
    q.pop();
    int x = tmp.first;
    int y = tmp.second;
    if (x == W-1 && y == H-1) return memo[y][x];
    REP(i,4) {
      int nextX = x + vx[i];
      int nextY = y + vy[i];
      
      if (0 <= nextX && nextX < W
      &&  0 <= nextY && nextY < H
      //&& memo[nextY][nextX] == -1
      &&  state[nextY][nextX] == false
      &&  B[nextY][nextX] == '.') {
        state[nextY][nextX] = true;
        memo[nextY][nextX] = memo[y][x] + 1;
        q.push({nextX,nextY});
      }
    }
  }
  return 0;
}


int main()
{
  int cnt = 0;
  cin >> H >> W;
  REP(hi,H) {
    cin >> B[hi];
    REP(si,B[hi].size()) if (B[hi][si] == '#') ++cnt;
  }
  
  int ans, res = solve();
  if (res == 0) {
    ans = -1;
  } else {
    //ans = H*W - (#の数) - (すぬけ君が通るマスの数);
    ans = H*W - cnt - res - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from math import cos, radians, sqrt

A, B, H, M = [int(el) for el in input().split()]

minutes = H * 60 + M
h = 360.0 / 60.0 * (minutes % 60)
m = 360.0 / 720.0 * (minutes % 720)
ang = abs(h - m)

print(sqrt(A*A + B*B - 2.0 * A * B * cos(radians(ang))))

Measured memory_bytes: 9436
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9

lli n;
vector<lli>v,psum;
lli dp[420][420];

lli sum(lli l,lli r)
{
    return psum[r]-psum[l]+v[l];
}

lli func(lli n)
{
    for(lli i=0;i<n;i++)
        dp[i][i]=0;
    for(lli l=2;l<=n;l++)
    {
        for(lli i=0;i<=n-l;i++)
        {
            lli j=l+i-1;
            lli ans=2e18;
            for(lli k=i;k<j;k++)
            {
                //cout << i << "," << k << "," << j << endl;
                lli a=sum(i,k),b=sum(k+1,j);
                //cout << a << "," << b << endl;
                ans=min(ans,a+b+dp[i][k]+dp[k+1][j]);
            }
            dp[i][j]=ans;
        }
    }
    return dp[0][n-1];
}

int main()
{
    cin >> n;
    v.resize(n);
    psum.resize(n);
    for(lli i=0;i<n;i++)
        cin >> v[i];
    lli temp=0;
    for(lli i=0;i<n;i++)
    {
        temp+=v[i];
        psum[i]=temp;
    }
    for(lli i=0;i<n;i++)
        for(lli j=0;j<n;j++)
            dp[i][j]=-1;
    cout << func(n) << endl;
    // for(lli i=0;i<n;i++)
    // {
    //     for(lli j=0;j<n;j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
}

Measured memory_bytes: 1536
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	for i := 0; i < 1<<uint(n); i++ {
		if bits.OnesCount32(uint32(i)) != k {
			continue
		}
		fmt.Fprintf(writer, "%d:", i)
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 == 1 {
				fmt.Fprint(writer, " ")
				fmt.Fprint(writer, j)
			}
		}
		fmt.Fprintln(writer, "")
	}
}



Measured memory_bytes: 4904
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  int N,K;cin >> N >>K;
  vll x(N);
  repeat(i,N)cin >> x[i];
  ll ans=INF;
  repeat(l,N-K+1){
    ll r = l+K;
    ll a = INF,b=INF;
    if(x[r-1]>=0){
      a = x[r-1];
      if(x[l]<0){
        a -= 2*x[l];
      }
    }
    if(x[l]<=0){
      b = -x[l];
      if(x[r-1]>0){
        b += 2*x[r-1];
      }
    }
    ans = min(ans,min(a,b));
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 1024
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int get(int n) {
  int ans = 1, x = 1, c = 2;
  while (x + c <= n) {
    ans++;
    x += c;
    c++;
  }
  return ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  int ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll c = 0;
      while (n % i == 0) {
        n /= i;
        c++;
      }
      ans += get(c);
    }
  }  
  if (n > 1)
    ans++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
vector <int> e[N];
int fa[N];
int p[N];
int sz[N];
int M(int u, int v)
{
	return 1ll * u * v % mod;
}
int P(int u, int v)
{
	if (v % 2)
		return M(u, P(u, v - 1));
	if (v)
		return P(M(u, u), v / 2);
	return 1;
}
int I(int u)
{
	return P(u, mod - 2);
}
int R(int u)
{
	return (mod + 1 - u) % mod;
}
int A(int u, int v)
{
	return (u + v) % mod;
}
void dfs(int u)
{
	sz[u] = 1;
	for (auto v : e[u])
	{
		if (v == fa[u])
			continue;
		fa[v] = u;
		dfs(v);
		sz[u] += sz[v];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int u, v;
		cin >> u >> v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	dfs(1);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (e[i].size() < 2)
			continue;
		int p1 = 1;
		for (int j : e[i])
		{
			p[j] = I(P(2, j == fa[i] ? n - sz[i] : sz[j]));
			p1 = M(p1, p[j]);
		}
		int p2 = 0;
		for (int j : e[i])
		{
			p2 = A(p2, M(M(p1, I(p[j])), R(p[j])));
		}
		ans = A(ans, M(I(2), R(A(p1, p2))));
	}
	cout << ans;
}

Measured memory_bytes: 20224
#include<cstdio>
#include<iostream>
#include<vector>

using namespace std;

int N, K;
vector<bool> record(10, false);

int main() {
    scanf("%d%d", &N, &K);
    int num;
    for (int i = 0; i < K; i++) {
        cin >> num;
        record[num] = true;
    }
    for (int i = N;;i++) {
        int j = i;
        bool flag = true;
        while(0 < j) {
            int digit = j % 10;
            j /= 10;
            if(record[digit])
                flag = false;
        }
        if(flag) {
            num = i;
            break;
        }
    }

    printf("%d\n", num);
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
		int64_t ansCount = 0;
	int N;
	int Alice = 0, Bob = 0;
	bool flag = true;

	cin >> N;
	
	vector<int> InVec(3 * N);

	for (auto& itr : InVec)
		cin >> itr;

	sort(InVec.begin(), InVec.end());
  
	for (int i = N + 1; i < N * 3; i+=2)
	{
		ansCount += InVec[i-1];
	}

	cout << ansCount << endl;

	return 0;
}

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

int main(void){
  int x,n,p[102],sw[103];
  int i,j;
  
  int min=999,imin;
  
  scanf("%d %d", &x, &n);
  
  if(n==0){
    printf("%d", x);
    return 0;
  }
  
  for(i=0;i<=101;i++){
    sw[i]=999;
  } 
  
  for(i=1;i<=n;i++){
    scanf("%d", &p[i]);
    sw[p[i]]=p[i];
  }
  
  for(i=0;i<=101;i++){
    if(sw[i]==999){
//      printf("%d ", i);
      if(abs(i-x)<min){
        min=abs(i-x);
        imin=i;
      }
    }
  }
  
  printf("%d", imin);
  
  return 0;
}




Measured memory_bytes: 1728
n, y = map(int,input().split())

for i in range(n+1):
    for j in range(n+1):
        if y-5000*j-10000*i == 1000*(n-i-j) and n-i-j >= 0:
            print(i,j,n-i-j)
            exit()
else:
    print("-1 -1 -1")


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

public class Main {
	private static final long DEV_NUM = 1000000000 + 7;
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		String S = in.next();
		in.close();
		
		int[] alpha = new int[26];
		Arrays.fill(alpha, 0);
		for (int i=0; i<N; i++) {
			alpha[S.charAt(i)-'a']++;
		}
		
		long total = 1;
		for (int i=0; i<alpha.length; i++) {
			total = (total * (alpha[i]+1)) % DEV_NUM;
		}
		
		total = (total - 1 + DEV_NUM) % DEV_NUM;
		
		System.out.println(total);
		
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
}


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

typedef long long ll;
typedef pair<int, int> pii;

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

	int n, m;
	cin >> n >> m;

	int sum = 0;

	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;

		sum += x;
	}

	cout << (sum > n ? -1 : n - sum);

	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int
#define mod 1000000007

int solve(vector<int>&v,int n,int k)
{
    int dp[n+2][k+2];

    for(int j=0;j<=k;j++)
        dp[1][j]=(j>v[1])?0:1;

    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(j==0)
            dp[i][j]=dp[i-1][j];
            
            else 
            dp[i][j] = (mod + dp[i-1][j] + dp[i][j-1] - ((j-v[i]-1>=0) ? dp[i-1][j-v[i]-1]:0) )%mod;
        }
    }
    
     return dp[n][k];
}

int32_t main()
{
	fast;
	int n,k;

	    cin>>n>>k;
	    
	    vector<int>v(n+1);
	    for(int i=1;i<=n;i++)
            cin>>v[i];
            
        cout<<solve(v,n,k)<<"\n";

	
	return 0;
}



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

int main() {
    int a, b, x, biggest, smallest;

    cin >> a >> b;

    if ( a > b){
        biggest = a;
        smallest = b;
    }else{
        biggest = b;
        smallest = a;
    }
    if((biggest - 1 ) > smallest){
        cout << biggest + biggest - 1;
    }else{
        cout << biggest + smallest;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define min(x,y) ( x < y ? x : y )

int main(void){
    int l,r;
    int ans = 10000000;
    cin >> l >> r;
    if(r-l>=2018||l%2019 >= r%2019||r%2019==0||l%2019==0)cout << 0 << endl;
    else{
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++){
                ans = min(((i%2019)*(j%2019))%2019,ans);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int w,a,b;
    scanf("%d%d%d",&w,&a,&b);
    if(a>b)
    {
       if(a>b+w)
            printf("%d",a-b-w);
       else
        printf("0");
    }
    if(a<b)
    {
        if(a+w<b)
            printf("%d",b-a-w);
        else
            printf("0");
    }
    if(a==b)
        printf("0");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	int n;
	cin >> n;
	int a[10];
	int evennum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 2 == 0) evennum++;
	}
	cout << (int)pow(3, n) - (int)pow(2, evennum) << endl;
	return 0;

}

Measured memory_bytes: 640
using System;
using System.IO;
using System.Linq;

namespace CompetitiveProgramming
{

  class Solve
  {
 
    private void main()
    {
      int N = int.Parse(Console.ReadLine());
      ulong[] a = new ulong[N];
      ulong[] b = new ulong[N];
      int[] idx = new int[N];

      for (int i = 0; i < N; i++)
      {
        a[i] = ulong.Parse(Console.ReadLine());
        b[i] = a[i];
        idx[i] = i;
      }

      Array.Sort(a, idx);

      int ans = 0;
     
      for (int i= 0; i < N; i++)
      {
        if (i % 2 == 1 && idx[i] % 2 == 0)
        {
          ans++;
        }
      }

      Console.WriteLine(ans);
    
    }


    public Solve()
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      main();
      Console.Out.Flush();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }

}

Measured memory_bytes: 8920
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
int rd(int s, int e) { return rand()%(e-s+1) + s; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }

char A[505][505];

int H, W;

int main() {
	scanf("%d%d", &H, &W);
	for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1);

	for(int i = 1; i <= H; i++) {
		for(int j = 1; j <= W; j++) {
			putchar('#' == A[i][j] || (j < W && (1 == j || (i&1))) ? '#' : '.');
		}
		puts("");
	}
	puts("");
	for(int i = 1; i <= H; i++) {
		for(int j = 1; j <= W; j++) {
			putchar('#' == A[i][j] || (1 < j && (W == j || !(i&1))) ? '#' : '.');
		}
		puts("");
	}
	return 0;
}

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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N, M; cin >> N >> M;
	ll a[50] = {}, b[50] = {};
	ll c[50] = {}, d[50] = {};
	rep(i, 0, N) {
		cin >> a[i] >> b[i];
	}
	rep(i, 0, M) {
		cin >> c[i] >> d[i];
	}

	rep(i, 0, N) {
		ll min = 1 << 30;
		ll cp = 0;
		rep(j, 0, M) {
			ll X = a[i] - c[j];
			ll Y = b[i] - d[j];
			X = (X < 0) ? -X : X;
			Y = (Y < 0) ? -Y : Y;
			if (min > X + Y) {
				min = X + Y;
				cp = j + 1;
			}
		}
		cout << cp << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    long long a,i,n;
    while(~scanf("%lld",&a))
    {
        for(i=1;i<=a;i++)
        {
            if(i*i>a)
                break;
            n=i;
        }

        printf("%lld\n",n*n);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

string s;
string::iterator p;
ll fact();
ll term();
ll exp();

ll fact() {
  ll x;
  string num;
  while(isdigit(*p)) {
    num += *p;
    ++p;
  }
  if(num.size()) {
    x = atoi(num.c_str());
  } else {
    ++p;
    x = exp();
    ++p;
  }
  return x;
}
 
ll term() {
  ll x = fact();
  while(*p == '*' || *p == '/') {
    if(*p == '*') {
      ++p;
      x *= fact();
    } else {
      ++p;
      x /= fact();
    }
  }
  return x;
 
}
 
ll exp() {
  ll x = term();
  while(*p == '+' || *p == '-') {
    if(*p == '+') {
      ++p;
      x += term();
    } else {
      ++p;
      x -= term();
    }
  }
  return x;
}

void Main() {
  R s;p=s.begin();
  int ans;R ans;
  ll x=exp();
  s+='=';
  ll y=0,d=0,q=1;
  rep(i,s.size()) {
    if(isdigit(s[i])) {
      d*=10;
      d+=s[i]-'0';
    } else {
      if(q) y+=d;
      else y*=d;
      d=0;
      if(s[i]=='+') q=1;
      else q=0;
    }
  }
  bool f1=ans==x,f2=ans==y;
  if(f1&&f2) pr("U");
  else if(f1) pr("M");
  else if(f2) pr("L");
  else pr("I");
}

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


Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

ll modpow(ll a, int n) {
    ll res = 1;
    while (n) {
        if (n & 1)
            (res *= a) %= MOD;
        n >>= 1;
        (a *= a) %= MOD;
    }
    return res;
}

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

    int N, K;
    cin >> N >> K;

    vector<ll> cnt(K + 1);

    ll ans = 0;
    for (int i = K; i >= 1; --i) {
        cnt[i] += modpow(K / i, N);
        (ans += cnt[i] * i) %= MOD;
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0) {
                (cnt[j] -= cnt[i]) %= MOD;
                if (i != j * j)
                    (cnt[i / j] -= cnt[i]) %= MOD;
            }
        }
        if (i > 1)
            (cnt[1] -= cnt[i]) %= MOD;
    }
    if (ans < 0)
        ans += MOD;

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


Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
cout << 1110 - N << endl;
return 0;
}

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

int main() {
	int n;
	cin >> n;
	if (n % 3 == 0) {
		cout << n / 3 << endl;
	}
	else {
		cout << n / 3 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, m, sum = 0;
    cin >> m >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        sum += x;
    }
    if(sum > m) cout << -1;
    else cout << m - sum;

    return 0;

}




Measured memory_bytes: 3656
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sin = new Scanner(System.in);
		
		int a, b, ans1, ans2;
		a = sin.nextInt();
		b = sin.nextInt();
		ans1 = a * b;
		ans2 = 2*(a + b);
		System.out.println(ans1 +" "+ ans2);
	}
}


Measured memory_bytes: 26240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    for (int i = 0; i <= x; i++) {
      if (i * 2 + (x - i) * 4 == y) {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 32668
#include<bits/stdc++.h>
using namespace std;
string ans="";
void make(string s,string t,int curs)
{
	int i;
	for(i=0;i<s.size();i++)
	{
		if(i<curs||i>=curs+t.size())
		{
			if(s[i]=='?')
				s[i]='a';
		}
		else
		{
			if(s[i]=='?')
				s[i]=t[i-curs];
			if(s[i]!=t[i-curs])
				return;
		}
	}
	if(ans==""||ans>s)
		ans=s;
}
int main(){
	int i;
	string s,t;
	cin>>s>>t;
	for(i=0;i<s.size()-t.size()+1;i++)
		make(s,t,i);
	if(ans=="")
		cout<<"UNRESTORABLE";
	else
		cout<<ans;
	return 0;
}

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

using namespace std;

using int64 = long long;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

constexpr int DEBUG = 0;

int64 SolvePartial(int64 l, int n, vector<int64>& xs) {
  int64 solution = 0;
  
  vector<int64> cum1(n);
  cum1[0] = xs[0];
  for (int i = 1; i < n; i++) {
    cum1[i] = cum1[i - 1] + xs[i];
  }

  auto r_range_sum = [&](int i, int j) -> int64 {
    if (i > j) return 0;
    int64 sum = cum1[j];
    if (i >= 1) sum -= cum1[i - 1];
    return sum;
  };
  
  vector<int64> cum2(n);
  cum2[n - 1] = l - xs[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    cum2[i] = cum2[i + 1] + (l - xs[i]);
  }

  for (int k = 1; k <= n; k++) {
    int remaining = n - k;
    if (remaining % 2 == 1) {
      int left_count = remaining / 2 + 1;
      int right_count = remaining / 2;
      int64 right_cost = 0;
      right_cost += 2 * cum1[k + right_count - 1];
      if (k >= 2) right_cost -= 2 * cum1[k - 2];
      int64 left_cost = 0;
      if (left_count > 0) left_cost += l - xs[n - left_count];
      if (left_count >= 2) left_cost += 2 * cum2[n - (left_count - 1)];
      int64 cost = right_cost + left_cost;
      if (DEBUG) {
        cout << "k: " << k << " cost: " << cost
            << " right_cost: " << right_cost
            << " left_cost: " << left_cost << endl;
      }
      UpdateMax(solution, cost);
    } else {
      int left_count = remaining / 2;
      int right_count = remaining / 2;
      int64 right_cost = 0;
      right_cost += xs[k + right_count - 1];
      right_cost += 2 * r_range_sum(k - 1, k + right_count - 2);
      // if (k + right_count >= 2) right_cost += 2 * cum1[k + right_count - 2];
      // if (k >= 2) right_cost -= 2 * cum1[k - 2];
      int64 left_cost = 0;
      if (left_count > 0) left_cost += 2 * cum2[n - left_count];
      int64 cost = right_cost + left_cost;
      if (DEBUG) {
        cout << "k: " << k << " cost: " << cost
            << " right_cost: " << right_cost
            << " left_cost: " << left_cost << endl;
      }
      UpdateMax(solution, cost);
    }
  }

  return solution;
}

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

  int64 l;
  int n;
  cin >> l >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  int64 s1 = SolvePartial(l, n, xs);
  vector<int64> ys(n);
  for (int i = 0; i < n; i++) ys[i] = l - xs[i];
  sort(ys.begin(), ys.end());
  int64 s2 = SolvePartial(l, n, ys);
  if (DEBUG) {
    cout << "s1: " << s1 << endl;
    cout << "s2: " << s2 << endl;
  }
  cout << max(s1, s2) << endl;
}


Measured memory_bytes: 6472
#include<bits/stdc++.h>
#include<vector>
#include <stdio.h>

using namespace std;

#define mod 1000000007LL
#define pi 3.141592653589793238462643383279;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second


int main()
{
    int n,m;
    cin>>n>>m;
    set<pii> s;
    vector<int> v(n);
    for(int i=1;i<=n;i++)
        v[i-1]=i;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        s.insert({a,b});
        s.insert({b,a});
    }
    int ans=0;
    //while(next_permutation(v.begin()+1,v.end()))
    do
    {
        //cout<<"3423"<<endl;
        bool temp=true;
        for(int i=1;i<n;i++)
        {
            if(s.find({v[i],v[i-1]})==s.end())
                {
                    temp=false;
                    break;
                }
        }
        if(temp)
            ans++;
    }while(next_permutation(v.begin()+1,v.end()));
    cout<<ans<<endl;
    //int acc;cin>>acc;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static final long MOD = 1000000007L;

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		String S = sc.nextLine();

		int[] alphabet = new int[26];
		for(int i=0;i<N;i++) {
			alphabet[(int)(S.charAt(i) - 97)]++;
		}

		long ans = 1;
		for(int i=0;i<26;i++) {
			ans = (ans % MOD) * ((alphabet[i] + 1) % MOD);
		}
		ans--;
		System.out.println(ans % MOD);
	}

}


Measured memory_bytes: 26304
/**
 * SimpleCalculator.cpp
 * Create:20180420
 * Description:a op pを読み込んで、計算を行う。opは以下の５種類。
 * + 加算
 * - 減算
 * / 除算
 * * 乗算
 * ? 終了
 * 答えは整数で、小数点以下が存在する場合は、切り捨てを行う。
 */
#include <iostream>
#include <vector>
#include <cmath>

/**
 * Calculatorクラス
 * @param a  数値　１
 * @param b  数値　２
 * @param op 演算子
 */
class Calculator{
private:
  int a;
  int b;
  std::string op;

public:
  /**
   * コンストラクタ
   * @param a  数値　１
   * @param b  数値　２
   * @param op 演算子
   */
  Calculator(int a, int b, const std::string &op){
    this->a = a;
    this->b = b;
    this->op = op;
  }

  /**
   * 計算する関数
   * @return 計算結果
   */
  int get_answer(){
    double result = 0.0;

    if (op == "+"){
      // 加算
      result = (double)a + (double)b;
    } else if (op == "-"){
      // 減算
      result = (double)a - (double)b;
    } else if (op == "*"){
      // 乗算
      result = (double)a * (double)b;
    } else {
      // 除算
      result = (double)a / (double)b;
    }

    return (int)floor(result);
  }
};

int main(int argc, char* argv[]){
  int a, b;
  std::string op;
  std::vector<Calculator> vec;

  while (true){
    std::cin >> a >> op >> b;
    if (op == "?")
      break;
    Calculator calc = Calculator(a, b, op);
    vec.push_back(calc);
  }

  for(Calculator c: vec){
    std::cout << c.get_answer() << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 3e2+5;
const int INF = 1e9+1;
const int MOD = 1e9+7;

int n, m, l;
int d[N][N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> m >> l;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			if (i == j) d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
	while(m--){
		int u, v, w; cin >> u >> v >> w;
		if (w > l) continue;
		d[u][v] = d[v][u] = w;
	}
	//Floyd
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			if (d[i][j] <= l) d[i][j] = 1;
			else d[i][j] = INF;
		}
	}
	//Floyd
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	int q; cin >> q;
	while(q--){
		int s, t; cin >> s >> t;
		if (d[s][t] == INF) cout << "-1\n";
		else {
			cout << d[s][t] - 1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template <typename T>
vector<pair<int, T>> rle(vector<T> a)
{
	int n = (int)a.size();
	vector<pair<int, T>> res;
	if (n == 0)
	{
		return res;
	}
	T now = a[0];
	int con = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == now)
		{
			con++;
		} else
		{
			res.push_back(pair<int, T>(con, now));
			now = a[i];
			con = 1;
		}
	}
	res.push_back(pair<int, T>(con, now));
	return res;
}

int main() {
	IOS;
	int n;
	cin >> n;
	vector<int> a(n);
	vector<ll> s(n + 1);
	s[0] = 0;
	REP(i, n) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}
	sort(all(s));
	auto r = rle(s);
	ll res = 0;
	REP(i, r.size()) {
		res += (ll)r[i].first * (r[i].first - 1) / 2;
	}
	put(res);
	return 0;
}


Measured memory_bytes: 9456
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define For(i,x,y) for(int i=x; i<y; ++i)
#define mem(x,y) memset(x,y,sizeof(x))
#define ALL(a) a.begin(),a.end()
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define se second
#define fi first
#define endl '\n'
 
template <typename T>
inline void read(T &r){
    static char c; r=0; int f=1;
    for(c=getchar(); c<'0'||c>'9'; c=getchar()) if(c=='-')f=-1;
    for(; c>='0'&&c<='9'; r=(r<<1)+(r<<3)+(c^48),c=getchar());
    r*=f;
} // -_- 

const int N = 2e5 + 105;

ll vis[10050] = {0};
ll a[N];
int main(){
    int n, p;
    string s;
    cin>>n>>p;
    for(int i = 1; i <= n; ++i) 
        scanf("%1d", &a[i]);
    ll ans = 0;
    if(p == 2 || p == 5){
        for(int i = 1; i <= n; ++i){
            if(a[i] % p == 0) ans += i;
        }
    }
    else{
        ll sum = 0, t = 1; vis[0] = 1;
        for(int i = n; i >= 1; --i){
            sum = sum + a[i]*t;
            sum %= p;
            ans += vis[sum]++;
            t = t*10%p;
        }
    }
    cout<<ans<<endl;
    // system("pause");
}

Measured memory_bytes: 1920
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp*/

#include <iostream>

using namespace std;

struct point{
    int x;
    int y;
};

char map[20][21];

int move(const struct point p,int h,int w){
    int count=1;
    map[p.x][p.y]='/';
    for (int i = 0; i < 4; ++i) {
        struct point tmp=p;

        switch (i){
            case 0:
                tmp.x++;
                break;
            case 1:
                tmp.x--;
                break;
            case 2:
                tmp.y++;
                break;
            case 3:
                tmp.y--;
                break;
            default:
                break;
        }
        if (tmp.x<w && tmp.y<h && map[tmp.x][tmp.y]=='.') {
            count+=move(tmp,h,w);
        }
    }
    return count;
}

int main(){
    int w,h;

    while (cin>>w>>h && (w>0 || h>0)){
        struct point start;

        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin>>map[j][i];
                if(map[j][i]=='@'){
                    start.x=j;
                    start.y=i;
                }
            }
        }
        cout<<move(start,h,w)<<endl;
    }
    return 0;
}

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

int main() {
	int k, n;
	cin >> k >> n;
	int arr[n] ;
	vector<int> v;
	for(int i = 0;i < n; i++)
	{
		cin >> arr[i];
	}
	for(int i = 0; i < n - 1; i++)
	{
		v.push_back(arr[i+1] - arr[i]);
	}
	v.push_back( k - abs(arr[0] - arr[n-1]) );
	sort(v.begin(), v.end());
	int sum = 0;
	for(int i = 0 ;i < n- 1; i++)
	{
		sum += v[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2168