akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define debug(n) cerr << #n << ':' << n << endl;

int main(){
  int n;cin >> n;
  vector<int> w(n);
  for(auto&&e : w)cin >> e;
  int ans = 1.0e+9;
  for(int i = 1; i < n; ++i){
    int suma=0,sumb=0;
    for(int j = 0; j < n; ++j){
      if(j < i)suma += w[j];
      else sumb += w[j];
    }
    ans = min(ans , abs(suma - sumb));    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int S;
	cin >> S;
	int a = S % 60;
	int b = (S - a) / 60 % 60;
		int c = (S - a - b) / 3600;
		cout << c << ":" << b << ":" << a << endl;
	return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h> 
using namespace std ;
int main () {
	int n ;
	cin >> n ;
	long long k ;
	cin >> k ;
	vector <int> v (n+1) ;
	for (int i = 1 ; i <= n ; ++i) {
		cin >> v[i] ;
	}
	vector <bool> vis(n+1) ;
	
	// to find cycle :
	vector <int> path ;
	int i = 1 ;
	int strt = -1 ;
	long long bkup = k ;
	bool cycle = false ;
	while (k--) {
		path.push_back(i) ;
		vis[i] = true ;
		i = v[i] ;
		if (vis[i]) {
			strt = i ;
			cycle = true ;
			break ;
		}
	}
	if (!cycle) {
		cout << i ;
		return 0 ;
	}
	int pos = 0 ;
	for ( ; path[pos] != strt ; ++pos) ;
	k = bkup ;
	if (k < pos) {
		cout << path[k] ;
		return 0 ;
	}
	k -= pos ;
	int len = path.size() - pos ;
	k %= len ;
	cout << path[pos + k] ;
	
	return 0 ;
}

Measured memory_bytes: 5040
N = int(input())
A = list(map(int, input().split()))

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1

    #print(A)

if A[N-1] >= 0:
    print(sum(A))
    exit()

A = A[::-1]
A[0] *= -1
idx = A.index(min(A))
#print(idx)
A[0] *= -1

for i in range(0, idx):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1

    #print(A)
    
print(sum(A))

Measured memory_bytes: 14464
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

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

  int h, w;
  cin >> h >> w;

  const int MAX = 13000;
  vector<vector<P>> table(h, vector<P>(w));
  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(MAX * 2 + 1, false)));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> table[i][j].first;
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> table[i][j].second;
    }
  }
  int x = table[0][0].first - table[0][0].second;
  dp[0][0][MAX + x] = true;
  dp[0][0][MAX - x] = true;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int now = table[i][j].first - table[i][j].second;
      for (int k = 0; k <= MAX * 2; ++k) {
        bool f = false;
        if (i > 0 && dp[i - 1][j][k]) f = true;
        if (j > 0 && dp[i][j - 1][k]) f = true;
        if (!f) continue;
        if (k + now >= 0 && k + now <= 2 * MAX) dp[i][j][k + now] = true;
        if (k - now >= 0 && k - now <= 2 * MAX) dp[i][j][k - now] = true;
      }
    }
  }
  int ans = INF;
  for (int i = -MAX; i <= MAX; ++i) {
    if (dp[h - 1][w - 1][MAX + i]) ans = min(abs(i), ans);
  }

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


Measured memory_bytes: 21248
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int be[][] = new int[100000+1][2];
        int bo[][] = new int[100000+1][2];
        for (int i=0; i<N/2; i++) {
            int e = in.nextInt();
            int o = in.nextInt();
            be[e][0] = e;
            bo[o][0] = o;
            be[e][1]++;
            bo[o][1]++;
        }
        Arrays.sort(be, Comparator.comparing((int[] a) -> a[1]).reversed());
        Arrays.sort(bo, Comparator.comparing((int[] a) -> a[1]).reversed());
        if(be[0][0] != bo[0][0]) out.println(N-be[0][1]-bo[0][1]);
        else out.println(Math.min(N-be[0][1]-bo[1][1], N-be[1][1]-bo[0][1]));
    }

}
}



