akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val K = input.nextInt()
    val H = IntArray(N)
    
    for (i in H.indices) {
      H[i] = input.nextInt()
    }
    
    Arrays.sort(H)
    
    var attackCount = 0L
    if (H.size > K) {
      for (i in 0..(H.size - K - 1)) {
        attackCount += H[i]
      }
    }
    
    println (attackCount)
  }
}

Measured memory_bytes: 60936
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;cin >> s >> t;
  int ans=9999;
  for (int i=0;i<s.size()-t.size()+1;i++) {
  int ans_a=0;
    for (int j=0;j<t.size();j++) {
	  if (s[i+j]!=t[j]) ans_a++;
	}
	ans=min(ans,ans_a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
/*
-----------------------------------------------------------------------------
Author :            ---------------------------------------------------------
    UTKARSH SAXENA  ---------------------------------------------------------
    GOOGLE          ---------------------------------------------------------
-----------------------------------------------------------------------------
*/
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define fre freopen("0.in", "r", stdin), freopen("0.out", "w", stdout)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007
#define LL signed long long int
#define ps(x) push_back(x)
#define scan(x) scanf("%d", &x)
#define print(x) printf("%d\n", x)
#define scanll(x) scanf("%lld", &x)
#define printll(x) printf("%lld\n", x)
#define boost ios_base::sync_with_stdio(0)
// vector<int> g[2*100000+5];int par[2*100000+5];
int main() {
  int N;
  cin >> N;
  set<pair<int, int>> S;
  for (int i = 1; i <= N; ++i) {
    for (int j = i + 1; j <= N; ++j) {
      S.insert({i, j});
    }
  }
  if (N % 2 == 0)
    N++;
  for (int i = 1; i < N - i; ++i) {
    S.erase({i, N - i});
  }
  cout << S.size() << endl;
  for (auto x : S) {
    cout << x.first << ' ' << x.second << endl;
  }
}


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

typedef long long ll;
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD 10e9+7

void max_self(int& a, int b) { a=a>b?a:b; }
void min_self(int& a, int b) { a=a<b?a:b; }

using namespace std;

int n, k;

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

    if ( n < k)
        cout << 0;
    else
        cout << 10;
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
int main(){
    int n;cin>>n;
    string s[n];rep(i,0,n-1)cin>>s[i];
    bool noflag=true;
    rep(i,0,n-1)rep(j,0,n-1)if(s[i][j]=='#')noflag=false;
    if(noflag){cout<<-1;return 0;}
    
    ll tatec=0;
    rep(j,0,n-1){
        bool flag=true;
        rep(i,0,n-1){
            if(s[i][j]=='.'){
                flag=false;
            }
        }
        if(flag)tatec++;
    }
    ll restate=n-tatec;
    
    /*bool yoko[n];memset(yoko,false,sizeof(yoko));
    rep(j,0,n-1){
        rep(i,0,n-1){
            if(s[i][j]=='#')yoko[j]=true;
        }
    }*/
    
    ll yokomin=inf;
    rep(i,0,n-1){
        bool flag=false;
        rep(j,0,n-1){
            if(s[j][i]=='#')flag=true;
        }
        ll count=0;
        if(!flag)count=-1;
        rep(j,0,n-1){
            if(s[i][j]=='#')count++;
        }
        Min(&yokomin,n-count);
    }
    
    ll ans=restate+yokomin;
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
	int x;
	cin >> x;
	for (int i = 400, ind = 8; i < 1999; i += 200, ind--) {
		//cerr << i << " " << ind << '\n';
		if (i <= x && x <= i + 199) {
			cout << ind << '\n';
			break;
		}
	}
  return 0;
}


Measured memory_bytes: 3624
N = int(input())
A = input()
B = input()
C = input()
cnt = 0

for i in range(N):
    if(A[i] == B[i] == C[i]):
        cnt += 0
    elif(A[i] == B[i] or C[i] == A[i] or B[i] == C[i]):
        cnt += 1
    elif(A[i] != B[i] != C[i]):
        cnt += 2
print(cnt)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    ll X,K,D; cin>>X>>K>>D;
    if(abs(X)-abs(K*D)>=0){
        if(X<0)cout<<abs(X+K*D)<<endl;
        else cout<<abs(X-K*D)<<endl;
        return 0;
    }

    ll dist1 = abs(X%D);
    ll step = X/D;
    if((K-step)%2==0){
        // if(X<0)cout<<-dist1<<endl;
        // else cout<<dist1<<endl;
        cout<<abs(dist1)<<endl;
    }else{
        // if(X<0)cout<<D-dist1<<endl;
        // else cout<<dist1-D<<endl;
        cout<<abs(dist1-D)<<endl;
    }
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        String s = ns();
        for (int i = 0; i < s.length()-1; i++) {
            if(s.charAt(i) == s.charAt(i+1)){
                System.out.println(String.format("%d %d", i+1, i+2));
                return;
            }
        }
        for (int i = 0; i < s.length() -2; i++) {
            if(s.charAt(i) == s.charAt(i+2)){
                System.out.println(String.format("%d %d", i+1, i+3));
                return;
            }
        }
        System.out.println("-1 -1");
    }
    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 36564
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int k;
  cin >> k;
  
  int num[100010];
  REP(i,k) cin >> num[i];
  
  ll min = 2,max = 2;
  REP(i,k){
    
    min = num[k-1-i]* ceil((double)min/num[k-1-i]); //端数切り上げ
  //  debug(min);
    
    if(min > max) {
      cout << -1 << endl;
      return 0;
    }    
    
    int f = 0;
    if(max % num[k-1-i] == 0) f = 1;
    max = num[k-1-i]* ceil((double)max/num[k-1-i] + f) - 1;
   // debug(max);
    
  }
  
  cout << min << " " << max << endl;
    
 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#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 all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int a,b,c,cnt = 0;
    cin >> a >> b >> c;
    while(c){
        cnt++; c--;
        if(b){
            cnt++; b--;
        }
        else if(a){
            a--;
        }
        else break;
    }
    if(b) cnt += b;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
d = defaultdict(int)
for i in a:
    d[i] += 1
print("Yes"
if(
    (len(d) == 3 and len(set(d.values())) == 1 and n % 3 == 0 and (list(d.keys())[0] ^ list(d.keys())[1] ^ list(d.keys())[2] == 0))
    or (len(d) == 2 and n % 3 == 0 and d[0] == n // 3 and (0 in d.keys()))
    or (sum(a) == 0)
)
else "No")


Measured memory_bytes: 14460
require 'pp'
n = gets.to_i
a = gets.split.map(&:to_i)

cnt4 = a.count{|x|x % 4 == 0}
cnt2 = a.count{|x|x % 4 != 0 && x.even?}
cnt1 = a.count{|x|x.odd?}
# p cnt4
# p cnt2
# p cnt1
if cnt2.even?
  puts cnt1 <= cnt4 + 1 ? 'Yes' : 'No'
else
  puts cnt1 <= cnt4 ? 'Yes' : 'No'
end
# cnt1 + 1 == cnt4 がギリギリセーフ
# cnt2が奇数なら、cnt1 == cnt4 がぎりになる



# o x o x o


Measured memory_bytes: 8696
### constant

KEYS = {
  '1' => '.,!? ', '2' => 'abc', '3' => 'def', '4' => 'ghi', '5' => 'jkl',
  '6' => 'mno', '7' => 'pqrs', '8' => 'tuv', '9' => 'wxyz'
}

### main

klens = {}

for ch in KEYS.keys
  klens[ch] = KEYS[ch].length
end

n = gets.to_i

n.times do
  keystr = gets.strip
  #puts keystr

  ans = ''
  
  for word in keystr.split('0')
    next if word.empty?

    wch = word[0]
    ans += KEYS[wch][(word.length - 1) % klens[wch]]
  end

  puts ans
end

Measured memory_bytes: 6132
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}

int N,M,W,T;
string ss[10];
int vs[10];
int ps[10];
int ls[10];
int xs[10];
int ys[10];
vector<pii> sels[10];
int minDists[1<<7];
// 各町の組み合わせごとに，何がいくらで買えるかをリストアップ
vector<pii> wb[1<<7];
// 今のmaskにおいて，まだWの余裕があるときに獲得できる利益の最大数
int dp1[1<<7][10][10001];
// 現在の時間からえられる最大の利益
ll dp2[10001];

const int INF=1<<30;
int main(){
  while(cin>>N>>M>>W>>T&&(N|M|W|T)){
    map<string,int> dict;
    for(int i=0;i<10;i++)sels[i].clear();
    for(int i=0;i<M;i++){
      cin>>ss[i]>>vs[i]>>ps[i];
      int idx=dict.size();
      if(dict.count(ss[i])==0)dict[ss[i]]=idx;
    }
    for(int i=0;i<N;i++){
      cin>>ls[i]>>xs[i]>>ys[i];
      for(int j=0;j<ls[i];j++){
	int r,q;
	string s;
	cin>>s>>q;
	r=dict[s];
	sels[i].push_back(pii(r,q));
      }
    }
    // 各訪れる町の組み合わせごとの最短コストを求める
    for(int mask=0;mask<(1<<N);mask++){
      vector<int> v;
      for(int j=0;j<N;j++)if((mask>>j)&1)v.push_back(j);
      minDists[mask]=INF;
      do{
	pii cur=pii(0,0);
	int sum=0;
	for(int j=0;j<(int)v.size();j++){
	  sum+=abs(cur.second-xs[v[j]])+abs(cur.first-ys[v[j]]);
	  cur=pii(ys[v[j]],xs[v[j]]);
	}
	sum+=abs(cur.first)+abs(cur.second);
	minDists[mask]=min(minDists[mask],sum);
      }while(next_permutation(v.begin(),v.end()));
    }
    // 各訪れる町ごとに，かえる商品のリストを作成し，DP
    for(int mask=0;mask<(1<<N);mask++){
      map<int,int> m;
      for(int j=0;j<N;j++){
	if((mask>>j)&1){
	  for(int k=0;k<(int)sels[j].size();k++){
	    int idx=sels[j][k].first;
	    int val=sels[j][k].second;
	    if(val<ps[idx]){
	      if(m.count(idx)==0)
		m[idx]=ps[idx]-val;
	      else
		m[idx]=max(m[idx],ps[idx]-val);
	    }
	  }
	}
      }
      for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
	wb[mask].push_back(pii(it->first,it->second));
    }
    // 各訪れる町の組み合わせごとに，ある重みWにおいて，買うことのできる最大の利益を求めておく
    for(int mask=0;mask<(1<<N);mask++){
      for(int i=wb[mask].size();i>=0;i--){
	for(int j=0;j<=W;j++){
	  int res=0;
	  if(i!=(int)wb[mask].size()){
	    res=max(res,dp1[mask][i+1][j]);
	    if(j-vs[wb[mask][i].first]>=0)
	      res=max(res,dp1[mask][i][j-vs[wb[mask][i].first]]+wb[mask][i].second);
	  }
	  dp1[mask][i][j]=res;
	}
      }
    }
    // 時間Tにおいて，どのmaskを選べば最大の利益を選べるかを行うDP
    for(int i=0;i<=T;i++){
      ll res=0;
      for(int mask=0;mask<(1<<N);mask++)
	if(i-minDists[mask]>=0)res=max(res,dp2[i-minDists[mask]]+dp1[mask][0][W]);
      dp2[i]=res;
    }
    cout<<dp2[T]<<endl;
  }
  return 0;
}

Measured memory_bytes: 40000
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll V,W;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> A;
    cin >> V;

    cin >> B;
    cin >> W;

    cin >> C;

    if(V<=W) cout << "NO" << endl;
    else{
        ll diff =  abs(A-B);
        ll diff_v = abs(V-W);
        ll time = (diff-1) / diff_v;
        time++;
        if(time <= C) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define size 100005

int main() {
    int N, A[size], B[size], C[size], max1;
    int A_h[size], B_h[size], C_h[size];
    cin >> N; 

    for(int i=0; i<N; i++) {
       cin >> A[i] >> B[i] >> C[i];
    }

    A_h[0] = A[0]; B_h[0] = B[0]; C_h[0] = C[0]; 

    for(int i=1; i<N; i++) {
        A_h[i] = A[i] + max(B_h[i-1], C_h[i-1]);
        B_h[i] = B[i] + max(A_h[i-1], C_h[i-1]);
        C_h[i] = C[i] + max(B_h[i-1], A_h[i-1]);
    }

    max1 = max(A_h[N-1], B_h[N-1]);
    max1 = max(max1, C_h[N-1]);
    cout << max1 << endl;
    return 0;
}    
    

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	a := io.NextInts(n)
	count := 0
	for i := 0; i < n; i += 2 {
		if a[i]%2 == 1 {
			count++
		}
	}
	io.Println(count)
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#define MAX 2000000

int left(int);
int right(int);
int parent(int);
void swap(int [],int,int);
void buildMaxHeap(int []);
void maxHeapify(int [],int);
void insert(int [],int);
void heapIncreaseKey(int [],int,int);
int heapExtract(int []);

int H,A[MAX];

int main(){
  char com[20];
  int ans;
  int key;

  while (1){
    scanf("%s",com);

    if (strcmp(com,"insert") == 0){
      scanf("%d",&key);
      insert(A,key);
    }

    else if (strcmp(com,"extract") == 0){
      ans = heapExtract(A);
      printf("%d\n",ans);
    }

    else if (strcmp(com,"end") == 0)
      break;
  }
  return 0;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2 + 1;
}

int parent(int i){
  return i/2;
}

void swap(int A[],int a,int b){
  int temp;

  temp = A[a];
  A[a] = A[b];
  A[b] = temp;
}

void buildMaxHeap(int A[]){
  int i;

  for (i = H/2;i >= 1;i--)
    maxHeapify(A,i);
}

void maxHeapify(int A[],int i){
  int l,r,largest;

  l = left(i);
  r = right(i);

  if (l <= H && A[l] > A[i])
    largest = l;

  else
    largest = i;

  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i){
    swap(A,i,largest);
    maxHeapify(A,largest);
  }
  
}

void insert(int A[],int key){
  H++;
  A[H] = -INT_MAX;
  heapIncreaseKey(A,H,key);
}

void heapIncreaseKey(int A[],int i,int key){
  if (key < A[i]){
    fprintf(stderr,"新しいキーは現在のキーよりも小さい\n");
    exit(1);
  }

  A[i] = key;

  while (i > 1 && A[parent(i)] < A[i]){
    swap(A,i,parent(i));
    i = parent(i);
  }
}

int heapExtract(int A[]){
  int max;
  
  if (H < 1){
    fprintf(stderr,"ヒープアンダーフロー\n");
    exit(2);
  }

  max = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(A,1);

  return max;
}



Measured memory_bytes: 5592
#include <iostream>
#include <cstring>
#include <map>
using namespace std;

const int Q=200007;

char v[Q];
int n;

int mp[1<<26];



int main()
{
	//freopen("data.in", "r", stdin);

	cin>>v+1;
	n=strlen(v+1);

	mp[0]=1;

	int act=0;

	int best;

	for(int i=1; i<=n; i++)
	{
		act^=(1<<(v[i]-'a'));

		best=i;

		if(mp[act]!=0)
			best=mp[act];

		for(int poz=0; poz<26; poz++)
		{
			if(mp[act^(1<<poz)] < best && mp[act^(1<<poz)]!=0)
				best=mp[act^(1<<poz)];
		}
		if(mp[act]==0 || mp[act] > best+1)
			mp[act]=best+1;
	}

	cout<<best;


	return 0;
}

Measured memory_bytes: 262272
#include <iostream>
#include <algorithm>
#include <list>
#include <iterator>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }
    sort(A, A + N);
    long comfort_sum = 0;
    int k=1;
    for(int i=0; i < N-1;i++){
        comfort_sum += A[N-k];
        if(i%2==0) k++;
    }
    cout << comfort_sum;
    return 0;
}

