akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

ll p[5010],c[5010];
vector<ll> adj[5010];
bool visited[5010];
ll summ,countt;

void DFS(ll s,vector<ll> &pref){
    if(countt!=0 && visited[s]==true)return;
    for(auto x:adj[s]){
        summ = summ + c[x];
        pref.push_back(summ);
        countt++;
        DFS(x,pref);
    }
    return;
}

int main(){
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>p[i];
        p[i]--;
    }
    for(int i=0;i<n;++i){
        cin>>c[i];
    }
    for(int i=0;i<n;++i){
        adj[i].push_back(p[i]);
    }
    ll maxx = LLONG_MIN;
    for(int i=0;i<n;++i){
        countt=0;
        summ=0;
        vector<ll> pref;
        visited[i]=true;
        DFS(i,pref);                  
        visited[i]=false;
        ll ans=0;
        if(summ>=0){
            
            if(k<=countt){
                ll local_max = pref[0];    
                for(int i=1;i<k;++i){
                    local_max = max(local_max,pref[i]);
                }
                ans = ans + local_max;
            }
            else {
                ll soul = pref[0];
                for(int i=1;i<countt;++i){
                    soul = max(soul,pref[i]);
                }
                ans = ans + (k/countt-1)*summ;
                //naku countt and k%countt unnnay chetilo
                if(k%countt==0){
                    ans = ans + soul;
                }
                else {
                    ll K = k%countt;
                    ll local_max=pref[0];
                    for(int i=1;i<K;++i){
                        local_max = max(local_max,pref[i]);
                    }
                    if(local_max==soul)ans = ans + summ + soul; //clear
                    else {
                        ll ayya = max(soul,max(summ,summ+local_max));
                        ans = ans + ayya;
                    }
                }
                /*ll K = k%countt;
                ll local_max=pref[0];
                for(int i=1;i<K;++i){
                    local_max = max(local_max,pref[i]);
                }
                if(K>0)ans = ans + local_max;*/
            }
            
        }
        else {
            
            ll K = min(k,countt);
            ll local_max = pref[0];    
            for(int i=1;i<K;++i){
                local_max = max(local_max,pref[i]);
            }
            ans = ans + local_max;
        }
        maxx = max(maxx,ans);
    }
    cout<<maxx;
    return 0;
}

Measured memory_bytes: 4368
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    private static void nCombination3(int c) {
        int count = c;
        int num = 0;
        for (int i = 0; i < count - 2; i++) {
            for (int j = i + 1; j < count - 1; j++) {
                for (int k = j + 1; k < count; k++) {
                    num++;
                }
            }
        }
    }



    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt(),M=sc.nextInt();
        long[] H=new long[N];
        int[] ans = new int[N];
        Arrays.fill(ans,1);
        for(int i=0;i<N;i++){
            H[i]=sc.nextLong();
        }
        int[] A=new int[M],B=new int[M];
        for(int i=0;i<M;i++){
            A[i]=sc.nextInt()-1;
            B[i]=sc.nextInt()-1;
            if(H[A[i]]<=H[B[i]]){
                ans[A[i]]=-1;
            }
            if(H[A[i]]>=H[B[i]]){
                ans[B[i]]=-1;
            }
        }
        int answer = 0;
        for(int i=0;i<N;i++){
            if(ans[i]==1){
                //System.out.println(i+1);
                answer++;
            }
        }
        System.out.println(answer);



    }
}


Measured memory_bytes: 62332
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int SIZE = 11;
const int MSIZE = 101;

int w, h;
int s;
int X[SIZE], Y[SIZE];
int t;
int PT[SIZE], QT[SIZE];
int T[MSIZE][MSIZE];
int Tcopy[MSIZE][MSIZE]; 

const int DSIZE = 6;
const int dr[2][DSIZE] = {
    { 1, 1, 0, 0, -1, -1 },
    { 1, 1, 0, 0, -1, -1 }
};
const int dc[2][DSIZE] = {
    { -1, 0, -1, 1, -1, 0 },
    { 0, 1, -1, 1, 0, 1 }
};

void init() {
    for ( int i = 0; i < MSIZE; ++ i ) {
        for ( int j = 0; j < MSIZE; ++ j ) {
            T[i][j] = INT_MAX;
        }
    }
}

void save() {
    for ( int i = 0; i < MSIZE; ++ i ) {
        for ( int j = 0; j < MSIZE; ++ j ) {
            Tcopy[i][j] = T[i][j];
        }
    }
}

void load() {
    for ( int i = 0; i < MSIZE; ++ i ) {
        for ( int j = 0; j < MSIZE; ++ j ) {
            T[i][j] = Tcopy[i][j];
        }
    }
}

typedef II NODE;
typedef queue <NODE> QUEUE;

