akhauriyash/Code-Regression huggingface dataset:
from typing import *

# @param b `1 <= b`
# @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
def _inv_gcd(a: int, b: int) -> Tuple[int, int]:
    a %= b
    if a == 0: return (b, 0)

    # Contracts:
    # [1] s - m0 * a = 0 (mod b)
    # [2] t - m1 * a = 0 (mod b)
    # [3] s * |m1| + t * |m0| <= b
    s: int = b; t: int = a
    m0: int = 0; m1: int = 1

    while t:
        u: int = s // t
        s -= t * u
        m0 -= m1 * u # |m1 * u| <= |m1| * s <= b

        # [3]:
        # (s - t * u) * |m1| + t * |m0 - m1 * u|
        # <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        # = s * |m1| + t * |m0| <= b

        tmp = s
        s = t
        t = tmp
        tmp = m0
        m0 = m1
        m1 = tmp
    
    # by [3]: |m0| <= b/g
    # by g != b: |m0| < b/g
    if m0 < 0: m0 += b // s
    return (s, m0)


def pow_mod(x: int, n: int, m: int) -> int:
    assert 0 <= n and 1 <= m
    if m == 1: return 0
    return pow(x, n, m)


def inv_mod(x: int, m: int) -> int:
    assert 1 <= m
    z = _inv_gcd(x, m)
    assert z[0] == 1
    return z[1]


