akhauriyash/Code-Regression huggingface dataset:
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
 *
 * @author Silviase
 */
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);
    AColorfulSubsequence solver = new AColorfulSubsequence();
    solver.solve(1, in, out);
    out.close();
  }

  static class AColorfulSubsequence {

    public void solve(int testNumber, Scanner in, PrintWriter out) {

      int n = in.nextInt();
      int[] alp = new int[26];
      String s = in.next();
      long l = 1;
      for (int i = 0; i < s.length(); i++) {
        alp[(int) s.charAt(i) - (int) 'a']++;
      }
      for (int i = 0; i < 26; i++) {
        l *= (alp[i] + 1);
        l = l % 1000000007;
      }
      out.println(l - 1);

    }

  }
}



Measured memory_bytes: 23996
#include<bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
# define M_PI           3.14159265358979323846  /* pi */
int main(){
  double r;
  cin>>r;
  cout<<M_PI*2*r<<"\n";  


  return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  double ans = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  ans = a.at(0);
  for (int i = 1; i < N; i++) {
    ans = (ans + a.at(i)) / 2.0;
  }
  cout << setprecision(17) << ans << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin>>n>>k;
    int p[n+1];
    for(int i=1; i<=n; i++) cin>>p[i];
    int c[n+1];
    for(int i=1; i<=n; i++) cin>>c[i];
    long long m = -2e9;
    for(int i=1; i<=n; i++){
        int t= p[i];
        int cyc = 1;
        long long psum[n+1];
        psum[0] = 0;
        psum[1] = c[i];
        while(t!=i){
            psum[cyc+1] = psum[cyc] + c[t];
            t= p[t];
            cyc++;
        }
        long long temp=-2e9;
        if(psum[cyc]>=0 && k>=cyc){
            temp = psum[cyc]*(k/cyc-1);
            for(int i=1; i<=cyc; i++){
                temp = max(temp,  psum[cyc]*(k/cyc-1)+psum[i]);
            }
            for(int i=0; i<=k%cyc; i++){
                temp = max(temp,  psum[cyc]*(k/cyc)+psum[i]);
            }
        }
        else{
            for(int j=1; j<=min(cyc,k); j++){
                temp = max(temp, psum[j]);
            }
        }
        m = max(m, temp);
    }
    cout<<m;
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	ll cnt = min(a, k);
	a -= cnt;
	k -= cnt;
	cnt = min(b, k);
   	b -= cnt;
	cout << a << " " << b << endl;	
	return 0;
}



Measured memory_bytes: 3632
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>

#define Size(c) (int)(c).size()
#define INT(...) int __VA_ARGS__;IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;IN(__VA_ARGS__)

int scan(){ return getchar(); }
void scan(int& a){ cin>>a; }
void scan(long long& a){ cin>>a; }
void scan(char &a){cin>>a;}
void scan(double &a){ cin>>a; }
void scan(long double& a){ cin>>a; }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }

void IN(){}
template <class Head, class... Tail> void IN(Head& head, Tail&... tail){ scan(head); IN(tail...); }

#define ios cin.tie(NULL), ios_base::sync_with_stdio(false)
#define cfs(n) cout<<fixed<<setprecision((n))
#define endl '\n'
#define ret return 0

constexpr ll mod=998244353;
constexpr ll mod2=10e9+7;
const double PI = 3.1415926535897932384626433832795028841971; //acos(-1)

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

int main(){
  ios; cfs(15);

  LL(a);
  ld b;scan(b);
  ll c = round(b*100);
  cout<<a*c/100<<endl;
  ret;
}   



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

int main(){
	
	int n, count=0, maxc = 0;
	cin >> n;
	string s;
	cin >> s;
	for (char c: s){
		if ( c == 'I') count++;
		else count--;
		maxc = max(maxc,count);
	}
	cout << maxc;
}



Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

import org.omg.CORBA.SystemException;

