akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,n){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define pii pair<int,int>
#define PI 3.141592653589793

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N,C; cin>>N>>C;
  int d[C+1][C+1],num[3][C+1];
  
  FILL2(d,C+1,C+1,0);
  FILL2(num,3,C+1,0);
  
  for(int ca=1;ca<=C;++ca){
    for(int cb=1;cb<=C;++cb){
      cin >> d[ca][cb]; // 色caを色cbに変更するコスト
    }
  }
  for(int i=1;i<=N;++i){
    for(int j=1;j<=N;++j){
      int c; cin >> c;
      ++num[ (i+j)%3 ][c];  //位置 (i+j)%3 における色cの総数
    }
  }
  
  ll ans = pow(10,10);
  for(int c1=1;c1<=C;++c1){
    for(int c2=1;c2<=C;++c2){
      if(c1==c2){continue;}
      for(int c3=1; c3<=C;++c3){
        if(c1==c3 || c2==c3){continue;}
        ll temp = 0;
        for(int pc=1;pc<=C;++pc){ temp += d[pc][c1]*num[0][pc]; }
        for(int pc=1;pc<=C;++pc){ temp += d[pc][c2]*num[1][pc]; }
        for(int pc=1;pc<=C;++pc){ temp += d[pc][c3]*num[2][pc]; }
        if(temp<ans){ ans = temp; }
      }
    }
  }
  cout << ans <<"\n";
}


Measured memory_bytes: 256
package main

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

var par []int

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	par = make([]int, n)
	for i := range par {
		par[i] = -1
	}

	candMap := make(map[int]int)
	for i := 0; i < m; i++ {
		var a, b int
		sc.Scan()
		a, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ = strconv.Atoi(sc.Text())
		a--
		b--
		candMap[a]++
		candMap[b]++
		unite(a, b)
	}
	for i := 0; i < k; i++ {
		var c, d int
		sc.Scan()
		c, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		d, _ = strconv.Atoi(sc.Text())
		c--
		d--
		if root(c) == root(d) {
			candMap[c]++
			candMap[d]++
		}
	}
	for i := 0; i < n; i++ {
		total := sizeTree(i) - 1
		total -= candMap[i]
		fmt.Printf("%d ", total)
	}
	fmt.Println()
}

func root(x int) int {
	if par[x] < 0 {
		return x
	}
	par[x] = root(par[x])
	return par[x]
}

func unite(x, y int) {
	rx := root(x)
	ry := root(y)
	if rx == ry {
		return
	}
	par[rx], par[ry] = ry, par[rx]+par[ry]
}

func sizeTree(x int) int {
	return -par[root(x)]
}


