akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
    int a,b,c,d,l,off,kokugo=0,sansu=0,i;
    scanf("%d",&l);
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    for(i=0;i<a;i+=c){
        kokugo=kokugo+1;
    }
    for(i=0;i<b;i+=d){
        sansu=sansu+1;
    }
    if(kokugo<=sansu){
        off=l-sansu;
    }else{
        off=l-kokugo;
    }
    printf("%d\n",off);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q; string S; cin >> N >> S >> Q;
  vector<set<int> > alp(26, set<int>());
  REP(i, N){
    alp[S[i]-'a'].insert(i); // setに要素(位置情報)を追加
  }
  vector<int> ans;
  REP(i, Q){
    int q; cin >> q;
    if(q == 1){
      int I; char c; cin >> I >> c; I--;
      char cc = S[I];
      S[I] = c; 
      alp[cc-'a'].erase(I);
      alp[c-'a'].insert(I);
    }else{
      int l, r; cin >> l >> r; l--; r--;
      int cnt = 0;
      REP(j, 26){
        if(alp[j].empty()) continue;
        int li = (alp[j].lower_bound(l) == alp[j].end() ? N : *alp[j].lower_bound(l));
        if(li <= r) cnt++;
      }
      ans.push_back(cnt);
    }
  }
  for(auto &i : ans){
    cout << i << endl;
  }  
}

Measured memory_bytes: 24476
#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 vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;
 
const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;
 
/*
  filippos
  Contest : AtCoder DP contest
  Task : S - Digit Sum
*/
 
int main(){
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

  string s; cin >> s;
  int d; cin >> d;
  const int n = s.size();

  const int MOD = 1e9 + 7;
  vector<vvi> memo(n, vvi(2, vi(d, -1)));

  function<int(int, bool, short)> dp = [&](int i, bool less, short sum) {
    // base case
    if(i == n) return (int)(sum == 0);
    int &ans = memo[i][less][sum];
    if(ans != -1) return ans;
    ans = 0;
    const short lim = (less ? 9 : (s[i] - '0'));
    // cout << "dp " << i << " " << less << " " << sum << ", lim: " << lim << '\n';
    for(short digit = 0; digit <= lim; digit++){
      ans = (ans + dp(i + 1, less | (digit < lim), (sum + digit) % d)) % MOD;
    }
    return ans;
  };

  cout << (dp(0, 0, 0) - 1 + MOD) % MOD;

  return cout << endl, 0;
}

Measured memory_bytes: 10240
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(void){
	
	
	vector<int> temp;
	vector<int> num;
	char ruman_num[100]={'0'};
	int sum;
	
	
	while(scanf("%s",ruman_num)!=EOF){
		sum=0;
		
		for(int i=0;i<100;i++){
			if(ruman_num[i]=='I'){
				num.push_back(1);
			}else if(ruman_num[i]=='V'){
				num.push_back(5);
			}else if(ruman_num[i]=='X'){
				num.push_back(10);
			}else if(ruman_num[i]=='L'){
				num.push_back(50);
			}else if(ruman_num[i]=='C'){
				num.push_back(100);
			}else if(ruman_num[i]=='D'){
				num.push_back(500);
			}else if(ruman_num[i]=='M'){
				num.push_back(1000);
			}else if(ruman_num[i]=='0'){
				break;
			}
		}
		
		num.push_back(0);
		for(int i=0;i<(num.size())-1;i++){
			if(num[i]<num[i+1]){
				temp.push_back(num[i+1]-num[i]);
				i++;
			}else{
				temp.push_back(num[i]);
			}
		}
			
			
		for(int i=0;i<temp.size();i++){
			sum=sum+temp[i];
		}
			
			
		cout<<sum<<endl;
		temp.clear();
		num.clear();
		for(int i=0;i<100;i++){
			ruman_num[i]='0';
		}
	}
	return 0;
}

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

#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0(i, n) for (i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

//* utility function
inline bool compare(ll i, ll j)
{
    return i < j;
}
//*/

//* function prototypes
template< typename T>
T gcd(T a, T b);
template< typename T>
T modpow(T number, T power, T mod_value);
//*/

