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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for(int i = 0;i < n;++i)
			v[i] = sc.nextInt();
		sc.close();
		
		int ans = 0;
		
		Map<Integer, Integer> map1 = new HashMap<Integer, Integer>();
		for(int i = 0;i < n;i+=2) {
			if(map1.containsKey(v[i])) {
				int cap = map1.get(v[i]);
				map1.remove(v[i]);
				map1.put(v[i], cap+1);
			}else {
				map1.put(v[i], 1);
			}
		}
		Map<Integer, Integer>map2 = new HashMap<Integer, Integer>();
		for(int i = 1;i < n;i+=2) {
			if(map2.containsKey(v[i])) {
				int cap = map2.get(v[i])+1;
				map2.remove(v[i]);
				map2.put(v[i], cap);
			}else {
				map2.put(v[i], 1);
			}
		}
		
		int max1_1 = 0;
		int max1_2 = 0;
		int max1_key = 0;
		for(Integer key : map1.keySet()) {
			if(max1_1 < map1.get(key)) {
				max1_key = key;
				max1_1 = map1.get(key);
			}
		}
		for(Integer key : map1.keySet()) {
			if(max1_2 < map1.get(key) && key != max1_key) {
				max1_2 = map1.get(key);
			}
		}
		
		int max2_1 = 0;
		int max2_2 = 0;
		int max2_key = 0;
		for(Integer key : map2.keySet()) {
			if(max2_1 < map2.get(key)) {
				max2_key = key;
				max2_1 = map2.get(key);
			}
		}
		for(Integer key : map2.keySet()) {
			if(max2_2 < map2.get(key) && key != max2_key) {
				max2_2 = map2.get(key);
			}
		}
		
		if(max1_key == max2_key) {
			int num1 = max1_1 + max2_2;
			int num2 = max1_2 + max2_1;
			if(num1 > num2) {
				ans += n/2 - max1_1;
				ans += n/2 - max2_2;
			}else {
				ans += n/2 - max1_2;
				ans += n/2 - max2_1;
			}
		}else {
			ans += n/2 - max1_1;
			ans += n/2 - max2_1;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 59384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N, K , S;
    cin >> N >> K >> S;

    if(S == 1000000000){
        for (ll i = 0; i < K; i++) {
            printf("%lld ", S);
        }   
        for (ll i = K; i < N; i++) {
            printf("1 ");
        }
    }
    else{
        for (ll i = 0; i < K; i++) {
            printf("%lld ", S);
        }   
        for (ll i = K; i < N; i++) {
            printf("1000000000 ");
        }
    }


}

Measured memory_bytes: 1280
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  int cnt = 0;
  for (char c : S) if (c == 'R') ++cnt;

  if (cnt <= 1 || cnt == 3) {
    cout << cnt << endl;
  } else {
    if (S[0] == S[1] || S[1] == S[2]) cout << 2 << endl;
    else                              cout << 1 << endl;
  }
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int H, W;
    cin >> H >> W;

    vector<string> board;
    inputVector(board, H);

    bool h[110], w[110];

    rep(y, H) {
        h[y] = true;
        rep(x, W) {
            h[y] &= board[y][x] == '.';
        }
    }

    rep(x, W) {
        w[x] = true;
        rep(y, H) {
            w[x] &= board[y][x] == '.';
        }
    }

    rep(y, H) {
        if (h[y]) continue;
        rep(x, W) {
            if (w[x]) continue;
            cout << board[y][x];
        }
        cout << endl;
    }
}


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

Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>
#define N 500000

int L[N/2+2],R[N/2+2],cnt=0;
void merge(int *,int,int,int,int);
void mergeSort(int*,int,int,int);
int main()
{
  int n,i;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  mergeSort(A,n,0,n);

  for(i=0;i<n;i++){
    if(i!=n-1)
      printf("%d ",A[i]);
    else
      printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}

void merge(int *A,int n,int left,int mid,int right)
{
  int n1 = mid-left;
  int n2 = right-mid;
  int i,j,k;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=R[n2]=2000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k]=L[i++];
    else A[k] = R[j++];
                         }
}

