akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int h, w, m; 

int main(void){
    cin >> h >> w >> m;
    vector<int> cntH(h+1, 0), cntW(w+1, 0);
    set<pair<int, int>> target;
    for(int i = 0; i < m; i++){
        int hTmp, wTmp;
        cin >> hTmp >> wTmp;
        target.insert( make_pair(hTmp, wTmp) );
        cntH.at(hTmp) = cntH.at(hTmp) + 1;
        cntW.at(wTmp) = cntW.at(wTmp) + 1;
    }

    vector<int> hCoor, wCoor;
    int maxH = 0, maxW = 0;
    for (int i = 1; i <= h; i++){
        if( maxH < cntH.at(i) ){
            maxH = cntH.at(i);
            hCoor.clear();
            hCoor.push_back(i);
        }
        else if( maxH == cntH.at(i) ) {
            hCoor.push_back(i);
        }
    }
    for (int i = 1; i <= w; i++){
        if( maxW < cntW.at(i) ){
            maxW = cntW.at(i);
            wCoor.clear();
            wCoor.push_back(i);
        }
        else if( maxW == cntW.at(i) ) {
            wCoor.push_back(i);
        }
    }
    
    int ans = maxH + maxW - 1;
    for ( auto itrH = hCoor.begin(); itrH != hCoor.end(); itrH++ ){
        for ( auto itrW = wCoor.begin(); itrW != wCoor.end(); itrW++ ){
            if( target.count(make_pair(*itrH, *itrW)) == 0 ){
                cout << ans + 1 << endl;
                return 0;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23868
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int  time = scanner.nextInt();//要素数
		int[] array = new int[num];
		String[] pro = new String[num];
		
		//配列作り
		for(int i = 0; i < num; i ++ ){
			pro[i] = scanner.next();		//マーク
			array[i] = scanner.nextInt();	//数字
		}
		
		Queue(pro, array,num,time);
		
		scanner.close();
	}

	public static void Queue( String[] pro, int[] array,int num,int time){
		int sub;
		int i;
		int end_count = 0;
		int end_count_now;
		int time_count = 0;
		boolean judge_end = false;
		
		//ラウンドロビンスケジューリング
		while( end_count < num  ){										//全部終わったら終わり
			end_count_now = 0;
			judge_end = false;
			
			for( i = 0; i < num - end_count; i ++ ){
				sub = array[i] - time;
				if(sub <= 0){
					time_count += array[i];								//時間分だけ足す
					System.out.println(pro[i] +  " " + time_count);		//時間内なら出力
					end_count_now ++;									//今回っている中での終わった数
					judge_end = true;									//終わったものがある示唆
				}else{
					array[i] -= time;									//処理したので要素から引く
					time_count += time;									//合計時間には足す
					if(judge_end) {										//終わってるものがあれば
						array[i - end_count_now] = array[i];			//終わってる数だけ前へ
						pro[i - end_count_now] = pro[i];				//マークも一緒に
					}
				}
				continue;
			}
			end_count += end_count_now;									//今回終わった数を出す
		}
	}
}


Measured memory_bytes: 72480
b = []
r = []

for _ in range(5):
  a = int(input())
  b.append((a // 10) * 10)
  r.append(a % 10)

ans = sum(b)
r.sort()

x = 10
count = 0
for _, ele in enumerate(r):
  if ele > 0:
    x = ele
    break
  count += 1
  
ans += (x + (4 - count) * 10)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int r; cin>>r;
    if(r<1200){
        o("ABC");
    }else if(r<2800){
        o("ARC");
    }else{
        o("AGC");
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int main()
{	
	int n;
	cin>>n;
	int n1;
	int n2;
	n1=n/500;
	int left = n%500;
	n2=left/5;
	int left2=left%5;
	cout<<(1000*n1+5*n2);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
ll f, g, h, i,j;
f = (a + 9) / 10 * 10;
g = (b + 9) / 10 * 10;
h = (c + 9) / 10 * 10;
i = (d + 9) / 10 * 10;
j = (e + 9) / 10 * 10;
ll ans = f + g + h + i + j;
ans -= max({f - a, g - b, h - c, i - d, j - e});
cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int cnt = 0;
  int H[1000];
  int W[1000];
  int i=0;
  int j=0;
  int k=0;
  int x=0;
  for(i=0;i<1000;i++){
      scanf("%d %d",&H[i],&W[i]);
      cnt++;
      if(H[i] == 0 && W[i] == 0) break;
      if( (H[i]<1 || H[i]>300) || (W[i]<1 || W[i]>300) ) return 1; 
  }
//  for(int y=0;y<5;y++) printf("%d,%d %d\n",H[y],W[y],cnt);
   for(x=0;x<cnt-1;x++){

        for(j=0;j<H[x];j++){

            for(k=0;k<W[x];k++) { putchar('#'); /* printf("%d",W[k]); */ }

             putchar('\n');
        }
        putchar('\n');
   }
    return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
int main(void)
{
    int k;
    char s[101];
    char S[105];
    int i;
    scanf("%d", &k);
    scanf("%s", s);
    int len = strlen(s);
    if (len <= k)
    {
        printf("%s\n", s);
    }
    else
    {
        for (i = 0; i < k; i++)
        {
            S[i] = s[i];
        }
        S[i] = '.';
        S[i + 1] = '.';
        S[i + 2] = '.';
        S[i + 3] = '\0';
        printf("%s\n", S);
    }

    return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll a, b, c; cin >> a >> b >> c;
	int kkt = 89;
	set<ll> s;
	int cur = 0;
	while (kkt) {
		if (s.find(cur % 60) != s.end()) {
			puts("-1");
			return 0;
		}
		for (int i = 1; i <= a; i++) {
			if ((cur + i) % 60 == c) {
				cout << cur + i << endl;
				return 0;
			}
		}
		s.emplace(cur % 60);
		cur += a + b;
	}
	return 0;

}



Measured memory_bytes: 3136
a, b, n = map(int, input().split())
x = min(n, b)
while x % b == 0 and b != 1:
    x -= 1
if b == 1:
    print(0)
else:
    i = x
    # print(a * i // b - a * int(i / b), a * i // b, a * int(i / b))
    print(a * x // b)
# print(x)
# ans = 0
# for i in range(1, n + 1):
#     ans = max(ans, a * i // b - a * int(i / b))
#     # print(i, ans, a * i // b - a * int(i / b), a * i // b, a * int(i / b))
# print(ans)

Measured memory_bytes: 8996
from sys import stdin
from math import factorial

n, k = [int(x) for x in stdin.readline().rstrip().split()]
MOD = 1000000007


def combination(x, y):
    return factorial(x) // (factorial(x-y) * factorial(y))


for i in range(1, k+1):
    if n - k + 1 < i:
        ans = 0
    else:
        blue = combination(k-1, i-1)
        red = combination(n-k+1, i)
        ans = blue * red
    print(ans % MOD)


Measured memory_bytes: 3316
#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 = 1001001001;

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> g(h);
    rep(i,h) {
        cin >> g.at(i);
    }
    
    int cnt = 0;
    rep(i,(1<<h)){
        rep(j,(1<<w)){
            int temp = 0;
            rep(k,h) {
                rep(l,w){
                 if(i & (1<<k)) {continue;}
                 if(j & (1<<l)) {continue;}
                 if(g.at(k).at(l) == '#') temp++;
                }
            }
            if(temp == k) cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3624
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

INF = 10000

for i in range(10):
    for j in range(10):
        for k in range(10):
            C[j][k] = min(C[j][k], C[j][i] + C[i][k])

ans = 0
for h in range(H):
    for w in range(W):
        a = A[h][w]
        if a == -1:
            continue
        ans += C[a][1]
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define MAXN 95555
using namespace std;

vector<int> Prime;
int flag[MAXN];
void siv() {
  Prime.push_back(2);
  for(int i = 4 ; i <= MAXN ; i += 2) flag[i] = 1;
  for(int i = 3 ; i * i <= MAXN ; i += 2) {
    if(!flag[i]) {
      for(int j = i * i , k = (i * 2) ; j <= MAXN ; j += k) {
        flag[j] = 1;
      }
    }
  }
  for(int i = 3 ; i < MAXN ; i += 2) {
    if(!flag[i]) {
      Prime.push_back(i);
    }
  }
}

int main()
{
  siv();
  int n;
  cin >> n;
  for(int i = 0 , ans = 0 ; i < Prime.size() && ans != n ; i++) {
    if(Prime[i] % 5 == 1) ans++ , printf("%d ", Prime[i]);
    //if(Prime[i] % 5 == 2) ans++ , printf("%d ", Prime[i]);
    //if(Prime[i] % 5 == 3) ans++ , printf("%d ", Prime[i]);
    //if(Prime[i] % 5 == 4) ans++ , printf("%d ", Prime[i]);
  }
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> A;

int main() {
	cin >> N;
	A.resize(N);
	ll ma = 0;
	for (ll n = 0; n < N; n++) {
		cin >> A[n];
		ma = max(ma, A[n]);
	}
	ll ansn = 0;
	ll ans = -1;
	for (ll n = 0; n < N; n++) {
		if (A[n] == ma)continue;
		if (min(ans, ma - ans) < min(A[n], ma - A[n])) {
			ansn = n;
			ans = A[n];
		}
	}
	cout << ma << " " << A[ansn] << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	for i := 0; i <= len(S); i++ {
		for j := i; j <= len(S); j++ {
			s := S[:i] + S[j:]
			if s == "keyence" {
				fmt.Println("YES")
				return
			}
		}
	}
	fmt.Println("NO")
}


Measured memory_bytes: 2024
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int odd = 0;
        for (int i = 0; i < N; i++) {
        	int a = sc.nextInt();
        	if (a % 2 == 1) {
        		odd++;
        	}
        }
        odd = odd % 2;
        
        System.out.println(odd == 1 ? "NO": "YES");
    }
}

Measured memory_bytes: 48456
n = gets.to_i
numbers = gets.chomp.split(" ").map(&:to_i)

swapFlg = true
count = 0
while swapFlg
    swapFlg = false
    for i in 1..n - 1
        if numbers[n - i] < numbers[n - i - 1]
            numbers[n - i], numbers[n - i - 1] = numbers[n - i - 1], numbers[n - i]
            swapFlg = true
            count += 1
        end
    end
end
puts numbers.join(" ")
puts count


Measured memory_bytes: 6876
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int x,y,z,a;
    double f;
    cin >> x >> y;
    
    z=x/y;
    a=x%y;
    f=(double)x/y;
    
    cout<< z << endl << a << endl;
    
    cout.precision(5);
    cout << fixed << f << endl;;
}


Measured memory_bytes: 3264
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n,0);
    for (int i = 0 ;i < n;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    
    cout << v[n/2]-v[n/2-1] << endl;
    
}



Measured memory_bytes: 640
s = list(input())
for i in range(len(s) - 1):
    v = s[i]
    if s[i + 1] == v:
        print(i + 1, i + 2)
        exit()
    if i + 2 < len(s) and s[i + 2] == v:
        print(i + 1, i + 3)
        exit()
print(-1, -1)


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,co=0,cou=0,minN=mod;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N>>M;
  N%M>0?cout<<N/M+1<<endl:cout<<N/M<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    rep(i,0,n) cin >> a[i];
    int j=0;
    rep(i,1,n) if(a[i]>a[j]) j=i;
    int best=a[j];
    int k=j;
    rep(i,0,n) if(i!=j) {
        int x=abs(2*a[i]-a[j]);
        if(x<=best) {
            k=i;
            best=x;
        }
    }
    assert(k!=j);
    cout<<a[j]<<" "<<a[k]<<"\n";
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);

  vector<int> GCD1(N);
  vector<int> GCD2(N);
  GCD1.at(0) = A.at(0);
  GCD2.at(N - 1) = A.at(N - 1);

  for (int i = 1; i < N; i++) {
    GCD1.at(i) = __gcd(GCD1.at(i - 1), A.at(i));
  }

  for (int i = N - 2; i >= 0; i--) {
    GCD2.at(i) = __gcd(GCD2.at(i + 1), A.at(i));
  }

  int ans = max(GCD1.at(N - 2), GCD2.at(1));
  for (int i = 1; i <= N - 2; i++) {
    int x = __gcd(GCD1.at(i - 1), GCD2.at(i + 1));
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function Main(_: NormalInput) {
  const [N,K]=[_.int(),_.int()]
  const S=_.str();
  
  console.log(S.substring(0,K-1)+S[K-1].toLowerCase()+S.substring(K,S.length));
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string ss;
    uint32_t qq;
    uint32_t buf;
    cin >> ss;
    cin >> qq;
    vector<uint32_t> query(qq, 0);
    vector<string> querychar(qq);
    string top_ssbuf;
    string bot_ssbuf;
    bool is_rv = 0;

    for(int i = 0; i < qq; i++){
        cin >> buf;
        //cout << "bufd is " << buf << endl;
        if(buf == 1){
            query[i] = 1;
        }else if(buf == 2){
            cin >> buf;
            if(buf == 1){
                query[i] = 3;
                cin >> querychar[i];
            }else if(buf == 2){
                query[i] = 4;
                cin >> querychar[i];
            }
        }
    }

    for(int i = 0; i < qq; i++){
        if(query[i] == 1){
            is_rv = !is_rv;
            //reverse(ss.begin(), ss.end());
        }else if(query[i] == 3){
            if(!is_rv){
                top_ssbuf.insert(0, querychar[i]);
            }else{
                bot_ssbuf.append(querychar[i]);
            }
        }else if(query[i] == 4){
            if(!is_rv){
                bot_ssbuf.append(querychar[i]);
            }else{
                top_ssbuf.insert(0, querychar[i]);
            }
        }
        //cout << i << " ss is " << ss << endl;
    }
    ss.insert(0, top_ssbuf);
    ss.append(bot_ssbuf);

    if(is_rv){
        reverse(ss.begin(), ss.end());
        }
    cout << ss << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

template <typename T> T gcd(T a, T b) {
  while (b > 0) {
    T r = a % b;
    a = b;
    b = r;
  }

  return a;
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll toA = (a - 1) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d));
  ll toB = b - (b / c + b / d - b / lcm(c, d));
  cout << toB - toA << endl;
}


Measured memory_bytes: 256
import sys
import collections

input = sys.stdin.readline
MOD = 998244353

def main():
    N = int(input())
    D = list(map(int, input().split()))

    if D[0] != 0:
        print(0)
        return
    
    D.sort()
    Dmax = max(D)
    Ditems = collections.Counter(D).items()
    Dcount = list(zip(*Ditems))

    Dset = set(Dcount[0])
    if Dset != set(range(Dmax+1)):
        print(0)
        return

    if Dcount[1][0] != 1:
        print(0)
        return

    ans = 1
    for i in range(2, Dmax+1):
        ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD)
        ans %= MOD

    print(ans%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 30620
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, x = 0, y = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'I') {x++;}
    else {x--;}
    y = max(y, x);
  }
  cout << y << endl;
}

Measured memory_bytes: 3572
w = input().lower()
S = []

while True:
    s = input()
    
    if s == 'END_OF_TEXT':
        break
    else:
        S.extend([s_.lower() for s_ in s.split()])
        
count = 0
for s in S:
    if w == s:
        count += 1
        
print(count)


Measured memory_bytes: 5568
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n, m;
	cin >> n >> m;
	if(n==1 && m==1)
		cout << 1 << endl;
	else if(n==1)
		cout << m-2 << endl;
	else if(m==1)
		cout << n-2 << endl;
	else
		cout << ll(n-2)*(m-2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define N 110000
inline char gc(){
	static char now[1<<16],*T,*S;
	if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
	return *S++;
}
inline int read(){
	int x=0;char ch=gc();
	while (ch<'0'||ch>'9') ch=gc();
	while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
	return x;
}
int n,a[N],ans[N],differ[N];
int main(){
	//freopen("box.in","r",stdin);
	n=read();long long sum=0;long long sum1=0;
	if (n==1){printf("YES");return 0;}
	sum1=(long long)n*(n+1)>>1;
	for (int i=1;i<=n;++i) a[i]=read(),sum+=a[i];a[n+1]=a[1];
	for (int i=1;i<=n;++i) differ[i]=a[i+1]-a[i];int k=sum/sum1;
	if (sum%sum1){printf("NO");return 0;}
	for (int i=1;i<=n;++i){
		double x=(differ[i]-k)/(-1.0*n);
		if (x<0){printf("NO");return 0;}
		int xx=x;if (xx!=x){printf("NO");return 0;}
		ans[i]=x;
	}int ans1=0;
	for (int i=1;i<=n;++i) ans1+=ans[i];
	if (ans1==k) printf("YES");else printf("NO");
	return 0;
}

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

int main(){
    string N;
    cin >> N;
    string ans;
    if(N[0] != '7' and N[1] != '7' and N[2] != '7'){
        ans = "No";
    }
    else{
        ans = "Yes";
    }

    cout << ans << endl;
}

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

int main() {
  int n, q;
  cin >> n;
  int A[n+1];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }
  int total = 0;
  for (int j = 0; j < q; j++) {
    A[n] = T[j];
    int i = 0;
    while(A[i] != T[j]) i++;
    if (i != n) total++;
  }
  cout << total << endl;
  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

int chkPerm(int a[],int n,int h[],int counter){
	int pos=1;
	for(int i=0;i<n;i++){
		if(a[i]!=h[i])
			pos=0;
	}
	if(pos){
		return counter;
	}
	else{
		for(int i=n-2;i>=0;i--){
			if(h[i]<h[i+1]){
				int ind;
				for(int j=i+1;j<n;j++){
					if(h[i]<h[j]){
						ind = j;
					}
					else{
						break;
					}
				}
				int swap=h[i];
				h[i]=h[ind];
				h[ind]=swap;
				sort(h+i+1,h+n);
				break;
			}
		}
		return chkPerm(a,n,h,counter+1);
	}
}

void solve(){
	int n;
	cin>>n;
	int p[n];
	int q[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=0;i<n;i++){
		cin>>q[i];
	}
	int h[n];
	for(int i=1;i<=n;i++){
		h[i-1]=i;	
	}
	int cp=chkPerm(p,n,h,1);
	sort(h,h+n);
	int cq=chkPerm(q,n,h,1);
	cout<<abs(cp-cq)<<ln;
}

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

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	ll N;
	cin >> N;
	string S;
	cin >> S;

	ll ans = N;
	for(int i=1; i<N; i++) {
		if (S[i-1] == S[i]) {
			ans--;
		}
	}

	cout << ans << endl;

}


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

using namespace std;

int a[2005];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1 ; i <= n ; ++ i)
	 scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int Ans = 0;
	if (n < 3)
	 puts("0");
	else
	 {
	 	for (int i = n ; i > 1 ; -- i)
	 	 {
	 	 	int l = 0, r = i - 1;
	 	 	while (l < r)
	 	 	 if (a[l] + a[r] > a[i])
	 	 	  Ans += r - l, -- r;
	 	 	 else
	 	 	  ++ l;
	 	 }
	 }
	 cout << Ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;double x,e=0;string s;cin>>N;
  for(int i=0;i<N;i++){
    cin>>x>>s;
    if(s=="JPY")e+=x;
    else e+=380000*x;
  }
  cout<<e<<endl;
}

