akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int main(){
  int h,w,k;cin >> h >> w >> k;
  vector<vector<int>> dp(h+1,vector<int>(w,0));
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<1<<(w-1);k++){
        bool f=true;
        for(int l=0;l<w-2;l++){
          if((k>>l)&1&&(k>>(l+1))&1){
            f=false;
          }
        }
        if(f){
          if(j>=1&&(k>>(j-1))&1){
            dp[i+1][j-1]+=dp[i][j];
            dp[i+1][j-1]%=mod;
          }
          else if(j<=w-2&&(k>>j)&1){
            dp[i+1][j+1]+=dp[i][j];
            dp[i+1][j+1]%=mod;
          }
          else{
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=mod;
          }
        }
      }
    }
  }
  cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(
					new InputStreamReader(System.in));
			// 入力ストリームの生成
			while(true){
			// 無限ループ
				String ans = br.readLine();
				// 入力文字を出力
				StringTokenizer stk = new StringTokenizer(ans," ");
				// 入力文字ansを” ”で区切ってstへ代入
				int a = Integer.parseInt(stk.nextToken());
				// ” ”で区切られた文字をint型に変換してaに代入
				String op = stk.nextToken();
				// ” ”で区切られた文字（符号）をopに代入
				int b = Integer.parseInt(stk.nextToken());
				// ” ”で区切られた文字をint型に変換してbに代入

				if(op.equals("?")) break;
				// opが”?”と等しい場合、処理を抜ける
				if(0 <= a && a<=20000
					&& 0 <= b && b<=20000){
				// aが0以上20000以下かつbが0以上20000以下
					if(op.equals("+")){
					// opが”+”の場合、下記出力して処理を抜ける
						System.out.printf("%d\n",a+b);
					}else if(op.equals("-")){
					// opが”-”の場合、下記出力して処理を抜ける
						System.out.printf("%d\n",a-b);
					}else if(op.equals("*")){
					// opが”*”の場合、下記出力して処理を抜ける
						System.out.printf("%d\n",a*b);
					}else if(op.equals("/")){
					// opが”/”の場合、下記出力して処理を抜ける
						System.out.printf("%d\n",a/b);
					}
				}
			}
		} catch(IOException e) {
			System.err.println(e);
		}
	}
}

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

