akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    char sr[3];
    scanf("%s", sr);

    int rc_cnt = 0;
    int rc_ans = 0;

    for (int i = 0; i < strlen(sr); i++)
    {
        if (sr[i] == 'S')
        {
            rc_cnt=0;
        }
        else if (sr[i] == 'R')
        {
            rc_cnt++;
            if (rc_cnt > rc_ans)
            {
                rc_ans = rc_cnt;
            }
        }
    }

    printf("%d\n", rc_ans);

    return (0);
}


Measured memory_bytes: 1724
N = int(input())
C = [None]*(N-1)
S = [None]*(N-1)
F = [None]*(N-1)

for i in range(N-1):
  C[i],S[i],F[i] = map(int, input().split())
  
ans = [None]*N
for i in range(N):
  t = 0
  for j in range(i,N-1):
    if t < S[j]: t = S[j]
    t = (t - S[j] + F[j]- 1) // F[j] * F[j] + S[j]
    t += C[j]
  ans[i] = t

for v in ans:
  print(v)

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

using namespace std;

int main(int argc, char* argv[]){
    int A,B;
    cin >> A >> B;
    for(int i=0;;i++){
    if(B<=(A-1)*i+1 ) {
        cout << i << endl;
        break;
    }
    }
    return 0;
}

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

using namespace std;

const int N = 200005;
vector<int> adj[2][N];
int cmp[2][N];
map<pair<int,int>,int> vmap;

void dfs(int f, int i, int c){
    cmp[i][f] = c;
    for(auto it:adj[i][f]){
        if(!cmp[i][it])
            dfs(it,i,c);
    }
}

int main(){
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    for(int i = 0; i<k+l; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        adj[i>=k][u].push_back(v);
        adj[i>=k][v].push_back(u);
    }
    for(int j = 0; j<2; j++){
        int numc = 0;
        for(int i = 1; i<=n; i++){
            if(!cmp[j][i])
                dfs(i,j,++numc);
        }
    }
    for(int i = 1; i<=n; i++)
        vmap[{cmp[0][i],cmp[1][i]}]++;
    for(int i = 1; i<=n; i++)
        printf("%d ",vmap[{cmp[0][i],cmp[1][i]}]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 27904
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int m,f,r;
		while(true){
			m=sc.nextInt();
			f=sc.nextInt();
			r=sc.nextInt();
			if(m!=-1||f!=-1||r!=-1){
				if(m==-1||f==-1||m+f<30){
					System.out.println("F");
				}
				else if(m+f>=80){
					System.out.println("A");
				}
				else if(m+f>=65){
					System.out.println("B");
				}
				else if(m+f>=50||r>=50){
					System.out.println("C");
				}
				else{
					System.out.println("D");
				}
			}
			else{
				break;
			}
		}
	}
}


Measured memory_bytes: 26272
#include <iostream>
#include <string>

int main(){
    int x, y;
    std::cin >> x >> y;
    
    std::string YorN = "No";
    for(int i = 0; i <= x; i++){
        if(2 * i + 4 * (x - i) == y){
            YorN = "Yes";
        }
    }
    std::cout << YorN << std::endl;

}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

int solve(string const& s, string const& t){
    int m=s.size(), n=t.size();
    int ans = -1;
    vi prev(n+1);
    rep(i,m){
        vi cur(n+1);
        rep(j,n){
            if(s[i]==t[j])cur[j+1]=prev[j]+1;
            ans = max(ans,cur[j+1]);
        }
        swap(cur,prev);
    }
    return ans;
}

int main(){
    string s,t;
    while(cin>>s>>t){
        cout << solve(s,t) << endl;
    }
}

Measured memory_bytes: 1232
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  char s[51]={};
  scanf("%s",s);
  int i=0;
  int count=0;
  while(s[i]!='\0'){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      i+=3;
      count++;
    }else{
      i++;
    }
  }
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(n-1):
    if i+1 == p[i]:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[n-1] == n:
    ans += 1

print(ans)
        

Measured memory_bytes: 14004
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int a, b;