Measured memory_bytes: 256
while True:
    try:
        (a,b,c,d,e,f)=map(float,raw_input().split())
        x=(f-c*e/b)/(d-a*e/b)
        y=(c-a*x)/b
        if abs(x)<1e-3:
            x=0
        if abs(y)<1e-3:
            y=0
        print "%.3f %.3f" % (x,y)
    except EOFError: break

Measured memory_bytes: 4244
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
  init();
  ll A,B,C,D;cin>>A>>B>>C>>D;
  if(A+B<C+D)cout<<"Right"<<endl;
  else if(A+B==C+D)cout<<"Balanced"<<endl;
  else cout<<"Left"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  int N, K;
  cin >> N >> K;
  vector<bool> v(N+1);
  for (int i = 0; i < K; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      cin >> a;
      v[a] = true;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (!v[i]) ans += 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3580
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<queue>

struct Cake {
	long long value[3], sum;
};
Cake cake[1000];
int n, m;

long long calc_max(const int[3]);

int main()
{
	long long max{};
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
			scanf("%lld", cake[i].value + j);
	}

	int arr[3]{};
	for (int i = 0; i < 2; i++)
	{
		arr[0] = -1 + i * 2;
		for (int j = 0; j < 2; j++)
		{
			arr[1] = -1 + j * 2;
			for (int k = 0; k < 2; k++)
			{
				arr[2] = -1 + k * 2;
				long long tmp = calc_max(arr);
				if (tmp > max) max = tmp;
			}
		}
	}

	printf("%lld\n", max);

	return 0;
}