void mergeSort(int *A,int n,int left,int right)
{
  int mid;
  if(left+1<right){
  mid=(left+right)/2;
  mergeSort(A,n,left,mid);
  mergeSort(A,n,mid,right);
  merge(A,n,left,mid,right);
                   }
}





Measured memory_bytes: 5752
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, d = MI()
    ans = 0
    for i in range(n):
        x, y = MI()
        if x ** 2 + y ** 2 <= d ** 2:
            ans += 1

    print(ans)


main()


Measured memory_bytes: 68580
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <math.h>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
#include <unordered_map>
using namespace std;
typedef long long ll;
ll ans, mx, sum,temp, mn = 1e14, flag,cnt;


int main(){
	ll n;
	cin>>n;
	if(n==1) cout<<0;
	else cout<<1;
} 

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D; cin>>A>>B>>C>>D;
  int ans=0;
  for(int i=0;i<=3000;i++){
    for(int j=0;j<=3000;j++){
      if(D-i*A-j*B>=0&&(D-i*A-j*B)%C==0)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3520
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	n := len(s)

	ans := 0
	for i, l := 0, 0; i < n; i++ {
		switch s[i] {
		case 'A', 'G', 'C', 'T':
			l++
		default:
			ans = max(ans, l)
			l = 0
		}
		if i == n-1 {
			ans = max(ans, l)
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int tmp = x;
        x = y;
        y = tmp;
        tmp = x;
        x = z;
        z = tmp;


        System.out.println(x+" "+y+" "+z);
    }
}

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

const int maxn = 200 * 1000 + 20;
int n, k, l;
vector <int> adj[2][maxn];
int vis[2][maxn], cnt_moalefe[2];
map <pair<int, int>, int> eshterak;

void input() {
    cin >> n >> k >> l;
	for(int i = 0, a, b; i < k; i++) {
        cin >> a >> b;
		adj[0][a].push_back(b);
		adj[0][b].push_back(a);
	}
	for(int i = 0, a, b; i < l; i++) {
		cin >> a >> b;
		adj[1][b].push_back(a);
		adj[1][a].push_back(b);
	}
}

void dfs(int v, int t) {
    vis[t][v] = cnt_moalefe[t];
    for (int i : adj[t][v])
        if (!vis[t][i])
            dfs(i, t);
}

int main() {    
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    input();
    for(int i = 1; i <= n; i++) {
		if(!vis[0][i]) {
            cnt_moalefe[0]++;
            dfs(i, 0);
        }
		if(!vis[1][i]) {
            cnt_moalefe[1]++;
            dfs(i, 1);
        }
	}
    for (int i = 1; i <= n; i++)
        eshterak[make_pair(vis[0][i], vis[1][i])]++;
    for (int i = 1; i <= n; i++) 
        cout << eshterak[make_pair(vis[0][i], vis[1][i])] << ' ';
    cout << endl;
    return 0;    
}



Measured memory_bytes: 27904
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);

            System.out.println(C <= A + B ? "Yes" : "No");
        }
    }
}


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

