akhauriyash/Code-Regression huggingface dataset:
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
char s[100111];
int cnt[256];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)cnt[s[i]]++;
	int mx=max(cnt['a'],max(cnt['b'],cnt['c']));
	int mn=min(cnt['a'],min(cnt['b'],cnt['c']));
	if(mx-mn<=1)
	{
		puts("YES");
	}
	else puts("NO");
	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;
int m;

vector<int> a;

void input() {
  cin >> n >> m;

  a.resize(m);
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;

    for (int j = 0; j < k; ++j) {
      int t;
      cin >> t;

      --t;

      a[t]++;
    }
  }
}

void solve() {
  int ans = 0;

  for (auto&& i : a) {
    if (i == n)
      ++ans;
  }

  cout << ans << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
typedef long long int lli;
template <typename T>
void out(vector <T> v){
    for(lli i = 1; i < v.size(); i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

void solve(){
    lli n, x , y;
    cin >> n >> x >> y;
    vector < vector <lli> > v(n, vector <lli>(n));
    x--;
    y--;
    vector <lli> ret(n);
    for(lli i = 0; i < n; i++){
        for(lli j = i + 1; j < n; j++){
            v[i][j] = min(j - i, abs(x - i) + 1 +  abs(y - j));
            ret[v[i][j]]++;
        }
    }
    out(ret);
    
}
int main(){
	#ifdef zanj0
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
    fastio
    lli t;
    
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}



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

 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(a,max(b,c)) - min(a,min(b,c)) << endl;
}

Measured memory_bytes: 256
# directions
x_dir = [0, 1, 0, -1]
y_dir = [1, 0, -1, 0]

# map info
visited = []
maps = []

# bfs algorithm
def bfs(h, w, cheese, sx, sy, moves):
    que = [(moves, sx, sy)]

    for i in range(h):
        for j in range(w):
            visited[i][j] = (maps[i][j] != 'X')

    visited[sy][sx] = False

    while len(que) > 0:
        c_moves, c_x, c_y = que.pop(0)
        if maps[c_y][c_x] == cheese:
            return (c_moves, c_x, c_y)

        for i in range(4):
            n_x = c_x + x_dir[i]
            n_y = c_y + y_dir[i]

            if(0 <= n_x < w and 0 <= n_y < h and visited[n_y][n_x]):
                que.append((c_moves+1, n_x, n_y))
                visited[n_y][n_x] = False

    return (-1, -1, -1)

# main function
if __name__ == '__main__':
    inputs = (input()).split()

    H = int(inputs[0])
    W = int(inputs[1])
    N = int(inputs[2])

    visited = [[True for i in range(W)] for j in range(H)]
    maps = ["" for i in range(H)]

    x, y = 0, 0
    for i in range(H):
        maps[i] = input()
        for j in range(W):
            if maps[i][j] == 'S':
                x, y = j, i

    moves = 0
    for i in range(1, N+1, 1):
        moves, x, y = bfs(H, W, str(i), x, y, moves)

    print(str(moves))

Measured memory_bytes: 19452
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

def main():
    N = cin.int()
    A = cin.intColsList(5)
    M = min(A)
    print(Math.roundUp(N, M) + 4)
    return

if __name__ == "__main__":
    main()


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

int main(){
    int n;
    cin >> n;
    int v[n], c[n];
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    int v_c[n];
    for (int i = 0; i < n; i++) v_c[i] = v[i]-c[i];
    int ans = 0;
    for (int i = 0; i < n; i++){
        if(v_c[i] > 0) ans += v_c[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    ll sum = 1;
    if( A > K ){
        sum += K-1;
        K = 1;
    }else{
        sum += (A-1);
        K   -= (A-1);
    }

    if( (B - A <= 2) || (K==1) ){
        cout<<(sum+K)<<endl;
    }else{
        if(K%2==1) sum++;
        cout<<(sum+(B-A)*(K/2))<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

vector<int> E[200010], F[200010];
bool usedE[200010], usedF[200010];
int cE[200010], cF[200010];
int groupE = 0, groupF = 0;

map<pair<int, int>, int> mp;

void dfsE(int u) {
    cE[u] = groupE;
    usedE[u] = true;
    for (int v : E[u]) {
        if (!usedE[v]) {
            dfsE(v);
        }
    }
}

void dfsF(int u) {
    cF[u] = groupF;
    usedF[u] = true;
    for (int v : F[u]) {
        if (!usedF[v]) {
            dfsF(v);
        }
    }
}

int main() {
    int n, k, l;

    cin >> n >> k >> l;

    int p, q, r, s;

    for (int i = 0; i < k; i++) {
        cin >> p >> q;
        E[p-1].push_back(q-1);
        E[q-1].push_back(p-1);
    }

    for (int i = 0; i < l; i++) {
        cin >> r >> s;
        F[r-1].push_back(s-1);
        F[s-1].push_back(r-1);
    }

    for (int i = 0; i < n; i++) {
        if (usedE[i]) continue;
        dfsE(i);
        groupE++;
    }

    for (int i = 0; i < n; i++) {
        if (usedF[i]) continue;
        dfsF(i);
        groupF++;
    }

    for (int i = 0; i < n; i++) {
        mp[make_pair(cE[i], cF[i])]++;
    }

    for (int i = 0; i < n; i++) {
        if (i != 0) cout << ' ';
        cout << mp[make_pair(cE[i], cF[i])];
    }
    cout << endl;
}


Measured memory_bytes: 28288
#include<stdio.h>

int main(void)
{
	int A,B,X1,X2;
	scanf("%d%d",&A,&B);
	X1=A/0.08;
	X2=B/0.1;
	while(X1<(X2+10)){
		if((int)(X1*0.08) == A && (int)(X1*0.1) == B){
			printf("%d",X1);
			return 0;
		}
		else ++X1;
	}
	printf("-1");
	
	
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		long n = fs.nextLong();
		HashMap<Long, Long> divisorMap = new HashMap<>();
		
		for(long i = 1; i*i <= n; i++) {
			
			if(n % i == 0) {
				divisorMap.put(i, n / i);
			}
		}
		
		int ans = 1_000_000_007;
		for(Map.Entry<Long, Long> entry : divisorMap.entrySet()) {
			
			ans = Math.min(ans, Math.max(getDigitNum(entry.getKey()), getDigitNum(entry.getValue())));
		}
		
		System.out.println(ans);
	}
	
	int getDigitNum(long num) {
		
		int ans = 0;
		while(num > 0) {
			ans++;
			num = num / 10;
		}
		return ans;
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //-freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int a, b;
  cin >> a >> b;
  cout << ((b >= a) ? "unsafe" : "safe") << endl;
  return 0;
}



Measured memory_bytes: 3648
# coding: utf-8

# https://beta.atcoder.jp/contests/abc081/tasks/abc081_b

def even(num):
    if num % 2 == 0:
        return num / 2
    else:
        return False

if __name__ == '__main__':

    n = input()
    a = map(int, input().split())
    count = 0

    while True:
        new = [0 if even(i) == False or even(i) == 0 else even(i) for i in a]
        if 0 in new:
            break
        a = new
        count += 1
    print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;

using namespace std;


int main() {
  int book_num1, book_num2;
  int limit_min;
  vector<ll> accume_times1, accume_times2;

  // Init
  cin >> book_num1 >> book_num2 >> limit_min;

  accume_times1.resize(book_num1 + 1);
  accume_times2.resize(book_num2 + 1);
  for(int i = 1; i <= book_num1; i++) {
    cin >> accume_times1[i];
  }
  for(int i = 1; i <= book_num2; i++) {
    cin >> accume_times2[i];
  }

  // Calc accum
  accume_times1[0] = 0;
  for(int i = 1; i <= book_num1; i++) {
    accume_times1[i] += accume_times1[i - 1];
  }
  accume_times2[0] = 0;
  for(int i = 1; i <= book_num2; i++) {
    accume_times2[i] += accume_times2[i - 1];
  }

  int max_book_num = 0;
  int current_book2_num = book_num2;
  for(int i = 0; i <= book_num1; i++) {
    ll read_time;

    while(true) {
      read_time = accume_times1[i] + accume_times2[current_book2_num];
      if(read_time <= limit_min || current_book2_num == 0) {
        break;
      }
      current_book2_num--;
    }

    if(read_time <= limit_min) {
      max_book_num = max(max_book_num, i + current_book2_num);
    }
  }

  cout << max_book_num << endl;
}

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

class UnionFind {
private:
  vector<ll> data;

public:
  UnionFind(ll n): data(n, -1) {}

  ll size(ll i) { return -data[find(i)]; }
  bool root(ll i) { return data[i] < 0; }
  bool same(ll i, ll j) { return find(i) == find(j); }

  ll find(ll i) { return root(i) ? i : (data[i] = find(data[i])); }

  bool unite(ll i, ll j) {
    if(same(i, j)) return false;
    data[find(i)] += data[find(j)];
    data[find(j)] = find(i);
    return true;
  }
};

int main(void) {
  ll N, H, W;
  cin >> N >> H >> W;
  vector<ll> X(N), Y(N);
  REP(i, 0, N) cin >> X[i] >> Y[i];

  UnionFind uf(N);
  REP(i, 0, N) REP(j, i + 1, N) {
    if(X[i] == X[j] || Y[i] == Y[j]) {
      uf.unite(i, j);
    }
  }

  set<ll> uniq;
  REP(i, 0, N) uniq.insert(uf.find(i));

  ll s = 0;
  for(ll i : uniq) s += uf.size(i) - 1;

  vector<bool> b1(N), b2(N), b3(N), b4(N);
  REP(i, 0, N) {
    ll r = uf.find(i);
    b1[r] = b1[r] || X[i] == 1;
    b2[r] = b2[r] || X[i] == H;
    b3[r] = b3[r] || Y[i] == 1;
    b4[r] = b4[r] || Y[i] == W;
  }
  ll t1 = 0, t2 = 0, t3 = 0, t4 = 0;
  for(ll i : uniq) {
    if(b1[i]) t1++;
    if(b2[i]) t2++;
    if(b3[i]) t3++;
    if(b4[i]) t4++;
  }

  if(uniq.size() == 1) {
    cout << s << endl;
  } else {
    cout << s + uniq.size() - max({ t1, t2, t3, t4 }) + ((ll) uniq.size() - 1) << endl;
  }
}


Measured memory_bytes: 4900
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a.first << " " << a.second;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

int main(){
    ll n; cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    unordered_map<ll,ll> mp_odd, mp_even;
    rep(i,n){
        if(i%2){
            mp_odd[v[i]]++;
        }
        else mp_even[v[i]]++;
    }
    auto comp = [](const auto a, const auto b) -> bool{
        return a.second > b.second;
    };
    vector<Pll> even(2),odd(2);
    partial_sort_copy(mp_even.begin(), mp_even.end(),even.begin(),even.end(),comp);
    partial_sort_copy(mp_odd.begin(), mp_odd.end(),odd.begin(),odd.end(),comp);
    // print(even);
    // print(odd);
    ll ans = 0;
    if(even[0].first != odd[0].first){
        ans = n - (even[0].second + odd[0].second);
    }
    else{
        ans = n-max(even[0].second + odd[1].second, even[1].second + odd[0].second);
    }
    cout << ans << endl;
    return 0;
}   

Measured memory_bytes: 5144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const int MAXV = 105;
vector<vector<int>> to(MAXV);

vector<vector<int>> M(2, vector<int>(MAXV));
void update(int i, int j, vector<int> now) {
  if(M[0][i] >= 0) {
    int prevj = M[0][i];
    int previ = now[prevj];
    update(previ, prevj, now);
  }
  M[0][i] = j;
  M[1][j] = i;
  return;
}

bool bfs(int i) {
  if(M[0][i] >= 0) return false;
  queue<int> que;
  que.push(i);
  vector<int> now(M[0].size(), -1);
  while(que.size()) {
    int ni = que.front();
    que.pop();
    for(auto j : to[ni]) {
      if(now[j] >= 0) continue;
      if(M[1][j] < 0) {
        update(ni, j, now);
        return true;
      } else {
        now[j] = ni;
        que.push(M[1][j]);
      }
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<P> R(n), B(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    R[i] = make_pair(a, b);
  }
  rep(j, n) {
    int c, d;
    cin >> c >> d;
    B[j] = make_pair(c, d);
  }

  rep(i, n) rep(j, n) {
    if(R[i].first < B[j].first
       && R[i].second < B[j].second) {
      to[i].push_back(j);
    }
  }
  rep(rb, 2) M[rb].resize(n);
  rep(rb, 2) M[rb].assign(n, -1);

  bool ok;
  do {
    ok = false;
    rep(i, n) ok |= bfs(i);
  } while(ok);

  int cnt = 0;
  for(auto m : M[0])
    if(m >= 0) cnt++;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,h,w,a,b;
  int count = 0;
  cin >> n >> h >> w;
 
  for (int i = 0 ; i < n ; i ++)
    {
      cin >> a >> b;
      if(h<=a && w<=b) count ++;
    }
  cout << count <<  endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k,a[2005];
int main(){
	cin>>n>>k;
	repn(i,n) cin>>a[i];
	ll ans1 = 0;
	repn(i,n) for(int j=i+1;j<=n;j++){
		if(a[i] > a[j]) ans1++;
	}
	ans1 *= k;
	ans1 %= mod;
	repn(i,n) for(int j=1;j<=n;j++){
		if(a[i] > a[j]) ans1 += (1LL*k*(k-1)/2)%mod;
	}
	cout<<(ans1%mod+mod)%mod<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int K = int.Parse(str[1]);
            int[] barLength = Console.ReadLine()
                .Split(' ')
                .Select(s => int.Parse(s))
                .ToArray();
            Array.Sort(barLength);

            int result = 0;
            for (int i = 0; i < K; ++i)
            {
                result += barLength[barLength.Length - 1 - i];
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13396
////!multi
//unordered_map<ll,ll> save;
//ll A,B,C,D;
//ll solve(ll x){
//    if(save.count(x))
//        return save[x];
//    ll ans = x <= 2e9 ? D*x : INF;
//    rep(ll,i,max(0ll,x-4),x+4){
//        if(i%2 == 0 && i/2 < x)
//            ans = min(ans,solve(i/2)+A+D*abs(x-i));
//        if(i%3 == 0 && i/3 < x)
//            ans = min(ans,solve(i/3)+B+D*abs(x-i));
//        if(i%5 == 0 && i/5 < x)
//            ans = min(ans,solve(i/5)+C+D*abs(x-i));
//    }
//    return save[x] = ans;
//}
//void __(){
//    save.clear();
//    ll N;
//    cin >> N >> A >> B >> C >> D;
//    print solve(N);
//}
#include <map>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_ANY(type,i,l,r) for(type i = (l); i <= (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
const ll INF = ll(2e18) + 666;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout) 
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }

    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
//!multi
unordered_map<ll,ll> save;
ll A,B,C,D;
ll solve(ll x){
    if(save.count(x))
        return save[x];
    ll ans = x <= 2e9 ? D*x : INF;
    rep(ll,i,max(0ll,x-4),x+4){
        if(i%2 == 0 && i/2 < x)
            ans = min(ans,solve(i/2)+A+D*abs(x-i));
        if(i%3 == 0 && i/3 < x)
            ans = min(ans,solve(i/3)+B+D*abs(x-i));
        if(i%5 == 0 && i/5 < x)
            ans = min(ans,solve(i/5)+C+D*abs(x-i));
    }
    return save[x] = ans;
}
void __(){
    save.clear();
    ll N;
    cin >> N >> A >> B >> C >> D;
    print solve(N);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int t;
    cin >> t;
    for(int i = 1; i <= t; ++i){
        __();
    }
}



Measured memory_bytes: 5140
#include <iostream>
#include<algorithm>
#include <cmath>
#include<vector>
#include<cstdlib>
using namespace std;

int main() {
	int n, m, k, buf, j;
	vector<int> A,a;
	cin >> n >> m >> k;
	for (j = 0; j < k; j++) {
		cin >> buf;
		A.push_back(buf);
		a = A;
	}
	for (int i = 1; i < n; i++) {
		A.clear();
		cin >> k;
		for (j = 0; j < k; j++) {
			cin >> buf;
			for (int loop = 0; loop < a.size(); loop++) {
				if (buf == a[loop])A.push_back(buf);
			}
		}
		a = A;
	}
	cout << a.size();
	return(0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();
  int cnt[3];
  fill(cnt, cnt+3, 0);
  for(int i=0;i<N;i++){
    if(s[i] == 'a') cnt[0]++;
    if(s[i] == 'b') cnt[1]++;
    if(s[i] == 'c') cnt[2]++;
  }

  sort(cnt, cnt+3);
  if(cnt[0] == cnt[1] && cnt[1] == cnt[2]) cout << "YES" << endl;
  else if(cnt[0] == cnt[1] && cnt[1] == cnt[2] - 1) cout << "YES" << endl;
  else if(cnt[0] == cnt[1] - 1 && cnt[1] == cnt[2]) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int N,mx=0;
    string S;
    cin >> N;
    map<string,int>m;

    for(int i=0; i<N; i++){
        cin >> S;
        m[S]++;
        if(mx<m[S]){
            mx = m[S];
        }
    }
    for(auto p:m){
        if(mx == p.second){
        cout << p.first << endl;
        }
    }
    return 0;

}

Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std ;

int main()
{
	double x,h ;
	double high = 0 ;

	while( cin >> x >> h )
	{
		if( x == 0 && h == 0 )	break ;

		high = sqrt( h*h + (x*x)/4 ) ;
		printf("%lf\n", (x*x)+(high*x/2*4)) ;
	}
	return 0 ;
}

Measured memory_bytes: 1232
using System;
class Program{
	const int mod=1000000007;
	static void Main(){
		string s=Console.ReadLine();
		long a=0,b=0,c=0,q=1;
		long[] r=new long[s.Length];
		for(int i=0;i<s.Length;i++){
			if(s[i]=='?'){q=(q*3)%mod;}
		}
		for(int i=s.Length-1;i>=0;i--){
			if(s[i]=='A'){a=(a+b)%mod;}
			else if(s[i]=='B'){b=(b+c)%mod;}
			else if(s[i]=='C'){c=(c+q)%mod;}
			else{
				a=(a+b*333333336)%mod;
				b=(b+c*333333336)%mod;
				c=(c+q*333333336)%mod;

			}
		}
		Console.WriteLine("{0}",a);
	}
}

Measured memory_bytes: 14176
def main():
    A, B = map(int, input().split())
    d = max(A, B) - min(A, B)
    if d % 2 == 0:
        K = min(A, B) + d//2
        print(K)
    else:
        print("IMPOSSIBLE")
if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
import bisect


def sorted_index(A):
    # Aをソートした後のindexのリスト
    A_ = sorted(A)
    B = []
    for a in A:
        idx = bisect.bisect_left(A_, a)
        B.append(idx)
    return B


def cyclic_factorize(A):
    # Aを巡回置換分解する
    B = sorted_index(A)
    checked = [False] * len(A)
    cycle_lst = []
    for i, a in enumerate(A):
        if checked[i]:
            continue
        now = i
        checked[now] = True
        cycle = [a]
        next = B[now]
        while not checked[next]:
            now = next
            next = B[now]
            cycle.append(A[now])
            checked[now] = True
        cycle_lst.append(cycle)
    return cycle_lst


N = int(input())
*W, = map(int, input().split())
cycle_lst = cyclic_factorize(W)
ans = 0
global_min = min(W)
for cycle in cycle_lst:
    l = len(cycle)
    s = sum(cycle)
    local_min = min(cycle)
    ans += s + min((l - 2) * local_min, local_min + (l + 1) * global_min)
print(ans)


Measured memory_bytes: 5672
#include<stdio.h>

#define N 100000
#define MAX 1000000

typedef struct Node
{
  int pre, next, cost;
}P;

int n, d[N], count = 0;
P data[500000];

void route();

int main()
{
  int i, j, k, c, u, v;

  scanf("%d",&n);
  
  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&u,&k);
      for(j = 0; j < k; j++)
	{
	  data[count].pre = u;
	  scanf("%d %d",&v,&c);
	  data[count].next = v;
	  data[count].cost = c;
	  count++;
	}
    }

  route();
  
  return 0;
}


void route(void)
{
  int i, flag = 0;

  for(i = 0; i < n; i++)
    {
      d[i] = MAX;
    }
  d[0] = 0;

  while(flag != 1)
    {
      flag = 1;
      for(i = 0; i < count; i++)
	{
	  if(data[i].cost+d[data[i].pre] < d[data[i].next])
	    {
	      d[data[i].next] = data[i].cost+d[data[i].pre];
	      flag = 0;
	    }
	}
    }

  for(i = 0; i < n; i++)
    {
      printf("%d %d\n",i,d[i]);
    }
}



Measured memory_bytes: 7560
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(void){
  int n; cin >> n;
  string s[n]; rep(i,n) cin >> s[i];
  map<string,int> mp;
  rep(i,n) mp[s[i]]++;
  int size = 0;
  vector<string> a = {};
  for(auto i = mp.begin(); i != mp.end(); i++){
    size = max(size,i->second);
  }
  for(auto i = mp.begin(); i != mp.end(); i++){
    if(size == i->second) a.push_back(i->first);
  }
  for(int i = 0; i < a.size();i++){
    cout << a[i] << "\n";
  }
}

Measured memory_bytes: 28404
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double pi = 2*acos(0.0);
    double alph = (60*h+m)/(60*12)*(2*pi);
    double beta = (m/60)*(2*pi);
    double res = sqrt(a*a+b*b-2*a*b*cos(alph - beta));
    cout << setprecision(10) << res;
    return 0;
}

Measured memory_bytes: 4148
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int k = stdIn.nextInt();
		
		if (k % 2 == 0) {
			System.out.println(k*k/4);
			return;
		}
		if (k % 2 == 1) {
			System.out.println((k-1)*(k-1)/4 + k/2);
			return;
		}
		
	
	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,ls[30],mx1,mx2,x,c[30];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=26;i++)scanf("%d",&c[i]),ls[i]=0;
    for(int i=1;i<=n;i++)
    {
        mx1=0,mx2=1;
        for(int j=1;j<=26;j++)
        {
            scanf("%d",&x);
            int k=((i-ls[j])*c[j])+x;
            if(mx1<k)mx1=k,mx2=j;
            else if(mx1==k)if(ls[j]<ls[mx2])mx2=j;
        }
        //printf("[%d]",mx1);
        ls[mx2]=i;
        printf("%d\n",mx2);
    }
}


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

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;


LL ruijo(int n){
    LL ans2=1;
    for(int i=0;i<n;++i){
        ans2*=2;
    }
    return ans2;
}


int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<3;++i){
        if(s[i]=='1')ans++;
    }   
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>

#define f(i,x) for(int i=0;i<x;i++)


using namespace std;

int main()
{
	int a[] = { 1,3,5,7,8,10,12 };
	int b[] = { 4,6,9,11 };

	int x, y;
	bool xx=false, yy=false;
	cin >> x >> y;

	if (x == 2 && y == 2) {
		cout << "Yes";
		return 0;
	}

	for (auto i : a) {
		if (i == x) {
			for (auto j : a) {
				if (j == y) {
					cout << "Yes";
					return 0;
				}
			}
		}
	}
	for (auto i : b) {
		if (i == x) {
			for (auto j : b) {
				if (j == y) {
					cout << "Yes";
					return 0;
				}
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

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


Measured memory_bytes: 256
def solve(y, m, d):
    Y = [195, 195, 200]
    M = [20, 19]

    ret = 196471
    for i in range(y-1):
        ret -= Y[i % 3]
    if y % 3 == 0:
        ret -= (m-1) * 20
    else:
        for i in range(m-1):
            ret -= M[i % 2]
    ret -= d

    return ret


N = int(raw_input())
for _ in range(N):
    y, m, d = map(int, raw_input().split(" "))
    print solve(y, m, d)


Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve()
{
   int n;int W;cin>>n>>W;
   int dp[n+1][W+1];
   int wt[n];
   int val[n];
   for(int i=0;i<n;i++)
   cin>>wt[i]>>val[i];
   
   for(int i=0;i<=n;i++)
   {
       for(int j=0;j<=W;j++)
       {
           if(i==0 || j==0)
           dp[i][j]=0;
           else if(wt[i-1]>j)
           dp[i][j]=dp[i-1][j];
           else
           dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);
       }
   }
   cout<<dp[n][W]<<endl;
}
int32_t main()
{
    rapido;
    int t;t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 82428
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n, m, ans;
struct PP {
	int a, b;
	friend bool operator < (PP u, PP v) {
		return u.a < v.a;
	}
} p[maxx];
priority_queue < int, vector<int>, less<int> > qua; //降序, 队头大

int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> p[i].a >> p[i].b;
	sort(p + 1, p + n + 1);
	int id = 1;
	for(int i = 1; i <= m; i++) { //第i天后可以拿到工资
		while(id <= n && p[id].a <= i) qua.push(p[id++].b);
		if(!qua.empty()) {
			ans += qua.top();
			qua.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> nums;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        nums.push_back(tmp);
    }
    int min = 3875820019684;

    for(int i =0; i < N; i++){
        int cnt = 0;
        while(!(nums[i] % 2)){
            nums[i] = nums[i] / 2;
            cnt++;
        }
        if(cnt < min){
            min = cnt  ;  
        }
        
    }
    cout << min;

}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}


int main() {
  string s;
  cin >> s;
  string t = "CODEFESTIVAL2016";

  int c = 0;
  rep(i, 16) {
    if (s[i] != t[i]) {
      c++;
    }
  }
  p(c);
}

Measured memory_bytes: 256
N,M,X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]
buy = []

for i in range(1,2**(N+1)):
  bought = list(format(i, '0{}b'.format(N)))
  params = [0] * (M+1)
  for b, book in zip(bought, books):
    if b == '1':
      params = [pi+ai for pi,ai in zip(params,book)]
  for p in params[1:]:
    if p < X:
      break
  else:
    buy.append(params)

buy.sort()
print(buy[0][0] if len(buy) > 0 else -1)


Measured memory_bytes: 70084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()

using namespace __gnu_pbds;
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

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

    int x;
    cin >> x;

    cout << (x >= 30 ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int N, K;

long long h[100010];

long long dp[100010];
int main(){
    cin >> N >> K;
    
    for (int i=0; i< N; ++i) cin >> h[i];
    
    for(int i=0; i<N; ++i) dp[i] = INF;
    
    dp[0] = 0;
    for(int i=1; i< N; ++i){
        for(int j=1; j<= i; ++j){
            if(j >K) break;
            chmin(dp[i], dp[i-j] + abs(h[i] -h[i-j]));
        }
    }
    
    cout << dp[N-1] << endl;
    
    return 0;
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int a,b,c,d;

int main(){
	cin >> a >> b >> c >> d;
	
	cout << min(a,b) + min(c,d) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  static Scanner sc = new Scanner(System.in);
  static char [][] map;
  static char ch;
  static int tmp_x, tmp_y;
  static int [] dx = {0, -1, 0, 1}, dy = {1, 0, -1, 0};
  static int H;
  static int W;
  static int ans;

	public static void main(String [] args){
    while(solve()){
      System.out.println(ans);
    }
	}

  static boolean solve(){
    ans = 0;
    H = sc.nextInt();
    W = sc.nextInt();
    if(H == 0 && W == 0)return false;
    readMap();
    Deque <Integer> x = new ArrayDeque <Integer>();
    Deque <Integer> y = new ArrayDeque <Integer>();
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(map[i][j] == '.') continue;
        x.push(j);
        y.push(i);
        while(!x.isEmpty()){
          tmp_x = x.pop();
          tmp_y = y.pop();
          ch = map[tmp_y][tmp_x];
          map[tmp_y][tmp_x] = '.';
          for(int k = 0; k < dx.length; k++){
            if(!check(tmp_x + dx[k], tmp_y + dy[k]))continue;
            if(ch == '.') continue;
            else if(ch == map[tmp_y + dy[k]][tmp_x + dx[k]]){
              x.push(tmp_x + dx[k]);
              y.push(tmp_y + dy[k]);
            }
          }
        }
        ans++;
      }
    }
    return true;
  }

  static boolean check(int x, int y){
    if(x < 0 || W <= x || y < 0 || H <= y) return false;
    else return true;
  }

  static void readMap(){
    map = new char[H][W];
    for(int i = 0; i < H; i++){
      map[i] = sc.next().toCharArray();
    }
    return;
  }
}

Measured memory_bytes: 22424
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

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

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

int main()
{
	string S;
	while (true)
	{
		cin >> S;
		if (S == "-")
		{
			break;
		}
		int m;
		cin >> m;
		REP(i, m)
		{
			int h;
			cin >> h;

			string sub1 = S.substr(0, h);
			string sub2 = S.substr(h, S.length() - h);
			S = sub2 + sub1;
		}
		cout << S << endl;
	}
	return 0;
}


Measured memory_bytes: 3240
n , m = map(int,input().split())
if n >= 2 and m >=2:
    print((n-2)*(m-2))
elif n == 1 and m != 1:
    print(m-2)
elif m == 1 and n != 1:
    print(n-2)
elif n == 1 and m == 1:
    print(1)

Measured memory_bytes: 3316
import sys
L, R = list(map(int, input().split()))

mod = 1000000
for i in range(L, R+1):
  for j in range(i+1, R+1):
    tmp = (i * j) % 2019
    if tmp == 0:
      print(tmp)
      sys.exit()
      
    if mod > tmp:
      mod = tmp
    
print(mod)
    

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int a = in.nextInt();
            int b = in.nextInt();
            double x = in.nextDouble() / a;
            double half = a * b / 2.0;
            if (half < x){
                double b2 = 2 * (b - x/a);
                double ang = Math.toDegrees(Math.atan2(b2,a));
                System.out.println(ang);
            } else {
                double a2 = (x*2) / b;
                double ang = Math.toDegrees(Math.atan2(a2,b));
                System.out.println(90 - ang);
            }
        }
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[202020];
int L[202020];
int R[202020];
set<int> S;
set<pair<int,int>> cand;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	A[0]=1LL<<30;
	A[N+1]=1LL<<30;
	
	S.insert(0);
	S.insert(N+1);
	cand.insert({1<<30,0});
	for(i=1;i<=N;i++) {
		cin>>A[i];
		L[i]=R[i]=1;
		S.insert(i);
		cand.insert({A[i],i});
	}
	
	ll ret=N;
	while(1) {
		auto c=*cand.begin();
		/*
		FORR(a,cand) cout<<a.first<<":"<<a.second<<" ";
		cout<<ret<<endl;
		*/
		
		if(c.first>=1<<30) break;
		x=y=c.second;
		
		vector<vector<int>> V;
		while(1) {
			//cout<<"take"<<y<<endl;
			V.push_back({y,L[y],R[y]});
			S.erase(y);
			cand.erase({A[y],y});
			y=*S.lower_bound(y+1);
			if(A[y]!=A[x]) break;
		}
		
		/*
		cout<<"!";
		FORR(v,V) cout<<v[0]<<":"<<v[1]<<":"<<v[2]<<"  ";
		cout<<endl;
		*/
		
		int nl=V.size();
		int ns=nl/M;
		if(ns==0) {
			A[x]=1<<30;
			S.insert(x);
			continue;
		}
		
		int RT=0;
		for(i=M-1;i<V.size();i++) RT+=V[i][2];
		FOR(i,V.size()-M+1) {
			//cout<<"ok"<<V[i][1]<<" "<<RT<<endl;
			ret+=1LL*V[i][1]*RT;
			RT-=V[i+M-1][2];
		}
		FOR(i,ns) L[x+i]=R[x+i]=0;
		FOR(i,V.size()) {
			if(i>=M-1) R[x+(i+1)/M-1]+=V[i][2];
			j=V.size()-1-i;
			if(j>=M-1) {
				j=(j+1)/M-1;
				L[x+ns-1-j]+=V[i][1];
			}
		}
		
		RT=0;
		for(i=M-1;i<ns;i++) RT+=R[x+i];
		FOR(i,ns-M+1) {
			ret-=1LL*L[x+i]*RT;
			RT-=R[x+i+M-1];
		}
		
		A[x]++;
		FOR(i,ns) {
			A[x+i]=A[x];
			cand.insert({A[x+i],x+i});
			S.insert(x+i);
		}
		
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

const string YES = "Yes";
const string NO = "No";

bool check(const string& S, ll start, ll end){
    const ll n = end - start;
    for(ll i = 0; i < n; ++i){
        if(S.at(start + i) != S.at(end - 1 - i)){
            return false;
        }
    }
    return true;
}

void solve(std::string S){
    const ll n = S.size();
    if(check(S, 0, n) && check(S, 0, (n - 1) / 2) && check(S, (n + 3) / 2 - 1, n)){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

bool check(vector<string>& a, vector<string>& b, int i, int j) {
  rep(y, b.size()) {
    rep(x, b.size()) {
      if (a[y + i][x + j] != b[y][x])return false;
    }
  }
  return true;
}
void Calc() {

  int n, m;
  in, n, m;

  auto a = in.Array<string>(n);
  auto b = in.Array<string>(m);

  rep(i, n - m + 1)rep(j, n - m + 1) {
    if (check(a, b, i, j)) {
      cout << ("Yes") << endl;
      return;
    }
  }
  cout << ("No") << endl;

}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int P, Q, R; cin >> P >> Q >> R;
    cout << P + Q + R - max({P,Q,R}) << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256