akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		Random rn = new Random();
		DecimalFormat df = new DecimalFormat("#,###.##");

		int N = sc.nextInt(), counter = 0;
		double pobobility = 0;

		for(int i = 0; i <= N; i++)
		{
			if (!(i%2==0))
				pobobility++;
		}
		pobobility = pobobility / N;

		System.out.println(pobobility);

	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

#define next _
const int maxn  = 2e5+10, mod=1e9+7;
vector<int>a(maxn),dp(maxn),next(maxn),mp(maxn);
int n;
int32_t main(){
	IOS
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=n;i>=1;i--){
		if( mp[a[i]] ){
			next[i] = mp[a[i]];
		}
		mp[a[i]]=i;
	}
	dp[n]=1;
	for(int i=n-1;i>=1;i--){
		dp[i]+=dp[i+1];
		if(next[i] && next[i]!=i+1){
			dp[i]+=dp[next[i]];
		}
		dp[i]%=mod;
	}
	cout<<dp[1];
	
 }
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 9456
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int quo = a / b;
		int rem = a % b;
		double de = 1.0 * a / b;
		String dec = String.format("%.8f", de);
		System.out.println(quo+" "+rem+" "+dec);
	}	
}

Measured memory_bytes: 26488
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
using namespace std;
const int N=1e3+5;
const int M=2e5+5;
bitset<N> vis;
bool vis1[N][N],vis2[N][N];
int n,m,a[M],b[M],mark[N];
vector<int> to[N];
inline void dfs1(int u,int s){
	if(vis1[s][u]) return;
	vis1[s][u]=1;
	for(re int i=0;i<to[u].size();i++) dfs1(to[u][i],s);
}
inline void dfs2(int u,int s,int tp,int c){
	if(vis[u]) return;
	vis[u]=1;
	if(!tp) mark[u]=c;
	else vis2[s][u]=(c!=mark[u]);
	for(re int i=0;i<to[u].size();i++) dfs2(to[u][i],s,tp,c);
}
int main(){
	scanf("%d%d",&n,&m);
	inc(i,1,m){
		scanf("%d%d",&a[i],&b[i]);
		to[a[i]].push_back(b[i]);
	}
	inc(i,1,n) dfs1(i,i);
	inc(u,1,n){
		vis.reset(),vis[u]=1;
		for(re int i=0;i<to[u].size();i++) dfs2(to[u][i],u,0,i);
		vis.reset(),vis[u]=1;
		for(re int i=to[u].size()-1;~i;i--) dfs2(to[u][i],u,1,i);
	}
	inc(i,1,m) puts(vis1[b[i]][a[i]]^vis2[a[i]][b[i]]?"diff":"same");
}