//int row, column;
//int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
//int dx[4] = {1,  0, -1, 0};
//int dy[4] = {0, -1,  0, 1};
//ll p2[63] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904};
#ifdef DEBUG
#endif // DEBUG

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll number_of_test_case = 1, test_case;
    //cin >> number_of_test_case;
    for (test_case = 1; test_case <= number_of_test_case; test_case++)
    {
        ll n, i, ans = 0;
        cin >> n;

        for(i = sqrt(n); i > 0; i--)
        {
            if (n % i == 0)break;
        }
        cout << i + n/i -2 << endl;
    	//cout << "Test #" << test_case << ": ";
    	//cout << "Case " << test_case << ": ";
    }
    return 0;
}


template< typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
template< typename T>
T modpow(T number, T power, T mod_value)
{
    if (power == 0)
        return 1%mod_value;
    ll u = modpow(number,power/2,mod_value);
    u = (u*u)%mod_value;
    if (power%2 == 1)
        u = (u*number)%mod_value;
    return u;
}

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

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  rep(i, n) {
    string in;
    cin >> in;
    if(in=="AC") ++ac;
    else if(in=="WA") ++wa;
    else if(in=="TLE") ++tle;
    else ++re;
    
  }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;


int main()
{
	int m1, m2, d1, d2;

	cin >> m1 >> d1;
	cin >> m2 >> d2;

	if (d2 == 1)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}


	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 2e6+10;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second


int a[maxN];
int c[maxN];
int b[maxN];
int tot = 0;
int n;


int main() {
	
	int m1,d1,m2,d2;
	scanf("%d%d%d%d",&m1,&d1,&m2,&d2);
	a[1] = a[3] = a[5] = a[7] = a[8] = a[10] = a[12] = 31;
	a[2] = 28;
	a[4] = a[6] = a[9] = a[11] = 30;
	if(a[m1] == d1)
	{
		puts("1");
	}
	else
	{
		puts("0");
	}
	return 0;
}

Measured memory_bytes: 2304
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef pair<long long,long long> P;
int main(){
    vector<P> z;
    long long i,j,x;
    cin >> x;
    i=0;
    while(i*i*i*i*i<=1000000000000000){
        z.push_back(P(i,i*i*i*i*i));
        i++;
    }
    for(i=0;i<z.size();i++){
        for(j=0;j<z.size();j++){
            if(z[i].second-z[j].second==x){
                printf("%lld %lld\n",z[i].first,z[j].first);
                return 0;
            }
        }
    }
    for(i=0;i<z.size();i++){
        for(j=0;j<z.size();j++){
            if(z[i].second+z[j].second==x){
                printf("%lld %lld\n",z[i].first,-1*z[j].first);
                return 0;
            }
        }
    }
  return 0;
}

Measured memory_bytes: 3736
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n = gets.to_i
a = gets.split.map(&:to_i)

count = 0
a.each_with_index do |data,i|
  if data % 2 == 1 && (i+1) % 2 == 1
    count += 1
  end 
end
puts count 

Measured memory_bytes: 14220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

static class CodeJam
{
    static int Max(string S, char C, int a, int b)
    {
        int max = 0;
        int cnt = 0;
        for (int i = a; i <= b; ++i)
        {
            cnt = (S[i] == C) ? (cnt + 1) : 0;
            max = Math.Max(cnt, max);
        }
        return max;
    }

    static bool Solve(int N, int A, int B, int C, int D, string S)
    {
        if (Max(S, '#', A, C) >= 2) { return false; }
        if (Max(S, '#', B, D) >= 2) { return false; }
        if (A < B && D < C)
        {
            if (S[B - 1] != '#' && S[B + 1] != '#') { return true; }
            if (S[D - 1] != '#' && S[D + 1] != '#') { return true; }
            if (Max(S, '.', B, D) < 3) { return false; }
        }
        else if (B < A && C < D)
        {
            if (S[A - 1] != '#' && S[A + 1] != '#') { return true; }
            if (S[C - 1] != '#' && S[C + 1] != '#') { return true; }
            if (Max(S, '.', A, C) < 3) { return false; }
        }
        return true;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        string S = Console.ReadLine();
        Console.WriteLine(Solve(V[0], V[1] - 1, V[2] - 1, V[3] - 1, V[4] - 1, S) ? "Yes" : "No");
    }
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  int odd = 0;

