akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll N;
  cin>>N;
  vector<ll> X(N);
  FOR(i,N){
    cin>>X[i];
  }
  sort(X.begin(),X.end());
  ll min_=LLONG_MAX;
  FOR(i,101){
    ll sum = 0;
    FOR(j,N){
      sum += (X[j] -i)*(X[j]-i);
    }
    if(sum<min_)min_=sum;
  }
  cout<<min_<<endl;
  return 0;
}

Measured memory_bytes: 256
input_n = input()
n = str(input_n)

listS = list(n)
#listN = n.split(' ')

input_m = input()
m = str(input_m)

listT = list(m)

min = 10000

if (len(listS) - len(listT)) == 0:
    tmp = 0
    for j in range(len(listT)):
        if listS[j] != listT[j]:
            tmp += 1
    if tmp < min:
        min = tmp

for i in range(len(listS) - len(listT)):
    tmp = 0
    for j in range(len(listT)):
        if listS[i + j] != listT[j]:
            tmp += 1
    if tmp < min:
        min = tmp

print(str(min))


Measured memory_bytes: 9108
// abc073_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#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 n,tmp;
  cin>>n;
  set<int> a;
  rep(i,n){
    cin>>tmp;
    decltype(a)::iterator it = a.find(tmp);
    if (it != a.end()) {
      a.erase(tmp);
    } else {
      a.insert(tmp);
    }
  }

  cout<<a.size()<<endl;
  return 0;
}


Measured memory_bytes: 4864
from collections import deque

