akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}
const long long INF = 1LL << 60;

int main(){
    int n, k;
    cin >> n >> k;
    vi x(n);
    rep(i, n){
        cin >> x[i];
    }
    ll ans = INF;
    rep(i, n-k+1){
        if(x[i] < 0 && x[i+k-1] > 0){
            chmin(ans, (ll)min(-2*x[i]+x[i+k-1], -1*x[i]+2*x[i+k-1]));
        }
        else if(x[i] >= 0){
            chmin(ans, (ll)x[i+k-1]);
        }
        else {
            chmin(ans, (ll)x[i]*(-1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
from sys import exit
# A, B, C = [int(n) for n in input().split()]

# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
while(True):
    N = int(input())
    if N < 0:
        exit()
    elif N <= 10:
        temp = 1150
        print(-(temp-4280))
    elif 10 < N <= 20:
        temp = (N - 10) * 125 + 1150
        print(-(temp-4280))
    elif 20 < N <= 30:
        temp = (N - 20) * 140 + 10 * 125 + 1150
        print(-(temp-4280))
    else:
        temp = (N - 30) * 160 + 1400 + 10 * 125 + 1150
        print(-(temp-4280))



Measured memory_bytes: 5592
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const N: usize = 8;
const FREE: i8 = -1;
const NOT_FREE: i8 = 1;

fn print_board(x: &mut Vec<Vec<bool>>, row: &mut Vec<i8>) {
    for i in 0..N {
        for j in 0..N {
            if x[i][j] {
                if row[i] != j as i8 {
                    return;
                }
            }
        }
    }

    for i in 0..N {
        for j in 0..N {
            if row[i] == j as i8 {
                print!("Q");
            } else {
                print!(".");
            }
        }
        println!();
    }
}

fn recursive(
    i: usize,
    x: &mut Vec<Vec<bool>>,
    row: &mut Vec<i8>,
    col: &mut Vec<i8>,
    dpos: &mut Vec<i8>,
    dneg: &mut Vec<i8>,
) {
    if i == N {
        print_board(x, row);
        return;
    }

    for j in 0..N {
        let i_j: usize = i + j;
        let i_j_n: usize = i + N - j - 1;

        if col[j] == NOT_FREE || dpos[i_j] == NOT_FREE || dneg[i_j_n] == NOT_FREE {
            continue;
        }
        row[i] = j as i8;
        col[j] = NOT_FREE;
        dpos[i_j] = NOT_FREE;
        dneg[i_j_n] = NOT_FREE;
        recursive(i + 1, x, row, col, dpos, dneg);
        row[i] = FREE;
        col[j] = FREE;
        dpos[i_j] = FREE;
        dneg[i_j_n] = FREE;
    }
}

fn main() {
    let mut row: Vec<i8> = vec![FREE; N];
    let mut col: Vec<i8> = vec![FREE; N];
    let mut dpos: Vec<i8> = vec![FREE; 2 * N - 1];
    let mut dneg: Vec<i8> = vec![FREE; 2 * N - 1];
    let mut x: Vec<Vec<bool>> = vec![vec![false; N]; N];

    let k: usize = read();

    for _ in 0..k {
        let r: usize = read();
        let c: usize = read();
        x[r][c] = true;
    }

    recursive(0, &mut x, &mut row, &mut col, &mut dpos, &mut dneg);
}



Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {

    int64_t N,K,S;
    cin >> N>>K>>S;
  if(S!=1000000000){
for(int i=0; i<K;i++){
    cout<<S; if(i!=N-1)cout<<" ";}
  for(int i=0; i<N-K;i++){
    cout<<S+1;if(i!=N-1-K)cout<<" ";}
  cout<<endl;}
  else{for(int i=0; i<K;i++){
    cout<<S; if(i!=N-1)cout<<" ";}
  for(int i=0; i<N-K;i++){
    cout<<1;if(i!=N-1-K)cout<<" ";}
  cout<<endl;}
}

    


Measured memory_bytes: 1280
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int Y = sc.nextInt();

    sc.close();

    int x = -1;
    int y = -1;
    int z = -1;

    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N - i; j++) {
        int k = N - i - j;
        int i_ = 10000 * i;
        int j_ = 5000 * j;
        int k_ = 1000 * k;
        if (i_ + j_ + k_ == Y) {
          x = i;
          y = j;
          z = k;
          break;
        }
      }
      if (x != -1) {
        break;
      }
    }

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

  }

}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


vector<lint> dijkstra(WeightedGraph<lint> &G,lint s)
{ 
  
  vector<lint> path(G.size(),I64_MAX);
  path[s] = 0;
  priority_queue <pair<lint,int> ,vector<pair<lint,int> > ,greater<pair<lint,int> > > que;

  que.emplace(path[s],s);

  while(!que.empty())
  {
    lint cost;
    int idx;
    tie(cost,idx) = que.top();
    que.pop();

    if(path[idx] < cost) continue;
    for (auto &e: G[idx])
    {
      lint next_cost = cost + e.cost;
      if(path[e.to] <= next_cost) continue;
      path[e.to] = next_cost;
      que.emplace(path[e.to],e.to);
    }
  }

  return path;
}
void solve()
{
  int V,E,r;
  cin>>V>>E>>r;
  WeightedGraph<lint> G(V);

  for (int i = 0; i < E; i++)
  {
    lint s,t,d;
    cin>>s>>t>>d;
    edge<lint> edge_v(s,t,d);
    G[s].push_back(edge_v);
  }

  vector<lint> path = dijkstra(G,r);

  for (int i = 0; i < V; i++)
  {
    if(path[i] != I64_MAX)
    cout<<path[i]<<endl;
    else
    cout<<"INF"<<endl;
    
  }
  
  

  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 19380
import itertools
N,M=map(int,input().split())
edges={tuple(sorted(map(int,input().split()))) for i in range(M)}
ans=0
for i in itertools.permutations(range(2,N+1),N-1):
    l=[1]+list(i)
    #ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1 以下はこの式を展開して書き直したもの
    sum=0
    for edge in zip(l,l[1:]): #これでlの1個目と2個目をとりだしたもの→2個目と3個目をとりだしたものみたいな感じになる
        if tuple(sorted(edge)) in edges:
            sum+=1
    if sum==N-1:
        ans+=1
print(ans)

Measured memory_bytes: 74636
#include <stdio.h>
#include <string.h>
#define ll long long int

int main(){
	int h1, m1, h2, m2, k;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	//h1 m1, bangun
	//h2 m2 tidur
	//k menit
	//study brp banyak
	//10 0 15 0 30
	//270
	int bangun =  (h2*60 + m2) -(h1*60 + m1)- k;
	printf("%d\n", bangun);
	
	
	return 0;
}

Measured memory_bytes: 1724
i = int(input())
str1 = ''
for z in range(1,i+1):
    x = z
    if x % 3 == 0:
        str1 =  str1 +' '+ str(z)
        continue
    while x > 0:
        if x % 10 == 3:
            str1 =  str1 +' '+ str(z)
            break
        x //= 10
print(str1)


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

using namespace std;

int main()
{
  int N, M, K;
  cin >> N >> M >> K;
  for(int j = 0; j <= M; j++) {
    for(int i = 0; i <= N; i++) {


      int black = i * M + j * N - i * j * 2;

      if(black == K) {
        cout << "Yes" << endl;
        return (0);
      }
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> ii;

vector<int> g[112345], w[112345];
bool cyc;
int n, m;
int vis[112345], dist[112345];

void check (int u) {
	vis[u] = 1;

	for (int i = 0; i < g[u].size(); i++) {
		if (vis[g[u][i]] == 0) {
			check(g[u][i]);
		} else {
			if (vis[g[u][i]] == 1) cyc = 1;
		}
	}

	vis[u] = 2;
}

int ruim;
void dfs (int u, int d) {
	vis[u] = 1;
	dist[u] = d;

	for (int i = 0; i < g[u].size(); i++) {
		if (vis[g[u][i]] == 0) {
			dfs(g[u][i], d + w[u][i]);
		} else {
			if (dist[g[u][i]] != d + w[u][i]) ruim = 1;
		}
	}

	vis[u] = 2;
}

int cnt[112345];

int main(void) {
	ios_base::sync_with_stdio(false);

	cin >> n >> m;


	for (int i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c;
		cnt[b]++;
		g[a].eb(b);
		w[a].eb(c);
	}

	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			check(i);
		}
	}

	memset(vis, 0, sizeof vis);

	int conta = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i] and cnt[i] == 0) {
			dfs(i, 0);
		}
	}

	if (!cyc and !ruim) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

/*動的計画法で解く*/
int main(){
	int a, b;
	while(std::cin >> a >> b){
		if(a == 0 && b == 0){
			break;
		}
		//入力2行目
		int n;
		std::cin >> n;
		//dpにはパターン数をいれる 1で初期化
		std::vector<std::vector<int> > dp(a, std::vector<int>(b, 1));
		//工事中の点に0をいれる
		int x, y;
		for(int i = 0; i < n; ++i){
			std::cin >> x >> y;
			//端が工事中になればその北と東を全て0にする
			if(y == 1){
				for(int i = x - 1; i < a; ++i){
					dp[i][y - 1] = 0;
				}
			}
			else if(x == 1){
				for(int i = y - 1; i < b; ++i){
					dp[x - 1][i] = 0;
				}
			}
			//端じゃないときはその点だけ0にする
			else{
				dp[x - 1][y - 1] = 0;
			}
		}
		//(2,2)から処理する
		for(int i = 1; i < a; ++i){
			for(int j = 1; j < b; ++j){
				if(dp[i][j] != 0){
					dp[i][j] = dp[i - 1][j] + dp[i][j - 1];//現在の点に辿り着くパターン数=その点の1つ西と南のパターン数の和
				}
			}
		}
		std::cout << dp[a - 1][b - 1] << std::endl;
	}
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn = 5100;
int n , k;
int a[maxn];
int dp1[maxn][maxn] , dp2[maxn][maxn];
int ans;
void work () {
	int i , j;
	scanf ( "%d%d" , &n , &k );
	for ( i = 1 ; i <= n ; i++ ) scanf ( "%d" , &a[i] );
	dp1[0][0] = 1;
	for ( i = 1 ; i <= n ; i++ ) {
		for ( j = 0 ; j <= k ; j++ ) {
			dp1[i][min(j+a[i],k)] |= dp1[i-1][j];
			dp1[i][j] |= dp1[i-1][j];
		}
	}
	dp2[n+1][0] = 1;
	for ( i = n ; i >= 1 ; i-- ) {
		for ( j = 0 ; j <= k ; j++ ) {
			dp2[i][min(j+a[i],k)] |= dp2[i+1][j];
			dp2[i][j] |= dp2[i+1][j];
		}
	}
	//for ( i = 1 ; i <= n ; i++ ) for ( j = 0 ; j <= k ; j++ ) printf ( "%d %d %d\n" , i , j , dp1[i][j] );
	for ( i = 1 ; i <= n + 1 ; i++ ) for ( j = 1 ; j <= k ; j++ ) {
		dp2[i][j] += dp2[i][j-1];
	}
	ans = n;
	for ( i = 1 ; i <= n ; i++ ) {
		for ( j = 0 ; j <= k ; j++ ) {
			//printf ( "%d %d %d %d\n" , i , j , dp1[i-1][j] , (dp2[i+1][k-j-1]-(k-a[i]-j-1<0?0:dp2[i+1][k-a[i]-j-1])) );
			if ( dp1[i-1][j] && (dp2[i+1][k-j-1]-(k-a[i]-j-1<0?0:dp2[i+1][k-a[i]-j-1])) >= 1 ) {
				ans--;
				//printf ( "%d %d\n" , i , j );
				break;
			}
		}
	}
	printf ( "%d\n" , ans );
}
int main () {
	work ();
	return 0;
}

Measured memory_bytes: 202880
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i, j;
        int work;
        int[] x = new int[3];
         
        for (i = 0; i < x.length; i++) {
            x[i] = scanner.nextInt();
        }
         
        for (i = 0; i < x.length; i++) {
            for (j = 0; j < x.length-1 - i; j++) {
                if (x[j] > x[j+1]) {
                    work = x[j];
                    x[j] = x[j+1];
                    x[j+1] = work;
                }
            }
        }
         
        for (i = 0; i < x.length; i++) {
            if (i != 0)
                System.out.print(" ");
            System.out.print(x[i]);
        }
        System.out.print("\n");
        scanner.close();
    }
}