Measured memory_bytes: 66804
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  vector<int> vv(30000, 1);
  vv[0] = vv[1] = 0;
  REP(i,30000)
    if (vv[i])
      for (int j=i*2; j<30000; j+=i)
        vv[j] = 0;
  vector<int> prime;
  REP(i, 30000)
    if (vv[i]) prime.push_back(i);
  
  int n;
  while(cin>>n,n) {
    int res = 0;
    for (int i=0; prime[i]<n; ++i) {
      int a = prime[i];
      for (int j=i; a+prime[j]<n; ++j) {
        int b = prime[j];
        int c = n-b-a;
        if (c<b) continue;
        if (vv[c]) {
          if (abs(a-b) < c && c < a+b) {
            //cout << a << " " << b << " " << c << endl;
            res++;
          }
        }
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1056
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        System.out.println(sort(scan.nextInt() , scan.nextInt(), scan.nextInt()));
    }

    /**
     * ソートして返します。
     */
    private static String sort(int a, int b, int c) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(a);
        list.add(b);
        list.add(c);
        Collections.sort(list);
        return list.get(0) + " " + list.get(1) + " " + list.get(2);
    }
}

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

using namespace std;

#define ll long long

int main(){
  int n, m; cin >> n >> m;
  vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
  
  vector<pair<int, int>> cb(m);
  for(int i = 0; i < m; i++){
    int b, c; cin >> b >> c;
    cb[i] = make_pair(c, b);
  }
  
  sort(a.begin(), a.end());
  sort(cb.begin(), cb.end());
  
  int cb_min_index = 0;
  /*for(int i = m - 1; i >= 0; i--){
    if(cb[i].first < a[0]){
      cb_min_index = i + 1;
      break;
    }
  }*/
  
  ll sum = 0;
  int a_index = n - 1;
  int cb_index = m - 1;
  int cb_count = 0;
  for(int i = 0; i < n; i++){
    if(cb_index >= 0 && cb[cb_index].first > a[a_index]){
      sum += (ll)cb[cb_index].first;
      if(cb_count == cb[cb_index].second - 1){
        cb_count = 0;
        cb_index--;
      }else{
        cb_count++;
      }
    }else{
      sum += (ll)a[a_index];
      a_index--;
    }
  }
  
  cout << sum << endl;
  
  return 0;
}


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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	vector<int> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	s[0] = s[0] - 1;
	for (int i = 1; i < n-1; i++) {
		if (s[i] > s[i-1]) {
			s[i] = s[i] - 1;
		}
		if (s[i + 1] < s[i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 892
#include <iostream>
#include <string>

int main(int argc, const char * argv[]) {
    std::string S,T;

    std::cin >> S;
    std::cin >> T;

    unsigned long long diff = 0;
    for(int i=0; i<S.length(); i++) {
        if(S[i] != T[i]) {
            diff++;
        }
    }

    std::cout << diff;

    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  
  int64_t m = n /(a+b);
  
  if(n - ((a+b)*m) < a){
    cout << a*m + (n - ((a+b)*m)) << endl;
  }
  else{
    cout << a*(m+1) << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#-------
# Initialize
t = input()
t_uniq = list(set(t))

#-------
# Define
def solve(t_list, c):
    li = t_list.split(c)
    ret = 0
    for i in li:
        ret = max(ret, len(i))
    return ret

#-------
# Do

ans = 101
for uniq in list(set(t)):
    ans = min(ans, solve(t, uniq))
print(ans)

#-------
# Output


Measured memory_bytes: 3060
#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	for(int i=105;i<=n;i+=2){
			int an=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)
					an++;
		}
			if(an>=8)
				ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int d=c-b;
    if(b>=c){
        cout<<"delicious"<<endl;
    }
    else{
        if(d>a){
            cout<<"dangerous"<<endl;
        }
        else{
            cout<<"safe"<<endl;
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func abs(n int64) int64 {
	if n >= 0 {
		return n
	} else {
		return -n
	}
}

func main() {
	var x, k, d int64
	fmt.Scan(&x)
	fmt.Scan(&k)
	fmt.Scan(&d)
	x = abs(x)
	k = abs(k)
	d = abs(d)
	ans := x

	if x > abs(k*d) {
		ans = x - abs(k*d)
	} else {
		if (k-x/d)%2 == 0 {
			ans = x % d
		} else {
			temp := x % d
			if abs(temp+d) < abs(temp-d) {
				ans = abs(temp + d)
			} else {
				ans = abs(temp - d)
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1772
L, R = list(map(int, input().split()))
ans = 2018
for i in range(L, min(R, L + 2019) + 1):
    for j in range(i + 1, min(R, L + 2019) + 1):
        ans = min(ans, ((i % 2019) * (j % 2019)) % 2019)
print(ans)


Measured memory_bytes: 2940
/* AOJ 0086
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0086
 *
 */

#include <stdio.h>

#define SIZE 101

/* http://ja.wikipedia.org/wiki/%E4%B8%80%E7%AD%86%E6%9B%B8%E3%81%8D */


int node[SIZE];

void init(void){
    int i;
    for(i=0; i< SIZE; i++){
        node[i] = 0;
    }
    /* goal and start */
    node[1]=1;
    node[2]=1;
}

int check(void){
    int i;
    for(i=1; i< SIZE; i++){
        if(node[i]%2){
            return 0;
        }
    }
    return 1;
}

int main(){
    int a, b;

    init();
    while(scanf("%d %d", &a, &b)==2){
        if(a==0 && b ==0){
            if(check()){
                printf("OK\n");
            }else{
                printf("NG\n");
            }
            init();
        }else{
            node[a]++;
            node[b]++;
        }
    }
    return 0;
}

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

using namespace std;
const int maxn = 110;
const int maxw = 1e5+10;

int n, w;
long long dp[maxn][maxw];
int wa[maxn], v[maxn];

int main() {
	scanf("%d%d", &n, &w);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", wa+i, v+i);
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= w; j++) {
			dp[i][j] = max(max(dp[i - 1][j], (j >= wa[i] ? dp[i - 1][j - wa[i]] + v[i] : 0)), (j > 0 ? dp[i][j - 1] : 0));
		}
	}
	printf("%lld\n", dp[n][w]);
	return 0;
}


Measured memory_bytes: 79360
import math
def lcm(x, y):return (x * y) // math.gcd(x, y)
a,b,c,d=map(int,input().split())

e = lcm(c,d)
print(b-a+1-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e))

Measured memory_bytes: 80584
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
if N < 3:
  print(0)
  exit(0)
for i in range(0,N-2):
  for j in range(i,N-1):
    for k in range(j,N):
      if L[i]!= L[j] and L[j] != L[k] and L[i] != L[k]:
        if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
          count += 1
print(count)

Measured memory_bytes: 9212
#include <stdio.h>
   #include <stdlib.h>

    
   int main(){
   	int n,ans=0;
   	scanf("%d", &n);
   	if(n % 10 == 1){
   	    ans+=9;
   }   
    else if(n % 10 == 9){
    	ans+=1;
    }
   else{
   	ans += (n % 10);
   }
   int x =(n / 10) % 10;
   switch (x) {
   	case 1: ans += 90; break;
   	case 9: ans += 10; break;
   	default: ans += (x * 10); break;
   }
   x = n/ 100;
   switch (x) {
   	case 1: ans += 900; break;
   	case 9: ans += 100; break;
   	default: ans += x * 100; break;
   }
   printf("%d",ans);
   return 0;
   }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int k = 0;
ll ans = 0;

int main() {
	cin >> n;
	rep(i, n) {
		int num, a;
		cin >> num >> a;
		if (k < num) {
			k = num;
			ans = num + a;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lu long unsigned

using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second&&a.first<b.first);
}
bool isPrime(int val){
    for(int i=2;i*i<=val;i++){
        if(val%i==0)
            return false;
    }
    return true;
}

void solve(){
    ll int m=1000000007,n,ans=1;
    cin>>n;
    vector<int>primes;
    map<int,int>prime;
    for(int i=2;i<=n;i++){
        if(isPrime(i)){
            primes.push_back(i);
            prime[i]=0;
        }
    }
    for(lu int i=0;i<primes.size();i++){
        int x=primes[i];
        while(n/x!=0){
            prime[primes[i]]+=n/x;
            x*=primes[i];
        }
        prime[primes[i]]++;
        ans=ans%m*prime[primes[i]];
    }
    cout<<ans%m;


}


int main(){
    /*int t;
    cin>>t;
    while(t--)*/
        solve();


    return 0;
}
































































//1-(3+5-2+(3+19-(3-1-4+(9-4-(4-(1+(3)-2)-5)+8-(3-5)-1)-4)-5)-4+3-9)-4-(3+2-5)-10




















Measured memory_bytes: 3640
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
N = int(input())
P = list(map(int,input().split()))
cnt = 0
mi = P[0]
for i in range(N):
    if P[i]<=mi:
        cnt +=1
    mi = min(mi,P[i])
print(cnt)

    














Measured memory_bytes: 75344
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int main() {
	string s;
	cin >> s;
	int n = s.length();
	string res;
	int ans = 0;
	rep(i, n) {
		rep(j, 2) {
			string s2 = s.substr(i, j + 1);
			if (res != s2) {
				ans++;
				res = s2;
				i += j;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/
int main(){
	char s[99];
	scanf("%s",s);
	int n = strlen(s);
	for(int i=0; i+1<n; i++)
		if(s[i] == 'A' && s[i+1] == 'C'){
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s,t;
int main(){
	int i,n;
	cin >> n >> s;
	for(i=0;i<n;i++){
		if(i==0 || t.back()!=s[i]){
			t.push_back(s[i]);
		}
	}
	cout << t.size() << endl;
}

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

int c[1001][1001];

int main(){
  int num,xlen,ylen;
  int i,j,k;
  char X[10001],Y[10001];
  
  scanf("%d",&num);
  for(k=1;k<=num;k++){
    scanf("%s",X);
    scanf("%s",Y);
    
    xlen=strlen(X);
    ylen=strlen(Y);
    for(i=1;i<=xlen;i++) c[i][0]=0;
    for(j=0;j<=ylen;j++) c[0][j]=0;
    
    for(i=1;i<=xlen;i++){
      for(j=1;j<=ylen;j++){
	if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
	else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
	else c[i][j]=c[i][j-1];
      }
    }
    printf("%d\n",c[xlen][ylen]);
  }

  
  return 0;
}



Measured memory_bytes: 5780
import sys
n,m=map(int,input().split())
a1=0
a2=0
a3=0
c1=0
c2=0
c3=0
for i in range(m):
    s,c=map(int,input().split())
    if s==1:
        if c1==1:
            if a1==c:
                pass
            else:
                print(-1)
                sys.exit()
        else:
            a1=c
            c1=1
    if s==2:
        if c2==1:
            if a2==c:
                pass
            else:
                print(-1)
                sys.exit()
        else:
            a2=c
            c2=1
    if s==3:
        if c3==1:
            if a3==c:
                pass
            else:
                print(-1)
                sys.exit()
        else:
            a3=c
            c3=1
if n==1:
    pass
else:
    if c1==0:
        a1=1
if n==1:
    ans=a1
elif n==2:
    ans=a1*10+a2
else:
    ans=a1*100+a2*10+a3
k=ans//10**(n-1)
if k==0:
    if n==1:
        print(ans)
    else:
        print(-1)
else:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    string x,y,z;
    cin>>x>>y>>z;
    string a;
    a+=x[0];
    a+=y[1];
    a+=z[2];
    cout<<a<<endl;
    


    
    

    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int N;
    cin >> N ;
    
    bool flag = true;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a%2==1){
            flag = false;
        }
    }
    if(flag) cout << "second" << endl;
    else  cout << "first"  << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long
#define rep0(i,j) for(int i=0; i<j; i++)
#define rep1(i,j) for(int i=1; i<=j; i++)
#define all(a) a.begin(), a.end()
using namespace std;

void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}

int main(){
    string s,t;
    int n;
    cin >> n >> s >> t;
    rep0(i,n)cout << s[i] << t[i];

}

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

int main() {
  int n;
  int A[21];
  int B[21];
  int C[21];

  int ans = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
     cin >> A[i];
  }
  for(int i = 0; i < n; i++) {
     cin >> B[i];
  }
  for(int i = 0; i < n-1; i++) {
     cin >> C[i];
  }

  for(int i = 0; i < n; i++) {
    ans += B[A[i]-1];

     int next = A[i] + 1;
     if(next == A[i+1]) {
       ans += C[A[i]-1];
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	/*
	各ビットについて，
	1の数×0の数を計算し，足し合わせる
	*/
	// cin.tie(0);
	// ios::sync_with_stdio(false);

	long long result = 0;
	int N;
	scanf("%d", &N);

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

	for (long long i = 0; i < 60; i++) {
		/* 2^i 桁について */
		long long i_2 = (long long)1 << i;
		long long num_1 = 0;
		long long num_2 = 0;
		for (int j = 0; j < N; j++) {
			if (A[j] & i_2) {
				num_1++;
			} else {
				num_2++;
			}
		}
		// cout << i_2 << " " << num_1 << " " << num_2 << "\n";
		result = (result + ((i_2 % (long long)1000000007) *
		                    ((num_1 * num_2) % (long long)1000000007)) %
		                       (long long)1000000007);
		// cout << result << "\n";
	}

	printf("%lld", result % (long long)1000000007);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	string S;
	cin >> S;

	int A[10];
	rep(i, S.size()) {
		A[i] = S[S.size() - i - 1] - '0';
	}

	int kumi = 1 << (S.size() - 1);
	ll goukei = 0;
	rep(i, kumi) {
		ll bai = 10;
		goukei += A[0];
		rep(ii, S.size() - 1) {
			if (i >> ii & 1) {
				goukei += bai * A[ii + 1];
				bai *= 10;
			}
			else {
				goukei += A[ii + 1];
				bai = 10;
			}
		}
	}
	co(goukei);

	Would you please return 0;
}

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

using namespace std;

static const int N = 1000;

int lcs (string x, string y) {
    int m = x.size();
    int n = y.size();
    int maxl = 0;
    int c[N + 1][N + 1] ;
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int j = 1; j <= n; j++) {
        c[0][j] = 0;
    }
    
    for (int i = 1; i <= m; i ++ ) {
        for (int j = 1; j <= n; j++) {
            if (x[i] == y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    
return maxl;
    
}

int main () {
    int n ;
    cin >> n;
    string str1, str2;
    for (int i = 0; i < n; i++) {
        cin>>str1>>str2;
    
        cout << lcs(str1, str2) <<endl;
    }
    
    
    
    return 0;
}





Measured memory_bytes: 6976
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize, k: usize,
        mut h_vec: [usize; n],
    }

    h_vec.sort();

    let mut ans = INF;
    for i in 0..n-k+1 {
        // dbg!(&h_vec[i+k-1], &h_vec[i]);
        ans = std::cmp::min(ans, h_vec[i+k-1] - h_vec[i])
    }
    

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

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

using namespace std;
// 0.001
main() {
  double d;
  cin >> d;
  double maxi = d;
  maxi = max(maxi,sqrt(2.0)*d);
  for(double x=1;x<=10;x++) {
    if( x <= d ) {
      double y = max(1.0,sqrt(d*d-x*x));
      maxi = max(maxi,x+y);
    }
  }
  printf("%.10f\n",maxi);
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define loop(i,a,b) for(int i=a; i<b; i++)
#define inf 1e9+1
#define mod 1000000007

struct item{
    int wt;
    int val;
};

int solve(vector<item> arr, int n, int w)
{
    int maxVal= n*1000;
    ll dp[n+1][maxVal+1];

    for(int val=0; val<=maxVal; val++) dp[1][val]= inf;
    dp[1][0]=0;
    dp[1][arr[1].val]= arr[1].wt;
    for(int i=2; i<=n; i++){
        for(int v=0; v<=maxVal; v++){
            dp[i][v]= dp[i-1][v];
            if(arr[i].val > v)
                continue;
            dp[i][v]= min(dp[i][v], arr[i].wt+ dp[i-1][v-arr[i].val]);
        }
    }
    int ans=0;
    for(int x=0; x<=maxVal; x++){
        if(dp[n][x]<=w)
            ans= x;
    }
    return ans;
}

int main()
{
    FASTIO;
    int n,w;
    cin>>n>>w;
    vector<item> arr(n+1);
    for(int i=1; i<=n; i++){
        cin>>arr[i].wt;
        cin>>arr[i].val;
    }
    cout<<solve(arr, n, w);
    return 0;
}




Measured memory_bytes: 81756
#include<iostream>
using ll = long long;

int main() {
    using namespace std;
    int n;
    cin >> n;
    ll sum = 0LL;
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0) sum+=i;
    }
    cout << sum <<endl;
    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  vector<int> ans(N,0);

  for (int i =0 ; i < M ; i++){
    cin >> a.at(i);
    cin >> b.at(i);
  }
  //ここまで入力
  

  for (int i = 0; i <N; i++){
      for (int j =0; j < M; j++){
          if(a.at(j)==i+1){
              ans.at(i)++;
          }
          if(b.at(j)==i+1){
              ans.at(i)++;
          }
      }
      cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 3604
// C - 100 to 105
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int X; cin>>X;
	vvi dp(6+1, vi(X+1));
	rp(i, 1, 6+1){
		int y = 99 + i;
		rp(j, y, X+1) dp[i][j] = max(dp[i][j-y]+y, dp[i-1][j-y]+y);
	}
	rp(i, 1, dp.size()) if(dp[i][X] == X){ puts("1"); return 0; }
	puts("0");
}

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

//街を表すクラスを定義しておくとはかどります
//成立年順でソートしたいので, そのように順序付けしておくと better
class City implements Comparable<City>{
	int year;
	int pref;
	int totalID;
	public City(int year, int pref, int totalID){
		this.year = year;
		this.pref = pref;
		this.totalID = totalID;
	}
	public int getYear(){return year;}
	public int getPref(){return pref;}
	public int getTotalID(){return totalID;}
	public int compareTo(City another){
		if(this.getYear()==another.getYear()) return this.getPref()-another.getPref();
		else return this.getYear() - another.getYear();
	}
	
	public String toString(){
		return "<year:"+year+", pref:"+pref+">";	}
}

public class Main {
    //整数を6桁で表す変換
    public static String to6digit(String s){
    	while(s.length()<6) s="0"+s;
    	return s;
    }
    public static String to6digit(int n){
    	return to6digit(Integer.toString(n));
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        City[] allCity = new City[M];
        //M個の市について情報を入力
        for(int m=0;m<M;m++){
        	int p = sc.nextInt();
        	int y = sc.nextInt();
        	allCity[m] = new City(y, p, m);
        }
        Arrays.sort(allCity);
        
        int[] oldCityNum = new int[N+1];//これまでに確認されたn県の市.
        //oldCityNum[N]を使いたいのでindexを余分にとった. [0]は使わない
        
        Arrays.fill(oldCityNum,0); //とりああえず0で初期化.
        String[] ans = new String[M];
        for(int m=0;m<M;m++){ //市を古い方から確認していく
        	City c = allCity[m];
        	int pref = c.getPref();
        	//"何県にあるか"と"同じ県でここより古い市の数"が分かるので,認識番号を求められる
        	ans[c.getTotalID()] = to6digit(pref) + to6digit(1+oldCityNum[pref]);
        	oldCityNum[pref]++;
        }
        for(int m=0;m<M;m++) System.out.println(ans[m]);
    }
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        LL a,b;
        cin >> a >> b;
        
        if (a == b) {
            cout << a*2-2 << endl;
            continue;
        }
        if (abs(a-b) == 1) {
            cout << min(a,b)*2-2 << endl;
            continue;
        }
        LL c = ceill(sqrt(a*b)) - 1;
        if (c*(c+1) < a*b) {
            cout << 2*c - 1 << endl;
            continue;
        }
        cout << 2*c - 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,q,i,num1=0,b[100000],k=0;
    char a[100000];
    scanf("%d%d",&n,&q);getchar();
    for(i=0;i<n;i++)
        {scanf("%c",&a[i]);
        if(a[i]=='C'&&a[i-1]=='A')
            num1++;
        b[k++]=num1;
        }
    while(q--)
    {
        int x,y,num;
        scanf("%d%d",&x,&y);
            num=b[y-1]-b[x-1];
        printf("%d\n",num);
    }
    return 0;
}


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

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

    int ma = 0;
    int count = 0;
    rep(i, s.size()){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            count++;
            ma = max(ma, count);
        }else{
            count = 0;
        }
    }

    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 256
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    vector<ll> a(n,0);
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    
    if(a[0] == 0)
    {
        cout<<0<<endl;
        return 0;
    }

    ll ans = 1, old = 1;

    for(ll i=0; i<n; i++)
    {
        ans *= a[i];
        if(ans > (ll)1e18 || ans<old)
        {
            cout<<-1<<endl;
            return 0;
        } 
        old = ans;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3992
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	
	int ans = 0;
	for(int i = 0; i <= a; i++)
	{
		for(int j = 0; j <= b; j++)
		{
			for(int k = 0; k <= c; k++)
			{
				if(i*500 + j*100 + k*50 == x)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    string s;
    cin>>s;
    bool ok = false;
    for (int i = 1; i < 4;i++){
        if(s[i]==s[i-1])
            ok = true;
    }
    if(ok){
        cout << "Bad" << endl;
    }
    else
        cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <array>
using i64 = long long;
using namespace std;


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

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

int main(){
  int k;
  char str[200], copy[200]={0};
  scanf("%d",&k);
  scanf("%s",str);
  if(strlen(str)>k){
    printf("%s...\n",memcpy(copy,str,k));
  }else {
    printf("%s\n",str);
  }
  return 0;
}

Measured memory_bytes: 1708
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double sum = 0d;
        for (int i = 0; i < n; i++) {
            sum += 1 / sc.nextDouble();
        }
        System.out.println(1 / sum);
        sc.close();
    }
}


Measured memory_bytes: 23252
using System;
namespace ITP1_5_A_2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string str = Console.ReadLine();
                string[] parseStr = str.Split((char[])null);
                int H, W;
                H = int.Parse(parseStr[0]);
                W = int.Parse(parseStr[1]);
                if (H == 0 && W == 0)
                    Environment.Exit(0);

                string[,] square = new string[H, W];

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 16280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int> arr(n);
    for(auto &x:arr)
        cin>>x;
    int ans=0;
    for(int i=1; i<n-1; i++)
    {
        set<int> s;
        s.insert(arr[i-1]);
        s.insert(arr[i]);
        s.insert(arr[i+1]);
        auto it=s.begin();
        it++;
        if(*it==arr[i])
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a,b,c,ans;
  
  if(scanf("%d %d %d", &a,&b,&c) == EOF)
  {
    return 0;
  }
  
  ans = (a*b)/2;
  
  printf("%d\n",ans);
  
  return 0;
}

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

int main(){
	int n, debt=100000;
	cin >> n;
	for(int i=0 ; i<n ; i++){
		debt*=1.05; //1555%1000=555
		if(debt%1000!=0) {
			debt-=debt%1000;
			debt+=1000;
		}
	}
	cout << debt << endl;
	return 0;
}

Measured memory_bytes: 1160
//In the name of Allah
#include <bits/stdc++.h>
using namespace std; 

int main() { 
	long long ans = 0; 
	int rem = 0; 
	int n; cin >> n;
	for( int i = 0 ; i < n ; i++ ) { 
		int x = 0; 
		cin >> x; 
		ans += (rem + x) / 2; 
		if( (rem + x) % 2 == 1 && x ) 
			rem = 1; 
		else
			rem = 0; 
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

ll a[100000];
ll c[100000];
ll abc[100000];
ll modExp2[100001];
ll modExp3[100001];
ll numABC;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  rep(i, N){
    switch(S[i]){
      case 'A':
        a[i]++;
        break;
      case 'B':
        break;
      case 'C':
        c[i]++;
        break;
      case '?':
        abc[i]++;
        break;
    }
  }
  modExp2[0] = 1;
  modExp3[0] = 1;
  rep(i, 1, N + 1){
    modExp2[i] = modExp2[i - 1] * 2;
    modExp2[i] %= MOD;
    modExp3[i] = modExp3[i - 1] * 3;
    modExp3[i] %= MOD;
  }
  rep(i, 1, N){
    a[i] += a[i - 1];
    c[i] += c[i - 1];
    abc[i] += abc[i - 1];
  }
  numABC = abc[N - 1];
  ll ans = 0;
  rep(i, 1, N - 1){
    if(S[i] == 'B'){
      ans += a[i - 1] * (c[N - 1] - c[i]) * modExp3[numABC];
      ans %= MOD;
      ans += a[i - 1] * (abc[N - 1] - abc[i]) * modExp3[numABC - 1];
      ans %= MOD;
      ans += abc[i - 1] * (c[N - 1] - c[i]) * modExp3[numABC - 1];
      ans %= MOD;
      ans += abc[i - 1] * (abc[N - 1] - abc[i]) * modExp3[numABC - 2];
      ans %= MOD;
    }else if(S[i] == '?'){
      ans += a[i - 1] * (c[N - 1] - c[i]) * modExp3[numABC - 1];
      ans %= MOD;
      ans += a[i - 1] * (abc[N - 1] - abc[i]) * modExp3[numABC - 2];
      ans %= MOD;
      ans += abc[i - 1] * (c[N - 1] - c[i]) * modExp3[numABC - 2];
      ans %= MOD;
      ans += abc[i - 1] * (abc[N - 1] - abc[i]) * modExp3[numABC - 3];
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vc<char> a(n);
    int r = 0;
    rep(i,n){
        cin >> a[i];
        if(a[i] == 'R') r++;
    }
    int ans = 0;
    rep(i,r){
        if(a[i] == 'W') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{
    int N; cin >> N;
    map<string, int> map;
    rep (i, 0, N) {
        string in; cin >> in;
        ++map[in];
    }

    int max_v = 0;
    vector<pair<string, int>> vec;
    vec.reserve(map.size());
    for (auto& mp : map) {
        vec.emplace_back(mp.first, mp.second);
        max_v = max(max_v, mp.second);
    }

    sort(vec.begin(), vec.end(), [&vec](pair<string, int> &p1, pair<string, int> &p2) {
        if (p1.second != p2.second) return p1.second > p2.second;
        else return p1.first < p2.first;
    });

    for (auto v : vec) {
        if (v.second == max_v) {
            cout << v.first << endl;
        }
    }
}

Measured memory_bytes: 28288
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MOD 998244353
#define MAX 1005

ll M,N,K;
ll fact[MAX];
ll nCm[MAX][MAX];
ll memo[MAX];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}


int main(){

	scanf("%lld %lld %lld",&M,&N,&K);

	if(K > M){

		printf("0\n");
		return 0;
	}

	fact[0] = 1;
	for(ll i = 1; i <= K; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}

	//コンビネーションを求める
	nCm[0][0] = 1;
	for(ll n = 1; n <= K; n++) {
		for (int m = 0; m <= K; m++) {
			if(m > 0){
				nCm[n][m] = nCm[n-1][m]+nCm[n-1][m-1];
			}else{ //m == 0
				nCm[n][m] = 1;
			}
			nCm[n][m] %= MOD;
		}
	}

	memo[1] = 1;

	for(ll i = 2; i <= K; i++){

		ll num = mod_pow(i,N,MOD);

		for(int k = 1; k <= i-1; k++){

			num -= nCm[i][k]*memo[k];
			if(num < 0){
				num += MOD;
			}
			num %= MOD;
		}

		memo[i] = num;
	}

	ll ans = mod_pow((M%MOD),N,MOD);

	ll mult = 1;

	for(int i = 1; i <= K-1; i++){

		mult *= (M-(i-1))%MOD;
		mult %= MOD;

		ll tmp = mult*mod_inverse(fact[i],MOD);
		tmp %= MOD;

		tmp *= memo[i];
		tmp %= MOD;

		ans -= tmp;
		if(ans < 0){

			ans += MOD;
		}
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 10972
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,a[100005],mx,res=-1e9;
int main(void){
	register int i;
	n=read();
	for(i=1;i<=n;++i)a[i]=read(),mx=max(mx,a[i]);
	for(i=1;i<=n;++i)if(a[i]!=mx&&abs(res-(mx+1)/2)>abs(a[i]-(mx+1)/2))res=a[i];
	printf("%d %d\n",mx,res);
	return 0;
}

Measured memory_bytes: 640
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let n = input
        .split_whitespace()
        .nth(0)
        .unwrap()
        .parse::<usize>()
        .unwrap();

    let goal = n - 1;

    let list = input
        .split("\n")
        .skip(1)
        .flat_map(|x| {
            let l = x.split_whitespace()
                .map(|x| x.parse::<usize>().unwrap() - 1)
                .collect::<Vec<_>>();
            vec![(l[0], l[1]), (l[1], l[0])]
        })
        .collect::<Vec<_>>();

    let mut nodes = Vec::new();
    for _ in 0..n {
        nodes.push(vec![]);
    }

    for (a, b) in list.into_iter() {
        nodes[a].push(b);
    }

    for &route in &nodes[0] {
        if route == goal {
            return "POSSIBLE".to_string();
        }

        for &route2 in &nodes[route] {
            if route2 == goal {
                return "POSSIBLE".to_string();
            }
        }
    }

    "IMPOSSIBLE".to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "3 2
1 2
2 3" => "POSSIBLE",
    test2: "4 3
1 2
2 3
3 4" => "IMPOSSIBLE",
    test3: "100000 1
1 99999" => "IMPOSSIBLE",
    test4: "5 5
1 3
4 5
2 3
2 4
1 4" => "POSSIBLE",
}


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

ll mod = 1e9 + 7;

vector<int> primes;
const int sieve_size = 1000;
vector<bool> sieve(sieve_size + 1, true);
void prime_sieve() {
  sieve[0] = false;
  sieve[1] = false;
  for (int i = 2; i <= sieve_size; i++) {
    if (!sieve[i])
      continue;
    primes.push_back(i);
    for (int j = i * i; j <= sieve_size; j += i)
      sieve[j] = false;
  }
}

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

  prime_sieve();

  vector<int> v(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    int n = i;
    for (auto p : primes) {
      while (n % p == 0) {
        v[p]++;
        n /= p;
      }
      if (p > i)
        break;
    }
  }

  ll ans = 1;
  rep(i, N + 1) {
    if (v[i] != 0) {
      ans *= v[i] + 1;
      ans %= mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
 
int main(){
     string n;
     cin >> n;
 
     for(int i = 0; i < n.size(); i++){ 
          if(n.at(i) == '1') n.at(i) = '9';
          else if(n.at(i) == '9') n.at(i) = '1';
     }
 
cout << n << endl; 
}

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

#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string a, b, c; cin >> a >> b >> c;
  cout << char(a[0] - 32) << char(b[0] - 32) << char(c[0] - 32) << endl;
  
  return (0);
}

Measured memory_bytes: 3652
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

from collections import deque

def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    #グラフの作成
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
#    print(graph)
    #幅優先探索
    q = deque()
    q.append(0)
    seen = [-1]*N
    seen[0] = 0
    while len(q)>0:
        cur = q.popleft()
        lvl = seen[cur]
        for i in graph[cur]:
            if seen[i]==-1:
                #階層
                #seen[i] = lvl + 1
                #親
                seen[i] = cur
                q.append(i)
#    print(seen)
    if min(seen)==-1:
        print('No')
    else:
        print('Yes')
        for i in seen[1:]:
            print(i+1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 35076