Measured memory_bytes: 4548
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	string s;
	cin>>s;
	bool y=true;
	for(int i=0;i<(s.size()-1);i++){
		for(int j=i+1;j<s.size();j++){
			if(s[i]==s[j]){
				y=false;
				break;
			}
		}
		if(!y){
			break;
		}
	}
	if(y){
		cout<<"yes";
	}
	else{
		cout<<"no";
	}
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
//#define int long long

 //bool dp[2][4000001];

signed main(){
   int n,m;
   cin >> n>>m;
   
   int a[n][m+1],u;
   for(int i=0;i<n;i++)for(int j=0;j<m;j++){
       cin >>u;
       a[i][j]=u-1;
   }
   for(int i=0;i<n;i++)a[i][m]=m;
   vector<int> sanka[m];
   int jun[n]={};
   int s[m+1]={},maxs,t=1;
   //cerr<<'u';
   for(int i=0;i<n;i++)sanka[a[i][0]].push_back(i);
  // cerr<<'u';
   while(t!=-1){
    maxs=0;
    for(int i=0;i<m;i++)maxs=max(maxs,int(sanka[i].size()));
    t=1;
    while(t==1){
        t=0;
        for(int i=0;i<m;i++){
            if(sanka[i].size()>=maxs){
                t=1;
                s[i]=1;
                while(!sanka[i].empty()){
                    int t=sanka[i].back();
                    sanka[i].pop_back();
                    while(s[a[t][jun[t]]]==1)jun[t]++;
                   if(jun[t]!=m) sanka[a[t][jun[t]]].push_back(t);
                }
            }
        }
        if(jun[0]==m)t=-1;
    }
   }
   cout <<maxs;


    return 0;
}