Measured memory_bytes: 26280
package main

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

func solve() {
	a := next()

	sum := 0
	for i := 0; i < len(a); i++ {
		s := a[i : i+1]
		if s == "1" {
			sum++
		}
	}

	fmt.Fprintln(out, sum)
	return
}

func main() {
	in.Split(bufio.ScanWords)

	defer out.Flush()
	solve()
}

// --- template ---

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	s := next()
	i, e := strconv.Atoi(s)
	if e != nil {
		fmt.Println(e)
	}
	return i
}


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

int RES;

void dfs(int cur, int left, int sum) {
    if (cur > 0) {
        dfs(cur-1, left, sum);
        if (left && sum >= cur) dfs(cur-1, left-1, sum-cur);
    } else if (sum == 0 && left == 0) RES++;
}

int main() {
    int N, K, S;

    while (cin >> N >> K >> S && (N || K || S)) {
        RES = 0; dfs(N, K, S);
        cout << RES << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
	"math"
	"sort"
)

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

	v := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Scan(&v[i])
	}

	min := int(math.Min(float64(n), float64(k)))

	result := 0
	for i:=0;i<=min;i++ {
		for j:=0;j<=min-i;j++ {
			sumArr := make([]int, 0, i+j)
			sumArr = append(sumArr, v[:i]...)
			sumArr = append(sumArr, v[len(v)-j:]...)

			var (
				sum int
				rem = k - i - j
			)

			sort.Ints(sumArr)
			for _, l := range sumArr {
				if l < 0 && rem > 0 {
					rem--
					continue
				}
				sum += l
			}
			//fmt.Println(i,j, k-i-j,sumArr, sum)
			if sum > result {
				result = sum
			}
		}
	}
	fmt.Println(result)
}

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

