akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int n,x,b1=0,b2=0,b3=0;
	cin>>n;
	for0(i,n){
		cin>>x;
		if(x%2) b1++;
		else if(x%2==0 && x%4!=0) b2++;
		else if(x%4==0) b3++;
		}
	if(b2==0){
		if(b1<=b3+1) pf("Yes");
		else pf("No");
		}
	else{
		if(b1<=b3) pf("Yes");
		else pf("No");
		}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

void solve(){
  int n; cin >> n;
  int h[n]; for(int i = 0; i < n; i++) cin >> h[i];
  int sum = 0, maxs = 0;
  for(int i = 0; i < n - 1; i++){
    if(h[i] >= h[i + 1]) sum++;
    else{
      maxs = max(sum, maxs);
      sum = 0;
    }
  }
  maxs = max(sum, maxs);
  cout << maxs << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>

using namespace std;
long long n,m,p;
char ch[1000+10][1000+10];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
	for(int j=1;j<=m;j++)
	{
		cin>>ch[i][j];
	}
}
for(int i=1;i<=n;i++)
{
	for(int j=i+1;j<=n;j++)
	{
		p=1;
		for(int q=1;q<=m;q++)
		{
			if(ch[j][q]>ch[i][q])
			{
				p=0;break;
			}
			if(ch[i][q]>ch[j][q])
			{
				break;
			}
		}
		if(p==0)
		{
			for(int q=1;q<=m;q++)
			{
				swap(ch[i][q],ch[j][q]);
			}
		}
	}
}
for(int i=n;i>=1;i--)
{
	for(int j=1;j<=m;j++)
	{
		cout<<ch[i][j];
	}
}
	return 0;
}

Measured memory_bytes: 384
// 問題URL
// https://atcoder.jp/contests/abc148/tasks/abc148_c

import java.util.Scanner;

public class Main {
    public static Long gcd(Long a, Long b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();

        Long sum = gcd(a, b);
        System.out.println((a * b) / sum);
    }
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
int a[333];

const LL MOD = 998244353;
LL dp[333][50000];
LL dph[333][50000];

LL mpow(LL a, LL x) {
	if (x == 0)return 1LL;
	LL half = mpow(a, x / 2);
	half *= half;
	half %= MOD;
	if (x % 2) {
		half *= a;
		half %= MOD;
	}
	return half;
}

int main() {
	cin >> N;
	LL ans = 1;
	int T = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		ans *= 3;
		ans %= MOD;
		T += a[i];
	}
	bool odd = (T % 2);
	T /= 2;
	//[0~T]
	dph[0][0] = 1;
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int v = 0; v <= 45000; ++v) {
			dp[i + 1][v] += dp[i][v];
			dp[i + 1][v] %= MOD;
			dp[i + 1][v + a[i]] += (dp[i][v] * 2) % MOD;
			dp[i + 1][v + a[i]] %= MOD; 
			dph[i + 1][v] += dph[i][v];
			dph[i + 1][v] %= MOD;
			dph[i + 1][v + a[i]] += (dph[i][v]) % MOD;
			dph[i + 1][v + a[i]] %= MOD;
		}
	}
	LL S = 0;
	if (odd) {
		for (int v = 0; v <= T; ++v) {
			S += dp[N][v];
			S %= MOD;
		}
		S *= 3;
		S %= MOD;
	}
	else {
		for (int v = 0; v <= T; ++v) {
			S += dp[N][v];
			S %= MOD;
		}
		S *= 3;
		S %= MOD;
		LL half = dph[N][T];
		//half *= mpow(2, MOD - 2);
		//half %= MOD;
		half *= 3;
		half %= MOD;
		half = MOD - half;
		half %= MOD;
		S += half;
		//S *= 3;
		S %= MOD;

	}
	ans += MOD;
	ans -= S;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 237312
