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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(int i  = 0; i < 2; i++){
    if(a > b){
      ans += a;
      a--;
    }else{
      ans += b;
      b--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 110000

ll dp1[MAXN];
ll dp2[MAXN];
vector<vector<int>>edges(MAXN);
ll n,m;

void dfs1(int x, int p = -1){
  dp1[x] = 1;
  for(auto to:edges[x]){
    if(to==p)continue;
    dfs1(to, x);
    dp1[x] *= dp1[to];
    dp1[x] %= m;
  }
  dp1[x]++;
}

void dfs2(int x, int p=-1){
  if(p==-1)dp2[x]=1;
  vector<ll> lprod(edges[x].size(), 1);
  rep(i, (int)edges[x].size()){
    int to = edges[x][i];
    if(i)lprod[i] *= lprod[i-1];
    if(to==p)continue;// 着目中のノードのパターン数はかけない

    lprod[i] *= dp1[to]; lprod[i] %= m;
  }

  vector<ll> rprod(edges[x].size(), 1);
  rrep(i, (int)edges[x].size()){
    int to = edges[x][i];
    if(i<edges[x].size()-1)rprod[i] *= rprod[i+1];
    if(to==p)continue;// 着目中のノードのパターン数はかけない

    rprod[i] *= dp1[to]; rprod[i] %= m;
  }

  rep(i, (int)edges[x].size()){
    int to = edges[x][i];
    if(to==p)continue;
    ll pr = 1;
    if(i)pr = pr * lprod[i-1] % m;
    if(i<edges[x].size()-1)pr = pr * rprod[i+1] % m;
    dp2[to] = (dp2[x] * pr+1)%m;
    dfs2(to, x);
  }
}

ll ans[MAXN];
void dfs3(int x, int p = -1){
  ans[x] = dp2[x];
  for(auto to:edges[x]){
    if(to==p)continue;
    ans[x] *= dp1[to];
    ans[x] %= m;
    dfs3(to, x);
  }
}

int main(){
  cin>>n>>m;
  rep(i, n-1){
    int x,y;cin>>x>>y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  dfs1(1);
  dfs2(1);
  dfs3(1);

  rep1(i, n)cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

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

    string s;cin>>s;
    s.insert(1," ");
    s.insert(3," ");
    s.insert(5," ");
    auto eval=[&](string a){
        int v=a[0]-'0';
        v+=(a[1]=='+'?1:-1)*(a[2]-'0');
        v+=(a[3]=='+'?1:-1)*(a[4]-'0');
        v+=(a[5]=='+'?1:-1)*(a[6]-'0');
        return v==7;
    };

    rep(i,0,2)rep(j,0,2)rep(k,0,2){
        if(i)s[1]='+';
        else s[1]='-';

        if(j)s[3]='+';
        else s[3]='-';

        if(k)s[5]='+';
        else s[5]='-';

        if(eval(s)){
            cout<<s+"=7"<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    a.sortDescending()
    var sum = 0L
    for (i in 0 until n - 1) {
        sum += a[(i + 1) / 2]
    }
    println(sum)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 60828
#define MAX 101
#define INF 100000
#include <stdio.h>

typedef struct  {
  int r;
  int c;
} arr;

int matrixChainOrder(int,int *);
int min (int,int);

int main(int argc, char const *argv[]) {
  int i,j,n,total;
  int p[MAX];

  scanf("%d",&n);

  for (i = 0; i < n; i++) {
    scanf("%d%d\n",&p[i],&p[i+1]);

  }

  printf("%d\n",matrixChainOrder(n,&p[0]));

  return 0;
}


int matrixChainOrder(int length,int *p){
  int i,j,n,k,l,q;
  int m[MAX][MAX];

  n = length;

  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for (l = 2; l <= n; l++) {
    for (i = 1; i <= n-l+1 ; i++) {
      j = i+l-1;
      m[i][j] = INF;
      for (k = i; k <= j-1; k++) {
        q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
        m[i][j] = min(m[i][j] , q);
      }
    }
  }
  return m[1][n];
}

int min(int x,int y){

  if (x<y) {
    return x;
  }
  else if (y<x) {
    return y;
  }
  else {
    return x;
  }
}

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

int main () {
    int N;
    cin >> N;
    vector<int> A(N), B;
    for (int &a : A) cin >> a;
    B = A;
    sort(B.rbegin(), B.rend());
    int mx = *max_element(B.begin(), B.end());
    for (int a : A) cout << ((a != mx) ? mx : B.at(1)) << "\n";
}

Measured memory_bytes: 3200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            boolean isFound = false;

            for (int i = 0; i < 26; i++) {
                if (s.indexOf((char) ('a' + i)) == -1) {
                    out.println((char) ('a' + i));
                    isFound = true;
                    break;
                }
            }

            if (!isFound) out.println("None");
        }
    }
}


Measured memory_bytes: 23764
#どの 2 つの街の間も、道を何本か通ることで行き来することができる
cnts=[0]*4
for i in range(3):
    ai,bi=map(int, input().split())
    ai-=1;bi-=1
    cnts[ai]+=1;cnts[bi]+=1
for i in range(4):
    if cnts[i]>2:
        print("NO")
        exit()
print("YES")


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

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 sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

struct sp
{
    string s;
    int p, idx;
    
    bool operator < (const sp &a) const {
	if(s != a.s)
	    return s < a.s;
	else
	    return p > a.p;
    }
};

int main()
{
    int rank[101] = {};
    vector<sp> v;
    int n;
    ci >> n;

    string s;
    int p;
    rep(i, 0, n) {
	ci >> s >> p;
	v.pb((sp){s, p, i + 1});
    }

    vsort(v);

    rep(i, 0, n) co << v[i].idx << en;
  
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(K: int):
    if K <= 12:
        print(K)
        return
    # a = []
    # for i in range(1,10000):
    #     s = str(i)
    #     for j in range(len(s)-1):
    #         if abs(int(s[j])-int(s[j+1]))<=1:
    #             continue
    #         else:
    #             break
    #     else:
    #         a.append(i)
    # print(a)
    # matrix[i][j] = i桁で最上位がjから始まるものの数
    matrix = [[0]*10 for _ in range(11)]

    for i in range(0,10):
        matrix[1][i] = 1

    keta = 2
    SUM = 9
    last = 0
    while True:
        for i in range(10):
            if SUM >= K:
                break

            if i == 0:                
                matrix[keta][i] = matrix[keta-1][0]+matrix[keta-1][1]
            elif i == 9:
                matrix[keta][i] = matrix[keta-1][i-1]+matrix[keta-1][i]
            else:
                matrix[keta][i] = matrix[keta-1][i-1]+matrix[keta-1][i]+matrix[keta-1][i+1]

            if i > 0:
                SUM += matrix[keta][i]
            last = i

        else:
            keta += 1
            continue
        
        break

    answer = str(last)

    while keta > 0:
        i = int(answer[-1])
        SUM -= matrix[keta][i]
        keta -= 1
 
        if i == 0:                
            for j in range(0,2):
                SUM += matrix[keta][j]
                if SUM >= K:
                    answer += str(j)
                    break        
        elif i == 9:
            for j in range(8,10):
                SUM += matrix[keta][j]
                if SUM >= K:
                    answer += str(j)
                    break
        else:
            for j in range(i-1,i+2):
                SUM += matrix[keta][j]
                if SUM >= K:
                    answer += str(j)
                    break
    print(answer)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
       int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int sam = 0;
      
      for(int i=1;i<T+1;i++){
       if(A*i<=T){
         sam += B;
       }
      }

      System.out.print(sam);


    }
}

Measured memory_bytes: 22100
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int W, H;

const int dx[2][6] = {{0, 1, 1, 1, 0, -1}, {-1, 0, 1, 0, -1, -1}};
const int dy[2][6] = {{-1, -1, 0, 1, 1, 0}, {-1, -1, 0, 1, 1, 0}};

int count(int x, int y, vector<vector<int>> &b) {
    int ret = 0;
    int check = !b[y][x];
    int p = y % 2;
    rep(i, 6) {
        int nx = x + dx[p][i], ny = y + dy[p][i];
        if(!(nx >= 0 && nx < W && ny >= 0 && ny < H)) {
            ret++;
            continue;
        }
        if(b[ny][nx] == check)
            ret++;
    }
    return ret;
}

void bfs(int xx, int yy, vector<vector<int>> &b) {
    queue<pii> que;
    que.push(MP(xx, yy));
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        int q = y % 2;
        if(b[y][x] == 1)
            continue;
        b[y][x] = 1;
        rep(i, 6) {
            int nx = x + dx[q][i], ny = y + dy[q][i];
            if(!(nx >= 0 && nx < W && ny >= 0 && ny < H)) {
                continue;
            }
            if(b[ny][nx] == 0) {
                que.push(MP(nx, ny));
            }
        }
    }
}

int main() {
    cin >> W >> H;
    vector<vector<int>> build(H, vector<int>(W));
    rep(i, H) rep(j, W) { cin >> build[i][j]; }
    int res = 0;
    rep(i, H) rep(j, W) {
        if(build[i][j] == 1) {
            res += count(j, i, build);
        }
    }

    rep(i, H) rep(j, W) {
        if(i == 0 || i == H - 1 || j == 0 || j == W - 1)
            bfs(j, i, build);
    }

    rep(i, H) rep(j, W) {
        if(build[i][j] == 0) {
            res -= count(j, i, build);
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3164
l, r = [int(elem) for elem in input().split()]

res = -1
if (r / 2019) - (l / 2019) < 1:
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            tmp = (i * j) % 2019
            if tmp < res:
                res = tmp
            elif res == -1:
                res = tmp
    print(res)
else:
    print(0)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000007

ll n;
ll dp[25][(1<<21)];
ll arr[25][25];

ll solve(ll i, ll womens){
    if(i == n){
        return womens == 0;
    }
    if(dp[i][womens] != -1) return dp[i][womens];

    ll ans=0;
    for(int w=0; w<n; w++){
        bool available = womens&(1<<w);
        if(available && arr[i][w]){
            ans = (ans+solve(i+1, womens&(~(1<<w))))%mod;
        }
    }
    return dp[i][womens]=(ans%mod);
}
int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin>>arr[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));
    cout<<solve(0, (1<<n)-1)<<endl;
    
    return 0;
}

Measured memory_bytes: 409856
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class EAllYouCanEat {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, t; cin >> n >> t;
      vector<P> vec(n);
      rep(i, n) {
        cin >> vec[i].first >> vec[i].second;
      }
      sort(all(vec));
      vector<ll> dp(t);
      ll ans = 0;
      rep(i, n) {
        rep(j, t) {
          chmax(ans, dp[j] + vec[i].second);
        }
        for(int j=t-1; j>=0; j--) {
          if (j-vec[i].first >= 0) {
            chmax(dp[j], dp[j - vec[i].first] + vec[i].second);
          }
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  EAllYouCanEat solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

struct st{int a,b,c;};
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	vector<st> v(n);
	rep(i,n){
		int x,y,c;
		cin>>x>>y>>c;
		v[i] = {x,y,c};
	}
	static int dp[401][401];
	rep(i,401)rep(j,401)dp[i][j]=INF;
	dp[0][0] = 0;
	
	for(int i=1;i<=n;i++){
		for(int j=400;j>=0;j--){
			for(int k=400;k>=0;k--){
				if(j-v[i-1].a<0||k-v[i-1].b<0)continue;
				dp[j][k] =min( dp[j-v[i-1].a][k-v[i-1].b]+v[i-1].c , dp[j][k] );
			}
		}
	}
	int res = INF;
	int c=1;
	while(c*a<=400&&c*b<=400){
		res = min(res,dp[c*a][c*b]);
		c++;
	}
	if(res==INF)cout<<-1<<endl;
	else cout<<res<<endl;
}

Measured memory_bytes: 896
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ans = 0 ;
    for i in 1..n+1 {
        if i % 2 == 0 { continue; }
        let mut divisor_num = 0 ;
        for j in 1..i+1 {
            if i % j == 0 {
                divisor_num += 1;
            }
        }
        if divisor_num == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}



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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}


int main(){
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int N = S.size();

    static int64_t dp[100001][13];
    dp[0][0] = 1;
    int base = 1;
    for(int i=0; i<N; i++){
        for(int j=0; j<13; j++){
            for(int d=0; d<=9; d++){
                if(S[i] == '?' || S[i] - '0' == d){
                    add(dp[i+1][(j+base*d)%13], dp[i][j]);
                }
            }
        }
        base = base * 10 % 13;
    }
    cout << dp[N][5] << endl;
    return 0;
}


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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k)
        cout << k;
    else if (a + b >= k)
        cout << a;
    else
        cout << a - (k - a - b);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

ll dp[100010][14],sep;
ll md = 1e9+7;
str s;
int n;
int main(){

//    freopen("input.txt", "r", stdin);0
//    freopen("output.txt", "w", stdout);

    cin>>s; n = s.size();
    s = " "+s;

    if(s[n]=='?'){for(int i=0;i<=9;i++)dp[n][i]=1;}
    else dp[n][numerize(s[n])]=1;

    sep = 1;
    for(int i=n-1;i>0;i--){
        int st,en;
        if(s[i]=='?'){st=0;en=9;}
        else{st=numerize(s[i]);en=numerize(s[i]);}
        sep = (sep*10)%13;
        for(int j=st;j<=en;j++){
            ll temp = (sep*j)%13;
            for(int k=0;k<13;k++){
                ll res = (temp+k)%13;
                dp[i][res] = ((dp[i][res]%md) + (dp[i+1][k]%md))%md;
            }
        }
    }
    cout<<dp[1][5]<<newl;

}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long int lint;
typedef unsigned long long int ulint;

//#define DEBUG

#ifdef DEBUG
#	define dump(i) cout << "[*] " #i " : " << i << endl;
#	define debug(i) i
#else
#	define dump(i)
#	define debug(i)
#endif
#define rep(i, MAX) for (int i = 0; i < (MAX); ++i)

inline void solve() {
	string s;
	cin >> s;
	int ans = 700;
	rep(i, 3) {
		if (s[i] == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;
}

int main() {
	//*
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	// */
#ifdef DEBUG
	const auto start = chrono::high_resolution_clock::now();
#endif
	solve();
#ifdef DEBUG
	const auto stop = chrono::high_resolution_clock::now();
	cerr << "[*] time: " << chrono::duration_cast<chrono::milliseconds>(stop-start).count()
		<< " [ms]" << endl;
#endif
	return 0;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int main() {
   ll i,j,k;
    ll n,a,b,ans=0;
    cin >>n >>a>>b;
    ans+=(n/(a+b))*a;
    n%=(a+b);
    if(n>a)
    {
      ans+=a;
    }else
    {
      ans+=n;
    }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n,m;cin >> n >> m;
    vector<pair<int,int>> v(m);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        v[i]=make_pair(b,a);
    }
    sort(all(v));
    int now=0;
    int ans=0;
    REP(i,m){
        if(v[i].second>now){
            ans++;
            now=v[i].first-1;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int H, W, N, sr, sc; cin>>H>>W>>N>>sr>>sc;
    string s, t; cin>>s>>t;

    string a;
    for(int i=N-1; i>=0; --i) (a+=t[i])+=s[i];

    int r0=1, r1=H, c0=1, c1=W;
    for(int i=1; i<a.size(); ++i) {
        auto d=a[i];
        if (i%2) {
            bool no=false;
            switch (d) {
                case 'L': no=++c0>W; break;
                case 'R': no=--c1<1; break;
                case 'U': no=++r0>H; break;
                case 'D': no=--r1<1; break;
            }
            if (no) return cout<<"NO"<<endl, 0;
        }
        else {
            switch (d) {
                case 'L': if (c1<W) ++c1; break;
                case 'R': if (c0>1) --c0; break;
                case 'U': if (r1<H) ++r1; break;
                case 'D': if (r0>1) --r0; break;
            }
        }
    }
    cout<<(r0<=sr and sr<=r1 and c0<=sc and sc<=c1 ? "YES" : "NO")<<endl;
}


Measured memory_bytes: 1292
#include<iostream>
#include<utility>
#include<string>
#include<algorithm>
using namespace std;
char in[120];
pair<pair<string,int>,int> p[101];
int main(){
int a;
cin>>a;
for(int i=0;i<a;i++){
int t;
  cin>>in>>t;
string tmp=in;
p[i]=make_pair(make_pair(in,-t),i);
}
sort(p,p+a);
for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
}


Measured memory_bytes: 384
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))

#ゼロでリストを分割する
# def split_list(st):
#     lis = st.split("0")
#     lis = [l for l in lis if l != ""]
#     return lis

def split_list(lis,num=0):
    res = []
    tmp = []
    for i in lis:
        if i != num:
            tmp.append(i)
        elif i == num and len(tmp)>0:
            res.append(tmp)
            tmp = []
        else:
            continue
    else:
        res.append(tmp)
    res = [l for l in res if len(l) != 0]
    return res

stack = split_list(arrA)
ans = 0
#リスト毎に処理.len0は処理しない。
while len(stack)>0:
    lis1 = stack.pop()
    arr = np.array(list(map(int,list(lis1))))
    #最小値を引いたリストにする。最小値をansに加算
    nmin = min(arr)
    ans += nmin
    arr = arr - nmin
    s = list(arr)
    lis2 = split_list(s)
    stack = stack + lis2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int main()
{
	long long int r,c,res;
	cin>>r>>c;
  	long long int ct=(r+1)/2;
	//int res = (floor(float(r)/2)*floor(float(c)/2))+(ceil(float(r)/2)*ceil(float(c)/2));
	if(r==1||c==1)
	{
		cout<<"1\n";
		return 0;
	}
	if(c%2==0)
	{
		res = (c/2)*r;
	}
	else
	{
		res = (c/2)*r + ct;
	}
	cout<<res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin >> A.at(i);
  
  
  vector<long long int> B(N);
  
  for(int i=0;i<N;i++)
    B.at(A.at(i)-1)++;
  
  long long int k=0;
  
  for(int i=0;i<N;i++){
      long long int x=B.at(i);
      if(x>=2){
        k+=x*(x-1)/2;
      }
    }
  
  for(int i=0;i<N;i++){
    long long int w=k;
    long long int p=B.at(A.at(i)-1);
    
    if(p!=0){
      w=w+(p-1)*(p-2)/2-p*(p-1)/2;
    }
    
    cout << w << endl;
  }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }
    return gcd(b%a,a);
}

const int N = 100005;

ll dp[N];

int main(){
    IOS
    
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    FOR(i,1,n+1){
        cin>>a[i];
    }
    FOR(i,0,n+1){
        dp[i]=MOD;
    }
    dp[1]=0;
    FOR(i,2,n+1){
        FOR(j,max(0LL,i-k),i+1){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n];
    cerr<<1.0/CLOCKS_PER_SEC<<endl;
    return 0;
}

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

int H, W;
int mp[1400][1400];
int h[1400][1400];

//i?????????????????????????????°??????????????§????????¢?????§??????????±???????
int max_rect(int i){
  stack< pair<int, int> > st;
  int ret=0;
  for(int j=0; j<W; j++){
    //?????????????????? ???????????? ???????????????????????????????´????????????????????????????
    if(st.empty() || st.top().second<h[i][j]){
      st.push(make_pair(j, h[i][j]));
      continue;
    }

    //???????????????????????????????´????????????????????????????
    if(st.top().second>h[i][j]){
      int most_left=j;
      while(!st.empty() && st.top().second>=h[i][j]){
	pair<int, int> tmp = st.top();
	st.pop();
	ret=max(ret, (tmp.second * (j-tmp.first))); //??¢????¨????
	most_left=tmp.first; //???????????´?????????x??§?¨??????????
      }
      st.push(make_pair(most_left, h[i][j]));
    }
  }

  while(!st.empty()){
    pair<int, int> tmp=st.top();
    st.pop();

    ret=max(ret, (W-tmp.first)*tmp.second);
  }

  return ret;
}

int main(){
  cin>>H>>W;
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++)
      cin>>mp[i][j];

  //???????????????????????¨??????????????????????±???????
  //1??????
  for(int i=0; i<W; i++){
    if(mp[0][i] == 1){h[0][i] = 0;}
    else{h[0][i] = 1;}
  }
  //2????????\???
  for(int i=1; i<H; i++){
    for(int j=0; j<W; j++){
      if(mp[i][j]==1){h[i][j] = 0;}
      else{h[i][j] = h[i-1][j]+1;}
    }
  }

  int ans=0;
  for(int i=0; i<H; i++){
    ans=max(ans, max_rect(i));
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  map<int, int> m;
  int tmp = 0;
  REP(i, n) {
    cin >> tmp;
    m[tmp]++;
  }

  vector<int> keys;
  for(auto i=m.begin();i!=m.end();i++) {
    keys.pb(i->first);
  }

  int ma = 0;
  REP(i, keys.size()) {
    tmp = keys[i];
    ma = max(ma, m[tmp-1] + m[tmp] + m[tmp+1]);
  }
  
  cout << ma << endl;
}


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

#define fi first
#define mp make_pair
#define se second
#define pb push_back
#define be(x) (x).begin(), (x).end()
#define rbe(x) (x).rbegin(), (x).rend()
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forl(i, n) for(int i = 1; i <= (int)(n); i++)    
#define fore(i , k, n) for(int i = (int)(k); i <= (int)(n); i++)

typedef long long ll;
typedef vector<ll> vl; 
typedef pair<int, int> pii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
  
    vl arr;
    ll a, b, c,d;
    cin >> a >> b >> c >> d;

    arr.pb(a*c);
    arr.pb(b*d);
    arr.pb(a*d);
    arr.pb(b*c);

    sort(rbe(arr));
    cout<<arr[0];

    return 0;

}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n,-1),b(n,inf);
    for(int i=0;i<n-1;i++)cin>>b[i];
    a[0]  = b[0];
    for(int i=1;i<n;i++){
	a[i] = min(b[i],b[i-1]);
    }
    ll res = 0;
    for(int i=0;i<n;i++)res+=a[i];
 //   for(int i=0;i<n;i++)cout<<a[i]<<endl;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine().trim();
		int x = Integer.parseInt(line);
		System.out.println(x * x * x);
		br.close();
	}
	
}

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