Measured memory_bytes: 8708
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

	string S;
	cin >> S;

	vector<int> count(N, 0);

	repl(i, 1, count.size())
	{
		count[i] = count[i - 1];

		if (S[i - 1] == 'A' && S[i] == 'C')
		{
			count[i] += 1;
		}
	}

	vector<pair<int, int>> queries;

	rep(i, Q)
	{
		int l, r;
		cin >> l >> r;

		l--;
		r--;

		queries.emplace_back(l, r);
	}


	for (auto q : queries)
	{
		cout << count[q.second] - count[q.first] << endl;
	}

	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  ll X, Y;
  cin >> X >> Y;
  if (X % Y == 0) {
    cout << -1 << endl;
  } else {
    cout << X << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200200;
inline int read(int x=0,bool f=0,char ch=getchar()){
	for(;!isdigit(ch);ch=getchar()) f=ch=='-';
	for(; isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return f?-x:x;
}
int n,m,tot,ccc,fi[N],to[N],u[N],ne[N];
bool vis[1010][1010];
int pre[1010][1010],suf[1010][1010],que[N],l,r;
vector<int> g[1010];
void dfs(int x,int id){
	vis[id][x]=true;
	for(int i:g[x]) if(!vis[id][i]) dfs(i,id);
}
void dfs1(int x,int id,int k){
	pre[id][x]=k;++ccc;
	for(int i:g[x]) if(!pre[id][i]) dfs1(i,id,k);
}
void dfs2(int x,int id,int k){
	suf[id][x]=k;
	for(int i:g[x]) if(!suf[id][i]) dfs2(i,id,k);
}
int main(){
//	freopen("t.in","r",stdin);
//	freopen("1.out","w",stdout);
	n=read(),m=read();
	for(int i=1,x,y;i<=m;++i) x=read(),y=read(),ne[++tot]=fi[x],u[tot]=x,to[fi[x]=tot]=y,g[x].push_back(y);
	for(int i=1;i<=n;++i) dfs(i,i);
	for(int i=1;i<=n;++i){
		vector<int> s; int sz=0; pre[i][i]=suf[i][i]=1;
		for(int j=fi[i];j;j=ne[j]) s.push_back(to[j]);
		for(int j:s){
			++sz;
			if(!pre[i][j]) dfs1(j,i,sz);
		}
		reverse(s.begin(),s.end());
		for(int j:s){
			if(!suf[i][j]) dfs2(j,i,sz);
			--sz;
		}
	}
	for(int i=1;i<=m;++i){
		int x=u[i],y=to[i];
		if(vis[y][x]^(pre[x][y]!=suf[x][y])) puts("diff");
		else puts("same");
	}
	return 0;
}

Measured memory_bytes: 16356
/*
	Created by Faisal Ahmed
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ll n, a, b;
	
	cin >> n >> a >> b;
	
	ll d = n / (a + b);
	ll r = n % (a + b);
	
	ll ans = d * a + min(r, a);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define mod 10007
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans=0,a[5]={0,0,0,0,0};
  s='J'+s;
  if(s[1]=='J') {
    a[2]=0;
    a[3]=0;
    a[4]=1;
  } else {
    a[2]=1;
    a[3]=0;
    a[4]=0;
  }
  for(int i=2; i<=s.size(); i++) {
    int x=a[2],y=a[3],z=a[4];
    if(s[i]==s[i-1]) {
      a[2]=0;
      a[3]=0;
      a[4]=(x*2+y*3+z*4)%mod;
    } else if(s[i]==s[i-2]) {
      a[2]=z;
      a[3]=(y+z)%mod;
      a[4]=(x*2+y*2+z*2)%mod;
    } else {
      a[2]=z;
      a[3]=(x+y+z)%mod;
      a[4]=(x+y*2+z*2)%mod;
    }
  }
  cout << (a[2]+a[3]+a[4])%mod << endl;
  return 0;
}


Measured memory_bytes: 1212
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
typedef pair <int ,int> P;
int main()
{
    int n,m;
    cin>>n>>m;
    vector <P> v;
    P p;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        p.first=a;
        p.second=b;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    priority_queue <int/*,vector<int>,greater<int>*/> p_q;
    long long ans=0;
    p=v.back();
    for(int i=1;i<=m;i++){
        while(p.first==i){
            int q;
            q=p.second;
            p_q.push(q);
            /*cout<<q<<' '<<i<<endl;*/
            v.pop_back();
            if(!v.empty()){p=v.back();}
            else{p.first=m+1;}
        }
        if(!p_q.empty()){
            ans=ans+p_q.top();
            p_q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

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

	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int total = 1e9;

	for (int i = 0; i <= 100000; i++) {
		int x = max(0, X - i);
		int y = max(0, Y - i);
		total = min(total, x*A + y*B + i*C * 2);
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>

int main(void){

	int a, b, c;
	int res1, res2, res3;
	int sum = 0;

	scanf("%d%d%d", &a, &b, &c );

	res1 = abs(a-b);
	res2 = abs(a-c);
	res3 = abs(b-c);

	if( res1 > res2 ){
		if( res1 > res3 ){
			sum = res2 + res3;
		}
		else{
			sum = res1 + res2;
		}
	}
	else{
		if( res2 > res3 ){
			sum = res1 + res3;
		}
		else{
			sum = res1 + res2;
		}
	}
	printf( "%d", sum );

	return 0;
}

Measured memory_bytes: 128
import scala.collection.mutable.ListBuffer


class Sum(str : String) {

  def eval(expr : String) : Long = {
    val arr = expr.split("\\+")
    var sum : Long = 0
    arr.foreach(s => {
      sum += s.toLong
    })

    sum
  }

  def getSum(): Long = {
    def getSumItr(index : Int) : List[String] = {
      if (index == str.length-1) {
        List(str.last.toString)
      }else {
        val current = str.charAt(index).toString
        val subLst = getSumItr(index+1)
        val lstBuffer = new ListBuffer[String]
        subLst.foreach(subElement => {
          val updatedElement = current + subElement
          lstBuffer.+=(updatedElement)
          val newElement = current + "+" + subElement
          lstBuffer.+=(newElement)
        })
        lstBuffer.toList
      }
    }

    val lst = getSumItr(0)
    var sum : Long = 0
    lst.foreach(elem => {
      sum += eval(elem)
    })

    sum

  }
}

object Main extends  App {
//  val s = new Sum("9999999999")
//  println(s.getSum())
  var a = readLine()
//  var num = readLine
//  var s = readLine
//  var sum = a + num.split(" ")(0).toInt + num.split(" ")(1).toInt
  val s  = new Sum(a)
  println(s.getSum())
}


Measured memory_bytes: 22204
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main {
     public static void main(String[] args) throws IOException {
         StringBuilder sb = new StringBuilder();
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

         while(true) {
             String str[] = br.readLine().split(" ");
             int h = Integer.parseInt(str[0]);
             int w = Integer.parseInt(str[1]);
             
             if (h==0&&w==0) break;
             
             for (int i=0; i<h; i++) {
                 for (int j=0; j<w; j++) {
                     if ((i+j)%2 == 0) sb.append("#");
                     else sb.append (".");
                 }
                 sb.append("\n");
             }
             sb.append("\n");
         }
         System.out.print(sb);
     }
}

Measured memory_bytes: 25544
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        double x1=sc.nextDouble();
        double y1=sc.nextDouble();
        double x2=sc.nextDouble();
        double y2=sc.nextDouble();
        double dis=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        System.out.println(dis);
    }
}



Measured memory_bytes: 28080
#include<stdio.h>
#include<math.h>
#define MAX 10000
int main()
{
  int h,li,be,b=0; /*li,beはカウンタ変数*/
  int he[MAX];
  scanf("%d",&h);
  for(li=0;li<h;li++)
    {
      scanf("%d",&he[li]);
    }
  for(li=0;li<h;li++)
    {
      for(be=2;be<=sqrt(he[li]);be++)
	{
	  if(he[li] % be == 0)
	    {
	      b++;
	      break;
	    }
	}
    }
  printf("%d\n",h-b);
  return 0;
}

Measured memory_bytes: 628
N = gets.to_i
a = gets.split.map(&:to_i)

box = Array.new(N, 0)

a.reverse[0..(N - 2)].each_with_index do |an, i|
  b = N - i

  v = 0
  (b * 2).step(N, b) do |j|
    v += box[j - 1]
  end

  if an == 1 && v.even?
    box[b - 1] = 1
  elsif an == 0 && v.odd?
    box[b - 1] = 1
  end
end

v = box.inject(:+)

if v.even?
  if a[0] == 1
    box[0] = 1
    v += 1
  end
else
  if a[0] == 0
    box[0] = 1
    v += 1
  end
end

p v

if v == 0
  exit
end

result = []
box.each_with_index do |d, i|
  result << i + 1 if d == 1
end

puts result.join(' ')


Measured memory_bytes: 23564
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e3 + 10, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int arr[N] = { }, dp[N][N][2] = { }, n, z;
int solve(int idx, int pr, bool c) {
	if (idx >= n)
		return abs(arr[pr] - arr[n]);
	int &ret = dp[idx][pr][c];
	if (ret != -1)
		return ret;
	int c1 = solve(idx + 1, pr, c);
	int c2 = solve(idx + 1, idx, !c);
	if (c)
		ret = max(c2, c1);
	else
		ret = min(c2, c1);
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	cin >> n >> z >> arr[0];
	lp(i,1,n)
		cin >> arr[i];
	clr(dp, -1);
	cout << solve(1, 0, 1);
	return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    long long int n,c=0,cx=0,r;
    cin>>n;
    vector<long long int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    if(n==1){
        cout<<1;
        return 0;
    }
    sort(a.begin(),a.end());
    r=a[0];
    for(int i=0;i<n;i++){
        if(a[i]==r){
            cx++;
        }else{
            if(cx%2==0){
                c+=0;
            }else{
                c++;
            }
            r=a[i];
            cx=1;
        }
    }
    if(cx>0&&cx%2==1){
        c++;
    }
    cout<<c;
}

Measured memory_bytes: 1024
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    l=LI()
    l.sort(reverse=True)
    ans=sum(l[:K])
    print(ans)

main()



Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
#define int long long int
using namespace std;
typedef pair<int,int> pii;

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

  int a,b;
  vector<int> v;
  vector<pii> p1,p2;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    p1.pb(pii(a+b,i));
    p2.pb(pii(a,b));
  }
  
  sort(p1.begin(),p1.end(),greater<pii>());
  //sort(p2.begin(),p2.end(),greater<pii>());

  int res=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      res+=p2[p1[i].second].first;
    }
    else{
      res-=p2[p1[i].second].second;
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3564
N=int(input())
a=list(map(int,input().split()))
A=[0]*N
B=[]
for i in range(N//2,N):
    if a[i]==1:
        A[i]=1
        B.append(i+1)
for i in range(N//2)[::-1]:
    asum=0 
    x=i+1
    for j in range(i,N,x):
        asum=asum+A[j]
    if asum%2!=a[i]:
        A[i]=1
        B.append(i+1)
count=sum(A)
print(count)
if count!=0:
    print(*B)

Measured memory_bytes: 14072
s=input()

def c(a): return ord(a) - ord('a')

d=[-100]*26
for i,v in enumerate(s):
    if i-d[c(v)] <=1:
        print(i,i+1)
        exit()
    elif i-d[c(v)] <=2:
        print(i-1,i+1)
        exit()
    d[c(v)]=i
print(-1,-1)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  vector<int> cnt(100000);
  rep(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  int ans = 0;
  rep(i, 100000-2) {
    chmax(ans, cnt[i]+cnt[i+1]+cnt[i+2]);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4508
//#undef DEBUG
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
const char lf = '\n', splf[] = " \n";
#define all(x) begin(x), end(x)
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
#define TCC template<class C
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
#define ENI typename enable_if<
#define DTOR , Dbg&>::type operator<<
#define RIS return *this
TCC> static auto o(C *x)->decltype(os << *x, 0);
TCC> static char o(...);
TCC> ENI sizeof o<C>(0)!=1 DTOR(const C &x) {os<<x; RIS;}
TCC> Dbg &dump(C b, C e) {
    int ii = 0;
    for(C i = (os << "\n[", b); i!=e and ii<26; i++, ii++) *this << ", "+2*(i==b) << *i;
    RIS << ']';
}
TCC> ENI sizeof o<C>(0)==1 DTOR(const C &x) {
    return dump(all(x));
}
TCC, size_t X> ENI !is_same<C, const char>::value DTOR(C (&x)[X]) {
    return dump(all(x));
}
TCC, class D> Dbg &operator<<(const pair<C, D> &x) {RIS<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(ostream&)) { os << x; RIS; }
} dbg;
void err(istringstream *iss) { delete iss; }
TCC, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#ifdef DEBUG
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
int T = 1, Q, cn;
const int inf = 1000000007, mxn = -1;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> T;
    auto kase = [&]()->void {   // if T>1, inputAll + resetAll -> solution
        //cout << "Case " << cn << ":";
        int d,t,s;
        cin>>d>>t>>s;
        cout<<(s*ll(t)>=d? "Yes": "No")<<lf;
    };
    while (cn++!=T) kase();
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    string s; ll k; cin >> s >> k;
    int n = s.length();

    bool same = true;
    ll cnt = 0;
    FOR(i, 1, n) {
        same &= s[0] == s[i];
        if (s[i] == s[i - 1]) {
            ++cnt, ++i;
        }
    }
    if (same) {
        cout << n * k / 2 << "\n";
        return 0;
    }

    cnt *= k;
    if (s[0] != s[n - 1]) {
        cout << cnt << "\n";
        return 0;
    }

    ll a = 1, b = 1;
    for (int i = 1; i < n && s[i] == s[i - 1]; ++a, ++i);
    for (int i = n - 1; i && s[i] == s[i - 1]; ++b, --i);

    cout << cnt - (k - 1)* (a / 2 + b / 2 - ((a + b) / 2));
}


Measured memory_bytes: 256
def main():
    N, A, B = (int(_) for _ in input().split())
    X = [int(_) for _ in input().split()]

    output = 0
    for i in range(1, N):
        d = X[i] - X[i-1]
        output += min(A * d, B)
    print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double


// EDITORIAL HELP
// NUMBER of connected comp = No of nodes - no of edges
int32_t main() 
{
    IOS;
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=i*(n-i+1);
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a>b)
            swap(a,b);
        ans-=a*(n-b+1);
    }
    print(ans);
}   

Measured memory_bytes: 3660
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;

    int ans = (int)(X-Z)/(Y+Z);

    cout << ans << endl;
}

Measured memory_bytes: 504
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

void alpha(){

	ll n;
	cin>>n;

	ll arr[n];
	loop(i,0,n) cin>>arr[i];

	ll count=0;

	ll exists_till = 0;
	map<ll, ll> mp;

	for(ll i=n-1; i>=0; i--){
		if(arr[i]==exists_till+1) {
			count++;
			exists_till+=2;
			while(mp[exists_till]!=0){
				mp.erase(exists_till);
				exists_till++;
			}
			exists_till--;
		}
		else{
			mp[arr[i]]=1;
		}
	}

	cout<<count<<endl;

	return;
}

int main(){

	ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

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

int main() {
	string s;
	while (cin >> s) {
		if (s == "0")break;

		int a = s.size();
		int ap = 0, bp = 0;
		for (int i = 1;i < a;i++) {
			if (s[i] == 'A')ap++;
			else bp++;
		}
		if (ap < bp)bp++ ;
		else ap++;
		cout << ap << ' ' << bp << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
import os
import sys

n,k = map(int, input().split())
a = [x for x in map(int, input().split())]

d = {}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1

s_d = sorted(d.items(), key=lambda x: x[1])

if(len(d) <= k):
    print(0)
    exit(0)

tmp = len(d)
ans = 0


for _,v in s_d:
    tmp-=1
    ans += v
    if(tmp==k):
        break

print(ans)
exit(0)




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

int main(){
    using namespace std;
    size_t W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << (W * H) / 2;
    if(W & H & 1)cout << ".5";
    cout << " " << (x * 2 == W && y * 2 == H) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
b_list = list(map(int, input().split()))
ans = []
while b_list:
    for i, b in enumerate(b_list):
        if i+1 == b:
            next_i = i
        if i+1 < b:
            print(-1)
            exit()
    ans.append(b_list.pop(next_i))
for i in reversed(ans):
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


void multiple_of_2_and_n()
{
  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

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

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


void atcoder_crackers()
{
  int n, k;
  cin >> n >> k;

  if (n % k == 0) cout << 0 << "\n";
  else cout << 1 << "\n";
}


void garden()
{
  int a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}


void train()
{
  int n, i;
  cin >> n >> i;

  cout << n - i + 1 << "\n";
}


void Pair()
{
  int k;
  cin >> k;

  if (k % 2 == 0) cout << k / 2 * k / 2 << "\n";
  else cout << k / 2 * (k / 2 + 1) << "\n";
}


void ABC333()
{
  int a, b;
  cin >> a >> b;

  if ((a == 1 && (b == 1 || b == 3)) || (a == 3 && (b == 1 || b == 3))) cout << "Yes\n";
  else cout << "No\n";
}


void maximize_the_formula()
{
  int a, b, c;
  cin >> a >> b >> c;

  int v_max = max({ a,b,c });
  cout << a + b + c + 9 * v_max << "\n";
}


void digit_sums()
{
  int n;
  cin >> n;

  int s = 0, tmp = n;
  while (tmp > 0)
  {
    s += tmp % 10;
    tmp /= 10;
  }
  if (n % s == 0) cout << "Yes\n";
  else cout << "No\n";
}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  //rated_for_me();
  //atcoder_crackers();
  //garden();
  //train();
  //Pair();
  //ABC333();
  //maximize_the_formula();

  digit_sums();
}

Measured memory_bytes: 256
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const ll N = 1e5 + 15, MOD =  998244353;

void solve() {
    int n;
    cin >> n;
    vector<int> cnt(N);
    ll s = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
        s += x;
    }
    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        cnt[c] += cnt[b];
        s += cnt[b] * (c - b);
        cnt[b] = 0;
        cout << s << "\n";
    }
}


int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    } 
}                                   

Measured memory_bytes: 3716
#include<stdio.h>

int main(void){
	int n, x;
	int i, j, k;
	int count;

	while(1){
	scanf("%d %d", &n, &x);

	if(n == 0 && x == 0){
		break;
	}
	
	count = 0;
	for(i = 1; i <= n; i++){
		for(j = i; j <= n; j++){
			for(k = j; k <= n; k++){
				if(i != j && (j != k && (i != k))){
					if(x == (i + j + k)){
						count++;
						//printf("%d %d %d %d\n", i + j + k, i, j, k);
					}
				}
			}
		}
	}

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a, b, x;
    cin>>a>>b>>x;
    double r;
    if(x <= a*a*b/2) r = atan2(b*b, 2*(x/a));
    else r = atan2(2*(a*b-(x/a)), a*a);
    double ans = r/(2*acos(-1)) * 360;
    cout << fixed << setprecision(12) << ans << endl;
}


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

ll N;
vector<ll> A;
vector<ll> B;

void solve() {
  vector<ll> D(N);
  for(int i = 0 ; i < N ; i++) D[i] = A[i] - B[i];
  sort(D.rbegin(), D.rend());
  if( accumulate(D.begin(), D.end(), 0ll) < 0 ){
    cout << -1 << endl;
    return;
  }
  long long sum = 0;
  int cnt = 0;
  for(int i = 0 ; i < N ; i++){
    if( D[i] < 0 ){
      sum += -D[i];
      cnt++;
    }
  }
  for(int i = 0 ; i < N ; i++){
    if( D[i] > 0 && sum > 0 ){
      sum -= D[i];
      cnt++;
    }
  }
  cout << cnt << endl;

}

void input() {
  N = ll();
  scanf("%lld", &N);
  A = vector<ll>(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  B = vector<ll>(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
}

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


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(long long i=0;i<int(N);++i)
using ll = long long;
// const int INF = 2147483647;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 double n,x,t;
	 cin >> n >> x >>t;
	 ll ans = ceil(n/x)*t;
	 cout << ans << endl;
	 return 0;
 }

Measured memory_bytes: 3736
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX];
ll s[MX], res = 1e18;

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

	forn (i, n) {
		cin >> a[i];
		s[i] = a[i];
		if (i) s[i] += s[i - 1];
	}

	forn (i, n - 1) {
		int p1 = lower_bound(s, s + n, s[i] / 2) - s;
		int p2 = lower_bound(s, s + n, s[i] + (s[n - 1] - s[i]) / 2) - s;

		for (int x = p1 - 4; x < p1 + 4; x++)
			for (int y = p2 - 4; y < p2 + 4; y++)
				if (0 <= x && x < i && i < y && y < n - 1) {
					vector<ll> v = {
						s[x],
						s[i] - s[x],
						s[y] - s[i],
						s[n - 1] - s[y]
					};
					sort(all(v));
					res = min(res, v[3] - v[0]);
				}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2560
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> G[200020];
vector<ll> P(200020),A(200020);
vector<ll> par(200020,-1);

void dfs(int u){
  A[u]=P[u]+A[par[u]];
  for(auto x:G[u]){
    if(par[x]!=-1) continue;
    par[x]=u;
    dfs(x);
  }
}

int main() {
  int q;
  cin>>n>>q;
  
  par[0]=0;

  int a,b;
  rep(i,n-1){
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  ll p,x;
  rep(i,q){
    cin>>p>>x;
    p--;
    P[p]+=x;
  }
  
  dfs(0);
  
  rep(i,n){
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 25120
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

typedef pair<int, char> P;

int main()
{
    int s1, s2;
    vector<P> shop(5);
    while(cin >> s1 >> s2 && s1 && s2) {
        shop[0] = P(s1 + s2, 'A');
        for(int i = 1; i < 5; i ++) {
            cin >> s1 >> s2;
            shop[i] = P(s1 + s2, 'A' + i);
        }

        sort(shop.begin(), shop.end());
        cout << shop[4].second << " " << shop[4].first << endl;
    }
    return 0;
}

Measured memory_bytes: 0
N = int(input())
S = input()
s = set(S)
count = 0
maxx = 0
for i in range(N): #切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  for(;;){
    int a[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)a[i][j]=0;
    string s;cin>>s;
    if(s=="#")exit(0);
    int x1,y1,x2,y2;
    cin>>y1>>x1>>y2>>x2;
    y1--;x1--;y2--;x2--;
    int h=0,w=0;
    for(int i=0;i<(int)s.size();i++){
      if(s[i]=='/'){h++;w=0;continue;}
      if(s[i]=='b'){
        a[h][w]++;
        w++;
      }else{
        int noww=s[i]-'0';
        for(int j=0;j<noww;j++){
          w++;
        }
      }
    }
    h++;
    a[y1][x1]--;
    a[y2][x2]++;
    string ans="";
    for(int i=0;i<h;i++){
      int now=0;
      for(int j=0;j<w;j++){
        if(a[i][j]==1){
        if(now!=0){ans+=to_string(now);now=0;}
        ans+='b';
      }else{
          now++;
        }
      }
      if(now!=0)ans+=to_string(now);
      ans+='/';
    }
    cout<<ans.substr(0,ans.size()-1)<<endl;
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int main() 
{
	unsigned long long int n ,k,q,inp;
	unsigned int a[100000];
	int i;
	cin >> n >> k >> q;
	for(i = 0;i<n;i++)
		a[i]=0;
	for (i = 0; i < q; i++)
	{
		cin >> inp;
		inp--;
		a[inp]++;
	}
	for (i = 0; i < n; i++)
	{
		if ( q - a[i] < k )
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int MOD = 1000000007;
//const int INF = 1e15;
using Graph = vector<vector<int>>;

//(i, j)に到着する道のりのうち、差がkのものがあるか
bool dp[85][85][13000];

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

  vector<vector<int>> A(H+2, vector<int>(W+2));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ) cin >> A[i][j];
  }

  vector<vector<int>> B(H+2, vector<int>(W+2));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ) cin >> B[i][j];
  }

  dp[0][0][abs(A[0][0]-B[0][0])] = true;
  dp[0][0][abs(B[0][0]-A[0][0])] = true;

  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      for( int k = 0; k <= 12800; k++ ){
        if( dp[i][j][k] == true ){
          //下へ移動する場合
          dp[i+1][j][abs(k + A[i+1][j]-B[i+1][j])] = true; //Aを赤く塗ったとき
          dp[i+1][j][abs(k + B[i+1][j]-A[i+1][j])] = true; //Bを赤く塗ったとき
          //右へ移動する場合
          dp[i][j+1][abs(k + A[i][j+1]-B[i][j+1])] = true;
          dp[i][j+1][abs(k + B[i][j+1]-A[i][j+1])] = true;
        }
      }
    }
  }

  for( int i = 0; i <= 12800; i++ ){
    if( dp[H-1][W-1][i] == true ){
      cout << i << endl;
      return 0;
    }
  }


}


Measured memory_bytes: 87424
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC126
{
    class Dist
    {
        public long nextvertex { get; set; }
        public long distance { get; set; }

        public Dist(long v, long d)
        {
            nextvertex = v;
            distance = d;
        }
    }

    class D
    {
        static bool[] Res;
        static List<Dist>[] list;

        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            Res = new bool[N];
            list = new List<Dist>[N];

            long[] input;
            long u = 0;
            long v = 0;
            long w = 0;
            for (long i = 0; i < N - 1; i++)
            {
                input = Console.ReadLine().Split().Select(long.Parse).ToArray();
                u = input[0] - 1;
                v = input[1] - 1;
                if (input[2] % 2 == 0) w = 0;
                else if (input[2] % 2 == 1) w = 1;

                if (list[u] == null) list[u] = new List<Dist>();
                if (list[v] == null) list[v] = new List<Dist>();
                list[u].Add(new Dist(v, w));
                list[v].Add(new Dist(u, w));
            }

            DFS(0, 0, false);

            foreach (var item in Res)
            {
                Console.WriteLine(item ? "1" : "0");
            }
        }

        static void DFS(long now, long previous, bool check)
        {

            Res[now] = check;
            if (list[now] == null) return;

            foreach (var item in list[now])
            {
                if (item.nextvertex != previous) DFS(item.nextvertex, now, item.distance % 2 == 0 ? check : !check);
            }
        }
    }
}


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