void main() {
    scan(a, b);

    if (!(a > 0 || b < 0)) {
        writeln("Zero");
    }
    else if (b < 0 && (b - a + 1) & 1) {
        writeln("Negative");
    }
    else {
        writeln("Positive");
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#Tenka1 D
from fractions import math
import decimal
from collections import defaultdict

N = int(input())

nlen = decimal.Decimal(1+decimal.Decimal(math.sqrt(1+8*N)))
if nlen%2==0:
    nlen = int(nlen//2)
    print("Yes")
    #グラフ処理
    print(nlen)
    E = defaultdict(list)
    e = 1
    for i in range(nlen):
        for j in range(i+1,nlen):
            E[i].append(str(e))
            E[j].append(str(e))
            e+=1
    for i in range(nlen):
        print(len(E[i])," ".join(E[i]))
    
else:
    print("No")

Measured memory_bytes: 19040
//******* It's LEVI_17 ***************

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

double getRes(double arr[],ll n)
{
    ll ones = 0, twos = 0, threes = 0;
    f(i, n)
    {
        if (arr[i] == 1)
            ones++;
        if (arr[i] == 2)
            twos++;
        if (arr[i] == 3)
            threes++;
    }
    ll maxones = ones + twos + threes;
    ll maxtwos = twos + threes;
    ll maxthrees = threes;
    double dp[n+1][n+1][n+1];
    memset(dp, 0, sizeof(dp));
    ll i=0, j=0, k=0;
    for ( k = 0; k <= maxthrees; k++)
    {
        for ( j = 0; j<=maxtwos-k; j++)
        {
            for ( i = 0; i <=maxones-j-k; i++)
            {
                if (i + j + k == 0)
                    continue;
                else
                {
                    dp[i][j][k] = ((double)n /(double) (i + j + k));
                    if (i > 0)
                        dp[i][j][k] += (dp[i - 1][j][k] * i) / (i + j + k);
                    if (j > 0)
                        dp[i][j][k] += (dp[i + 1][j-1][k] * j) / (i + j + k);
                    if (k > 0)
                        dp[i][j][k] += (dp[i][j+1][k-1] * k) / (i + j + k);

                }
            }
        }
    }

    return dp[ones][twos][threes];
}

void solve()
{
    ll n;
    cin >> n;
    double arr[n];
    f(i, n)
        cin >> arr[i];

    double res = getRes(arr, n);

    printf("%0.14lf\n", res);
}

//###############################################################################################

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


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 216840
Sa = raw_input()
Sb = raw_input()
Sc = raw_input()

turn = 'A'
winner = 'X'

while winner == 'X':
    if turn == 'A':
        if len(Sa) > 0:
            the_card = Sa[0]
            Sa = Sa[1:]
        else:
            winner = 'A'
    elif turn == 'B':
        if len(Sb) > 0:
            the_card = Sb[0]
            Sb = Sb[1:]
        else:
            winner = 'B'
    else:
        if len(Sc) > 0:
            the_card = Sc[0]
            Sc = Sc[1:]
        else:
            winner = 'C'

    if the_card =='a':
        turn = 'A'
    elif the_card =='b':
        turn = 'B'
    else:
        turn = 'C'

print winner


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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int greater = 0;
    int less = 0;
    for (int i = 0; i < m; ++i) {
        int num;
        cin >> num;
        if (num > x && num < n) ++greater;
        else ++less;
    }
    int ans = min(greater, less);
    cout << ans << endl;
}

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

using namespace std;

int check_relation(string a, string b) {
	int la = a.length();
	int lb = b.length();
	if (la != lb) {
		if (la > lb) {
			return 1;
		}
		else {
			return -1;
		}
	}

	for (int i = 0; i < la; ++i) {
		if (a[i] != b[i]) {
			if (a[i] > b[i]) {
				return 1;
			}
			else {
				return -1;
			}
		}
	}
	return 0;
}

int main(void) {
	string A,B;
	cin >> A >> B;
	int rel = check_relation(A,B);
	if (rel > 0) {
		cout << "GREATER" << endl;
	}
	else if (rel == 0) {
		cout << "EQUAL" << endl;
	}
	else {
		cout << "LESS" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace 

main :: IO ()
main = readLine >>= printRes . solve 
    where
        printRes = putStrLn . unwords . map show 

solve :: [Int] -> [Int]
solve [a, b, c, d, e, f] = head . traceShowId $ sortBy (flip cmpf) cs
    where
        as = filter (\(x, y) -> 100 * (x * a + y * b) <= f) $ tail ((,) <$> [0..(f `div` (100 * a))] <*> [0..(f `div` (100 * b))])
        cs = [check x | x <- as]

        cmpf [la, lb] [ra, rb] = compare (100 * lb * (ra + rb)) (100 * rb * (la + lb))

        check (x, y) = [100 * (a * x + b * y) + s, s]
            where
                r = f - 100 * (a * x + b * y)
                m = min r $ (a * x + b * y) * e
                s = maximum . filter (<= m) . map (\(u, v) -> u * c + v * d) $ ((,) <$> [0..(m `div` c)] <*> [0..(m `div` d)])


readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    REP(i, K)
    {
        if (i % 2 == 0)
        {
            A /= 2;
            B += A;
        }
        else
        {
            B /= 2;
            A += B;
        }
    }
    cout << A << " " << B << endl;
    return 0;
}

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

int N; char S[6060];
int A[3030], B[3030], C[6060];

int main()
{
	scanf("%d %s", &N, S);
	A[0] = B[0] = -1;
	for (int i=0, a=0, b=0;i<N*2;i++){
		if (S[i] == 'a') A[++a] = i;
		if (S[i] == 'b') B[++b] = i;
	}

	string ans = "", best = "";
	int l = N*2+1, lm = N*2+1; bool see = false;
	for (int i=N;i>=0;i--){
		if (A[i] >= B[i]){
			if (A[i] < l) best = ans, lm = l;

			if (i){
				C[A[i]] = C[B[i]] = 1;
				string now = "";
				for (int j=B[i];j<lm;j++) if (C[j]) now += S[j];

				string mk = now + best;
				if (ans < mk)
					ans = move(mk);
			}

			l = B[i];
			see = true;
		}
		else if (!see){
			if (B[i] < l){
				ans += "ab";
				best += "ab";
				l = A[i];
			}
		}
	}

	puts(ans.c_str());
	return 0;
}

Measured memory_bytes: 384
/*
    Flowers, wake up like the sea!
*/
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 705, MOD = 7+1e9;
int n, m, x, y;
bool G[N][N];
int vis[N];
bool dfs(int u, int col)
{
    if(col) x ++;
    else y ++;
    vis[u] = col;
    for(int i = 1;i <= n;i ++)
    {
        if(i == u || G[u][i]) continue;
        if(vis[i] != -1)
        {
            if(vis[i] == vis[u]) return false;
            else continue;
        }
        if(!dfs(i, col^1)) return false;
    }
    return true;
}
inline int calc(int x) {return x * (x - 1) / 2;};
int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0;i < m;i ++)
    {
        int u, v; cin >> u >> v;
        G[u][v] = G[v][u] = true;
    }
    memset(vis, -1, sizeof vis);
    bitset<N> dp;
    dp.set(0);
    for(int i = 1;i <= n;i ++)
    {
        if(vis[i] != -1) continue;
        x = y = 0;
        if(!dfs(i, 0)) return cout << "-1\n", 0;
        dp = (dp << x) | (dp << y);
    }
    int ans = n * (n - 1) / 2;
    for(int i = 0;i <= n;i ++)
        if(dp[i]) ans = min(ans, calc(i) + calc(n - i));
    cout << ans << "\n";
    return 0;
}

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


int main(){

    int N, A[200000];
    cin >> N;
    for( int i = 0; i < N; i++ ) cin >> A[i];


    long ans = 0;
    int right = 0, sum = 0;

    /* しゃくとり法 */
    for( int left = 0; left < N; left++ ){ // 左端を動かす
        /* [left,right)の範囲が条件を満たす間 */
        while( right < N && ( sum^A[right] ) == sum + A[right] ){
            sum += A[right];
            right++;
        }

        ans += right - left; // その区間に含まれる全てが条件を満たす

        if( left == right ) right++; // rightとleftが同じならrightも進める
        else sum -= A[left]; // iを1つ左へ動かすのでその分をbitから引く
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1024
A,B,C = map(int,input().split())
max_val=(max([A,B,C]))
odd_chk =3 * max_val - A - B - C
if(odd_chk%2 == 0):
         print(int(odd_chk/2))
else:
         print(int((odd_chk+3)/2))
 

Measured memory_bytes: 2940
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>

using namespace std;
int n,p,pp;
string st[100+10];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>st[i];
	}
	for(int i=1;i<=26;i++)
	{
		p=1;
		while(p==1)
		{
			for(int j=1;j<=n;j++)
			{
				pp=0;
				for(int q=0;q<st[j].size();q++)
				{
					if(st[j][q]==char('a'+i-1))
					{
						st[j][q]=' ';
						pp=1;break;
					}
				}
				if(pp==0)
				{
					p=0;break;
				}
			}
			if(p==1)
			cout<<char('a'+i-1);
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        ll a, b;
        cin >> a;
        cin >> b;
        cout << a + b << endl;
    }
}

Measured memory_bytes: 3552
/* 
    Author : Jeff Ahn
    Sat 27 Jun 2020 05:19:54 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int unsigned long long
// #define uint unsigned long long
#define endl '\n'

const int mn = 1e7 + 10;
int lp[mn], pr[mn];

signed main() {
  fastio;
  int n;
  cin >> n;

  memset(lp, 0, sizeof(lp));
  memset(pr, 0, sizeof(pr));
  pr[1] = 1;
  int pi = 0;
  for (int i = 2; i <= n; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr[pi++] = i;
    }
    for (int j = 0; j < (int) pi && pr[j] <= lp[i] && i * pr[j] <= n; j++) {
      lp[i * pr[j]] = pr[j];
    }
  }

  int res = 1;
  for (int i = 2; i <= n; i++) {
    int tmp = i;
    int prod = 1;
    while(tmp != 1) {
      int smallest = lp[tmp];
      int cnt = 0;
      while (tmp % smallest == 0) {
        tmp /= smallest;
        cnt++;
      }
      prod *= (cnt + 1);
    }

    res += i * prod;
  }
  cout << res << endl;
}


Measured memory_bytes: 159852
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  string s;
  int k;
  cin >> s >> k;

  vector<string> unko;
  rep(i, 1, 6) {
    rep(j, 0, s.size() - i + 1) { unko.push_back(s.substr(j, i)); }
  }
  sort(unko.begin(), unko.end());
  unko.erase(unique(unko.begin(), unko.end()), unko.end());
  cout << unko[k - 1] << endl;

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 4284
#include"bits/stdc++.h"
#include<random>
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> H(N);
    for (ll& h : H) {
        cin >> h;
    }

    ll ans = 0;
    ll curr = 0;
    for (ll i = N - 2; i >= 0; i--) {
        if (H[i] >= H[i + 1]) {
            curr++;
        } else {
            ans = max(ans, curr);
            curr = 0;
        }
    }
    ans = max(ans, curr);

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
#define endl "\n"
#define mod 1000000007

ll n,a[200002],ans,start,jump;
ll dp[200002][3];

ll call(ll pos, ll taken){
    if(pos>=n) return 0;
    if(start==0 && taken==0 && pos==n-1) return 0;
    ll &ret=dp[pos][taken];
    if(ret!=-1) return ret;
    ret=-1e18;
    ret=max(ret,a[pos]+call(pos+2,taken));
    if(taken<jump) ret=max(ret,a[pos]+call(pos+3,taken+1));
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    if(n%2==0){
        if(n==2) cout<<max(a[0],a[1])<<endl;
        else if(n==4){
            ans=max(a[0]+a[2],a[0]+a[3]);
            ans=max(ans,a[1]+a[3]);
            cout<<ans<<endl;
        }
        else{
            ll ans=-1e18;
            for(int i=0;i<2;i++){
                jump=1-i;
                start=i;
                memset(dp,-1,sizeof dp);
                ans=max(ans,call(i,0));
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    if(n==3){
        cout<<max(a[0],max(a[1],a[2]))<<endl;
        return 0;
    }
    if(n==5){
        ans=max(max(a[0]+a[2],a[0]+a[3]),a[0]+a[4]);
        ans=max(ans,max(a[1]+a[3],a[1]+a[4]));
        ans=max(ans,a[2]+a[4]);
        cout<<ans<<endl;
        return 0;
    }
    ll ans=-1e18;
    for(int i=0;i<3;i++){
        jump=2-i;
        start=i;
        memset(dp,-1,sizeof dp);
        ans=max(ans,call(i,0));
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;
vector<vector<pair<int,pair<long long,long long> > > >adj;

vector<long long>ss,tt;
struct edge{
    int f,to;
    long long w;

    edge(int f,int to,long long w):f(f),to(to),w(w){};

    bool operator <(const edge e)const{
        return w>e.w;
    }

};


void dijk1(int s){

    priority_queue<edge>pqe;
    pqe.push(edge(-1,s,0));

    while(pqe.size()){
        edge cre=pqe.top();  pqe.pop();
        ///cout<<cre.to<<'\n';
        if(ss[cre.to]!=-1)
            continue;
        ss[cre.to]=cre.w;
        for(int i=0;i<adj[cre.to].size();i++){
            pqe.push(edge(cre.to,adj[cre.to][i].first,cre.w+adj[cre.to][i].second.first));
        }
    }

}
void dijk2(int t){

    priority_queue<edge>pqe;
    pqe.push(edge(-1,t,0));

    while(pqe.size()){
        edge cre=pqe.top();  pqe.pop();
        ///cout<<cre.to<<'\n';
        if(tt[cre.to]!=-1)
            continue;
        tt[cre.to]=cre.w;
        for(int i=0;i<adj[cre.to].size();i++){
            pqe.push(edge(cre.to,adj[cre.to][i].first,cre.w+adj[cre.to][i].second.second));
        }
    }

}

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

    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--; t--;
    adj=vector<vector<pair<int,pair<long long,long long> > > >(n);
    for(int i=0;i<m;i++){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;  v--;
        adj[u].push_back({v,{a,b}});
        adj[v].push_back({u,{a,b}});
    }
    ss=tt=vector<long long>(n,-1ll);
    dijk1(s);
    dijk2(t);
    vector<pair<long long,int> >pq(n);
    for(int i=0;i<n;i++){
        pq[i]={ss[i]+tt[i],i};
    }
    sort(pq.begin(),pq.end());
    vector<int>vis(n);
    int bst=0;
    /**for(int i=0;i<n;i++){
        cout<<ss[i]<<' '<<tt[i]<<'\n';
    }*/
    for(int i=0;i<n;i++){
        while(vis[pq[bst].second]) bst++;
        cout<<(long long)1e15-pq[bst].first<<'\n';
        vis[i]=1;
    }

    return 0;
}
/***
4 3 2 3
1 4 1 100
1 2 1 10
1 3 20 1
*/


Measured memory_bytes: 18244
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
void fx(vector<int> &a,int n, int m){

}

// -----------------------------------------------------------------------

int arr[3000000];
void input(int n){
	for(int i=0;i<n;++i)
	cin>>arr[i];
}

// -----------------------------------------------------------------------



void q1(){
	int n;
	cin>>n;
	n*=(n+1);
	n/=2;
	cout<<n;
}
// -----------------------------------------------------------------------


void q2(){
	string s,t;
	cin>>s;
	t="";
	int skip=0;
	for(int i=(int)s.size()-1;i>=0;i--){
		if(s[i]=='B'){
			skip++;
		} else{
			if(skip>0){
				skip--;
			} else{
				t+=s[i];
			}
		}
	}
	for(int i=sz(t)-1;i>=0;--i)
	cout<<t[i];
}

// -----------------------------------------------------------------------

void q3(){
	int n;
	cin>>n;
	input(n);
	ld sum=0;
	for(int i=0;i<n;++i){
		sum+=arr[i];
	}
	sum/=n;
	int l=sum;
	sum+=1.00;
	int u=sum;
	int pp,p;
	pp=0;
	sum=l;
	for(int i=0;i<n;++i){
		pp+=((arr[i]-sum)*(arr[i]-sum));
	}p=0;sum=u;
	for(int i=0;i<n;++i){
		p+=((arr[i]-sum)*(arr[i]-sum));
	}
	cout<<min(p,pp);
}


// -----------------------------------------------------------------------

void q4(){
	string s;
	cin>>s;
	int xp=sz(s);
	for(int i=0;i<xp-2;++i){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return ;
		}
		if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return ;
		}
	}
	if(s[xp-1]==s[xp-2]){
		cout<<xp-1<<" "<<xp<<endl;
		return ;
	}
	cout<<"-1 -1\n";
	return ;
}