int main(){
  string s, res = "";
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0' || s[i] == '1'){
      res += s[i];
    }else if(s[i] == 'B' && res != ""){
      res.pop_back();
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt(), G = sc.nextInt(), B = sc.nextInt(), N = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < N/R+1; i++) {
            int r = i;
            for (int j = 0; j < (N-R*r)/G+1; j++) {
                int g = j;
                if (N-R*r-G*g >= 0 && (N-R*r-G*g) % B == 0)
                    ans += 1;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
  return b? gcd(b, a%b) : a;
}

ll lcm( ll a, ll b){
  return a/gcd(a,b)*b;
}

ll f( ll x, ll c, ll d ){
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main(){

  ll  a=0, b=0, c=0, d=0;


  cin >> a >> b >> c >> d;

  ll ans = f(b,c,d) - f(a-1,c,d);

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



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

	    int a = scan.nextInt();
	    int b = scan.nextInt();
	    int c = scan.nextInt();
	    int d = scan.nextInt();
	    
	    if(a+b>c+d)
	    System.out.println("Left");
	    if((a+b)==(c+d))
		    System.out.println("Balanced");
	    if(a+b<c+d)
		    System.out.println("Right");


	}
}


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

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

    int c , d ,e , f , i , j;
    c = a /100;
    d = b /100;

    e = a /10000;
    f = b /10000;

    i = (a%10000)/1000;
    j = (b%10000)/1000;

    if (100*c + 10* i + e< a && 100*d + 10* j + f > b){
        cout << d-c-1 << endl;
    }
    else if (100*c + 10* i + e >= a && 100*d + 10* j + f <= b){
        cout << d-c+1 << endl;
    }
    else {
        cout << d-c << endl;
    }



}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,n;
string s;
bool f[200000];
bool isgood(int x)
{
	return(s[x-1]=='.'&&x<=n);
}
void dfs(int a1,int b1)
{
	if(!isgood(a1)||!isgood(b1))
	return;
//	if((a1==1&&b1==4)||(a1==3&&b1==4)||(a1==3&&b1==6)||(a1==4&&b1==6)||(a1==4&&b1==7)||(a1==6&&b1==7))
//	cout<<1; 
	f[a1-1]=true;
	f[b1-1]=true;
	if(a1==c&&b1==d)
	{ 
		cout<<"Yes";
		exit(0);
	}
	f[a1-1]=false;
	f[b1-1]=true;
	if(!f[a1]&&a1!=c)
	dfs(a1+1,b1);
	f[a1]=false;
	f[b1-1]=true;
	if(!f[a1+1]&&a1!=c)
	dfs(a1+2,b1);
	f[a1+1]=false;
	f[b1-1]=false;
	f[a1-1]=true;
	if(!f[b1]&&b1!=d)
	dfs(a1,b1+1);
	f[b1]=false;
	if(!f[b1+1]&&b1!=d)
	dfs(a1,b1+2);
	cout<<"No";
	exit(0);
}
int main()
{
	cin>>n>>a>>b>>c>>d;
	cin>>s;
	memset(f,false,sizeof(f));
	dfs(a,b);
	return 0;
}