long long calc_max(const int arr[3])
{
	for (int i = 0; i < n; i++)
	{
		cake[i].sum = 0;
		for (int j = 0; j < 3; j++)
		{
			cake[i].sum += arr[j] * cake[i].value[j];
		}
	}
	std::sort(cake, cake + n,
		[](const Cake& a, const Cake& b) { return a.sum > b.sum; });
	long long ret{};
	for (int i = 0; i < m; i++)
	{
		ret += cake[i].sum;
	}
	return ret;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int k, x;
	cin >> k >> x;
	for(int i=x-k+1;i<=x+k-1;i++)
		cout << i << " ";
	cout << endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const int GCM(const int a, const int b)
{
    if (b == 0)
    {
        return a;
    }
    return GCM(b, a % b);
}

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> cities(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> cities[i];
    }
    vector<int> distances(N);
    for (int i = 0; i < N; ++i)
    {
        distances[i] = abs(cities[i] - X);
    }
    int gcm = distances.front();
    for (int i = 1; i < N; ++i)
    {
        gcm = GCM(gcm, distances[i]);
    }
    cout << gcm << endl;
}


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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B ;
  R = C + D ;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  
  else if (L == R){
    cout << "Balanced" << endl;
  }
  
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 380
import math
a, b, x = map(int, input().split())