class Main {
	public static void main(String[] a) throws IOException {
		Scanner scan = new Scanner(System.in);
		while (true){
		int m = scan.nextInt();
		int d = scan.nextInt();
		if(m == 0){
			break;
		}
		int y = 2004;
	   if(m<3){
		   y = y-1;
		   m = m + 12;
	   }
		int youbi = (y + y/4 - y/100 + y/400 + (26*m+16)/10 + d) % 7;
		if(youbi == 1){
			System.out.println("Monday");
		}else if(youbi == 2){
			System.out.println("Tuesday");
		}else if(youbi == 3){
			System.out.println("Wednesday");
		}else if (youbi == 4){
			System.out.println("Thursday");
		}else if (youbi == 5){
			System.out.println("Friday");
		}else if (youbi == 6){
			System.out.println("Saturday");
		}
		else if (youbi == 0){
			System.out.println("Sunday");
		}
	}
	}
}

Measured memory_bytes: 26000
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
char s[N];
unordered_map<int,int> ma;
int main() {
	//freopen("in.txt","r",stdin);
	int n,p;
	scanf("%d%d%s",&n,&p,s+1);
	ll ans=0;
	if(10%p==0) {
		for(int i=1;i<=n;i++) {
			if((s[i]-'0')%p==0) ans+=i;
		}
	}
	else {
		int res=0,t=1;
		for(int i=n;i>=1;i--) {
			ma[res]++;
			res=(res+(s[i]-'0')*t)%p;
			t=t*10%p;
			ans+=ma[res];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		char[] n    = scanner.nextLine().toCharArray();
		int ans = 0;
		int cnt = 0;

		for(char x : n) {

			if(x == 'R') {
				cnt++;
				ans = Math.max(ans, cnt);
			}else {
				cnt = 0;
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 35640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);



void solve() {
	int n; cin >> n;
	cout << n * n*n << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

const int mod = 1e9 + 7;
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int p2[61];
	p2[0] = 1;
	for (int i = 1; i < 61; i++) {
		p2[i] = p2[i - 1] * 2;
	}
	int ans = 0;
	for (int j = 0; j <= 60; j++) {
		int pw = p2[j] % mod;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] & p2[j]) cnt++;
		}
		ans += cnt * (n - cnt) % mod * pw % mod;
		ans %= mod;
	}
	cout << ans << "\n";
}



Measured memory_bytes: 2560
# https://atcoder.jp/contests/abc126/tasks/abc126_d

# ｄfsでやっていき、最初の点を黒か白かで固定する。偶数ならどんどん加えていく。
n = int(input())
tree = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    tree[u].append((v, w))
    tree[v].append((u, w))


def dfs(tree, n):
    visited = [False] * n
    dis = [0] * n
    even = set([0])
    stack = [0]
    while stack:
        v = stack.pop()
        cur_dis = dis[v]
        for next_v, d in tree[v]:
            if not visited[next_v]:
                visited[next_v] = True
                stack.append(next_v)
                dis[next_v] = cur_dis + d
                if (cur_dis + d) % 2 == 0:
                    even.add(next_v)
    return even

even = dfs(tree, n)
for i in range(n):
    if i in even:
        print(0)
    else:
        print(1)

Measured memory_bytes: 98180
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    std::ios::sync_with_stdio(false);
    int n, m; std::cin >> n >> m;
    int wa[n] = {0};
    int ans = 0;
    bool ac[n] = {false};
    for(int i=0; i<m; i++)
    {
        int p; std::string s;
        std::cin >> p >> s;
        if(s=="WA") wa[p-1]++;
        if(s=="AC" && !ac[p-1])
        {
            ac[p-1] = true;
            ans += wa[p-1];
        }
    }
    int acs = 0;
    for(int i=0; i<n; i++)
    {
        acs += ac[i];
    }
    std::cout << acs << " " << ans << std::endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  REP(i, 1, n + 1) {
    if (i % 2 == 1) {
      int cnt = 0;
      REP(j, 1, i + 1) {
        if (i % j == 0) ++cnt;
      }
      if (cnt == 8) ++ans;
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
// 解説見た
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)
ll p[100100];

int main(void)
{
    ll n;
    ll bu;
    cin >> n;
    REP(i, n) cin >> p[i];
    ll cnt = 0;
    REP(i, n) {
        if(p[i]==i+1) {
            if(i==n-1) {
                bu = p[i]; p[i] = p[i - 1]; p[i - 1] = bu;
            } else {
                bu = p[i]; p[i] = p[i + 1]; p[i + 1] = bu;
            }
            cnt ++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int x,y;
  cin>>x>>y;

  int ans;
  if(x==1 && y==1) ans=1000000;
  else ans=max(400000-x*100000,0)+max(400000-y*100000,0);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
n, k, c = map(int, input().split())
s = list(input())
left = []
right = []

i = 0
while i < n:
    if len(left) >= k:
        break
    if s[i] == "o":
        left.append(i)
        i += c + 1
    else:
        i += 1
i = n - 1
while i >= 0:
    if len(right) >= k:
        break
    if s[i] == "o":
        right.append(i)
        i -= c + 1
    else:
        i -= 1

for i in range(k):
    if left[i] == right[k - 1 - i]:
        print(left[i] + 1)

Measured memory_bytes: 22024
#include <bits/stdc++.h>
#include <string> 
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mid 2019
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
 
 
int main()
{
    fastio;
    ll n,m,i,sum=0;
    cin>>n>>m;
    ll a[m];
    for(i=0;i<m;i++){
    cin>>a[i];
    sum=sum+a[i];
    }
    if(sum>n)
    cout<<-1<<endl;
    else
    cout<<n-sum<<endl;

}

Measured memory_bytes: 3708
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,n*10+1):
  N=list(str(i))
  for j in range(len(N)):
    N[j]=int(N[j])
  N=set(N)
  d=set(d)
  if N.isdisjoint(d):
    print(i)
    exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll ans = 0;
    reps(i, 1, n + 1) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
y_map, x_map = map(int, input().split())
field_map = [list(input()) for i in range(y_map)]

dp = [[0 for i in range(x_map+1)]for j in range(y_map+1)]
dp[1][1] = 1
for i in range(y_map):
    for j in range(x_map):
        if field_map[i][j] == ".":
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j] + dp[i][j+1])
        else:
            dp[i+1][j+1] = 0

print(dp[-1][-1]%((10**9)+7))

Measured memory_bytes: 245340
io = STDIN
n=io.gets.to_i
t,a=io.gets.split.map(&:to_i)
h=io.gets.split.map(&:to_i)
def temp(t,x)
  (t-x*0.006)
end
ar= h.map.with_index(1){|hh,i|[(temp(t,hh)-a).abs,i]}
puts ar.min_by{|diff,no|diff}[1]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n; cin >> n;
  map<pair<string, int>, int> mp;
  REP(i, n){
    string s; int p;
    cin >> s >> p;
    mp[make_pair(s, -p)] = i;
  }

  for(const auto it : mp){
    cout << it.second + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU DONT LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define inv (mod+1)/3
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;while(t--)
ll zero=0;
ll one=1;
ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return(a.second<=b.second);}

//https://www.youtube.com/watch?v=k4V3Mo61fJM

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};

signed main()
{
    bolt;
    ll n;cin>>n;
    string s;cin>>s;ll c=0;
    forci(0,n)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C' && i+2<n)
            i+=2,c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int k= 1;
        HashMap<String,Integer> hashMap = new HashMap<>();
        hashMap.put("SUN",7);
        hashMap.put("MON",6);
        hashMap.put("TUE",5);
        hashMap.put("WED",4);
        hashMap.put("THU",3);
        hashMap.put("FRI",2);
        hashMap.put("SAT",1);
        String s1;
        String s2;
        int a,b;
        while(k-->0){
            a=s.nextInt();
            b=s.nextInt();
            if(a<10 && b<10)
                System.out.println(a*b);
            else
                System.out.println(-1);
        }
    }

    private static int binary_search(
            int arr[], int l,
            int h, int x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 27036
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    //答えansを仮置きする。
    //これが十分に大きくないと不正解となるので、
    //この値なら絶対に正しい答えが出る、という値を仮置きすること
    int ans = T.size();
 
    //Sの何文字目から調べるかを全探索する
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  
  cin >> N >> K;
  
  int r = 1;
  
  for (int i = 0; i < N; i++) {
    if (r + K > r * 2)
      r *= 2;
    else
      r += K;
  }
  
  cout << r << endl;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	N, K := readInt2()
	P := readIntArray(N)

	head := P[0]
	var initial int
	for i := 0; i < K; i++ {
		initial += P[i]
	}
	//fmt.Printf("init: %d\n", initial)

	tmp := initial
	max := tmp
	var maxIdx int
	for i := 1; i <= N-K; i++ {
		tmp -= head
		tmp += P[i+K-1]
		head = P[i]
		//fmt.Printf("total[%d]: %d\n", i, tmp)
		if max < tmp {
			max = tmp
			maxIdx = i
		}
	}
	//fmt.Printf("max pair: %d-%d\n", maxIdx, maxIdx+K-1)

	var et float64
	for i := maxIdx; i <= maxIdx+K-1; i++ {
		et += expval(P[i])
	}
	fmt.Println(et)
}

func expval(p int) float64 {
	var e float64
	for i := 1; i <= p; i++ {
		e += float64(i) / float64(p)
	}
	//fmt.Printf("p: %d, e: %f\n", p, e)
	return e
}


Measured memory_bytes: 6272
x = []
y = []
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    else:
        if a <= b:
            x.append(a)
            y.append(b)
        else:
            x.append(b)
            y.append(a)

for i in range(len(x)):
    print(x[i], y[i])


Measured memory_bytes: 6124
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <climits>
#include <random>
#include<algorithm>

#define int_max 2147483647;

int main(int argc, char const *argv[])
{
    
    int x , y;
    std::cin>>x>>y;
    std::cout<<x+y/2<<std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long
#define rp(i,start,end) for(ll i =start ; i<end; i++)


int main(){


ll N;
ll K;

ll sum =0;

cin >> N >> K;

rp(i,K,N+2){

    sum = sum +(N+1)*N/2 -(N-i)*(N-i+1)/2 - (i-1)*i/2 +1;
   

}


ll ans =sum%(1000000007);

cout << ans << endl;
return 0;






}




Measured memory_bytes: 3636
X, Y = list(map(int, input().split()))
P = 10 ** 9 + 7


def conb(n, r):
    x = 1
    y = 1
    for i in range(n - r + 1, n + 1):
        x = (x * i % P)
    for i in range(1, r + 1):
        y = (y * i % P)
    y_inv = power(y, P - 2)
    return (x * y_inv)%P


def power(x, n):
    ans = 1
    while (n > 0):
        if (bin(n & 1) == bin(1)):
            ans = (ans * x) % P
        x = (x * x) % P
        n = n >> 1  # ビットシフト
    return ans


if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
    u = (2 * Y - X) // 3
    r = (2 * X - Y) // 3
    if u < 0 or r < 0:
        print(0)
    else:
        print(conb(u + r, r))


else:
    print(0)


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

int c = 0;

void merge(int A[], int left, int mid, int right){
   int n1, n2; //分割後の要素数
   n1 = mid - left;
   n2 = right - mid;
   int L[n1 + 1], R[n2 + 1];
   for(int i = 0; i < n1; i++)
      L[i] = A[left + i];

   for(int i = 0; i < n2; i++)
      R[i] = A[mid + i];
   L[n1] = INT_MAX;
   R[n2] = INT_MAX;
 
   //ソートする
   int j = 0, k = 0;
   for(int i = left; i < right; i++){
      if(L[j] <= R[k]){
         A[i] = L[j];
         j++;
         c++;
      }
      else{
         A[i] = R[k];
         k++;
         c++;
      }
   }
}

void merge_sort(int A[], int left, int right){//マージソートする関数
   if(left + 1 < right){//もし要素が2つ以上であれば分割
      int mid = (left + right) / 2;
      merge_sort(A, left, mid);
      merge_sort(A, mid, right);
      
      //併合する
      merge(A, left, mid, right);
   }
}

int main(void){
    int n;
    cin >> n;
    int B[n];
    for(int i = 0; i < n; i++) cin >> B[i];

    merge_sort(B, 0, n);
    
    for(int i = 0; i < n; i++){
       if(i != n - 1)
       cout << B[i] << " ";
       else
       cout << B[i] << endl;
    }
    cout << c << endl;
}



Measured memory_bytes: 6904
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong
  val nn = n - 1
//  def ModSum(n: Long): AnyVal = {
  //    val nn = (n - 1)
  //    (1 + nn) * nn / 2
  //  }

  println((1 + nn) * nn / 2)
}

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

public class Main {
	static class Node {
		int key = 0;
		Node parent = NIL;
		Node left = NIL;
		Node right = NIL;
	}
	static Node NIL = new Node();
	
	static class Tree {
		Node root = NIL;
	}
	
	public static void main(String[]  args) {
		int m = nextInt();
		
		Tree tree = new Tree();
		
		for (int i = 0; i < m; i ++) {
			next();
			switch (nextbuf[0]) {
				case 'i':
					insert(tree, nextInt());
					break;
				case 'f':
					int key = nextInt();
					System.out.println((find(tree, key).key == key) ? "yes": "no");
					break;
				case 'd':
					delete(tree, nextInt());
					break;
				default:
					inorder(tree.root);
					System.out.println();
					preorder(tree.root);
					System.out.println();
					break;
			}
		}
	}
	
	static void insert(Tree tree, int key) {
		Node z = new Node();
		z.key = key;
		Node y = NIL;
		
		y = find(tree, key);
		
		if (y == NIL) {
			tree.root = z;
		} else if (z.key < y.key) {
			y.left = z;
			z.parent = y;
		} else {
			y.right = z;
			z.parent = y;
		}
	}
	
	static Node find(Tree tree, int key) {
		Node x = tree.root;
		Node y = NIL;

		while (x != NIL) {
			y = x;
			if (key == x.key) break;
			x = (key < x.key) ? x.left: x.right;
		}
		return y;
	}
	
	static void delete(Tree tree, int key){
		Node z = find(tree, key);
		if (z == NIL) return;
		
		Node y;
		if (z.left == NIL || z.right == NIL) {
			y = z;
		} else {
			for (y = z.right; y.left != NIL; y = y.left);
		}
		
		Node x = (y.left != NIL) ? y.left: y.right;
		if (x != NIL) x.parent = y.parent;
		
		if (y.parent == NIL) {
			tree.root = x;
		} else if (y == y.parent.left) {
			y.parent.left = x;
		} else {
			y.parent.right = x;
		}
		
		if (y != z) z.key = y.key;
	}

	static void preorder(Node u) {
		if (u == NIL) return;

		System.out.print(" ");
		System.out.print(u.key);
		preorder(u.left);
		preorder(u.right);
	}

	static void inorder(Node u) {
		if (u == NIL) return;

		inorder(u.left);
		System.out.print(" ");
		System.out.print(u.key);
		inorder(u.right);
	}
	
	private static byte[] buf = new byte[1 << 20];
	private static int len = 0;
	private static int ptr = 0;

	private static byte read() {
		if (ptr >= len) {
			try {
				len = System.in.read(buf);
			} catch (Exception e) {
			}
			ptr = 0;
		}

		return buf[ptr++];
	}

	private static int nextInt() {
		int num = 0;

		byte b = read();
		while(!Character.isDigit(b) && b != '-') b = read();
		int sign;
		if (b == '-') {
			sign = -1;
			b = read();
			if (!Character.isDigit(b)) return 0;
		} else {
			sign = 1;
		}
		
		while(Character.isDigit(b)) {
			num *= 10;
			num += sign * (b - '0');
			b = read();
		}
		
		return num;
	}

	private static byte[] nextbuf = new byte[11];
	private static int nextlen;

	private static void next() {
		nextlen = 0;

		byte b = read();
		while(!Character.isAlphabetic(b) && !Character.isDigit(b)) b = read();
		while(Character.isAlphabetic(b) || Character.isDigit(b)) {
			nextbuf[nextlen++] = b;
			b = read();
		}
	}
} 



Measured memory_bytes: 143112
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include <cassert>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main(){
	ll N;
	cin >> N;
	vector<char> c(N + 1);
	repn(i, N)cin >> c[i];

	ll r = 0;
	ll w = 0;
	repn(i, N) {
		if (c[i] == 'R') { r++; }
	}

	ll ans = r;

	repn(i, N) {
		if (c[i] == 'R') { r--; }
		else { w++; }
		ans = min(ans, max(r, w));
	}

	cout << ans << endl;
}



Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =2000010;
int heap[MAX_N];
int n;

int parent(int i){
	return i/2;
}
int rightchild(int i){
	return 2*i+1;
}
int leftchild(int i){
	return 2*i;
}
int sz = 1;
void push(int x){
	int i =sz++;
	while(i >1){
		int p =parent(i);
		//もし逆転していないなら抜ける
		if(heap[p] >=x)break;
		//親のノードの数字をおろして自分は上に
		heap[i]=heap[p];
		i = p;
	}
	heap[i] = x;
}
int pop(){
	//最大値取り出し
	int  ret =heap[1];
	//根に持ってくる値
	int x =heap[--sz];
	//根から下ろしていく
	int i = 1;
	while(leftchild(i) <=sz){
		//子同士を比較
		int left =leftchild(i);
		int right =rightchild(i);
		if(leftchild(i) <sz&&heap[rightchild(i)] >heap[leftchild(i)]){
			left =right;
		}
		if(heap[left]<=x)break;

		heap[i]=heap[left];
		i =left;
	}
	heap[i]=x;
	return ret;
}
int main(){
	string str;
	while(cin>>str){
		if(str=="end")return 0;
		if(str=="insert"){
			int x;
			cin>>x;
			push(x);
		}else{
			cout <<pop()<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5296
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
const ll mod = 1e9+7;

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  
  ll sum = 0;
  rep(i,n) sum += a[i];
  vl b(n);
  b[0] = sum - a[0];
  rep(i,n-1) b[i+1] = b[i] - a[i+1];
  
  ll ans = 0;
  rep(i,n-1) ans += (a[i] % mod) * (b[i] % mod) % mod;
  ans %= mod;
  cout << ans << endl;
}

Measured memory_bytes: 6432
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,so,cnt,aa[220000],ab[220000],kt=0;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i];
	}
	for(int i=a-1;i>-1;i--){
		cnt=0;
		so=i;
		while(1){
			so+=(i+1);
			if(so+1>a){
				break;
			}
			if(ab[so]==1){
				cnt++;
			}
		}
		if((cnt%2==0&&aa[i]==0)||(cnt%2==1&&aa[i]==1)){
			ab[i]=0;
		}else{
			ab[i]=1;
			kt++;
		}
	}
	cout<<kt<<endl;
	rep(i,a){
		if(ab[i]==1){
			cout<<i+1<<" ";
		}
	}
}

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