int main() {
	int N;
    cin >> N;
    vector<int> kagamimochi(N);
    for(int i = 0; i < N ; i++){
    	cin >> kagamimochi.at(i);
    }
    sort(kagamimochi.begin(), kagamimochi.end());
    int count = 0;
    int size = 0;
    int konkai;
    for(int i = 0; i < N ; i++){
    	konkai = kagamimochi.at(i);
        if(size == konkai){
        	continue;
        }else{
        	size = konkai;
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3604
'''
Created on 2019/09/28

@author: oiwaiman
'''

import heapq as hq

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [-i for i in A]
hq.heapify(B)
for i in range(M):
    a_largest = int((-B[0])/2)
    a_list = hq.heappushpop(B, -a_largest)

sum = 0
for j in range(N):
    sum -= B[j]

print(sum)


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

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
  int n,m;
  cin >> n >> m;
  int s[m][n+1];
  rep(i,m) {
    cin >> s[i][0];
    rep(j,s[i][0]) {
      cin >> s[i][j+1];
      s[i][j+1]--;
    }
  }
  int p[m];
  rep(i,m) cin >> p[i];
  int ans = 0;
  rep(i,1<<n) {
    bool flag = true;
    rep(j,m) {
      int cnt = 0;
      rep(k,s[j][0]) {
        if (i>>s[j][k+1]&1) cnt++;
      }
      if (cnt%2 != p[j]) flag = false;
    }
    if (flag) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
    private void solve() {
        String s = in.next();
        int[] counter = new int[256];
        loop: {
            for (int i = 2; i < 5; ++i) {
                for (int j = 0; j + i <= s.length(); ++j) {
                    Arrays.fill(counter, 0);
                    for (int k = j; k < j + i; ++k) {
                        counter[s.charAt(k)]++;
                    }
                    for (int k = 0; k < 256; ++k) {
                        if (counter[k] > (i / 2)) {
                            out.println((j + 1) + " " + (j + i));
                            break loop;
                        }
                    }
                }
            }
            out.println("-1 -1");
        }
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }

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

    private FastScanner in;
    private PrintWriter out;


    private void run() {
        try {
            in = new FastScanner();
            out = new PrintWriter(new BufferedOutputStream(System.out));
            solve();
        } catch (Exception e) {
            throw e;
        } finally {
            out.close();
        }
    }


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




Measured memory_bytes: 10936
import java.util.*;

public class Main {
    public static  void main(String  args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int max = x;
        int min = x;
        long sum = x;
        for (int i = 1; i < n; i++) {
        	x = sc.nextInt();
        	if (max < x) max = x;
        	if (min > x) min = x;
        	sum += x;
	
        }
        System.out.printf("%d %d %d\n", min, max, sum);
    }
}

Measured memory_bytes: 42020
<?php
fscanf(STDIN, '%d %d', $n, $k);
$high_s = fgets(STDIN);
$exploded_high_s = explode(' ', trim($high_s));

$count = 0;
foreach ($exploded_high_s as $high) {
	if ($high >= $k) {
		$count++;
    }
}
echo $count;

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

int main() {
  int N,a,b,c,d;
  cin>>N;
  	a= N/1000;
    b= (N - a*1000)/100;
    c= (N - a*1000 - b*100)/10;
    d= N - a*1000 - b*100 - c*10;
  if(a==b && b==c||b==c && c==d)
        cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

using ll = long long;
using ld = long double;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll n, m, a[30], b[30];
bool g[10][10];

ll dfs(bool seen[10], int node) {
  seen[node] = true;

  bool all_seen = true;
  rep(i, n) {
    if (seen[i] == false) {
      all_seen = false;
    }
  }
  if (all_seen) {
    return 1;
  }

  ll c = 0;
  rep(i, n) {
    if (g[node][i]) {
      if (seen[i]) {
        continue;
      }
      debug(node);
      debug(i);
      c += dfs(seen, i);
      seen[i] = false;
    }
  }
  return c;
}

int main() {
  cin >> n >> m;
  rep(i, m) {
    cin >> a[i] >> b[i];
    g[a[i] - 1][b[i] - 1] = true;
    g[b[i] - 1][a[i] - 1] = true;
  }

  bool seen[10];
  rep(i, n) {
    seen[i] = false;
  }

  cout << dfs(seen, 0) << endl;
}

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


int main(){
	int A, B;
	cin >> A >> B;
	int minb = B*10;
	int ans = 0;
	for(int i = 0; i < 10; i++){
		int tmpans=minb+i;
		if(int(tmpans*0.08) == A){
			ans = tmpans;
			break;
		}
	}
	cout << (ans?ans:-1) << endl;

	return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s==t) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

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

void Fill(int x,int y,vector<vector<char>>& masu){
    masu[x][y] = '.';
    for(int k = 0; k < 4;k++){
        int nx = x + dx[k],ny = y + dy[k];
        if(masu[nx][ny] == '#') Fill(nx,ny,masu);
    }
}
string solve(){
    ll H,W; cin >> H >> W;
    vector<vector<char>> masu(H+2,vector<char>(W+2,'@'));
    for(int i = 1; i <= H;i++){
        for(int j = 1; j <= W;j++){
            cin >> masu[i][j];
        }
    }
    for(int i = 1; i<=H;i++){
        for(int j = 1; j <=W;j++){
            for(int k = 0; k < 4;k++){
                int nx = i + dx[k], ny = j + dy[k];
                if(masu[i][j] == '#' && masu[nx][ny] == '#'){
                    Fill(i,j,masu);
                }
            }
        }
    }
    for(int i = 1; i <= H;i++){
        for(int j = 1; j <= W;j++){
            if(masu[i][j] == '#') return "No";
        }
    }
    return "Yes";
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
void init(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int main()
{
    int q;
    int n[6];
    int i,j;
    char t[110];
    int ts;
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init(n);
    scanf("%s",&t);
    ts=strlen(t);
    for(i=0;i<ts;i++){
        throwdice(t[i]);    
    }
    printf("%d\n",dice1.d[0]);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
    int m,f,r;
    while(1){
    cin>>m>>f>>r;
    if(m==-1&&f==-1&&r==-1)break;
    else if(m==-1||f==-1||m+f<30)cout<<"F"<<endl;
    else if(m+f>=80)cout<<"A"<<endl;
    else if(m+f>=65)cout<<"B"<<endl;
    else if(m+f>=50||r>=50)cout<<"C"<<endl;
    else cout<<"D"<<endl;
    }
}


Measured memory_bytes: 3092
import std.stdio;
import std.string;
import std.range;
import std.algorithm;

void main() {
	auto s = readln.chomp.retro.array;
	auto cands = ["dream", "dreamer", "erase", "eraser"].map!(s => s.retro.array).array;
	int idx = 0;
	while(true) {
		bool succ;
		if (idx >= s.length-1) break;
		foreach(cand; cands) {
			if (idx+cand.length <= s.length && s[idx..idx+cand.length] == cand) {
				idx += cand.length;
				succ = true;
				break;
			}
		}
		if (!succ) {
			"NO".write;
			return;
		}
	}
	"YES".write;
}


Measured memory_bytes: 2840
import sys

sys.setrecursionlimit(10**7)
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


class MinCostFlow:
    def __init__(self, n):
        self.n = n
        self.G = [[] for _ in range(n)]

    def addEdge(self, f, t, cap, cost):
        # [to, cap, cost, rev]
        self.G[f].append([t, cap, cost, len(self.G[t])])
        self.G[t].append([f, 0, -cost, len(self.G[f])-1])

    def minCostFlow(self, s, t, f):
        n = self.n
        G = self.G
        prevv = [0]*n; preve = [0]*n
        INF = 10**18

        res = 0
        while f:
            dist = [INF]*n
            dist[s] = 0
            update = 1
            while update:
                update = 0
                for v in range(n):
                    if dist[v] == INF:
                        continue
                    gv = G[v]
                    for i in range(len(gv)):
                        to, cap, cost, rev = gv[i]
                        if cap > 0 and dist[v] + cost < dist[to]:
                            dist[to] = dist[v] + cost
                            prevv[to] = v; preve[to] = i
                            update = 1
            if dist[t] == INF:
                return -1

            d = f; v = t
            while v != s:
                d = min(d, G[prevv[v]][preve[v]][1])
                v = prevv[v]
            f -= d
            res += d * dist[t]
            v = t
            while v != s:
                e = G[prevv[v]][preve[v]]
                e[1] -= d
                G[v][e[3]][1] += d
                v = prevv[v]
        return res


N,K = MI()
A = [LI() for _ in range(N)]
max = 10**13

MCF = MinCostFlow(2*N+2)

s,t = 2*N,2*N+1

MCF.addEdge(s,t,N*K,max)

for i in range(N):
    MCF.addEdge(s,i,K,0)
    MCF.addEdge(i+N,t,K,0)
    for j in range(N):
        MCF.addEdge(i,j+N,1,max-A[i][j])

print(N*K*max-MCF.minCostFlow(s,t,N*K))

ANS = [['.']*N for _ in range(N)]

for i in range(N):
    for to,cap,cost,_ in MCF.G[i]:
        if cap == 0 and N <= to < 2*N:
            ANS[i][to-N] = 'X'

for i in range(N):
    print(''.join(ANS[i]))


Measured memory_bytes: 70644
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,ans=0;
  cin >> n;
  for(int i=0; i<=n-1; i++) {
    ans+=i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
mod = 10**9 + 7
ans = 1
if abs(n - m) > 1:
    print(0)
elif n == m:
    for i in range(n):
        ans = ans * (i + 1) % mod
    ans = ans ** 2 % mod
    ans = ans * 2 % mod 
    print(ans)
else:
    for i in range(min(n,m)):
        ans = ans * (i + 1) % mod
    ans = ans * ans * (i + 2) % mod
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n, x, t;
   cin >> n >> x >> t;
   int ans = (n + x - 1) / x * t;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int R, G, B, N;
int memo[3001][3001];

int dfs(int r, int g)
{
  int sum = R*r+G*g;
  int ret = 0;
  if (memo[r][g] != 0) return 0;
  if ((N-sum) % B == 0) {
    ret++;
  }
  if (sum + R <= N)
    ret += dfs(r+1, g);
  if (sum + G <= N)
    ret += dfs(r, g+1);
  memo[r][g] = ret;
  return ret;
}

int main()
{
  cin >> R >> G >> B >> N;
  int ans = dfs(0, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35328
#include <stdio.h>

int main(void) {
    int a, b, c, d, e, k;
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);

    if ( e - a > k ) {
        printf(":(\n");
    }
    else {
        printf("Yay!\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
 
using namespace std;
 
const int MAX = 20;
int in[MAX][MAX], X,Y,data[MAX][MAX],ans;
int dx[4] = {-1,0,1};
 
 
void init(){
  memset(data,0,sizeof(data));
  ans = 0;
}
 
 
void solve(){
  for(int i = 1; i <= Y; i++)
    for(int j = 1; j <= X; j++){
      for(int k = 0; k < 3; k++)
	if(in[i][j] == 2){
	  if(in[i+2][j] != 1) data[i+2][j] += data[i][j];
	  break;
	}else if(in[i][j] == 0){
	  int nex = j+dx[k];
	  if(nex < 1 || nex > X) continue;

	  if(in[i+1][nex] == 2 && dx[k] == 0) data[i+1][nex] += data[i][j];
	  if(in[i+1][nex] == 0) data[i+1][nex] += data[i][j];

	}
    }
  
  for(int j = 1; j <= X; j++){
    if(Y-1 > 0 && in[Y-1][j] == 2) ans+=data[Y-1][j];
    ans+=data[Y][j];
  }
  cout << ans << endl;
}
 
void print(){
  for(int i = 1; i <= Y; i++){
    for(int j = 1; j <= X; j++)
      cout << data[i][j]<< " ";
    cout << endl;
  }
}
int main(){
  while(cin >> X >> Y && X+Y){
    init();
    for(int i = 1; i <= Y; i++)
      for(int j = 1; j <= X; j++)
    cin >> in[i][j];
     
    for(int i = 1; i <= X; i++)
      if(in[1][i] == 0) data[1][i] = 1;
 
    solve();
    //print();
  }
  return 0;
}

Measured memory_bytes: 1164
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B

a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C

s = list(input())
an0 = 0
an1 = 0
for i in s:
    if i == "1":
        an1 += 1
    if i == "0":
        an0 += 1
print(min(an0, an1)*2)
"""
"""
#D

n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

ab = ab[-1::-1]
size = [1 for _ in range(n)]
height = [1 for _ in range(n)]
par = [i for i in range(n)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def union(x, y):
    s1 = find(x)
    s2 = find(y)
    if s1 != s2:
        if height[s1] < height[s2]:
            par[s1] = s2
            size[s2] += size[s1]
            size[s1] = 0
        else:
            par[s2] = s1
            size[s1] += size[s2]
            size[s2] = 0
            if height[s1] == height[s2]:
                height[s1] += 1
 

ans = [0 for i in range(m)]
ans[0] = n * (n - 1) // 2
for num, i in enumerate(ab):
    if num == m-1:
        break
    a = i[0] - 1
    b = i[1] - 1
    sizea = size[find(a)]
    sizeb = size[find(b)]
    if find(a) == find(b):
        ans[num + 1] = ans[num]
    else:
        ans[num + 1] = ans[num] - (sizea * sizeb)
    union(a,b)
    
    
ans = ans[-1::-1]
for i in ans:
    print(i)
"""


Measured memory_bytes: 38388
#include <iostream>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int cnt = 0;
    REP (x, 10) REP (y, 10) REP (z, 10) {
        int n = x * 10000 + y * 1000 + z * 100 + y * 10 + x;
        cnt += (a <= n and n <= b);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vvi vector<vi>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll MAXN=2e5 + 5;
void print(vi v){
	ll n = v.size();
	for(ll i = 0; i < n; i++)
	    cout<<v[i]<<" ";
	cout<<endl;
}
ll power(ll a, ll b){
	ll res = 1;
	while(b != 0) {
		if(b & 1)
		  res *= a;
		a = a * a;
		b /= 2;
	}
	return res;
}
struct FenwickTree {
    vector<ll> bit;  // binary indexed tree
    ll n;

    FenwickTree(ll n) {
        this->n = n;
        bit.assign(n, 0);
    }

    FenwickTree(vector<ll> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    ll sum(ll r) {
        ll ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    ll sum(ll l, ll r) {
        return sum(r) - sum(l - 1);
    }

    void add(ll idx, ll delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};
FenwickTree bitr(MAXN), bitw(MAXN);
int main() {
    SPEED;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(s == string(n, 'W') || s == string(n, 'R')) {
    	cout<<0;
    	return 0;
    }
    for(ll i = 0; i < n; i++) {
    	if(s[i] == 'R')bitr.add(i, 1);
    	else bitw.add(i, 1);
    }
    ll ans = n;
    for(ll i = 1; i < n; i++) {
    	ll lw = bitw.sum(0, i - 1);
    	ll rr = bitr.sum(i, n - 1);
    	ans = min(ans, max(lw, rr));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7000
import numpy as np
n = int(input())
p = np.array(list(map(int,input().split())))

a = np.arange(1, n+1)
tmp = p - a
cnt = np.count_nonzero(tmp != 0)

flg = False
if cnt == 0 or (cnt == 2 and tmp.sum() == 0):
    flg = True

print('YES') if flg else print('NO')

Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  vec p(n),c(n);
  for(ll i=0;i<n;i++) {
    cin >> p[i];
    p[i]--;
  }
  for(ll i=0;i<n;i++) {
    cin >> c[i];
  }
  ll ans=-inf;
  set<ll> al;
  for(ll idx=0;idx<n;idx++) {
    if(al.count(idx)) continue;
    vec a;
    for(ll i=idx;;) {
      a.push_back(c[i]);
      al.insert(i);
      i=p[i];
      if(i==idx) break;
    }
    ll N=a.size();
    vec mo(N+1,-inf);
    mo[0]=0;
    for(ll i=0;i<N;i++) {
      ll sum=0;
      for(ll j=0;j<N;j++) {
        idx=(i+j)%N;
        sum+=a[idx];
        mo[j+1]=max(mo[j+1],sum);
      }
    }
    ll sum=mo[N];
    for(ll i=1;i<N;i++) {
      mo[i+1]=max(mo[i+1],mo[i]);
    }
    
    if(k<=N) {
      ans=max(ans,mo[k]);
    }
    else {
      ans=max(ans,mo[N]);
      ans=max(ans,k/N*sum+max(mo[k%N],0LL));
      ans=max(ans,(k/N-1)*sum+max(mo[N],0LL));
    }
  }
  cout << ans << endl;
}

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

int main(){

    size_t k, a, b;
    std::cin >> k >> a >> b;

    if(k >= 2 && a + 2 < b){
        size_t ans = a;
        k -= a - 1;
        if(k % 2 == 1) ans++, k--;

        ans += (b - a) * (k / 2);

        std::cout << ans << std::endl;
    }else{
        std::cout << k + 1 << std::endl;
    }

    return 0;
}


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

int a[100010], b[100010];

int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(0);
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	vector<int> v;
	v.push_back(k);
	for (int i = 0; i <= 30; i++) {
		int mask = 1 << i;
		if (k & mask) {
			int tmp = k ^ mask;
			tmp |= mask - 1;
			v.push_back(tmp);
		}
	}
	int64_t ans = 0;
	for (int kk = 0; kk < v.size(); kk++) {
		int64_t res = 0;
		for (int i = 0; i < n; i++) {
			if ((a[i] | v[kk]) == v[kk]) {
				res += b[i];
			}
		}
		ans = max(ans, res);
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  ll ans = INF;
  rep(i, N) {
    ll a;
    cin >> a;

    ll count = 0;
    while (a % 2 == 0) {
      count++;
      a /= 2;
    }
    ans = min(ans, count);
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3608
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string s, temp;

void change(char &ch);

int main(void)
{
	cin >> s;
	temp = s;
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); i++)
		change(s[i]);
	if (s == temp)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
	//system("pause");
	return 0;
}

void change(char &ch)
{
	if (ch == 'b')
		ch = 'd';
	else if (ch == 'd')
		ch = 'b';
	else if (ch == 'p')
		ch = 'q';
	else if (ch == 'q')
		ch = 'p';
}

Measured memory_bytes: 512
/*
PROG: agc26a
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
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);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N;
int was = -1, ans = 0;

int32_t main()
{
	ios_base::sync_with_stdio(0); 
	srand(time(0));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	if (fopen("agc26a.in", "r"))
	{	
		freopen ("agc26a.in", "r", stdin);
		//	freopen ("agc26a.out", "w", stdout);
	}
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;
		if (x == was)
		{
			ans++;
			was = -1;
		}
		else
		{
			was = x;
		}
	}
	cout << ans << '\n';
	//	cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	int n,tmp,ans=0,old=0;
	cin >> n;
	vector<int> b(n);
	rep(i, n - 1) {
		cin >> b[i];
	}
	old = ans = b[0];
	rep(i,n-2) {
		ans += min(b[i], b[i + 1]);
	}
	ans += b[n - 2];

	cout << ans;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto A = RDA;
	bool ans = true;
	foreach (e; A)
	{
		if (e % 2 == 1) continue;
		if (e % 3 != 0 && e % 5 != 0)
			ans = false;
	}

	writeln(ans ? "APPROVED" : "DENIED");
	stdout.flush;
	debug readln;
}

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

using namespace std;
typedef long long ll;

ll GCD(ll a, ll b){
  while(1){
    a=a%b;
    if(a==0){
      return b;
    }
    b=b%a;
    if(b==0){
      return a;
    }
  }
}
int N;
int main(){
  ll k;
  cin >> N >> k;
  vector<ll> a(N);
  ll max=0;
  ll min=1000000000;
  ll tmp;
  for(int i=0;i!=N;i++){
    cin >> a[i];
    if(max<a[i]){
      max=a[i];
    }
    if(i==0){
      tmp=a[i];
      continue;
    }
    tmp=GCD(tmp,a[i]);
  }
  if(max<k){
    cout << "IMPOSSIBLE" << endl;
  }
  else if(k%tmp==0){
    cout << "POSSIBLE" << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}


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

using namespace std;

double dp[303][303][303];
int n;

double ans (int i, int j, int k) {
  if (!i && !j && !k) return 0;
  if (i < 0 || j < 0 || k < 0) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int sum = i + j + k;
  return dp[i][j][k] = (n + ans(i -1, j, k)*i + ans (i + 1 , j-1, k)*j + ans(i, j+1, k-1)*k)/sum;
}

int main () {
  int count[] = {0, 0, 0};
  cin >> n;

  for (int i = 0; i < n; i++) {
    int h; cin >> h;
    if (h) count[h-1]++;
  }
  // for (int i = 0; i < 3; i++) cout << count[i] << endl;
  for (int i = 0; i <=n; i++)
    for (int j = 0; j <=n; j++)
      for (int k = 0; k <=n; k++)
        dp[i][j][k] = -1;
  dp[0][0][0] = 0;
  printf("%.11lf\n", ans(count[0],count[1],count[2]));
}

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

int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int r,d,x;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++)
    {
        cout<<r*x-d<<endl;
        x=r*x-d;

    }
    return 0;
}


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

int main(){
    string s,t;
    cin>>s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

ll n;
ll ans = 0;

bool check(ll x) {
	string S = to_string(x);
	if (count(S.begin(), S.end(), '3') == 0 || count(S.begin(), S.end(), '5') == 0 || count(S.begin(), S.end(), '7') == 0) {
		return 0;
	}
	else return 1;
}

void dfs(ll x) {
	if (x > n) return;
	if (check(x)) {
		ans++;
	}
	if (x * 10 < 1000000000) {
		dfs(x * 10 + 3);
		dfs(x * 10 + 5);
		dfs(x * 10 + 7);
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())

pre = ''
mat = ''
state = 1

for _ in range(q):
    query = input()
    if query[0] == '1':
        state = 3 - state
    else:
        _, f, c = query.split()
        if int(f) == state:
            pre += c
        else:
            mat += c

if state == 1:
    print(pre[::-1] + s + mat)
else:
    print(mat[::-1] + s[::-1] + pre)

Measured memory_bytes: 4468
#!/usr/bin/env python3
#ABC65 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heapify
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
par = [i for i in range(n)]
rank = [0]*n
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

x,y = [],[]
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    x.append((a,i))
    y.append((b,i))
x.sort()
y.sort()
h = []
heapify(h)
for i in range(n-1):
    x1, j1 = x[i]
    x2, j2 = x[i+1]
    y1, k1 = y[i]
    y2, k2 = y[i+1]
    heappush(h,(x2-x1, j1, j2))
    heappush(h,(y2-y1, k1, k2))
ans = 0
x = 0
while h:
    w,s,t = heappop(h)
    if find(s) != find(t):
        x += 1
        union(s,t)
        ans += w
    if x == n-1:
        break
print(ans)


Measured memory_bytes: 54624
n,a,b = map(int,input().split())
mod = int(1e9+7)

def combination(n, r, mod):
    np1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (np1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

calc = pow(2, n, mod) - combination(n,a,mod) - combination(n,b,mod) - 1
print(calc%mod)


Measured memory_bytes: 3060
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;

int main() {

	long N, M; cin >> N >> M;
	vector<long> A(M), B(M);
	vector<long> C(M, 0);//bit整数化しておく

	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		for (int j = 0; j < B[i]; j++) {
			long c; cin >> c;
			C[i] += (1 << (c - 1));
		}
	}

	//bit_jにするための金額の最小値 -> 鍵を一つ買うごとに最小値をとっていく
	vector<long> dp((1 << N), INT_MAX); 
	dp[0] = 0;

	for (int i = 0; i < M; i++) {//鍵を一つづつ買う
		for (int k = 0; k < (1 << N); k++) {//ここでbit値は全通りやるので最適なものを選べる
			dp[k | C[i]] = min(dp[k | C[i]], dp[k] + A[i]);
		}
	}
    
	if (dp[(1 << N) - 1] == INT_MAX) dp[(1 << N) - 1] = -1;
	cout << dp[(1 << N) - 1] << endl;
}

Measured memory_bytes: 256