def main():
    n, x, y = map(int, input().split())
    cnt = [0]*n
    q = deque()
    
    for i in range(n):
        q.appendleft(i)
        dist = [None]*n
        dist[i] = 0
        while q:
            j = q.pop()
            d = dist[j]
            cnt[d] += 1
            if j > 0 and dist[j-1] is None:
                dist[j-1] = d+1
                q.appendleft(j-1)
            if j < n-1 and dist[j+1] is None:
                dist[j+1] = d+1
                q.appendleft(j+1)
            if j == x-1 and dist[y-1] is None:
                dist[y-1] = d+1
                q.appendleft(y-1)
            elif j == y-1 and dist[x-1] is None:
                dist[x-1] = d+1
                q.appendleft(x-1)
    for i in range(1, n):
        print(cnt[i]//2)
                

if __name__ == "__main__":
    main()

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

int main() {
  int A, B, X;
  scanf("%d%d%d", &A, &B, &X);

  if (A <= X && A + B >= X) {
    printf("YES");
  } else {
    printf("NO");
  }
  return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

solver :: Int -> Int -> Int -> Int
solver n a b = min b (a * n)

main :: IO ()
main = do
  n:a:b:[] <- toInts
  print $ solver n a b


Measured memory_bytes: 380
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10

def check(ans1, ans2, field):
    h, w = len(ans1), len(ans1[0])
    ans = [[0] * w for _ in range(h)]
    for y in range(h):
        for x in range(w):
            c = "#" if ans1[y][x] == ans2[y][x] == "#" else "."
            if field[y][x] != c:
                print(y, x)


def main():
    H, W = map(int, input().split())
    field = []
    for _ in range(H):
        field.append(input())

    ans1, ans2 = [["."] * W for _ in range(H)], [["."] * W for _ in range(H)]
    for i in range(H):
        ans1[i][0] = "#"
        ans2[i][-1] = "#"
        if i % 2 == 0:
            ans1[i] = ["#"] * (W - 1) + ["."]
        else:
            ans2[i] = ["."] + ["#"] * (W - 1)

    for y in range(H):
        for x in range(W):
            if field[y][x] == "#":
                if y % 2 == 0:
                    ans2[y][x] = "#"
                else:
                    ans1[y][x] = "#"
    
    for line in ans1:
        print("".join(line))
    print()
    for line in ans2:
        print("".join(line))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8176
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
string S1, S2;

bool query()
{
	printf("%s\n%s\n", S1.c_str(), S2.c_str());
	fflush(stdout);
	char ans[10];
	scanf("%s", ans);
	if (ans[0] == 'e') exit(0);
	return ans[0] == 'T';
}

int main()
{
	scanf("%d", &N);
	bool app_right = true;
	while (S1.size() < N) {
		if (app_right) {
			S1.push_back('.');
			S2.push_back('.');
			for (int i = 0; i < 4; ++i) {
				S1[S1.size() - 1] = (i % 2 == 0 ? '.' : '#');
				S2[S2.size() - 1] = (i / 2 == 0 ? '.' : '#');
				if (query()) goto nxt;
			}
			app_right = false;
			S1.pop_back();
			S2.pop_back();
		}
		S1.insert(S1.begin(), '.');
		S2.insert(S2.begin(), '.');
		for (int i = 0; i < 4; ++i) {
			S1[0] = (i % 2 == 0 ? '.' : '#');
			S2[0] = (i / 2 == 0 ? '.' : '#');
			if (query()) goto nxt;
		}
	nxt:
		continue;
	}
	return 0;
}


Measured memory_bytes: 596
def examA():
    S = SI()
    if len(S)==3:
        ans = S[::-1]
    else:
        ans = S
    print(ans)
    return

def examB():
    A, B, K = LI()
    for i in range(K):
        if i%2==0:
            B +=A//2
            A //=2
        else:
            A +=B//2
            B //=2
    print(A,B)
    return

def examC():
    N = I()
    A = [I() for _ in range(N)]
    A.sort()
    A1 = A[:N//2]; A2 = A[N//2:]
    ans = 0; cur = 0
    for i in range(len(A2)):
        if i<len(A1):
            cur +=(A2[i]-A1[i])
        if i-1>=0:
            cur +=(A2[i]-A1[i-1])
    if N%2==1:
        cur += (A2[-1] - A2[1])
    ans = max(ans,cur)
#    print(A1,A2)
#    print(ans)
    if N%2==1:
        A1 = A[:1+(N//2)]; A2 = A[1+(N//2):]
        cur = 0
        for i in range(len(A1)):
            if i < len(A2):
                cur += (A2[i] - A1[i])
            if i - 1 >= 0:
                cur += (A2[i-1] - A1[i])
        cur +=(A1[-2]-A1[0])
        ans = max(ans, cur)
#    print(A1,A2)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 45148
from itertools import product

h,w =  map(int,input().split())	
slili=[list(input()) for i in range(h)]

for i in range(h):
    slili[i].insert(0,'.')
    slili[i].append('.')

slili.insert(0,['.']*(w+1))
slili.append(['.']*(w+1))


def srinsetsu(i,j):
    if slili[i][j] == '.':
        return True
    elif slili[i-1][j]=='#' or slili[i][j-1]=='#' or slili[i+1][j]=='#' or slili [i][j+1]=='#':
        return True
    else: 
        False

ans = True
for i,j in product(range(1,h+1) , range (1,w+1)):
    ans = ans and srinsetsu(i,j)

if ans:
    print ("Yes")
else:
    print ("No")


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

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

  queue<char> a;
  for (int i = 0; i < A.size(); i++) a.push(A.at(i));
  queue<char> b;
  for (int i = 0; i < B.size(); i++) b.push(B.at(i));
  queue<char> c;
  for (int i = 0; i < C.size(); i++) c.push(C.at(i));

  char turn = 'a';
  while (true) {
    if (turn == 'a') {
      if (a.empty()) break;
      turn = a.front();
      a.pop();
    } else if (turn == 'b') {
      if (b.empty()) break;
      turn = b.front();
      b.pop();
    } else {
      if (c.empty()) break;
      turn = c.front();
      c.pop();
    }
  }

  if (turn == 'a')
    cout << 'A' << endl;
  else if (turn == 'b')
    cout << 'B' << endl;
  else
    cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
main(){
  long long int n,w=0,x[21]={0},i,j=1,ans=1;
  scanf("%lld",&n);
  for(i=n;i>0;i--){
    ans=ans*i;
  }
  printf("%lld\n",ans);
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B,C,D; cin >>A >>B >> C >> D;
    cout << min(A,B) + min(C,D) << endl;
    return 0;
}

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

using namespace std;

int main() {
	int x1, x2, x3, x4, x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
	cout << (x1 == 0 ? 1 : x2 == 0 ? 2 : x3 == 0 ? 3 : x4 == 0 ? 4 : 5) << '\n';
	return 0;
}


Measured memory_bytes: 3536
//you never give up.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define v32 vector<int>
#define v64 vector<ll>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    int i = 1000;
    while (1)
    {
        if (i >= n)
        {
            cout << i - n << endl;
            break;
        }
        else
        {
            i = i + 1000;
        }
    }
}
int main()
{
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,S=0;cin>>N>>M;int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];S+=A[i];
  }
  sort(A,A+N);reverse(A,A+N); 
  if(A[M-1]*4*M>=S)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

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

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

    // start
    int a, b;
    cin >> a >> b;
    cout << max(a + a - 1, max(a + b, b + b - 1)) << endl;
    // end

    return 0;
}


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

int MOD = 1000000007;

ll mod_pow(ll x, ll n)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

vector<ll> fact;
vector<ll> ifact;

void mod_ifact(ll n)
{
  fact.resize(n + 1);
  fill(fact.begin(), fact.end(), 1);
  ifact.resize(n + 1);
  fill(ifact.begin(), ifact.end(), 0);
  for (ll i=1; i<n+1; i++)
    fact[i] = fact[i-1] * i % MOD;
  ifact[n] = mod_pow(fact[n], MOD - 2);
  for (ll i=n; i>0; i--)
    ifact[i-1] = ifact[i] * i % MOD;
}

ll mod_comb(ll n, ll k)
{
  if (k < 0 || k > n)
    return 0;
  return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}
int main()
{
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  mod_ifact(n * m);
  ll c = mod_comb(n * m - 2, k - 2);
  for (int i=1; i<m; i++)
    ans = (ans + i * n % MOD * n % MOD * (m - i) % MOD * c) % MOD;
  for (int i=1; i<n; i++)
    ans = (ans + i * m % MOD * m % MOD * (n - i) % MOD * c) % MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(a<b)swap(a,b);
    if(a%b == 0) return b;
    return gcd(b,a%b);
}
signed main(void) {
    int i,j;
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s;
    cin >> t;
    if(s[0] != t[0]){
        cout << -1 << endl;
        return 0;
    }
    int g = gcd(n,m);
    int l = n * m / g;
    map<int,char> ma;
    rep(i,n){
        ma[1+i*l/n]=s[i];
    }
    rep(i,m){
        char c = ma[1+i*l/m];
        if('a' <= c && c <= 'z' && c != t[i]){
            cout << -1 << endl;
            return 0;
        }
        ma[1+i*l/m] = t[i];
    }
    cout << l << endl;
}


Measured memory_bytes: 10880
#include<stdio.h>

#define N 100

int main(){
    int M[N][N];
    int n, u, k, v;
    int i, j;

    scanf("%d", &n);

    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j]=0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d%d", &u, &k);
        for(j=0; j<k; j++){
            scanf("%d", &v);
            M[i][v-1]=1;
        }
    }

    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            printf("%d", M[i][j]);
            if(j!=n-1) printf(" ");
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (y - r >= 0 && y + r <= H && x - r >= 0 && x + r <= W) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int n, A;
	cin >> n >> A;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<vector<ll> > dp;
	dp.assign(n + 1, vector<ll> ());
	for(int i = 0; i <= n; ++i) {
		dp[i].assign(5005, 0);
	}
	dp[0][2500] = 1;
	for(int i = 0; i < n; ++i) {
		int x = a[i] - A;
		for(int j = 0; j <= 5000; ++j) {
			dp[i + 1][j] += dp[i][j];
			if(j + x >= 0) {
				dp[i + 1][j + x] += dp[i][j];
			}
		}
	}
	cout << dp[n][2500] - 1  << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(int, char**)
{
	int a, b, c, d, n;
	string str;
	cin >> n >> a >> b >> c >> d >> str;
	a--; b--; c--; d--;

	bool isNuke = false;
	list<int> x;
	for (int i = 0; i < n - 1; ++i) {
		if (str[i] == '#' && str[i+1] == '#') {
			if (i > a && i < c) {
				cout << "No" << endl;
				return 0;
			}
			if (i > b && i < d) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (i < n - 2 && str[i] == '.' && str[i+1] == '.' && str[i+2] == '.') {
			if (i + 1 >= b && i + 1 <= d)
				isNuke = true;
		}
	}
	if (c < d) {
		cout << "Yes" << endl;
		return 0;
	}

	if (isNuke)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

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


class BDigitSums {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      in >> n;
      string s = to_string(n);
      int sn = 0;
      REP(i, s.length()) sn += s[i] - '0';
      out << (n % sn == 0 ? "Yes" : "No") << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BDigitSums solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9 + 7);
const int MAX_N = 212345;
ll two[MAX_N];
ll inv2 = (MOD + 1) / 2;
vector<int> g[MAX_N];
int depth[MAX_N];

struct Cell {
  ll p0, p1;
};
deque<Cell> dp[MAX_N];

Cell merge(Cell a, Cell b) {
  ll p0 = (a.p0 * b.p0) % MOD;
  ll p1 = (a.p1 * b.p0 % MOD + a.p0 * b.p1 % MOD) % MOD;
  return (Cell){p0, p1};
}

void dfs(int v) {
  // dp[v][d] := 頂点vから（相対的な）深さdについての値
  int md = 0;
  for (int child : g[v]) {
    dfs(child);
    if (dp[child].size() > dp[v].size()) dp[child].swap(dp[v]);
    REP(d, dp[child].size()) {
      dp[v][d] = merge(dp[v][d], dp[child][d]);
    }
    chmax(md, (int)dp[child].size());
  }
  REP(d, md) {
    dp[v][d].p0 = (1 - dp[v][d].p1 + MOD) % MOD;
  }
  dp[v].push_front((Cell){inv2, inv2});
}

int main2() {
  REP(i, MAX_N) dp[i].clear();
  REP(i, MAX_N) g[i].clear();
  int N = nextInt() + 1;
  depth[0] = 0;
  REP(i, N - 1) {
    int p = nextInt();
    g[p].push_back(i+1);
    depth[i+1] = depth[p] + 1;
  }

  dfs(0);
  ll ans = 0;
  REP(d, dp[0].size()) {
    ans += dp[0][d].p1;
    ans %= MOD;
  }
  ans = (ans * two[N]) % MOD;
  cout << ans << endl;
  return 0;
}

int main() {
  two[0] = 1;
  REP(i, MAX_N - 1) two[i+1] = two[i] * 2 % MOD;
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 254328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = a[n+1] = 0;
    rep1(i,n) {
        cin >> a[i];
    }
    ll sum = 0;
    rep1(i,n+1) {
        sum += abs(a[i]-a[i-1]);        
    }
    rep1(i,n) {
        cout << sum + abs(a[i-1]-a[i+1]) - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    cout << S[0];
    int c = 0;
    for(int i = 1; i < S.length()-1; i++){
        c++;
    }
    cout << c << S[S.length()-1] << endl;
}

Measured memory_bytes: 256
N = int(input())
M = len(str(N))
res = [0]
def dfs(x):
    # 長さがMになったら終了
    if len(x) > M:
        return
    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0 and int(x) <= N:
        res[0] += 1
    dfs(x + '3')
    dfs(x + '5')
    dfs(x + '7')
    return

dfs('3')
dfs('5')
dfs('7')
print(res[0])    
    

Measured memory_bytes: 43752
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100009
int main() {
	int ope = 0;
	char strs[11], strt[12];
	scanf("%s", strs, 11);
	scanf("%s", strt, 12);
	for (int i = 0;i < strlen(strs);i++) {
		if (strs[i] != strt[i])
			ope = 1;
	}
	if (ope)
		printf("No");
	else
		printf("Yes");
}

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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        int num = 0;
        for (int j = i; j < S.size(); ++j) {
            if (S[j] != 'A' && S[j] != 'C' && S[j] != 'G' && S[j] != 'T') break;
            num++;
        }
        ans = max(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,k;
  cin >> n >> k;
  vector<int64_t> h(n);
  int64_t i;
  for(i=0;i<n;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  for(i=0;i<min(k,n);i++){
    h.at(i)=0;
  }
  int64_t sum=0;
  for(i-0;i<n;i++){
    sum+=h.at(i);
  }
  cout << sum;
}

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

#define SE second
#define FI first
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int) (x).size())

#define _ << " " <<
#define TR(x) cout << #x _ x << endl

using namespace std;
using ii = pair<int, int>;

const int INF = (int) 1e9 + 5;

int main() {
    string s; cin >> s;
    if (s[0] == s[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

static const int MAX_N = 100;

int selectionSort(int A[], int N) {
    int cnt = 0;
    for (int i = 0; i < N-1; ++i) {
        int minj = i;
        for (int j = i+1; j < N; ++j) {
            if (A[minj] > A[j]) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A[minj], A[i]);
            cnt++;
        }
    }
    return cnt;
}

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

    int cnt = selectionSort(A, N);
    for (int i = 0; i < N; ++i) {
        if (i == N-1) cout << A[i] << endl;
        else cout << A[i] << " ";
    }
    cout << cnt << endl;
    return 0;
}


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

int main()
{
    string S;
    ll K;

    cin >> S;
    cin >> K;

    ll days = 5000000000000000;

    char ans;
    rep(i, S.size())
    {
        char c = S.at(i);
        int num = (int)(c - '0');
        ll digit = days * log10(num);
        if (log10(K) <= digit)
        {
            ans = c;
            break;
        }
        else
        {
            K -= pow(num, days);
        }
    }

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

Measured memory_bytes: 3968
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100],i,p,x=0;
    scanf("%s",&s);
    p=strlen(s);
    for(i=0;i<p;i++){
        if((i+1)%2!=0&&s[i+1]=='R'){
            printf("No\n");
            x=1;
            break;
        }
        else if((i+1)%2==0&&s[i+1]=='L'){
            printf("No\n");
            x=1;
            break;
        }
        if(s[0]=='L'){
            printf("No\n");
            x=1;
            break;
        }
    }
    if(x==0){
        printf("Yes\n");
    }
    return 0;
}

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

using namespace std;

int main()
{
    char cc[15];
    scanf("%s",cc);
    if(cc[0]!='A')
        cout<<"WA"<<endl;
    else
    {
        int noc=0;
        int len=strlen(cc);
        int index;
        for(int i=2;i<=len-2;i++)
            if(cc[i]=='C')
            noc++,index=i;
        if(noc!=1)
            cout<<"WA"<<endl;
        else
        {
            for(int i=0;i<len;i++)
            {
                if(i==0||i==index)continue;
                if(cc[i]-'a'<0||cc[i]-'a'>25)
                {
                    cout<<"WA"<<endl;
                    return 0;
                }
            }
            cout<<"AC"<<endl;
        }
    }
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int gcd(int a, int b) {
    if (!a)
        return b;
    return gcd(b % a, a);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int x;
    cin >> x;
    int lcm = 360 * x / gcd(x, 360);
    cout << lcm / x;
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

string s;
int n;
int main(){
    cin >> s;
    n = s.size();
    int MOD = 1e9+7;
    vector<vector<ll>> dp(n+1,vector<ll>(4,0));
    dp[n][3]=1;
    for(int i=n;i>=1;--i){
        REP(j,4){
            if(j==3){
                int m;
                if(s[i-1]=='?')m=3;
                else m=1;
                dp[i-1][j]=(m*dp[i][j])%MOD;
            }else{
                int m1,m2;
                if(s[i-1]=='?')m1=3;
                else m1=1;
                if(j==(s[i-1]-'A')||s[i-1]=='?')m2=1;
                else m2=0;
                dp[i-1][j]=(m1*dp[i][j]+m2*dp[i][j+1])%MOD;
            }
        }
    }
    put(dp[0][0]);
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define ll long long
#define ss second
#define ff first
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, x1, x2;
    cin>>n;
    vector<int> inf, sup;

    for(int i=0; i<n; i++){
        cin>>x1>>x2;
        inf.push_back(x1); sup.push_back(x2);
    }

    sort(inf.begin(), inf.end());
    sort(sup.begin(), sup.end());

    if(n%2 == 0){
        int m1 = inf[n/2-1] + inf[n/2], m2 = sup[n/2-1] + sup[n/2];
        cout<<m2 - m1 + 1<<endl;
    } else {
        cout<<sup[n/2] - inf[n/2] + 1<<endl;
    }

}

Measured memory_bytes: 5128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;

	int i = 1;
	while (1) {
		int x = i;

		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (1) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
				if (x == 0) break;
			}
		}

		if (++i > n) break;
	}
	cout << endl;

	return 0;
}




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


int main(){
    ll a,b,n; cin>>a>>b>>n;
    ll res=0;
    if(b-1<=n) chmax(res, a*(b-1)/b);
    chmax(res, a*n/b - a*(n/b));
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>

int main() {
	int n;
	long long ans = 0;
	std::vector<int> cards;

	std::cin >> n;
	cards.resize(n, 0);

	for (int i = 0; i < n; i++) {
		std::cin >> cards[i];
	}

	for (int i = 0; i < n; i++) {
		if (i > 0 && cards[i - 1] > 0 && cards[i] > 0) {
			ans++;
			cards[i - 1]--;
			cards[i]--;
		}
		ans += cards[i] / 2;
		cards[i] %= 2;

	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2e5+10;
const int mod = 998244353;
using namespace std;

ll N,M,K;
ll f[maxn],invf[maxn];
void init(int N){
    f[0] = invf[0] = f[1] = invf[1] = 1;
    for(int i=2;i<=N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<=N;i++) invf[i]=invf[i-1]*invf[i]%mod;
}
ll C(ll n,ll m){
	if(n == m || m == 0) return 1;
	if(n < m) return 0;
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
ll ksm(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1) res = res*a%mod;
		a = a*a%mod;
		b>>=1;
	}
	return res;
}
int main(){
	// debug;
	ios;
	init(maxn);

	cin>>N>>M>>K;
	ll ans = 0;
	for(int t = N-K;t<=N;t++){
		ans += C(N-1,t-1) * M % mod * ksm(M-1,t-1)%mod; 
		ans %= mod;
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 6792
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

#define MOD = 1e9+7;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define de(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif





int32_t main()
{
    
    IOS
    
    int n;
    cin>>n;
    vi a(n+1),b(n+1),c(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    vector<vector<int>>final(n+1,vector<int>(3,0));
    for(int i=1;i<=n;i++){
        final[i][0]=a[i]+max(final[i-1][1],final[i-1][2]);
         final[i][1]=b[i]+max(final[i-1][0],final[i-1][2]);
          final[i][2]=c[i]+max(final[i-1][1],final[i-1][0]);
    }
    cout<<max({final[n][0],final[n][1],final[n][2]});
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  string s, t;
  int count = 0;
  
  for (int i = A; i <= B; i++) {
    t = "";
    s = to_string(i);
    for (int j = s.size(); j > 0; j--) {
      t += s.at(j - 1);
    }
    if (t == s) count ++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

struct Vec{
	int ind;
	int val;
};

bool valDesc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val> right.val: left.val > right.val;
}

bool valAsc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val <  right.val: left.val < right.val;
}
int main(void){
	int N,M,c,d,ans =0,t=0;
	scanf("%d%d",&N,&M);
	pair<int,int> a[100000];
	for (int i;i<M;i++){
		scanf("%d%d",&c,&d);
		a[i].first = d;
		a[i].second = c;
	}
	sort(a,a+M);
	for(int i=0;i<M; i++){
		if(t <= a[i].second){
			ans++;
			t = a[i].first;
		}
	}

	printf("%d\n",ans);
	fflush(stdout);

	return 0;
}

Measured memory_bytes: 1024
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

ll inn,ins,ret;

ll f(ll b, ll n){
    return n ? f(b,n/b) + n%b : 0 ;
}

int main(){
    LL(inn); LL(ins);
    if (inn == ins) {
        cout << inn+1 << endl;
        return 0;
    }
    ll nsq = sqrt(inn);
    FOR(i,2,nsq+1){
        if (f(i,inn) == ins){
            cout << i << endl;
            return 0;
        }
    }
    REPN(i,nsq+1){
        if ((inn-ins)/i+1 < 2) continue;
        if (f((inn-ins)/i+1,inn) == ins){
            cout << (inn-ins)/i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
#define LF '\n'
using namespace std;

#define ALL(x) x.begin(), x.end()

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int N, M;

  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];

  cin >> M;
  vector<int> b(M);
  for (int i = 0; i < M; ++i) cin >> b[i];

  cout << (a < b) << LF;

  return 0;
}




Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include <algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};
int n,k;

int main() {
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = 0;
  int y3 = 0;
  int x4 = 0;
  int y4 = 0;
  
  x3 = x2 - (y2 - y1);
  y3 = y2 + (x2 - x1);
  x4 = x3 - (x2 - x1);
  y4 = y3 - (y2 - y1);
  
  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
  
}

Measured memory_bytes: 1024
import java.util.*;
import java.math.*;

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int T = sc.nextInt();      
      
      int t[] = new int[N];
      
      for(int i = 0;i < N;i++){
          t[i] = sc.nextInt();
      }
      
      
      int start = t[0];      
      int end = t[0] + T;
      int value = t[0];
      
      int X = 0;
      
      for(int i = 1;i < N;i++){
       if(start <= t[i] && t[i] <= end){
           end = t[i] + T;
       }else{
           X += end - start; 
           start = t[i];
           end = t[i] + T;
       }       
      }
      
      X += end - start;
      
      System.out.println(X);
      
   }
}

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

using ll = long long;
const int mod = 1e9+7, mxN = 2e5;

int add (int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

int mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector <int> c(n), a, each(mxN+1);
	for (int i=0; i<n; i++) {
		cin >> c[i];
		if (!i || c[i] != c[i-1]) {
			a.push_back(c[i]);
		}
	}
	n = a.size();
	vector <int> dp(n+1);
	dp[n] = 1;
	for (int i=n-1; i>=0; i--) {
		dp[i] = add(each[a[i]], dp[i+1]);
		each[a[i]] = add(each[a[i]], dp[i+1]);
	}
	cout << dp[0];
	return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;cin>>n;
	std::vector<ll> a(n+1);
	std::vector<std::vector<ll> > dp(n+1,std::vector<ll>(n+2,0));
	std::vector<std::vector<ll> > ans(n+1,std::vector<ll>(n+2,0));
	for (int i = 1; i <= n; ++i)
	{
		/* code */cin>>a[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= (n-i+1); ++j)
		{
			dp[i][j]=a[j]+dp[i-1][j+1];
			if(i>1)ans[i][j]=ans[i-1][j+1]+a[j]+dp[i-1][j+1];
			ll t=2;
			while(i>t){
				if(ans[i-t][j+t]+ans[t][j]+dp[i-t][j+t]+dp[t][j]<ans[i][j]){
					dp[i][j]=dp[i-t][j+t]+dp[t][j];
					ans[i][j]=dp[i-t][j+t]+dp[t][j]+ans[i-t][j+t]+ans[t][j];

				}
				t++;
			}		
		}
	}
	cout<<ans[n][1]<<"\n";

}











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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	int k; cin >> k;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int hi; cin >> hi;
		if (hi >= k)
			++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    int cnt=0;
    for(int i=1;i<s.size();i++){
        if(isupper(s[i])){
            if(i==1 or i==s.size()-1 or s[i] != 'C'){
                cout<<"WA"<<endl;
                return 0;
            }
            ++cnt;
        }
    }
    if(cnt!=1){
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <string>

#include <algorithm>
using namespace std;


int main(void) {

    int a,b,c,result = 0;

    cin >> a >> b >> c;

    for (int i = 0; i < 100000; i++) {
        if (result % b == c) {
            cout << "YES" << endl;
            return 0;
        }
        result += a;
        result %= b;
    }

    cout << "NO" << endl;


    return 0;
}


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

int main(){
    long long x, k, d;
    cin >> x >> k >> d;
    if(x > 0){
        long long r = x/d;
        if(r < k){
            if((k-r)%2 == 0) printf("%lld\n", x - r*d);
            else printf("%lld\n", abs(x - (r+1)*d));
        }
        else{
            printf("%lld\n", x-d*k);
        }
    }
    else if(x < 0){
        long long r = abs(x) /d;
        if(r < k){
            if((k-r)%2 == 0) printf("%lld\n", abs(x+r*d));
            else printf("%lld\n", abs(x+(r+1)*d));
        }
        else{
            printf("%lld\n", abs(x + d*k));
        }
    }
    else{
        if(k % 2 == 0){
            printf("0\n");
        }
        else{
            printf("%lld\n", d);
        }
    }
    return 0;
}

Measured memory_bytes: 3740
from math import isinf
 
V, E = map(int, input().split())
d = [[float('inf') for i in range(V)] for j in range(V)]
 
for i in range(V):
    d[i][i] = 0
 
for i in range(E):
    s, t, w = map(int,input().split())
    d[s][t] = w
 
for k in range(V):
    for i in range(V):
        for j in range(V):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
for i in range(V):
    if d[i][i] < 0:
        print('NEGATIVE CYCLE')
        exit()
 
for di in d:
    print(' '.join( ('INF' if isinf(dij) else str(dij) for dij in di)))


Measured memory_bytes: 6476
#include <stdio.h>
int main(){
	int a, b, c, d, n, m = 0;
	while (scanf("%d", &n) != EOF){

		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if (a + b + c + d == n){ m++; }
					}
				}
			}
		}
		printf("%d\n", m);
		m = 0;
	}
	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final long a = in.nextLong();
        final long b = in.nextLong();
        final long n = in.nextLong();
        in.nextLine();
        long lo = 1;
        long hi = n;
//        while (lo < hi) {
//            long mid = lo + hi >>> 1;
//            long f = f(a, mid, b);
//            long f1 = f(a, mid + 1, b);
//            if (f <= f1) {
//                lo = mid + 1;
//            } else {
//                hi = mid;
//            }
//        }
        System.out.println(f(a, Math.min(n, b-1), b));
    }

    private static long f(long a, long mid, long b) {
        return Math.floorDiv(a * mid, b) - a * Math.floorDiv(mid, b);
    }
}


Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    int len = (int)S.size();
    vector<int> cnt(len), ans(len);

    int ct = 1;
    rep(i, len - 1) {
        cnt[i] = ct;
        ct++;
        if (S[i] != S[i + 1]) ct = 1;
    }
    cnt[len - 1] = ct;

    int rmax;
    for (int i = len - 1; i >= 0; i--) {
        if (S[i] == 'L') {
            int lcnt = cnt[i] - 1;
            lcnt *= -1;
            if (lcnt % 2) lcnt--;
            ans[i + lcnt]++;
        }
        else {
            if (S[i + 1] == 'L') rmax = cnt[i];
            int rcnt = rmax - cnt[i];
            if (rcnt % 2) rcnt++;
            ans[i + rcnt]++;
        }
    }

    rep(i, len) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4284
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	if s[0] != 'A' {
		fmt.Println("WA")
		return
	}

	cnt := 0
	for _, r := range s[2 : len(s)-1] {
		if r == 'C' {
			cnt++
		}
	}
	if cnt != 1 {
		fmt.Println("WA")
		return

	}

	cntA, cntC, cntCL := 0, 0, 0
	for _, r := range s {
		switch {
		case r == 'A':
			cntA++
		case r == 'C':
			cntC++
		case r <= 90:
			cntCL++
		}
	}
	if cntA == 1 && cntC == 1 && cntCL == 0 {
		fmt.Println("AC")
		return
	}
	fmt.Println("WA")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=(int)1e9+7;
map<long long,int> freq;
long long C[55][55],ans;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int i=0;i<=50;i++)
        C[i][0]=1,
        C[i][i]=1;
    for(int i=1;i<=50;i++)
        for(int j=1;j<i;j++)
            C[i][j]=C[i-1][j-1]+C[i-1][j];
    long double cnt=0;
    int n,a,b,num=0;
    cin>>n>>a>>b;
    vector<long long> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i],
        freq[v[i]]++;
    sort(v.rbegin(),v.rend());
    if(freq[v[0]]>=a)
    {
        cnt=v[0];
        for(int i=a;i<=min(b,freq[v[0]]);i++)
            ans+=C[freq[v[0]]][i];
    }
    else
    {
        for(int i=0;i<a;i++)
            cnt+=v[i];
        cnt/=a;
        for(int i=0;i<a;i++)
            if(v[i]==v[a-1])
                num++;
        ans=C[freq[v[a-1]]][num];
    }
    cout<<fixed<<setprecision(12)<<cnt<<"\n"<<setprecision(0)<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,qw;
  cin >> n;
  Vi a(0);
  cin >> qw;
  a.pb(qw);
  
  rep(i,1,n){
    cin >> qw;
    if(qw!=a.back()) a.pb(qw);
  }
  
  //Vout(a);
  
  int l = a.size();
  Vi pre(200010,-1),ans(l);
  ans[0]=1;
  pre[a[0]]=0;
  
  rep(i,1,l){
    if(pre[a[i]]==-1) {
      ans[i] = ans[i-1];
      pre[a[i]] = i;
    }
    else {
      ans[i] = ans[pre[a[i]]]+ans[i-1];
      ans[i] %= MOD;
      pre[a[i]] = i;
    }
  }
  cout << ans[l-1]%MOD << endl;
  //Vout(ans);
  return 0;
}

Measured memory_bytes: 5104