akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

int x[11]{1}, ans, n, m, q, a[51], b[51], c[51], d[51];

void judge() {
    int sum = 0;
    Rep(i, q) if(x[b[i]] - x[a[i]] == c[i]) sum += d[i];
    ans = max(ans, sum);
}

void dfs(int k) {
    if(k == 11) {
        judge();
        return;
    }
    for(int i = x[k-1]; i <= m; ++i) {
        x[k] = i;
        dfs(k+1);
    }
}

int main()
{
    cin >> n >> m >> q;
    Rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(1);
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<bool> ac(n + 1);
	vector<int> count_wa(n + 1);
	int penalties = 0, cnt_ac = 0;
	for(int i = 0; i < m; ++i) {
		int id;
		string type;
		cin >> id >> type;
		if(type == "AC") {
			if(!ac[id]) {
				penalties += count_wa[id];
				ac[id] = true;
				++cnt_ac;
			}
		}
		else {
			count_wa[id]++;
		}
	}
	cout << cnt_ac << " " << penalties << endl;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(){
    long long int h;
    if (scanf("%lld", &h) != 1) return 0;

    long long int result = 0;
    for (long long int i = 0; h > 0; i++) {
        long long int pow = 1;
        for (long long int j = 0; j < i; j++){
            pow *= 2;
        }
        result += pow;
        h /= 2;
    }

    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 128
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    ans <- show . length . group . sort . words <$> getLine
    -- 出力
    putStrLn ans


Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

ll N, K;
vector<double> m(100010, -1);

double solve(ll p) {
    if (p >= K)return 1;
    if (m[p] != -1)return m[p];
    return m[p] = solve(p * 2) / 2;
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += solve(i);
    }
    ans /= N;
    cout << ans << endl;
}

Measured memory_bytes: 1024
while ( s = gets ) && ( n = s.to_i ) >= 0 do p ->() {
    res = 0
    10.times { |a|
        10.times { |b|
            10.times { |c|
                10.times { |d|
                    res += ( a + b + c + d == n ? 1 : 0 )
                }
            }
        }
    }
    res
}.call end

Measured memory_bytes: 6104
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		long MOD=1000000007L;

		Scanner sc = new Scanner(System.in);

		int h=sc.nextInt();
		int w=sc.nextInt();

		String s[]=new String[h];
		char c[][]=new char[h][w];

		for(int i=0;i<h;++i){
			s[i]=sc.next();
			c[i]=s[i].toCharArray();
		}

		int L[][]=new int[h][w];
		int R[][]=new int[h][w];
		int U[][]=new int[h][w];
		int D[][]=new int[h][w];


		for(int i=0;i<h;++i){
			if(c[i][0]=='.')L[i][0]=1;
			else L[i][0]=0;
			for(int j=1;j<w;++j){
				if(c[i][j]=='.')L[i][j]=L[i][j-1]+1;
				else L[i][j]=0;
			}
			if(c[i][w-1]=='.')R[i][w-1]=1;
			else R[i][w-1]=0;
			for(int j=w-2;j>=0;--j){
				if(c[i][j]=='.')R[i][j]=R[i][j+1]+1;
				else R[i][j]=0;
			}
		}

		for(int i=0;i<w;++i){
			if(c[0][i]=='.')U[0][i]=1;
			else U[0][i]=0;
			for(int j=1;j<h;++j){
				if(c[j][i]=='.')U[j][i]=U[j-1][i]+1;
				else U[j][i]=0;
			}
			if(c[h-1][i]=='.')D[h-1][i]=1;
			else D[h-1][i]=0;
			for(int j=h-2;j>=0;--j){
				if(c[j][i]=='.')D[j][i]=D[j+1][i]+1;
				else D[j][i]=0;
			}
		}
		long ans=0;
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				ans=Math.max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3);

			}
		}
		System.out.println(ans);
	}
}

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) >= 'a' && s.at(0) <= 'z') {
    cout << "a" << endl;
  }
  else {
    cout << "A" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, Ans = 0, i, j, A, B;
cc judge1 = 0, judge2 = 0, judge3 = 0;

string S;


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

	judge1 = N * A;

	if (judge1 > B)
		Ans = B;
	else
		Ans = judge1;
		cout << Ans << endl;
		
		return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s.at(0) != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int n = s.size();
  int count = 0;
  for(int i=2; i<n-1; i++) {
    if(s.at(i) == 'C') {
      count++;
    } else if(isupper(s.at(i))) {
      cout << "WA" << endl;
      return 0;
    }
  }
  if(isupper(s.at(1)) || isupper(s.at(n-1))) {
    cout << "WA" << endl;
    return 0;
  }
  if(count == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
int main(){
  int x,cnt=0;

  while(scanf("%d",&x)!=-1){
    if(isprime(x)==1){
      cnt++;
    }
  }

  printf("%d\n",cnt);

  return 0;
}


int isprime(int x){
  int i;

  //2 is prime number
  if(x==2) return 1;

  //odd-numbers is not prime number;
  if(x<2 || (x%2)==0) return 0;

  i = 3;
  while(i<=sqrt(x)){
    if((x%i)==0) return 0;

    i = i + 2;
  }

  return 1;
}

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

using namespace std;
const int MOD=2019;
#define ll long long

int main()
{
   int k;
   cin>>k;
   ll ans=0;
   for (int i=1;i<=k;i++)
    for (int j=1;j<=k;j++)
    for (int h=1;h<=k;h++)
    ans+=__gcd(__gcd(i,j),h);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

using E = pair<int, int>;  // to, weight

int main() {
  int L;
  while (cin >> L) {
    const int N = 20;
    vec<E, 2> G(N);
    int p = 0, geta = 0;
    for (int i = 0; i < 30; i++) {
      if ((L >> i) & 1) {
        int add = geta;
        while (p < i) {
          G[p].push_back(E(p + 1, add + 0));
          G[p].push_back(E(p + 1, add + (1 << p)));
          add = 0;
          ++p;
        }
        if (p != N - 1) {
          G[p].push_back(E(N - 1, 0));
        }
        geta = 1 << i;
      }
    }
    int M = 0;
    for (int i = 0; i < N; i++) M += G[i].size();
    cout << N << " " << M << endl;
    for (int i = 0; i < N; i++) {
      for (auto e : G[i]) {
        int j = e.fst;
        int w = e.snd;
        cout << (i + 1) << " " << (j + 1) << " " << w << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc074/tasks/arc083_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    int n;
    cin >> n;
    vector<vector<int>> d(n, vector<int>(n));
    vector<bitset<300>> b(n);

    REP(i, n) REP(j, n) cin >> d[i][j];
    REP(k, n) REP(i, n) {
        if (k == i)
            continue;
        REP(j, n) {
            if (k == j)
                continue;
            // 3辺の一番長い辺が、それ以外の辺の合計より大きければ不成立
            if (d[i][j] > d[i][k] + d[k][j]) {
                cout << "-1\n";
                return 0;
            }
            // 等しければ辺を作らない
            if (d[i][j] == d[i][k] + d[k][j]) {
                b[i][j] = true;
            }
        }
    }
    ll ans = 0;
    REP(i, n) FOR(j, i + 1, n) {
        if (!b[i][j]) {
            ans += d[i][j];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define f(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
ll n;
ll a[10000];

ll dp[3100][3100];
ll find(ll i,ll j){
if(i>j){
  return 0;
 }
if(dp[i][j]!=-1){
  return dp[i][j];
}
ll c1=a[i]+min(find(i+1,j-1),find(i+2,j));
ll c2=a[j]+min(find(i+1,j-1),find(i,j-2));
return dp[i][j]=max(c1,c2);
}
int main(){
cin>>n;
ll sum=0;
f(i,0,n){
  cin>>a[i];
  sum+=a[i];
}
f(i,0,n+2){
  f(j,0,n+2){
    dp[i][j]=-1;
  }
}
cout<<2*find(0,n-1)-(sum);

}

Measured memory_bytes: 74112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;

int n, m;
int g[50][50] = {};

void dfs(vector<bool> &visit, int num){
    if(visit[num]){
        return;
    }

    visit[num] = true;
    rep(i, n){
        if(g[num][i] == 1){
            dfs(visit, i);
        }
    }
}

void bfs(vector<bool> &visit, int num){
    if(visit[num]){
        return;
    }

    visit[num] = true;
    rep(i, n){
        if(g[i][num] == 1){
            bfs(visit, i);
        }
    }
}

int main() {

    cin >> n >> m;

    int a[50], b[50];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }

    int ans = 0;
    rep(i, m){
        vector<bool> visit(n, false);
        
        g[a[i]][b[i]] = g[b[i]][a[i]] = 0;
        bfs(visit, 0);

        rep(k, n){
            if(!visit[k]){
                ans++;
                break;
            }
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

           int H = sc.nextInt();
           int W = sc.nextInt();
        
           if(H == 0 && W == 0) break;

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



Measured memory_bytes: 38488
from math import factorial

n, m = map(int, input().split())
if n == m:
    ans = factorial(n) % (10 ** 9 + 7)
    ans = ans ** 2 % (10 ** 9 + 7)
    print(ans * 2 % (10 ** 9 + 7))
elif abs(n - m) == 1:
    ans1 = factorial(n) % (10 ** 9 + 7)
    ans2 = factorial(m) % (10 ** 9 + 7)
    print(ans1 * ans2 % (10 ** 9 + 7))
else:
    print(0)

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    int ans = 1, m = 0;
    FOR(i, 1, n + 1) {
        int t = i;
        int s = 0;
        while (t % 2 == 0) {
            s++;
            t /= 2;
        }
        if (m < s) { 
            ans = i;
            m = s;
        }
    }
    cout << ans << endl;
}


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

int main() {
	int n;
	int m;
	
	cin >> n;
	
	int maxv = -2000000000;
	int minv = 2000000000;
	
	for (int i = 0; i < n; i++) {
		cin >> m;
		maxv = max(maxv, m - minv);
		minv = min(minv, m);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#[allow(unused_imports)]
use std::io::{self, BufRead};
#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(dead_code)]
fn readln_to_vec<T>(buf: &mut BufRead) -> Vec<T> 
where T: std::str::FromStr,
      <T as std::str::FromStr>::Err: std::fmt::Debug
{
    let mut s = String::new();
    buf.read_line(&mut s).unwrap();
    s.split(" ")
        .map(|x| x.trim())
        .filter(|x| !x.is_empty())
        .filter_map(|x| x.parse().ok())
        .collect()
}

#[allow(dead_code)]
fn readln_to<T>(buf: &mut BufRead) -> T
where T: std::str::FromStr + std::clone::Clone,
      <T as std::str::FromStr>::Err: std::fmt::Debug
{
    readln_to_vec::<T>(buf)[0].clone()
}

#[allow(unused_macros)]
macro_rules! readln_to_tuple {
    (
        $bufRead: expr, ( $( $t: ty ),* )
    ) => (
        {
            let buf: &mut BufRead = $bufRead;
            let ln = readln_to_vec::<String>(buf);
            let mut i = ln.into_iter();
            ( $( i.next().unwrap().parse::<$t>().unwrap() ),* )
        }
        )
}


fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;

    let a: String = readln_to(stdin);
    let a = a.as_bytes();
    let mut c = [0; 26];
    let mut ans = 1;
    for i in 0..a.len() {
        ans += i - c[a[i] as usize -'a' as usize];
        c[a[i] as usize - 'a' as usize] += 1;
    }
    println!("{}", ans);
}





Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

vector<int> comb(int N, int mod, int b) {
  N++;
  bitset<30> modbit = mod-2;
  vector<int> comb(b+3, 1);
  rep(i, b+2) {
    comb[i+1] = (comb[i]*(N-1-i))%mod;
    int x = i+1;
    rep(j, 30) {
      if(j > 0) x *= x;
      x %= mod;
      if(modbit.test(j)) {
        comb[i+1] *= x;
        comb[i+1] %= mod;
      }
    }
  }
  return comb;
}

int power(int n, int N, int mod) {
  if(N == 0) return 1;
  if(N == 1) return n;
  int a = power(n, N/2, mod);
  if(N%2 == 0) return (a*a)%mod;
  else return (a*a*n)%mod;
}

signed main() {
  int n, a, b; cin >> n >> a >> b;
  const int mod = 1000000007;
  
  if(n == 2) {
    if(a == 1 && b == 1) cout << 1 << endl;
    else if(a == 2 && b == 2) cout << 2 << endl;
    else cout << 0 << endl;
    return 0;
  }
  
  int ans = power(2, n, mod);
  vector<int> c = comb(n, mod, b);
  
  cout << ((ans-1-c[a]-c[b])%mod+mod)%mod << endl;
    
  
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	
	int n;
	cin >>n;
	bool f = false;
	ffor(i,1, 10) {
		ffor(j,1,10) {
			if (n == i * j) {
				f = true;
				break;
			}
		}
	}
	string s= f ? "Yes" : "No";
	c(s);

	ed;
	return 0;
}



Measured memory_bytes: 256
X,Y=map(int,input().split())
MOD = 1000000007

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res




if 2*X-Y>=0 and (2*X-Y)%3==0 and 2*Y-X>=0 and (2*Y-X)%3==0:
    n = (2*X-Y)//3
    m = (2*Y-X)//3
    res=combination(n+m,n,MOD)
    print(res)

else:print(0)

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

void selectionSort(int *,int);
int cnt=0;

int main(){
  int i,n,array[100];
  scanf("%d",&n);
  if(n<1 || n>100) exit(2);
  for(i=0;i<n;i++){
    scanf("%d",&array[i]);
  }
  selectionSort(array,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",array[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}

void selectionSort(int *arr,int n){
  int i,j,tmp,min;
  for(i=0;i<n-1;i++){
    min=i;
    for(j=n-1;j>i;j--){
      if(arr[min] >= arr[j]) min=j;
    }
    if(arr[min]!=arr[i]){
      tmp=arr[min];
      arr[min]=arr[i];
      arr[i]=tmp;
      cnt++;
    }
  }
}



Measured memory_bytes: 2044
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//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())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
	string A,B;
	cin >> A >> B;
	if(SZ(A)>SZ(B)){
		cout << "GREATER" << endl;
		return 0;
	}
	else if(SZ(A)<SZ(B)){
		cout << "LESS" << endl;	
		return 0;
	}
	else{
		REP(i,SZ(A)){
			if(A[i]>B[i]){
				cout << "GREATER" << endl;
				return 0;
			}
			else if(A[i]<B[i]){
				cout << "LESS" << endl;
				return 0;
			}
		}
	}
	cout << "EQUAL" << endl;
	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 main() {
  string s;
  cin >> s;

  vector<int> up(s.size() + 1, 0);
  rep(i, s.size()) {
    if (s[i] == '<') {
      if (i == 0 || s[i - 1] == '>') {
        up[i] = 0;
      }
      up[i + 1] = up[i] + 1;
    }
  }

  vector<int> down(s.size() + 1, 0);
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == '>') {
      if (i == s.size() - 1 || s[i + 1] == '<') {
        down[i + 1] = 0;
      }
      down[i] = down[i + 1] + 1;
    }
  }
  vector<int> ss(s.size() + 1, 0);
  for (int i = 0; i < ss.size(); i++) {
    ss[i] = max(up[i], down[i]);
  }
  ll res = 0;
  rep(i, ss.size()) {
    res += ss[i];
  }
  cout << res << endl;
  return 0;
}


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

int main()
{
	int x,y;
   cin >> x >> y;
   for(int i = 0;i<=x;i++)
   {
      if(i*2+(x-i)*4==y)
      {
         cout<<"Yes"<<endl;
         return 0;
      }
   }
   cout<<"No"<<endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++) scanf("%d", &A[i]);
    sort(A.begin(), A.end());
    
    for(int i=0;i<N;i++){
        if(i) printf(" ");
        printf("%d", A[i]);
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 10668
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
  rtn 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int o,f=0;
  long n,t;
  scanf("%ld",&n);
  t=n;
  while (t){
    o=t%10;
    f+=o;
    t=(t-o)/10;
  }
  printf("%s\n",(n%f)? "No":"Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  string result = "No";
  for (int i=0; i*4<=N; i++) if ((N-i*4)%7==0) result = "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) if((int)(1.08*i)==n){
		cout<<i<<endl;
		return 0;
	}
	cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;
  long all;
  all = 0;
  
for (int i = 1; i < N+1; i++) {
    if(i % 3 != 0 && i % 5 != 0){
        all = all + i;
    }
  }

  cout << all << endl; 
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	vl v(1e7+10,1);
	ll n; cin>>n;
	rep(i,2,n+1){
		ll k=i;
		while(k<=n){
			v[k]++;
			k+=i;
		}
	}
	ll ans=0;
	rep(i,1,n+1){
		ans+=(i*v[i]);
	}
	cout<<ans<<endl;
	
	return 0;
}

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

int main()
{

  bool card[4][13];
  int n;

  int num; char c;

  for(int i=0; i<4; i++)
    for(int j=0; j<13; j++)
      card [i][j]=false;

  cin >> n;

  for(int i=0; i<n; i++){
    cin >> c >> num;

    if(c=='S')
      card[0][num-1] = true;
    else if(c=='H')
      card[1][num-1] = true;
    else if(c=='C')
      card[2][num-1] = true;
    else
      card[3][num-1] = true;

  }


  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      if(card[i][j]==false){

	if(i==0)  cout << "S " << j+1 << endl;
	
	else if(i==1)  cout << "H " << j+1 << endl;

	else if(i==2)  cout << "C " << j+1 << endl;

	else           cout << "D " << j+1 << endl;

      }
    }
  }


  return 0;
      
}

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

int main() {
  long double l;
  cin>>l;
  
  long double size=l/3;
  
  cout<< fixed << setprecision(10) <<size*size*size<<endl;

}

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

int main(void)
{
    char s[5];

    scanf("%s",s);
    // printf("%s",s);

    if (strcmp(s,"ABC")==0)
        printf("%s\n","ARC");
    else if (strcmp(s,"ARC")==0)
        printf("%s\n","ABC");

    return 0;
    

}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	char b; cin >> b;
	if (b=='A') b='T';
	else if (b=='T') b='A';
	else if (b=='C') b='G';
	else b='C';

	cout << b << endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std ;
int main () {

int x,y;
    char ope;
   cin>>x;
    cin>>ope;
     cin>>y;

    switch(ope)
    {
    case '+':
        cout<<x+y;
        break;

    case '-':
        cout<<x-y;
        break;
    }
 return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
   double x1, y1, x2, y2;
   double X, Y;
   scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
   X = pow((x2 - x1), 2);
   Y = pow((y2 - y1), 2);
   printf("%.8f\n", sqrt(X + Y));
   return 0;
}


Measured memory_bytes: 2044
N = int(input())
p = [int(i) for i in input().split()]

A = [0] * N
B = [0] * N

for i in range(1, N) :
    if p[i] > p[i-1] :
        A[p[i]-1] = A[p[i-1]-1] + N * (p[i] - p[i-1]) + 1
        B[p[i]-1] = B[p[i-1]-1] - N * (p[i] - p[i-1])
    else :
        A[p[i]-1] = A[p[i-1]-1] + N * (p[i] - p[i-1])
        B[p[i]-1] = B[p[i-1]-1] - N * (p[i] - p[i-1]) + 1

ma, mb = min(A), min(B)
for i in range(N) :
    A[i] = A[i] - ma + 1
    B[i] = B[i] - mb + 1
    
print(*A)
print(*B)

Measured memory_bytes: 46468
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#include<mutex>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));
int arr[20][20];
int brr[20][20];
int crr[20];
int fff(int n){
	int sum=0;
	while(n){
		sum+=n%2;
		n/=2;
	}
	return sum;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>crr[i];
		for(int j=0;j<crr[i];j++){
			cin>>arr[i][j]>>brr[i][j];
		}
	}
	int ans=0;
	for(int i=pow(2,n)-1;i>=0;i--){
		int c=1;
		for(int j=0;j<n;j++){
			if(!(i&(1<<j))){
				continue;
			}
			for(int z=0;z<crr[j];z++){
				if(((i>>(arr[j][z]-1))&1)^brr[j][z]){
					c=0;
					break;
				}	
			}
			if(!c) break; 
		}
		if(c){
			ans=max(ans,fff(i));
		}
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 888
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		if(a%2==0){
			System.out.println(a);
		}else {
			System.out.println(2*a);
		}

	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

int dsum(int x) {
    int s = 0;
    for (int i = x; i > 0; i /= 10) {
        s += i % 10;
    }

    return s;
}

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

    int N; cin >> N;

    int result = dsum(1) + dsum(N - 1);

    for (int A = 2; A <= N - 1; ++A) {
        result = min(result, dsum(A) + dsum(N - A));
    }

    cout << result << "\n";

    return 0;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
nT = 0
s1 = []
s2 = []
for i in range(Q):
  Query = input()
  if Query == "1":
    nT += 1
    continue
  T, F, C = Query.split()
  if (F == "1") ^ (nT%2 == 1):
    s1.append(C)
  else:
    s2.append(C)
#print(s1, s2)
r = "".join(reversed(s1))+S+"".join(s2)
if nT%2 == 1:
  r = "".join(reversed(r))
print(r)


Measured memory_bytes: 7300
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 1e5 + 100;
int a[N];
int dg[N];
int cnt[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i] );
        dg[i] = 1;
        cnt[i] = 0;
        while (2 * dg[i] <= a[i] )
        {
            cnt[i]++;
            dg[i] *= 2;
        }
        if (a[i] != dg[i] )
            cnt[i]++;
        eprintf("cnt[i] = %d\n", cnt[i]);
    }

    long long hasBorder = cnt[0];
    long long noBorder = cnt[0];

    for (int i = 0; i < n; i++)
    {
        int open = max(0, cnt[i + 1] - cnt[i] );
        if (cnt[i] > cnt[i + 1] )
        {
            hasBorder = min(hasBorder, noBorder);
        }
        eprintf("%d .. %d\n", cnt[i], cnt[i + 1] );
        eprintf("i = %d, hasB = %lld, noB = %lld\n", i, hasBorder, noBorder);

        long long nHB = hasBorder + open + 1;
        if (open != 0) nHB = hasBorder + open;
        long long nNB = hasBorder + open;
        nHB = min(nHB, noBorder + open + 1);
    
        hasBorder = nHB;
        noBorder = nNB;

        if (a[i + 1] == dg[i + 1] )
            hasBorder = min(hasBorder, noBorder);
    }

    long long ans = hasBorder;
    if (a[n - 1] == dg[n - 1] )
        ans = min(ans, noBorder);

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

	return 0;
}



Measured memory_bytes: 1408
# input
x, y, z, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = []
ab.extend([i+j for j in b for i in a])
ab.sort(reverse=True)

abc = []
abc.extend([i+j for j in ab[:k] for i in c])
abc.sort(reverse=True)

print('\n'.join(str(i) for i in abc[:k]))


Measured memory_bytes: 236112
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int h[3],ans[4]={0};
	bool check=true;
	while(cin>>h[0]>>h[1]>>h[2]){
		sort(h,h+3);
		if(h[2]>=h[1]+h[0])
			check=false;
		if(check==true){
			ans[0]++;
			if(h[0]*h[0]+h[1]*h[1]>h[2]*h[2])
				ans[2]++;
			if(h[0]*h[0]+h[1]*h[1]==h[2]*h[2])
				ans[1]++;
			if(h[0]*h[0]+h[1]*h[1]<h[2]*h[2])
				ans[3]++;
		}
	}
	for(int i=0;i<3;i++)
		cout<<ans[i]<<" ";
	cout<<ans[3]<<endl;
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	int a[6];
	for (int i = 0; i < 6; i++)cin >> a[i];
	cout << accumulate(a, a + 6, 0) - *min_element(a, a + 4) - *min_element(a + 4, a + 6) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;

int main(){
  int a,b;
  std::cin >> a>>b;
  if((a+b)%2==1)std::cout << "IMPOSSIBLE" << std::endl;
  else {
      std::cout <<  (a+b)/2<< std::endl;
  }
}

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

int main(){
    int p; //AB間
    int q; //BC間
    int r; //AC間

    cin >> p >> q >> r;

    int ans;
    if(min(p+q,q+r) > min(p+q,p+r)){
        ans = min(p+q,p+r);
    }else{
        ans = min(p+q,q+r);
    }

    cout << ans << endl;
}

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

#define ll long long
#define UN unsigned
#define pb push_back
#define mod 1000000007
#define mt make_tuple
#define f first
#define s second
typedef tuple<int, int> tii;
typedef pair<int, int> pii;

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

    int k;
    cin >> k;
    int n = s.length();
    
    vector< vector<int> > adj(26);
    for(int i=0; i<n; i++){
        adj[int(s[i])-97].pb(i);
    }

    vector<string> ans;

    for(int i=0; i<26; i++){
        for(auto& j: adj[i]){
            string tmp = "";
            for(int f=j; f<min(j+5, n); f++){
                tmp += s[f];
                if(find(ans.begin(), ans.end(), tmp) == ans.end())
                    ans.pb(tmp);
            }
        }    
        if((int)ans.size() >= k)
            break;
    }

    sort(ans.begin(), ans.end());
    cout << ans[k-1];
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 384
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 24/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n, k = iia()
arr = iia()
dp = [0] * n
for i in range(1, n):
    cur = float("inf")
    for j in range(1, k + 1):
        if i - j >= 0:  
            t = abs(arr[i] - arr[i - j]) + dp[i - j]
            cur = min(cur, t)
        else:
            break
    dp[i] = cur
print(dp[-1])


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

int main(){
    long long n;cin>>n;
    if(n==2){
        cout<<1<<endl;
    }
    else if(n==3){
        cout<<2<<endl;
    }
    else{
    long long ans=2;
    for(long long i=2;i*i<=n;++i){
        long long m=n;
        if(m%i==0){
            while(m%i==0){
                m/=i;
            }
            if(m%i==1)ans++;
        }
    }
    for(long long i=2;i*i<=n-1;++i){
        long long m=n-1;
        if(m%i==0){
            ans++;
            if(m/i!=i)ans++;
        }
    }
    cout<<ans<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int clamp(int x, int lb, int ub) {
    return max(lb, min(x, ub));
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> need(2, vector<int>(n, 1));
    vector<vector<int>> have(2, vector<int>(n));
    ll ans = 0;
    for(int i = 0; i < 2 * n; i++) {
        int x, y;
        cin >> x >> y;
        int nx = clamp(x, 1, n);
        int ny = clamp(y, 1, 2);
        ans += abs(x - nx) + abs(y - ny);
        have[ny - 1][nx - 1]++;
    }
    for(int x = 0; x < n; x++) {
        if(have[0][x] < need[0][x] and have[1][x] > need[1][x]) {
            int transfer = min(need[0][x] - have[0][x], have[1][x] - need[1][x]);
            ans += transfer;
            have[1][x] -= transfer;
            have[0][x] += transfer;
        }
        if(have[0][x] > need[0][x] and have[1][x] < need[1][x]) {
            int transfer = min(have[0][x] - need[0][x], need[1][x] - have[1][x]);
            ans += transfer;
            have[0][x] -= transfer;
            have[1][x] += transfer;
        }
        if(x < n - 1) {
            for(int y : {0, 1}) {
                if(have[y][x] < need[y][x]) {
                    ans += need[y][x] - have[y][x];
                    need[y][x + 1] += need[y][x] - have[y][x];
                }
                if(have[y][x] > need[y][x]) {
                    ans += have[y][x] - need[y][x];
                    have[y][x + 1] += have[y][x] - need[y][x];
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4880
#include<iostream>
using namespace std;
int main(){
  
  int N,M,masu[1000],dice[1000],counter,now;
  
  while(1){
    
    cin >>N>>M;

    if( N == 0 && M == 0)break;

    counter=0;
    now=1;
    
    for(int i=0 ; i < N ; i++)cin >>masu[i];
    for(int i=0 ; i < M ; i++)cin >>dice[i];

    for(int i=0 ; i < M ; i++){
      counter++;
      now+=dice[i];
      now+=masu[now-1];
      if(now >= N)break;
    } 
    
    cout <<counter<<endl;

  }
  
  return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  i64 Q;
  std::cin >> S >> Q;

  bool flipped = false;
  std::string head = "";
  std::string tail = "";
  for (i64 i = 0; i < Q; ++i) {
    i64 type;
    std::cin >> type;
    switch (type) {
    case 1:
      flipped = !flipped;
      break;

    case 2:
      {
        i64 F_i;
        char C_i;
        std::cin >> F_i >> C_i;

        if ((F_i == 2) == flipped) {
          head.push_back(C_i);
        } else if ((F_i == 1) == flipped) {
          tail.push_back(C_i);
        }
      }
      break;
    }
  }

  if (flipped) {
    std::reverse(tail.begin(), tail.end());
    std::reverse(S.begin(), S.end());
    std::cout << tail << S << head << std::endl;
  } else {
    std::reverse(head.begin(), head.end());
    std::cout << head << S << tail << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1088
#include<iostream>
#include<map>
using namespace std;
map<int,int>mp;
int main()
{	
	int a,b[100]={0},i=0,maxn=0;
	while(cin>>a)
	{
	    mp[a]++;
		if(mp[a]==1)
		{
			b[i]=a;
			
			i++;		
		}        	
		if(mp[a]>maxn)maxn=mp[a];
		
	}
	for(int j=0;j<i;j++)
	{
		if(mp[b[j]]==maxn)cout<<b[j]<<endl;
	}
	return 0;
} 


Measured memory_bytes: 3036
import java.util.*;

import static java.lang.System.*;

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

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int[] maxNum = new int[N];    //i番目より後の最大値

        maxNum[N - 1] = A[N - 1];
        for (int i = N - 2; i >= 0; i--) {
            maxNum[i] = Math.max(maxNum[i + 1], A[i]);
        }

        int maxDiff = 0;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (maxDiff == maxNum[i] - A[i]) {
                cnt++;
            } else if (maxDiff < maxNum[i] - A[i]) {
                maxDiff = maxNum[i] - A[i];
                cnt = 1;
            }
        }

        out.println(cnt);
    }
}

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

typedef long long ll;

ll n,W;
ll w[110],v[110];
ll dp[110][100010];

int main() {
    cin >> n >> W;
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= W; j++) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + w[i] <= W)
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= W; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 79360
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double h = sc.nextInt();
        double m = sc.nextInt();
        double dega = h/12d * 360 + m/60d * 30;
        double degb = m/60d * 360;
        double deg = Math.min(Math.abs(dega-degb),360-Math.abs(dega-degb));
        System.out.println(Math.sqrt(a*a+b*b-2*a*b*Math.cos(toRadians(deg))));
    }
    
    private static double toRadians(double deg)
    {
        return deg * Math.PI / 180.0;
    }
}
 
class Point{
    int cnt,x,y;
    public Point(int cnt, int y, int x){
        this.cnt = cnt;
        this.x = x;
        this.y = y;
    }
}
 
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
 
    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public double nextDouble() {
         return Double.parseDouble(next());
    }
 
    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }
 
    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n,r;
  cin>>n>>r;
  int ans=r+100*max(10-n,0);
  cout<<ans<<endl;
  return(0);
}


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

bool is[100005];
int cnt[100005];

int main(){
	
	int n, m, ans = 0, u, v;

	scanf("%d %d", &n, &m);

	is[1] = 1;

	for(int i = 1; i <= n; i++)	cnt[i] = 1;

	for(int i = 1; i <= m; i++){
		scanf("%d %d", &u, &v);
		if(is[u])	is[v] = 1;
		cnt[u]--, cnt[v]++;
		if(cnt[u] == 0)	is[u] = 0;
	}

	for(int i = 1; i <= n; i++)	ans += is[i];

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void)
{
        int X,Y,Z,A,a,i;
        scanf("%d%d%d",&X,&Y,&Z);
        a=Y+Z;
        for(i=0;A+Z<=X;i++)
                A=A+a;
        printf("%d\n",i-1);
        return 0;
}


Measured memory_bytes: 128
N,M = map(int, input().split())
H = list(map(int, input().split()))
dp = [1]*N
for i in range(M):
  A,B = map(int, input().split())
  if H[A-1] <= H[B-1]:
    dp[A-1] = 0
  if H[B-1] <= H[A-1]:
    dp[B-1] = 0
print(dp.count(1))

Measured memory_bytes: 84956