# (rem, mod)
def crt(r: List[int], m: List[int]) -> Tuple[int, int]:
    assert len(r) == len(m)
    n: int = len(r)
    # Contracts: 0 <= r0 < m0
    r0: int = 0; m0: int = 1
    for i in range(n):
        assert 1 <= m[i]
        r1: int = r[i] % m[i]; m1: int = m[i]
        if m0 < m1:
            r0, r1 = r1, r0
            m0, m1 = m1, m0
        if m0 % m1 == 0:
            if r0 % m1 != r1: return (0, 0)
            continue
        # assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)

        # (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
        # r2 % m0 = r0
        # r2 % m1 = r1
        # -> (r0 + x*m0) % m1 = r1
        # -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
        # -> x = (r1 - r0) / g * inv(u0) (mod u1)

        # im = inv(u0) (mod u1) (0 <= im < u1)
        (g, im) = _inv_gcd(m0, m1)

        u1: int = (m1 // g)
        # |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
        if (r1 - r0) % g: return (0, 0)

        # u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
        x: int = (r1 - r0) // g % u1 * im % u1

        # |r0| + |m0 * x|
        # < m0 + m0 * (u1 - 1)
        # = m0 + m0 * m1 / g - m0
        # = lcm(m0, m1)
        r0 += x * m0
        m0 *= u1  # -> lcm(m0, m1)
        if r0 < 0: r0 += m0
    
    return (r0, m0)


def floor_sum(n: int, m: int, a: int, b: int) -> int:
    ans: int = 0
    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += n * (b // m)
        b %= m

    y_max: int = (a * n + b) // m; x_max: int = (y_max * m - b)
    if y_max == 0: return ans
    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans


# https://atcoder.jp/contests/practice2/tasks/practice2_c
def main() -> None:
    import sys

    t = int(sys.stdin.readline())

    for _ in range(t):
        n, m, a, b = map(int, sys.stdin.readline().split())
        print(floor_sum(n, m, a, b))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10452
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
using Graph = vector<vector<int>>;
#define rep(i,N) for(int i=0;i<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

int main() {
	int N; cin >> N;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	int ans = 0;
	rep(i, N) {
		bool judge = true;
		while (judge) {
			if (a[i] % 2 == 0) {
				++ans;
				a[i] /= 2;
			}
			else judge = false;
		}
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
#define ull unsigned long long
#define ll long long
const int maxn=100000;
using namespace std;
priority_queue<int,vector<int>,greater<int>>q;
int b[13];
int c[13];
int d[13][13];
int C(int x,int y)
{ int z=1;
    for(int i=1;i<=y;i++)
        z=z*(x-i+1)/i;//cout<<z<<endl;;
    return z;
}
int sum1[103],sum2[103],a[103];
int pp[103];int n,m;
int dd(int x,int y,int z)
{ int w=0;
  int v=0;
  if(z<0)return 0;
     for(int i=1;i<=x;i++)
     {
         w+=a[i];
         pp[++v]=a[i];
     }
     for(int i=n;i>=y;i--)
     {
         w+=a[i];
         pp[++v]=a[i];
     }
     sort(pp+1,pp+1+v);
     int q=1;
     while(z&&q<=v)
     {
         if(pp[q]<0)w-=pp[q];
         else break;
         q++;
         z--;

     }
     return w;
}
int main()
{

/* int n,m;
     cin>>n>>m;
     for(int i=1;i<=m;i++)
     {
         cin>>c[i];
         for(int j=1;j<=c[i];j++)
            cin>>d[i][j],b[d[i][j]]=1;
     }
     int sum=1;
     for(int i=1;i<=m;i++)
     {
         int a;
         cin>>a;
         if(a&1)
         { int zz=0;
            for(int j=1;j<=c[i];j+=2)
                zz+=C(c[i],j);
                sum=sum*zz;//,cout<<c[i]<<" "<<j<<endl,zz=1;

         }
         else { int zz=0;
                for(int j=2;j<=c[i];j+=2)
                zz+=C(c[i],j);
                sum=sum*zz;//,cout<<c[i]<<" "<<j<<endl,zz=1;
         }
     }
     int ant=0;
     for(int i=1;i<=n;i++)
        if(!b[i])ant++;
        int x=1;
        for(int i=1;i<=ant;i++)
            x*=2;
        if(ant)
     sum=sum*x;
     cout<<sum<<endl;*/

     cin>>n>>m;
     for(int i=1;i<=n;i++)
      cin>>a[i];
     /* for(int i=1;i<=n;i++)
        sum1[i]=sum1[i-1]+a[i];

      for(int i=n;i>=1;i--)
        sum2[i]=sum2[i+1]+a[i];
        cout<<sum2[3]<<endl;*/int Max=0;
        for(int i=0;i<=n;i++)
        {   for(int j=n+1;j>i;j--)
            {  // if(dd(i,j,m-(i+(n+1-j)))>Max)
                 Max=max(Max,dd(i,j,m-(i+(n+1-j))));
                //cout<<i<<" "<<j<<" "<<Max<<endl;}
            }
        }cout<<Max<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

largeA = 0
largeB = 0
for i in range(N):
  d = A[i] - B[i]
  if d > 0:
    largeA += d
  elif d < 0:
    d = -d
    # 奇数の差をつぶす
    if d % 2 == 1:
      d = -1
      B[i] -= 1
    largeB += d

dsum = sum(B) - sum(A)
if dsum >= 0 and largeB//2 <= dsum and largeA <= dsum:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int h[n];
  r(i,n) cin >> h[i];
  int cost[n];
  cost[0] = 0;
  cost[1] = abs(h[1]-h[0]);
  for(int i=2;i<n;i++) {
    cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]));
  }
  cout << cost[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import Control.Monad

main :: IO ()
main = print =<< solve . parse .lines <$>  getContents

parse :: [String] -> (Int, Int, [[Int]])
parse ls = (h, w, boards)
  where
    [_, h, w] = map read . words . head $ ls
    boards = map (map read . words) . tail $ ls

solve :: (Int, Int, [[Int]]) -> Int
solve (h, w, bs) = length . filter isValid $ bs
  where
    isValid [a, b] = (a >= h) && (b >= w)

Measured memory_bytes: 1532
//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
int main()
{
   start;
   ll i,j,k,n,m;
   cin>>n>>k>>m;
   vector<ll>ami;
   ll ans=0;
   for(i=k,j=0;j<100000;j++)
   {
       if(j<=n-1)
       {
           ans+=(i%m);
       }
       ami.pb(i%m);
      if(j==n-1)
      {
        cout<<ans<<endl;
        rr;
       }
       i=i%m;
       i=i*i;
        i%=m;
   }
   ll ajob=ami.size();
   ll st;
   for(i=0;i<ajob;i++)
   {
       if(ami[i]==ami[ajob-1])
       {
         st=i;
         break;
       }
   }
   ll len;
   for(i=st+1;i<ajob;i++)
   {
       if(ami[st]==ami[i])
       {
           len=i-st;
           break;
       }
   }
   i-=len;
   ans=0;
   for(j=0;j<i;j++) ans+=ami[j];
   ll l_sum=0;
   for(i=st,j=0;j<len;i++,j++)
   {
       l_sum+=ami[i];
   }
   ll bad=n-st;
   ll ro=bad/len;
   ans=ans+ro*l_sum;
   bad=(n-st)%len;
    for(i=st,j=0;j<bad;i++,j++)
        ans+=ami[i];
   cout<<ans<<endl;
   rr;
}

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

//#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n;
    cin>>n;
    vector<Pii> v;
    map<Pii,int> ma;
    REP(i,0,n){
        int tx,ty;
        cin>>tx>>ty;
        v.pb(mp(tx,ty));
    }
    REP(i,0,n){
        REP(j,0,n){
            if(i==j) continue;
            ma[mp(v[i].first-v[j].first,v[i].second-v[j].second)]++;
        }
    }
    int M=0;
    for(auto x : ma){
        chmax(M,x.second);
    }
    cout<<n-M<<endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define vi vector<int>
#define mkp make_pair
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD = 1e9 + 7;
int arr[mxn];
int n, m, k;
string s;

ll pow(ll A,ll B,ll R=1)
{while(B){if(B&1)R=R*A%MOD;A=A*A%MOD;B>>=1;}return R;}

void read(){
    cin >> n;
//    for(int i = 0, u, v; i < n; i++){
//        cin >> arr[i];
//    }
}

void solve(){
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    //init();
    while(T--) read(), solve();
    return 0;
}


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

using namespace std;

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define PQ priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define FORD(i, n) for (int (i) = (int)(n) - 1; i>= 0; i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl;
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1 << 30;
const int N = 1005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

inline ll read()
{
	ll x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

string s; 
int n, m; 

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	n = read(); m = read(); 
	REP(i, n) s.pb('-'); 
	REP(i, m)
	{
		int x = read() - 1, y = read(); 
		if (s[x] != '-' && s[x] != y + '0')
		{//printf("%d\n", x); cout << s << endl; 
			puts("-1"); 
			return 0; 
		}
		s[x] = y + '0'; 
	}
	if (s[0] == '0' && s != "0")
	{
		puts("-1"); 
		return 0; 
	}
	if (s == "-") s = "0"; 
	if (s[0] == '-') s[0] = '1'; 
	REP(i, n) if (s[i] == '-') s[i] = '0'; 
	cout << s << endl; 
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 200

int kansu(int,int);
  
int a[N],b;

int kansu(int i,int y)
{
  int kusuo;
  if(y==0)
    return 1;
   if(i>=b)
    return 0;
  kusuo=kansu(i+1,y) || kansu(i+1,y-a[i]);
  return kusuo;
}


int main()
{
  int i,c,d,e;
  
  scanf("%d",&b);
  for(i=0;i<b;i++)
    {
      scanf("%d",&a[i]);
    }
  
  scanf("%d",&c);
  for(i=0;i<c;i++)
    {
      scanf("%d",&d);
      if(kansu(0,d))
	printf("yes\n");
      else printf("no\n");
    }
  return 0;
}




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

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
        vec[i]--;
    }
    ll ans = 0;
    vector<bool> visited(N, false);
    vector<ll> vec_copy(N, 0);
    vector<ll> amari(0);
    ll count = 0;
    ll next = 0;
    ll roop = 0;
    rep(i,200005){
        if (visited[next]){
            count++;
            roop = count - vec_copy[next];
            break;
        }
        else if (count == K){
            ans = next + 1;
            break;
        }
        else{
            count++;
            vec_copy[next] = count;
            visited[next] = true;
            amari.push_back(next + 1);
            next = vec[next];
        }
    }
    ll len = amari.size();
    if (ans == 0){
        K -= count - roop - 1;
        ll start = len - roop;
        ans = amari[start + K % roop];
    }
    cout << ans << endl;
}


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

int check_n(char math[]){
	int i=0;
	int count = 0;
	while(math[i]){
		if(math[i]=='1') count++;
		i++;
	}
	return (count);
}

int check_p(char math[]){
	int i=0;
	int count = 0;
	while(math[i]){
		if(math[i]=='1') break;
		i++;
	}
	return (i);
}


int main(void)
{
	char math[10][10]={0};
	while(cin >> math[0]){
		for(int i=1; i<8; i++){
			cin >> math[i];
		}
		int i=0;
		int count;
		for(; i<8; i++){
			if(check_n(math[i])) {
				count = check_n(math[i]);
				break;
			}
		}
		if(count == 4){
			cout << "C" << endl;
		}else if( count == 2 ){
			switch(check_p(math[i+1])-check_p(math[i])){
			case 1:
				cout << "E" << endl;
				break;
			case 0:
				cout << "A" << endl;
				break;
			case -1:
				cout << "G" << endl;
				break;
			}
		}else if (count == 1){
			switch(check_n(math[i+1])){
			case 1:
				cout << "B" << endl;
				break;
			case 2:
				if(check_p(math[i+1])-check_p(math[i])==0){
					cout << "F" << endl;
				}else{
					cout << "D" << endl;
				}
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const char c[4] = {'R', 'Y', 'G', 'B'};
int h, w, d;
char s[500][501];

int main() {
    cin >> h >> w >> d;
    forn(i, h) forn(j, w) {
        int cur = 0;
        cur += ((i + j) / d) & 1;
        cur += (((i + w - 1 - j) / d) & 1) << 1;
        assert(cur >= 0 && cur < 4);
        s[i][j] = c[cur];
    }
    forn(i, h) printf("%s\n", s[i]);
    return 0;
}


Measured memory_bytes: 768
from sys import stdin

def read_edge(e):
    E = []
    for _ in range(e):
        line = stdin.readline().strip().split()
        u = line[0]
        v = line[1]
        w = line[2]
        E.append((int(w), int(u), int(v)))
    return E

class DisjointSet(object):
    def __init__(self, n):
        self.parent = [None] * (n + 1)
        self.rank = [None] * (n + 1)

    def make_set(self, x):
        if self.parent[x] == None:
            self.parent[x] = x
            self.rank[x] = 0

    def find_set(self, x):
        if x != self.parent[x]:
            self.parent[x] = self.find_set(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        self.link(self.find_set(x), self.find_set(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

def kuruskal(n, E):
    S = DisjointSet(n)
    for i in range(n):
        S.make_set(i)
    K = []
    for i in sorted(E):
        if S.find_set(i[1]) != S.find_set(i[2]):
            S.unite(i[1], i[2])
            K.append(i[0])

    return K

n, e = [ int(i) for i in input().split() ]
E = read_edge(e)
K = kuruskal(n, E)
print(sum(K))



Measured memory_bytes: 24412
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0;i < n;i++)cin >> a[i];

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

	ll ans = 0;
	if(n % 2 == 1){
		//両端を小さくする場合
		ll sum = 0;
		for(int i = 1;i <= n;i++){
			if(i <= n / 2)sum += 2 * a[i-1];
			else{
				if(i <= n / 2 + 2)sum -= a[i-1];
				else sum -= 2 * a[i-1];
			}
		}
		ans = sum;
		sum = 0;
		//両端を大きくする場合
		for(int i = 1;i <= n;i++){
			if(i <= n / 2 - 1)sum += 2 * a[i-1];
			else if(i <= n / 2 + 1)sum += a[i-1];
			else sum -= 2 * a[i-1];
		}
		ans = max(ans,sum);
	}
	else{
		ll sum = 0;
		for(int i = 1;i <= n;i++){
			if(i < n / 2)sum += 2 * a[i-1];
			else if(i == n / 2)sum += a[i-1];
			else if(i == n / 2 + 1)sum -= a[i-1];
			else sum -= 2 * a[i-1];
		}
		ans = sum;
	}
	cout << ans << endl;
}


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

int main() {
    int n, m, s, l, p;
    cin >> n;
    int dp[400];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; ++i) {
        cin >> s >> l >> p;
        for (int j = 0; j <= 393; ++j) {
            for (int k = s; j - k >= 0 && k <= l; ++k) {
                dp[j] = max(dp[j], dp[j - k] + p);
            }
        }
    }
    cin >> m;
    int w, ans[m + 1];
    for (int i = 0; i < m; ++i) {
        cin >> w;
        if (dp[w] == 0) {
            cout << -1 << endl;
            return 0;
        }
        ans[i] = dp[w];
    }
    for (int i = 0; i < m; ++i) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 3112
using static System.Console;

class Program
{
	static void Main(string[] args)
	{
			string[] s = ReadLine().Split(' ');
			int N = int.Parse(s[0]), M = int.Parse(s[1]), C = int.Parse(s[2]),sum = C,count = 0;
			int[] B = new int[M];
			int[,] A = new int[N,M];
			string[] s2 = ReadLine().Split(' ');
			for (int i = 0; i < M; i++) B[i] = int.Parse(s2[i]);
			for(int i = 0;i < N;i++)
			{
				string[] s3 = ReadLine().Split(' ');
				for (int j = 0;j < M;j++)
				{
					sum += B[j] * int.Parse(s3[j]);
				}
				if (sum > 0) count++;
				sum = C;
			}
			WriteLine(count);
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
    map<string,int> m;                  //通常のmapはkeyに対して1つの値を持つ。multimapになると、keyにいくつもの値を持たせることが出来る。
    int n, q, x;
    string k;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> q >> k;

        if( q == 0 )
        {
            cin >> x;
            m[k] = x;
        }
        else
            cout << m[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 27860
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{lli n,i;
 lli dp[100001];
 dp[0]=0;
 dp[1]=0;
 cin>>n;
 lli a[n+1];
 for(i=1;i<=n;i++)
 {cin>>a[i];
 }
dp[2]=abs(a[2]-a[1]);
 for(i=3;i<=n;i++)
 {dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],dp[i-1]+abs(a[i]-a[i-1]));
 }
 cout<<dp[n]<<"\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 

lli power(lli x,lli y,lli k)
{
     //cout<<x<<" "<<k<<'\n';
    lli res=1;
    while(y>0)
    {
        if(y&1)res=((res%k)*(x%k))%k;
        y>>=1;
        x=((x%k)*(x%k))%k;
    }
    //cout<<res<<'\n';
    return res;
}

int main()
{
   
                        
     fio

      lli n;
      cin>>n;
      string s;
      cin>>s;
      lli cnt=0;
      fr(i,0,n)if(s[i]=='1')cnt++;



      
      
      
         lli p1=0,p2=0,ans=1;

        if(cnt>1)
        fr(i,0,n)
        if(s[i]=='1')p1=((p1%(cnt-1))+(power(2,n-i-1,cnt-1)))%(cnt-1);

        fr(i,0,n)
        if(s[i]=='1')p2=((p2%(cnt+1))+(power(2,n-i-1,cnt+1)))%(cnt+1);

       

        fr(i,0,n)
        {

             lli z;
            if(s[i]=='1' && cnt<=1)cout<<"0\n";
            else
            {
                 ans=1;
                if(s[i]=='1')
                {
                      z=((p1%(cnt-1))-(power(2,n-i-1,cnt-1)))%(cnt-1);
                      if(z<0)z+=(cnt-1);
                     
                }
                else 
                {
                    
                    z=((p2%(cnt+1))+(power(2,n-i-1,cnt+1)))%(cnt+1);
                    
                    if(z<0)z+=(cnt+1);
                }
               

                while(z!=0)
                {
                    z%= __builtin_popcount(z);
                    ans++;
                }
                cout<<ans<<'\n';
            }
        }

 
         
     

     
    
      
      



     



     


     
    
     




      
     

     
              


return 0;}    


Measured memory_bytes: 3776
plist = [2]
for i in range(3, 1001, 2):
    tmp = 0
    for j in range(3, i+1, 2):
        if i % j == 0:
            tmp = j
            break
    if tmp == i:
        plist.append(i)

n = int(input())
tmp = [1] * len(plist)
for i in range(1, n+1):
    for j, p in enumerate(plist):
        i_tmp = i
        while(i_tmp % p == 0):
            i_tmp /= p
            tmp[j] += 1

ret = 1
for i in tmp:
    ret *= i
print(ret % (10**9+7))

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100000

int parent(int i) {return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

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

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(parent(i)>=1)printf("parent key = %d, ",a[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",a[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",a[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<vector>
using namespace std;vector<vector<int> >a(11,vector<int>(331));void r(int n,int u,int s,int d){a[n][s]++;for(int i=10;i-->0;)if(!(u>>i&1))r(n+1,u^1<<i,s+d*i,d+1);}main(){r(0,0,0,1);for(int n,s;cin>>n>>s;)cout<<a[n][s]<<endl;}

Measured memory_bytes: 804
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e5+5;



int main(){
	int N;
	cin>>N;
	int A[MAX];
	rep(i,N)cin>>A[i];
	if(A[0]!=0){
		cout<<-1<<endl;
		return 0;
	}
	if(N==1){
		cout<<0<<endl;
		return 0;
	}

	bool ok=true;
	ll ans=(ll)A[N-1];
	for(int i=N-2;i>=0;i--){
		if(A[i]+2<=A[i+1]){
			ok=false;
			break;
		}
		else if(A[i]+1==A[i+1])continue;
		else ans+=(ll)A[i];
	}
	if(ok){
		cout<<ans<<endl;
	}
	else cout<<-1<<endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;

ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*  
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int csrand(int l=0, int r=1e9)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define PR(x) cout<<#x<<" : "<<x<<"\n";
#define PR1(x,y) cout<<#x<<" : "<<x<<"  |  "<<#y<<" : "<<y<<"\n";
#define PR2(x,y,z) cout<<#x<<" : "<<x<<"  |  "<<#y<<" : "<<y<<"  |  "<<#z<<" : "<<z<<"\n";
#define ED cout<<'\n';

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define endl            '\n'
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define PB              push_back
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first       
#define S               second 
#define mod             1000000007

int mod1=998244353;

const int N=2e5+99;
int freq[N],arr[N];

int32_t main()
{       
    IO

    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>arr[i],freq[arr[i]]++;

    if(arr[1]!=0 || freq[0]>1)
    {
        cout<<0<<endl;
        return 0;
    }   

    ll ans=1;
    for(int i=1;i<N;i++)
    {
        if(freq[i]==0)
        {
            for(int j=i+1;j<N;j++)
            {
                if(freq[j]!=0)
                {
                    cout<<0<<endl;
                    return 0;
                }
            }
            break;
        }
        ll tt=power(freq[i-1],freq[i],mod1);
        ans=(ans*tt)%mod1;
    }

    cout<<ans<<endl;


   

}





Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define y1 y12312123
#define int ll

using namespace std;

const int N = 3e5 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;
int n, k, ans;
vector<int> a[N];
int f[N], ob[N];

int bin(int a,int n){
    int res = 1;
    while(n){
        if(n & 1)res *= a;
        a *= a;
        res %= md;
        a %= md;
        n /= 2;
    }
    return res;
}

void dfs(int v, int pr = 0){
    if(v == 1){
        ans *= k;
        ans %= md;
    }
    int cnt = 0;
    for(int i = 0; i < a[v].size(); ++i){
        int to = a[v][i];
        if(to == pr)continue;
        dfs(to, v);
        cnt++;
    }
    if(v == 1){
        if(cnt + 1 > k){
            cout << 0;
            exit(0);
        }
        ans *= f[k - 1] * ob[k - 1 - cnt] % md;
        ans %= md;
    }else{
        if(cnt + 2 > k){
            cout << 0;
            exit(0);
        }
        ans *= f[k - 2] * ob[k - 2 - cnt] % md;
        ans %= md;
    }
}

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

    ans = 1;
    cin >> n >> k;
    f[0] = 1;
    ob[0] = 1;
    for(int i = 1; i <= k; ++i){
        f[i] = (f[i - 1] * i) % md;
        ob[i] = bin(f[i], md - 2);
    }
    for(int i = 1; i < n; ++i){
        int x, y;
        cin >> x >> y;
        a[x].pb(y);
        a[y].pb(x);
    }
    dfs(1);
    cout << ans;
}


Measured memory_bytes: 17792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
ll n,m,cnt; 
ll sum;
/*int h[200010],dis[200010],v[200010];
int dp[1005][1005];
struct edge
{
	int v,w,next;
}e[200010*2];
il void add(int u,int v)
{
	e[++cnt].v=v;
//	e[cnt].w=w;
	e[cnt].next=h[u];
	h[u]=cnt;
}*/ 
const ll mod=1e9+7;
int main()
{
	n=read(),m=read();
	for(ll i=m;i<=n+1;i++)
	{
		sum=(sum+(n-i+1)*i+1)%mod;
	}
	printf("%lld\n",sum);
	return 0;
}

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

int main(void){
  int ans = 0;
  string eat;
  cin >> eat;
  for(int i=0;i<eat.length();i++){
    if(eat[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> to(n);
    rep(i,n){
        cin >> to[i];
        to[i]--;
    }
    vector<bool> been(n,false);// n番目の街に行ったことがあるか
    been[0] = true;
    ll now = 0,step = 0;
    vector<ll> ever;
    ever.push_back(0);
    ll re = 0;
    while(true){
        step++;
        now = to[now];
        if(!been[now]){
            been[now] = true;
            ever.push_back(now);
        }
        else{
            rep(i,ever.size()){
                if(ever[i] == now){
                    re = i;
                    break;
                }
            }
            break;
        }
    }
    if(k < ever.size()){
        dunk(ever[k]+1);
    }
    else{
    ll a = (k-re)%(step-re)+re;
    dunk(ever[a]+1);
    }
    return 0;
}

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

int basket[200001];
int main()
{
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		int a; cin >> a;
		basket[a]++;
	}
	sort(basket, end(basket));
	int c = 0;
	for (int i = 0; i < 200001; ++i)
		if(basket[i])
			c++;
	c -= k;
	if (c <= 0)
	{
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	for (int i = 0; i < 200001 && c; ++i)
	{
		if (basket[i]) 
		{
			ans += basket[i];
			c--;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 4392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n,w; cin >>n>>w;
    vector<ll> c(n); vector<ll> v(n);
    REP(i,n) cin >> c[i] >> v[i];

    vector<vector<ll> > dp(n+1, vector<ll>(100100, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            if (c[i] <=  j) {
                dp[i+1][j] = max(dp[i][j], dp[i][j-c[i]]+v[i]);
            } else {
                dp[i+1][j] = dp[i][j];
            } 
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}



Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int  xx;
int  yy;
int lt[2050][2050];
int main () {
	memset(lt,0,sizeof(lt));
	int n,k,x,y;
	char c[10];
	cin>>n>>k;
	for(int i=0; i<n; i++) {
		scanf("%d %d %s",&xx,&yy,c);
		if(c[0]=='W') {
			yy+=k;
		}
		xx%=2*k;
		yy%=2*k;
		lt[xx][yy]++;
	}
	for(int i=0; i<=2*k; i++)
		for(int j=1; j<=2*k; j++)
			lt[i][j]+=lt[i][j-1];
	for(int i=1; i<=2*k; i++)
		for(int j=0; j<=2*k; j++)
			lt[i][j]+=lt[i-1][j];
	int  ans=0;
	for(int a=1; a<=k; a++) {
		for(int b=1; b<=k; b++) {
			int c1=lt[b-1][a-1];
			int c2=lt[b-1][2*k-1]-lt[b-1][k+a-1];
			int c3=lt[2*k-1][a-1]-lt[k+b-1][a-1];
			int c4=lt[2*k-1][2*k-1]-lt[k+b-1][2*k-1]-lt[2*k-1][k+a-1]+lt[k+b-1][a+k-1];
			int c5=lt[k+b-1][a+k-1]-lt[b-1][a+k-1]-lt[b+k-1][a-1]+lt[b-1][a-1];
			ans=max(ans,c1+c2+c3+c4+c5);
			ans=max(ans,n-(c1+c2+c3+c4+c5));
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  string s;
  cin>>s;


  vector<int> check(26,0);

  for(int i=0;i<s.size();i++){
    int wk=s.at(i)-'a';
    check.at(wk)++;
  }

  bool flg=true;
  for(int i=0;i<26;i++){
    if(check.at(i)>=2){
      flg=false;
      break;
    }
  }

  if(flg)
    cout<<"yes"<<endl;
  else
    cout<<"no"<<endl;

	return 0;
}

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


int main(){
	while (1) {
		int a, b;
		char c;
		cin >> a >> c >> b;
		if (c == '?')break;
		if (c == '+')cout << a + b << endl;
		if (c == '-')cout << a - b << endl;
		if (c == '*')cout << a * b << endl;
		if (c == '/')cout << a / b << endl;
	}
}


Measured memory_bytes: 3092
#include<stdio.h>

int main(void)
{
	int i;
	char s[4], t[20];

	scanf("%s", &s);
	

	for (i = 0;s[i] != '\0';i++) {
		
		
	}
i--;
if(s[i]=='2'|| s[i] == '4'|| s[i] == '5'|| s[i] == '7'||s[i] == '9')
	printf("hon");
if(s[i] == '0' || s[i] == '1' || s[i] == '6' || s[i] == '8')
printf("pon");
if(s[i] == '3')
printf("bon");

	return 0;
}

Measured memory_bytes: 1732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int Q=sc.nextInt();
		WUnionFindTree uft=new WUnionFindTree(N);
		for(int i=0; i<Q; i++) {
			int com=sc.nextInt();

			if(com==0) {
				int x=sc.nextInt();
				int y=sc.nextInt();
				int z=sc.nextInt();
				uft.union(x,y,z);
			}
			else {
				int x=sc.nextInt();
				int y=sc.nextInt();
				Integer df=(Integer)uft.diff(x,y);
				if(df==null) {
					pl("?");
				}
				else {
					pl(df);
				}
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static class WUnionFindTree{
		int[] par; // 親の番号
		int[] ws;  // 親との重みの差
		public WUnionFindTree(int n){
			par = new int[n+1];
			ws  = new int[n+1];
			for(int i = 0; i <= n; i++){ par[i] = -1; }
		}
		public int find(int x){
			if(par[x] < 0){
				return x;
			}else{
				final int parent = find(par[x]);
				ws[x] += ws[par[x]];
				return par[x] = parent;
			}
		}
		public int weight(int x){
			find(x);
			return ws[x];
		}
		public boolean union(int x, int y, int w){ // x <-(w)- y (x + w = y)
			w += weight(x);
			w -= weight(y);
			x = find(x); y = find(y);
			if(x != y){
				if(par[y] < par[x]) {
					int tmp = x; x = y; y = tmp; w = -w;
				}
				par[x] += par[y]; par[y] = x;
				ws[y] = w;
				return true;
			}else{
				return false;
			}
		}
		public boolean same(int x, int y){
			return find(x) == find(y);
		}
		public Integer diff(int x, int y){ // y - x を求める. 比較不能ならnull.
			if(!same(x, y)){ return null; }
			return this.weight(y) - this.weight(x);
		}
		public int size(int x){
			return -par[find(x)];
		}
	}
}


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

int main(){

  int a,b; cin>>a>>b;

  if(a % 3 ==0 || b % 3 == 0 || (a+b) % 3 == 0 ) cout<<"Possible"<<endl;

  else cout<<"Impossible"<<endl;

  return 0;
}


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

int main() {
  int in_height, out_height=0;
  int in_width, out_width=0;
  vector<vector<char>> picture(100,vector<char>(100));
  
  // 画枠入力
  cin >> in_height >> in_width;

  //出力画像サイズ
  out_height = in_height+2;
  out_width  = in_width+2;
 
  //画像データ入力
  for(int i=0; i<in_height; i++){
    for(int j=0; j<in_width; j++){
      cin >> picture.at(i).at(j);
     // cout << picture.at(i).at(j);
    }
  }
  for (int i = 0; i < out_height; i++) {
    for (int j = 0; j < out_width; j++) {
      if(i==0 || i==(out_height-1)){
        cout << '#';
      }else if(j==0 || j==(out_width-1)){
        cout << '#';
      }else{
        //画像本体
        cout << picture.at(i-1).at(j-1);
      }
      if (j == out_width -1 ) cout << endl;
     }
  }


}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <queue>
#include <numeric>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  long N;
  cin >> N;
  vector<long> v(N);
  rep (i, N) {
    long x;
    cin >> x;
    v[i] = x - i - 1;
  }

  sort(v.begin(), v.end());

  vector<long> lsum(N), rsum(N+1);

  lsum[0] = v[0];
  for (int i=1; i<N; ++i) lsum[i] = lsum[i-1] + v[i];
  rsum[N] = 0;
  rsum[N-1] = v[N-1];
  for (int i=N-2; i>=0; --i) rsum[i] = rsum[i+1] + v[i];

  long ans=1e15;
  
  rep(i, N) {
    long b = v[i];
    long subans = -lsum[i] + rsum[i+1] + (i+1)*b - (N-(i+1))*b;
    
    ans = min(ans, subans);
  }

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








Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using range = boost::multi_array_types::index_range;
using array_type = boost::multi_array<int, 2>;
// ------------------------

void solve() {
    int W, H, N; cin >> W >> H >> N;
    array_type region(boost::extents[W][H]);
    rep(i, W){
        rep(j, H){
            region[i][j] = 1;
        }
    }
    rep(i, N){
        int x, y, a;
        cin >> x >> y >> a;
        switch(a){
            case 1:{
                array_type::array_view<2>::type view = region[ boost::indices[range(0, x)][range(0, H)] ];
                for(int l = 0; l < x; ++l){
                    for(int m = 0; m < H; ++m){
                        view[l][m] = 0;
                    }
                }
                break;
            }
            case 2:{
                array_type::array_view<2>::type view = region[ boost::indices[range(x, W)][range(0, H)] ];
                for(int l = 0; l < (W-x); ++l){
                    for(int m = 0; m < H; ++m){
                        view[l][m] = 0;
                    }
                }
                break;
            }
            case 3:{
                array_type::array_view<2>::type view = region[ boost::indices[range(0, W)][range(0, y)] ];
                for(int l = 0; l < W; ++l){
                    for(int m = 0; m < y; ++m){
                        view[l][m] = 0;
                    }
                }
                break;
            }
            case 4:{
                array_type::array_view<2>::type view = region[ boost::indices[range(0, W)][range(y, H)] ];
                for(int l = 0; l < W; ++l){
                    for(int m = 0; m < (H-y); ++m){
                        view[l][m] = 0;
                    }
                }
                break;
            }
        }
    }
    int sum = 0;
    rep(j, H){
        rep(i ,W){
            sum += region[i][j];
        }
    }

    cout << sum << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    vector<int> p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());

    vector<int> d;
    rep(i,x) d.push_back(p[i]);
    rep(i,y) d.push_back(q[i]);
    rep(i,c) d.push_back(r[i]);

    sort(d.rbegin(), d.rend());

    ll ans = 0;
    rep(i, x+y) ans += d[i];

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

Measured memory_bytes: 3572
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        double pai=3.141592653589;
        double r;
        scanf("%lf",&r);
        printf("%.8lf %.8lf\n",r*r*pai,r*2*pai);
        return 0;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


template <ll mod>
struct ModCombination{
    ll N;
    vector<ll> fact,inv,finv;

    ModCombination(ll n):N(n){
        fact.assign(n+1, 1);
        inv.assign(n+1, 1);
        finv.assign(n+1,1);
        for(int i=1;i<n;i++){
            fact[i+1] = fact[i]*(i+1)%mod;
            inv[i+1] = inv[mod%(i+1)]*(mod-mod/(i+1))%mod;
            finv[i+1] = finv[i]*inv[i+1]%mod;
        }
    }

    ll Comb(ll n,ll k){
      if(n<0||n<k)return 0;
        return (fact[n]*finv[k]%mod)*finv[n-k]%mod;
    }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  if(N==2){
    cout << 1 << endl;
  }else if(N==3){
    cout << 4 << endl;
  }else{
    ModCombination<MOD> C(N);
    ll ans = 0;
    if(N>=4){
      repeat(k,N-1){
        ll K = k+1;
        ans = (ans+((C.Comb(K-1,N-K-1)*C.fact[K]%MOD*C.fact[N-K-1]%MOD)-(C.Comb(K-2,N-K)*C.fact[K-1]%MOD*C.fact[N-K]%MOD)+MOD)%MOD*K%MOD)%MOD;
        //debug(ans);
      }
    }
    cout << ans << endl;

  }
  return 0;
}


Measured memory_bytes: 23680
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
#define p 998244353
using namespace std;
inline ll read(){
    ll x = 0; char zf = 1; char ch = getchar();
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int i,j,k,m,n,x,y,z,cnt,sum,ans;
char c[200010];
int main(){
	n=r;
	scanf("%s",c+1);
	for(rt i=1;i<=n;i++)cnt+=(c[i]=='R');
	if(cnt+cnt>n)puts("Yes");else puts("No");
}








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

typedef long long LL;

const int N=200000;

int n,m,a[N+9];
LL ans;

int main(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
  sort(a+1,a+n+1);
  for (int i=n-m;i>=1;--i) ans+=a[i];
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(),(VECTOR).end()

int main(){

	ll N, M;
	vector<pll> V;
	cin >> N >> M;
	ll a, b;
	for(ll i = 0; i < N; i ++){
		cin >> a >> b;
		V.pb(mp(a, b));
	}
	sort(all(V));
	ll cnt = 0;
	ll ans = 0;
	for(int i = 0; i < N; i ++){
		//cout << cnt << endl;
		if(M - cnt > V[i].second){
			cnt += V[i].second;
			ans += V[i].first * V[i].second;
			continue;
		}
		ans += V[i].first * (M - cnt);
		break;
	}
	cout << ans << endl;

	return 0;
}

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

unsigned long long t[6];
using namespace std;

int main()
{
  for(int i =0; i<6; i++)
  {
    std::cin >> t[i];
  }

  unsigned long long minT = ULLONG_MAX;
  for(int i = 1; i < 6; i++)
  {
    minT = std::min(t[i], minT);
  }

  cout << (t[0]-1) / minT + 5;
  return 0;
}

Measured memory_bytes: 256