max_val = a*a*b
if  2 * x > max_val:
    ans = math.degrees(math.atan(2 * (max_val-x) / (a**3) ))
else:
    ans = 90.0 - math.degrees(math.atan(2*x / (a*b*b) ))
print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().rstrip()


alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

ans = []
for x in S:
    i = alphabet.index(x)
    if i + N >= 26:
        ans.append(alphabet[i+N-26])
    else:
        ans.append(alphabet[i+N])

print(*ans, sep='')


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin>>n;
  ll count=0;
  for(ll i=1;i<n;i++){
    ll num=n/i;
    if(n%i==0){
      num--;
    }
    count+=num;
  }
  print(count);
}


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

#define MOD 998244353
// #define INF 100000000000

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int H, W, N;
    cin >> H >> W >> N;
    int s_r, s_c;
    cin >> s_r >> s_c;
    string S, T;
    cin >> S >> T;

    int pos;

    pos = s_c;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'L') {
            if (pos == 1) {
                cout << "NO" << endl;
                return 0;
            } else {
                pos -= 1;
            }
        }
        if (T[i] == 'R' && pos < W) {
            pos += 1;
        }
    }

    pos = s_c;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') {
            if (pos == W) {
                cout << "NO" << endl;
                return 0;
            } else {
                pos += 1;
            }
        }
        if (T[i] == 'L' && pos > 1) {
            pos -= 1;
        }
    }

    pos = s_r;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'U') {
            if (pos == 1) {
                cout << "NO" << endl;
                return 0;
            } else {
                pos -= 1;
            }
        }
        if (T[i] == 'D' && pos < H) {
            pos += 1;
        }
    }

    pos = s_r;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'D') {
            if (pos == H) {
                cout << "NO" << endl;
                return 0;
            } else {
                pos += 1;
            }
        }
        if (T[i] == 'U' && pos > 1) {
            pos -= 1;
        }
    }

    cout << "YES" << endl;

    return 0;
}


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