// -----------------------------------------------------------------------


int32_t main()
{
	mod=1e+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	q3();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()




int main() {
	ll N;
	cin >> N;
	vll p(N);
	rep(i, N) cin >> p[i];
	sort(all(p));
	cout << accumulate(all(p), 0) - p.back() / 2 << endl;
}


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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first
#define sec second
#define MAXN 300001
#define MAXL 20
#define mod 1000000009

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++)
  {
    if (i % d == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  string s;
  cin >>s;
  int N=s.size();
  int ans=0;
  int count=0;
  char me='g';
  for(int i=0;i<N;i++){
    if(s[i]=='g') {
      if(count==0){
        count++;
        continue;
      }
      else{
        ans++;
        count--;
        continue;
      }
    }
    if(s[i]=='p'){
      if(count>0) {
        count--; 
        continue;
      }
      else{
        ans--;
        count++;
        continue;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 512
s = [input() for _ in range(3)]
d = {"a": 0, "b": 1, "c": 2}
i = [-1] * 3
t = 0
while True:
    i[t] += 1
    if i[t] >= len(s[t]):
        break
    t = d[s[t][i[t]]]
print(["A", "B", "C"][t])

Measured memory_bytes: 8820
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeSet;

public class Main {
	static int[] c;
	static Map<Integer, TreeSet<Integer>> mapc;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		c = new int[n + 1];
		for (int i = 0; i < n; i++) {
			c[a[i]]++;
			c[b[i]]++;
		}
		for (int i = 1; i <= n; i++) {
			if (c[i] > n) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");

		reverse(b);
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == b[i]) {
				for ( ; j < n; j++) {
					if (a[j] != b[i] && a[i] != b[j]) {
						int tmp = b[j];
						b[j] = b[i];
						b[i] = tmp;
						break;
					}
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(b[i]).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}

	static void reverse(int[] a) {
		for (int i = 0; i < a.length / 2; i++) {
			int tmp = a[i];
			a[i] = a[a.length - 1 - i];
			a[a.length - 1 - i] = tmp;
		}
	}
}


Measured memory_bytes: 76516
#include <iostream>
using namespace std;
const long INF = 1e9;
int main(){
    int n,c;
    cin >> n >> c;
    long tem;
    long d[c+1][c+1];
    long memo[3][c+1];
    for(int i = 0;i<3;i++){
        for(int j = 0;j<c+1;j++){
            memo[i][j] = 0;
        }
    }
    for(int i = 1;i<=c;i++){
        for(int j = 1;j<=c;j++){
            cin >> d[i][j];
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            cin >> tem;
            if((i+j)%3==0){
                memo[0][tem]++;
            }
            else if((i+j)%3==1){
                memo[1][tem]++;
            }
            else{
                memo[2][tem]++;
            }
        }
    }
    long temm;
    long ans = INF;
    for(int i = 1;i<=c;i++){
        for(int j = 1;j<=c;j++){
            for(int k = 1;k<=c;k++){
                if(i == j || j == k || i == k) continue;
                temm = 0;
                for(int l = 1;l<=c;l++){
                    temm+=(memo[0][l]*d[l][i]+memo[1][l]*d[l][j]+memo[2][l]*d[l][k]);
                }
                ans = min(ans,temm);
            }
        }
    }
    cout << ans << endl;
}

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


int count(int n, int x){
    int cnt = 0;
    for (int i = 1; i <= n-2; i++){
        for (int j = i + 1; j <= n-1; j++){
            for(int k = j + 1; k <= n; k++){
                if(i + j + k == x) cnt++;
                    
            }
        }
    }
    return cnt;
}

int main(){
    int n, x;
   
    while(1){
        cin >> n >> x;
        if( n == 0 && x == 0) break;
        cout << count(n,x) << endl;
    }
    
    return 0;
    
    
}

Measured memory_bytes: 3088
#include <iostream>

using namespace std;

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

long long lcm(long long a, long long b)
{
   long long g = gcd(a,b);
   return (min(a,b)/g)*max(a,b);
}

int main()
{
   int N;
   long long T1, T2;

   cin >> N;
   
   N -= 1;
   cin >> T1;

   while (N--)
   {
      cin >> T2;
      T1 = lcm(T1,T2);
   }

   cout << T1 << "\n";

}

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

int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    if (s[a] == '-'){
        bool check = 1;
        rep(i, 0, a){
            if (s[i] == '-') check = 0;
            break;
        }
        rep(i, a+1, a+b){
            if (s[i] == '-') check = 0;
            break;
        }
        if (check) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import copy
h,w = map(int,input().split())

s = [['#' for _ in range(w+2)]]
for i in range(h):
    si = ['#']
    sij = list(input())
    si.extend(sij)
    si.append('#')
    s.append(si)
s.append(['#' for _ in range(w+2)])

def bfs(i,j):
    root = copy.deepcopy(s)
    q = []
    q.append([i,j])
    root[i][j] = 0
    while q:
        ij = q.pop(0)
        i = ij[0]
        j = ij[1]
        
        if root[i-1][j] == '.': #左
            q.append([i-1,j])
            root[i-1][j] = root[i][j] + 1
        if root[i+1][j] == '.': #右
            q.append([i+1,j])
            root[i+1][j] = root[i][j] + 1
        if root[i][j+1] == '.': #上
            q.append([i,j+1])
            root[i][j+1] = root[i][j] + 1
        if root[i][j-1] == '.': #下
            q.append([i,j-1])
            root[i][j-1] = root[i][j] + 1
    max = 0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if root[i][j] != '#' and root[i][j] > max:
                max = root[i][j]
    return max

ans = -1
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == '.':
            k = bfs(i,j)
            if ans < k:
                ans = k
print(ans)

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var hwk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = hwk[0];
            var w = hwk[1];
            var k = hwk[2];

            var field = new string[h];
            var rowBlack = new int[h];
            var columnBlack = new int[w];
            var sumBlack = 0;

            for (int i = 0; i < h; i++)
            {
                field[i] = Console.ReadLine();
                for(int j = 0;  j < w; j++)
                {
                    if(field[i][j] == '#')
                    {
                        rowBlack[i]++;
                        columnBlack[j]++;
                        sumBlack++;
                    }
                }
            }

            /*
            for(int i = 0; i < h; i++)
            {
                Console.WriteLine(rowBlack[i]);
            }
            for (int j = 0; j < w; j++)
            {
                Console.WriteLine(columnBlack[j]);
            }
            */


            var ans = 0;

            for(int  i = 0; i < Math.Pow(2,h); i++)
            {
                for(int j = 0; j < Math.Pow(2,w); j++)
                {
                    var count = sumBlack;
                    var crossRow = new List<int>();
                    var crossColumn = new List<int>();
                    for (int n = 0; n < h; n++)
                    {
                        if (((i >> n) & 1) == 1)
                        {
                            count -= rowBlack[n];
                            crossRow.Add(n);
                        }
                    }
                    for(int m = 0; m < w; m++)
                    {
                        if (((j >> m) & 1) == 1)
                        {
                            count -= columnBlack[m];
                            crossColumn.Add(m);
                        }
                    }
                    foreach(var x in crossRow)
                    {
                        foreach(var y in crossColumn)
                        {
                            if(field[x][y] == '#')
                            {
                                count++;
                            }
                        }
                    }

                    if(count == k)
                    {
                        ans++;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 29208
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String scan_N = scan.next();
        String str = scan.next();
		scan.close();
        int N = Integer.parseInt(scan_N);
        if (str.substring(0,N/2).equals(str.substring(N/2,N))) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
      
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    int n;
    vector<ll> a(3);
    cin >> n;
    for(auto& i : a){
        cin >> i;
    }

    ll ans = INF;

    vector<ll> v(n);
    for(auto& i : v){
        cin >> i;
    }

    int m = 1 << 2*n;
    for(int bit = 0; bit < m; bit++){
        vector<int> u(3, 0);
        ll sum = -30;
        REP(i, n){
            int b = (bit >> 2*i) & 0b11;
            if(b == 3){
                continue;
            }
            u[b] += v[i];
            sum += 10;
        }
        if(u[0] == 0 || u[1] == 0 || u[2] == 0){
            continue;
        }
        REP(i, 3){
            sum += abs(u[i] - a[i]);
        }
        ans = min(ans, sum);
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589
int main(void)
{
	double r,are,circ;

	scanf("%lf",&r);
	are = 2*r*PI;
	circ = r*r*PI;

	printf("%f %f\n", circ, are);


	return 0;
}



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

int main(){
  ll a,b,r,temp,x;
  cin >> a >> b;
  x=a*b;
  if(a<b){
    temp=a;
    a=b;
    b=temp;
  }
  r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  cout << x/b << endl;
  return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int base = 700;
  for (int i = 0; i < 3; i++) {
    if (S[i] == 'o') {
      base += 100;
    }
  }
  cout << base << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define INF (1LL<<61LL)

typedef pair<int, int> pii;

int N, L, a[100005], dx[] = {-1, 1};
vector<int> g[100005];
bool flg[100005];

int cal(int x) {
  int res = L - a[x], temp = 0;
  for (int i = 0; i < g[x].size(); ++i) {
    temp = max(temp, cal(g[x][i]));
  }

  return res + temp;
}

signed main() {
  fill(a, a + 100005, INF);
  cin >> N >> L;
  for (int i = 1; i <= N; ++i)
    cin >> a[i];

  for (int i = 1; i <= N; ++i) {
    int count = 0;
    for (int j = 0; j < 2; ++j) {
      if (a[i + dx[j]] < a[i]) {
	g[i].PB(i + dx[j]);
	count++;
      }
    }

    if ((count == 2) || (((i == 1) || (i == N)) && (count == 1)))
      flg[i] = true;
  }

  int maxt = 0;
  for (int i = 1; i <= N; ++i) {
    if (!flg[i]) continue;
    maxt = max(maxt, cal(i));
  }

  cout << maxt << endl;
  
  return 0;
}

Measured memory_bytes: 8224
cards={}
for m in 'SHCD':
    for n in range(13):
        if m not in cards:
            cards[m] = {}
        cards[m][n+1] = False

c = input()
for i in range(int(c)):
    m, n = input().split()
    cards[m][int(n)] = True

for m in 'SHCD':
    for n in range(13):
        if not cards[m][n+1]:
            print(m, n+1)



Measured memory_bytes: 5608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String c = sc.next();
        List<String> list = new ArrayList<>(Arrays.asList("a", "i", "u", "e", "o"));
        String result = "consonant"; 
        for (String s : list) {
            if (c.contains(s)) result = "vowel";
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int a[5],nr;
int main()
{
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    for(int i=1;i<=3;i++)
    {
        int j=i;
        nr++;
        while(j<=3 && a[i]==a[j])
            j++;
        i=j-1;
    }
    if(nr==2)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

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

# s[i] = sum(a[:i])
s = [0]*(N+1)
for i in range(N):
    s[i+1] = s[i]+a[i]

# [i:j) のスライムを合体させるのに必要な最小のコスト
dp = [[10**(18)]*(N+1) for _ in range(N)]
for i in range(N):
    dp[i][i+1] = 0
for l in range(2, N+1):
    for i in range(N-l+1):
        j = i+l
        for k in range(i, j):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j] + s[j]-s[i])

print(dp[0][N])

Measured memory_bytes: 42476
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef long long i64;
typedef pair<int, i64> pii;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, f[N], d[N], dep[N]; vector<int> e[N]; pii ans;
int bfs(int u, int v)
{
    queue<int> q; q.push(u), dep[u] = 1; if(v) q.push(v), dep[v] = 1; int ret = 0;
    while(q.size())
    {
        int x = q.front(); q.pop(); f[dep[x]] = max(f[dep[x]], d[x]), ret = max(ret, dep[x]);
        for(int y:e[x]) if(!dep[y]) dep[y] = dep[x]+1, q.push(y);
    }
    return ret;
}
pii solve(int u, int v)
{   
    for(int i = 1; i <= n; ++i) f[i] = dep[i] = 0;
    pii ret; ret.fi = bfs(u, v), ret.se = f[1]-(v!=0);
    for(int i = 2; i <= n&&f[i] != 1; ++i) ret.se *= f[i]-1;
    if(v) ret.se <<= 1; return ret;
}
int main()
{
    n = read(), ans.fi = n;
    if(n == 2) return puts("1 2"), 0;
    for(int i = 1; i < n; ++i)
    {
        int x = read(), y = read(); ++d[x], ++d[y];
        e[x].push_back(y), e[y].push_back(x);
    }
    for(int i = 1; i <= n; ++i)
    {
        ans = min(ans, solve(i, 0));
        for(int j:e[i]) ans = min(ans, solve(i, j)); 
    }
    printf("%d %lld\n", ans.fi, ans.se);
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define u128 __int128
#define pb push_back

#define N 100010
#define MOD 1000000007

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
   cout.precision(10);

   int a;
   string s;
   cin >> a >> s;
   if(a >= 3200)
      cout << s;

   else
      cout << "red";
   return 0;	
}

      // while(b)
      // {
      //    if(b & 1)
      //    {
      //       an = (an * a);
            
      //       if(an > 1e18) 
      //          an /= 1e18;
      //    }
      //    a = (a * a);
      //    if(a > 1e18)
      //       a /= 1e18;
      //    b >>= 1;
      // }


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 59, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

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

    ll x = 0;
    for(int i = 0;i < n;i++){
        ll a;  cin >> a;
        x += a * i - a * (n - i - 1);
        x %= modulo;
    }

    ll y = 0;
    for(int i = 0;i < m;i++){
        ll a;  cin >> a;
        y += a * i - a * (m - i - 1);
        y %= modulo;
    }

    cout << (x * y) % modulo;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    char x,y;
    cin>>x>>y;
    int a,b;
    if(x=='A'){
    a=11;
    }else if(x=='B'){
        a=12;
    }else if(x=='C'){
        a=13;
    }else if(x=='D'){
        a=14;
    }else if(x=='E'){
        a=15;
    }else if(x=='F'){
        a=16;
    }
    if(y=='A'){
    b=11;
    }else if(y=='B'){
        b=12;
    }else if(y=='C'){
        b=13;
    }else if(y=='D'){
        b=14;
    }else if(y=='E'){
        b=15;
    }else if(y=='F'){
        b=16;
    }
    if(a==b){
        cout<<'=';
    }else if(a<b){
        cout<< '<';
    }else{
        cout<<'>';
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll g = (n+999)/1000 *1000;
	cout<<g-n<<endl;
	return 0;
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
vector<int> c;
vector<vector<pair<int, int>>> G;
void dfs(int v) {
	for (auto nx : G[v]) {
		if (c[nx.first] == -1) {
			c[nx.first] = (nx.second % 2) ^ c[v];
			dfs(nx.first);
		}
	}
}
int main()
{
	int n, u, v, w;
	cin >> n;
	G.resize(n);
	c.resize(n, -1);
	rep(i, 0, n - 1) {
		cin >> u >> v >> w;
		u--, v--;
		G[u].push_back({ v, w });
		G[v].push_back({ u, w });
	}
	c[0] = 0;
	dfs(0);
	for (auto ans : c) {
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 11156
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n;
    int ans = 0;

    cin >> n;

    for (int i = 1; i <= n; i++) {
        if (i%2) {
            int cnt = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 8) {
                ans++;
            }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
def main():
    n, d = map(int, input().split())

    if n % (2 * d + 1) == 0:
        ans = n // (2 * d + 1)
    else:
        ans = n // (2 * d + 1) + 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61868
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cfloat>
#include <cmath>
#include <functional>
#include <forward_list>
#include <list>


#define DEBUG(x) cout << #x << "\t:" << x << endl;
#define EPS (1e-9)
#define INF (INT_MAX/3)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPV(it,v) for(auto it = (v).begin(); it != (v).end(); ++it)

#define ll long long
#define ull unsigned long long


using namespace std;



class Main {
public:
	int getAreaDiff(int a, int b, int c) {
		int M = max(a, max(b, c));
		int m = min(a, min(b, c));
		return M - m;
	}

	int minArea(int w, int h) {
		int a = (w + 3 - 1) / 3;

		int b = getAreaDiff((w / 3) * h, (w - w / 3)*(h / 2), (w - w / 3)*((h + 2 -1 ) / 2));
		int c = getAreaDiff(a * h, (w - a)*(h / 2), (w - a)*((h + 2 - 1) / 2));
		int d = getAreaDiff(a * h, (w / 3)*h, (w / 3)*h);

		return min(b,min(c,d));
	}

	int getAns(int w, int h) {
		return min(minArea(w, h), minArea(h, w));
	}
};

int main(void) {
	Main main;
	int w, h;
	cin >> h >> w;

	cout << main.getAns(w, h) << endl;

	return 0;
}

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

void input(int& rnMaxNum, int& rnBase)
{
  cin >> rnMaxNum >> rnBase;
}

llong calcNumOfCase(int nMaxNum, int nBase)
{
  llong nNumOfCase = 0;
  int nTerm;

  if (nBase % 2 == 0)
  {
//    an = a1 + (n - 1)d
//    nMaxNum = (nBase / 2) + (n - 1)nBase  
     if ( nMaxNum - (nBase / 2) >= 0 )
     {
       nTerm = ( nMaxNum - (nBase / 2) ) / nBase + 1;
       nNumOfCase += (llong)nTerm * nTerm * nTerm;
     }
  }
  nTerm = nMaxNum / nBase;
  nNumOfCase += (llong)nTerm * nTerm * nTerm;

  return nNumOfCase;
}
  
int main()
{
  int nMaxNum, nBase;
  
  input(nMaxNum, nBase);
  cout << calcNumOfCase(nMaxNum, nBase) << endl;

  return 0;
}

Measured memory_bytes: 3628
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
q=[a:=~w+a*w+b]
d[a]=1
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1
   if'.'!=m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)

Measured memory_bytes: 66356