Measured memory_bytes: 10372
N, W = map(int, input().split())
wv = []

for i in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])
MAX_V = 10**5+100
INF = 10**10
dp = [[INF]*MAX_V for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_V):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = 0
for i in range(MAX_V):
    if dp[N][i] <= W:
        ans = i
print(ans)

Measured memory_bytes: 120428
H,W = map(int,input().split())
S = list(list(input())for _ in range(H))

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            flag = False
            for x,y in [[i-1,j],[i+1,j],[i,j+1],[i,j-1]]:
                if 0 <= x < H and 0 <= y < W and S[x][y]=="#":
                    flag = True
            if not flag:
                print("No")
                exit()
print("Yes")
                        


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

int main() {
 
  string A, B, C;
  cin >> A >> B >> C;
  
  if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s;
    cin >> s;
    map<char, int> mp;
    repeat(i, (int)s.length()) {
        auto it = mp.find(s[i]);
        if (it != mp.end()) {
            cout << "no" << endl;
            return 0;
        }
        mp[s[i]] = 1;
    }
    cout << "yes" << endl;
    return 0;
}


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

vector<vector<int>> G(8);
int dfs(const int &ind,int n,bool seen[8]){
  bool all = true;
  for(int i = 0;i<n;i++) if(!seen[i]) all = false;
  if(all) return 1;
  int ret = 0;
  for(auto nv:G[ind]){
    if(seen[nv]) continue;
    seen[nv] = true;
    ret += dfs(nv,n,seen);
    seen[nv] = false;
  }
  return ret;
}