const int N_MAX = 100;
const int INF = 1000000;

struct edge{
    int to, cap, rev;
    edge(int t, int c, int r): to(t), cap(c), rev(r){}
};

vector<edge> G[N_MAX * 2];
bool used[N_MAX * 2];

void add_edge(int from, int to, int cap){
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size()-1);
}

int dfs(int v, int t, int f){
    if (v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> RED;
    vector<pair<int, int>> BLUE;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        RED.emplace_back(a, b);
    }
    for(int i = 0; i < n; i++){
        int c, d;
        cin >> c >> d;
        BLUE.emplace_back(c, d);
    }
    for(int i = 1; i <= n; i++){
        int a = RED[i-1].first, b = RED[i-1].second;
        for(int j = 1; j <= n; j++){
            int c = BLUE[j-1].first, d = BLUE[j-1].second;
            if (a < c && b < d){
                add_edge(i, n+j, 1);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        add_edge(0, i, 1);
        add_edge(n+i, 2 * n + 1, 1);
    }
    cout << max_flow(0, 2 * n + 1) << endl;
    return 0;
}

Measured memory_bytes: 384
#include<map>
#include<iostream>
#include<string>
using namespace std;

int main()
{
	string s;
	std::cin >> s;
	int counter = 0;
	for (char c : s) {
		if (c == 'o')counter++;
	}
	cout << 700 + counter * 100;


	return 0;
}


Measured memory_bytes: 256
from itertools import product

H, W = map(int, input().split())
table = [input().split() for _ in range(H)]
for i, j in product(range(H), range(W)):
    if table[i][j] == 'snuke': print('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[j] + str(i+1)); break

Measured memory_bytes: 3060
S = list(input())

X, Y = int(S[0] + S[1]), int(S[2] + S[3])

if (1 <= X <= 12) and (1 <= Y <= 12):
    print('AMBIGUOUS')
elif (1 <= X <= 12) and not (1 <= Y <= 12):
    print('MMYY')
elif not (1 <= X <= 12) and (1 <= Y <= 12):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

const double PI = acos(-1);

vector<int> g[605];

int n, m;
const double INF = 1e9;

double memo1[605];
int maxV[605];
double solve1(int u) {
  double &res = memo1[u];
  if(res < 0) {
    if(u == n-1) {
      res = 0;
    } else {
      res = 0;
      for(int v : g[u]) {
        double cur = solve1(v);
        if(maxV[u] == -1 || solve1(maxV[u]) < cur) {
          maxV[u] = v;
        }
        res += cur + 1;
      }
      res /= g[u].size();
    }
  }
  return res;
}

double memo2[605][605];
double solve2(int u, int x) {
  double &res = memo2[u][x];
  if(res < 0) {
    if(u == n-1) {
      res = 0;
    } else if(x < u) {
      res = solve1(u);
    } else {
      res = 0;
      for(int v : g[u]) {
        if(u == x && maxV[u] == v) {
          continue;
        }
        double cur = solve2(v, x);
        res += cur + 1;
      }
      if(res == 0) { // forbidden
        res = INF;
      }
      res /= u == x ? (int)g[u].size() - 1 : (int)g[u].size();
    }
  }
  return res;
}

int main(void) {
  scanf("%d%d", &n, &m);
  REP(i, m) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s;
    --t;
    g[s].push_back(t);
  }
  REP(i, n) {
    memo1[i] = -1;
    maxV[i] = -1;
    REP(j, n) {
      memo2[i][j] = -1;
    }
  }
  double res = solve1(0);
  // REP(i, n) {
  //   cerr << "> " << i << ": " << maxV[i] << " " << memo1[i] << endl;
  // }
  REP(i, n) {
    double cur = solve2(0, i);
    // cerr << ">> " << i << " : " << cur << endl;
    if(cur < res) {
      res = cur;
    }
  }
  printf("%.10f\n", res);
  
  return 0;
}


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

//GCD,LCM
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main()
{
    int N,x,A[110]={},ans=0;
    cin>>N>>x;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    sort(A,A+N);

    for(int i=0;i<N;i++){
        if(x<A[i]){
            break;
        }else{
            x-=A[i];
            ans++;
        }
    }

    if(N==ans&&x>0)ans--;

    cout<<ans<<endl;

    return 0;
}

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

int main() {
	long long int K;
	int N; 
	cin >> N >> K;
	vector<int> A(N + 1);
	for (int n = 1; n <= N; n++) {
		cin >> A[n];
	}

	vector<int> route;		// i回目の移動で訪れる場所の番号
	vector<int> spot_n(N + 1, -1);	// 町n(1<=n<=N)を何番目に訪れたか
	int period = 0;			// 周期
	int initial_p = 0;		// 周期に入る前の移動回数
	route.push_back(1);
	route[0] = 1;
	spot_n[1] = 0;
	for (int i = 1; i < N; i++) {
		int temp_n = A[route[i - 1]];
		route.push_back(temp_n);
		if (spot_n[route[i]] != -1) {
			int former = spot_n[route[i]];
			int latter = i;
			period = latter - former;
			initial_p = spot_n[route[i]];
			break;
		}
		spot_n[route[i]] = i;
	}
	
	if (K <= initial_p) {
		cout << route[K] << endl;
	}
	else {
		int temp = (K - initial_p) % period + initial_p;
		cout << route[temp] << endl;

	}
	return 0;

}

Measured memory_bytes: 5860
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
  ll D;
  cin >> D;
  cout << (D==25 ? "Christmas" : (D==24 ? "Christmas Eve" : (D==23 ? "Christmas Eve Eve" :  "Christmas Eve Eve Eve"))) <<endl;
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define gcd __gcd
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int)(1e9+7);

int pDivisors(int n, int t)
{
    vector<int> v;
    int mx = 0;
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if(i<=t)mx = max(i, mx);
            if(n/i<=t)mx = max(n/i, mx);
        }

    }
    return mx;
}