Measured memory_bytes: 11496
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> h(N, 0), dp(N, 1<<30);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  dp[0] = 0;
  for (int j = 1; j < N; j++) {
    for (int k = 1; k <= K; k++) {
      if (j - k < 0) {
        continue;
      }
      dp[j] = min(dp[j], abs(h[j] - h[j-k]) + dp[j-k]);
    }
  }

  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for(int i  = 0; i < (s.size()+1)/2; i++){
        if(s[i] != s[s.size()-i-1])ans++;
    }
    cout << ans << endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  LD sum=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  sum/=n;
  int ans=-1;
  LD sa=10000;
  for(int i=0;i<n;i++){
    if(sa>abs(a[i]-sum)){
      sa=abs(a[i]-sum);
      ans=i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a[2];
	while(1)
	{
		scanf("%d %d", &a[0], &a[1]);
		if ((a[0] == 0 && a[1] == 0))
		{
			break;
		}
		for (int i=0; i<a[0]; i++)
		{
			for (int d = 0; d < a[1]; d++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include <cctype>

using namespace std;

int main(){
  string str;

  getline(cin, str);
  for(string::size_type i=0; i != str.size(); ++i){
    str[i] = toupper(str[i]);
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 0
# 2019/08/15

from fractions import gcd

n,k=map(int,input().split())
a=list(map(int,input().split()))
ans='POSSIBLE'
max_a=max(a)
if max_a==k:
    print(ans)
    exit()
elif max_a<k:
    print('IMPOSSIBLE')
    exit()

    

g=0
for i in range(n):
    g=gcd(g,a[i])

if k%g==0 or k in a:
    print(ans)
else:
    print('IMPOSSIBLE')

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

int main(){
    int N;
    int max = -1;
    int now = 0;
    int ans = 0;
    cin >> N;

    for (int i=0; i<N;i++){
        cin >> now;
        if(max <= now){
            ans++;
            max = now;
        }else{
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

int main()
{
   int n,k;
   cin>>n>>k;
   int arr[n];
   forl(i,0,n)cin>>arr[i];
   bool dp[k+1];
   dp[0]=false;
   forl(i,1,k+1)
   {
       dp[i]=false;
       forl(j,0,n)
       {
           if(arr[j]<=i) dp[i]=(dp[i]||(!dp[i-arr[j]]));
       }
   }
   if(dp[k]) cout<<"First"<<endl;
   else cout<<"Second"<<endl;
    // forl(i,0,k+1) cout<<dp[i]<<" ";
    // cout<<endl; 
}



Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define rad 1.0471975511966 //60度のラジアン角

void kock(int n, double p1_x, double p1_y, double p2_x, double p2_y){
	
	if(n == 0){
		return;
	}
	double s_x, s_y, t_x, t_y, u_x, u_y;
	
	s_x = (2 * p1_x + 1 * p2_x) / 3;
	s_y = (2 * p1_y + 1 * p2_y) / 3; 
	
	t_x = (1 * p1_x + 2 * p2_x) / 3;
	t_y = (1 * p1_y + 2 * p2_y) / 3;
	
//	double rad = 60 * PI / 180.0;
	u_x = (t_x - s_x) * cos(rad) - (t_y - s_y) * sin(rad) + s_x;
	u_y = (t_x - s_x) * sin(rad) + (t_y - s_y) * cos(rad) + s_y;
	
	kock(n-1, p1_x, p1_y, s_x, s_y);
	printf("%lf %lf\n", s_x, s_y);
	
	kock(n-1, s_x, s_y, u_x, u_y);
	printf("%lf %lf\n", u_x, u_y);
	
	kock(n-1, u_x, u_y, t_x, t_y);
	printf("%lf %lf\n", t_x, t_y);
	
	kock(n-1, t_x, t_y, p2_x, p2_y);

}


int main() {
	int n;
	
	scanf("%d",&n);
	
	printf("%lf %lf\n",0.0,0.0);
	kock(n,0,0,100,0);
	printf("%lf %lf\n",100.0,0.0);
	
	
	return 0;
}






Measured memory_bytes: 2080
c[];main(n,m,i,j,k){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",j>m?i:j)){for(i=3;i--;)for(scanf("%d",&j);j--;c[n-k]=i)scanf("%d",&k);for(i=n;i--;k+=c[i])j-=pow(3,i)*abs(k*2%4-c[i]);j=fmin(~j,pow(3,n)+j);}}

Measured memory_bytes: 644
def main():
    # import sys
    # readline = sys.stdin.buffer.readline
    # readlines = sys.stdin.buffer.readlines
    N = int(input())
    L = input()

    A = [None] * (N + 1)
    for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        A[0] = a0
        A[1] = a1
        for i in range(2, N + 1):
            a = A[i - 1]
            s = 0 if L[i - 1] == 'o' else 1
            # if a == 0:
            #     if s == 0:
            #         A[i] = A[i - 2]
            #     elif s == 1:
            #         A[i] = A[i - 2] ^ 1
            # elif a == 1:
            #     if s == 0:
            #         A[i] = A[i - 2] ^ 1
            #     elif s == 1:
            #         A[i] = A[i - 2]
            A[i] = A[i - 2] ^ (a ^ s)
        am = A[1] ^ (A[0] ^ (L[0] == 'x'))
        if A[0] == A[N] and am == A[N - 1]:
            exists = True
            break
    else:
        exists = False

    if exists:
        ans = []
        for i in range(N):
            c = 'W' if A[i] else 'S'
            ans.append(c)
        print(''.join(ans))
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4988
/*													   *********************
													   	  G. LONGEST PATH
													   *********************                                                    */
													   
import java.util.*;
import java.io.*;
public class Main
{
	
	static int c=0;
	public static int util(int n,LinkedList<Integer> graph[],int [] max)
	{
		
		if(max[n]>=0)
			return max[n];
		if(graph[n].size()==0){
			max[n]=0;
			return 0;}
		
		for(int i=0;i<graph[n].size();i++)
			max[n]=Math.max(1+util(graph[n].get(i),graph,max),max[n]);
			
		return max[n];
		
	}
	
	public static void main(String args[]) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String inp[]=br.readLine().split(" ");
		int n=Integer.parseInt(inp[0]),m=Integer.parseInt(inp[1]);
		LinkedList<Integer> graph[]=new LinkedList[n+1];
		for(int i=1;i<=n;i++)
			graph[i]=new LinkedList<Integer>();
		
		for(int i=0;i<m;i++)
		{
			inp=br.readLine().split(" ");
			graph[Integer.parseInt(inp[0])].add(Integer.parseInt(inp[1]));
		}
		int max[]=new int[n+1];
		Arrays.fill(max,Integer.MIN_VALUE);
		for(int i=0;i<n;i++)
		util(i+1,graph,max);
		long ans=Integer.MIN_VALUE;
		for(int i=1;i<=n;i++)
			if(max[i]>ans)
				ans=max[i];
		
		System.out.println(ans);

	}
}

Measured memory_bytes: 57864
#include <iostream>

using namespace std;

int main()
{
	int n; cin>>n;
	bool f=true;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		if (a % 2 == 0 and a % 3 != 0 and a % 5 != 0) f = false;
	}
	cout << (f ? "APPROVED" : "DENIED") << endl;
}


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

string S;

long long dfs(int i=0, long long sum=0, long long num=0)
{
  if (i == S.size()){
    return num ? 0 : sum;
  }

  num = num * 10 + (S[i] - '0');

  return dfs(i + 1, sum + num, 0) + dfs(i + 1, sum, num);
}

int main()
{
  cin >> S;

  cout << dfs() << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    int a[n]={};
    int ans=0;
    for(int i=0;i<q;i++){
        cin>>ans;
        ans--;
        a[ans]++;
    }
    for(int i=0;i<n;i++){
        if(q-a[i]>=k){cout<<"No"<<endl;}
        else{cout<<"Yes"<<endl;}
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int MAXN = 200010;
long long a[MAXN],b[MAXN],c[MAXN],sum[MAXN];
map<long long,int> mp;
int n,k,nn;
int lowbit(int x) {return x&(-x);}
int getSum(int x) {
	int ans = 0;
	while (x>0) {
		ans += sum[x];
		x -= lowbit(x);
	}
	return ans;
}
void update(int x,int num) {
	while (x<=nn) {
		sum[x] += num;
		x += lowbit(x);
	}
}
int main()
{
	while (scanf("%d%d",&n,&k)!=EOF) {
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		c[0] = 0,b[0] = 0;
		for (int i=1;i<=n;i++) {
			c[i] = c[i-1] + a[i] - k;
			b[i] = c[i];
		}
		sort(b,b+1+n);
		nn = 0;
		mp.clear();
		for (int i=0;i<=n;i++) {
			if (!mp[b[i]]) mp[b[i]] = ++nn;
		}
		long long ans = 0;
		for (int i=0;i<=n;i++) {
			ans += getSum(mp[c[i]]);
			update(mp[c[i]],1);
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 19072
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
int n;

int main(){ 
  auto dmy=scanf("%d", &n);
  
  vector<ll> height(n);
  
  for(int i=0; i<n; i++){
    dmy = scanf("%lld", &height[i]);
  }
  
  bool flag=true;
  for(int i=n-1; i>0; i--){
    if(height[i-1]-height[i]>1){
      flag=false;
      break;
    }else if(height[i-1]-height[i]==1){
      height[i-1]--;
    }
  }
  if(flag){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	int N,A,B;
	cin >> N >> A >> B;
	int ans = min(A*N, B);

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


Measured memory_bytes: 3596
a,b,c,d,e,f = (int(i) for i in input().split())
w,s,num,answer = set(),set(),0,[a*100,0]
for i in range((f-f%(a*100))//(a*100)+1):
	for j in range((f-f%(b*100))//(b*100)+1):
		if i*a*100+j*b*100 <= f:
			w.add(i*a*100+j*b*100)
		else:
			break
smax = int(e*f/((100+e)*1.0))
for i in range((smax-smax%c)//c+1):
	for j in range((smax-smax%d)//d+1):
		if i*c+j*d <= smax:
			s.add(i*c+j*d)
		else:
			break
w2,s2 = sorted(list(w))[::-1],sorted(list(s))[::-1]
for i in w2:
	for j in s2:
		if 0 < i+j <= f and e*i>=100*j and num<(j/((i+j)*1.0)):
			num =  j/((i+j)*1.0)
			answer = [i,j]
print(sum(answer),answer[1])


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}


int atcoder() {
    int n;
    cin >> n;
    
    int s = (n/2)*2+1;
    vector<Pii> v;
    REP(i,1,n+1){
        REP(j,1,n+1){
            if(i+j!=s && i<j) v.emplace_back(i,j);
        }
    }
    
    cout << v.size() << ENT;
    REP(i,0,v.size()) cout << v[i].first << " " << v[i].second << ENT;
    return 0;
}

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


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;


int main(){
  int p[201000];
  int k, n;
  int imax = 0;


  cin >> n >> k;

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


  int x, dx, xtemp;
  x = 0; //記録用
  xtemp = 0; //xをトラック
  dx = 0;

  for (int i = 0; i < n-k; i++){
    dx = p[i+k] - p[i];
    xtemp = xtemp + dx;
    if (xtemp > x) {
      x = xtemp;
      imax = i+1;
    }
    //cout << xtemp << endl;
  }

  double y = 0.0;
  for (int j = 0; j < k; j++){
    y += ((double)p[imax+j] + 1.0)/2;
  }

   cout << std::setprecision(10) << y << endl;

  return 0;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
ans = 0
MOD = 10**9+7

for i in range(K,N+2):
    l = (i*(i-1))//2
    r = N*i - (i*(i-1))//2
    ans += r-l+1
    ans %= MOD
    
print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL N, A, B, C, D;

int main(void) {
    cin >> N >> A >> B >> C >> D;
    bool f = false;

    REP(plus, N) {
        const int minus = N - plus - 1;
        const LL high = A + D * plus - C * minus;
        const LL low = A + C * plus - D * minus;
        f |= (low <= B && B <= high);
    }

    cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#define re register
using namespace std;
int len;
char s[110];
bool flag;
int main()
{std::ios::sync_with_stdio(false);
 cin.tie(0);cout.tie(0);
 cin>>s;
 len=strlen(s);
 for(re int i=0;i<len;i++)
  {if(s[i]=='C')
    flag=true;
   if(flag&&s[i]=='F')
    {cout<<"Yes";
     return 0;
    }
  }
 cout<<"No";
 return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

struct cube {
  enum Face { Top, Front, Right, Left, Back, Bottom };
  int f[6];
  unordered_map<int, string> mp;
  cube(){}
  /*
            1(Top)
    4(Left) 2(Front) 3(Right) 5(Back)
            6(Bottom)
  */
  cube(vector<int> const& vs){ for(int i=0; i<6; i++) f[i] = vs[i]; }
  cube(vector<string> const& vs) { for(int i=0; i<6; i++) mp[i+1] = vs[i]; }
  void roll_z() { roll(1, 2, 4, 3); }
  void roll_y() { roll(0, 2, 5, 3); }
  void roll_x() { roll(0, 1, 5, 4); }
  void roll(int i, int j, int k, int l) {
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }

  void roll(int k) {
    if(k == 0) roll_y();
    if(k == 1) roll_x();
    if(k == 2) for(int i=0; i<3; i++) roll_y();
    if(k == 3) for(int i=0; i<3; i++) roll_x();
  }

  bool roll_top_front(int top, int front) {
    for(int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), k++)
      for(int i = 0; i < 4; roll_z(), ++i)
        if(top == f[Top] && front == f[Front]) return true;
    return false;
  }

  bool operator == (cube const& rhs) const {
    for(int i=0; i<6; i++)
      if(f[i] != rhs.f[i]) return false;
    return true;
  }

  bool isomorphic(cube rhs) const {
    for(int i=0; i<6; i++) {
      for(int j=0; j<4; j++) {
        if(operator==(rhs)) return true;
        rhs.roll_z();
      }
      if(i % 2 == 0) rhs.roll_y();
      else rhs.roll_x();
    }
    return false;
  }

};

int main() {

  cube c; for(int i=0; i<6; i++) cin >> c.f[i];
  string q; cin >> q;
  string d = "WNES";
  rep(i, q.size()) c.roll(d.find(q[i]));
  cout << c.f[0] << endl;
  
  return 0;
}

Measured memory_bytes: 3204
k, a, b = map(int, input().split())
ans = 0
if b - a <= 1: # 叩き続けたほうがいい
    ans = k + 1
else:
    n = k - a + 1 #a個
    if n % 2 == 1:
        ans = a + 1 + (b-a)*(n//2) #最後交換しない
    else:
        ans = a + (b-a)*(n//2) 
print(ans)

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

void search(char maxc, int depth, int N, char A[]){
    if (depth == N - 1){
        for(char i = 'a'; i <= maxc + 1; i++){
            A[N - 1] = i;
            rep(j, N) cout << A[j];
            // cout << i << endl;
            cout << endl;
        }
    }else{
        // A[depth - 1] = 'a';
        for(char i = 'a'; i <= maxc + 1; i++){
            A[depth] = i;
            search(max(maxc, i), depth + 1, N, A);
        }
    }
}

int main(){
    int N;
    cin >> N;
    char A[N];
    rep(i, N) A[i] = 'a';
   
    if (N == 1){
        cout << "a" << endl;
    }else{
        search('a', 1, N, A);
    }

    return 0;
}

Measured memory_bytes: 1536
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, x = map(int, input().split())
    a, p = [1], [1]
    for i in range(n):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)

    def solve(n, x):
        if n == 0:
            return 1 if x == 1 else 0

        if x < 2:
            return 0

        if a[n] - 1 <= x:
            return p[n]

        if 1 + a[n] // 2 < x:
            return p[n - 1] + 1 + solve(n - 1, x - (a[n] // 2 + 1))
        elif 1 + a[n] // 2 == x:
            return p[n - 1] + 1
        else:
            return solve(n - 1, x - 1)

    print(solve(n, x))


if __name__ == '__main__':
    resolve()


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

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    int x = n % 10;
    if (x == 7) {
      puts("Yes");
      return 0;
    }
    n /= 10;
  }
  puts("No");
  return 0;
}



Measured memory_bytes: 3596
#include<cstdio>
#include<cmath>
using namespace std;
int main(void)
{
	int n,m,i,j,t;
	int a[51],b[51],c[51],d[51];
	int dist[51][51];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d %d",&a[i],&b[i]);
	for(i=0;i<m;i++)
		scanf("%d %d",&c[i],&d[i]);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			dist[i][j]=abs(a[i]-c[j])+abs(b[i]-d[j]);
		}
		t=0;
		for(j=1;j<m;j++){
			if(dist[i][j]<dist[i][t])t=j;
		}
		printf("%d\n",t+1);
	}
	return 0;
}
			

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    ans += min(A, K);
    K -= min(A, K);
    if (K != 0)
    {
        K -= min(B, K);
    }
    if (K != 0)
    {
        ans -= min(C, K);
        K -= min(C, K);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const double pi = 3.141592653589793;
#define MOD 1000000007
//#define INF 10000000000000

struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P=pair<int,int>;
const int INF=1LL<<60;

/*dijkstra(G,s,dis)
  入力　G　グラフ、s 開始点　dis 距離を格納する
*/
void dijkstra(const Graph &G, int s, vector<int> &dis){
  int n=G.size();//nはノードの数
  dis.resize(n,INF);//スタートから各ノードへの距離をINFで初期化
  priority_queue<P, vector<P>, greater<P>> pq;
  //priority_queue<型、vector<型>、greater<型>>で、値が小さいほうから取り出される
  dis[s]=0;//startまでの距離は０
  pq.emplace(0,s);
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    int v=p.second;
    if(dis[v]<p.first){
      continue;
    }
    for(auto &e:G[v]){
      if(dis[e.to]>dis[v]+e.cost){
        dis[e.to]=dis[v]+e.cost;
        pq.emplace(dis[e.to],e.to);
      }
    }
  }
}
signed main(){
  int v,n,s;
  cin>>v>>n>>s;
  Graph G(v,vector<Edge>(0));

  rep(i,n){
    int t;cin>>t;
    int to,cost;
    cin>>to>>cost;
    G[t].push_back({to,cost});
  }
  vector<int>dis;
  dijkstra(G,s,dis);
  rep(i,v){
    if(dis[i]==INF)cout<<"INF"<<endl;
    else cout<<dis[i]<<endl;
  }
}



Measured memory_bytes: 19432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n;cin>>n;
  ll mn=LLONG_MAX;
  rep(i,5){
    ll a;cin>>a;
    mn=min(mn,a);
  }
  mn=min(mn,n);
  ll ans=(n+mn-1)/mn+4;
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    int c = 0;
    priority_queue<int> que;
    for(auto& x : a)
        que.emplace(x);
    int tmp = 0;
    int ans = 0;
    for(int i = 0; i < k; ++i){
        if(!que.empty()){
            int t = que.top();
            que.pop();
            if(tmp)
                que.emplace(tmp);
            tmp = --t;
        }else{
            ans = tmp;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	int s;
	cin>>a[0]>>a[1]>>a[2]; 
	if(a[0]==a[1])s++;
	if(a[1]==a[2])s++;
	if(a[2]==a[0])s++;
	if(s==1)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main(){
  int N,k = 0, c = 0;
  cin >> N;
  int A[N];
  for(int n = 0; n <= N - 1; n++){
    cin >> A[n];
  }
  for(int i = 0;; i++){
    k = A[i%N] % 2;
    if(k != 0){
      break;
    }
    if(i % N == 0){
      for(int n = 0; n <= N - 1; n++){
    A[n] /= 2;
  }
      c++;
    }
  }
  cout << c <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

vector<vector<int>> grid_bfs(int h,int w,int x,int y,vector<string> &maze,char obstacle='#') {
  const int dx[] = { 1,0,-1,0}, dy[] = { 0,1,0,-1};//4方向移動
  const int init=1e7;
  vector<vector<int>>d(h,vector<int>(w,init));
  d[x][y]=0;
  deque<pair<int, int>>q;
	pair<int, int>p;
  q.emplace_back(x,y);
	while (!q.empty()) {
		p = q.front();
		q.pop_front();
		for (int i = 0; i < 4;++i) {
			int nx = p.first+dx[i]; int ny = p.second+dy[i];
			if (0 <= nx && nx < h && 0 <= ny && ny < w &&chmin(d[nx][ny],d[p.first][p.second])&&maze[nx][ny]!=obstacle) {
				q.emplace_front(nx,ny);
			}
			for(int a=-2;a<=2;++a){
				for(int b=-2;b<=2;++b){
					if(0<=p.first+a&&p.first+a<h&&0<=p.second+b&&p.second+b<w&&chmin(d[p.first+a][p.second+b],d[p.first][p.second]+1)&&maze[p.first+a][p.second+b]!=obstacle){
						q.emplace_back(p.first+a,p.second+b);
					}
				}
			}
		}
	}
  return d;//initを含むことに注意
}

using P=pair<int,int>;
void solve(){
  int h,w;
  cin>>h>>w;
  vector<string>s(h);
  P start,goal;
	cin>>start.first>>start.second;
	start.first--;
	start.second--;
	cin>>goal.first>>goal.second;
	goal.first--;
	goal.second--;
  rep(i,h){
    cin>>s[i];
  }
  auto x=grid_bfs(h,w,start.first,start.second,s);
  if(x[goal.first][goal.second]==1e7)cout<<-1;
  else cout<<x[goal.first][goal.second];
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 8700
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int slen = s.length;
        char[] t = sc.next().toCharArray();
        int tlen = t.length;
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < slen-tlen+1; i++) {
            int cnt = 0;
            for (int j = 0; j < tlen; j++) {
                if(s[i+j] != t[j]) cnt++;
            }
            if(cnt < ans) ans = cnt;
        }
        System.out.println(ans);
        sc.close();

    }

}


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

using namespace std;
typedef long long ll;

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

    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin >> b[i];
    }

    int cnt=0;
    for(int i=0; i<n; i++){
        int sum =0;
        for(int j=0; j<m; j++){
            int tmp;
            cin >> tmp;
            sum += tmp*b[j];
        }
        if(sum+c>0){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, A, B, res, g[100000], t;
vector<int>v[100000], r[100000];

void dfs(int x) {
	for (int i = 0; i != v[x].size(); ++i) {
		if (!g[v[x][i]])
			dfs(v[x][i]);
	}
	g[x] = t;
	++t;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i != N + M - 1; ++i) {
		cin >> A >> B;
		--A; --B;
		v[A].push_back(B);
		r[B].push_back(A);
	}
	for (int i = 0; i != N; ++i) {
		if (!r[i].size()) {
			t = 1;
			dfs(i);
		}
	}
	for (int i = 0; i != N; ++i) {
		int m = 0xe869120;
		res = -1;
		for (int j = 0; j != r[i].size(); ++j) {
			if (g[r[i][j]] < m) {
				m = g[r[i][j]];
				res = r[i][j];
			}
		}
		cout << res + 1 << endl;
	}
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int ans =1;
  rep(i,n){
    ans = min(ans +k, ans *2);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int pref[200005];
int suff[200005];

int main() {
	int n;
	string s;
	cin >>n>>s;
	for (int i=0 ; i<s.size() ; i++) {
		if (i) pref[i] = pref[i-1];
		if (s[i] == 'W') pref[i]++;
	}
	for (int i=s.size()-1 ; i>=0 ; i--) {
		suff[i] = suff[i+1];
		if (s[i] == 'R') suff[i]++;
	}
	int sol = suff[0];
	for (int i=1 ; i<=n ; i++) {
		sol = min(sol, max(pref[i-1], suff[i]));
	}
	printf("%d\n", sol);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct Train
{
    int c,s,f;
};


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

    vector<Train> T(N-1);
    REP(i,N-1){
        int c,s,f; cin >> c >> s >> f;
        T[i] = {c,s,f};
    }

    REP(i,N-1){
        int time = 0;
        FOR(j,i,N-1){
            if(time <= T[j].s){
                time = T[j].s + T[j].c;
            }else{
                time = ((time-1)/T[j].f + 1)*T[j].f + T[j].c;
            }
        }
        cout << time << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
char str[17];

int main(){
	int i;
	int p,q;
	int qold;
	int fr,re;
	int max = 3;
	int amax = 3;
	int len;
	char cp;
	scanf("%s",str);
	len = strlen(str);
	p = 0;

	for( i=0; i<(len-2); i++){
		if(str[i] == 'i' && str[i+2] == 'i'){
			fr = i;
			re = i+2;
			break;
		}
	}
	
	/*(´；ω；`)*/
	while(p != fr){
		q = len-1;
		qold = q;
		for(i = p;i < fr;i++){
			cp = str[i];
			while(q != re){
				if(cp == '(' && str[q] == ')'){
					qold = --q;
					max += 2;
					break;
				}
				if(cp == ')' && str[q] == '('){
					qold = --q;
					max += 2;
					break;
				}
				if(cp == '{' && str[q] == '}'){
					qold = --q;
					max += 2;
					break;
				}
				if(cp == '}' && str[q] == '{'){
					qold = --q;
					max += 2;
					break;
				}
				if(cp == '[' && str[q] == ']'){
					qold = --q;
					max += 2;
					break;
				}
				if(cp == ']' && str[q] == '['){
					qold = --q;
					max += 2;
					break;
				}
				q--;
			}
			if(q == re && p != fr){
				q = qold;
			}
			if(q == re && p == fr-1){
				break;
			}
		}
		if(amax < max){
			amax = max;
		}
		max = 3;
		p++;
	}
	printf("%d\n",amax);
	return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<vector>
#include<cstdio>
#include<iterator>
#include<string>
#include<queue>
#include<algorithm>
#include<string.h>
#include<map>
using namespace std;
#define MP make_pair
#define F first
#define S second
#define LL long long
#define INF	int(1e9)
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

int main()
{
	LL x, ans =  0;
	cin >> x;
	ans += x / 11;
	x %= 11;
	ans *= 2;
	if (x > 0) {
		x -= 6;
		ans++;
	}
	if (x > 0){
		x -= 5;
		ans++;
	}
	cout << ans << endl;
}

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

int main() {
	// your code
	int w,a,b;
	cin >> w >> a >> b;
	if(a+w<b){
		cout << b-a-w<< endl;
	}
	else if(b+w<a){
		cout << a-b-w << endl;
	}
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,C,A;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) cin >> B[i];
  int ans = 0;
  for (int i = 0; i < N; i++){
    int sum = C;
    for (int j = 0; j < M; j++){
      cin >> A;
      sum += A * B[j];
    }
    if (sum > 0) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    // ABC152
    static final long MOD = 1_000_000_007;
    //10^9+7
    static final int MAX = 2_147_483_646;
    //intの最大値
    static final int INF = 1_000_000_000;
    //10^9
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //int[] ary = new int[n];
        int ans = 0;
        int min = MAX;
        for(int i = 0;i < n;i++){
            int tmp = sc.nextInt();
            if(tmp <= min){
                min = tmp;
                ans++;
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 62724
N,M=map(int,input().split())
H=list(map(int,input().split()))
a=[list(map(int,input().split()))for i in range(M)]
tenbou=[1]*N
for i in range(M):
    if H[a[i][0]-1] < H[a[i][1]-1]:
        tenbou[a[i][0]-1]=0
    elif H[a[i][0]-1] > H[a[i][1]-1]:
        tenbou[a[i][1]-1]=0
    else:
        tenbou[a[i][0]-1]=0
        tenbou[a[i][1]-1]=0
print(sum(tenbou))


Measured memory_bytes: 31916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main()
{
    string s;
    long long int k;

    cin >> s >> k;

    for (int i = 0; i < k; i++) {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return (0);
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
a=[['\'',',','.','!','?'],
   ['a','b','c','A','B','C'],
   ['d','e','f','D','E','F'],
   ['g','h','i','G','H','I'],
   ['j','k','l','J','K','L'],
   ['m','n','o','M','N','O'],
   ['p','q','r','s','P','Q','R','S'],
   ['t','u','v','T','U','V'],
   ['w','x','y','z','W','X','Y','Z']]
while 1:
    try:b=input()+'@'
    except:break
    c=0
    ans=''
    for i in range(len(b)-1):
        if b[i]!=b[i+1]:
            if b[i]!='0':
                d=int(b[i])-1
                ans+=a[d][c%len(a[d])]
            c=0
        else: c+=1
        if b[i]==b[i+1]=='0':ans+=' '
    print(ans)

Measured memory_bytes: 7644
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val N = readInt
  val arr = readLine.split(" ").map(_.toInt)

  def selectionSort(A: Array[Int], N: Int): Int = {
    var count = 0
    for (i <- 0 until N) {
      var minJ = i
      for (j <- i until N) {
        if (A(j) < A(minJ)) minJ = j
      }
      val tmp = A(i)
      A(i) = A(minJ)
      A(minJ) = tmp
      if (i != minJ) count += 1
    }
    count
  }

  val ans = selectionSort(arr, arr.length)
  println(arr.mkString(" "))
  println(ans)
}


Measured memory_bytes: 43964
#include <iostream>
#include <set>

using namespace std;

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

    int m = 1;
    set<int> a;
    while (!a.count(s)) {
        a.insert(s);

        if (s % 2 == 0) {
            s /= 2;
        } else {
            s = 3 * s + 1;
        }

        m++;
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for i in range(N):
    left = []
    right = []
    for j in range(N):
        if j <= i:
            if S[j] not in left:
                left.append(S[j])
        else:
            if S[j] not in right:
                right.append(S[j])
    tmp_ans = 0
    for j in range(len(left)):
        if left[j] in right:
            tmp_ans += 1
    ans = max(ans, tmp_ans)
    
print(ans)

Measured memory_bytes: 3064
TLE = 1e+9.to_i

(n, s) = gets.chomp.split(' ').map(&:to_i)

m = TLE
n.times do
  (c, t) = gets.chomp.split(' ').map(&:to_i)
  if t <= s then
    m = [m, c].min
  end
end

if m == TLE then
  puts 'TLE'
else
  puts m.to_s
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define LL long long
#define M 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	fastio
	int n, i;
	cin>>n;
	cout<<fixed<<setprecision(10)<<((n+1)/2)/(float)n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair

// random generator
// mt19937 rndm(time(0));

ll gcd(ll a, ll b)
{
    while (b>0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

 
const int M=1e9+7;
ll powmod(ll a,ll b, ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}/* a^b%mod */
const int N=1e5+10;



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

	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	a[2]*=10;
	a[2]+=a[1]+a[0];
	cout<<a[2];

	return 0;
}



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

int main()
{
    int a,s,d,f;
    scanf("%d%d%d%d",&a,&s,&d,&f);
    int q,w,e;
    e=fabs(d-a);
    q=fabs(s-a);
    w=fabs(d-s);
    if(e<=f||(q<=f&&w<=f))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	vector <ll> v(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> v[i];
	}

	ll ret = -BIGLL;

	for (int l=0;l<=N;l++)
	{
		for (int r=l;r<=N;r++)
		{

			const int toru = N - r + l;

			if (toru > K) continue;

			vector <ll> p;
			for (int i = 0; i < l; ++i)
			{
				p.push_back(v[i]);
			}

			for (int i = r; i < N; ++i)
			{
				p.push_back(v[i]);
			}

			int modosu = K - toru;
			sort(p.begin(), p.end());

			ll sum = 0;
			for (int i = 0; i < SZ(p); ++i)
			{
				if (p[i] < 0 && modosu > 0)
				{
					modosu--;
				}
				else
				{
					sum += p[i];
				}
			}
			amax(ret, sum);
		}
	}


	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
from math import floor,sqrt
def prime(n):
    a = []
    d={}
    while n % 2 == 0:
        try:
            d[2]+=1
        except:
            d[2]=1
            a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            try:
                d[f]+=1
            except:
                d[f]=1
                a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        try:
            d[n]+=1
        except:
            d[n]=1
            a.append(n)
    return a,d
n=int(input())
a,d=prime(n)
ans=0
for i in range(len(a)):
    k=floor(sqrt(2*d[a[i]]))
    if k*(k+1)//2>d[a[i]]:
        k-=1
    ans+=k
print(ans)
        


Measured memory_bytes: 9248
#include <stdio.h>

#define INF 100000000

int N, Ma, Mb;
int a[1000];
int b[1000];
int c[1000];

int memo[50][500][500];

int search(int pos, int cur_a, int cur_b) {
	int ret = INF;
	int candidate;
	if (cur_a > 0 && cur_b > 0 && cur_a * Mb == cur_b * Ma) return 0; /* 条件を満たした */
	if (pos >= N) return ret; /* もう入れる薬品が無い */
	if (memo[pos][cur_a][cur_b]) return ~memo[pos][cur_a][cur_b];

	/* 買う */
	candidate = search(pos + 1, cur_a + a[pos], cur_b + b[pos]) + c[pos];
	if (candidate < ret) ret = candidate;
	/* 買わない */
	candidate = search(pos + 1, cur_a, cur_b);
	if (candidate < ret) ret = candidate;

	return ~(memo[pos][cur_a][cur_b] = ~ret);
}

int main(void) {
	int i;
	int ret;
	if (scanf("%d%d%d", &N, &Ma, &Mb) != 3) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d%d", &a[i], &b[i], &c[i]) != 3) return 1;
	}
	ret = search(0, 0, 0);
	printf("%d\n", ret == INF ? -1 : ret);
	return 0;
}


Measured memory_bytes: 37120
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

char S[200002];
char S2[200002];

int main(void) {
  int N;

  cin >> N;
  cin >> S;
  
  int bcnt = 0;
  for (int i = 0; i < N; i++) 
    if (S[i] == '#') bcnt++;

  int m = N;
  int tb = bcnt;
  for (int i = 0; i <= N; i++) {
    m = min(m, bcnt - tb + N - i - tb);
    if (S[i] == '#')
      tb--;  
  }

  cout << m << endl;
  return 0;
}

Measured memory_bytes: 384
// Problem : D - Road to Millionaire
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n;
	ll ar[n];
	m=1000;
	for(i=0;i<n;i++)
	cin>>ar[i];
	for(i=1;i<n;)
	{
		vector<ll> v;
		v.push_back(ar[i-1]);
		if(ar[i]<ar[i-1])
		{
			i++;
			continue;
		}
		while(i<n and ar[i]>=ar[i-1])
		{
			v.push_back(ar[i]);
			i++;
		}
		/*for(auto x:v)
		cout<<x<<' ';
		cout<<endl;*/
		if(v.size()>0)
		{
			ll x=m/v[0];
			m=m%v[0]+x*(v[v.size()-1]);
		}
	}
	cout<<m;
}

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

int main() {
    int m[50], f[50], r[50], c = 0;
    while(1){
        cin >> m[c] >> f[c] >> r[c];
        if(m[c] == -1 && f[c] == -1 && r[c] == -1) break;
        c++;
    }
    for(int i = 0; i < c + 1; i++){
        if(m[i] == -1 && f[i] == -1 && r[i] == -1) return 0;
        if(m[i] == -1 || f[i] == -1){
            cout << "F" << endl;
        } else if(m[i] + f[i] >= 80) {
            cout << "A" << endl;
        } else if(m[i] + f[i] >= 65 && m[i] + f[i] < 80){
            cout << "B" << endl;
        } else if(m[i] + f[i] >= 50 && m[i] + f[i] < 65){
            cout << "C" << endl;
        } else if(m[i] + f[i] >= 30 && m[i] + f[i] < 50){
            if(r[i] >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else {
            cout << "F" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3076
L=[]
M=[]

for i in range(0,28):
    a=int(input())
    L.append(a)
    i+=1

for j in range(1,31):
    b=L.count(j)
    if b==0:
        M.append(j)
        
c=M[-1]
d=M[-2]

if c>d:
    print(d)
    print(c)
else:
    print(c)
    print(d)


Measured memory_bytes: 5596
H,W = map(int, input().split())
c = tuple(map(lambda x: int(x) - 1, input().split()))
d = tuple(map(lambda x: int(x) - 1, input().split()))
maze = [[ch == '#' for ch in input().rstrip()] for _ in range(H)]
 
from sys import exit
from collections import deque
from itertools import product
que = deque([(*c, 0)])
passed = set()
while que:
    h,w,dist = que.popleft()
#         print(f'{h=},{w=}')
    if (h,w) == d:
        print(dist)
        exit()
    if (h,w) in passed:
        continue
    passed.add((h,w))
    for dh, dw in [[0,1], [0,-1], [1,0], [-1,0]]:
        nh = h + dh
        nw = w + dw
        if 0 <= nh < H and 0 <= nw < W and (nh,nw) not in passed and not maze[nh][nw]:
#                 print(f'no_warp: {nh=},{nw=}')
            que.appendleft((nh, nw, dist))

    for dh,dw in [
        [-2,-2], [-2,-1], [-2,0], [-2, 1], [-2, 2], 
        [-1,-2], [-1,-1], [-1, 1], [-1, 2], 
        [0,-2], [0, 2], 
        [1,-2], [1,-1], [1, 1], [1, 2], 
        [2,-2], [2,-1], [2,0], [2, 1], [2, 2], 
    ]: 
        nh = h + dh
        nw = w + dw
        if 0 <= nh < H and 0 <= nw < W and (nh,nw) not in passed and not maze[nh][nw]:
#                 print(f'warp: {nh=},{nw=}')
            que.append((nh, nw, dist + 1))
print(-1)

Measured memory_bytes: 240352