bool isValidPos( int r, int c ) {
    return r >= 0 && r < h && c >= 0 && c < w;
}

int spread( int sr, int sc ) {
    QUEUE Q;
    Q.push( II( sr, sc ) );
    T[sr][sc] = 0;
    
    int res = 1;
    while ( ! Q.empty() ) {
        NODE node = Q.front();
        Q.pop();

        int r = node.first;
        int c = node.second;
        int d = r % 2;

        for ( int i = 0; i < DSIZE; ++ i ) {
            int nr = r + dr[d][i];
            int nc = c + dc[d][i];
            if ( ! isValidPos( nr, nc ) ) continue;
            if ( T[r][c] + 1 >= T[nr][nc] ) continue;
            T[nr][nc] = T[r][c] + 1;
            res ++;
            NODE next( nr, nc );
            Q.push( next );
        }
    }
    return res;
}

void solve() {
    init();
    for ( int i = 0; i < s; ++ i ) {
        spread( Y[i], X[i] );
    }
    save();
    int res = 0;
    for ( int i = 0; i < t; ++ i ) {
        load();
        res = max( res, spread( QT[i], PT[i] ) );
    }
    cout << res << endl;
    return;
}

void input() {
    cin >> s;
    for ( int i = 0; i < s; ++ i ) {
        cin >> X[i] >> Y[i];
        X[i] -= 1;
        Y[i] -= 1;
    }
    cin >> t;
    for ( int i = 0; i < t; ++ i ) {
        cin >> PT[i] >> QT[i];
        PT[i] -= 1;
        QT[i] -= 1;
    }
}

int main() {
    while ( cin >> w >> h ) {
        if ( w == 0 && h == 0 ) break;
        input();
        solve();
    }
    return 0;
}

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

int main(void){
    
    int N;
    cin >> N;
    string ans = "hon";
    if(N%10 == 3)ans = "bon";
    else if(N%10 == 0
    || N%10 == 1
    || N%10 == 6
    || N%10 == 8)ans = "pon";
    cout << ans <<endl;
}

Measured memory_bytes: 3596
n, p = list(map(int, input().split()))
a = list(map(int, input().split()))
flag = True
for ele in a:
  if ele%2==1:
    flag = False
if flag:
  if p==1:
    print(0)
  else:
    print(2**n)
else:
  print(2**(n-1))

Measured memory_bytes: 3060
object Main extends App {
  var array = Vector.empty[Long]
  var n = 0L
  for(i<-1 to 6) {
    if (i == 1) {
      n = scala.io.StdIn.readLong()
    } else {
      array :+= scala.io.StdIn.readLong()
    }

  }
  var sum = 4L
  val timeTurple = array.zipWithIndex.map { case(a, index) =>
    val time =
      if (n / a == 0) 1
      else if (n % a == 0) n / a
      else (n / a) + 1
    (a, time, index)
  }
  val max = timeTurple.find(_._2 == timeTurple.map(_._2).max).get
  sum = sum + max._2
  println(sum)
}

Measured memory_bytes: 25524
#include <iostream>

#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#include <utility>
#include <cmath>

#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;


#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort(ALL(c))
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
// #define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ITER(it,v) for(auto it=v.begin();it!=v.end();++it)
#define IN_LL(v) ll v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const int INF = 1e9;

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

  string s;
  cin >> s;
  IN(K);
  int N = s.size();

  vector<string> v(N), ans;
  REP(i, N) {
    v[i] = s.substr(i, N);
  }
  SORT(v);
  REP(i, N) {
    REP(j, min(K, (int)v[i].size()))
      ans.push_back(v[i].substr(0, j+1));
  }
  SORT(ans);
  unique(ALL(ans));
  OUT(ans[K-1]);


  return 0;
}


Measured memory_bytes: 17532
import collections
N = int(input())
S = {}
for i in range(N):
    si = input()
    if si in S:
        S[si] += 1
    else:
        S[si] = 1
#print(S)
m = max(S.values())
for i in sorted(S.items()):
    #print(sorted(S.items()))
    #print(S,i[0])
    if i[1] == m:
        print(i[0])


Measured memory_bytes: 138308
from math import gcd

N = int(input())
AB = [map(int, input().split()) for _ in range(N)]

t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
    i = gcd(a, b)
    if i != 0:
        a //= i
        b //= i
    t.append((a, b))
    d.setdefault(a, {})
    d[a].setdefault(b, 0)
    d[a][b] += 1
t = set(t)
if (0, 0) in t:
    t.remove((0, 0))