int main(){
	int N;
	cin >> N;
	int A[N+2];
	A[0] = 0;
	A[N+1] = 0;
	int tot = 0;
	rep(i,N) {
		cin >> A[i+1];
		tot += abs(A[i+1] - A[i]);
	}
	tot += abs(A[N]);

	for (int i = 1; i <= N; i++) {
		int p = tot - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]);
		p += abs(A[i+1] - A[i-1]);
		cout << p << endl;
	}

	return 0;
}


Measured memory_bytes: 4000
'use strict';
(function(stdin) {

  var inputs  = stdin.toString().trim().split('\n');
  var line = inputs.map(Number);
  var end = line.indexOf(0);
  
  for(var i = 0; i < end; i++){
    console.log('Case ' + (i + 1) + ': '+line[i]);
  }
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 20560
n, s0, s1, g0, g1 = gets.split.map(&:to_i)
s = gets.chomp

if s[s0,g0-s0].index("##") || s[s1,g1-s1].index("##")
  
  puts "No"
  exit
end

if g0 > g1 && ! s[s1-2, g1-s1+3].index("...")
  puts "No"
  exit
end

puts "Yes"

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

struct box{
    ll w,s,v;
};

bool cmp(box &A,box &B)
{
    return (A.w+A.s)<(B.w+B.s);
}
ll dp[1000][20001];
void solve()
{
    ll n;
    cin >> n;
    vector<box> boxs(n);
    for(int i=0;i<n;i++)
    {
        cin >> boxs[i].w >> boxs[i].s >> boxs[i].v;
    }
    sort(boxs.begin(),boxs.end(),cmp);
    memset(dp,0,sizeof dp);
     //cout << "c0 " << endl;
    //base case
    for(int i=0;i<20001;i++)
    {
        if(boxs[0].w<=i)
        dp[0][i]=boxs[0].v;
    }
    //cout << "c1 " << endl;
    // fill the dp
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<20001;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(boxs[i].w<=j)
            {
                dp[i][j]=max(dp[i][j],boxs[i].v+dp[i-1][min(boxs[i].s,j-boxs[i].w)]);
            }
        }
    }
     //cout << "c2 " << endl;
    ll ans=0;
    for(int i=0;i<20001;i++)
    ans=max(ans,dp[n-1][i]);
     //cout << "c3 " << endl;
    cout << ans << endl;

}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 156544
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 2000, M = 2000, MD = 1000000007;