int main(){
  int n,m;
  cin >> n >> m;
  G.assign(n,vector<int>());
  rep(i,m){
    int a,b;cin >> a >> b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  bool seen[8];
  rep(i,n) seen[i] = false;
  seen[0] = true;
  
  cout << dfs(0,n,seen) << endl;
  
}

Measured memory_bytes: 3572
import java.util.Scanner;

//AtCoder Grand Contest 037
//A	Dividing a String
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		int count = 0;
		char pre = S.charAt(0);
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i) == pre) {
				count++;
				pre = ' ';
				i++;
			} else {
				pre = S.charAt(i);
			}
		}

		long ans = S.length() - count;

		System.out.println(ans);
	}
}


Measured memory_bytes: 26040
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int64 a, b, c; cin >> a >> b >> c;

    if (a + b >= c) print(b + c);
    else print(2 * b + a + 1);
    
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc=0
dd = defaultdict(int)
dd[0]+=1
for s in S[::-1]:
    acc+=r*int(s)
    acc%=2019
    r*=10
    r%=2019

    dd[acc]+=1
ans=0
for i in dd.values():
    ans+=(i*(i-1))//2
print(ans)


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

int main(){
	string s,t;
	cin>>s>>t;
	for(int i=s.size()-t.size();i>=0;i--){
		bool flag=true;
		for(int j=0;j<t.size();j++){
			if(s[i+j]!='?'&&s[i+j]!=t[j]){
				flag=false;
				break;
			}
		}
		if(flag){
			string s2=s;
			for(int j=0;j<t.size();j++){
				s2[i+j]=t[j];
			}
			for(int j=0;j<s2.size();j++){
				if(s2[j]=='?'){
					s2[j]='a';
				}
			}
			cout<<s2<<endl;
			return 0;
		}
	}
	cout<<"UNRESTORABLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a)=min((a),(b))
typedef long long ll;
typedef vector<int> vi;

char buf[25];

int h,w;
char s,t;
char mp[52][52];

int g[26][26];

int ddd[5] = {1,0,-1,0,1};

int main(){
  scanf("%d%d",&h,&w);
  scanf("%s",buf); s=buf[0];
  scanf("%s",buf); t=buf[0];
  REP(i,h)scanf("%s",mp[i]);
  REP(i,26)REP(j,26)g[i][j] = 10000000;
  REP(i,h)REP(j,w)if(isalpha(mp[i][j]) && mp[i][j]!='o'){
    int id = mp[i][j]-'A';
    REP(d,4){
      int ni = i+ddd[d];
      int nj = j+ddd[d+1];
      while(true){
        if(ni>=h || nj>=w || ni<0 || nj<0)break;
        if(mp[ni][nj]=='.')break;
        if(d%2==0 && mp[ni][nj]=='-')break;
        if(d%2==1 && mp[ni][nj]=='|')break;
        if(isalpha(mp[ni][nj]) && mp[ni][nj]!='o'){
          int nid = mp[ni][nj]-'A';
          g[id][nid] = g[nid][id] = 1;
          // printf("%d - %d\n",id,nid);
          break;
        }
        ni += ddd[d];
        nj += ddd[d+1];
      }
    }
  }
  // printf("s:%d, t:%d\n",s-'A',t-'A');
  REP(k,26)REP(i,26)REP(j,26)CHMIN(g[i][j],g[i][k]+g[k][j]);
  printf("%d\n",g[s-'A'][t-'A']);
  return 0;
}



Measured memory_bytes: 3228
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(), k=sc.nextInt();
        sc.close();
        int max=((n-1)*(n-2))/2;
        if(k>max){
            System.out.println(-1);
            return;
        }
        int plus=max-k;
        int m=n-1+plus;
        StringBuilder sb=new StringBuilder();
        for(int v=2;v<=n;v++) sb.append(1+" "+v+"\n");

        for(int u=2;u<=n-1;u++){
            for(int v=u+1;v<=n;v++){
                if(plus==0) break;
                sb.append(u+" "+v+"\n");
                plus--;
            }
            if(plus==0) break;
        }
        System.out.println(m);
        System.out.println(sb);
    }
}