while True:
  inp = input()
  aopb= inp.split()
  a = int(aopb[0])
  b = int(aopb[2])
  op = aopb[1]

  if op == '+':
      print(a+b)
  elif op == '-':
      print(a-b)
  elif op == '*':
      print(a*b)
  elif op == '/':
      print(a//b)
  elif op == '?':
      break


Measured memory_bytes: 5592
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def dfs(v, d):
    if visited[v] and X[v] != d:
        return False
    if visited[v] and X[v] == d:
        return True
    visited[v] = True
    X[v] = d
    for u, c in E[v]:
        if not dfs(u, d + c):
            return False
    return True

N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    E[l].append((r, d))
    E[r].append((l, -d))
X = [None] * N
visited = [False] * N
for v in range(N):
    if not visited[v]:
        if not dfs(v, 0):
            print('No')
            exit()
print('Yes')


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

using namespace std;

int main()
{   string S;
    cin>>S;
    if (S!="Sunny"&&S!="Cloudy"&&S!="Rainy"){
        cout<<"error"<<endl;
    }
    else if (S=="Sunny"){
        cout<<"Cloudy"<<endl;
    }
    else if (S=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    else{
        cout<<"Sunny"<<endl;
    }


    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) { cin >> a[i]; }

  vector<int> wa;
  int tmp = 0;
  rep(i, n) {
    wa.push_back(tmp + a[i]);
    tmp = tmp + a[i];
  }

  int left;
  int max_sum = 0;
  rep(i, n - k + 1) {
    int sum = wa[i + k - 1] - wa[i - 1];
    if (sum >= max_sum) {
      max_sum = sum;
      left = i;
    }
  }

  double ans = 0.0;

  for (int i = left; i < left + k; i++) {
    if (a[i] % 2 == 0) {
      ans += double(a[i] / 2) + 0.5;
    } else {
      ans += double(a[i] / 2) + 1;
    }
  }

  cout << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
int N;
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
int dfs(int cu, int pa = -1) {
    int g = 0;
    for (int to : E[cu]) if (to != pa) g ^= dfs(to, cu);
    return g + 1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    rep(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    int g = dfs(1) - 1;

    if (g == 0) printf("Bob\n");
    else printf("Alice\n");
}

Measured memory_bytes: 8576
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

import math

ans = 0
for i in range(n):
    if i == 0:
        pass
    elif i == 1:
        ans += a[0]
    else:
        ans += a[math.floor(i/2)]

print(ans)

Measured memory_bytes: 94196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int h1 = sc.nextInt();
		int w1 = sc.nextInt();
		int h2= sc.nextInt();
		int w2 = sc.nextInt();

		int count = h1 * w1;
		int discount = h2 * w2 + (h1 - h2) * w2 + (w1- w2) * h2;

		System.out.println(count - discount);


	}

}


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

A = []
A.append(B[0])
for i in range(1,N):
  a = 10 ** 6
  a = min(a,B[i-1])
  a = a if N-1 <= i else min(a,B[i])
  A.append(a)
  
print(sum(A))
  

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

priority_queue<int> pq;
int N,M;
int arr[100000];
long long sum;

int main(){
  cin >> N >> M;
  int x;
  for (int i=0;i<N;i++){
    cin >> x;
    pq.push(x);
  }
  int temp;
  while (M>0){

    temp = pq.top()/2;
    pq.pop();pq.push(temp);
    M -= 1;
  }
  while (!pq.empty()){
    sum += pq.top();
    pq.pop();
  }
  cout << sum;
  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll a;
    unordered_map<ll,ll> mp;
    REP(i,n){
        cin >> a;
        mp[a]++;
    }
    ll ans=0;
    for(pair<ll,ll> p:mp){
        if(p.fr>p.sc)ans+=p.sc;
        if(p.fr<p.sc)ans+=(p.sc-p.fr);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4260
#include<stdio.h>
#include<math.h>

int main(){

 int A,B,C,D;
 scanf("%d %d %d %d",&A,&B,&C,&D);

 int takashi = C / B;
 int amari = C%B;
 if (amari > 0){takashi =takashi + 1;} 

 int aoki = A / D;
 int aoki_amari = A%D;
 if(aoki_amari > 0){aoki = aoki + 1;}

 if(takashi>aoki){
	printf("No");
}else if(takashi == aoki){
	printf("Yes");
}else{
	printf("Yes");

}



return 0;
}

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

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

    /* 数値を降順にソート */
  for (int i = 0; i < n;i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] < a[j]) {
        int tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
    //M位の得票数が全体の1/4M以上であればYes,　そうでなければNO
    if(a[m-1] * (4 * m) >= total){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	char ch=getchar();
	int num=0,flus=1;
	while(ch<'0'||ch>'9')
	{if(ch=='-') flus=-flus;ch=getchar();}
	while(ch>='0'&&ch<='9')
	{num=num*10+ch-'0';ch=getchar();}
	return num*flus;
}
int main(void)
{
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	for(int i=0;i<n;i++)
		cout<<a[i]<<b[i];
	return 0;
}
//	freopen("working.in","r",stdin);
//	freopen("working.out","w",stdout);

Measured memory_bytes: 256
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeApplications #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.IntSet as Set
import qualified Data.List as L
import System.Random

main :: IO ()
main = do
  [d] <- readInts
  scoreTable <- readInts
  replicateM d readInts >>= output d . solve
 
solve :: [[Int]] -> _
solve xs = xs
 
output :: Int -> _ -> IO ()
output d _ = mapM_ (print . (+1) . flip mod 26 . read @Int) $ take d $ f digs
  where
    f (x1:x2:xs) = [x1,x2] : f xs

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

-- リストのhead側を正格評価する版
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' f (x:xs) (y:ys) = let z = f x y
                           in z `seq` (z : zipWith' f xs ys)

-- zipWithを使った版（正格評価）
fib' :: [Int]
fib' = 0 : 1 : zipWith' (+) fib' (tail fib')

pi_ :: [Integer]
pi_ = g(1,0,1,1,3,3) where
  g (q,r,t,k,n,l) =
   if 4*q+r-t < n*t
    then n : g (10*q, 10*(r-n*t), t, k, div (10*(3*q+r)) t - 10*n, l)
    else g (q*k, (2*q+r)*l, t*l, k+1, div (q*(7*k+2)+r*l) (t*l), l+2)
 
digs :: [Char]
digs = drop 2 $ insertPoint digs'
  where insertPoint (x:xs) = x:'.':xs
        digs' = map (head . show) pi_

Measured memory_bytes: 6028
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,k,x,y;
    cin >> n >> k >>x >>y;
    ll ans=0;
    for(ll i =1;i<=n;i++)
    {
        if(i<=k)
        {

            ans+=x;
        }
        else 
        {
            ans+=y;
        
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

long long gcd(long long a, long long b)
{
  while(b) {
    long long at = a;
    a = b;
    b = at % b;
  }
  return a;
}

long long lcm(long long a, long long b)
{
  if (b > a) swap(a, b);
  return a / gcd(a, b) * b;
}

ll get(ll A, ll B, ll N)
{
  return B/N - (A - 1)/N;
}

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

  ll L = lcm(C, D);
  ll X = get(A, B, C),
     Y = get(A, B, D),
     Z = get(A, B, L);
  cout << (B - A  + 1 - (X + Y - Z)) << endl;

  return 0;
}


Measured memory_bytes: 256
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, k = map(int, input().split())
data = getInputListInt()

def calcCost(a, b):
    mina = abs(a)+abs(a-b)
    minb = abs(b)+abs(b-a)

    return min(mina, minb)

ans = sys.maxsize
for i in range(0, n-k+1, 1):
    tmpans = calcCost(data[i], data[i+k-1])
    ans = min(ans, tmpans)

print(ans)

Measured memory_bytes: 24060
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	mod = 10^9+7
	n = readline() |> parseInt
	s = readline() |> chomp
	t = readline() |> chomp
	dp = zeros(Int,n)
	dp[1] = s[1]==t[1]?3:6
	now = s[1]==t[1]?2:3
	if s[1]!=t[1]
		dp[2]=dp[1]
	end
	while now<=n
		if s[now]==t[now]
			if s[now-1]!=t[now-1]
				dp[now]=dp[now-1]
			else
				dp[now]=(dp[now-1]*2)%mod
			end
			now += 1
		elseif s[now-1]==t[now-1]
			dp[now]=(dp[now-1]*2)%mod
			dp[now+1] = dp[now]
			now += 2
		else
			dp[now]=(dp[now-1]*3)%mod
			dp[now+1] = dp[now]
			now += 2
		end
	end
	println(dp[n])
end
main()

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

int main(){
    long long x,a,b;
    cin >> x >> a >> b;
    if(b<=a)cout << "delicious" << endl;
    else if(a+x>=b)cout << "safe" << endl;
    else cout << "dangerous" << endl; 
    return 0;
}

Measured memory_bytes: 256
use proconio::marker::*;
use proconio::*;
use std::cmp::max;

fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    };
    let x = x.abs();

    let ans;
    if x / d >= k {
        ans = x - d * k;
    } else {
        ans = if (k - x / d) % 2 == 0 {
            x % d
        } else {
            (x % d - d).abs()
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 2120
n = int(input())
s = list(map(str,input()))
left = 0
right = 0
for i in range(n):
    if s[i]==".":
        right += 1
ans = right
if s[0]==".":
    right -= 1
for j in range(1,n):
    if s[j-1]=="#":
        left += 1
    if s[j]==".":
        right -= 1
    ans = min([ans,left+right])
if s[n-1]=="#":
    left += 1
ans = min([ans,left])
print(ans)


Measured memory_bytes: 5096
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
int main(){
 ll n,x;
 cin >> n>>x;
 ll a[n];
 ll ans=0;
 for(ll i=0;i<n;i++) cin >>a[i];
 for(ll i=0;i<n-1;i++){
   if(a[i]+a[i+1]>x){
      ll b=a[i]+a[i+1]-x;
      if(b>a[i+1]){
         ans+=b;
         a[i+1]=0;
       }
       else {
         ans+=b;
         a[i+1]-=b;
       }
 }
}
cout << ans<<endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
def main():
  n,m,s=map(int,input().split())
  uvab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(n)]
  g=[[]for _ in range(n)]
  for u,v,a,b in uvab:
    g[u-1].append((v-1,a,b))
    g[v-1].append((u-1,a,b))
  import heapq
  inf=pow(10,21)
  max_s=50*50
  dp=[[inf]*(max_s+1)for _ in range(n)]
  kakutei=[[0]*(max_s+1)for _ in range(n)]
  dp[0][min(s,max_s)]=0
  todo=[[0,0,min(s,max_s)]] # [dp[v][i],v,i]
  heapq.heapify(todo)
  flgs=[0]*n
  flg=0
  ans=[inf]*n
  while flg<n:
    _,v,i=heapq.heappop(todo)
    if kakutei[v][i]==1:
      continue
    kakutei[v][i]=1
    if flgs[v]==0:
      flg+=1
      flgs[v]=1
    c,d=cd[v]
    ans[v]=min(ans[v],_)
    # 両替
    j=min(max_s,i+c)
    if kakutei[v][j]==0:
      dp[v][j]=min(dp[v][j],dp[v][i]+d)
      heapq.heappush(todo,[dp[v][j],v,j])
    # 鉄道
    l=g[v]
    for u,a,b in l:
      if i-a>=0 and kakutei[u][i-a]==0:
        dp[u][i-a]=min(dp[u][i-a],dp[v][i]+b)
        heapq.heappush(todo,[dp[u][i-a],u,i-a])
  print(*ans[1:],sep='\n')
if __name__=='__main__':
  main()


Measured memory_bytes: 32984
n, k = map(int,input().split())
p = list(map(int,input().split()))
e = []
ruiseki = []

for i in p:
    temp = (1+i)/2
    e.append(temp)
    if len(ruiseki) == 0:
        ruiseki.append(temp)
    else:
        ruiseki.append(ruiseki[len(ruiseki)-1] + temp)

e_sum = []

for i in range(n-k+1):
    if i == 0:
        e_sum.append(ruiseki[i+k-1])
    else:
        e_sum.append(ruiseki[i+k-1] - ruiseki[i-1])

print(max(e_sum))


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

const int N = int(5e5);
int n, k, a[101], dp[N];
 
int main()
{
	memset(dp, -1, sizeof(dp));
 
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
	}
	
 
	for (int i = 0; i <= k; i++)
	{
		dp[i] = 0;
		for (int j = 0; j < n; j++)
		{
			if (i - a[j] == 0)
			{
				dp[i] |= 1;
			}
			else if (i - a[j] > 0)
			{
				dp[i] |= dp[i - a[j]] ^ 1;
			}
			else
			{
				dp[i] |= 0;
			}
		}
	}
 
	puts((dp[k] ? "First" : "Second"));
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int k, a, b;
    bool flag = false;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            flag = true;
            cout << "OK";
            break;
        }
    }
    if (!flag)
        cout << "NG";
}

Measured memory_bytes: 3608
a = input()
b = input()
dic = {}

for i in range(len(a)):
  if not b[i] in dic:
    dic[b[i]] = a[i]
  else:
    if dic[b[i]] != a[i]:
      print("No")
      quit()
  #print(dic)
c = list(dic.values())
d = set(c)
#print(c)
#print(d)
if len(c) == len(d):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll a,b,k;
  cin >>a >> b >> k;

  ll aans = max(a-k,0LL);
  ll bans = max(b - (k-(a-aans)),0LL);
  cout << aans << " " << bans << endl;    

  
  return 0;
    

}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	if(n%10==9 || n/10==9) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<algorithm>
typedef long long int ll;
using namespace std;
ll f(ll n,ll b){
    ll a=0;
    while(n>0){
        a+=n%b;
        n=n/b;
    }
 
    return a;
}
int main(){
    ll b,n,s,ans=-1;
    cin>>n>>s;
       if(n==s)ans=n+1;
       if(s<=(n+1)/2){
        ll k=1;
        bool flag=true;
        do{
          if(k*k>=n||k>s)flag=false;
            if((n-s)%k==0){
            b=(n-s)/k+1;
            if(b<=s-k)flag=false;
            if(flag) ans=b;
            }
            k++;
        }while(flag);
    }
    b=2;
        while(b*b<=n){
            if(f(n,b)==s){
                ans=b;
                goto end;
            }
          b++;
        }
    end:
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int mod = 1e9 + 7;

const int nax = 2e5 + 5;
int fac[nax], inv_fac[nax];

int mul(int a, int b) {
    return (ll) a * b % mod;
}
int my_pow(int a, int b) {
    int r = 1;
    while(b) {
        if(b % 2) {
            r = mul(r, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return r;
}
int my_inv(int a) {
    return my_pow(a, mod - 2);
}

int binomial(int a, int b) {
    if(a < 0 || b < 0 || b > a) {
        return 0;
    }
    return mul(fac[a], mul(inv_fac[b], inv_fac[a-b]));
}

int f(int a, int b) {
    int tmp = binomial(a + b, b);
    //~ debug() << imie(a) imie(b) imie(tmp);
    return tmp;
}

int sub(int a, int b) {
    return (a - b + mod) % mod;
}

int main() {
    fac[0] = inv_fac[0] = 1;
    for(int i = 1; i < nax; ++i) {
        fac[i] = mul(fac[i-1], i);
        inv_fac[i] = my_inv(fac[i]);
    }
    int h, w, n;
    scanf("%d%d%d", &h, &w, &n);
    vector<pair<int,int>> in(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d%d", &in[i].first, &in[i].second);
    }
    sort(in.begin(), in.end(), [&](pair<int,int> a, pair<int,int> b) {
        return a.first + a.second < b.first + b.second;
    });
    // dp[i] - the number of paths to vertex in[i] such that it's the first
    // forbidden vertex
    
    in.emplace_back(h, w);
    
    vector<int> dp(n + 1);
    for(int i = 0; i <= n; ++i) {
        int tmp = f(in[i].first - 1, in[i].second - 1);
        debug() << imie(tmp);
        for(int j = 0; j < i; ++j) {
            if(in[j].first <= in[i].first && in[j].second <= in[i].second) {
                tmp = sub(tmp, mul(dp[j], f(in[i].first - in[j].first, in[i].second-in[j].second)));
            }
        }
        dp[i] = tmp;
    }
    debug() << imie(dp);
    printf("%d\n", dp[n]);
}


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

using namespace std;

#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())

typedef long long ll;typedef vector<int> vi;
typedef pair<int,int> ii;typedef vector<ii> vii;
typedef vector<vi> vvi;

signed main(){
	IOS
	int n,k;cin>>n>>k;
	vi ok(10,1);
	forn(i,k){
		int x;cin>>x;ok[x]=0;
	}
	forn(i,1e5){
		if(i<n) continue;
		int nc=i;
		bool good=1;
		while(nc){
			if(!ok[nc%10]) good=0;
			nc/=10;
		}
		if(good){
			cout<<i<<"\n";
			return 0;
		}
	}
}

Measured memory_bytes: 3576
#include <stdio.h>
 
int main() {
	int n;
	int k;
	int hitung=1;
	scanf("%d", &n);
	scanf("%d", &k);
	for(int i=0;i<n;i++){
		if(hitung<k){
			hitung*=2;
		}else{
			hitung+=k;
		}
	}
	
	printf("%d\n", hitung);
	
	return 0;	
}

Measured memory_bytes: 1732
while True:
    
    amax=-1; amin=1001; t=0
    n = int(input())
    if n==0:
        break
    
    for i in range(n):
        a = int(input())
        amax = max(amax,a)
        amin = min(amin,a)
        t += a
    
    print((t-amax-amin)//(n-2))


Measured memory_bytes: 5592
main :: IO ()
main = do
  [w, a, b] <- map (read :: String -> Int) . words <$> getLine
  print $ solve w a b

solve :: Int -> Int -> Int -> Int
solve w a b = if a' + w > b'
              then 0
              else b' - (a'+w)
  where
    a' = min a b
    b' = max a b


Measured memory_bytes: 508
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
const int N=100010;

void solve(){
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    for(int i=0;i<n;i++){
        cout<<a[i]<<b[i];
    }
    cout<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int n,m;
const int nax =1e5 + 10;
vvi adj(nax);
vi vis(nax), par(nax),dist(nax);

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    int u,v;
    forn(i,m){
        cin>>u>>v;
        adj[u].pb(v); adj[v].pb(u);
    }    

    vi q;
    vis[1] = 1;
    q.pb(1);
    
    int d = 0;
    while(!q.empty()){
        vi nq;
        for(auto top: q){
            dist[top] = d;
            for(auto ad: adj[top]){
                if(vis[ad]) continue;
                vis[ad] = true;
                par[ad] = top;
                nq.push_back(ad);
            }
        }
        q = nq;
        ++d;
    }

    // fore(i,1,5){
    //     deb(i,par[i], dist[i]);
    // }

    bool no = false;
    fore(i,1,n+1)   
        if(!vis[i])
            no = true;
    
    if(no){
        cout<<"No\n";
        return 0;
    }

    cout<<"Yes\n";
    fore(i,2,n+1){
        // deb(i,par[i]);
        cout<<par[i]<<endl;
    }

    
    return 0;
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    string s, t;
    cin >> s >> t;

    ll count = 0;
    REP(i, s.length()) {
      if (s[i] != t[i]) {
        count++;
      }
    }

    COUT(count);

}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3776
from collections import deque

S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))


Measured memory_bytes: 95320
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;
typedef long long ll;

ll fact(long n)
{
	if (n == 1) return 1;
	return (n * fact(n - 1)) % MOD;
}

int main()
{
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int N, M;
	cin >> N >> M;

	ll count = 0;
	if (N == M)
	{
		count = fact(N);
		count = count * count * 2;
	}
	else if (abs(N - M) == 1)
	{
		count = fact(N) * fact(M);
	}
	else
	{
		count = 0;
	}

	cout << count % MOD << "\n";

	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int n,a,b;
	scanf("%d",&n);
	if(n==1)
	{
		puts("Hello World");
	}
	else
	{
		scanf("%d%d",&a,&b);
		printf("%d\n",a+b);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,x,m;
    cin>>n>>x>>m;
    long long ans=0;
    long long prev=x;
    unordered_map<long long,int> st;
    vector<long long> vec;
    vec.push_back(0);
    int mark=1e9;
    for(int i=1;i<=n;i++)
    {
        //cout<<prev<<endl;
        if(st.find(prev)==st.end())
        {
            st.insert({prev,i});
            vec.push_back(prev);
            prev=(prev*prev)%m;
        }
        else
        {
            mark=st[prev];
            break;
        }
    }
    mark=min(mark,(int)vec.size());
    for(int i=1;i<mark;i++)
    {
        ans=ans+vec[i];
    }
    int len=vec.size()-mark;
    if(len>0)
    {
        long long cycleSum=0;
        for(int i=mark;i<vec.size();i++)
        {
            cycleSum+=vec[i];
        }
        n=n-(mark-1);
        ans=ans+(n/len)*cycleSum;
        for(int i=mark;i<=(n%len)-1+mark;i++)
        {
            ans+=vec[i];
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int sum=0;
    for(int i=0;i<=n;i++){
        int dsum=0;
        int num=i;//iを保存
        while(num>0){
            int dig=num%10;
            dsum+=dig;
            num/=10;
        }
        if(dsum>=a && b>=dsum) sum+=i;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
import kotlin.system.exitProcess

fun main(args: Array<String>) {
    abc081B(args)
}
fun abc081B(args: Array<String>) {
    val N = readLine()!!
    val Ai = readLine()!!.split(" ").map(String::toInt).toMutableList()

    var counter = 0
    loop@ while (true) {
        Ai.forEachIndexed { i, a ->
            run {
                if(a % 2 != 0) {
                    println(counter)
                    exitProcess(0)
                }
                Ai[i] = Ai[i] / 2
            }
        }
        counter++
    }
    println(counter)
}


Measured memory_bytes: 38152
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
if n%2 == 0:
    ans = sum(a[:n//2])*2 - a[0]
else:
    ans = sum(a[:n//2+1])*2 - a[0] - a[n//2]
print(ans)

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var N = r[0].ToInt();
            var R = r[1].ToInt();
            if (N >= 10)
            {
                WriteLine(R);
            }
            else
            {
                WriteLine(R + (100 * (10 - N)));
            }
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteLine(object str)
        {
            Console.WriteLine(str);
        }
    }
}

public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



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

const int N = 1000000 + 1;
ll dp[N], dp2[N];

int main() {

    dp[0] = dp2[0] = 0;
    for (int i=1; i<N; ++i) {
        dp[i] = dp2[i] = i;
        for (int n=1;; ++n) {
            int p = n*(n+1)*(n+2)/6;
            if (p > i) break;
            dp[i] = min(dp[i], dp[i-p]+1);
            if (p%2) {
                dp2[i] = min(dp2[i], dp2[i-p]+1);
            }
        }
    }

    int n;
    while (cin >> n and n) {
        cout << dp[n] << " " << dp2[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 18612
#include<iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    int a[n],sum=0;
    r(i,n)cin>>a[i];
    r(i,n)for(int j=1;j<n;j++){
      if(a[j-1]>a[j]){
        swap(a[j-1],a[j]);
        sum++;
      }
    }
    cout<<sum<<endl;
  }
}

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


int main() {
	vector<int> x(3);
	int count = 0;
	cin >> x[0] >> x[1] >> x[2];
	sort(x.begin(), x.end(), greater<int>());
	int a = x[0];
	int b = x[1];
	int c = x[2];
	if (a % 2 == b % 2 &&a%2!= c % 2) {
		a++;
		b++;
		count++;	
	}
	else if (a % 2 == c % 2 &&a%2!= b % 2) {
		a++;
		c++;
		count++;
	}
	else if (b % 2 == c % 2 &&b%2!= a % 2) {
		b++;
		c++;
		count++;
	}
		count += (a - c) / 2;
		count += (a - b) / 2;
		cout << count;
}

Measured memory_bytes: 256
#include <stdio.h>

void chmax(long *a, long b) {
    if(*a < b) *a = b;
}

void chmin(long *a, long *b) {
    if(*a > *b) *a = *b;
}


int main(void) {

    int n; scanf("%d", &n);

    long r[n];
    long ans = -9999999999, minv = 9999999999;
    for(int i = 0; i < n; i++) scanf("%ld", &r[i]);

    for(int i = 0; i < n; i++) {
        chmax(&ans, r[i]-minv);
        chmin(&minv, &r[i]);
    }

    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
const int N=100001;
struct node {
	int to,cl,le;
};
struct ques {
	int id,cl,le,fg;
};
int n,q;
int f[N][18],dep[N],dis[N],ans[N],cs[N],cc[N];
vector<node>G[N];
vector<ques>Q[N];
void dfs(int x,int fa,int d) {
	f[x][0]=fa;
	dep[x]=dep[fa]+1;
	dis[x]=d;
	for(unsigned i=0; i<G[x].size(); i++) {
		int y=G[x][i].to;
		if(y==fa)continue;
		dfs(y,x,d+G[x][i].le);
	}
}
int UP(int x,int step) {
	for(int i=0; i<=17; i++)if(step&(1<<i))x=f[x][i];
	return x;
}
int LCA(int a,int b) {
	if(dep[a]>dep[b])swap(a,b);
	b=UP(b,dep[b]-dep[a]);
	if(b==a)return a;
	for(int i=17; i>=0; i--)if(f[a][i]!=f[b][i])a=f[a][i],b=f[b][i];
	return f[a][0];
}
void DFS(int x) {
	for(unsigned i=0; i<Q[x].size(); i++) {
		ans[Q[x][i].id]+=Q[x][i].fg*(dis[x]-cs[Q[x][i].cl]+cc[Q[x][i].cl]*Q[x][i].le);
	}
	for(unsigned i=0; i<G[x].size(); i++) {
		int y=G[x][i].to;
		if(y==f[x][0])continue;
		cc[G[x][i].cl]++;
		cs[G[x][i].cl]+=G[x][i].le;
		DFS(y);
		cc[G[x][i].cl]--;
		cs[G[x][i].cl]-=G[x][i].le;
	}
}
int main() {
	scanf("%d%d",&n,&q);
	for(int i=1,a,b,c,d; i<n; i++) {
		scanf("%d%d%d%d",&a,&b,&c,&d);
		G[a].push_back((node)<%b,c,d%>);
		G[b].push_back((node)<%a,c,d%>);
	}
	dfs(1,0,0);
	for(int j=1; j<18; j++)for(int i=1; i<=n; i++)f[i][j]=f[f[i][j-1]][j-1];
	for(int i=1,a,b,c,d; i<=q; i++) {
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int t=LCA(c,d);
		Q[c].push_back((ques)<%i,a,b,1%>);
		Q[d].push_back((ques)<%i,a,b,1%>);
		Q[t].push_back((ques)<%i,a,b,-2%>);
	}
	DFS(1);
	for(int i=1; i<=q; i++)printf("%d\n",ans[i]);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> um;
  vector<int> v;
  int a;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a);
    if (um.find(a) == um.end()) {
      um[a] = 1;
      v.push_back(a);
    } else {
      um[a] = um[a] + 1;
    }
  }
  ll ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    if (um[v[i]] > v[i]) {
      ans += um[v[i]] - v[i];
    } else if (um[v[i]] < v[i]) {
      ans += um[v[i]];
    }
  }

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


Measured memory_bytes: 4636
import scala.io.StdIn.readLine

object Main{
	def main(args: Array[String]){
		val input = readLine().split(" ").map(_.toInt)
		val a: Int = input(0)
		val b: Int = input(1)
		
		if(a > b){
			println("a > b")
		}else if(a < b){
			println("a < b")
		}else{
			println("a == b")
		}
	}
}

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


vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i=1ll; i*i<=n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


int main() {
    long long n, m;
    cin >> n >> m;
    vector<long long> div = calc_divisor(m);

    long long res = 1;
    for(auto d : div){
        if (d * n <= m){
            res = max(res, d);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    S = list(input().rsplit()[0])

    x = int(S[-1])
    if x in [2, 4, 5, 7, 9]:
        print('hon')
    elif x in [0, 1, 6, 8]:
        print('pon')
    else:
        print('bon')


if __name__ == "__main__":
    main()


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

int main() {
    string s, t, u;
    int a, b;

    cin >> s >> t >> a >> b >> u;
    if (s == u) a--;
    if (t == u) b--;

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
 
int main(){
  int n;
  cin >> n;
  pint b[n],r[n];
  rep(i,n)cin >> r[i].second >> r[i].first;
  rep(i,n)cin >> b[i].first >> b[i].second;
  sort(r,r+n,greater<>());
  sort(b,b+n);
  bool bused[n],rused[n];
  rep(i,n){
    rused[i]=false;
  }
  ll ans=0;
  rep(i,n){
   rep(j,n){
    if(b[i].first>r[j].second && b[i].second>r[j].first && !rused[j]){
               rused[j]=true;
      ans++;
      break;
    }
   }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  rep(i,n){
    cin>>a[i];
  }
  int count=0;
  bool fg=true,fg2=false;
  REP(i,1,n){
    if(fg){
      if(a[i]>a[i-1]){
        fg2=true;
      }
      else if(a[i]<a[i-1]){
        fg2=false;
      }
      else{
        fg=true;
        continue;
      }
      fg=false;
    }
    else{
      if(fg2){
        if(a[i]<a[i-1]){
          count++;
          fg=true;
        }
      }
      else{
        if(a[i]>a[i-1]){
          count++;
          fg=true;
        }
      }
    }
  }
  cout<<count+1<<'\n';
  return(0);
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

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

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		40010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//




//
int main(){
	int N,K,Q;cin>>N>>K>>Q;
	V p(N,0);
	REP(i,Q){
		int t;cin>>t;
		p[t-1]++;
	}

	REP(i,N){
		if(Q-p[i] < K)puts("Yes");
		else puts("No");
	}

	return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;

int main() {
  int n, ans[100], i;
  while (cin >> n) {
    if (n == -1)
      break;
    if (n == 0) {
      cout << 0 << endl;
      continue;
    }
    vector<int> v;
    while (n != 0) {
      v.push_back(n % 4);
      n /= 4;
    }
    for (int i = v.size() - 1; i >= 0; i--) {
      cout << v[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3072