int x[102],y[202], h[234];
void _(){
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> h[i];
    }

    bool ok = 1;
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j < 101; ++j) {
            map<int,int> s;
            int mi = INT_MAX;
            for (int k = 0; k < n; ++k) {
                if(h[k])s[abs(i-x[k]) + abs(j-y[k])+h[k]] ++;
                else mi = min(mi, abs(i-x[k]) + abs(j-y[k])+h[k]);
            }
            if(s.size()==1 && s.begin()->second>1 && mi >= s.begin()->first){
                ok = 0;
                cout << i << " " << j << " " << s.begin()->first;
                return;
            }

        }
    }

    if(ok){
        for (int i = 0; i <= 100; ++i) {
            for (int j = 0; j < 101; ++j) {
                map<int,int> s;
                int mi = INT_MAX;
                for (int k = 0; k < n; ++k) {
                    if(h[k])s[abs(i-x[k]) + abs(j-y[k])+h[k]] ++;
                    else mi = min(mi, abs(i-x[k]) + abs(j-y[k])+h[k]);
                }
                if(s.size()==1 &&  mi >= s.begin()->first){
                    ok = 0;
                    cout << i << " " << j << " " << s.begin()->first;
                    return;
                }

            }
        }
    }


}


int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}





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

int debug = 0;