int aa[N], bb[M], dp[N + 1][M + 1];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	for (int j = 0; j < m; j++)
		cin >> bb[j];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
			if (i == 0 && j == 0)
				dp[i][j] = 1;
			else {
				int x = 0;
				if (i > 0)
					x = (x + dp[i - 1][j]) % MD;
				if (j > 0)
					x = (x + dp[i][j - 1]) % MD;
				if (i > 0 && j > 0 && aa[i - 1] != bb[j - 1])
					x = (x - dp[i - 1][j - 1]) % MD;
				dp[i][j] = x;
			}
	int ans = dp[n][m];
	if (ans < 0)
		ans += MD;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 19248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int P[200010];
int idx[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    idx[P[i]] = i;
  }
  int l = 1, r = 1;
  int ans = N;
  while (l <= N) {
    while (r+1 <= N && idx[r] <= idx[r+1]) r++;
    ans = min(ans, N - (r - l + 1));
    l = ++r;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    L = int(buflist[1])
    apple = []
    for i in range(N):
        apple.append(L+i)
    nearest = int(1e9)+7
    for i in range(N):
        if abs(apple[i]) < abs(nearest):
            nearest = apple[i]
    print(sum(apple) - nearest)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[1010][1010];
bool ok[1010];
int line[1010];
signed main(){

    int n;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n-1; j++)
        {
            cin>>a[i][j];
            a[i][j];
        }
        
    }
    int ans=0;
    int kou=-1;
    bool flag=false;
    int cnt=0;
   for (int i = 0; i <= n*(n-1)/2; i++)
   {
       flag=false;
       cnt=0;
       for (int j = 0; j < n; j++)
       {
           if(line[j]==n-1) {
               cnt++;
               continue; 
           }
           int x=a[j][line[j]];//2
           if(line[x-1]==n-1 ) continue;
           if(j+1 == a[x-1][line[x-1]] && !ok[j] &&!ok[x-1] ){
               //ok[j][line[j]]=true;
               //ok[a[j][line[j]]][line[a[j][line[j]]]]=true;
               ok[j]=ok[x-1]=true;
               line[j]++;
               line[x-1]++;
               flag=true;
           }   
           }
           if(!flag){
               if(cnt==n){ 
                   cout<<ans<<endl;
                    return 0;
               }
               else{
                   cout<<-1<<endl;
                   return 0;
               }
           }
           ans++;
           for (int i = 0; i < n; i++)
           {
               ok[i]=false;
            //   cerr<<line[i]<<" ";
           }
         //  cerr<<endl;
          // cerr<<cnt<<endl;
           
       }
      // cout<<ans<<endl;
   
   
    
    
   
    return 0;
}