Measured memory_bytes: 21844
using System;

namespace ABC142
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            if (N % 2 == 1) Console.WriteLine((double)(N / 2 + 1) / (double)N);
            else Console.WriteLine((double)(N / 2) / (double)N);
        }
    }
}


Measured memory_bytes: 11092
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

type Record = (usize,usize,usize,usize);

fn score(aa: &mut Vec<usize>, abcds: &Vec<Record>) -> usize {
    let mut score = 0;
    for &(a,b,c,d) in abcds.iter() {
        if aa[b-1] - aa[a-1] == c {
            score += d;
        }
    }
    score
}


fn rec(i: usize, cur: usize, n: usize, m: usize, abcds: &Vec<Record>, aa: &mut Vec<usize>) -> usize {
    if i == n {
        return score(aa, abcds);
    }
    let mut score = 0;
    aa[i] = cur;
    for j in cur..=m {
        score = max(rec(i+1, j, n, m, abcds, aa), score);
    }
    score
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      q: usize,
      abcds: [(usize,usize,usize,usize); q],
    }
    let mut aa = vec![0; n];
    let cur = 1;
    let ans = rec(0, cur, n, m, &abcds, &mut aa);
    puts!("{}\n", ans);
}


Measured memory_bytes: 2168
#include <iostream>

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

  size_t result = 0;
  char prev_color = 0;
  for (int i = 0; i < N; ++i) {
    char color;
    std::cin >> color;
    if (color != prev_color) {
      result++;
      prev_color = color;
    }
  }
  
  std::cout << result;
  return 0;
}


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