used = set()
result = 1
for a, b in t:
    if (a, b) in used:
        continue
    used.add((a, b))
    i = d[a][b]
    j, k, l = 0, 0, 0
    if -a in d and -b in d[-a]:
        j = d[-a][-b]
        used.add((-a, -b))
    if -b in d and a in d[-b]:
        k = d[-b][a]
        used.add((-b, a))
    if b in d and -a in d[b]:
        l = d[b][-a]
        used.add((b, -a))
    result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1
    result %= 1000000007
result += d[0][0] - 1
result %= 1000000007
print(result)


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

int main()
{
  int A,B,C,D;
  
  cin >> A >> B >> C >> D;
  
  if ( (A+B) > (C+D) )
    cout << "Left" << endl;
  else if ( (A+B) < (C+D) )
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*3 for _ in range(n)]
dp[0] = abc[0]
for i in range(1, n):
    for j in range(3):
        tmp = 0
        for k in range(3):
            if j != k:
               tmp = max(tmp, dp[i-1][k] + abc[i][j])
        dp[i][j] = tmp

print(max(dp[-1]))

Measured memory_bytes: 76164
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static void f(String[] strings){
		Set<String> linkedHashSet = new LinkedHashSet<String>();

		for (int i = 0; i < strings.length; i++) {
		    linkedHashSet.add(strings[i]);
		    }
		 Object[] strings_after = linkedHashSet.toArray();

		 System.out.println(strings_after.length);
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		String[] S = new String[N];

		for(int i=0;i<N;i++) {
			S[i] = scan.next();
		}

		f(S);

		scan.close();
	}

}


Measured memory_bytes: 74092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<vector>
#include<algorithm>
#define INF 1000000000000LL
using namespace std;

vector<long long> s;
vector<long long> t;

int main() {
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	
	s.push_back(-INF);
	t.push_back(-INF);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld",&x);
		s.push_back(x);
	}
	for(int i=0;i<m;i++) {
		long long x;
		scanf("%lld",&x);
		t.push_back(x);
	}
	s.push_back(INF);
	t.push_back(INF);
	
	for(int i=0;i<q;i++) {
		long long x;
		scanf("%lld",&x);
		
		int sr = upper_bound(s.begin(), s.end(), x) - s.begin();
		int sl = sr - 1;
		int tr = upper_bound(t.begin(), t.end(), x) - t.begin();
		int tl = tr - 1;
		
		long long ans = INF;
		ans = min(ans, abs(x - min(s[sl], t[tl])));
		ans = min(ans, abs(x - max(s[sr], t[tr])));
		ans = min(ans, abs(x - s[sl]) * 2 + abs(x - t[tr]));
		ans = min(ans, abs(x - s[sl]) + abs(x - t[tr]) * 2);
		ans = min(ans, abs(x - t[tl]) * 2 + abs(x - s[sr]));
		ans = min(ans, abs(x - t[tl]) + abs(x - s[sr]) * 2);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int n,all,cnt[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++){
    	int x;cin>>x;
    	cnt[x]++;
    	all=gcd(all,x);
    }
    bool ok=true;
    for(int i=2;i<N&&ok;i++){
    	int sum=0;
    	for(int j=i;j<N;j+=i) sum+=cnt[j];
		if(sum>1) ok=false;
    }
    cout<<(ok?"pairwise coprime":all==1?"setwise coprime":"not coprime");
    return 0;
}

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

int judge(int x,int y,int t)
{
	//cout<<x<<y<<t;
	if(abs(x)+abs(y)>t||(t-abs(x)-abs(y))%2==1)
		return 1;
	else 
	 	return 0;
}


int main()
{
	int n;
	int x1=0,x2=0,x3,x4;
	int t1=0,t2;
	scanf("%d",&n);
	
	for(int i=1;i<=n;i++)
	{
		if(i!=1)
			x1=x3,x2=x4,t1=t2;
			
		scanf("%d%d%d",&t2,&x3,&x4);
		
		if(judge(x1-x3,x2-x4,t2-t1))
		{
			printf("No\n");
			return 0;
		}
		
	}
	printf("Yes\n");
	return 0;
}

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

const int MAX_N = 110000;

int dp[MAX_N]; // dp[i] が i についての答え