Measured memory_bytes: 8192
N,A,B = map(int, input().split())
*X,   = map(int, input().split())

ans = 0
for i in range(N-1):
    if abs(X[i]-X[i+1])*A<B:
        ans = ans + abs(X[i]-X[i+1])*A
    else:
        ans = ans + B

print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
int main(){
    int n,a[10000],bot,ans=0,temp;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        bot=i;
        for(int j=i+1;j<n;j++)
            if(a[j]<a[bot])bot=j;
        if(bot!=i){
            ans++;
            temp=a[bot];
            a[bot]=a[i];
            a[i]=temp;
        }
        
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++)printf(" %d",a[i]);
    printf("\n%d\n",ans);
}

Measured memory_bytes: 2768
// AtCoder Beginner Contest 167 - Problem F: Bracketing Sequencing (https://atcoder.jp/contests/abc167/tasks/abc167_f)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

string solve(int N, const vector<string>& xs)
{
    vector<int> cs;
    vector<ii> ds, es;

    int open = 0, close = 0;

    for (int i = 0; i < N; ++i)
    {
        int a = 0, b = 0;

        for (auto c : xs[i])
        {
            open += (c == '(' ? 1 : 0);
            close += (c == ')' ? 1 : 0);

            b += (c == '(' ? 1 : -1);

            if (b < 0)
            {
                a--;
                b = 0;
            }
        }

        if (b + a >= 0)
            ds.push_back(ii(-a, i));
        else
            es.push_back(ii(b, i));
    }

    if (open != close)
        return "No";

    sort(ds.begin(), ds.end());
    sort(es.begin(), es.end(), greater<ii>());

    int s = 0;

    for (auto p : ds)
    {
        auto i = p.second;

        for (auto c : xs[i])
        {
            s += (c == '(' ? 1 : -1);

            if (s < 0)
                return "No";
        }
    }

    for (auto p : es)
    {
        auto i = p.second;

        for (auto c : xs[i])
        {
            s += (c == '(' ? 1 : -1);

            if (s < 0)
                return "No";
        }
    }


    return "Yes";
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<string> xs(N);

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

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


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

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n, 0) { }
  T sum(int i, int j) {//両端を含む
    if (i == 0) {
      T S = 0;
      for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
      return S;
    } else return sum(0, j) - sum(0, i-1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k+1) x[k] += a;
  }
};

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main(void) {
  int Q;
  cin >> Q;
  int n = 1e5 + 1;
  vector<int> primes = sieve_of_eratosthenes(n);
  fenwick_tree<int> ft(n);
  for (int i = 0; i < n; i++) {
    if (primes[i] && primes[(i + 1) / 2]) {
      ft.add(i, 1);
    }
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << ft.sum(l, r) << endl;
  }


  
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a,i,j,ans=0,odd=0;
	while(cin>>a)
	{
		ans=0;
		for(j=1;j<=a;)
		{
			odd=0;
			for(i=1;i<=j;i++)
			{
				if(j%i==0)
				{
					odd++;
				}
			}
			if(odd==8)
			{
				ans++;
			}
			j=j+2;
		}
		cout<<ans<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
		
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int x[]=new int[n];
		for (int i = 0; i < n; i++) {
			x[i]=sc.nextInt();
		}
		int o=0;
		if(l_max(x)<0) {
			o=n;
		}else if(x[0]>0){
			o=0;
			
		}else {	
			while(x[o]<0) {
				o++;
			}
		}	
		int ans=1000000000;
		int ans1;
		int ans2;
		for(int i=0;i<=n-k;i++) {
			if(i<=o+1&&o-1<=i+k-1) {
				ans1=Math.abs(x[i])+x[i+k-1]-x[i];
				ans2=Math.abs(x[i+k-1])+x[i+k-1]-x[i];
				ans=Math.min(ans,ans2);
				ans=Math.min(ans,ans1);
			}	
		}
		
		System.out.println(ans);
	
	
	
	}

	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}