int main(){
    int n,m;
    cin>>n;
    int t[n];
    for(int i=0;i<n;i++)cin>>t[i];
    cin>>m;
    int p,x;
    for(int i=0;i<m;i++){
        cin>>p>>x;
        int ans=0;
        for(int i=0;i<n;i++){
            if(i!=p-1)ans+=t[i];
            else ans+=x;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-

n = int(input())

n_100 = n // 100
n_10 = (n - n_100 * 100) // 10
n_1 = (n - n_100 * 100 - n_10 * 10)

if(n_100 == 9):
    n100 = 1
else:
    n100 = 9
if(n_10 == 9):
    n10 = 1
else:
    n10 = 9
if(n_1 == 9):
    n1 = 1
else:
    n1 = 9

print(n100*100 + n10*10 + n1)

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

int dp[200][5][5];

int main()
{
  int n,k,a,b[108]={},ans=0;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    cin>>a;
    cin>>b[a];
  }
  if(b[1]==0){
    for(int j=1;j<=3;j++){
      dp[2][j][0]=1;
    }
  }else {
    dp[2][b[1]][0]=1;
  }
  for(int i=3;i<=n+1;i++){                 //?????\?????\??°
    for(int j=0;j<=3;j++){              //?????\???????????????????¨????
      for(int k=0;k<=3;k++){            //?????\???????????????????¨????
        if(dp[i-1][j][k]!=0){           //??¨??\????????????????£??????????
          if(b[i-1]!=0){                  //?????\????????????????±??????£????????????
            if(!(j==k && b[i-1]==j)){     //?????\??£?¶????????????????
              dp[i][b[i-1]][j]+=dp[i-1][j][k];
              dp[i][b[i-1]][j]%=10000;
            }
          }else{                        //?????\????????????????±??????£???????????´???
            for(int l=1;l<=3;l++){
              if(!(j==k && l==j)){      //?????\??£?¶????????????????
                dp[i][l][j]+=dp[i-1][j][k];
                dp[i][l][j]%=10000;
              }
            }
          }
        }
      }
    }
  }
  for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
      ans+=dp[n+1][i][j];
      ans%=10000;
    }
  }
  ans%=10000;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1172
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int x, n;
	cin >> x >> n;
	vector<bool> p(400, false);
	REP(i, n)
	{
		int tmp;
		cin >> tmp;
		p[tmp + 200] = true;
	}
	int mi = INF;
	int ans = -INF;
	REP(i, 400)
	{
		if (p[i])continue;

		if (abs(x - (i-200)) < mi)
		{
			mi = abs(x - (i-200));
			ans = i - 200;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int m, n; std::cin >> m >> n;
	std::vector<long long int> weights(m + 1, 0), thicks(m + 1, 0);
	for (auto i = 1; i <= m; ++i) std::cin >> weights[i] >> thicks[i];
	for (auto i = 1; i <= m; ++i) {
		weights[i] += weights[i - 1];
		thicks[i] += thicks[i - 1];
	}
	std::vector<long long int> max_weight(n), max_thick(n);
	for (auto i = 0; i < n; ++i) std::cin >> max_weight[i] >> max_thick[i];
	std::vector<int> max_size(1 << n, 0);
	for (auto p = 0; p < (1 << n); ++p) {
		const int current = max_size[p];
		for (auto i = 0; i < n; ++i) if ((p & (1 << i)) == 0) {
			const int next_with_weight = (current == m) ? current : std::distance(weights.begin(), std::upper_bound(std::next(weights.begin(), current), weights.end(), weights[current] + max_weight[i])) - 1;
			const int next_with_thick = (current == m) ? current : std::distance(thicks.begin(), std::upper_bound(std::next(thicks.begin(), current), thicks.end(), thicks[current] + max_thick[i])) - 1;
			max_size[p | (1 << i)] = std::max(max_size[p | (1 << i)], std::min(next_with_weight, next_with_thick));
		}
	}
	std::cout << max_size.back() << '\n';
}



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

public static class Program
{
  public static void Main(string[] args)
  {
    do
    {
      string inputLine = Console.ReadLine();
      if(inputLine == null)
      {
        break;
      }

      List<int>[] graph = new List<int>[100];
      for(int i = 0;i < 100; i++)
      {
        graph[i] = new List<int>();
      }

      var inputs = inputLine.Split(' ').Select(a => int.Parse(a)).ToArray();
      do
      {
        graph[inputs[0]].Add(inputs[1]);
        graph[inputs[1]].Add(inputs[0]);
        inputs = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
      }
      while(inputs[0] != 0);

      bool canPatrol = (graph[1].Count % 2 == 1) && (graph[2].Count % 2 == 1);
      if(canPatrol)
      {
        for(int i = 3;i < 100; i++)
        {
          if(graph[i].Count % 2 == 1)
          {
            canPatrol = false;
            break;
          }
        }
      }

      var answer = canPatrol ? "OK" : "NG";
      Console.WriteLine(answer);
    }    
    while(true);
  }
}



Measured memory_bytes: 9620
use std::io::Read;

struct DisjointSet {
    group: Vec<i32>,
}

impl DisjointSet {
    fn new(n: usize) -> DisjointSet {
        let group = vec![-1; n];
        DisjointSet { group: group }
    }

    fn root(&mut self, x: usize) -> usize {
        if self.group[x] < 0 {
            x
        } else {
            let g = self.group[x] as usize;
            self.group[x] = self.root(g) as i32;
            self.group[x] as usize
        }
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let x = self.root(x);
        let y = self.root(y);
        if x == y {
            return false;
        }

        if self.group[y] < self.group[x] {
            return self.unite(y, x);
        }

        self.group[x] += self.group[y];
        self.group[y] = x as i32;
        return true;
    }

    fn size(&mut self, x: usize) -> usize {
        let r = self.root(x);
        -self.group[r] as usize
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let mut a: Vec<usize> = vec![0; m];
    let mut b: Vec<usize> = vec![0; m];

    for i in 0..m {
        a[i] = iter.next().unwrap().parse().unwrap();
        b[i] = iter.next().unwrap().parse().unwrap();
    }
    let mut ds = DisjointSet::new(n);

    let mut ans = vec![0; m];
    let mut inconvenience = n * (n - 1) / 2;

    for i in (0..m).rev() {
        ans[i] = inconvenience;

        let x = a[i] - 1;
        let y = b[i] - 1;
        if ds.root(x) != ds.root(y) {
            inconvenience -= ds.size(x) * ds.size(y);
            ds.unite(x, y);
        }
    }

    for i in 0..m {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 9468
import java.util.*;

public class Main {

    static int[][] dir4 = new int[][]{{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int SH = sc.nextInt()-1;
        int SW = sc.nextInt()-1;
        int S = SH*1000 + SW;
        int GH = sc.nextInt()-1;
        int GW = sc.nextInt()-1;
        boolean[][] g = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            char[] s = sc.next().toCharArray();
            for (int j = 0; j < W; j++) {
                if(s[j] == '.') g[i][j] = true;
            }
        }
        int[][] d = new int[H][W];
        for (int i = 0; i < H; i++) {
            Arrays.fill(d[i], Integer.MAX_VALUE);
        }
        d[SH][SW] = 0;
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.add(S);
        while(!q.isEmpty()){
            int v = q.poll();
            int h = v / 1000;
            int w = v % 1000;
            for(int[] dir : dir4){
                int nh = h + dir[0];
                int nw = w + dir[1];
                if(nh < 0 || H-1 < nh || nw < 0 || W-1 < nw) continue;
                if(!g[nh][nw] || d[nh][nw] <= d[h][w]) continue;
                d[nh][nw] = d[h][w];
                q.addFirst(nh*1000 + nw);
            }
            for (int i = -2; i <= 2; i++) {
                int nh = h + i;
                if(nh < 0 || H-1 < nh) continue;
                for (int j = -2; j <= 2; j++) {
                    int nw = w + j;
                    if(nw < 0 || W-1 < nw) continue;
                    if(!g[nh][nw] || d[nh][nw] <= d[h][w]+1) continue;
                    d[nh][nw] = d[h][w]+1;
                    q.addLast(nh*1000 + nw);
                }
            }
        }
        System.out.println(d[GH][GW] == Integer.MAX_VALUE ? -1 : d[GH][GW]);
        sc.close();

    }

}


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

int main() {
    long long S;
    cin >> S;
    int x0=0, y0=0;
    long long x1,x2,y1,y2;
    x1=1000000000;
    x2=1;
    y2=S/x1+1;
    y1=x1*y2-S;
    if (S==1000000000000000000){
    cout << 0 << " " << 0 << " ";
    cout << x1 << " " << 0 << " ";
    cout << 0 << " " << x1 << endl;
    }else{
    cout << x0 << " " << y0 << " ";
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << endl;
    }
}

Measured memory_bytes: 256
import functools
import itertools
import collections

l = list("ACGT")

@functools.lru_cache(maxsize=None)
def f(d, sl, e):
    if e == d:
        return 1
    else:
        cnt = 0
        for v in l:
            tsl = collections.deque(sl)
            if len(sl) == 4:
                tsl.popleft()
            tsl.append(v)
            ts = "".join(tsl)
            if len(ts) >= 3 and (ts[-3:] == "AGC" or ts[-3:] == "GAC" or ts[-3:] == "ACG"):
                continue
            if len(ts) >= 4 and ts[0] == "A" and ts[2:] == "GC":
                continue
            if len(ts) >= 4 and ts[:2] == "AG" and ts[3] == "C":
                continue
            cnt += f(d + 1, ts, e)
        return cnt


def slove():
    import sys
    input = sys.stdin.readline
    e = int(input().rstrip('\n'))
    sl = []
    print(f(0, "".join(sl), e) % (10 ** 9 + 7))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 91612
#include <bits/stdc++.h>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = n-1; i >= 0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using in = int64_t;
using P=pair<in,in>;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string s,t;

int main(){
    map<string,int> mp;
    int n,m;
    string s;
    cin >> n;
    rep(i,n){
        cin >> s;
        mp[s]++;
    }

    cin >> m;
    rep(i,m){
        cin >> s;
        mp[s]--;
    }

    int ans = 0;
    for(auto p : mp){
        ans = max(ans,p.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// triangles.cpp : This file contains the 'main' function. Program execution begins and ends there.
//how many triangles can we form with the sticks of lengths L (a triangle satisfies :  a < b + c , b < c + a , c = a+b
//by farah on 28/2/2020

#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 2e3;
int L[N] , ans = 0 , n ;
int i = 0 , j = 0;
//bool used[N];
vector<int> v;

bool valid() {
	return v[0] + v[1] > v[2];
}
int BS(int begin ) {
	int right = n - 1 , mid , left = begin ,val = 0;
	while (left <= right) {
		mid = (left + right) / 2;
		v.push_back(L[mid]);
		if (valid()) {
			val = max(mid - begin, val);
			left = mid + 1;
		}
		else
			right = mid - 1;
		
		v.pop_back();

	}
	return val;
}
void solve() {
	for (int i = 0; i < n - 2; ++i) {
		v.push_back(L[i]);
		for (int j = i + 1; j < n - 1 ; j++) {
			v.push_back(L[j]);
			ans+=BS(j);
			v.pop_back();
		}
		v.pop_back();
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> L[i];
	}
	sort(L, L + n);
	solve();
	cout << ans;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll N, x;
ll a[111111];

void print() {
   rep (i, N) {
      printf(" %2d", a[i]);
   }
   puts("");
}

int main() {
   cin >> N >> x;
   rep (i, N) { cin >> a[i]; }

   ll ans = 0;
   for (int i = 1; i < N; i++) {
      ll sum = a[i-1] + a[i];
      if (sum > x) {
         ll diff = sum - x;
         ans += diff;
         if (diff > a[i])  {
            a[i] = 0;
         } else {
            a[i] -= diff;
         }
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 1024
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 0;
        long i = 1;
        while(h>0){
            h /= 2;
            count += i;
            i *=2;
        }
        System.out.println(count);
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<array<int, 2>> P(n);
    for (int i = 0; i < n; i++){
        cin >> P[i][0] >> P[i][1];
    }

    double ans = 0;
    sort(P.begin(), P.end());
    do {
        double d = 0;
        for (int i = 1; i < n; i++)
            d += sqrt(pow(P[i][0] - P[i - 1][0], 2) + pow(P[i][1] - P[i - 1][1], 2));
        ans += d;
    } while(next_permutation(P.begin(), P.end()));

    for (int i = 1; i <= n; i++)
        ans /= i;
    
    cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 256
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  a = input()
  if a.upper() == a:
    print('A')
  else:
    print('a')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 8980
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
char s[SIZE];
int N,A,B,C,D;
bool can_go(int x,int y){
    while(x<y){
        if(s[x+1]!='#')x++;
        else if(s[x+2]!='#')x+=2;
        else break;
    }
    return x==y;
}
int main(){
    R(N,A,B,C,D);
    RS(s+1);
    if(!can_go(A,C)||!can_go(B,D))W("No");
    else if(C<D)W("Yes");
    else{
        FOR(i,B,D){
            if(s[i]!='#'&&s[i-1]!='#'&&s[i+1]!='#'){
                W("Yes");
                return 0;
            }
        }
        W("No");
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans = 999;
  for(int i=0; i <= S.size()-3; i++){
    int aaa = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + S[i+2] - '0';
        ans = min(ans,abs(aaa-753));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define N 10000
ll tra[100006],tra1[100006];

int main()
{
    string s;
    cin>>s;
    ll one=0,zero=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
            one++;
        else
            zero++;
    }
    cout<<(min(one,zero)*2)<<endl;



}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#define mp make_pair
#define pb push_back
#define mst(a,b)  memset((a),(b),sizeof (a))
#define eps 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=1e8;
const int maxn=1e5+100;
const int mod=1e9+7;
ll a[150];
void init(){
    a[0]=2;a[1]=1;
    for(int i=2;i<150;++i)a[i]=a[i-1]+a[i-2];
}
int main() {
#ifdef local
//    freopen("in.txt", "r", stdin);
#endif
    init();
    int n;cin>>n;
    cout<<a[n];
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list(range(1,14))
h=list(range(1,14))
c=list(range(1,14))
d=list(range(1,14))
for _ in range(n):
    x,y=input().split()
    if x=="S":
        s.remove(int(y))
    elif x=="H":
        h.remove(int(y))
    elif x=="C":
        c.remove(int(y))
    elif x=="D":
        d.remove(int(y))
for i in range(len(s)):
    print("S",s[i])
for i in range(len(h)):
    print("H",h[i])
for i in range(len(c)):
    print("C",c[i])
for i in range(len(d)):
    print("D",d[i])


Measured memory_bytes: 5600
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))

int main(void)
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(b%a==0) c=a+b;
	else c=b-a;
	printf("%d\n",c );
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False

for i in range(0, N-M+1):
    for j in range(0, N-M+1):
        sample = []
        for k in range(M):
            sample.append(A[i+k][j:j+M])
        if sample == B:
            flag = True
            break
   
print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
    IOS;
    int n; cin >> n;
    vector<int> v(n+1);
    rep(i,0,n-1){
        int x; cin >> x;
        v[x]++;
    }   
    for(int i = 1;i<=n;i++){
        cout << v[i] << "\n";
    }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

int A, B;

int main() {
    cin >> A;
    cin >> B;
    if (A > 12) {
        cout << B;
    } else if (5 < A and A < 13) {
        cout << B/2;
    } else if ( A < 6 ) {
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in1[100050];
char in2[100050];
int main() {
	scanf("%s %s", in1, in2);
	int L1 = strlen(in1), L2 = strlen(in2);
	sort(in1, in1 + L1);
	sort(in2, in2 + L2);
	reverse(in2, in2 + L2);
	if (string(in1) < string(in2)) printf("Yes\n");
	else printf("No\n");
}

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

#define MOD 1000000007
#define int long long

int n;
vector<vector<int> > tree(1010);
string node[1010];

int dp(int i){
	int ans = 1;
	if(node[i][0] == 'E'){
		for(auto e : tree[i]){
			ans *= dp(e);
			ans %= MOD;
		}
		if(node[i][node[i].size()-1] == '?') ans = (ans + 1) % MOD;
	}else if(node[i][0] == 'A'){
		for(auto e : tree[i]){
			ans += dp(e);
			ans %= MOD;
		}
		if(node[i][node[i].size()-1] != '?') ans = (MOD+ans-1) % MOD;
	}else{
		for(auto e : tree[i]){
			ans *= (dp(e) + 1);
			ans %= MOD;
		}
		if(node[i][node[i].size()-1] != '?') ans = (MOD+ans-1) % MOD;
	}
	return ans;

}


signed main(){
	cin >> n;
	for(int i = 0;i < n;i++) cin >> node[i];
	for(int j = 0;j < n-1;j++){
		int s, t; cin >> s >> t;
		s--, t--;
		tree[s].push_back(t);
	}

	cout << dp(0) << endl;
	return 0;
}

		


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define D double
#define lli long long int
#define testcase int t;cin>>t;while(t--)
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define P pair<int,int>
/*bool isprime(lli n)
{
    if(n==1) return 0;
    for(lli i=2;i<=n/2;i++)
    {
        if(n%i==0) return 0;
    }
    return 1;
}
bool issemiprime(lli n)
{
    for(int i=2;i<n;i++)
    {
        if(isprime(i)&&isprime(n/i)&&n%i==0&&i!=n/i){
            return 1;
        }
    }
    return 0;
}
lli extendedgcd(lli q,lli r1,lli r2,lli r,lli s1,lli s2,lli s,lli t1,lli t2,lli t)
{
if(r2==0) return r1;
	r1=r2;
        r2=r;
        s1=s2;
        s2=s;
        t1=t2;
        t2=t;
        q=r1/r2;
        r=r1%r2;
        s=s1-(s2*q);
        t=t1-(t2*q);
return extendedgcd(q,r1,r2,r,s1,s2,s,t1,t2,t);
}
lli gcd(lli a,lli b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
void SOE()
{
    for(lli i=2;i<=100000;i++)
    {
        if(sieve[i]) continue;
        for(lli x=i;x<=100000;x+=i)
        {
            sieve[x]+=1;
        }
    }
}*/
/*bool func(pair<int,int> a,pair<int,int> b)
{
    return a.first<b.first;
}
int dfs(vector<vector<int>> g,int n)
{
    if(g[n].size()==0) return 0;
    if(dp[n]!=-1) return dp[n];
    for(auto x:g[n])
    {
        dp[n]=max(dp[n],1+dfs(g,x));
    }
    return dp[n];
}*/
void solve()
{
    int n,k;
    cin>>n>>k;
    bool dp[k+1];
    memset(dp,false,sizeof(dp));
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        s.insert(a);
    }
    dp[0]=false;
    for(int i=1;i<k+1;i++)
    {
        for(auto x:s)
        {
            if((i-x)<0){
                break;
            }
            if((dp[i-x]==false))
            {
                dp[i]=true;
                break;
            }
        }
    }
    if(dp[k]==true) cout<<"First";
    else cout<<"Second";

}
int main()
{
    fast_io;
    solve();
}


Measured memory_bytes: 3764
def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

def solve(n, pos):
    x,y = pos
    if x > n // 2:
        x = n - x + 1
    if y > n // 2:
        y = n - y + 1

    if x == y:
        color = ( (x-1) % 3 ) + 1
    else:
        definitive = min(x,y)
        color = ((definitive - 1) % 3) + 1
    return color

n = getN()
k = getN()

for i in range(k):
    pos = getlist()
    print(solve(n, pos))


Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long 
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
using namespace std;

ll f(vl x,ll p){
    ll ret = 0;
    for(int i=0;i<x.size();++i) ret += (p-x[i])*(p-x[i]);
    return ret;
}

int main(void){
    ll n; cin>>n;
    vl x(n);
    for(int i=0;i<n;++i) cin>>x[i];
    sort(x.begin(),x.end());
    ll ans = f(x,x[0]);
    for(int i=x[0];i<=x[n-1];++i) ans = min(ans,f(x,i));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;
#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int a[N];
  REP(i, N) cin >> a[i];
  auto f = vector<vector<int>>(H, vector<int>(W));
  int cnt = 0;
  REP(i, N) {
    REP(j, a[i]) {
      int h = cnt / W;
      int w = cnt % W;
      cnt++;
      if(h % 2 == 0) {
        f[h][w] = i + 1;
      } else {
        f[h][W - w - 1] = i + 1;
      }
    }
  }
  REP(i, H) {
    REP(j, W) { cout << f[i][j] << " "; }
    cout << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<set>
#include<map> 
using namespace std;

const int mod=1e9+7;
const int N=1e5+10;
long long ans;
int n,k,w[N],first[N],to[2*N],nxt[2*N],tot,sum,num[N];
bool vis[N];
queue<int> q; 

void create(int x,int y)
{
	tot++;
	nxt[tot]=first[x];
	first[x]=tot;
	to[tot]=y;
}

void dfs(int u)
{
	for(int e=first[u];e;e=nxt[e])
	{
		int v=to[e];
		if(vis[v]==true) sum++;
		else q.push(v);
		sum+=num[v];
		num[v]++;
	}
}

int main()
{
	//freopen("lx.in","r",stdin);
	
	int x,y;
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		create(x,y);
		create(y,x);
		w[i]=k;
	}
	w[n]=k;
	q.push(1); vis[1]=true;ans=1;
	while(!q.empty())
	{
		sum=0;
		int z=q.front();q.pop();
		dfs(z);
		w[z]=w[z]-sum;
		vis[z]=true;
		if(w[z]==0)
		{
			ans=0;
			break;
		}
		ans=(ans*w[z])%mod;
	}

	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 6784
#include <stdio.h>

#define MAX_N 20

int main() {
        int i;
        int N;
        int H[MAX_N] = { 0 };
        int cnt;

        scanf("%d", &N);

        for (i = 0; i < N; i++) scanf("%d", &H[i]);

        for (i = 1, cnt = 1; i < N; i++) {
                if (H[i] >= H[i-1]) {
                        cnt++;
                } else {
                        H[i] = H[i-1];
                }
        }

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

        return 0;
}


Measured memory_bytes: 128
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto N = readln.chomp.to!long;
    auto s = readln.chomp.to!(char[]);
    auto DP = new long[][](N, N);
    foreach (i; 0..N) DP[0][i] = 1;
    foreach (i; 1..N) {
        long c;
        if (s[i-1] == '<') {
            foreach_reverse (j; 0..N-i+1) {
                DP[i][j] = c;
                c = (c + DP[i-1][j]) % P;
            }
        } else {
            foreach (j; 0..N-i+1) {
                c = (c + DP[i-1][j]) % P;
                DP[i][j] = c;
            }
        }
    }
    writeln(DP[$-1][0]);
}

Measured memory_bytes: 74364
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if (a>=13) printf("%d\n",b);
	 else if (a<=5) printf("0\n");
	 else printf("%d\n",b/2);
	 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  lli x;
  while (scanf("%lld", &x) != EOF)
  {
    lli curr = 100, ans = 0;
    while (curr < x) curr = curr + (curr / 100), ans++;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3828
import sys


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return len(lower_divisors + upper_divisors[::-1])


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    ans = 0
    for i in range(1, n + 1, 2):
        if make_divisors(i) == 8:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 0, mod = (int) 0;
#define int long long
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int res = 0, mx = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        int use = mx + 1;
        int p = x;
        if (p <= use) {
            mx = max(mx, p);
            continue;
        }
        res += (x - 1) / use;
        mx = max(mx, 1LL);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#https://note.nkmk.me/python-gcd-lcm/
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n,x = map(int,input().split())
a = list(map(int,input().split()))
tmp = []
for i in range(n):
    tmp.append(abs(a[i]-x))
    
print(gcd_list(tmp))

Measured memory_bytes: 20440
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){

	int n;
	cin>>n;
	int tmp;
	bool flag=false;
	fo(i,n){
		cin>>tmp;
		if(tmp%2==0){
			if(tmp%5==0||tmp%3==0) ;
			else {flag=true; break;}
		}


	}
	if(!flag) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;
 
namespace ALDS1_4_B {
    public static class MyExtension {
        public static bool Contains(this int[] nums,int n) {
            int left = 0;
            int right = nums.Length;
            while (left < right) {
                int mid = (left + right) / 2;
                if (n == nums[mid])
                    return true;
                if (n > nums[mid])
                    left = mid + 1;
                else
                    right = mid;
            }
            return false;
        }
    }
 
    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] S = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.ReadLine();
            int[] T = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int count = 0;
            foreach (int t in T) {
                if (S.Contains(t))
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 23040
import random
import time

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]

def decr(tl,cl):
    dec=0
    for i in range(26):
        last=[a for a, x in enumerate(tl) if x==i+1]
        if last==list():
            dec+=(d*(d+1)/2)*cl[i]
        else:
            for v in range(len(last)):
                if v!=len(last)-1:    
                    dec+=cl[i]*(last[v+1]-last[v]-1)*(last[v+1]-last[v])/2
                else:
                    dec+=cl[i]*(d-last[v]-1)*(d-last[v])/2
            dec+=cl[i]*(last[0])*(last[0]+1)/2
    return(int(dec))

oldscore=sat
oldans=oldscore-decr(tl,cl)
oldtl=[int(x) for x in tl]
t2=time.time()
while t2-t1<1.85:
    if round(t2)/2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        tl[d2-1]=q1
        tl[d1-1]=q2
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
        if newans<oldans:
            tl=[int(x) for x in oldtl]
        else:
            oldans=newans
            oldtl=[int(x) for x in tl]
            oldscore=newscore
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        tl[da-1]=q
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
        if newans<oldans:
            tl=[int(x) for x in oldtl]
        else:
            oldans=newans
            oldtl=[int(x) for x in tl]
            oldscore=newscore
    t2=time.time()
for i in range(d):
    print(tl[i])
        


Measured memory_bytes: 88984
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,L=0;cin>>n>>k;
  vector<int> l(n);
  for(int i=0;i<n;i++)cin>>l.at(i);
  sort(l.begin(),l.end());
  for(int j=n-1;j>=n-k;j--)L+=l.at(j);
  cout<<L<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int pos[20005],n,i,x,sum[20005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		pos[x]=i;
	}
	for(i=1;i<=n;i++)sum[i]=pos[i]+sum[i-1];
	for(i=1;i<n;i++)printf("%d ",sum[i]);
	printf("%d\n",sum[n]);
	for(i=1;i<n;i++)printf("%d ",n*(1+n)/2-sum[i-1]);
	printf("%d\n",n*(1+n)/2-sum[n-1]);
	return 0;
} 

Measured memory_bytes: 640
import sys
import collections

n = int(input())
a = sorted([int(i) for i in input().split()])
# print(a)
top = a.pop(-1)

nega = sorted([i for i in a if i < 0])
posi = sorted([i for i in a if i >= 0])
#print(nega,posi)

if len(nega) == 0:
    nega.append(posi.pop(0))

process = []

for _ in range(len(posi)):
    x = nega.pop(0)
    y = posi.pop(0)
    nega.append(x - y)
    process.append([x, y])
x = top
y = nega.pop(0)
process.append([x, y])
x -= y
for _ in range(len(nega)):
    y = nega.pop(0)
    process.append([x, y])
    x -= y
ans = x

print(ans)
for i in range(len(process)):
    print('{} {}'.format(process[i][0], process[i][1]))


Measured memory_bytes: 22624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;
int n;
vector<int> que[200];
map<int,P> dex;

int getEmptyArea(){
  for(int i=1;i<=n;i++){
    if(que[i].size() == 0)return i;
  }
  assert(false);
}

int main(){
 

  while(true){
    cin >> n;
    
    if(n == 0)break;

    dex.clear();
    que[0].clear();
    for(int i=1;i<=n;i++){
      que[i].clear();
      que[i].pb(i);
      dex[i] = P(i,0); //P(場所,番地)
    }


    while(true){//
      int I,J;
      cin >> I >> J;
      
      if(I+J == 0)break;
      if(que[dex[I].F].size() == 0)continue;//とるものがない
      if(dex[I].S == 0 && J == 0)continue;
      if(dex[I].F == dex[J].F && dex[I].S >= dex[J].S)continue;//置く場所が下にある
      
      int pos = que[dex[I].F].size()-1;

      while(que[dex[I].F][pos] != I){
	int emp = getEmptyArea(),val =que[dex[I].F][pos];
	que[dex[I].F].pop_back();
	que[emp].pb(val);
	dex[val] = P(emp,0);
	pos--;
	assert(pos >= -1);
      }

      assert(I == que[dex[I].F][pos]);
      que[dex[I].F].pop_back();
      int emp = getEmptyArea();
      J==0?que[emp].pb(I):que[dex[J].F].pb(I);
      J==0?dex[I] = P(emp,0):dex[I] = P(dex[J].F,que[J].size()-1);
   

    }//
    vector<int> stac;
    for(int i=1;i<=n;i++){
      if(que[i].size() == 0)continue;
      stac.pb(que[i].size());
    }
    sort(all(stac));
    rep(i,stac.size()){
      cout << stac[i] << endl;
    }
    cout << "end" << endl;

  }
return 0;
}

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

using namespace std;
typedef long long Int;
#define INF (1LL<<30)

Int n;
Int a[216000], b[216000];
int main(){
	cin >> n;
	bool allsame = 1;
	Int minbig = INF;
	Int sum = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
		if(a[i] != b[i])allsame = 0;
		if(a[i] > b[i])minbig = min(minbig, b[i]);
		sum += a[i];
	}
	if(allsame)
		cout << 0 << endl;
	else
		cout << sum - minbig << endl;
	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main()
{
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    vector<int> past(n, 0);
    
    for(int i = 0 ; i< n;i++){
        if(i-k >= 0 && t[i-k] == t[i]){

            if(t[i] == 'r'  && past[i-k]==0){ 
                ans += p;
                past[i] = 1;
            }
            else if(t[i] == 'r' && past[i-k] == 1){
                continue;
            }

            if(t[i] == 's'  && past[i-k]==0){ 
                ans += r;
                past[i] = 1;
            }
            else if(t[i] == 's' && past[i-k] == 1){
                continue;
            }

            if(t[i] == 'p'  && past[i-k]==0){ 
                ans += s;
                past[i] = 1;
            }
            else if(t[i] == 'p' && past[i-k] == 1){
                continue;
            }

        }else{
            if(t[i] == 'r'){
                ans += p;
                past[i] = 1;
            }
            if(t[i] == 's'){
                ans += r;
                past[i] = 1;
            }
            if(t[i] == 'p'){
                ans += s;
                past[i] = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t quot = N/(A+B);
  int64_t rem =N%(A+B);

  int64_t ans = quot*A + min(rem,A);

   cout <<  ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,s;
    cin>>k>>s;
    int ans=0;
    for (int i = 0; i <= k; i++){
        for (int j = 0; j <= k; j++){
            if(0<=s-i-j && s-i-j<=k){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int count = 0;
  
  for (int i=0;i<N;i++) {
    if (i<2) {
      continue;
    }
    else if (S.at(i-2)== 'A' &&S.at(i-1)== 'B' &&S.at(i)== 'C') {
      count++;
    }
    else {
    }
  }
  cout << count <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline void chmax(T& a, T b){if(a<b)a=b;}
template<class T> inline void chmin(T& a, T b){if(a>b)a=b;}
const long long INF = 1LL << 60;

int N;
long long a[410];
long long b[410];
long long dp[410][410];
bool ischecked[410][410] = {false}; 

//累積和の保持
long long init(){
  b[0] = a[0];
  for(int i=1;i<N;++i) b[i] = b[i-1] + a[i];
}

//累積和の取り出し
long long get(int L,int R){
   return b[R] - b[L-1];
}
long long rec(int L,int R){
  if(L == R) return 0;
  if(ischecked[L][R]) return dp[L][R];
  ischecked[L][R] = true;
  long long ret = INF;
  for(int i=L;i<R;++i) chmin(ret, rec(L, i) + rec(i + 1, R) + get(L, R));
  return dp[L][R] = ret;
}

int main(){
  cin >> N;
  for(int i=0;i<N;++i) cin >> a[i];
  init();
  
  cout << rec(0,N-1) << endl;
  return 0;
}

Measured memory_bytes: 1792