int main() {
	int N;
	cin >> N;

	// 初期化
	for (int i = 0; i < MAX_N; ++i) dp[i] = N; // INF の気持ち
	dp[0] = 0;

	// 配る DP --- dp[n] から遷移を出して行く
	for (int n = 0; n < N; ++n) {
		for (int pow6 = 1; n + pow6 <= N; pow6 *= 6) {
			dp[n + pow6] = min(dp[n + pow6], dp[n] + 1);
		}
		for (int pow9 = 1; n + pow9 <= N; pow9 *= 9) {
			dp[n + pow9] = min(dp[n + pow9], dp[n] + 1);
		}
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> L(87);
    L[0] = 2;
    L[1] = 1;
    for(size_t i=2;i<=86; i++)
    {
        L[i] = L[i-1] + L[i-2];
    }
    cout << L[N] << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

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

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

INF=Float::INFINITY

a,b,c=get_i
k=gets.to_i
cnt=0
if a>=b
    until a<b
        b*=2
        cnt+=1
    end
end
if b>=c
    until b<c
        c*=2
        cnt+=1
    end
end
if cnt<=k
    puts "Yes"
else
    puts "No"
end

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

int main(){
    int n,m;
    int t1,t2;
    int sum;
    cin >> n >> m;
    sum = n;
    vector<long> H(n);
    vector<int> G(n,1);
    for(int i = 0; i < n; i++){
        cin >> H[i];
    }

    for(int i = 0; i < m; i++){
        cin >> t1 >> t2;
        if(H[t1-1] > H[t2-1]){
            if(G[t2-1] == 1){
                G[t2-1] = 0;
                sum--;
            }
        }else if(H[t2-1] > H[t1-1]){
            if(G[t1-1] == 1){
                G[t1-1] = 0;
                sum--;
            }
        }else{
            if(G[t1-1] == 1){
                G[t1-1] = 0;
                sum--;
            }
            if(G[t2-1] == 1){
                G[t2-1] = 0;
                sum--;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    ll ans = 0, n,a,b,d;
    cin >> n >> d;
    rep(i,0,n) {
        cin >> a >> b;
        if (a*a+b*b <= d*d) ++ans;
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}



Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());

		if(n % 2 != 0) {

			System.out.println("No");

		}else {

			char[] tm 	 = scanner.nextLine().toCharArray();
			boolean flag = false;
			int x = n / 2 ;

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

				if(tm[i] != tm[x + i]) {

					flag = true;
					break;
				}



			}

			if(flag) {

				System.out.println("No");
			}else{

				System.out.println("Yes");
			}
		}
	}

}

Measured memory_bytes: 21844
import java.util.*;

public class Main {

	public static void main(String[] args)  {

		Scanner in = new Scanner(System.in);
		

		int H = in.nextInt();

		int[] a = new int[H + 1];

		for (int i = 1; i <= H; i++)
			a[i] = in.nextInt();

		for (int i = H / 2; i >= 1; i--)
			maxHeapify(a, i);

		for (int i = 1; i <= H; i++)
			System.out.print(" " + a[i]);
		System.out.print("\n");
		
		

		in.close();
		
	}

	private static void maxHeapify(int[] a, int i) {
		int l = i * 2;
		int r = i * 2 + 1;
		
		int max = i;
		// is the largest on the left
		if (l < a.length && a[l] > a[i])
			max = l;
		// of is the largest on the right
		if (r < a.length && a[r] > a[max])
			max = r;
		// if the maximum isn't the current position...
		if (max != i) {
			int tmp = a[i];
			a[i] = a[max];
			a[max] = tmp;
			maxHeapify(a, max);
		}
	}
}
	



Measured memory_bytes: 166800
#include<iostream>
using namespace std;
int main() {
    int n = 0;
    string s;
    cin >> s;
    for(int i = 0; i < (int)s.size(); ++i){
        if(s[i] == '+') {
            n += 1;
        } else {
            n -= 1;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
  double r,S,L;
  cin >> r;
  
  S = M_PI * r * r;
  L = M_PI * 2 * r;
  
  std::cout << std::fixed;
  std::cout << std::setprecision(8) << S << " " <<  std::setprecision(8) << L <<endl;
  
  return 0;
}


Measured memory_bytes: 3236
N,K = map(int, input().split())

if K % 2 == 0:
    cnt1,cnt2 = 0,0
    for n in range(1,N+1):
        if n % K == 0:
            cnt1 += 1
        if n % K == (K // 2):
            cnt2 += 1
    print(cnt1 ** 3 + cnt2 ** 3)
else:
    cnt1 = 0
    for n in range(1,N+1):
        if n % K == 0:
            cnt1 += 1
    print(cnt1 ** 3)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int H=1,W=1,i=1,j=0;

	while(H!=0&&W!=0)
	{	
		
		scanf("%d %d",&H,&W);
		if(H!=0&&W!=0)
		{
			
		
		
		
		for(j=0;j<H;j++)
		{
				if(j%2==0)
				{
					for(i=0;i<W;i++)
					{
						if(i%2==0)
						{
							printf("#");
						}
						else
						{
							printf(".");
						}
					}

					printf("\n");
				
				}
				else
				{
					for(i=0;i<W;i++)
					{
						if(i%2==0)
						{
							printf(".");
						}
						else
						{
							printf("#");
						}
					}
					printf("\n");
				
				}
				
			}
		printf("\n");
		 }
		
		else
		{
			
		}
		}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long cnt=1,sum=0;
    while(n>0)
    {
        sum+=cnt;
        n/=2ll;
        cnt*=2ll;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define endl "\n"
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);  
    
      /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
  int n,x,t;cin>>n>>x>>t;
  int ans=0;
  ans+=(n/x)*t;
  if(n%x)ans+=t;
  cout<<ans<<endl;
 
} 


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int64_t y[300000]={};
int main()
{
    uint64_t cow,gav=0;
    cin>>cow;
    cin>>y[0];
    for(int i=1;i<cow;i++){
        cin>>y[i];
        if(y[i]<y[i-1]){
            gav+=y[i-1]-y[i];
            y[i]=y[i-1];
        }
    }
    cout<<gav;
}

Measured memory_bytes: 5176
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define HOGE 5000
#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()


int main(){
    string s;
    getline(cin,s);
    
    rep(i,s.sz-5+1){
        string a[2]={"apple","peach"};
        rep(j,2){
            bool f=true;
            rep(k,5){
                if(s[i+k]!=a[j][k])f=false;
            }
            if(f){
                rep(k,5){
                    s[i+k]=a[!j][k];
                }
                break;
            }
        }
    }
    
    cout<<s<<endl;
    return 0;
}

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

int main(){
	int n; cin >> n;
	vector<int> p(n+1);
	vector<vector<int> > dp(n, vector<int>(n,-1));
	cin >> p[0] >> p[1];
	int a;
	for (int i=0;i<n;i++){
		cin >> a >> p[i+2];
	}
	//前処理
	for (int i=0;i<n;i++) dp[i][i] = 0;
	for (int i=1;i<n;i++) dp[i-1][i] = p[i-1] * p[i] * p[i+1];
	
	//DPの遷移
	for (int i=0;i<n;i++){
		for (int j=0;j<n-i;j++){
			int a = j, b = j + i;
			if (dp[a][b] != -1) continue;
			//実際の処理
			dp[a][b] = 1e9;
			for (int k=a;k<b;k++){
				int now = dp[a][k] + p[a]*p[k+1]*p[b+1] + dp[k+1][b];
				if (dp[a][b] > now)
				dp[a][b] = now;
			}
		}
	}
	
	cout << dp[0][n-1] << endl;
	return 0;

}




Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int bas=31;
const int mx=bas*2;
int cnt[mx][mx];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        ll a=0;
        int j=0;
        for(;j<(int)s.size();j++)
        {
            if(s[j]=='.')
                break;
            a=a*10+(s[j]-'0');
        }
        j++;
        int c2=0,c5=0;
        for(;j<(int)s.size();j++)
            a=a*10+(s[j]-'0'),c2--,c5--;
        while(a%2==0)
            a/=2,c2++;
        while(a%5==0)
            a/=5,c5++;
        cnt[c2+bas][c5+bas]++;
    }
    ll ans=0;
    for(int i=0;i<mx;i++)
    {
        for(int j=0;j<mx;j++)
        {
            for(int k=mx-i;k<mx;k++)
            {
                for(int l=mx-j;l<mx;l++)
                {
                    ans+=(ll)cnt[i][j]*cnt[k][l];
                    if(pi(i,j)==pi(k,l))
                        ans-=cnt[i][j];
                }
            }
        }
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]==t[i]) continue;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3916
import numpy as np

MOD = 998244353

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = np.zeros((n+1, s+1), dtype=np.int64)
    for i, v in enumerate(a):
        dp[i][0] += 1
        dp[i+1] += dp[i]
        if v <= s:
            dp[i+1][v:] += dp[i][:-v]
        dp[i+1] %= MOD
    ans = 0
    for i in range(n+1):
        ans += dp[i][s]
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 97288
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
int x,y;
if(a<b)
x=a;
else
x=b;
if(c<d)
y=c;
else
y=d;
cout<<x+y;
system("pause");
return 0;}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
//#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15+5;
const ll N=1e5+10;
std::vector<int> v[N];
ll fact[N];
bool visited[N];
ll n,k;

ll mod_expo(ll a,ll b, ll c)
{
	ll ans=1;
	while(b)
	{
		if(b & (ll)1) ans=(ans*a)%c;
		a=(a*a)%c;
		b=b>>1;
	}
	return ans;
}
ll invese(ll n)
{
	return mod_expo(n,mod-2,mod);
}

ll npr(ll n, ll k)
{
	if(n<k) return 0;
	//check(n);check(k);
	return (fact[n]*invese(fact[n-k]))%mod;
}

ll dfs(ll now,ll cnt)
{
	visited[now]=1;
	ll ans=1,x=0;
	for(auto &i:v[now])
	{
		if(visited[i] == 0)
		{
			x++;
			ans*=dfs(i,max(cnt-1,k-2));
			ans%=mod;
		}
	}
	ans*=npr(cnt,x);
	ans%=mod;
	return ans;
}

int main()
{
	boost;
	fact[0]=1;
	for(ll i=1;i<N;i++) fact[i]=(fact[i-1]*i)%mod;
	cin>>n>>k;
	for(int i=0;i<n-1;i++)
	{
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	cout<<(k*dfs(1,k-1))%mod;


	return 0;
} 


Measured memory_bytes: 12416
append :: Int -> Int -> Int
append a b = 10 * a + b

solve :: [Int] -> Int
solve [] = error "invalid"
solve [x] = x
solve (x:y:xs) = x * (2 ^ length xs) + solve (y:xs) + solve (append x y : xs)

main :: IO ()
main = getLine >>= print . solve . map (read . (:[]))


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

int main () {
int n;
cin >> n;
int tmp = n%1000;
if ((tmp/10)%11!=0)
  cout << "No" << endl;
else{
  if (n/1000!=((tmp/10)/11) && (((tmp/10)/11)!=n%10) )
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

int main_(){
  int N;
  string S;
  cin>>N>>S;
  map<char,int>m;
  for(int i=0;i<N;i++){
    m[S[i]]++;
  }
  ll ans=1;
  for(auto it:m){
    ll a=it.second%MOD;
    if(a>0)ans*=a+1;
    else ans*=2;
    ans%=MOD;
  }
  ans--;
  cout<<ans<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<"---------------------"<<endl;
  }
#else
  main_();
#endif

  return 0;
}


Measured memory_bytes: 512
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


x, y = map(int, input().split())

if (x+y) % 3 != 0:
    print(0)
else:
    n = (x+y)//3
    r = min(x, y) - n
    mod = 10**9+7
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]

    for i in range(2, n + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    print(cmb(n, r, mod))


Measured memory_bytes: 84704
[r, g, b, n] = [int(i) for i in input().split()]
l = [r, g, b]
l.sort()

sum = 0
for i in range(n // l[2] + 1):
    for j in range((n - l[2] * i) // l[1] + 1):
        if ((n - l[2] * i - l[1] * j) % l[0] == 0):
            sum += 1

print(sum)


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	String n=sc.next();
	char x = n.charAt(n.length()-1);

	if(x=='2'||x=='4'||x=='5'||x=='7'||x=='9') { System.out.println("hon");}
	if(x=='0'||x=='1'||x=='6'||x=='8') {System.out.println("pon");}
	if(x=='3') {System.out.println("bon");}
	}
}

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

int main() {
    long long ans = 0;
    long long N;
    cin >> N;
    if(N % 2 == 0) {
        long long five_pow = 10;
        while(N >= five_pow) {
            ans += N / five_pow;
            five_pow *= 5;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<ll>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

using pl = pair<ll, ll>;

ll ans = 0;


vector<bool> check(10001, false);
vector<int> res(10001);

int cnt = 0;

void dfs(int now, const vector<vector<int>>& v, const vector<int>& c) {
  check[now] = true;
  res[now] = c[cnt];
  
  for (auto itr : v[now]) {
    // cout << itr << endl;
    if (!check[itr]) {
      cnt += 1;
      ans += c[cnt];
      
      dfs(itr, v, c);
    }
  }
  // cout << cnt << endl;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n-1), b(n-1), c(n);
  vector<vector<int>> v(n+1);
  rep(i, n-1) {
    cin >> a[i] >> b[i];
    a[i] -= 1;
    b[i] -= 1;
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  rep(i, n) cin >> c[i];
  sortd(c);
  /*
  for (auto itr : c) {
    cout << itr << endl;
  }*/
  dfs(0, v, c);
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    cout << res[i] << " ";
  }
  END;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int H, W;

    scanf("%d%d", &H, &W);

    int N;

    scanf("%d", &N);

    int a[N];

    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }

    int c[H][W];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            c[i][j] = 0;
        }
    }

    int h = 0, w = 0, k = 0, t = 0;

    while(1){
        t++;
        if(a[k] > 0){
            c[h][w] = k+1;
            a[k]--;
        }else{
            k++;
            c[h][w] = k+1;
            a[k]--;
        }
        if(t == H*W){
            break;
        }else{
            if(w == 0 && c[h][w+1] > 0){
                h++;
            }else if(w == W-1 && c[h][w-1] > 0){
                h++;
            }else if(w != W-1 && c[h][w+1] == 0){
                w++;
            }else{
                w--;
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W-1; j++){
            printf("%d ", c[i][j]);
        }
        printf("%d\n", c[i][W-1]);
    }

    return 0;
}

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

bool IsPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {
    long long int X;

    cin >> X;

    while (1) {
        if (!IsPrime(X) == 0) {
            break;
        }
        X++;
    }
    
    cout << X << endl;
    
    return 0;
}

Measured memory_bytes: 256
n=input()

for i in range(2 ** 3):
    

    co=["-","-","-"]

    for j in range(3):
        if ((i>>j)&1):
            co[2-j]="+"

    eq=n[0]+co[0]+n[1]+co[1]+n[2]+co[2]+n[3]


    if eval(eq)==7:
            ans=eq

print(ans,end="")
print("=7")


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

int main()
{
    int N;
    cin >> N;
    vector<int> a;
    for (int i = 0; i < N; i++)
    {
        int temp;
        scanf("%d", &temp);
        temp--;
        a.push_back(temp);
    }
    int now = 0;
    for (int i = 0; i < N; i++)
    {
        if (now == 1)
        {
            cout << i;
            return 0;
        }
        now = a[now];
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 892
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;


namespace aizu
{
	public class EntryPoint
	{
		public static string[] Split(string line)
		{
			return Regex.Split(line, " ");
		}
		public static int[] SplitToInt(string line)
		{
			return Regex.Split(line, " ").Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDouble(string line)
		{
			return Regex.Split(line, " ").Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLong(string line)
		{
			return Regex.Split(line, " ").Select(x => long.Parse(x)).ToArray();
		}
		public static void Main()
		{
			
			while (true)
			{
				var line = Console.ReadLine();
				var v = Split(line);
				
				var a = int.Parse(v[0]);
				var op = v[1];
				var b = int.Parse(v[2]);
				
				switch (op)
				{
					case "+" :
					{
						Console.WriteLine(a + b);
						break;
					}

					case "-" :
					{
						Console.WriteLine(a - b);
						break;
					}

					case "/" :
					{
						Console.WriteLine(a / b);
						break;
					}

					case "*" :
					{
						Console.WriteLine(a * b);
						break;
					}
					
					case "?" :
					{
						return;
					}
				}
			}
		}
	}


}

Measured memory_bytes: 7344
import sys
input = sys.stdin.readline

def main():
  
  def knapsack_price(single=True):
    V = sum(price_list)
    dp_max = W + 1
    dp = [dp_max] * (V+1)
    dp[0] = 0
    
    for i in range(N):
      if single:
        S = list(reversed(range(price_list[i], V+1)))
      else:
        S = list(range(price_list[i], V+1))
      for price in S:
        dp[price] = min(dp[price], dp[price - price_list[i]] + weight_list[i])
    
    return max(price for price in range(V+1) if dp[price] <= W)
  
  N,W = map(int,input().split())
  
  price_list = []
  weight_list = []
  for _ in range(N):
    weight, price = map(int,input().split())
    price_list.append(price)
    weight_list.append(weight)
    
  print(knapsack_price(single=True))

if __name__ == '__main__':
    main()

Measured memory_bytes: 96376
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
ans = 0
mod = 10**9+7
C = [1]*(N+1)
for t in T:
    d = 0
    for i, s in enumerate(S):
        d_ = C[i]
        if t==s:
            ans = (ans + d_) % mod

        C[i] += d
        C[i] %= mod
        if t==s:
            d += d_
            d %= mod
print(ans+1)


Measured memory_bytes: 43740
a, b, c, x, y = map(int, input().split())
if a+b > 2*c:
  temp_1 = 2 * min(x, y) * c
  if x > y:
    temp_1 += (x - y) * a
  else:
    temp_1 += (y - x) * b
  temp_2 = 2 * max(x, y) * c
  if temp_1 < temp_2:
    price = temp_1
  else:
    price = temp_2
else:
  price = x * a + y * b
print(price)

Measured memory_bytes: 3064
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	input(arr,n);
	ll dp[n];
	dp[0]=0,dp[1]=abs(arr[1]-arr[0]);
	for(ll i=2;i<n;i++)
	dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	int n;
	string s;
	cin>>s;
	n = s.length();
	
	bool f = (s[n-1] == '0') && (s[0] == '1');
	for(int i=0;i<n/2;i++) {
		f = f & (s[i] == s[n-i-2]);
	}
	
	if(!f) {cout<<"-1"<<endl;return 0;}
	
	int total = 1;
	
	vector<pair<int, int> > v;
	for(int i=1;i<n-1;i++) {
		int num = i+1;
		if(s[i] == '1') {
			for(int j=total+1;j<=num;j++) v.PB(MP(total, j));
			v.PB(MP(total, num+1));
			total = num+1;
		}
	}
	
	for(int i=0;i<v.size();i++) cout<<v[i].X<<" "<<v[i].Y<<endl;
	
    return 0;
}



Measured memory_bytes: 2420
#!/usr/bin/env python3
import sys, math, fractions, itertools

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    R = list(reversed(list(S)))
    tmp = ''
    for r in R:
        tmp = r + tmp
        if tmp in ['dream', 'dreamer', 'erase', 'eraser']:
            tmp = ''
        else:
            if len(tmp) >= 7:
                print('NO')
                return
    print('YES')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

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

    int n,c,k;cin>>n>>c>>k;
    vector<int> t(n);
    for(int i=0;i<n;i++)cin>>t[i];

    sort(t.begin(),t.end());

    int ans=0;

    for(int i=0;i<n;i++)
    {
        int cnt=c-1;
        for(int j=0;j<c;j++)
        {
            if(j+i>=n)
            {
                cnt=j-1;
                break;
            }
            if(t[j+i]-t[i]>k)
            {
                cnt=j-1;
                break;
            }
        }
        i+=cnt;
        ans++;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3728
n, m = map(int, input().split())
mod = 10**9+7

def prime_decomposition(n):
    p = 2
    prime = {}
    while n!=1:
        while n%p == 0:
            n = n//p
            if p not in prime:
                prime[p] = 0
            prime[p] += 1
        p += 1
    return prime

primes = prime_decomposition(m)
# print(primes)
ans = 1

def combination(n,k):
    ret1 = 1
    ret2 = 1
    for i in range(k):
        ret1 *= n-i
        ret2 *= k-i
    return ret1//ret2

for pw in primes.values():
    comb = combination(pw+n-1, pw)
    ans *= comb
    ans %= mod

print(ans)


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

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    string start, end;
    int p = 0;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            p = 1 - p;
        }
        else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if(f == 1 && p == 0 || f == 2 && p == 1) {
                start.push_back(c);
            }
            else {
                end.push_back(c);
            }
        }
    }
    if(p == 0) {
        for(int i = 0; i < start.length(); i++) {
            cout << start[start.length() - i - 1];
        }
        for(int i = 0; i < s.length(); i++) {
            cout << s[i];
        }
        for(int i = 0; i < end.length(); i++) {
            cout << end[i];
        }
    }
    else {
        for(int i = 0; i < end.length(); i++) {
            cout << end[end.length() - i - 1];
        }
        for(int i = 0; i < s.length(); i++) {
            cout << s[s.length() - i - 1];
        }
        for(int i = 0; i < start.length(); i++) {
            cout << start[i];
        }        
    }
    cout << "\n";
}

Measured memory_bytes: 3984
use std::io::{self, Read};

fn main() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer);

    let st: Vec<&str> = buffer.lines().collect();

    let f = st.get(0).unwrap();
    let s = st.get(1).unwrap();

    let mut answ = 0;

    for i in 0..3 {
        if f.chars().nth(i) == s.chars().nth(i) {
            answ += 1;
        }
    }

    println!("{}", answ);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  a += b,c += d;
  if(a > c){
    printf("Left\n");
  }else if(a < c){
    printf("Right\n");
  }else{
    printf("Balanced\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
int main(void)
{
   optimize
   ll n,x,y;
   ll mx1=INT_MIN,mx2=INT_MIN,mn1=INT_MAX,mn2=INT_MAX;
   cin>>n;
   for(ll i=0;i<n;i++)
   {
      cin>>x>>y;
      mx1=max(mx1,x+y);
      mn1=min(mn1,x+y);
      mx2=max(mx2,x-y);
      mn2=min(mn2,x-y);
   }
   cout<<max(mx1-mn1,mx2-mn2)<<endl;
   return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main (){
  char b;
  cin >> b;
  if (b=='A') {
    cout << 'T' << endl;
  }
  if (b=='T') {
    cout << 'A' << endl;
  }
  if (b=='C') {
    cout << 'G' << endl;
  }
  if (b=='G') {
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 256
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a, b = invr()

print(a*b)

Measured memory_bytes: 9124
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 1e9+10;
string s;
int main()
{
    _SAD()

    cin>>s;
    bool n=false,ss=false,e=false,w=false;
    for(int i=0;i<SZ(s);i++)
    {
		if(s[i]=='N')
		{
			n=true;
		}
		if(s[i]=='E')
		{
			e=true;
		}
		if(s[i]=='S')
		{
			ss=true;
		}
		if(s[i]=='W')
		{
			w=true;
		}
	}
	if(ss)
	{
		if(!n)
		{
			cout<<"No"<<nl;
			return 0;
		}
	}
	if(!ss)
	{
		if(n)
		{
			cout<<"No"<<nl;
			return 0;
	}	
	}
	if(e)
	{
		if(!w)
		{
			cout<<"No"<<nl;
			return 0;
		}
	}
	if(!e)
	{
		if(w)
		{
			cout<<"No"<<nl;
			return 0;
		}
	}
	cout<<"Yes"<<nl;
    return 0;
}


Measured memory_bytes: 256