vector<int> divisorEnum(long long n) {
    vector<int> ret;
    for (int i = 1; i <= sqrt(n) + 1; i++) {
        if (n % i == 0) {
            ret.push_back(i);
        }
    }
    sort(ret.begin(), ret.end(), greater<int>());
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (1) {
        long long n;
        cin >> n;
        if (!n) break;

        vector<int> divisor = divisorEnum(2 * n);
        for (auto i : divisor) {
            int res = (n - i * (i - 1) / 2);
            if (res % i == 0 && res > 0) {
                cout << res / i << " " << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3188
import sys

s = input()
k = int(input())

flg = True
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        flg = False
        break

if flg:
    print(len(s) * k // 2)
    sys.exit()

ans = 0
skip = -1
for i in range(len(s) - 1):
    if i == skip:
        continue
    
    if s[i] == s[i + 1]:
        ans += 1
        skip = i + 1
        
#print(ans)
ans *= k


if s[0] == s[-1]:
    cnt_h = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
    cnt_t = 1
    for i in reversed(range(1, len(s))):
        if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
    cnt = cnt_h // 2 + cnt_t // 2
    cnt -= (cnt_h + cnt_t) // 2
    cnt *= k - 1
    ans -= cnt

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n, rank;
    bool card[4][13];
    char c;
    string suits="SHCD";
 
    for (int i=0; i<4; i++)
        for (int j=0; j<13; ++j) 
            card[i][j] = true;
    
    cin >> n;
    for (int i=0; i<n; i++){
        cin>>c>>rank;
        card[suits.find(c)][rank-1] = false;
    }
 
    for(int i=0;i<4;i++)
      for(int j=0;j<13;j++) 
            if(card[i][j]==true) cout<<suits.at(i)<<" "<<j+1<<endl;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define Eps (1e-10)

int main() {
  double x[4], y[4];
  while (cin >> x[0] >> y[0]) {
    for (int i = 1; i < 4; ++i) cin >> x[i] >> y[i];
    double S, subS;
    S = fabs((x[0]*y[1] + x[1]*y[2] + x[2]*y[0]
              - y[0]*x[1] - y[1]*x[2] - y[2]*x[0]) / 2);
    
    subS = fabs((x[0]*y[1] + x[1]*y[3] + x[3]*y[0]
              - y[0]*x[1] - y[1]*x[3] - y[3]*x[0]) / 2);
    subS += fabs((x[0]*y[3] + x[3]*y[2] + x[2]*y[0]
              - y[0]*x[3] - y[3]*x[2] - y[2]*x[0]) / 2);
    subS += fabs((x[3]*y[1] + x[1]*y[2] + x[2]*y[3]
              - y[3]*x[1] - y[1]*x[2] - y[2]*x[3]) / 2);
    printf("%s\n", (fabs(S-subS) < Eps) ? "YES" : "NO");
  }
 
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	string S;  cin >> S;
	int N = S.size();
	int ALL = 1 << (N - 1);

	ll ans = 0;

	FOR(i, 0, ALL) {
		int t = i;
		ll term = S[0] - '0';

		FOR(j, 1, N) {
			if (t & 0x01) {
				ans += term;
				term = 0;
			}
			else {
				term *= 10;
			}
			term += S[j] - '0';
			t >>= 1;
		}

		ans += term;
	}

	cout << ans << endl;
	return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

// make vector of divisor O(sqrt(n))
vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int f(ll a, ll b) {
    return max(ceil(log10(a + 1)), ceil(log10(b + 1)));
}

int main() {
    ll n;
    cin >> n;
    vector<ll> d = divisor(n);
    vector<P> p;
    int s = d.size();
    for (ll i = 0; i < s; i += 2) {
        p.push_back(P(d[i], d[i + 1]));
    }
    auto comp = [](const P &fst, const P &sec) {
        return f(fst.first, fst.second) < f(sec.first, sec.second);
    };
    sort(p.begin(), p.end(), comp);
    ll div1 = p[0].first;
    ll div2 = p[0].second;
    cout << f(div1, div2) << endl;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string a, b, c;
    cin >> a >> b >> c;

    cout << (char)(a[0] + ('A' - 'a'));
    cout << (char)(b[0] + ('A' - 'a'));
    cout << (char)(c[0] + ('A' - 'a')) << endl;
}


Measured memory_bytes: 256
#include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l[], int l_top, int r[], int r_top) {
  int bi = (l_top + 1) + (r_top + 1);
  if (bi == N_BALL) return true;

  l[l_top+1] = balls[bi];
  if (l_top >= 0 && l[l_top] > l[l_top+1]) return false;
  if (solve(l, l_top+1, r, r_top)) return true;
  l[l_top+1] = 0;

  r[r_top+1] = balls[bi];
  if (r_top >= 0 && r[r_top] > r[r_top+1]) return false;
  if (solve(l, l_top, r, r_top+1)) return true;;
  r[r_top+1] = 0;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

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

    int left[N_BALL] = {}, right[N_BALL] = {};
    if (solve(left, -1, right, -1)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 1008
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

int main()
{
    int H, W;
    scanf("%d %d\n", &H, &W);
    vector<char> row_reached(W, false); row_reached[0] = true;
    int count = 0;
    for (int h = 0; h < H; ++h){
        vector<char> next_row_reached(W, false);
        for (int w = 0; w < W; ++w){
            const char c = getchar();
            if (c == '.') continue;
            ++count;
            if (row_reached[w] || (w > 0 && next_row_reached[w - 1])) next_row_reached[w] = true;
        }
        getchar();
        swap(row_reached, next_row_reached);
    }
    if (row_reached.back() && count == H + W - 1){
        puts("Possible");
    }else{
        puts("Impossible");
    }
}


Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 100000
#define min(a, b) ((a) < (b) ? (a) : (b))

int a[MAX_N];
int S;
int n;

int
solve()
{
	int s, t;

	int res = n + 1;
	int sum = 0;
	s = 0, t = 0;
	while (true)
	{
		while (t < n && sum < S)
			sum += a[t++];

		if (sum < S)
			break;

		res = min(res, t - s);
		sum -= a[s++];
	}

	if (res > n)
		return 0;

	return res;
}

int
main(int argc, char** argv)
{
	int i;

	scanf("%d %d", &n, &S);
	for (i = 0; i < n; ++i)
		scanf("%d", &a[i]);

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

Measured memory_bytes: 984
import java.util.*;
public class Main{
	public static void main(String[] args){
		//1<=x<=1000
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();//Xが与えられる！
		int max = 0;//現在の最大のべき乗
		for(int b = 1;b <= x;b++){//
			for(int q = 2;q <= 1000;q++){
				if(Math.pow(b, q) <= x){
					max = (Math.max((int)Math.pow(b, q), max));
				}
			}
		}
		System.out.println(max);
		
		
		
	
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,0,s.length()){
        char x=s[i]-'A';
        int y=(x+n)%26+0x41;
        cout<<char(y);
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int X = sc.nextInt();
		for(int i=1; i<=360; i++) {
			if((X*i)%360==0) {
				System.out.println(i);
				break;
			}
		}
		
		sc.close();
	}
}


Measured memory_bytes: 27000