int main() {
	int i=0, n, x[10001];
	while (cin >> x[i], x[i++] != 0);
	n=i;
	--i;
	while (	cout << "Case " << n-i << ": " << x[n-i-1] << endl,--i > 0);
	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pll;
const int N = (int)3e5 + 7;
//const ll inf = 1e16;

ll n,m,k,x,y,a[N],ans;

int main(){
    cin>>n;
    forn(i,3*n) cin>>a[i];
    sort(a,a+3*n);
    x=0,y=3*n-1;
    while(x<y){
        --y;
        ans+=a[y];
        --y;
        ++x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

int main(){
    int n;
    cin>>n;
    if(n<1200)cout<<"ABC"<<endl;
    else if(n<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	vector<int> res = {a[0]};
	rep(i,n){
		if(!i)continue;
		//trace(i,a[i],a[i-1]);
		if(a[i] != a[i-1])res.push_back(a[i]);
	}
	//trace(res);
	int m = res.size();
	int ret = 1000;
	int kabu = 0;
	rep(i,m-1){
		if(res[i] < res[i+1]){
			//kau
			int losemon = ret/res[i]*res[i];
			int getkabu = ret/res[i];
			ret -= losemon;
			kabu += getkabu;
		}
		else{
			//uru
			int getmon = kabu*res[i];
			kabu = 0;
			ret += getmon;

		}
		//trace(i,ret,kabu);

	}
	ret += kabu*res.back();
	cout << ret << endl;
	return 0;
}

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

using namespace std;

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

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

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

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

int main(){
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h)cin >> s[i];
	if(h == 1 && w == 1){
		cout << "No" << endl;
		return 0;
	}
	bool ok = true;
	rep(i,h){
		rep(j,w){
			if(s[i][j] == '#'){
				bool f = false;
				rep(k,4){
					int ny = i + dy[k];
					int nx = j + dx[k];
					if(ny >= 0 && ny < h && nx >= 0 && nx < w){
						f |= (s[ny][nx] == '#');
					}
				}
				if(!f)ok = false;
			}
		}
	}
	if(!ok)cout << "No" << endl;
	else cout << "Yes" << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

namespace NyaGadget
{
	/**
	@brief 素因数分解ライブラリ
	@note
	 nを素因数分解する。
	 ans[i]がnだったとき、素因数分解して得られた積のなかにn個の素数iが含まれていることを表す。
	 例えば n=12 のとき ans[0] = 0, ans[1] = 0, ans[2] = 2, ans[3] = 1, ans[4] = 0, ... ans[12] = 0
	 となるので 12 = 2 * 2 * 3 と分かる。
	**/
	void PrimeFactorization(ll n, map<ll, ll>& ans)
	{
		for (ll i = 2; i * i <= n; i++)
		{
			while (n % i == 0)
			{
				ans[i]++;
				n /= i;
			}
		}
		if (n != 1)
			ans[n]++;
	}
}

namespace NyaGadgetCpp17
{
	/**
	@brief 最大公約数を計算する関数
	@note
	 aとbの最大公約数を返す
	**/
	long long Gcd(long long a, long long b)
	{
		return b ? Gcd(b, a % b) : a;
	}
	/**
	@brief 最小公倍数を計算する関数
	@note
	 aとbの最小公倍数を返す
	**/
	long long Lcm(long long a, long long b)
	{
		return a / Gcd(a, b) * b;
	}
};

using namespace NyaGadget;

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

	map<ll, ll> ans;
	PrimeFactorization(NyaGadgetCpp17::Gcd(a, b), ans);

	cout << size(ans) + 1;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int t,i,max,s,a[3]={0};
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&a[0],&a[1],&a[2]);
        max = 0;s = 0;
        for(i=0;i<3;i++)
            if(a[i]>max)max = a[i];
        for(i=0;i<3;i++)
        {
            if(a[i]!=max)
                s += a[i]*a[i];
        }
        max = max*max;
        if(max==s)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1008
def calc(arr, xyz, t)
    sum = 0
    ret = []
    (0..arr.count-2).each do |index|
        ret << xyz[arr[index]][arr[index+1]]
    end
    ret.sort.reverse.each_with_index {|v, index| sum = sum + v/t[index] }
    return sum
end
def find(n, xyz, a, b, t)
    rets = {}
    tmp = [[a]]
    while !tmp.empty?
        arr = tmp.pop
        keys = xyz[arr.last].keys
        keys.each do |key|
            if key == b
                sum = calc(arr.dup << b, xyz, t)
                rets[b] = rets[b] == nil ? sum : [rets[b], sum].min
            elsif !arr.include?(key) && arr.count <= n-1
                tmp_arr = arr.dup << key
                sum = calc(tmp_arr, xyz, t)
                if rets[key] == nil || rets[key] > sum
                    rets[key] = sum
                    tmp << tmp_arr
                end
            end
        end
    end
    return rets[b] || 0
end

while true ########
n, m, r, a, b = gets.split(' ').map(&:to_i)
break if n + m + r + a + b == 0

t = gets.split(' ').map(&:to_i).sort.reverse
xyz = {}
(1..m).each{ |e| xyz[e] = {} }
r.times do
    x, y, z = gets.split(' ').map(&:to_i)
    xyz[x][y] = z.to_f
    xyz[y][x] = z.to_f
end

answer = find(n, xyz, a, b, t)

if answer == 0
    puts 'Impossible'
else
    puts sprintf("%.3f", answer)
end

end ###############


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C

const int inf = 1000000000;

int part(int a[], char b[], int p, int r) {
	int x = a[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (a[j] <= x) {
			i += 1;
			swap(a[i], a[j]);
			swap(b[i], b[j]);
		}
	}
	swap(a[i + 1], a[r]);
	swap(b[i + 1], b[r]);
	return i + 1;
}

void qsort(int a[], char b[], int p, int r) {
	if (p < r) {
		int q = part(a, b, p, r);
		qsort(a, b, p, q - 1);
		qsort(a, b, q + 1, r);
	}
}


void merge(int a[], char b[], int l, int m, int r) {
	int n1 = m - l;
	int n2 = r - m;
	int al[n1], ar[n2];
	char bl[n1], br[n2];
	for (int i = 0; i < n1; i++) {
		al[i] = a[l + i];
		bl[i] = b[l + i];
	}
	for (int i = 0; i < n2; i++) {
		ar[i] = a[m + i];
		br[i] = b[m + i];
	}
	al[n1] = inf;
	ar[n2] = inf;
	bl[n1] = 255;
	br[n2] = 255;
	int i = 0, j = 0;
	for (int k = l; k < r; k++) {
		if (al[i] <= ar[j]) {
			a[k] = al[i];
			b[k] = bl[i];
			i += 1;
		} else {
			a[k] = ar[j];
			b[k] = br[j];
			j += 1;
		}
	}
}

void mergesort(int a[], char b[], int l, int r) {
	if (l + 1 < r) {
		int m = (l + r) / 2;
		mergesort(a, b, l, m);
		mergesort(a, b, m, r);
		merge(a, b, l, m, r);
	}
}

int main() {
	int n;
	cin >> n;
	int oa[n], a[n];
	char ob[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> ob[i] >> oa[i];
		b[i] = ob[i];
		a[i] = oa[i];
	}
	qsort(a, b, 0, n - 1);
	mergesort(oa, ob, 0, n);
	/*for (int i = 1; i < n; i++) {
		int ta = oa[i];
		char tb = ob[i];
		if (oa[i - 1] > ta) {
			int j = i;
			do {
				oa[j] = oa[j - 1];
				ob[j] = ob[j - 1];
				j--;
			} while (j > 0 && oa[j - 1] > ta);
			oa[j] = ta;
			ob[j] = tb;
		}
	}*/
	
	bool stable = true;
	for (int i = 0; i < n; i++) {
		if (b[i] != ob[i]) {
			stable = false;
			break;
		}
	}
	
	cout << (stable ? "Stable" : "Not stable") << endl;
	for (int i = 0; i < n; i++) cout << b[i] << " " << a[i] << endl;
	return 0;
}

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

flag = 1
perm = 0
while flag == 1:
    flag = 0
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            temp = A[j]
            temp2 = A[j-1]
            A[j-1] = temp
            A[j] = temp2
            perm += 1
            flag = 1
print(" ".join(list(map(str, A))))
print(perm)


Measured memory_bytes: 5608