int main(){
	int a, b, v[101] = {} , p = 0;
	while(cin >> a && cin >> b){
		v[a]++;
		v[b]++;
		if(a == 0){
			if (v[1]%2 == 0 || v[2]%2 == 0){
				p = 1;
			} 
			for (int i = 3; i <= 100; i++){
				if (v[i]%2 == 1){
					p = 1;
				        v[i] = 0;
				}
			}

			if (p == 1) 
				cout << "NG" << endl;
			else 
				cout << "OK" << endl;
			v[1] = 0;
			v[2] = 0;	
			p = 0;
		}
	}
}
		

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

int N;

int GCD(int a, int b){
	if(b == 0) return a;
	else return GCD(b, a % b);
}

int main(){
	scanf("%d", &N);
	int res;
	for(int i = 0; i < N; i++){
		int A;
		scanf("%d", &A);
		if(i == 0) res = A;
		else res = GCD(res, A);
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <set>
using namespace std;
using ll = long long;

int n;
set<string> st;

int main()
{
    cin >> n;
    string s, t;
    for (int i = 0; i < n; i++)
    {
        cin >> s >> t;
        if (s == "insert")
            st.insert(t);
        else
        {
            if (st.find(t) == st.end())
                cout << "no" << endl;
            else
                cout << "yes" << endl;
        }
    }
}


Measured memory_bytes: 32536
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] arrivalTime = new int[n];
        for (int i = 0; i < n - 1; i++) {
            int spentTime = sc.nextInt();
            int startTime = sc.nextInt();
            int frequentTime = sc.nextInt();
            for (int j = 0; j <= i; j++) {
                if (arrivalTime[j] < startTime) {
                    arrivalTime[j] = startTime;
                }

                if (arrivalTime[j] % frequentTime != 0) {
                    arrivalTime[j] += frequentTime - (arrivalTime[j] % frequentTime);
                }
                arrivalTime[j] += spentTime;
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(arrivalTime[i]);
        }
    }
}

Measured memory_bytes: 26280