akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>
#include <utility>
 
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl
#define ROUNDED(N) fixed << setprecision(N)
#define SPACE " "
 
typedef long long ll;
using namespace std;
 
int nextInt() { int n; cin >> n; return n; }
double nextDouble() { double d; cin >> d; return d; }
string nextString() { string str; cin >> str; return str; }
 
int main() {
    cin.tie(0); //??????±?????????????????????
    ios::sync_with_stdio(false); //printf???¨???±??????????????????
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M){
      vector<vector<pair<bool,int>>> team(T,vector<pair<bool,int>>(P,make_pair(false,0)));//first is the number of problem
        REP(i,R){
            int m,t,p,j;
            cin >> m>>t>>p>>j;
	    t--;
	    p--;
            if(!j){
                team[t][p].first = true;
                team[t][p].second += m;
            }else{
                team[t][p].second += 20;
            }
        }
        vector<pair<int,pair<int,int>>> teamres(T,make_pair(0,make_pair(15000,0)));
        REP(i,T){
            teamres[i].second.second = i;
            REP(j,P){
                if(team[i][j].first){
                    teamres[i].first++;
                    teamres[i].second.first -= team[i][j].second;
                }
            }
        }
        sort(ALL(teamres));
        reverse(ALL(teamres));
            REP(i,T-1){
                if(teamres[i].first == teamres[i+1].first && teamres[i].second.first == teamres[i+1].second.first){
                    cout << teamres[i].second.second + 1 << "=";
                }else{
                    cout << teamres[i].second.second + 1 << ",";
                }
            }
            cout << teamres[T-1].second.second + 1 << endl;
 
    }
return 0;
}

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

bool checkw(char c[100][100],int w, int i){
    for(int j=0;j<w;j++){
        if(c[i][j]=='#'){
            return true;
        }
    }
    return false;
}
bool checkh(char c[100][100],int h, int i){
    for(int j=0;j<h;j++){
        if(c[j][i]=='#'){
            return true;
        }
    }
    return false;
}

int main(){
    int h,w;
    char c[100][100];
    cin >> h >> w;
    for(int i = 0; i<h;i++){
        for(int j = 0; j<w;j++){
            cin >> c[i][j];
        }
    }
    char a[100][100];
    int n = 0;
    for(int i = 0; i<h;i++){
        if(checkw(c, w, i)){
            for(int k = 0; k < w;k++){
                a[n][k]=c[i][k];
            }
            n++;
        }
    }
    char ans[100][100];
    int m = 0;
    for(int i = 0; i<w;i++){
        if(checkh(a, n, i)){
            for(int k = 0; k < n;k++){
                ans[k][m]=a[k][i];
            }
            m++;
        }
    }
    for(int i = 0; i<n;i++){
        for(int j = 0; j<m;j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct res{
	string name;
	int score;
	int num;
}a[110];
bool cmp(const res &a,const res &b){
	if(a.name==b.name)
		return a.score>b.score;
	else
		return a.name<b.name;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].name>>a[i].score;
		a[i].num=i+1;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++)
		cout<<a[i].num<<endl;
	return 0;
}

Measured memory_bytes: 256
K, A, B = (int(i) for i in input().split())
num = 1
while True:
    if A + 2 - num >= B:
        print(K + num)
        break
    elif num >= A and (K // 2) is not 0:
        print(num + (K // 2) * (B - A) + (K % 2))
        break
    elif K >= 2 and K >= (A + 2 - num):
        K -= (A + 2 - num)
        num = B
    else:
        print(K + num)
        break


Measured memory_bytes: 3060
import sys
ab=[0 for _ in range(2001)]
for a in range(1001):
    for b in range(1001):
        ab[a+b]+=1
for l in sys.stdin:
    n=int(l[:-1])
    ans=sum(ab[i]*ab[n-i] for i in range(2001) if 0<=n-i<=2000)
    print(ans)


Measured memory_bytes: 5624
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String Sd = scan.next();
			String T = scan.next();
			char[]s = new char[Sd.length()];
			char[]t = new char[T.length()];
			s = Sd.toCharArray();
			t = T.toCharArray();
			
			if(t.length>s.length) {
				System.out.println("UNRESTORABLE");
				System.exit(0);
			}
			
			for(int i = s.length-t.length;i>=0;i--) {
				int count = 0;
				for(int j = 0;j<t.length;j++) {
					if(t[j]==s[i+j]||s[i+j]=='?')count++;
					
					
					
				}
				if(count==t.length) {
					
					Sd = Sd.substring(0, i)+T+Sd.substring(i+t.length,Sd.length());
					Sd = Sd.replace('?','a');
					
					System.out.println(Sd);
					System.exit(0);
				}
			}
			
			System.out.println("UNRESTORABLE");
			
			
			
		}
		
		
	}
		

}


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

int main() {
  int N; //入力の個数
  cin >> N;
  
  int M=0; //最大値を保持する変数
  int S=0; //求める合計値
  
  for (int i=0; i<N; i++) {
    int p;
    cin >> p; //入力
    S += p;
    M = max(M, p);
  }
  int ans = S - M / 2 ;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String ans = "";

        if ("Sunny".equals(a)){
            ans = "Cloudy";
        }else if("Cloudy".equals(a)){
            ans = "Rainy";
        }else{
            ans = "Sunny";
        }
        // 出力
        System.out.println(ans);

    }
}

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