int main()
{
    int h;
    double a;
    cin >> h >> a;

    cout << ceil(h / a) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<LL>>;

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}



int main() {
  LL n,k=-1,sum=0,a=0,b=0,c=0,d=0,ans=0;
  LL MOD = 1000000007;
  LL INF = 1LL << 60;
  LL h[100001],L[100001],R[100001];
  string S="",T="",U="";
  cin >> n;
  cin >> h[0];
  L[0]=h[0];
  for(LL i=1;i<n;i++){
    cin >> h[i];
    L[i] = gcd(L[i-1],h[i]);
  }
  R[n-1] = h[n-1];
  for(LL i=n-2;i>0;i--){
    R[i] = gcd(R[i+1],h[i]);
  }
  for(LL i=1;i<n;i++){
    ans = max(ans,gcd(L[i-1],R[i+1]));
  }
  ans = max(ans,max(L[n-2],R[1]));
  cout << ans << endl;
}

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

int main(){
    char c;
    cin >> c;
    if( c == 'a' || c == 'i' || c == 'u'||
        c == 'e' || c == 'o'){
            cout << "vowel" << endl;
        }
        else{
            cout << "consonant" << endl;
        }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

ll val[201010];
vector<int> E[202020];
using Graph = vector<vector<int>>;

void dfs(int cur, int pre, ll v) {
    val[cur] += v;
    for (auto x : E[cur]) {
        if (x != pre) {
            dfs(x, cur, val[cur]);
        }
    }
}

int main() {

    int N, Q;
    cin >> N >> Q;

    int x, y;
    REP(i, N-1) {
        cin >> x >> y;
        E[x-1].push_back(y-1);
        E[y-1].push_back(x-1);
    }

    REP(i, Q) {
        cin >> x >> y;
        val[x-1] += y;
    }

    dfs(0, -1, 0);
    REP(i, N) {
        cout << val[i] << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	int n;
	cin >> n;
	vector<double> x(n, .0), y(n, .0);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	double sum = 0;
	for (int i = 1; i <= 3; i++) {
		for (int j = 0; j < n; j++) {
			sum += pow(abs(x[j] - y[j]), i);
		}
		cout << setprecision(8) << fixed << pow(sum, 1. / i) << endl;
		sum = 0;
	}
	double ma = 0;
	for (int i = 0; i < n; i++) {
		ma = max(ma, abs(x[i] - y[i]));
	}
	cout << setprecision(8) << fixed << ma << endl;
	return 0;
}



Measured memory_bytes: 3396
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int hoge(ll n, int cnt){
  if(n%2){
    return cnt;
  }else{
    return hoge(n/2,cnt+1);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D,N,ans=1;
  cin>>D>>N;
  for(int i=0;i<D;i++){
    ans*=100;
  }
  if(N==100)N+=1;
  ans*=N;
  cout<<ans<<endl;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a) cin >> i;
	bool ok = true;
	for (auto i : a)
	{
		if (~i&1)
		{
			ok &= i % 3 == 0 || i % 5 == 0;
		}
	}
	if (ok) cout << "APPROVED\n";
	else cout << "DENIED\n";

	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<61;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int now = c;
	bool ans = false;
	REP(i, 100000) {
		now += b;
		if (now % a == 0) ans = true;
	}
	
	puts(ans ? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)
a = []
n.times {|i| a << i + l}
sum = 0
a.each {|i| sum += i}
if sum < 0
  puts sum + a.map{|i| i < 0 ? -1 * i : i}.sort.first
else
  puts sum - a.map{|i| i < 0 ? -1 * i : i}.sort.first
end

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

int main() {
    int a, b;
    cin >> a >> b;

    if (a <= 9 && b <= 9)
        cout << a * b << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cmath>
#include<iostream>
#include<iomanip>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;

class Point {
public:
    double x, y;

    Point(double x=0, double y=0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(x*a, y*a); }
    Point operator / (double a) { return Point(x/ a, y/ a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x*x, y*y; }
    bool operator < (const Point &p) const {
	return x != p.x ? x<p.x : y < p.y;
    }
    
    bool operator == (const Point &p) const {
	return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;

double dot(Vector a, Vector b) {
    return a.x*b.x + a.y*b.y;
}

double norm(Vector a) {
    return a.x*a.x + a.y*a.y;
}


Point project(Point p0, Point p1, Point p2) {
    Point base = p1-p0;
    double r = dot(p2-p0, base) /norm(base);
    return p0 + base*r;
}

int main() {
    int n,i;
    
    Point p0, p1, p2,p3;
    cin >> p0.x >> p0.y >> p1.x >> p1.y;
    cin >> n;
    for(i=0;i<n;i++){
	cin >>  p2.x >> p2.y;
	p3 = project(p0,p1, p2);
	cout << fixed << showpoint;
	cout << setprecision(8);
	cout << p3.x <<" " << p3.y << endl;
    }
    return 0;

}

Measured memory_bytes: 1292
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	cin>>s;
	bool alpha[26];
	rep(i,26)alpha[i]=false;
	bool check=false;
	rep(i,s.size()){
		if(alpha[s[i]-'a']){
			check=true;
			break;
		}else alpha[s[i]-'a']=true;
	}
	if(check)cout<<"no"<<endl;
	else cout<<"yes"<<endl;
	return 0;
}

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

int main() {
  int N, K, tmp, Sum=0;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N){
    cin >> tmp;
    A.at(tmp-1)++;
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for(int i=K; i<N; i++) Sum+=A.at(i);
  cout << Sum << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int D) {
  string ans = "Christmas";
  for (int i = 25; i > D; i--) {
    ans += " Eve";
  }
  printf("%s\n", ans.c_str());
}

int main() {
  int D;
  cin >> D;
  solve(D);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
temp_list = []
ans_list = []
for i in range(n):
    temp = t - h[i] * 0.006
    temp_list.append(temp)
for i in temp_list:
    ans = abs(i - a)
    ans_list.append(ans)
print(ans_list.index(min(ans_list))+1)


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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Array w(n),s(n),v(n);
	REP(i,n) cin>>w[i]>>s[i]>>v[i];
	Array o(n);
	REP(i,n) o[i]=i;
	sort(all(o),[&](ll i,ll j){
		return min(s[i]-w[j],s[j]) < min(s[j]-w[i],s[i]);
	});

	ll sn=20101;
	Matrix dp(n+1,Array(sn,-1));
	dp[0][0]=0;
	REP(i,n){
		REP(j,sn){
			if(dp[i][j]==-1) continue;
			if(j<=s[o[i]]) chmax(dp[i+1][j+w[o[i]]],dp[i][j]+v[o[i]]);//のっける
			chmax(dp[i+1][j],dp[i][j]);//のっけない
		}
	}

	ll ans=0;
	REP(i,sn) chmax(ans,dp[n][i]);
	cout<<ans<<en;
}

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

    solve();
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s,t;cin>>s>>t;
	string u="";
	rep(i,t.size()){
		u+=s[i];
		u+=t[i];
	}
	if(s.size()>t.size()){
		u+=s[s.size()-1];
	}
	cout<<u<<endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())

    for a in range(1, 3501):
        for b in range(1, 3501):
            nu = n * a * b
            dn = 4 * a * b - n * (a + b)
            if dn > 0 and nu % dn == 0:
                return print(a, b, nu // dn)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64628
#include <stdio.h>
#include <string.h>

int main()
{
        char w[10];
        char t[1000][1000];
        int input_size = 0, num = 0, word_num = 0;
        int match = 0;
        int w_len, t_len;

        scanf("%s", w);
        w_len = strlen( w );

        while ( 1 )
        {
                        scanf("%s", t[input_size]);
                        if ( strcmp(t[input_size], "END_OF_TEXT") == 0 )
                                break;
                        input_size = input_size + 1;

        }

        while ( word_num < input_size )
        {
                if ( strcmp(t[word_num], w) == 0 )
                {
                        match = match + 1;
                }

                else if ( strlen(t[word_num]) == w_len )
                {
                        num = 0;
                        while ( num < w_len )
                        {
                                t[word_num][num] = tolower(t[word_num][num]);
                                w[num] = tolower(w[num]);
                                num = num + 1;
                        }

                        if ( strcmp(t[word_num], w) == 0 )
                        {
                                match = match + 1;
                        }
                }

                word_num = word_num + 1;
        }

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

Measured memory_bytes: 740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
using namespace std;
int n,m;
ll cnt1,cnt2;
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
int main()
{
	n=read();m=read();
	if(n>m) swap(n,m);
	if(n==1&&m==1) puts("1");
	else if(n==1) printf("%lld",m-2);
	else printf("%lld",(ll)max(n-2,0)*max(m-2,0));	 
    return 0;
}



Measured memory_bytes: 256
"use strict";
    
const gcd = (a, b) => {
    return b ? gcd(b, a % b) : a;    
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    // 累積GCD
    let left  = [...Array(N + 1)].fill(0);
    let right = [...Array(N + 1)].fill(0);
    
    for(let i=0; i<N; i++) {
        left[i + 1] = gcd(left[i], A[i]);
    }
    
    for(let i=N-1; i>=0; i--) {
        right[i] = gcd(right[i+1], A[i]);
    }

    // 集計する
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        // 左側
        let l = left[i];
        // 右側
        let r = right[i + 1];
        
        // 更新
        answer = Math.max(answer, gcd(l, r));
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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; }

const int INF = 1001001001;

int main()
{   
    int n;
    string s;
    cin >> n >> s;
    int r = 0, w = 0;
    rep(i, n) if(s[i]=='R') r++; 

    int ans = r;
    rep(i, n) {
        if(s[i]=='R') r--;
        else w++;
        int now = max(r, w);
        ans = min(ans, now);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3700
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
use std::collections::VecDeque;
fn main() {
    input! {
    N:usize,
    M:usize,
    AB:[(Usize1,Usize1);M]
    }
    // 部屋iから繋がっている部屋のリスト
    let mut tonari: Vec<Vec<usize>> = vec![Vec::with_capacity(M); N];
    let mut ans: Vec<usize> = vec![N; N];
    for (a, b) in AB {
        tonari[a].push(b);
        tonari[b].push(a);
    }
    //    for i in 0..N {
    //        println!("{}={:?}", i, tonari[i]);
    //    }
    let mut nexts: VecDeque<usize> = VecDeque::new();
    nexts.push_front(0);
    while let Some(i) = nexts.pop_back() {
        //        println!("{}={:?}", i, tonari[i]);
        for &j in tonari[i].iter() {
            if ans[j] == N {
                ans[j] = i;
                nexts.push_front(j);
            }
        }
    }
    println!("Yes");
    for j in 1..N {
        println!("{}", ans[j] + 1);
    }
}


Measured memory_bytes: 16800
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,sum=0,max,a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sum+=a;
        if(!i){
            max=a;
            sum-=max;
        }else if(max<a){
            sum+=max;
            sum-=a;
            max=a;
        }
    }
    cout<<(max<sum?"Yes":"No")<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,b,a[100],c,i,j,m,k=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for (  i=0;i <n;  i++) {
  m=i;
  b=0;
  for(j=i;j<n;j++){
    if(a[j]<a[m]){
      m=j;
    b=1;
    }
  }
  if(b==1){
      c=a[i];
      a[i]=a[m];
      a[m]=c;
      k++;
    }
  }
  for(i=0;i<n-1;i++){
  printf("%d ",a[i]);
}
printf("%d\n%d\n",a[n-1],k);
return 0;
}

Measured memory_bytes: 600
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let a=nin()*100+nin()*10+nin()
  out(a%4==0?'YES':'NO')
}
main()


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

const int MAX = 100001;

int n;
int main(){
    cin >> n;
    vector<int> a(n); rep(i, 0, n) cin >> a[i];

    vector<int> odd_hist(MAX, 0), even_hist(MAX, 0);
    rep(i, 0, n){
        if(i%2 == 0) even_hist[a[i]]++;
        else odd_hist[a[i]]++;
    }

    // (要素数, 数値)
    vector<P> odd, even;
    rep(i, 0, MAX){
        odd.push_back(P(odd_hist[i], i));
        even.push_back(P(even_hist[i], i));
    }

    sort(ALLR(odd)); sort(ALLR(even));

    // 要素数
    int odd_f = odd[0].first, odd_s = odd[1].first;
    int even_f = even[0].first, even_s = even[1].first;

    if(odd[0].second == even[0].second){
        int ch = max(odd_f + even_s, even_f + odd_s);
        cout << n - ch << endl;
    }
    else cout << n - odd_f - even_f << endl;

    return 0;
}


Measured memory_bytes: 5868
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String st;

		st = sc.nextLine();
		for (int i = 0; i < st.length(); i++) {
			if ('a' <= st.charAt(i) && st.charAt(i) <= 'z') {
				System.out.print((char)(st.charAt(i) + 'A' - 'a'));
			} else {
				System.out.print((char)(st.charAt(i)));
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    rep (i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int cnt = 0, ans = mp.size();
    for (auto p : mp) {
        if (p.second > 1) {
            if (p.second % 2 == 0) {
                cnt++;
            }
        }
    }
    if (cnt % 2 == 1) ans--;
    cout << ans << "\n";
}


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

using namespace std;

void f(string &s)
{
    for (char &c : s) {
        if ('a' <= c && c <= 'z') c = (c - 'a' + 25) % 26 + 'a';
    }
}

int main()
{
    string s;

    while (getline(cin, s)) {
        if (s == "") break;
        while (s.find("the") == string::npos && s.find("this") == string::npos && s.find("that") == string::npos) f(s);
        cout << s << endl;
    }
}

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

using namespace std;



int main(int argc, char const *argv[]){
    long long l, r;
    long long c = 2019;
    cin >> l >> r;
    long long answer=10000;

    r = r - (l/c)*c;
    l = (long long)(l%c);
    if(r>=2019){
        answer = 0;
    }else{
        for(long long int i=l;i<r;i++){
            for(long long int j=(i+1);j<=r;j++){
                answer = min(answer, (long long)((long long)(i%c)*(long long)(j%c))%c);
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int K=9;

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

    int ans=0;
    for(int i=1;i<=K-2;i++){
        for(int j=1;i+j<=K-1;j++){
            for(int k=1;i+j+k<=K;k++){
                vint v;
                REP(l,i) v.push_back(3);
                REP(l,j) v.push_back(5);
                REP(l,k) v.push_back(7);

                do{
                    int x=0,digits=i+j+k;
                    REP(l,digits){
                        x+=v[l]*pow(10,digits-l-1);
                    }
                    if(x<=N) ans++;

                }while(next_permutation(ALL(v)));

            }
        }
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256