Measured memory_bytes: 1152
n,*a=map(int,open(0).read().split())
a.sort()
l=[]
if a[-1]>=0>a[0]:
  a,b=[t for t in a if t>=0],[t for t in a if t<0]
  c,y=a.pop(),b.pop()
  while b:
    t=b.pop()
    l.append((c,t))
    c-=t
  while a:
    t=a.pop()
    l.append((y,t))
    y-=t
  l.append((c,y))
  c-=y
elif a[0]>=0:
  s,*a,c=a
  while a:
    t=a.pop()
    l.append((s,t))
    s-=t
  l.append((c,s))
  c-=s
else:
  *a,c=a
  while a:
    t=a.pop()
    l.append((c,t))
    c-=t
print(c)
for t in l:print(*t)

Measured memory_bytes: 18940
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  long long a;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    int x = 0;
    while (a) {
      if (a % 2 != 0) 
        break;
      ++x;
      a /= 2;
    }
    ans += x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int C[15][15], dp[15][17];

int main() {
  for (;;) {
    int X, Y;
    cin >> X >> Y;
    if (!X && !Y) return 0;
    for (int y = 0; y < Y; y++)
      for (int x = 0; x < X+2; x++) {
        C[y][x] = 1;
        dp[y][x] = 0;
      }
    for (int y = 0; y < Y; y++)
      for (int x = 1; x <= X; x++)
        cin >> C[y][x];
    for (int x = 1; x <= X; x++)
      if (!C[0][x])
        dp[0][x] = 1;
    for (int y = 1; y < Y; y++)
      for (int x = 1; x <= X; x++) {
        switch (C[y][x]) {
        case 1:
          break;
        case 0:
          dp[y][x] += (C[y-1][x-1] ? 0 : dp[y-1][x-1]) +
                      (C[y-1][x+1] ? 0 : dp[y-1][x+1]);
        case 2:
          if (y >= 2 && C[y-2][x] == 2)
            dp[y][x] += dp[y-2][x];
          dp[y][x] += C[y-1][x] ? 0 : dp[y-1][x];
          break;
        default:
          break;
        }
      }
    int s = 0;
    for (int x = 1; x <= X; x++)
      s += dp[Y-1][x];
    if (Y >= 2)
      for (int x = 1; x <= X; x++)
        if (C[Y-2][x] == 2)
          s += dp[Y-2][x];
    cout << s << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
 int main()
{
 char s[2048];
 int i;
 fgets(s, sizeof(s), stdin);
 for(i = 0;
s[i] != '\0';
i++)
{
 if('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a';
 else if('A' <= s[i] && s[i] <= 'Z') s[i] += 'a' - 'A';
 }
 printf("%s",s);
 return 0;
 } 


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

#define MOD 1000000007LL

long long fac[1000001],finv[1000001],inv[1000001];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<1000001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
long long MODpow(long long a,int b){
	if(b==0)return 1;
	if(b%2==0){
		long long t=MODpow(a,b/2);
		return (t*t)%MOD;
	}
	return (a*MODpow(a,b-1))%MOD;
}

int main(){
	int N,K;
	cin >> N >> K;
	long long ans=0;
	vector<long long> a(K+1,0);
	for(int k=K;k>0;k--){
		long long add=MODpow(K/k,N);
		int x=2*k;
		while(x<=K){
			add=(add-a[x]+MOD)%MOD;
			x+=k;
		}
		a[k]=add;
	}
	for(int k=1;k<=K;k++)ans=(ans+((k*a[k])%MOD))%MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4044
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=4050;
//ここまでテンプレ
int main(){
	string S,T;
	cin>>S>>T;
	S='@'+S;
	T='@'+T;
	//DS[i][0 or 1]=S[i]の次に0 or 1が現れる場所のindex
	//length()に-2(終了を意味する),
	int DS[SIZE][2]={},DT[SIZE][2]={};
	for(int i:{0,1}){
		DS[S.length()-1][i]=-1;
		DT[T.length()-1][i]=-1;
	}
	//DSの遷移
	for(int i=S.length()-2;i>=0;i--){
		for(int j:{0,1}){
			DS[i][j]=(S[i+1]-'0'==j?i+1:DS[i+1][j]);
		}
	}
	//DTの遷移
	for(int i=T.length()-2;i>=0;i--){
		for(int j:{0,1}){
			DT[i][j]=(T[i+1]-'0'==j?i+1:DT[i+1][j]);
		}
	}
	for(int i:{0,1}){
		DS[S.length()][i]=-2;
		DT[T.length()][i]=-2;
	}
	//DP[i][j]=S[i],T[j]以降(自身を含まない)の文字列の最小共通非部分列の長さ
	int DP[SIZE][SIZE]={};
	for(int i=0;i<SIZE;i++)
		for(int j=0;j<SIZE;j++)
			DP[i][j]=INF;
	//DPの遷移
	for(int i=S.length();i>=0;i--){
		for(int j=T.length();j>=0;j--){
			for(int k:{0,1}){
				if(DS[i][k]==-2 && DT[j][k]==-2){
					DP[i][j]=0;
				}
				else if(DS[i][k]==-2){
					if(DT[j][k]==-1)
						DP[i][j]=1;
					else
						DP[i][j]=min(DP[i][j],DP[S.length()][DT[j][k]]+1);
				}
				else if(DT[j][k]==-2){
					if(DS[i][k]==-1)
						DP[i][j]=1;
					else
						DP[i][j]=min(DP[i][j],DP[DS[i][k]][T.length()]+1);
				}
				else{
					if(DS[i][k]==-1 && DT[j][k]==-1)
						DP[i][j]=1;
					else if(DS[i][k]==-1)
						DP[i][j]=min(DP[i][j],DP[S.length()][DT[j][k]]+1);
					else if(DT[j][k]==-1)
						DP[i][j]=min(DP[i][j],DP[DS[i][k]][T.length()]+1);
					else
						DP[i][j]=min(DP[i][j],DP[DS[i][k]][DT[j][k]]+1);
				}
			}
		}
	}
	//構築
	string U;
	int Sidx=0,Tidx=0;	//今見ているindex
	while(1){
		//DPの小さい方に飛ぶ(0優先)
		int Snxt=0,Tnxt=0;	//次に見るindex
		if(DP[Sidx][Tidx]==0)
			break;
		//0に飛ぶとき
		if(DP[(DS[Sidx][0]<=-1?S.length():DS[Sidx][0])][(DT[Tidx][0]<=-1?T.length():DT[Tidx][0])]<=DP[(DS[Sidx][1]<=-1?S.length():DS[Sidx][1])][(DT[Tidx][1]<=-1?T.length():DT[Tidx][1])]){
			Snxt=(DS[Sidx][0]<=-1?S.length():DS[Sidx][0]);
			Tnxt=(DT[Tidx][0]<=-1?T.length():DT[Tidx][0]);
			U+='0';
		}
		//1に飛ぶとき
		else{
			Snxt=(DS[Sidx][1]<=-1?S.length():DS[Sidx][1]);
			Tnxt=(DT[Tidx][1]<=-1?T.length():DT[Tidx][1]);
			U+='1';
		}
		Sidx=Snxt;
		Tidx=Tnxt;
	}
	cout<<U<<endl;
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define F first
#define S second

int n, k, ans = 0, a[100010];
vector<int> g[100010];
int d[100010];
int life[100010], b[100010], sz = 0;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (i == 1) {
      if (a[i] != 1) {
        ans++;
      }
    }
    else {
      g[a[i]].push_back(i);
    }
  }
  queue<int> q;
  d[1] = 1;
  q.push(1);
  while (q.size()) {
    int x = q.front(); q.pop();
    b[sz++] = x;
    for (int y : g[x]) {
      d[y] = d[x] + 1;
      q.push(y);
    }
  }
  REPE(i, 1, n) {
    life[i] = k;
  }
  while (sz--) {
    if (sz == 0) break;
    int x = b[sz];
    if (life[x] == 1) {
      ans += a[x] != 1;
    }
    else {
      life[a[x]] = min(life[a[x]], life[x] - 1);
    }
  }
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 7296
n=gets.to_i
s=[0,1].map{gets.chomp}
pre_pattern=:none
cnt=1
i=0
while i<n
  case pre_pattern
  when :none
    if s[0][i]==s[1][i]
      x=3
      pre_pattern=:tate
    else
      x=6
      pre_pattern=:yoko
      i+=1
    end
  when :tate
    if s[0][i]==s[1][i]
      x=2
      pre_pattern=:tate
    else
      x=2
      pre_pattern=:yoko
      i+=1
    end
  when :yoko
    if s[0][i]==s[1][i]
      x=1
      pre_pattern=:tate
    else
      x=3
      pre_pattern=:yoko
      i+=1
    end
  end
  cnt = cnt*x%1000000007
  i+=1
end

p cnt

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
typedef long long ll;

void ans(bool qus)
{
    if (qus == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool qust)
{
    if (qust == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

/////////////////////////////////////////

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout << c << endl;
    }
    else if(b==c){
        cout << a << endl;
    }
    else
        cout << b << endl;
}


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

int main() {
	char s;
  	vector<vector<char>> vec(3,vector<char>(3));
  	
    for(int i= 0; i < 3; i++) {
    	for(int j = 0; j < 3; j++){
        cin >> vec.at(i).at(j);
        }
    }
  
  	  for(int i= 0; i < 3; i++) {
    	for(int j = 0; j < 3; j++){
        if(i == j) {
        		cout << vec.at(i).at(j);
        	}
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string s;
  cin >> s;

  ll l = s.size();
  cout << s[0] << l - 2 << s[l - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Jan 12 21:05:35 2019
//
package main

import "fmt"

const (
	WHITE = '.'
	BLACK = '#'
)

func dfs(board []string, kinds [][]int, x, y int, index int, color rune) {
	if rune(board[x][y]) == color {
		kinds[x][y] = index

		for _, d := range [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} {
			dx := x + d[0]
			dy := y + d[1]
			nextColor := WHITE
			if color == nextColor {
				nextColor = BLACK
			}

			if 0 <= dx && dx < len(board) && 0 <= dy && dy < len(board[0]) && kinds[dx][dy] == 0 {
				dfs(board, kinds, dx, dy, index, nextColor)
			}
		}

	}
}

func routes(board []string, kinds [][]int, x, y int, index int) {
	dfs(board, kinds, x, y, index, rune(board[x][y]))
}

type pair struct {
	x, y int
}

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	board := make([]string, H)
	for i := range board {
		fmt.Scan(&board[i])
	}

	kinds := make([][]int, len(board))
	for i := range kinds {
		kinds[i] = make([]int, len(board[0]))
	}

	index := 1
	for i := range board {
		for j := range board[i] {
			if kinds[i][j] == 0 {
				routes(board, kinds, i, j, index)
				index++
			}
		}
	}

	m := map[int]*pair{}
	for i := range board {
		for j := range board[i] {
			if _, ok := m[kinds[i][j]]; !ok {
				if board[i][j] == WHITE {
					m[kinds[i][j]] = &pair{y: 1}
				} else {
					m[kinds[i][j]] = &pair{x: 1}
				}
			} else {
				if board[i][j] == WHITE {
					m[kinds[i][j]].y++
				} else {
					m[kinds[i][j]].x++
				}
			}
		}
	}
	ans := 0
	for _, p := range m {
		ans += p.x * p.y
	}
	fmt.Println(ans)
}


Measured memory_bytes: 115456
/*
 * Fast UNION(サイズによるUNION) + 経路圧縮
 * (入門データ構造とアルゴリズム(オライリー)8章)
 */
#include <stdio.h>

#define N 100000

/* 互いに素な集合を木で表す配列: */
/* 負の値: この要素は根であり、値はその木の要素数*(-1) */
/* 正の値: 親要素のインデックス */
int S[N+1];

/* 各場所に置いてある数字 */
int P[N+1];

/* 経路圧縮のためのワーク */
int W[N+1];

void makeset(int size) {
    int i;
    /* 自身のみを含む1要素の集合に属するように初期化 */
    for (i = 1; i <= size; i++) {
        S[i] = -1; /* 根であり要素数は1 */
    }
}

/* 経路圧縮つきfind(非再帰版) */
int find(int x) {
    int *w, *ww;

    for (w = W; S[x] > 0; w++) {
        *w = x;
        x = S[x];
    }

    for (ww = W; ww < w; ww++) {
        S[*ww] = x;
    }


    return x;
}

void merge(int x, int y) {
    int root1 = find(x);
    int root2 = find(y);

    if (root1 == root2) {
        return;
    }

    /* 要素数が少ない方を子にする。*/
    /* 要素数を-1倍して格納しているので不等号の向きに注意 */
    if (S[root2] < S[root1]) {
        /** root1をroot2の子にする */
        S[root2] += S[root1];
        S[root1] = root2;
    } else {
        /** root2をroot1の子にする */
        S[root1] += S[root2];
        S[root2] = root1;
    }
}

int main()
{
    int i;
    int n, m;
    int x, y;
    int r;

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

    makeset(n);

    for (i = 1; i <= n; i++) {
        scanf("%d", &P[i]);
    }

    for (i = 1; i <= m; i++) {
        scanf("%d %d", &x, &y);
        merge(x, y);
    }

    r = 0;
    for (i = 1; i <= n; i++) {
        if (find(i) == find(P[i])) {
            r++;
        }
    }

    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 896
X = int(input())
if 400 <= X < 600: print(8)
elif 600 <= X < 800: print(7)
elif 800 <= X < 1000: print(6)
elif 1000 <= X < 1200: print(5)
elif 1200 <= X < 1400: print(4)
elif 1400 <= X < 1600: print(3)
elif 1600 <= X < 1800: print(2)
elif 1800 <= X < 2000: print(1)

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

int get_min(string str)
{
  int min = 10001;
  for (char& c : str) 
    if (min > c)
      min = c;
  return min;
}
int get_max(string str)
{
  int max = -1;
  for (char& c : str) 
    if (max < c)
      max = c;
  return max;
}
int num_num(string str, int num)
{
  int numa = 0;
  for (char &c : str) {
    if (c == (char)num)
       numa += 1;
  }
  return numa;
}

int main()
{
  string s, t;
  cin >> s;
  cin >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), std::greater<char>());
//  cout << s << endl;
//  cout << t << endl;
  if (s.compare(t) < 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
//  if (get_min(s) < get_max(t)) 
//    printf("Yes\n");
//  else if (get_min(s) > get_max(t))
//    printf("No\n");
//  else if (get_min(s) == get_max(t)) {
//    if (num_num(
//  }
   
  
}


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

#define FasterIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(), v.end()
const int MOD = 1e9+7;

int main(){
    FasterIO;

    int n;

    while(cin>>n){
        int data[n], temp[n];

        for(int i=0; i<n; i++){
            cin>>data[i];
            temp[i] = data[i];
        }

        sort(temp, temp+n, greater<>());

        for(int i=0; i<n; i++){
            if(data[i]==temp[0])
                cout<<temp[1]<<endl;
            else
                cout<<temp[0]<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3200
n, m = map(int, input().split())
a = [-1] * n

is_possible = True
for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    if a[s] == -1:
        a[s] = c
    elif a[s] != c:
        is_possible = False

if n > 1 and a[0] == 0:
    is_possible = False

if is_possible:
    if a[0] == -1:
        if n > 1:
            a[0] = 1
        else:
            a[0] = 0

    for i in range(1, n):
        if a[i] == -1:
            a[i] = 0
    ans = ''.join([str(ai) for ai in a])
else:
    ans = -1

print(ans)


Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int kingaku;
int main()
{
  int hyaku,gozyu,zyuu,gohya;
  int ans1,ans2,ans3,ans4;
  bool flag = true;
  while(cin>>kingaku,kingaku){
    cin >>zyuu>>gozyu>>hyaku>>gohya;
    ans1 = ans2 = ans3=ans4=0;
    int sum = zyuu*10+gozyu*50+hyaku*100+gohya*500-kingaku;
    ans4 = sum/500;
    sum -= ans4*500;
    ans3 = sum/100;
    sum -=ans3*100;
    ans2 = sum/50;
    sum -=ans2*50;
    ans1 = sum/10;
    sum -=ans1*10;
    if(flag)flag = false;
    else cout <<endl;
    if((zyuu-=ans1)>0)
      cout <<10 <<' '<<zyuu<<endl;
    if((gozyu-=ans2)>0)
      cout <<50 <<' '<<gozyu<<endl;
    if((hyaku-=ans3)>0)
      cout <<100 <<' '<<hyaku<<endl;
    if((gohya-=ans4)>0)
      cout <<500 <<' '<<gohya<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
vector<vector<LL>> edge;
LL hako[100100];
LL flag[100100];
  queue<pair<LL,LL>>q;
int main(){
  fill(flag,flag+100100,BIG_NUM);
  edge = vector<vector<LL>>(100100,vector<LL>(0,0));
  LL n,m;
  cin >> n >> m;
  for(LL i=0;i<m;i++){
    LL a,b;
    cin >> a >> b;
    edge[b].push_back(a);
  }
  LL s,g;
  cin >> s >> g;
  q.push(make_pair(g,0));
  while(q.size() != 0){
    pair<LL,LL>pair;
    pair = q.front();
    q.pop();
    if((1 << (pair.second % 3)) & hako[pair.first])continue;
    hako[pair.first] |= 1 << (pair.second % 3);
    if(pair.second % 3 ==0)flag[pair.first] = min(flag[pair.first],pair.second);
    for(LL i=0;i<edge[pair.first].size();i++){
      q.push(make_pair(edge[pair.first][i],pair.second+1));
    }
  }
  if(hako[s] & (1<<0)){
    cout << flag[s] / 3 << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}



Measured memory_bytes: 7416
H, W = map(int, input().split())

field = [list(input()) for _ in range(H)]
count = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            count += 1
            
if count <= (H + W - 1):
    print('Possible')
else:
    print('Impossible')


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


n = int(input())
info = [list(map(int, input().split())) for i in range(n-1)]
MOD = 10**9 + 7

tree = [[] for i in range(n)]
for i in range(n-1):
    x, y = info[i]
    x -= 1
    y -= 1
    tree[x].append(y)
    tree[y].append(x)

def solve(pos):
    b = 1
    w = 1
    flag = False
    for next_pos in tree[pos]:
        if not visited[next_pos]:
            visited[next_pos] = True
            flag = True
            tmp_b, tmp_w = solve(next_pos)
            w *= (tmp_b + tmp_w)
            b *= tmp_w
            w %= MOD
            b %= MOD
    if not flag:
        black[pos] = 1
        white[pos] = 1
        return (black[pos], white[pos])
    else:
        black[pos] = b
        white[pos] = w
        return (black[pos], white[pos])

black = [0]*n
white = [0]*n
visited = [False]*n
visited[0] = True
print(sum(solve(0)) % MOD)

Measured memory_bytes: 122012
#include <iostream>
#include <map>
using namespace std;
const int MAX = 26;
int G[MAX][MAX],n,visit[MAX];
string str;
bool flg;

void dfs(int pos){
  visit[pos] = 0;
  for(int i = 0 ; i < 26 ; i++){
    if(G[pos][i]&&visit[i]){
      G[pos][i]--;
      dfs(i);
    }
  }
}

int main(){
  while(cin >> n,n){
    map<char,int> in,out;
    fill(G[0],G[MAX],0);
    fill(visit,visit+MAX,0);
    for(int i = 0 ; i < n ; i++){
      cin >> str;
      in[str[0]]++; out[str[str.size()-1]]++;
      visit[str[0]-'a'] = visit[str[str.size()-1]-'a'] = 1;
      G[str[0]-'a'][str[str.size()-1]-'a']++;
    }
    flg = false;
    for(char j = 'a' ; j <= 'z'; j++){
      if(in[j] != out[j]) flg = true;
    }
    if(!flg){
      dfs(str[str.size()-1]-'a');
      for(int i = 0 ; i < 26 ; i++){
	if(visit[i]) flg = true;
      }
      if(flg) cout << "NG" << endl;
      else cout << "OK" << endl;
    }
    else cout << "NG" << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dI = { 0, 1, 0, -1 };
        static readonly int[] dJ = { 1, 0, -1, 0 };
        //static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>>G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            var p = cin.ReadSplitLong();
            Console.WriteLine(500 * p[0] >= p[1] ? "Yes" : "No");

            //Console.Out.Flush();
        }
        struct Edge
        {
            public int from;

            public int to;
            public long dist;
            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }

        }
    }
    public class Scanner
    {
        public int[] ReadSplitInt()
        {
            return ConvertAll(Console.ReadLine().Split(), int.Parse);
        }
        public long[] ReadSplitLong()
        {
            return ConvertAll(Console.ReadLine().Split(), long.Parse);
        }
        public double[] ReadSplit_Double()
        {
            return ConvertAll(Console.ReadLine().Split(), double.Parse);
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }

        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }

        static public long LPow(int a, int b)
        {
            return (long)Pow(a, b);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	map<int, int> mp;
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mp[A[i]]++;
	}
	int M;
	cin >> M;
	vector<int> B(M);
	bool f = true;
	for (int i = 0; i < M; i++) {
		cin >> B[i];
		mp[B[i]]--;
		if (mp[B[i]] < 0) {
			f = false;
		}
	}
	if (f) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int k = (a + b) / 2;
    if (ceil((double)(a + b) / 2) == floor((double)(a + b) / 2)) {
        cout << k << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


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

#define R register

int N, K;
string s, las, res;

int main() {
	cin >> s;
	N = s.length();
	for(R int i = 0; i < N; ++i) {
		res += s[i];
		if(res != las) ++K, las = res, res.clear();
	}
	return !printf("%d\n", K);
}


Measured memory_bytes: 640
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    dp = [INF for i in range(1 << N)]
    dp[0] = 0

    key = []
    for _ in range(M):
        a, b = map(int, input().split())
        C = tuple(map(lambda x: int(x) - 1, input().split()))
        status = 0
        for c in C:
            status += 2 ** c
        key.append((a, status))

    for a, status in key:
        if dp[status] > a:
            dp[status] = a

    for i in range(2 ** N - 1):
        for a, status in key:
            new_status = status | i
            if dp[new_status] > dp[i] + a:
                dp[new_status] = dp[i] + a

    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


if __name__ == "__main__":
    main()


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll lim = 1e5;
  vector<ll> k(lim + 1);
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    k.at(a)++;
  }
  ll even = 0;
  ll odd = 0;
  for (ll i = 1; i <= lim; i++) {
    if (k.at(i) == 0) continue;
    if (k.at(i) % 2 == 0) even++;
    else odd++;
  }
  if (even % 2 == 0) {
    cout << even + odd << endl;
  }else {
    cout << even + odd - 1 << endl;
  }
  

  return 0;
}



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

int main()
{
    string s;
    bool f1 = true, f2 = true, f3 = true;
    cin >> s;
    int sz = s.size();

    REP(i, (sz - 1) / 2 - 1)
    {
        if (s.at(i) != s.at(sz - 1 - i))
            f1 = false;
    }

    REP(i, (sz - 1) / 2 - 1)
    {
        if (s.at(i) != s.at((sz - 1) / 2 - i - 1))
            f2 = false;
    }

    REP(i, (sz - 1) / 2 - 1)
    {
        if (s.at(i + (sz - 1) / 2 + 1) != s.at(sz - 1 - i))
            f3 = false;
    }

    if (f1 && f2 && f3)
    {
        cout << "Yes"
             << "\n";
    }
    else
    {
        cout << "No"
             << "\n";
    }
  //  cout << f1 << f2 << f3 << "\n";
    return 0;
}


Measured memory_bytes: 256