akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    int table[101][101];
    int r, c;
    cin >> r >> c;
    int ysum[101] = {0,};
    int tsum[101] = {0,};
    int total = 0;

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j ++) {
            cin >> table[i][j];
            ysum[i] += table[i][j];
        }
    }
    for (int j = 0; j < c; j++) {
        for (int i = 0; i < r; i++) {
            tsum[j] += table[i][j];
        }
    }

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j ++) {
            cout << table[i][j] << " ";
        }
        cout << ysum[i] <<'\n';
        total += ysum[i];
    }

    for (int j = 0; j < c; j++) {
        cout << tsum[j] << " ";
        
    }
    cout << total << endl;

    return 0;

}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

void fastio(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	return;
}
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
	if (n == 0)return 1;
	if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
	return (x * modexp((x * x) % md, n / 2, md)) % md;
}


vvl dp(2001,vl(2001,-1));
vll a(2000);
ll happy(ll l,ll r,int n){
    //cout<<l<<" "<<r<<endl;
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(l==r){
        return dp[l][r]=a[n].first*abs(a[n].second-l);
    }
    dp[l][r]=happy(l+1,r,n+1)+a[n].first*abs(a[n].second-l);
    dp[l][r]=max(dp[l][r],happy(l,r-1,n+1)+a[n].first*abs(a[n].second-r));
    return dp[l][r];
}
int main() {
	fastio();
	//clock_t tm = clock();
	ll n;
    cin>>n;
    f(i,0,n){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(all(a),greater<pll>());
    cout<<happy(1,n,0)<<endl;
	//cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 35156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int INF = 1e9;

int main() {
    int k, n;
    cin >> k >> n;
    int a[n * 2];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    for (int i = n; i < n * 2; i++) a[i] = a[i - n];
    ll cs[2 * n] = {};
    for (int i = 1; i < 2 * n; i++) {
        cs[i] = cs[i - 1] + min(abs(a[i] - a[i - 1]), k - abs(a[i] - a[i - 1]));
    }
    ll ans = INF;
    for (int i = 0; i <= n; i++) {
        ans = min(ans, cs[i + n - 1] - cs[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

alias mint = ModInt!(10^^9 + 7);

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];

    auto comb = new Combinations!(10^^9+7)(N+10);
    mint ans = mint(0);

    foreach (zero; 0..min(N-1,K)+1) {
        auto a = comb.nCr(N, zero);
        auto b = comb.nCr(N-1, N-zero-1);
        ans += a * b;
    }

    ans.writeln;
}

// require: number/modint.d

// manually verified on: https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_e
// manually verified on: https://yukicoder.me/problems/no/117

class Combinations(uint mod) {
    alias mint = ModInt!mod;
    mint[] f;

    this(int maxval) {
        f = new mint[](maxval);
        f[0] = f[1] = mint(1);
        foreach(i; 1..maxval-1) {
            f[i+1] = f[i] * (i+1);
        }
    }

    mint nCr(int n, int r) {
        if (n < r) return mint(0);
        return f[n] / f[n-r] / f[r];
    }

    mint nPr(int n, int r) {
        if (n < r) return mint(0);
        return f[n] / f[n-r];
    }

    mint nHr(int n, int r) {
        if (n == 0 &&r == 0) return mint(1);
        if (n == 0) return mint(0);
        return f[n+r-1] / f[n-1] / f[r];
    }
}

// This implementation of ModInt references https://github.com/yosupo06/dunkelheit/blob/master/source/dkh/modint.d

// Manually verified on: https://yukicoder.me/problems/no/117
// Manually verified on: https://atcoder.jp/contests/cpsco2019-s3/tasks/cpsco2019_s3_f

struct ModInt(uint mod) {
    import std.conv : to;

    uint n;

    this(int n) {
        this.n = (n % mod + mod) % mod;
    }

    this(long n) {
        this.n = (n % mod + mod) % mod;
    }

    private this(uint n) {
        this.n = n;
    }

    string toString() const {
        return to!string(this.n);
    }

    private uint normilize(uint n) const {
        return n < mod ? n : n - mod;
    }

    private ModInt pow(uint n, long x) const {
        long ret = 1;
        long a = n;
        while (x) {
            if (x & 1) ret = ret * a % mod;
            a = a * a % mod;
            x >>= 1;
        }
        return ModInt(to!ulong(ret));
    }

    ModInt opBinary(string op : "+")(ModInt rhs) const {
        return ModInt(normilize(n + rhs.n));
    }

    ModInt opBinary(string op : "-")(ModInt rhs) const {
        return ModInt(normilize(n + mod - rhs.n));
    }

    ModInt opBinary(string op : "*")(ModInt rhs) const {
        return ModInt(to!uint(to!long(n) * rhs.n % mod));
    }

    ModInt opBinary(string op : "/")(ModInt rhs) const {
        return this * pow(rhs.n, mod-2);
    }

    ModInt opBinary(string op : "^^")(ModInt rhs) const {
        return pow(this.n, rhs.n);
    }

    ModInt opBinary(string op, T)(T rhs) const {
        ModInt mod_rhs = ModInt(rhs);
        return opBinary!op(mod_rhs);
    }

    ModInt opOpAssign(string op)(ModInt rhs) {
        return mixin ("this=this"~op~"rhs");
    }
}

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

struct node
{
    // int id;
    int k;         // degree
    vector<int> c; // children
    int p = -1;    // parent
    int d;         // depth
    string type;   // {root, internal node, leaf}
};

int main(int argc, char const *argv[])
{
    // rt[0] = {0, 3, vector<int>{1, 4, 10}, -1, 0};

    // vector<int> a(3, 0);

    int n = 0;
    cin >> n;

    vector<node> RootedTree(n);

    for (int i = 0; i < n; ++i)
    {
        int id = 0, k = 0;
        cin >> id >> k;
        RootedTree[id].k = k;

        RootedTree[id].c = vector<int>(RootedTree[id].k, 0);
        for (int j = 0; j < RootedTree[id].k; ++j)
        {
            cin >> RootedTree[id].c[j];
            RootedTree[RootedTree[id].c[j]].p = id;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        if (RootedTree[i].p == -1)
        {
            RootedTree[i].type = "root";
        }
        else if (RootedTree[i].k > 0)
        {
            RootedTree[i].type = "internal node";
        }
        else if (RootedTree[i].k == 0)
        {
            RootedTree[i].type = "leaf";
        }
    }

    for (int i = 0; i < n; ++i)
    {
        // cout << i << "-th node has the parent " << RootedTree[i].p << endl;
        
        int depth = 0;
        node current = RootedTree[i];

        while (current.p != -1)
        {
            // cout << "while clojure" << endl;
            depth++;
            current = RootedTree[current.p];
        }

        RootedTree[i].d = depth;
    }

    for (int i = 0; i < n; ++i)
    {
        cout << "node " << i << ": parent = " << RootedTree[i].p;
        cout << ", depth = " << RootedTree[i].d << ", " << RootedTree[i].type;
        cout << ", [";
        if (RootedTree[i].k > 0)
        {
            for (int j = 0; j < RootedTree[i].k - 1; j++)
            {
                cout << RootedTree[i].c[j] << ", ";
            }
            cout << RootedTree[i].c[RootedTree[i].k - 1];
        }
        cout << "]" << endl;
    }

    return 0;
}



Measured memory_bytes: 13012
while True:
  try:
    xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = map(float,input().split())
  except:
    break
  if (min(xa1,xa2) <= max(xb1,xb2) and max(xa1,xa2) >= min(xb1,xb2)) and (min(ya1,ya2) <= max(yb1,yb2) and max(ya1,ya2) >= min(yb1,yb2)):
    print("YES")
  else:
    print("NO")

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

int main() {
    int N;
    cin >> N;
    
    int *a = new int[N]; 
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }

    sort(a, a + N);

    int cnt = 0;
    for (int i = 0; i < N-1; i++)
    {
        if(a[i] != a[i+1])
        {
            cnt++;
        }
    }

    cout << cnt+1 << endl;


    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) cin >> v.at(i);
    int mini = v.at(0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (mini >= v.at(i)) ans++;
        mini = min(mini, v.at(i));
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    cout << ((N-1)/111 + 1) * 111 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  if(N%2 == 0) cout << N << endl;
  else cout << 2*N << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int get(int n){
    string s = to_string(n);
    return s[0] - '0';
}

int run_test(){
    int n;
    cin>> n;
    int arr[10][10];
    for(int i=0; i<10; i++){
        for(int j =0; j < 10; j++){
            arr[i][j] = 0;
        }
    }
    for(int i=1; i<=n; i++){
        int r = i % 10;
        int l = get(i);
        arr[l][r]++;
    }
    ll ans = 0;
    for(int i=1; i<10; i++){
        for(int j =1; j< 10; j++){
            ans += arr[i][j] * arr[j][i];
        }
    }
    cout << ans;
    return 0;

}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

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

int main()
{
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+')
        cout << (a + b) << endl;
    else
        cout << (a - b) << endl;
}


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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int n;

int a[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    ll ans = 0;
    int curr = 0;
    for(int i = 1; i <= n; i++)
    {
        curr = max(curr, a[i]);
        ans += curr - a[i];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4392
#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 pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}







int main(){
 string o,e;
 cin >> o >> e;
 rep(i,o.size()){
   cout << o[i];
   if (i<e.size()) cout << e[i];
 }
 cout << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import product

def main():
    n = int(input())
    s = input()
    ans = "-1"

    ls = list(product("SW", repeat = 2))

    for tpl in ls:
        anss = str(tpl[0]) + str(tpl[1])
        for i in range(1,n+1):
            if anss[-1] == "S":
                if s[i-1] == "o":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
            else:
                if s[i-1] == "x":
                    anss += anss[-2]
                else:
                    if anss[-2] == "S":
                        anss += "W"
                    else:
                        anss += "S"
        if anss[:2] == anss[-2:]:
            ans = anss[1:-1]
            break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  string s;
  cin>>s;
  char c=s[0];
  int res=0;
  for(int i=1;i<s.size();i++){
    if(c!=s[i]){
      c=s[i];
      res++;
    }
  }
  cout<<res<<endl;
  return 0;
}


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

const ll mod = 1e+9 + 7;

ll power(ll a, ll x){
    if(x == 0) return 1;
    if(x & 1) return a * power(a, x-1) % mod;
    return power(a * a % mod, x / 2);
}

ll fact(ll n){
    //if(n == 0) return 1;
    //return n * fact(n-1) % mod;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        res = res * i % mod;
    }
    return res;
}

ll combi(ll n, ll r){
    ll tmp = fact(n) * power(fact(r), mod-2) % mod;
    return tmp * power(fact(n-r), mod-2) % mod;
}

int main(){
    int x, y;
    cin >> x >> y;
    int a = (2*y - x) / 3;
    int b = (2*x - y) / 3;
    if((2*y - x) % 3 != 0 || (2*x - y) % 3 != 0
        || a < 0 || b < 0){
        cout << 0 << endl;
        return 0;
    }
    cout << combi(a + b, a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define ll long long
using namespace std;

int main(){
 //cout<<123<<endl;
  double T,X;
  cin>>T>>X;
  cout<<T/X<<endl;
  
  return 0;
}


Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 10;

int p[N], nxt[N], par[N];

int get_root(int u);
bool merge(int u, int v);

int main() {
	fast_cin();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	for (int i = 1; i <= n; ++i) {
		par[i] = i;
	}
	int ans = n - k + 1, s_id = -1;
	nxt[n] = n;
	for (int i = n - 1; i >= 1; --i) {
		nxt[i] = nxt[i + 1];
		if (p[i + 1] < p[i]) {
			nxt[i] = i;
		}
		if (nxt[i] >= i + k - 1) {
			s_id = max(s_id, i);
			ans -= merge(i, s_id);
		}
	}
	set<int> s1, s2;
	for (int i = 1; i <= k; ++i) {
		s1.insert(p[i]);
	}
	for (int i = 2; i <= k + 1; ++i) {
		s2.insert(p[i]);
	}
	for (int i = 1; i + k <= n; ++i) {
		if (*s1.begin() == p[i] and *s2.rbegin() == p[i + k]) {
			ans -= merge(i, i + 1);
		}
		s1.erase(p[i]);
		s1.insert(p[i + k]);
		s2.erase(p[i + 1]);
		s2.insert(p[i + 1 + k]);
	}
	cout << ans << endl;
}

int get_root(int u) {
	if (u != par[u]) {
		par[u] = get_root(par[u]);
	}
	return par[u];
}

bool merge(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u == v) {
		return false;
	}
	par[u] = v;
	return true;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

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

void Main() {
	ll N, M; cin >> N >> M;
	vvll dp(3*N+1, vll(4*N+1, 0));
	dp[0][N] = 1;

	for (int i = 0; i < 3*N; i++) {
		for (int j = 0; j < 4*N; j++) {
			if (i < 3*N-2) (dp[i+3][j] += dp[i][j] * (3*N-i-1) % M * (3*N-i-2)) %= M;
			if (i < 3*N-1 && j > 0) (dp[i+2][j-1] += dp[i][j] * (3*N-i-1)) %= M;
			(dp[i+1][j+1] += dp[i][j]) %= M;
		}
	}
	ll sum = 0;
	for (int i = N; i <= 4*N; i++) (sum += dp[3*N][i]) %= M;
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 375680
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

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

const int INF = 1 << 24;

typedef unsigned long long ull;

int main(){
    int N, D;// D: days
    std::cin >> D >> N;

    int T[210], A[210], B[210], C[210];
    REP(i, D){
        std::cin >> T[i];
    }

    REP(i, N){
        std::cin >> A[i] >> B[i] >> C[i]; // <=, value
    }

    int dp[210][210];
    REP(i, D){
        REP(i, N){
            dp[D][N] = 0;
        }
    }

    REP(i, N){
        if(A[i] <= T[0] && T[0] <= B[i]){
            dp[0][i] = 0;
        }else{
            dp[0][i] = -INF;
        }
    }

    FOR(i, 1, D){
        REP(j, N){
            if(A[j] <= T[i] && T[i] <= B[j]){
                REP(k, N){
                    dp[i][j] = std::max(dp[i][j], dp[i-1][k] + std::abs(C[k] - C[j]));
                }
            }else{
                dp[i][j] = -INF;
            }
        }
    }

    // REP(i, D){
    //     REP(j, N){
    //         printf("%d ", dp[i][j]);
    //     }
    //     puts("");
    // }
    
    int res = 0;
    REP(i, N){
        res = std::max(res, dp[D-1][i]);
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 1332
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;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; }
 
signed main(){
    ll n;
    cin >> n;
    vector<ll> a(n), suma(n+1);
    rep(i, n) cin >> a[i];
    rep(i, n) suma[i+1] = suma[i] + a[i];
 
    ll ans = 0;
    rep(i, n-1){
        ll x = suma[n] - suma[i+1];
        x %= MOD;
        /* cout << a[i] << " * " << x << endl; */
        ans += (a[i] * x);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6404
S = list(map(int, list(input())))

def ops(x):
    o = []
    for i in range(len(S)-1):
        o.append(x%2 == 1)
        x //= 2
    return o

ans = 0
for i in range(2**(len(S)-1)):
    op = ops(i)
    x = S[0]
    for i in range(len(S)-1):
        if op[i]:
            ans += x
            x = S[i+1]
        else:
            x = x*10 + S[i+1]
    ans += x
print(ans)


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

int main() {
  string S, T; cin >> S >> T;
  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3912
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  vector<double> p(N);
  FOR(i, N) cin >> p[i];
  vector<vector<double>> dp(N + 1, vector<double>(N + 1));
  dp[0][0] = 1;
  FORIN(i, 1, N + 1) {
    FOR(j, i + 1) {
      if (j > 0)
        dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
      if (j < i)
        dp[i][j] += dp[i - 1][j] * (1.0 - p[i - 1]);
    }
  }
  double ans = 0;
  FORIN(i, (N + 1) / 2, N + 1) { ans += dp[N][i]; }
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
const int MAXN = 100000;
char ret[20];
int Query(int ans){
    printf("%d\n", ans);
	fflush(stdout);
    scanf("%s", ret);
    if( ret[0] == 'V' ) return -1;
    return ret[0] == 'M' ? 1 : 0;
}
int guess[MAXN + 5];
int main() {
	int N;
	scanf("%d", &N);
	int p = Query(0);
	if( p == -1 )
		return 0;
	for(int i=0;i<N;i++)
		guess[i] = (i&1)^p;
	int le = 0, ri = N-1;
	while( true ) {
		int Mid = (le+ri) / 2;
		int res = Query(Mid);
		if( res == -1 )
			return 0;
		if( res == guess[Mid] )
			le = Mid+1;
		else ri = Mid-1;
	}
}

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

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;
  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }
  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }
  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


int main(){
  int n,q; cin>>n>>q;
  BinaryIndexedTree<ll> bit(n);
  rep(i,n){
    int a; cin>>a;
    bit.add(i,a);
  }
  while(q--){
    ll t; cin>>t;
    if(t==0){
      ll p,x; cin>>p>>x;
      bit.add(p,x);
    }else if(t==1){
      ll l,r; cin>>l>>r;
      ll ans = bit.sum(r-1) - bit.sum(l-1);
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8208
#include <iostream>
#include<algorithm>
#include<vector>
#include <bits/stdc++.h>

using namespace std;

int main() {
	string N;
	cin >> N;
	long long sum = 0;
	for (int i = 0; i < N.size(); i++) {
		sum += N[i] - '0';
	}
	if (sum % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#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 INF 2e12
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
  
int main()
{
  ll N,M;
  cin >> N >> M;
  vector<vector<ll>> A(N,vector<ll>(3));
  REP(i, N){
    REP(j, 3){
      cin >> A.at(i).at(j);
    }
  }

  ll MAX = 0;
  REP(i,1<<3){
    bitset<3> bs(i);
    vector<P> vec(N);
    REP(j,N){
      ll cnt = 0;
      REP(k,3){
        if(bs[k]==0){
          cnt+=A.at(j).at(k);
        }else{
          cnt+=-A.at(j).at(k);
        }
      }
      vec[j].first=cnt;
      vec[j].second=j;
    }
    sort(ALL(vec));
    reverse(ALL(vec));
    ll ans=0;
    ll x=0,y=0,z=0;
    REP(j,M){
      ans+=vec[j].first;
      x+=A[vec[j].second][0];
      y+=A[vec[j].second][1];
      z+=A[vec[j].second][2];
    }
    if(((x>=0&&bs[0]==0)||(x<0&&bs[0]==1))&&((y>=0&&bs[1]==0)||(y<0&&bs[1]==1))&&((z>=0&&bs[2]==0)||(z<0&&bs[2]==1))){
      MAX=max(MAX,ans);
    }
  }

  cout << MAX << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) cin >> s[i];
    int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                int b = 0;
                for (int k = 0; k < 8; k++) {
                    if (i + dx[k] < 0 || i + dx[k] >= h) continue;
                    if (j + dy[k] < 0 || j + dy[k] >= w) continue;
                    if (s[i + dx[k]][j + dy[k]] == '#') b++;
                }
                s[i][j] = b + '0';
            }
        }
    }
    for (int i = 0; i < h; i++) {
        cout << s[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N;
string s[50];
int t[50];
int ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>s[i]>>t[i];
	string x;cin>>x;
	bool flag=false;
	for(int i=0;i<N;i++)
	{
		if(flag)ans+=t[i];
		if(s[i]==x)flag=true;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
# Judge Status Summary

N = int(input())
stringList = [input() for i in range(N)]

c0 = 0
c1 = 0
c2 = 0
c3 = 0


for j in range(N):
    if stringList[j] == 'AC':
        c0 = c0 + 1
    if stringList[j] == 'WA':
        c1 = c1 + 1
    if stringList[j] == 'TLE':
        c2 = c2 + 1
    if stringList[j] == 'RE':
        c3 = c3 + 1

print('AC x '+ str(c0))
print('WA x '+ str(c1))
print('TLE x '+str(c2))
print('RE x '+ str(c3))



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

int main(){
  int n,sum=0;
  cin >> n;
  vector<int> va(n,0),vb(n-1,0);
  r(0,i,n-1)cin >> vb.at(i);
  r(0,i,n){
    if(i==0)va.at(i)=vb.at(i);
    else if(i==n-1)va.at(i)=vb.at(i-1);
    else va.at(i)=min(vb.at(i),vb.at(i-1));
    sum+=va.at(i);  
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
main(i,j,k){
  for(k=1,i=2;i<200000;i++)
    if(!pr[i])
      for(p[k++]=i,j=i*2;j<200000;j+=i)pr[j]=1;
  for(k=1;k<10001;k++)
    p[k]+=p[k-1];
  for(;scanf("%d",&i),i;printf("%d\n",p[i]));
  return 0;
}

Measured memory_bytes: 0
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,D = LI()
XY = [LI() for _ in range(N)]
ans = 0
for x,y in XY:
    temp = x**2+y**2
    if temp<=D**2:
        ans += 1
print(ans)


Measured memory_bytes: 45452
#include <stdio.h>

int main(){
  char b[5];

  scanf("%c %c %c",&b[0],&b[1],&b[2]);

  if((b[0]=='1' && b[1]=='1') || b[2]=='1') printf("Open\n");
  else printf("Close\n");

  return 0;
}

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

int main() {
    int n, a, cnt=1, count=0;
    bool flag=false;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a;
        if((cnt==a)) {
            cnt++;
            flag=true;
        }
        else count++;
    }
    if(flag) cout << count;
    else cout << -1;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.function.BiConsumer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			long n = in.nextLong();
			long a = in.nextLong();
			long b = in.nextLong();
			long ans = (n / (a + b)) * a;
			if (n % (a + b) > a) {
				ans += a;
			} else if (n % (a + b) < a) {
				ans += n % (a + b);
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

	}
}


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

class Main{
    public static void main(String[] args) throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");

        double r = Double.parseDouble(strArr[0]);
        double area = r * r * Math.PI;
        double length = 2 * Math.PI * r;

        System.out.printf("%.6f %.6f\n", area,length);

    }
}

Measured memory_bytes: 24844
n, p = map(int, input().split())
A = list(map(int, input().split()))

cnt_even = 0
for i in range(n):
	if A[i] % 2 == 0:
		cnt_even += 1

if cnt_even == n:
	if p == 0:
		print(2 ** n)
	else:
		print(0)
else:
	print(2 ** (n - 1))

Measured memory_bytes: 38384
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a <= 9 && b <= 9 ? (a * b) : -1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	long a,b,x;cin>>a>>b>>x;
	cout<<b/x+1-(a ? (a-1)/x+1 : 0)<<endl;
}

Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  int h1, m1; cin >> h1 >> m1;
  int h2, m2; cin >> h2 >> m2;
  int k; cin >> k;
  int tot = (h2 - h1) * 60 - m1 + m2;
  cout << tot - k << '\n';
}

int main() {
  int t; t = 1;
  while(t--) solve();
}

Measured memory_bytes: 3640
#!/usr/bin/env ruby



$visited = []
$pre_vertex = []


def min a,b
  if a<b then return a else b end
end

def init_dfs v,e
  $visited = Array.new(v,false)
  $pre_vertex = Array.new(v,false)
end

#b -> e ??§edges
def dfs b,e,es
  es[b].each_with_index do |c,v|
    if !$visited[v] and c>0 then
      $visited[v] = true
      $pre_vertex[v] = b
      if v==e then
        return
      end
      dfs(v,e,es)
    end
  end
end


def back_trace v,e,es
  flow =[]
  min_c = 10e8

  to = v-1
  from = $pre_vertex[v-1]
  flow=[[from,to]]+flow
  min_c = min(min_c,es[from][to])

  while from != 0
    to = from
    from = $pre_vertex[from]
    flow=[[from,to]]+flow
    min_c = min(min_c,es[from][to])
  end
  return flow,min_c
end



v_size,e_size = gets.chomp.split(/ /).map{|i| i.to_i}

edges = Array.new(v_size).map{ Array.new(v_size,0)}


e_size.times do
  u,v,c = gets.chomp.split(/ /).map{|i| i.to_i}
  edges[u][v]=c
end

  @ans = 0
loop do
  init_dfs(v_size,e_size)
  dfs(0,v_size-1,edges)
  if $visited[v_size-1] then
    f,min_c = back_trace(v_size,e_size,edges)
    f.each do |i|
      edges[i[0]][i[1]]-=min_c
      edges[i[1]][i[0]]+=min_c
    end
    @ans = @ans+ min_c
  else
    p @ans
    break
  end
end

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

int main() {
  ll l, r, d;
  cin >> l >> r >> d;
  ll ans=0;
  for (ll i=d;i<=r;i+=d) {
    if (i>=l) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3632
class Solution:
    def CountABC(self, s: str):
        if len(s) < 3:
            return 0
        count = 0
        for idx in range(len(s)):
            if s[idx : idx + 3] == "ABC":
                count += 1
        return count


if __name__ == "__main__":
    n, s = int(input()), input()
    solution = Solution()
    print(solution.CountABC(s))



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> mn(n), cnt(n);
    vector< vector<int> > v(3);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mn[i] = cnt[i] = 0;
        for (auto& c : s) {
            if (c == ')') {
                cnt[i]--;
            }
            else {
                cnt[i]++;
            }
            mn[i] = min(mn[i], cnt[i]);
        }
        if (mn[i] == 0) {
            v[0].push_back(i);
        }
        else {
            if (cnt[i] >= 0) {
                v[1].push_back(i);
            }
            else {
                v[2].push_back(i);
            }
        }
    }
    if (accumulate(cnt.begin(), cnt.end(), 0) != 0) {
        cout << "No\n";
        return 0;
    }
    bool pos = true;
    if (v[0].empty()) {
        pos = false;
    }
    int cur = 0;
    for (auto& x : v[0]) {
        cur += cnt[x];
    }
    sort(v[1].begin(), v[1].end(), [&](const int &a, const int &b) {
        return mn[a] > mn[b];
    });
    for (auto& x : v[1]) {
        if (cur + mn[x] < 0) {
            pos = false;
            break;
        }
        cur += cnt[x];
    }
    sort(v[2].begin(), v[2].end(), [&](const int &a, const int &b) {
        return cnt[a] - mn[a] > cnt[b] - mn[b];
    });
    for (auto& x : v[2]) {
        if (cur + mn[x] < 0) {
            pos = false;
            break;
        }
        cur += cnt[x];
    }
    if (pos) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 15176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
string s = "RYGB";
int main(){
    int h, w, d;
    cin >> h >> w >> d;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int k = (i + j) / d % 2;
            int l = abs(i - j - h + 1) / d % 2;
            cout << s[k * 2 + l];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 512
while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        w=0
        e=[]
        b=0
        for i in range(n):
            d=[int(x) for x in raw_input().split()]
            e.append((d[1],d[0]))
            e.append((d[2],-d[0]))
        es=sorted(e)
        for i in range(2*n):
            h=es.pop(0)
            w=w+h[1]
            if w>150:
                b=1
                break
        if b:
            print 'NG'
        else:
            print 'OK'

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    ll x = tx-sx;
    ll y = ty-sy;
    FOR(i,0,y){
      cout<<"U";
    }
    FOR(i,0,x){
      cout<<"R";
    }

    FOR(i,0,y){
      cout<<"D";
    }
    FOR(i,0,x){
      cout<<"L";
    }
    cout<<"L";
    FOR(i,0,y+1){
      cout<<"U";
    }
    FOR(i,0,x+1){
      cout<<"R";
    }
    cout<<"DR";
    FOR(i,0,y+1){
      cout<<"D";
    }
    FOR(i,0,x+1){
      cout<<"L";
    }
    cout<<"U"<<endl;

}


Measured memory_bytes: 256
in1 = input()
ins = in1.split()
oneNum = int(ins[0])
zeroNum = int(ins[1])
enoNum = int(ins[2])
num = int(ins[3])


if oneNum >= num:
  print(num)
else:
  sum = oneNum
  num -= oneNum
  num -= zeroNum
  if num <= 0:
    print(sum)
  else:
    sum -= num
    print(sum)


Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };



int main() {

	int n;
	int ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
    cin >> a >> b;
    if(a > b)
    	cout << 2*a -1 <<'\n';
    else if(a == b)
    	cout << 2*a <<'\n';
    else
    	cout << 2*b -1 << '\n';


	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

def gcd(a,b):
    if (b == 0) :
        return a
    else:
        return gcd(b, a%b)

num = gcd(a[0],a[1])

for i in range(n):
    num = gcd(num,a[i])
    if num == 1:
        break
print(num)


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

int main()
{
    int A[2][100];
    int N;
    int max = 0;

    cin >> N;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    for (int i = 1; i <= N; i++) {
        int tmp1 = 0;
        int tmp2 = 0;
        
        for (int j = 0; j < i; j++) {
            tmp1 += A[0][j];
        }
        for (int k = i - 1; k < N; k++) {
            tmp2 += A[1][k];
        }
        
        if(max < (tmp1 + tmp2)) {
            max = tmp1 + tmp2;
        }
    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

x = [0 for i in range(n)]
y = [0 for i in range(n)]
h = [0 for i in range(n)]

k = 0

for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())
    if h[i] > 0:
        k = i

ansx = -1
ansy = -1
ansh = -1

for cx in range(101):
    for cy in range(101):
        H = h[k] + abs(x[k] - cx) + abs(y[k] - cy)
        flag = True
        for i in range(n):
            if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
                flag = False
                break
        if flag:
            ansx = cx
            ansy = cy
            ansh = H
            break
    if ansx >= 0:
        break

print(ansx, ansy, ansh)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdlib.h>

typedef long long int lli;
using namespace std;

void yespr(){cout<<"Yes\n"<<endl;}
void nopr(){cout<<"No\n"<<endl;}

int main(void){
    int n;
    int a[200000];
    int list[200000];

    cin>>n;

    for(int i=0;i<200000;i++)list[i]=0;
    for(int i=1;i<n;i++){
        cin>>a[i];
        list[a[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<list[i]<<endl;
    }    return 0;
}

Measured memory_bytes: 5204
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    boolean ok = true;

    if (s.charAt(0) != 'A') {
      ok = false;
    }

    boolean cok = true;
    for (int i = 2; i < (s.length() - 1); i++) {
      if (s.charAt(i) == 'C') {
        if (!cok) {
          ok = false;
        } else {
          cok = false;
        }
      }
    }

    if (cok) {
      ok = false;
    }

    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if ((c != 'A') && (c != 'C')) {
        if (!(('a' <= c) && (c <= 'z'))) {
          ok = false;
        }
      }
    }

    if (ok) {
      System.out.println("AC");
    } else {
      System.out.println("WA");
    }

  }
}

Measured memory_bytes: 35668
import java.util.*;
class Main {
  public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
    int n= scan.nextInt();
    ArrayList<Integer> a = new ArrayList<>();
    int i = 1 ;
    while(true){
      
      
      //System.out.println(n);
      if(a.contains(n)){
        System.out.println(i);
        break;
      }else{
        a.add(n);
      }
      
      if( n %2 == 0){
        n = fe(n);
      }else{
        n = fo(n);
      }
      i++;
    }
    
    
  }
  
  static int fe(int n){
    return n/2 ;
  }
  
  static int fo(int n){
    return 3*n + 1 ; 
  }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    vector<int> v(n);
    REP(i,n){
        cin>>v[i];
    }
    int result=0;
    REP(i,n){
        if(i==v[v[i]-1]-1){
            result++;
            //cout<<v[i]-1<<
        }

    }

    cout<<result/2<<endl;
    return 0;
}


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

using i64 = int64_t;

int const N = 1e6 + 5;

i64 f[N], g[N];
int sum_C[N];
char s[N];
int n;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin >> n;
	std::cin >> s + 1;
	for(int i = 1; i <= n; ++i)
		g[i] = g[i - 1] + (s[i] == 'M');
	for(int i = 1; i <= n; ++i)
		f[i] = f[i - 1] + (s[i] == 'C' ? g[i] : 0);
	for(int i = 1; i <= n; ++i)
		sum_C[i] = sum_C[i - 1] + (s[i] == 'C' ? 1 : 0);

	int Qcnt;
	std::cin >> Qcnt;
	while(Qcnt--) {
		int k;
		std::cin >> k;
		i64 ans = 0;
		for(int i = 1; i <= n; ++i)
			if(s[i] == 'D') {
				int mx = std::min(n, i + k - 1);
				int cnt_C = sum_C[mx] - sum_C[i - 1];
				ans += f[mx] - f[i] - cnt_C * g[i];
			}
		std::cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 20736