akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    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;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        String str = obj.next();
        for(int i=0;i<str.length();i++)
            if(str.charAt(i)=='7')
            {
                System.out.println("Yes");
                return;
            }
        System.out.println("No");
    }
}


Measured memory_bytes: 32676
using System;
using System.Linq;

namespace AGC027_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var Nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = Nx[0];
            var x = Nx[1];
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);

            var c = 0;
            foreach (var ai in a)
            {
                if (x-ai>=0)
                {
                    c++;
                    x -= ai;
                }
            }
            if (c==N && x>0)
            {
                c--;
            }
            Console.WriteLine(c);
        }
    }
}


Measured memory_bytes: 13396
n, m = [int(i) for i in input().split()]
S = input()
Q = [[i for i in input().split()] for j in range(m)]

def solve(i):
    cur = i
    for t, d in Q:
        if S[cur] == t:
            cur += 1 if d == 'R' else -1
        if cur < 0 or cur >= n:
            return False
    return True

def b_search(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(max(0, b_search(-1, n) - b_search(n, -1) + 1))

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

int main() {

	int E,X,tempmin;
	int min;

	while(true) {
		cin >> E;
		if(E == 0) {
			break;
		}
		min = 1000000;
		for(int Z = 0; Z*Z*Z<=E; Z++) {
			for(int Y = 0; Y*Y<=(E-Z*Z*Z); Y++) {
				X = E-Y*Y-Z*Z*Z;
				tempmin = X+Y+Z;
				//cout << X << " " << Y << " " << Z << endl;
				//cout << tempmin << endl;
				if((tempmin<min) && (X+Y*Y+Z*Z*Z == E)) {
					min = tempmin;
					
				}
			}
		}
		cout << min << endl;

	}
	return 0;
}

Measured memory_bytes: 3028
#!/usr/bin/env python
# coding: utf-8

# In[2]:


import collections


# In[17]:


N,K = map(int, input().split())
A = list(map(int, input().split()))


# In[18]:


mylist = collections.Counter(A).most_common()
mylist = list(reversed(mylist))
ans = 0
if len(mylist) > K:
    for a,n in mylist[:len(mylist)-K]:
        ans += n
print(ans)


# In[ ]:






Measured memory_bytes: 44468
package main

import(
    "fmt"
    _"bufio"
    _"os"
    _"math"
    _"strconv"
    _"strings"
)

func main() {
    
    var a int
    
    for i := 0; i < 5; i++ {
        
        fmt.Scan(&a)
        if a == 0 {
            fmt.Println(i+1)
            break
        }
    }
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline bool chmax(T1& a,T2 b)
{if (a < b) {a = b; return true;} return false;}

int main(){
    string S;
    cin >> S;
    int N = S.length();
    vector<int> A(3, 0);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'a') A[0]++;
        if (S[i] == 'b') A[1]++;
        if (S[i] == 'c') A[2]++;
    }
    
    int a = abs(A[0] - A[1]), b = abs(A[1] - A[2]), c = abs(A[2] - A[0]);
    if (max({a, b, c}) < 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(b%a==0){
        printf("%d\n",a+b);
    }
    else{
        printf("%d\n",b-a);
    }
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ios();
    int n;
    cin >> n;
    vector<ll> v(3*n);
    for(auto& i : v) cin >> i;

    vector<ll> sum_left(n+1, 0), sum_right(n+1, 0);
    priority_queue<ll, vector<ll>, greater<ll>> pq;

    ll sum = 0;
    REP(i, n){
        pq.push(v[i]);
        sum += v[i];
    }
    sum_left[0] = sum;

    REP(i, n){
        sum_left[i+1] = sum_left[i];
        ll mi = pq.top();
        if(v[n+i] > mi){
            sum_left[i+1] += v[n+i] - mi;
            pq.pop();
            pq.push(v[n+i]);
        }
    }

    priority_queue<ll, vector<ll>, less<ll>> pq2;
    
    sum = 0;
    REP(i, n){
        pq2.push(v[2*n + i]);
        sum += v[2*n + i];
    }
    sum_right[n] = sum;

    RREP(i, n){
        sum_right[i] = sum_right[i+1];
        ll ma = pq2.top();
        if(v[i+n] < ma){
            sum_right[i] += v[i+n] - ma;
            pq2.pop();
            pq2.push(v[n+i]);
        }
    }

    ll ans = -INF;
    REP(i, n+1){
        chmax(ans, sum_left[i] - sum_right[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6516
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	int a[110];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int mi = 1000000007;
	for (int i = -111; i <= 111; i++) {
		int co = 0;
		for (int j = 0; j < n; j++) {
			co += abs(a[j] - i) * abs(a[j] - i);
		}
		if (mi > co) {
			mi = co;
		}
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi   = vec<int>;
using vvi  = vec<vi>;
using vvvi = vec<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n; cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  int ret = 0; int m = 0;
  rep(i,1,n){
    if(h[i-1]>=h[i]) ret++;
    else ret = 0;
    m = max(m,ret);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3972
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort()
    maxa = aa[-1]
    dp = [False]*(maxa+1)
    for a in aa:
        dp[a] = True
    dup = set()
    for a in aa:
        if a in dup:
            dp[a] = False
            continue
        else:
            dup.add(a)
        if dp[a]:
            for j in range(a*2,maxa+1,a):
                dp[j] = False
    print(sum(1 for d in dp if d))



if __name__ == '__main__':
    main()

Measured memory_bytes: 40124
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  h,w,i,j,count,x,y,sw,m,n,a,b,c:Integer;
  s123,s1,s2,s3:string;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    nyu:=TStringList.Create;
    Readln(s123);
    nyu.CommaText:=s123;

    if (nyu[0][length(nyu[0])]=nyu[1][1] )and(nyu[1][length(nyu[1])]=nyu[2][1] ) then
      Writeln('YES')
    else
      Writeln('NO');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    int ans = 0;
    vector<int> last(26, -1);
    for (int i = 0; i < D; i++) {
        int t;
        cin >> t;
        t--;
        ans += s[i][t];
        last[t] = i;
        for (int k = 0; k < 26; k++) ans -= c[k] * (i - last[k]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
# bit演算
N, M = map(int, input().split())
# 各スイッチがどの電球に繋がっているかをbitで持つ
# スイッチ1が電球1、電球2に繋がっている場合は
# 101 -> 5 という持ち方
a = [0] * N
for i in range(M):
    K, *S = list(map(int, input().split()))
    for j in range(K):
        s = S[j]
        s -= 1
        # s番目のスイッチにi番目の電球が繋がっている
        a[s] |= 1 << i

expected = 0
l = list(map(int, input().split()))
for i in range(M):
    expected |= l[i] << i

# on/offの2通り、スイッチは最大10個なので、# 2^10=1024で全通り試してもOK
# on/offの全ての組み合わせをbitでループする
ans = 0
for s in range(1 << N):
    # 各電球の状態(bit)
    lighting = 0
    for i in range(N):
        # iビット目が立っているか
        if s >> i & 1:
            # スイッチを押して、つながった電球の状態を反転させる
            lighting ^= a[i]
    # 各スイッチを押した後の電球の状態が理想と一致するか
    if lighting == expected:
        ans += 1

print(ans)


Measured memory_bytes: 39792
# 改良版
# - chunkではなくchunk_whileで切るほうが綺麗だった
# - S2は見なくて良いことに気づいた
MOD = 10**9+7
gets
S1 = gets.chomp
verts = S1.chars.chunk_while{|c1, c2| c1 == c2}.map{|ch| ch.size == 1}

prev_vert = nil
m = verts.map.with_index{|vert, i|
  if i == 0
    vert ? 3 : 6
  else
    prev_vert = verts[i-1]
    case
    when prev_vert && vert
      2
    when prev_vert
      2
    when vert
      1
    else
      3
    end
  end
}

p m.inject{|a, b| a*b%MOD}


Measured memory_bytes: 1788
using System;

class Program
{
	static void Main()
	{
		int i = 1;

		while (true)
		{
			var stringInput = Console.ReadLine();
			var input = int.Parse(stringInput);

			if (input == 0)
				break;

			Console.WriteLine("Case " + i + ": " + input);
			i++;
		}
	}
}

Measured memory_bytes: 9348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct State
    {
        internal int x, y, cnt;

        public State(int x, int y, int cnt)
        {
            this.x = x;
            this.y = y;
            this.cnt = cnt;
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };
        readonly int INF = 1 << 20;
        readonly int w, h;

        int[,] map, counts;
        int sx, sy, minCnt;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            counts = new int[h, w];
        }

        public int Solve()
        {
            MakeMap();
            minCnt = INF;

            Stack<State> stk = new Stack<State>();
            stk.Push(new State(sx, sy, 0));

            while (stk.Count > 0)
            {
                State cur = stk.Pop();
                counts[cur.y, cur.x] = cur.cnt;

                for (int i = 0; i < 4; i++)
                {
                    int nextX = cur.x + moveX[i];
                    int nextY = cur.y + moveY[i];

                    if (IsValid(nextX, nextY))
                    {
                        int tempCnt = cur.cnt + (map[cur.y, cur.x] == 1 ? 0 : map[nextY, nextX]);

                        if (tempCnt < minCnt && counts[nextY, nextX] > tempCnt)
                        {
                            stk.Push(new State(nextX, nextY, tempCnt));
                        }
                    }
                    else minCnt = Math.Min(minCnt, cur.cnt);
                }
            }
            return minCnt;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0 || x >= w) return false;
            if (y < 0 || y >= h) return false;
            return true;
        }

        private void MakeMap()
        {
            for (int i = 0; i < h; i++)
            {
                string input = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    switch (input[j])
                    {
                        case '#':
                            map[i, j] = 1;
                            break;
                        case '&':
                            sx = j;
                            sy = i;
                            break;
                    }
                    counts[i, j] = INF;
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int w = int.Parse(input[0]);
                int h = int.Parse(input[1]);

                if (w == 0 && h == 0) break;

                Problem pb = new Problem(w, h);
                sb.AppendLine(pb.Solve().ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
    long long int n,i,j;
    cin>>n;
    char str[100001]; 
    i = 0; 
  
    while (n > 0) { 
 
        long long int rem = n % 26; 
  
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  
  
    reverse(str, str + strlen(str)); 
    cout << str <<"\n"; 
       
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<map>
using namespace std;
int main(){
  long long n;
  long long x;
  long long MOD;
  cin>>n>>x>>MOD;
  
  map<long long,long long>mp;
  long long pre=x;
  long long sum=x;
  long long left,right;
  mp[x]=1;
  for(int i=2;i<=MOD&&i<=n;i++){
    pre=(pre*pre)%MOD;
    sum+=pre;
    if(mp[pre]==0){
      mp[pre]=i;
    }else{
      left=mp[pre];
      right=i;
      break;
    }
  }

  n-=right;
  long long temp=0;
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    long long pos=itr->second;
    if(left<=pos&&pos<right){
      temp+=itr->first;
    }
  }

  long long cnt=n/(right-left);
  sum+=temp*cnt;
  n%=(right-left);
  
  for(int i=0;i<n;i++){
    pre=(pre*pre)%MOD;
    sum+=pre;
  }
  cout<<sum<<endl;
  return(0);
}

Measured memory_bytes: 6680
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var u=e[n]={i:n,l:!1,exports:{}};return r[n].call(u.exports,u,u.exports,t),u.l=!0,u.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var u in r)t.d(n,u,function(e){return r[e]}.bind(null,u));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,u=!1,a=void 0;try{for(var o,i=r[Symbol.iterator]();!(n=(o=i.next()).done)&&(t.push(o.value),!e||t.length!==e);n=!0);}catch(r){u=!0,a=r}finally{try{n||null==i.return||i.return()}finally{if(u)throw a}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=t(r.split("\n")[0].split(" ").map(function(r){return Number(r)}),6),n=e[0],u=e[1],a=e[2],o=e[3],i=e[4],s=e[5],f=100*i/(100+i),l={},c={water:0,sugar:0,p:0},p=[{water:0,sugar:0}];p.length>0;){var g=p.shift(),d=g.water+g.sugar,w=`${g.water}-${g.sugar}`;if(!(d>s||1==l[w])){l[w]=1;var y=100*g.sugar/d;y>c.p&&y<=f&&(c.p=y,c.water=g.water,c.sugar=g.sugar),p.push({water:g.water+100*n,sugar:g.sugar}),p.push({water:g.water+100*u,sugar:g.sugar}),p.push({water:g.water,sugar:g.sugar+a}),p.push({water:g.water,sugar:g.sugar+o})}}0==c.water&&0==c.sugar&&(c.water=100*n),console.log(`${c.water+c.sugar} ${c.sugar}`)}},function(r,e){r.exports=require("fs")}]);

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

int main(){
  int N;
  cin >>N;
  vector<ll> a(N);
  vector<ll> c(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
    c[i]=a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(c[i]<a[(N/2)]){
     cout << a[(N/2)] <<endl;
    }
    else{
      cout << a[(N/2)-1] <<endl;
    }
  }
}

  


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



int main() {
    int n;
    cin >> n;
    int ans = 0;
    int cnt = 0;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    rep(i,n-1) {
        if (h[i] >= h[i+1]) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
int nCr(long long m, long long n){

    //6 * 5 * 4 *../ 1*2*3*...
    int ans = 1;
    for (long long i = 1; i <= n; i++){
        ans = ans * (m - i + 1) / i;
 
    }
    return ans;
}

int32_t main()
{
    char ch;cin>>ch;
    if(isupper(ch)){
        cout<<'A'<<endl;
    }else cout<<'a'<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>

int
main(int argc, char** argv) {
    int n, l;
    std::cin >> n >> l;
    int min = l -1;

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += l + i - 1;
    }

    int ans;
    if (l > 0) {
        ans = sum - l;
    } else if (n > -l) {
        ans = sum;
    } else {
        ans = sum - (n - 1 + l);
    }
    std::printf("%d\n", ans);


    return 0;
}

Measured memory_bytes: 888
def r;gets.split.map &:to_i;end
N,M = r
S = N.times.map{r}
S.sort_by!{|v|v[0]}

count = M
money = 0
S.each do |(a,b)|
  if b < count
    count -= b
    money += b * a
  else
    money += count * a
    puts money
    exit
  end
end

Measured memory_bytes: 12664
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *P = map(int, read().split())

    min_p = INF
    ans = 0
    for p in P:
        if p < min_p:
            ans += 1
            min_p = p

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 102904
import sys

sys.setrecursionlimit(10**5)


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        if self.parents[x] > self.parents[y]:
            rx, ry = ry, rx
        self.parents[rx] += self.parents[ry]
        self.parents[ry] = rx

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def size(self, x):
        return -self.parents[self.root(x)]


n, m = map(int, input().split())
bridges = [tuple((int(i)-1 for i in input().split())) for _ in range(m)]
islands = UnionFind(n)
res = [n*(n-1)//2]
for a, b in bridges[:0:-1]:
    if islands.same(a, b):
        res.append(res[-1])
    else:
        res.append(res[-1] - islands.size(a) * islands.size(b))
        islands.unite(a, b)
print('\n'.join(map(str, res[::-1])))


Measured memory_bytes: 40944
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int ans=0,maximum=0;
	for(int i=0; i<5 ; i++){
		int temp;
		cin>>temp;
		ans+=temp;
		if(temp%10){
			ans+=(10-temp%10);
			maximum=max(maximum,(long long)(10-temp%10));
		}
	}
	cout<<ans-maximum<<endl;
	
	return 0;
}
/*
29
20
7
35
120
*/


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>cnt;
int main()
{
	int n;
	cin >>n;
	while(n--)
	{
		int  a;
		cin>>a;
		cnt[a]++;
	}
	int flag=0;
	for(map<int ,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	{
		if(it->second!=1)
		{
			flag=1;
			break;
		}
		
	}
	if(flag)
	printf("NO\n");
	else
	printf("YES\n");
	return 0;
 } 

Measured memory_bytes: 9600
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] arr = reader.readLine().split(" ");
        long N = Long.parseLong(arr[0]);
        long A = Long.parseLong(arr[1]);
        long B = Long.parseLong(arr[2]);
        long div = N / (A + B);
        long mod = N % (A + B);
        System.out.println(A * div + Math.min(A, mod));
    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;

string s;

vector<int> z;

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

       cin >> h >> w;
       int flo[201][201];
       rep(i,10){
           rep(j,10){
               if(i==j){
                   flo[i][j]=0;
               }
               else{
                   flo[i][j]=INF;
               }
           }
       }
       rep(i,10){
           rep(j,10){
               cin >> a;
               flo[i][j]=a;
              // flo[j][i]=a;
           }
       }
       rep(i,10){
           rep(j,10){
               rep(k,10){
                   flo[j][k]=min(flo[j][k],flo[j][i]+flo[i][k]);
                    //cout << flo[j][k] << "j" << j << "k" <<k << endl;
               }
           }
       }
       rep(i,h){
           rep(j,w){
               cin >> b;
               //Cout(b);
               if(b!=-1 && b!=1){
                   ans+=flo[b][1];
               }
           }
       }
       Cout(ans);
return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NL = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            string[] dictionary = new string[NL[0]];
            for(int j = 0; j < NL[0]; j++)
            {
                dictionary[j]= Console.ReadLine();
            }
            Array.Sort(dictionary);
            string result = "";
            for(int z = 0; z < dictionary.Count(); z++)
            {
                result += dictionary[z];
            }
            Console.WriteLine(result);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 29180
#include <stdio.h>
 

int main(){
  int n = 2, m = 1;
  int a[ 100001 ] = {0};
  int a_c[ 100001 ] = {0};

  scanf( "%d %d", &n, &m );
  
  int i = 1;
  for ( i = 1; i < n + 1; i++ ){
    int h = 0;
    scanf( "%d", &h );
    a[ i ] = h;
    a_c[ i ] = 1;
  }

  
  for ( i = 1; i < m + 1; i++ ){
    int ai = 0, bi = 0;
    scanf( "%d %d", &ai, &bi );
    if ( a[ ai ] < a[ bi ] ){
      a_c[ ai ] = 0;
    }else if ( a[ ai ] > a[ bi ] ){
      a_c[ bi ] = 0;
    }else if ( a[ ai ] == a[ bi ] ){
      a_c[ ai ] = 0;
      a_c[ bi ] = 0;
    }
  }
  
  int c = 0;
  for ( i = 1; i < n + 1; i ++ ){
    c += a_c[ i ];
  }

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

  return 0;
  
}


Measured memory_bytes: 2516
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int dan=2,j=1;

string bowling_pin(int x) {
	int i;
	for (i=2;i<100001; i++)
	{
		if (x == j) return "Yes";
		j += i;
		dan++;
	}
	return "No";
}

int main() {
	int n,x,y;
	cin >> n;
	string ans;
	vector<vector<int>> s(200000);

	ans = bowling_pin(n);

	cout << ans << endl;

	
	int cnt = 1;
	if (ans == "Yes") {
		for(int i=1;i<dan;i++)
			for (int j = i + 1; j <= dan; j++) {
				s[i].push_back(cnt);
				s[j].push_back(cnt);
				cnt++;
			}
      cout<<dan<<endl;

		for (int i = 1; i <= dan; i++) {
			cout << s[i].size();
			for (int j = 0; j < s[i].size(); j++) {
				cout << " " << s[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
int n,a; cin>>n>>a;
if(n-(n/500)*500 <= a) cout<<"Yes";
else cout<<"No";
return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <array>
#include <iomanip>
#include <algorithm> //using for swap()
using namespace std;

array<int,100001> A;

void Partition(int p,int  r){
	int x = A[r];
	int i = p-1;
	for(int j=p;j<r;j++){
		if(A[j] <= x){
	       	i++;
		    swap(A[i],A[j]);
		}
	
/*
	    for(int p=0;p<r;p++){
	    	cout<<setw(2)<<A.at(p)<<" ";
	    }
	    cout<<setw(2)<<A.at(r)<<endl;
*/		
	}
    swap(A[i+1],A[r]);

    for(int p=0;p<r;p++){
    	if(p==i+1){
    		cout<<"["<<A.at(p)<<"] ";
    	}else{
    		cout<<A.at(p)<<" ";
    	}
    }
    cout<<A.at(r)<<endl;
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		A[i]=tmp;
	}
	Partition( 0, n-1);
	
	return 0;
}

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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<double,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, e,f, g,sum, A[500010], B[500000], rui[500000], dp[5000];
ll ma = Min;
P C[10010];
str S; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> n;
	map<ll,ll> m;
	for(int i = 0;i < n;i++){
	cin >> A[i];
	m[A[i]]++;
	}
	for(int i = 0;i < n;i++){
	if(m[A[i]] > 1)check = false;
	}

if(check)cout << "YES" << endl;
else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n; cin >> n;
  cout << 48-n << endl; 
  return 0;
}  


Measured memory_bytes: 256
if ARGV[0] == "test"
  require 'minitest/autorun'

  class TestC < Minitest::Unit::TestCase
    def test_true
      c = C.new("xyxy")
      assert c.couple_string?
    end
    def test_true2
      c = C.new("xyzxyz")
      assert c.couple_string?
    end
    def test_not
      c = C.new("hage")
      assert !c.couple_string?
    end
    def test_not2
      c = C.new("xyzxy")
      assert !c.couple_string?
    end
    def test_succ
      c = C.new("fuga")
      assert_equal "fug", c.succ
    end
  end
end

class C
  attr_reader :str
  def initialize(str)
    @str = str
  end
  def couple_string?
    return false if @str.length % 2 != 0
    first = @str.split('').take(@str.length / 2)
    last =  @str.split('').slice(@str.length / 2, @str.length)
    return true if first == last
    return false
  end
  def succ
    @str = @str.slice(0..-2)
  end
end

c = C.new(STDIN.gets.chomp)
c.succ
until c.couple_string?
  c.succ
end

puts c.str.length


Measured memory_bytes: 2300
import heapq
import sys
input = sys.stdin.readline
from operator import itemgetter

def readlines(n):
    for _ in range(n):
        b, c = map(int, input().split())
        yield b, c

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    change = []
    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):
        change.extend([c] * b)
        if len(change) > N:
            break

    A += change
    A.sort()
    answer = sum(A[-N:])
    print(answer)

main()

Measured memory_bytes: 23672
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vvi X(1001, vi(1001));
    rep(i, n) {
        P x, y;
        cin >> x >> y;
        X[x.first][x.second]++;
        X[y.first][y.second]++;
        X[x.first][y.second]--;
        X[y.first][x.second]--;
    }

    rep(i, 1001) {
        rep(j, 1000) {
            X[i][j+1] += X[i][j];
        }
    }
    rep(j, 1001) {
        rep(i, 1000) {
            X[i+1][j] += X[i][j];
        }
    }
    int ma = 0;
    rep(i, 1000) rep(j, 1000) {
        chmax(ma, X[i][j]);
    }

    cout << ma << endl;
}


Measured memory_bytes: 6852
#include <bits/stdc++.h>
 using namespace std;
 
 int n,m,T;
 int x;
 
 int main()
 {
 	cin >> n >> x >> T;
 	int now = n%x == 0 ? n/x : n/x+1;
 	cout << now * T << endl;
	 return 0;
 }

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep (i, n) {
    cin >> p[i];
    p[i]--;
  }

  int ans = 0;
  rep (i, n) {
    if (p[i] != i) continue;
    ans++;
    if (i + 1 < n) swap(p[i], p[i + 1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
temp = 0

for i in range(len(a)):
    if i == len(a)-1:
        if temp > a[i]:
            ans += a[i]
            break
        else:
            ans += temp
            break
        break
    if a[i] > (temp + b[i]):
        ans += (temp + b[i])
        temp = 0
    else:
        ans += a[i]
        if temp > a[i]:
            temp = b[i]
        else:
            if b[i] > (a[i] - temp):
                temp = b[i] + temp - a[i]
            else:
                temp = 0



print(str(ans))


Measured memory_bytes: 18476
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 500005
using namespace std;
const int Mod = 998244353;

inline void inc(int &x, int y) {
    x += y; if (x >= Mod) x -= Mod;
}

inline int fsp(int x, int p = Mod - 2) {
    int res = 1;
    while (p) {
        if (p & 1) res = 1ll * res * x % Mod;
        x = 1ll * x * x % Mod, p >>= 1;
    } return res;
}

int n, m, fac[N << 2], ifac[N << 2];

inline int C(int x, int y) {
    if (x < 0 || y < 0) return 0;
    return 1ll * fac[x + y] * ifac[x] % Mod * ifac[y] % Mod;
}

inline int calc(int r, int b) {
    if (r - b >= n) return C(r, b);
    return (C(r, b) + Mod - C(b - r + n - 1, 2 * r - n + 1)) % Mod;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> m; int sz = max(n, m) << 2;
    for (int i = fac[0] = 1; i <= sz; ++i)
        fac[i] = 1ll * fac[i - 1] * i % Mod;
    ifac[sz] = fsp(fac[sz]);
    for (int i = sz; i >= 1; --i)
        ifac[i - 1] = 1ll * ifac[i] * i % Mod;
    int ans = 0;
    for (int r = max((m + 1) / 2, n); r <= m; ++r)
        inc(ans, calc(r, r == m - r ? m - r - 1 : m - r));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;
/*
struct dice {
	int s[6];
	void roll(char c) {
		int b;
		if (c == 'E') {
			b = s[0];
			s[0] = s[3];
			s[3] = s[5];
			s[5] = s[2];
			s[2] = b;
		}
		if (c == 'N') {
			b = s[0];
			s[0] = s[1];
			s[1] = s[5];
			s[5] = s[4];
			s[4] = b;
		}
		if (c == 'S') {
			b = s[0];
			s[0] = s[4];
			s[4] = s[5];
			s[5] = s[1];
			s[1] = b;
		}
		if (c == 'W') {
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
		if (c == 'R') {
			b = s[1];
			s[1] = s[3];
			s[3] = s[4];
			s[4] = s[2];
			s[2] = b;
		}
	}
	int top() {
		return s[0];
	}
	int right() {
		return s[2];
	}
	int left() {
		return s[3];
	}
	int front() {
		return s[1];
	}

};

int main() {
	dice d;
	for (int i = 0; i < 6; i++) {
		cin >> d.s[i];
	}
	int order;
	cin >> order;
	while(order--) {
		int top, front;
		cin >> top >> front;
		if (d.left() == top) {
			d.roll('E');
		}
		if (d.right() == top) {
			d.roll('W');
		}
		while (d.top() != top) {
			d.roll('N');
		}
		while (d.front() != front) {
			d.roll('R');
		}
		cout << d.right() << endl;
	}
}
*/

int main() {
	int h, w, pop[26][26];
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> pop[i][j];

		}
	}
	int minDisum = 1000000;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int disum = 0;
			for (int k = 1; k <= h; k++) {
				for (int l = 1; l <= w; l++) {
					disum += pop[k][l] * min(abs(k - i), abs(l - j));
				}
			}
			if (disum < minDisum) {
				minDisum = disum;
			}
		}
	}
	cout << minDisum << endl;
}


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

int main() {
	int A, B, C, D, N;
	cin >> N;
	D = N % 10;
	C = ((N - D) / 10) % 10;
	B = ((N - C - D) / 100) % 10;
	A = (N - B - C - D) / 1000;
	
	for (int i = -1;i <= 1;i += 2) {
		for (int j = -1;j <= 1;j += 2) {
			for (int k = -1;k <= 1;k += 2) {
				if (A + (i * B) + (j * C) + (k * D) == 7) {
					cout << A << (i == 1 ? "+" : "-") << B << (j == 1 ? "+" : "-") << C << (k == 1 ? "+" : "-") << D << "=7";
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll n, m;
ll k;
vector <ll> a, v, swaps;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(ll i = 0, x ; i < n && cin >> x ; i++)
        a.push_back(x);
    vector <ll> b;
    for(ll i = 1 ; i < n ; i++)
        b.push_back(a[i] - a[i - 1]);
    cin >> m >> k;
    for(ll i = 0, x ; i < m && cin >> x ; i++)
        swaps.push_back(x - 2);
    vector <ll> plain, s;
    for(ll i = 0 ; i < n - 1 ; i++)
        plain.push_back(i);
    s = plain;
    for(auto &i : swaps)
        swap(s[i], s[i + 1]);
    v.resize(s.size());
    for(ll i = 0 ; i < (ll)s.size() ; i++)
        v[s[i]] = i;
    vector <ll> ans(v.size());
    vector <ll> vis(v.size());
    for(ll i = 0 ; i < n ; i++){
        if(vis[i]) continue;
        vector <ll> c;
        ll cur = i;
        while(vis[cur] == 0){
            c.push_back(cur);
            vis[cur] = 1;
            cur = v[cur];
        }
        for(ll i = 0 ; i < (ll)c.size() ; i++)
            ans[c[i]] = c[(k + i) % c.size()];
    }
    vector <ll> res(v.size());
    for(ll i = 0 ; i < (ll)ans.size() ; i++)
        res[ans[i]] = b[i];
    ll cur = a[0];
    cout << cur << " ";
    for(auto &i : res){
        cur += i;
        cout << cur << " ";
    }
    cout << endl;
}


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

// #define NDEBUG
#include<assert.h>
const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int pre, now;
    ll rest = 1000, cnt = 0;
    cin >> pre;
    while(--n) {
        cin >> now;
        cnt = rest / pre;
        rest += max(0, (now - pre)) * cnt;
        pre = now;
    }
    cout << rest << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
using P = pair<int, int>;

P get_num(string &str) {
    int n = (int)str.size();
    P ret(0, 0);
    int r = 0;
    for (int i = 0; i < n; i++) {
        if (str[i] == '(') {
            r++;
        } else {
            if (r > 0) {
                r--;
            } else {
                ret.first++;
            }
        }
    }
    ret.second = r;
    return ret;
}

bool comp(P l, P r) {
    if (min(l.first, l.second) != min(r.first, r.second)) {
        return min(l.first, l.second) < min(r.first, r.second);
    } else {
        return max(l.first, l.second) < max(r.first, r.second);
    }
}

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }

    vector<P> num(N);
    for (int i = 0; i < N; i++) {
        num.at(i) = get_num(S[i]);
    }

    P tmp(0, 0);
    for (int i = 0; i < N; i++) {
        //   cerr << num.at(i).first << " " << num.at(i).second << endl;  // debug
        P now = num[i];
        if (now.first == 0) {  // ( しかない
            tmp.first += now.second;
        } else if (now.second == 0) {
            tmp.second += now.first;
        }
    }
    // cerr << endl;  // debug
    sort(ALL(num), comp);
    for (int i = 0; i < N; i++) {
        P now = num[i];
        if (now.first == 0 || now.second == 0) continue;
        //cerr << i << " " << tmp.first << " " << tmp.second << endl;  // debug
        if (now.first < now.second) {
            if (tmp.first >= now.first) {  // ) が多い
                tmp.first -= now.first;
                tmp.first += now.second;
            } else if (tmp.second >= now.second) {
                tmp.second -= now.second;
                tmp.second += now.first;
            } else {
                cout << "No\n";
                return 0;
            }
        } else {
            if (tmp.second >= now.second) {
                tmp.second -= now.second;
                tmp.second += now.first;
            } else if (tmp.first >= now.first) {  // ) が多い
                tmp.first -= now.first;
                tmp.first += now.second;
            } else {
                cout << "No\n";
                return 0;
            }
        }
    }

    if (tmp.first == tmp.second && tmp.first >= 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

/*
4
)((
))(((
)))
(
*/


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

#define ALL(a) (a).begin(), (a).end()

using namespace std;

const vector<int> coin = {500, 100, 50, 10, 5, 1};

signed main(){
	while(true) {
		int n; cin >> n;
		if(n == 0) break;
		n = 1000 - n;
		int ans = 0;
		for(auto e : coin) {
			while(n >= e) {
				ans += 1;
				n -= e;
			}
		}
		cout << ans << endl;
	}

	return 0;
}




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

using namespace std;

int main()
{
	int n, d, x;
	int a[100];
	
	cin >> n >> d >> x;
	
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < n; i++){
		for (int j = 1; j <= d; j += a[i]) x++;
	}
	
	cout << x << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n;
  char a[101], b[101], c[101];
  scanf("%d%s%s%s", &n, a, b, c);
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    if (a[i] == b[i] && b[i] == c[i]) continue;
    if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ++ans;
    else ans += 2;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
N = int(input())

next_li = []

for i in range(N):
    next_li.append(int(input()))

#判定処理
st = 0
c = 1
for i in range(N):
    if next_li[st] == 2:
        print(c)
        exit()
    else:
        c += 1
        st = next_li[st]-1
print(-1)


Measured memory_bytes: 7084