int main()
{
    long long L, R;
    cin >> L >> R;

    if(2019 <= R-L)
    {
        cout << 0 << endl;
    }
    else
    {
        long long ans = 2019;
        for (long long i = L; i <= R; i++)
        {
            for (long long j = i + 1; j <= R;j++)
            {
                ans = min(ans, (i * j) % 2019LL);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc152/tasks/abc152_e

MOD = 10**9+7

N = gets.to_i
As = gets.split.map(&:to_i)

l=1
As.each do |a|
  l=l.lcm(a)
end
ans=0
As.each do |a|
  t=l/a
  ans+=t
end
puts ans%MOD


Measured memory_bytes: 57084
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  char b; cin>>b;
  char ans;
  if(b=='A')
  ans='T';
  else if(b=='T')
  ans='A';
  else if(b=='G')
  ans='C';
  else
  ans='G';
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 22:24:11 2020

@author: Kanaru Sato
"""

import itertools
import copy

def setdanger(Map,r,c):
    Map[r][c] == 0
    for i in range(8):#縦横
        Map[r][i] = 0
        Map[i][c] = 0
    for i in range(max(r-7,-c),min(r,7-c)+1):#右上がり斜め
        Map[r-i][c+i] = 0
    for i in range(max(-c,-r),min(7-c,7-r)+1):#左上がり斜め
        Map[r+i][c+i] = 0

def dfs(i,Map,ans):#i個をmapに配置するやり方を深さ優先探索し、存在したら座標を追加、Trueを返す
    if i == 0:
        return True
    else:
        for pointtuple in itertools.product([i for i in range(8)], repeat=2):
            point = list(pointtuple)
            if Map[point[0]][point[1]]:
                currentMap = copy.deepcopy(Map)
                setdanger(currentMap,point[0],point[1])
                if dfs(i-1,currentMap,ans):
                    ans.append(point)
                    return True
                    break
    
k = int(input())

ans = []
for i in range(k):
    ans.append(list(map(int,input().split())))

Map = [[1 for i in range(8)] for j in range(8)]
for i in range(k):
    setdanger(Map,ans[i][0],ans[i][1])

dfs(8-k,Map,ans)

for i in range(8):
    row = []
    for j in range(8):
        if [i,j] in ans:
            row.append("Q")
        else:
            row.append(".")
    print("".join(row))



Measured memory_bytes: 6336
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ls = VU.accum (+) (VU.replicate n 0) . map (flip (,) 1 . pred) $ as :: VU.Vector Int
    m = VU.sum . VU.map comb $ ls :: Int
  mapM_ print . map ((m -) . pred . (ls VU.!) . pred) $ as

comb :: Int -> Int
comb l = (l * pred l) `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 27260
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int i;
		int cnt;
		public Pair(int i, int cnt) {
			this.i=i;
			this.cnt=cnt;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		ArrayList<ArrayList<Integer>> a = new ArrayList<>();
		for(int i=0; i<=n; i++) {
			a.add(new ArrayList<Integer>());
		}
		for(int i=0; i<m; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			a.get(s).add(t);
		}
		ArrayDeque<Pair> stack = new ArrayDeque<Pair>();
		stack.add(new Pair(1,0));
		boolean ok = false;

		while(!stack.isEmpty()) {
			Pair p = stack.pop();
			if(p.i == n && p.cnt == 2) {
				ok=true;
				break;
			}
			for(int t : a.get(p.i)) {
				stack.add(new Pair(t, p.cnt+1));
			}
		}
		if(ok) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
		sc.close();
	}
}


Measured memory_bytes: 126572
#include <stdio.h>

int main()
{
	int a,b,d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	
	d = a / b;
	r = a % b;
	f = (double)a / (double)b;
	
	printf("%d %d %lf\n",d,r,f);
	
	return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    ll H;
    scan(H);
    int n  = log2(H) + 1;
    ll ans = 0;
    rep(i, n) { ans += pow(2, i); }
    print(ans);

    return 0;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(non_snake_case)]
fn main() {
    input![a: usize, b: usize, h: usize];
    println!("{}", (a + b) * h / 2);
}


Measured memory_bytes: 2156
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1, 0);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(26 + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        ans -= c[t[i]] * (i - last[t[i]]) * (i - last[t[i]] - 1) / 2;
        last[t[i]] = i;
    }

    for (int i = 1; i <= 26; i++)
    {

        ans -= c[i] * (d - last[i] + 1) * (d - last[i]) / 2;
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    double BestScore = scoring(BestT);
    double score;

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1, 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1980;

    ll count = 0;

    while (1)
    {
        ll msec;

        if (count % 100 == 0)
        {
            msec = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
        }

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }

        count++;
    }

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


Measured memory_bytes: 4404
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <numeric>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <iostream>

using namespace std;

#define FOR(k,a,b) for(int k(a); k < (b); ++k)
#define REP(k,a) for(int k=0; k < (a); ++k)
#define ABS(a) ((a)>0?(a):-(a))
#define EPS 1e-9
typedef long long LL;
const LL MOD = 1e9 + 7;

void generate(int& N, vector<vector<bool> >& v)
{
	REP(i, N) REP(j, N)
	{
		v[i][j] = rand() & 1;
	}
}

int solver(int N, vector<vector<bool> >& v)
{
	vector<int> w(N), z(N);
	bool found = 0, found2 = 0;
	REP(i, N)
	{
		REP(j, N)
			if (v[i][j])
			{
				found = 1;
			}
			else
			{
				found2 = 1;
			}
	}
	REP(i, N)
	{
		REP(j, N)
		{
			w[i] += v[i][j];
			z[i] += v[j][i];
		}
	}
	if (!found)
	{
		return -1;
	}
	if (!found2)
	{
		return 0;
	}
	int res = 1010;
	REP(i, N) // we want to make black the i-th row
	{
		int act = 0;
		found = 0;
		REP(j, N) if (v[j][i])
			found = 1;
		if (!found && w[i] < N)
			act++;
		act += N - w[i];
		REP(j, N) if (z[j] != N)
			act++;
		if (act < res)
			res = act;
	}
	return res;
}

bool isFull(int N,vector<vector<bool> >& v)
{
	REP(i, N)
		REP(j, N)
		if (!v[i][j])
			return false;
	return true;
}

vector<vector<bool> > step(vector<vector<bool> > v,int  i, int j)
{
	vector<bool> t = v[i];
	REP(o, v.size())
		v[o][j] = t[o];
		
	return v;
}

int gsolver(int N, vector<vector<bool> >& v)
{
	set<vector<vector<bool> > > s;
	vector<pair<int, vector<vector<bool> > > > q;
	q.push_back(make_pair(0, v));
	REP(i, q.size())
	{
		int actS = q[i].first;
		vector<vector<bool> > actV = q[i].second;
		REP(i, N) REP(j, N)
		{
			vector<vector<bool> > tmp = step(actV, i, j);
			if (!s.count(tmp))
			{
				if (isFull(N,tmp)) return actS + 1;
				s.insert(tmp);

				q.push_back(make_pair(actS+1,tmp));
			}
		}
	}
	return -1;
}

int main(int argc, char** argv) {
#ifdef HOME
	freopen("in.txt", "rb", stdin);
	freopen("out.txt", "wb", stdout);
#endif
	int N;
	cin >> N;
	vector< vector<bool> > v(N, vector<bool>(N));
	string s;
	REP(i, N)
	{
		cin >> s;
		REP(j, N) 
			if (s[j] != '.')
			{
				v[i][j] = 1;
			}
	}
	int res = solver(N, v);
	printf("%d\n", res);
	/*N = 3;
	vector< vector<bool> > v(N,vector<bool> (N));
	while (1)
	{
		generate(N, v);
		// 	string s;
		// 	REP(i, N)
		// 	{
		// 		cin >> s;
		// 		REP(j, N) 
		// 			if (s[j] != '.')
		// 			{
		// 				v[i][j] = 1;
		// 			}
		// 	}
		int r = solver(N, v);
		int r2 = gsolver(N, v);
		if (r != r2)
		{
			printf("%d %d\n", r, r2);
			printf("%d\n",N);
			REP(i, N)
			{
				REP(j, N)
				{
					printf("%d", (v[i][j]? 1 : 0));
				}
				printf("\n");
			}
			int alma = 42;
		}
	}*/
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<long> viFre(n);
    for(int i = 0; i < n; i++){
        scanf("%ld", &viFre[i]);
    }
    sort(viFre.begin(), viFre.end(), greater<long>());
    
    long nAns = 0;
    int j = 0;
    for(int i = 1; i < n; i++){
        nAns += viFre[j];
        if(i % 2 == 1){
            j++;
        }
    }
  
    printf("%ld", nAns);
    return 0;
}


Measured memory_bytes: 4460
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(K * (K - 1) ** (N - 1))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


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

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(Re int i = a;i <= b;++i)
#define nfor(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int a[26];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    string s;
    cin>>s;
    memset(a,0,sizeof(a));
    for(int i=0;i<4;i++)
    {
        int d=s[i]-'A';
        a[d]++;
    }
    bool ok=true;
    int cnt=0;
    for(int i=0;i<26;i++)
    {
        if(a[i]==1||a[i]>=3)
        {
            ok=false;
        }
        if(a[i]==2)
        {
            cnt++;
        }
    }
    if(ok&&cnt==2)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#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 repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);

void solve()
{	
	int k, x;
	cin >> k >> x;
	vector<int> v;
	for(int i = x - k + 1; i <= x + k - 1; ++i){
		cout << i << " ";
	}
}

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


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int n, m, N, a[21000];

int main()
{
  while (cin >> n >> m >> N) {
	for (int i = 0; i < N; ++i) cin >> a[i];
	vector<vector<int> > res(n, vector<int>(m, 0));

	int x = 0, y = 0;
	for (int i = 0; i < N; ++i) {
	  for (int j = 0; j < a[i]; ++j) {
		res[x][y] = i+1;
		++y;
		if (y == m) {
		  ++x, y = 0;
		}
	  }
	}
	for (int i = 0; i < n; ++i) {
	  if (i & 1)
		reverse(res[i].begin(), res[i].end());
	}
	for (int i = 0; i < n; ++i) {
	  for (int j = 0; j < m; ++j) {
		cout << res[i][j];
		if (j != m-1) cout << " ";
	  }
	  cout << endl;
	}
						
  }
}

















Measured memory_bytes: 384
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{

	ll a, b = 0, c = 0, d = 0;
	ll l;
	char C[1000][1000] = {};
	string s, t;
	ll n, h, w;
	cin >> a;
	cin >> b;
	ll A[1000];
	for (int i = 0; i < a; i++)
	{
		cin >> A[i];
	}
	sort(A, A + a);
	/*for (int i = 0; i < a; i++)
	{
		cout << A[i]<<endl;

	}*/
	ll i = 0;
	while (b >= 0&&i<a)
	{
		if (i==a-1)
		{
			if (b - A[i] == 0)
			{
				c++;
			}
			else if (b - A[i] >= 0)
			{
				
			}
			else
			{

			}
		}
		else if (b - A[i] >= 0)
		{
			b -= A[i];
			c++;
		}
		i++;
	}

	cout <<c<< endl;

	//cout << sum << endl;
	//cout <<  endl;

	return 0;
}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}



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

using namespace std;

int main(){
    int N;

    cin >> N;

    for(int i = 1;i <= 9;i++){
        int n = i * 100 + i * 10 + i;
        if(N <= n){
            cout << n << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N,K;
    cin >>N>>K;
    vector<long double> p(N);
    vector<long double> sum(N+1);
    rep(i,N){
        cin>>p[i];
    }
    sum[0] = 0;
    sum[1] = (1+p[0])/2.0;
    rep3(i,2,N+1){
        sum[i] = sum[i-1] + (1+p[i-1])/2.0;
    }


    long double ans = 0.0;
    rep(i,N-K+1){
        chmax(ans,sum[i+K]-sum[i]);
    }
    cout << fixed << setprecision(15) << ans << endl;



    return 0;
    

}

Measured memory_bytes: 9500
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
   string n;
   cin>>n;
   cout<<"ABC"<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
void DiagonalString() {
	string r = "";
	for (size_t i = 0; i < 3; i++)
	{
		string s;
		cin >> s;
		r += s[i];
	}
	cout << r << endl;
}
int main() {
	DiagonalString();
	return 0;
}

Measured memory_bytes: 256
X,Y = map(int,input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
n = (-X+2*Y)//3
m = (2*X-Y)//3
if n < 0 or m < 0:
    print(0)
    exit()

mod = 10**9+7
mod_inv = [0, 1] + [0] * (max(n,m)+3)
for i in range(2, max(n,m)+5):
    mod_inv[i] = - mod_inv[mod % i] * (mod // i) % mod
def comod(n, r, mod):
    ans = 1
    for i in range(r):
        ans *= (n-i) % mod
        ans *= mod_inv[i+1]
        ans %= mod
    return ans
ans = comod(n+m,n,mod)
print(ans)

Measured memory_bytes: 20612
#include "bits/stdc++.h"

using namespace std;
int main()
{
	int a, b, c;
	char m, n;
	cin >> a >> m >> b >> n >> c;
	bool ans;
	if (a > 2019)
		ans = false;
	else if (a == 2019 && b > 4)
		ans = false;
	else
		ans = true;
	if (ans == true)
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
}



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

#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;

vector<double> conv(vector<double> a, vector<double> b)
{
	int sa = (int) a.size(), sb = (int) b.size();
	vector<double> r(sa + sb - 1, 0);
	for(int i = 0; i < sa; i++)
		for(int j = 0; j < sb; j++)
			r[i + j] += a[i] * b[j];
	return r;
}

int main()
{
	int n;
	cin >> n;
	vector<double> v = {1};
	for(int i = 0; i < n; i++)
	{
		double f;
		cin >> f;
		vector<double> tmp;
		tmp.push_back(1 - f);
		tmp.push_back(f);
		v = conv(v, tmp);
	}

	double ans = 0;
	for(int i = (n + 2) / 2; i <= n; i++)
		ans += v[i];
	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}


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

namespace ABC097C
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split();

            int h = int.Parse(str[0]);
            int w = int.Parse(str[1]);

            var foo = new char[h][];
            for (int i = 0; i < h; i++)
            {
                foo[i] = Console.ReadLine().ToArray();
            }

            if (S(h, w, foo))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        private static bool S(int h, int w, char[][] foo)
        {
            var v = new int[][] { new int[] { 0, 1 }, new int[] { 0, -1 }, new int[] { 1, 0 }, new int[] { -1, 0 } };
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    if (foo[y][x] == '#')
                    {
                        var f = false;
                        for (int k = 0; k < 4; k++)
                        {
                            var x_tmp = v[k][0] + x;
                            var y_tmp = v[k][1] + y;
                            if (x_tmp < 0 || y_tmp < 0 || x_tmp >= w || y_tmp >= h)
                            {
                                continue;
                            }
                            if (foo[y_tmp][x_tmp] == '#')
                            {
                                f = true;
                                break;
                            }
                        }
                        if (f == false)
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0; (int)TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  string S;
  cin >> S;
  int sum = 0;
  int l = S.length();

  rep(i, l / 2){
    if(S[i] != S[l - i - 1])sum++;   
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl().chars().collect::<Vec<_>>();
    let n = S.len();

    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + if S[i] == '1' { 1 } else { 0 };
    }

    let mut K = (n + 1) / 2;
    while K <= n {
        debug!(K, n - K);

        let d = acc[K] - acc[n - K];
        if d != 0 && d < K - (n - K) {
            break;
        }

        K += 1;
    }

    println!("{}", K - 1)
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int age[7] = {0};
		int i;
		
		for (i = 0; i < n; i++){
			int t;
			scanf("%d", &t);
			t / 10 >= 7 ? age[6]++ : age[t / 10]++;
		}
		for (i = 0; i < 7; i++){
			printf("%d\n", age[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
string a;
bool n, w, s, e;

int main() {
    cin >> a;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == 'N') n = true;
        else if (a[i] == 'W') w = true;
        else if (a[i] == 'S') s = true;
        else e = true;
    }
    if (n == s && w == e) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;

bool possible(ll mid, ll k, vector<pair<ll, int> > a) {
    ll req = 0;
    int n = a.size();
    for (int i = 0; i < n; ++i) {
        if (a[i].first > mid) {
            req += ceil((1.0*(a[i].first - mid))/a[i].second);
        }
    }
    if (req <= k) {
        return 1;
    }
    return 0;
}

int main() {
    FAST_IO;
    
    int n;
    ll k;
    cin >> n >> k;

    vector<ll> a(n), f(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> f[i];
    }

    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());

    vector<pair<ll, int> > prod;
    for (int i = 0; i < n; ++i) {
        prod.push_back(make_pair(a[i]*f[i], f[i]));
    }
    
    ll low = 0;
    ll high = 1e12;
    ll mid;
    while (low < high) {
        mid = low + ((high - low)>>1);
        if (possible(mid, k, prod)) {
            // ans = mid;
            high = mid;
        } else {
            low = mid + 1;
        }
    }
    cout << low << endl;
    return 0;
}

Measured memory_bytes: 10604
#include <stdio.h>

int main(void)
{
	int num;
	int x[200],y[200];
	int xmax,xmin;
	int ymax,ymin;
	int ni,di;
	int dx[]={-1,0,1,0};
	int dy[]={0,-1,0,1};
	
	while(1){
		scanf("%d",&num);
		if(num==0)break;
		x[0]=y[0]=0;
		xmax=xmin=ymax=ymin=0;
		for(int i=1;i<num;i++){
			scanf("%d%d",&ni,&di);
			x[i]=x[ni]+dx[di];
			y[i]=y[ni]+dy[di];
			if(xmax<x[i])xmax=x[i];
			if(xmin>x[i])xmin=x[i];
			if(ymax<y[i])ymax=y[i];
			if(ymin>y[i])ymin=y[i];
		}
		printf("%d %d\n",xmax-xmin+1,ymax-ymin+1);
	}
	return 0;
}


Measured memory_bytes: 2580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, h, w);
    int ans = 0;
    Rep(n){
        Cin(int, a, b);
        if(a >= h && b >= w) ans ++;
    }
    Cout(ans);
    
}





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

using namespace std;

int main(){
    int a, A=0, B=0, C=0, ans=0;
    int ks[3]={};
    for(int i=0; i<3; i++){
        cin >> a;
        ks[i]+=a;
    }
    sort(ks,ks+3);
    ans+=ks[2]*10;
    ans+=ks[1];
    ans+=ks[0];
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  std::cin >> n;
  deque<ll> dq;

  bool dir=true;

  rep(i,n){
    ll now;
    std::cin >> now;
    if(i%2==0)dq.push_back(now);
    else dq.push_front(now);
  }

  if(n%2==1)reverse(dq.begin(),dq.end());

  for(ll i:dq)std::cout << i<<' ';
  std::cout << "" << '\n';

  return 0;
}


Measured memory_bytes: 3840
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

n=gets.to_i-1
ans=[]
ab=("a".."z").to_a
while n>=26
  ans.push(ab[n%26])
  n/=26
  n-=1
end
ans.push(ab[n%26])
puts ans.reverse!.join("")

Measured memory_bytes: 14328
#abc059c

n=int(raw_input())
a=map(int,raw_input().split())
def f(a,s):
 ac=0
 cnt=0
 for i in xrange(n):
  ac+=a[i]
  if i%2:
   if s*ac>=0:
    cnt+=1+s*ac
    ac=-s
  else:
   if s*ac<=0:
    cnt+=1-s*ac
    ac=s
 return cnt
print min(f(a,1),f(a,-1))


Measured memory_bytes: 11248
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String S = sc.next();
			if(S.equals("-")) break;
			int m = sc.nextInt();
			
			for(int i = 0; i < m; i++){
				int h = sc.nextInt();
				String right = S.substring(h);
				String left = S.substring(0, h);
				S = right + left;
			}
			
			System.out.println(S);
		}
	}
}


Measured memory_bytes: 26396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    map<char,int> mp;
    REP(i,s.size()) mp[s[i]]++;
    int cnt=0;
    for(auto c:mp){
        cnt++;
        if(c.second!=2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(cnt!=2) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

int main(){

  int n,k[10000],p[10000],q[10000],r[10000],a,b,c,d;

  while(cin >> n, n){

    int z = 0;

    for(int i=0;i<n;i++) cin >> k[i] >> p[i] >> q[i] >> r[i];

    cin >> a >> b >> c >> d;

    for(int i=0;i<n;i++){

      if(a >= p[i] && b >= q[i] && c >= r[i] && d >= (4*(p[i]+r[i])+9*q[i])){
	cout << k[i] << endl;
	z = 1;
      } 
    }

    if(!z) cout << "NA" << endl;
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll n; cin >> n;
    vl a(n);
    ll mx = -inf;
    ll mn = inf;
    ll mxindex = 0;
    ll mnindex = 0;
    rep(i,n){
        cin >> a[i];
        if(mx<a[i]){
            mx = a[i];
            mxindex = i+1;
        }
        if(mn>a[i]){
            mn = a[i];
            mnindex = i+1;
        }
    }
    vpl ans;
    if(abs(mx)>abs(mn)){
        rep(i,n-1){
            while(a[i]>a[i+1]){
                ans.emplace_back(mxindex,i+2);
                a[i+1] += mx;
            }
            if(a[i+1]>mx){
                mx = a[i+1];
                mxindex = i+2;
            }
        }
    }else{
        for(ll i=n-1; i>0; i--){
            while(a[i]<a[i-1]){
                ans.emplace_back(mnindex,i);
                a[i-1] += mn;
            }
            if(a[i-1]<mn){
                mn = a[i-1];
                mnindex = i;
            }
        }
    }
    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,j;
	int num[3];
	int tmp;
	
	scanf("%d%d%d",&num[0],&num[1],&num[2]);
	
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(num[i]>num[j]){
				tmp=num[i];
				num[i]=num[j];
				num[j]=tmp;
			}
		}
	}
	
	printf("%d %d %d\n",num[0],num[1],num[2]);
	
	return 0;
}

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  */

signed main() {
  int n, m;
  cin >> n >> m;

  if(n == 1 and m == 0){
    cout << 0 << endl;
    return 0;
  }

  map<int, int> ma;
  char ans[n+1];
  rep(i, 0, n) ans[i] ='0';
  ans[0] = '1';
  ans[n] = '\0';
  rep(i, 0, m){
    int s, c;
    cin >> s >> c;
    if(n != 1 and s == 1 and c == 0){
      cout << -1 << endl;
      return 0;
    }
    if(ma.count(s) > 0 and ma[s] != c){
      cout << -1 << endl;
      return 0;
    }
    ma[s] = c;
    ans[s-1] = c+'0';
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys


def read():
    return sys.stdin.buffer.readline().rstrip()


def floor_sum(n, m, a, b):
    s = 0
    if a >= m:
        s += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        s += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return s
    s += (n - (x_max + a - 1) // a) * y_max
    s += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return s


def main():
    t = int(read())
    for _ in range(t):
        print(floor_sum(*map(int, read().split())))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9416
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	while (getline(cin,st)) {
		string ans;
		bool ok = true;
		if (st.size() % 2)ok = false;
		for (int i = 0; i < st.size(); ++i) {
			if (!isdigit(st[i]))ok = false;
			if ('0' == st[i] || '7' <= st[i])ok = false;
		}
		for (int i = 0; i < st.size() / 2; ++i) {
			string ast = st.substr(2 * i, 2);
			int num = (ast[0] - '1') * 5 + (ast[1] - '1');
			if (ast[1] >= '6')ok = false;
			if (0<=num&&num <= 25)ans += 'a' + num;
			else if (num == 26)ans += '.';
			else if (num == 27)ans += '?';
			else if (num == 28)ans += '!';
			else if (num == 29)ans += " ";
			else {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << ans << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3216
#include <stdio.h>
#include <stdlib.h>
 
int main(){
  int N = 0;
  if(scanf("%d",&N) == 0 ) exit(1);
  if ((N < 0 ) || ( N > 200)) exit(1);
  int count = 0;
  int hoge = 0;
  for(int i = 1; i <= N; i+=2){
    for(int j = 1; j <= i; j+=2){
      if(i % j == 0) hoge++;
    }
    if(hoge == 8) count++;
    hoge = 0;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128