Measured memory_bytes: 36396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int a[4], e, f;
bool s[31][3001];
int n;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    FFOR(i, 0, 4) read(a[i]);
    read(e);
    read(f);
    s[0][0]=1;
    FOR(i, 0, f/100) FFOR(j, 0, f){
        if(!s[i][j]) continue;
        FOR(k, 0, 1) if(i*100+j+a[k]*100<=f) s[i+a[k]][j]=1;
        FOR(k, 2, 3) if(i*100+j+a[k]<=f) s[i][j+a[k]]=1;
    }
    int res1=-1, res2=-1;
    FOR(i, 1, f/100) FOR(j, 0, f) if(s[i][j]){
        if(j<=e*i){
            if(res1==-1){
                res1=i*100+j;
                res2=j;
            }
            else{
                if(res2*(i*100+j)<j*res1){
                    res1=i*100+j;
                    res2=j;
                }
            }
        }
    }
    printf("%d %d\n", res1, res2);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		for(int i = 0; i < num.length; i++) {
			String line = sc.next();
			num[i] = Integer.parseInt(line);
		}

		int count = 0;
		for(int i = 1; i < num.length - 1 ; i++) {
			if(num[i-1] < num[i] && num[i] < num[i+1]) {
				count++;
			}else if(num[i-1] > num[i] && num[i] > num[i+1]) {
				count++;
			}
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 35720