  rep(i, n) {
    int a; cin >> a;
    if (a % 2) ++odd;
  }

  if (odd % 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<vector<int>> ans(n+1);
  for(int i=0;i<n-1;i++){
    int a;cin>>a;
    ans[a].push_back(i+2);
  }
  for(int i=0;i<n;i++){
    cout<<ans[i+1].size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 13904
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define oo (1<<30)
#define min(a,b) (a)<(b)?(a):(b)
char mp[110][110];
int h,w;
#define S 0
#define T h+w+1
struct Edges
{
	int to,next;
	int flow;
}edges[202020];
int te=1;
int first[220];
int second[220];
void addE(int a,int b,int c)
{
	te++;
	edges[te].to=b;
	edges[te].next=first[a];
	first[a]=te;
	edges[te].flow=c;
}
int dis[220];
bool bfs()
{
	memset(dis,-1,sizeof(dis));
	queue<int> q;
	q.push(S);
	dis[S]=0;
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		for(int e=first[now];e;e=edges[e].next)
		{
			int to=edges[e].to;
			if(edges[e].flow&&dis[to]==-1)
			{
				dis[to]=dis[now]+1;
				q.push(to);
			}
		}
	}
	return dis[T]!=-1;
}
long long dfs(int now,long long flow)
{
	if(!flow||now==T)
		return flow;
	long long ret=0;
	for(int &e=second[now];e;e=edges[e].next)
	{
		int to=edges[e].to;
		if(dis[to]==dis[now]+1&&edges[e].flow)
		{
			long long tmp=dfs(to,min(flow,edges[e].flow));
			edges[e].flow-=tmp;
			edges[e^1].flow+=tmp;
			ret+=tmp;
			flow-=tmp;
			if(!flow)
				break;
		}
	}
	return ret;
}
int main()
{
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;i++)
		scanf("%s",mp[i]+1);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(mp[i][j]=='S')
			{
				addE(S,i,oo);
				addE(i,S,oo);
				addE(S,j+h,oo);
				addE(h+j,S,oo);
			}
			else if(mp[i][j]=='T')
			{
				addE(i,T,oo);
				addE(T,i,oo);
				addE(j+h,T,oo);
				addE(T,j+h,oo);
			}
			else if(mp[i][j]=='o')
			{
				addE(i,j+h,1);
				addE(j+h,i,1);
			}
	long long ans=0;
	while(bfs())
	{
		memcpy(second,first,sizeof(int)*(T+5));
		ans+=dfs(S,oo);
	}
	if(ans>=oo)
		puts("-1");
	else
		printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int X,Y,tx,ty,kx,ky;
int wall[50][50];
bool vis[50][50][50][50];

typedef struct _node{
  int cost,tx,ty,kx,ky;
  int geth()const{
    return (abs(tx-kx)+abs(ty-ky))/2;
  }
  bool operator<(const _node& r)const{
    return cost+geth()>r.cost+r.geth();
  }
  _node (int c,int atx,int aty,int akx,int aky){
    cost=c;
    tx=atx;
    ty=aty;
    kx=akx;
    ky=aky;
  }
}node;

void solve(){
  cin>>tx>>ty>>kx>>ky;
  --tx,--ty,--kx,--ky;
  rep(i,Y)rep(j,X)cin>>wall[i][j];

  priority_queue<node>q;
  q.push(node(0,tx,ty,kx,ky));
  memset(vis,0,sizeof(vis));
  while(!q.empty()){
    int cc=q.top().cost;
    tx=q.top().tx;
    ty=q.top().ty;
    kx=q.top().kx;
    ky=q.top().ky;
    q.pop();
    if(cc>=100 || vis[tx][ty][kx][ky])continue;
    vis[tx][ty][kx][ky]=true;
    if(tx==kx && ty==ky){
      cout<<cc<<endl;
      return;
    }
    rep(i,4){
      int ntx=tx+dx[i],nty=ty+dy[i];
      int nkx=kx-dx[i],nky=ky-dy[i];

      if(0>ntx || ntx>=X ||
         0>nty || nty>=Y ||
         wall[nty][ntx])ntx=tx,nty=ty;
      if(0>nkx || nkx>=X ||
         0>nky || nky>=Y ||
         wall[nky][nkx])nkx=kx,nky=ky;
      if(vis[ntx][nty][nkx][nky])continue;
      q.push(node(cc+1,ntx,nty,nkx,nky));
    }
  }
  cout<<"NA"<<endl;
}

main(){
  while(cin>>X>>Y,X)
    solve();
}

Measured memory_bytes: 7332
#include<iostream>
#include<cstdio>
#include<stack>
#include<cstdlib>
using namespace std;
int main()
{
  stack<int> S;
  int a,b,x;
  string s;
  while(cin>>s)
  {
    if(s[0] == '+')
  {
    a = S.top();S.pop();
    b = S.top();S.pop();
    S.push(a+b);
  }
  else if(s[0] == '-')
    {
      b = S.top();S.pop();
      a = S.top();S.pop();
      S.push(a-b);
    }
    else if(s[0] == '*')
    {
      a = S.top();S.pop();
      b = S.top();S.pop();
      S.push(a*b);
    }
    else S.push(atoi(s.c_str()));
  }
  cout<<S.top()<<endl;
  return 0 ;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    char c;
    cin >> c;
    cout << char(c+1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    int n,a;
    cin>>n;
    if (n%1000!=0) a=n/1000+1;
    else a = n/1000;
    cout<<a*1000-n;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 101024;
int a[MAXN];

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

    map<int,int> m;
    if(n % 2 == 0) {
        for(int i = 0; i < n/2; ++i) {
            m[2*i + 1] = 2;
        }
    }
    else {
        m[0] = 1;
        for(int i = 1; i <= n/2; ++i) {
            m[2*i] = 2;
        }
    }

    for(int i = 0; i < n; ++i) {
        if(m[a[i]] == 0) {
            cout << 0 << endl;
            return 0;
        }
        --m[a[i]];
    }

    ll res = 1;
    ll div = pow(10, 9) + 7;
    for(int i = 0; i < n/2; ++i) {
        res *= 2;
        res %= div;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define mo 998244353
int n,m,i,j,ans,flag,a[100005];
int read(){
	int xx=0,flag2=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
	if(ch=='-'){
		flag2=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return flag2*xx;
}
int main(){
	n=read();m=read();
	for(i=max(-1000000,m-n+1);i<=min(1000000,m+n-1);i++)
		cout<<i<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1e9+7;

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

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

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

// 確度を返す
double ltime(int i){
    // if(6*i)
    return 6*i;
}

double stime(int h, int m){
    if(h>12)h-=12;
    return h*30 + m*(1/2.0);
}

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double ang = ltime(m) - stime(h,m);
    if(ang<0)ang*=-1;
    if(ang>180)ang = 360- ang;
    double rad = ang * PI / 180.0;
    double ans = sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(rad));
    printf("%.15f\n",ans);
    return 0;
}

Measured memory_bytes: 4100
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar (' ')
#define EL putchar ('\n')
#define inf 2147483647
#define N 55
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
typedef unsigned long long int ll;
template<class T1>inline void read(T1&);
template<class T1>inline void write(T1);
ll work(int, ll);
ll num[N];
ll ful[N];
int main () {
    num[0]=1;
    ful[0]=1;
    for (int i=1; i<=50; ++i) {
        num[i]=3+(num[i-1]<<1);
        ful[i]=1+(ful[i-1]<<1);
    }
    int n;
    ll x;
    read(n);
    read(x);
    write(work(n, x));
    EL;
    return 0;
}
template<class T1>void read(T1 &r_e_a_d) {
    T1 k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch)) {
        if (ch=='-') {
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch)) {
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    r_e_a_d = flag*k;
}
template<class T1>void write(T1 w_r_i_t_e) {
    if (w_r_i_t_e<0) {
        putchar('-');
        write(-w_r_i_t_e);
    }else {
        if (w_r_i_t_e<10) {
            putchar(w_r_i_t_e+'0');
        }else {
            write(w_r_i_t_e/10);
            putchar((w_r_i_t_e%10)+'0');
        }
    }
}
ll work(int n, ll x) {
    if (n==0) {
        return x;
    }
    if (x<=0) {
        return 0;
    }
    --x;
    ll ans=0;
    if (x<=num[n-1]) {
        ans+=work(n-1, x);
    }else {
        ans+=ful[n-1]+1;
        x-=num[n-1]+1;
        ans+=work(n-1, min(x, num[n-1]));
    }
    return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;

void solve(){
	int n;
	cin>>n;
	cout<<1-n<<endl;
}

int main(){
	io;
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

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

const int maxn  = 200000 + 10;
int t[maxn];
int N, T;
int ans, i;

int main()
{
    scanf("%d%d", &N, &T);
    for(i = 0; i < N; i++) scanf("%d", &t[i]);
    for(i = 0, t[N] = 0x7fffffff, ans = 0; i < N; i++)
    {
        if(t[i+1] - t[i] >= T) ans += T;
        else ans += t[i+1] - t[i];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

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

// main function
int main()
{
	ll N = 0;
	string A, B, C;
	ll ans = 0;

	cin >> N >> A >> B >> C;
	Rep(i, N) {
		set<char> tmp;
		tmp.insert(A[i]);
		tmp.insert(B[i]);
		tmp.insert(C[i]);
		ans += (tmp.size() - 1);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
//#define endl '\n'

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}


int T, n, m;

const vector<string> code({
    "4:2",
    "5:2",
    "7:2",
    "9:2",
    "1:0",
    "6:0",
    "8:0",
    "00:0",
    "20:0",
    "30:0",
    "02:2",
    "22:2",
    "32:2",
    "03:3",
    "23:3",
    "33:3",
    "0::pon",
    "2::hon",
    "3::bon"
});

int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    vector<tuple<string, string, bool>> program;
    for (const string &l : code) {
        const long long int c = l.find(':', 0);
        if (l[c + 1] == ':') {
            program.emplace_back(l.substr(0, c), l.substr(c + 2), true);
        } else {
            program.emplace_back(l.substr(0, c), l.substr(c + 1), false);
        }
    }

    while (true) {
        bool end = true;
        for (const auto &op : program) {
            string src, dst;
            bool term;
            tie(src, dst, term) = op;
            int p = s.find(src, 0);
            if (p != string::npos) {
                s = s.substr(0, p) + dst + s.substr(p + src.size());
                end = term;
                break;
            }
        }
        if (end) break;
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
int main()
{
int a,b,c,d,n;
int i,j,k,l;
int ans=0;
while(scanf("%d",&n) != EOF){
for(i=0;i<10;i++){
for(j=0;j<10;j++){
for(k=0;k<10;k++){
for(l=0;l<10;l++){
if(i+j+k+l == n)
ans++;
}
}
}
}
printf("%d\n",ans);
ans = 0;
}
return 0;
}

Measured memory_bytes: 1024
def comb(n,x):
    ans = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    ans += 1
    return ans

n,x = map(int,input().split())
while True:
    print(comb(n,x))
    n,x = map(int,input().split())
    if n == 0:
        break



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct students{
  int number;
  int turn;
};

int main(){
  int N, A[100010];
  vector<students> array;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  for(int i=0;i<N;i++){
    students student = {i+1, A[i]};
    array.push_back(student);
  }
  
  sort(array.begin(), array.end(), 
  [](const students &x, const students &y) { return x.turn < y.turn; });
  
  for(int i=0;i<N-1;i++){
    cout << array[i].number << " ";
  }
  
  cout << array[N-1].number << endl;
  
  return 0;
  
}

Measured memory_bytes: 2164
import sys
K = int(input())
num = [i**5 for i in range(150)]
for i in range(len(num)):
    for j in range(len(num)):
        if num[i] - num[j] == K :
            print(i,j)
            sys.exit()
        elif num[i] + num[j] == K:
            print(i,-j)
            sys.exit()
            

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n;i++){
    	ll num=n-i;
    	ll ma=(n+1)*n/2-(num+1)*num/2;
    	ll mi=(i-1)*(i)/2;
    	num=(ma-mi+1)%mod;
    	ans+=num;
    	ans%=mod;
    }
    cout << (ans+1)%mod <<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, a, b;
	cin>>n>>a>>b;
	if(a*b<n||a+b>n+1){
		cout<<-1<<endl;
		return 0;
	}
	vector<int> res;
	for(ll i = n-a+1; i <= n; i++) res.pb(i);
	ll n2 = n-a;
	n = n2;
	rep(j, b-1){
		ll c = n/(b-1)+(n%(b-1)>j);
		for(ll i = n2-c+1; i <= n2; i++) res.pb(i);
		n2 -= c;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3440
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

signed main() {
  int H, W; 
  cin >> H >> W;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  int ans = 0;
  REP(i, H) REP(j, W){
    if(s[i][j] == '#') continue;

    int ret = 0;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[i][j] = 0;

    queue<pair<int, int>> q;
    q.push({i, j});
    while(!q.empty()){
      auto p = q.front(); q.pop();
      int x = p.first;
      int y = p.second;
      REP(i, 4){
        int xx = x+dx[i];
        int yy = y+dy[i];
        if(OUT(0, xx, H)) continue;
        if(OUT(0, yy, W)) continue;
        if(s[xx][yy] == '#') continue;
        if(dist[xx][yy] == INF){
          q.push({xx, yy});
          dist[xx][yy] = dist[x][y]+1;
          chmax(ret, dist[xx][yy]);
        }
      }
    }
    chmax(ans, ret);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n,maxval=0;
  cin>>n;
  map<string,ll> map;
  vector<string> vec(n);
  for(ll i=0;i<n;i++){
    string s;
    cin>>s;
    map[s]++;
  }
  for(auto it=map.begin();it!=map.end();it++){
    ll val = (*it).second;
    if(val>maxval){maxval=val;}
  }
  for(auto it = map.begin(); it != map.end(); it++){
    if((*it).second==maxval){
      cout<<(*it).first<<endl;
    }
  }
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
//#define double long double
const int maxn=2e5+10;
const int mod=998244353;
double dis[1005];
vector<pair<int,double>>E[1005];

struct ac
{
    double x,y,r;
};
ac a[1005];




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    double sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
       cin>>a[i].x>>a[i].y>>a[i].r;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            double temp=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
            temp-=a[i].r+a[j].r;
            temp=max(temp,0.0);
            E[i].pb({j,temp});
            E[j].pb({i,temp});
        }
    }
    double t=sqrt((sx-ex)*(sx-ex)+(sy-ey)*(sy-ey));
    dis[n+1]=t;
    for(int i=1;i<=n;i++)
    {
        double temp=sqrt((sx-a[i].x)*(sx-a[i].x)+(sy-a[i].y)*(sy-a[i].y));
        double temp2=sqrt((ex-a[i].x)*(ex-a[i].x)+(ey-a[i].y)*(ey-a[i].y));
        temp-=a[i].r;
        temp2-=a[i].r;
        temp=max(0.0,temp);
        temp2=max(0.0,temp2);
        E[i].pb({0,temp});
        E[0].pb({i,temp});
        E[n+1].pb({i,temp2});
        E[i].pb({n+1,temp2});

    }
    priority_queue<pair<double,int>>q;
    for(int i=1;i<=n;i++)
    {
        dis[i]=1e18;
    }
    dis[0]=0;
    q.push({0,0});
    while(!q.empty())
    {
        int u=q.top().second;
        q.pop();
        for(auto &v:E[u])
        {
            if(dis[v.first]>dis[u]+v.second)
            {
                dis[v.first]=dis[u]+v.second;
                q.push({-dis[v.first],v.first});
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dis[n+1]<<'\n';



}


Measured memory_bytes: 23752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    string S;
    cin >> A >> S >> B;
    if(S == "+")cout << A + B << endl;    
    else cout << A - B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
#include <bitset>
#include<set>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;
 
int main()
{
 ll n, k, ans;
 cin >> n >> k;
 int a1[n]; int a2[2*n];
 ll aa1=0,aa2=0;
 for(int i=0;i<n;i++){
   cin >> a1[i];
   a2[i]=a1[i];
   a2[n+i]=a1[i];
 }
 for(int i=0;i<n-1;i++){
   for(int j=i+1;j<n;j++){
     if(a1[i]>a1[j]) aa1=aa1+1;
   }
 }
  
  for(int i=0;i<2*n-1;i++){
   for(int j=i+1;j<2*n;j++){
     if(a2[i]>a2[j]) aa2=aa2+1;
   }
 }
  
 ans=((k*aa1)%MOD+(k*(k-1)/2)%MOD*((aa2-2*aa1)%MOD))%MOD;
// cout << aa1 << endl << aa2 << endl;
 cout << ans;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> p(n),c(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    bool flag=true;
    rep(i,n){
        cin>>c[i];
        if(c[i]>0) flag=false;
    }
    if(flag){//全部負だったら
        cout<<*max_element(begin(c),end(c))<<endl;
        return 0;
    }
    //答えは絶対正になる
    ll ans=0;
    rep(st,n){
        ll roop=0,num=0;
        for(ll v=p[st];;v=p[v]){
            roop+=c[v];
            num++;
            if(v==st) break;
        }
        ll cost=0,ret=k;
        if(roop>0){
            if(ret>=num){
                cost=roop*(ret/num-1);
                ret%=num;
                ret+=num;
            }
        }else{
            ret=num+1;
        }
        ll v=st;
        while(ret--){
            cost+=c[p[v]];
            v=p[v];
            chmax(ans,cost);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3732
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset
#include <queue>			//std::queue

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());
	//std::ofstream ofs("456.csv");
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();

	int N = 0;
	std::cin >> N;
	std::vector<int> A(N);
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int min = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[min]) {
				min = j;
			}
		}
		if (A[i] != A[min]) {
			int temp = A[i];
			A[i] = A[min];
			A[min] = temp;
			ans++;
		}
	}

	std::cout << A[0];
	for (int i = 1; i < N; i++) {
		std::cout << " " << A[i];
	}
	std::cout << std::endl;
	std::cout << ans << std::endl;

	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;

}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    while (1) {
        cin >> n;
        if (n == 0)break;
        ll sum = 0, p;
        deque<ll> v(n - 1);
        FOR(i, 0, n){
            cin >> p;
            sum += p;
        }
        FOR(i, 0, n - 1)cin >> v[i];

        rSORT(v, greater<int>());
        v.push_front(0);
        FOR(i, 1, n)v[i] += v[i - 1];
        ll ans = 0;
        FOR(i, 0, n)chmax(ans, (sum + v[i]) * (n - i));
        cout << ans << "\n";
    }
}



Measured memory_bytes: 3376
n = int(input())
a = []
for i in range(3):
    a.append(list(map(int,input().split())))


d=a[1][n-1]
for i in range(n-1):
	d=d+a[1][i]

	if a[0][i+1]==a[0][i]+1:
		d=d+a[2][a[0][i]-1]

print(d)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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;
};

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  }

  if (N == 2) {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }

  return 0;
};


Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
char c;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string s="";
	for(ll i=1;i<=3; i++)
	{
	    for(ll j=1; j<=3; j++)
	    {
	        cin>>c;
	        if(i==j)
	        s+=c;
	    }
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
from bisect import*
n,*t=map(int,open(0).read().split())
s=sorted
a,b,c=s(t[:n]),s(t[n:n+n]),s(t[n+n:])
x=[n-bisect(c,i)for i in b]+[0]
for i in range(n):x[-i-2]+=x[~i]
print(sum(x[bisect(b,i)]for i in a))

Measured memory_bytes: 36292
x, y = map(int, input().split())
ans = 0

if (x >= 0 and y > 0 and x < y) or (x < 0 and y <= 0 and x < y):
    print(y - x)
elif (x > 0 and y > 0 and x > y) or (x < 0 and y < 0 and x > y):
    print(x - y + 2)
else:
    print(abs(x + y) + 1)

Measured memory_bytes: 9124
#include <iostream>
#include <climits>

using namespace std;

int main(){
	int n, a;
	long sum = 0; int max = INT_MIN; int min = INT_MAX;

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a;
		sum += a;
		if(max < a){
			max = a;
		}
		if(min > a){
			min = a;
		}
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1164