akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int p, q, r; cin >> p >> q >> r;
    cout << min(min(p+q, q+r), r+p) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program {

    static int MAX = 6;
    const int wht = 6, gry = 1, blk = 2;
    const int inf = int.MaxValue;

    static int[,] g = null;
    static int[] d = null;

    static int[] p = null;
    static int[] stt = null;




    static void dijkstra(int s) {

        d[0] = 0;
        p[0] = -1;

        int mn = inf;
        while (true) {
            mn = inf;
            int u = -1;
            for (int i = 0; i < MAX; i++) {
                if (stt[i] != blk && d[i] < mn) {
                    mn = d[i];
                    u = i;
                }
            }
            if (u == -1) break;
            stt[u] = blk;

            for (int v = 0; v < MAX; v++) {
                if (stt[v] != blk && g[u, v] != inf) {
                    if (d[v] > g[u, v]) {
                        d[v] = g[u, v];
                        p[v] = u;
                        stt[v] = gry;
                    }
                }
            }
        }
    }

    static void Main(string[] args) {


        var inp = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();
        int v, e; v = inp[0]; e = inp[1];

        MAX = v;
        d = Enumerable.Repeat(int.MaxValue, MAX).ToArray();
        p = Enumerable.Repeat(-1, MAX).ToArray();
        stt = new int[MAX];
        g = new int[MAX, MAX];

        for (int i = 0; i < MAX; i++) {
            for (int j = 0; j < MAX; j++) {
                g[i, j] = inf;
            }
        }

        for (int i = 0; i < e; i++) {
            var c = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();

            g[c[0], c[1]] = c[2];
            g[c[1], c[0]] = c[2];
        }


        dijkstra(0);

        int mst = 0;
        for (int i = 0; i < p.Length; i++) {
            if (p[i] != -1) {
                mst += g[p[i], i];
            }
        }

        Console.WriteLine(mst);
    }
}



Measured memory_bytes: 413560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define A_MAX 200

int calcSumKeta(int Num)
{
  int sum=0;
  for(int i=0; i< 5; i++)
  {
    sum += Num%10;
    if(Num==0)break;
    Num /= 10;
  }
  return sum;
}

int main(void)
{
  int N, A, B;
  cin >> N >> A >> B;
  
  int ret;
  int sum=0;
  for(int i=1; i<=N; i++)
  {
    ret = calcSumKeta(i);
//    cout << i << " : " << ret << endl;
    if( ret >= A && ret <=B)
    {
      sum += i;
//      cout << "sum : " << sum << endl;
    }
  }
  cout << sum;
  return 0;
}

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

int main() {
    int n,p;
    cin >> n;
    int a=0;
    for (int i=0;i<n;i++) {
        cin >> p;
        if (i+1!=p) a++;
    }
    
    if (a<=2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import math
n = int(readline())
m = int(math.sqrt(n))
l = []
for a in range(1, m + 1):
    if n % a == 0:
        b = n // a
        c = max(len(str(a)), len(str(b)))
        l.append(c)
print(min(l))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=250000+50;
ll  num[maxn];
ll sum[maxn];
ll he(ll n){
        if(n==1)
                return 0;
        if(n==0)
                return 0;
        return (n*(n-1))/2;
}
map<ll,int>mp;
int main()
{
    //std::ios::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    long long summ=0;
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++){
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++){
        if(mp[sum[i]]==0)mp[sum[i]]++;
        else{
                mp[sum[i]]++;
        }

    }
    map<ll,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        //cout<<it->first<<" "<<it->second<<endl;
        if(it->first==0)
        summ+=(he(it->second)+(it->second));
        else if(it->second>1){
                if(it->first!=0)
                        summ+=he(it->second);

        }

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

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

using namespace std;
typedef long long ll;

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<vector<char>> ar(n, vector<char>(m, 0));
    for (int x = 0; x < n; x++)
    {
        string s;
        cin >> s;
        for (int y = 0; y < m; y++)
        {
            ar[x][y] = s[y];
        }
    }
    vector<vector<ll>> ans(n, vector<ll>(m, 0));
    ans[0][0] = 1;
    ll num = 0;
    while (num <= (n - 1 + m - 1))
    {
        for (int x = 0; x < n; x++)
        {
            int y = num - x;
            if (y >= 0 && y < m)
            {
                if (ar[x][y] != '#')
                {
                    if (x > 0)
                    {
                        ans[x][y] += ans[x - 1][y];
                    }
                    if (y > 0)
                    {
                        ans[x][y] += ans[x][y - 1];
                    }
                    ans[x][y] %= ((ll)1e9 + 7);
                }
            }
        }
        num++;
    }
    cout << ans[n - 1][m - 1] << endl;
}

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

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
const int N=1e5+5;

int mod=1e9+7;
//int cache[N];
//int a[N];
int n,k;

int a[N][4];
int cache[N][4];
int dp(int idx,int prev){
    if(idx==n+1) return 0;

    int &ans=cache[idx][prev];
    if(ans!=-1) return ans;
    else ans=0;


        for(int j=1;j<=3;j++){
            if(j==prev) continue;
            ans=max(ans,dp(idx+1,j)+a[idx][j]);
        }


    return ans;
}

int32_t main() {
    faster;

    cin>>n;
    memset(cache,-1,sizeof(cache));

    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++) cin>>a[i][j];
    }

    cout<<dp(1,0)<<endl;
}

Measured memory_bytes: 12800
LI=lambda:list(map(int,input().split()))
MI=lambda:map(int,input().split())
I=lambda:input()

n=int(I())
p=LI()
a=[i+1 for i in range(n)]
if a==p:print("YES");exit()
b=0
for i in range(n):
  if a[i]!=p[i]:b+=1
if b==2:print("YES")
else:print("NO")

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            int a1 = int.Parse(str[0]);
            int a2 = int.Parse(str[1]);
            int a3 = int.Parse(str[2]);
            if (a1 + a2 + a3 <= 21)
            {
                Console.WriteLine("win");
            }
            else
            {
                Console.WriteLine("bust");
            }
        }
        
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;

namespace Allocation
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Array.ConvertAll(Console.ReadLine()
                        .Split(), e => int.Parse(e));
            
            int n = input[0], k = input[1];

            var w = new int[n];

            int maxw = 0, sumw = 0;

            for (var i = 0; i < n; i++)
            {
                var num = int.Parse(Console.ReadLine());
                sumw += num;
                w[i] = num;
            }

            maxw = w.Max();

            var minp = 0;

            if (1 == k)
                minp = sumw;
            else if (n == k)
                minp = maxw;
            else
            {
                var left = maxw;
                var right = 100000*10000;

                while (left <= right)
                {
                    var middle = (left + right) / 2;
                    int trucknt = 0, loadings = 0;

                    for (var i = 0; i < n; i++)
                    {
                        loadings += w[i];

                        if (middle < loadings)
                        {
                              trucknt += 1;
                              if (k < trucknt + 1) break;
                              loadings = w[i];
                        }
                    }

                    if (trucknt + 1 <= k)
                        minp = middle;
                    
                    if  (k < trucknt + 1)
                        left = middle + 1;
                    else
                        right = middle - 1;
                }
            }

            Console.Write("{0}\n", minp);
        }
    }
}

Measured memory_bytes: 10232
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

int a, b, c, N, M, K;
string s;


int main(){
    cin>>N>>a>>b;
    if((b-a)%2) p("Borys");
    else p("Alice");
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a[5];
    cin>>a[1]>>a[2]>>a[3];
    int ans=(1<<30);
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++)
            for(int k=1;k<=3;k++)
            {
                if(i==j)continue;
                if(i==k)continue;
                if(j==k)continue;
                ans=min(ans,abs(a[i]-a[j])+abs(a[j]-a[k]));
            }
    cout<<ans<<"\n";
    return 0;
}
/**



**/


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

int main()
{
	int n,a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int v;
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			v = a[i];
			for (int j = i-1; j >= 0; j--) {
				if (a[j] > v) {
					a[j + 1] = a[j];
					a[j] = v;
				}
			}
		}

		for (int j = 0; j < n; j++) {
			printf("%d", a[j]);
			if (j != n - 1) printf(" ");
		}
		printf("\n");
	}

	return 0;
}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
//#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define Sort(v) sort(all(v))


/* constant */
//const int inf = 100100100100100100;
const int mod = 998244353;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }
vector<int> cs(vector<int> arr){vector<int> tmp;if(arr.size() == 0) return tmp;tmp.push_back(arr[0]);rep(i,1,arr.size()){tmp.push_back(tmp.back() + arr[i]);}return tmp;}

/* math_library */
int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b);}
int lcm(int a, int b){ return a * b / gcd(a,b);}
int ceil(int a, int b){ if(a % b == 0) return a/b; else return a/b + 1;}
int digitlen(int n){int t = n;int cnt = 0;while(t){cnt++;t /= 10;}return cnt;}
bool isprime(int n){if(n < 2) return false;if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;for(int i = 7; i * i < n + 1; i += 2){if(n % i == 0) return false;}return true;}
int mod_pow(int x, int n, int m){if(n== 0) return 1;int res = mod_pow(x*x%m,n/2,m);if(n&1) res = res*x%m;return res;}
int digitsum(int n){int ret = 0;while(n){ret += n % 10;n /= 10;}return ret;}



/* main */


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int c[3][3];

    rep(i,0,3){
        rep(j,0,3){
            cin >> c[i][j];
        }
    }

    int a[3]; a[0] = 0;

    int b[3];

    rep(i,0,3){
        b[i] = c[0][i];
    }

    rep(i,1,3){
        a[i] = c[i][0] - b[0];
    }

    rep(i,0,3){
        rep(j,0,3){
            if(a[i] + b[j] != c[i][j]){
                print("No");
                return 0;
            }
        }
    }

    print("Yes");


}






    










    




    










Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

// 最大公約数
LL gcd(LL v1, LL v2){
    assert(v2 > 0);
    if(v1 < v2) swap(v1, v2);
    if(v1 % v2 == 0) return v2;
    return gcd(v2, v1 % v2);
}


bool is_prime(LL v){
    if(v <= 1) return false;
    if(v == 2 || v == 3) return true;
    for(LL i = 2; i*i <= v; ++i){
        if(v % i == 0) return false;
    }
    return true;
}

int main(){
    LL a, b;
    cin >> a >> b;
    LL c = gcd(a, b);
    LL ans = 1;
    for(LL i = 1; i*i <= c; ++i){
        if(c % i == 0){
            if(is_prime(i)) ans += 1;
            if(c/i > i && is_prime(c/i)) ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int bikkuri(int x){
    if(x == 0)return 1;
    else return x *= bikkuri(x-1);
}

int main(){
    int N;
    cin >> N;
    //vector<vector<int>> all(bikkuri(N),vector<int>(N));
    int p[N];
    int q[N];
    vector<int> a(N);
    int P,Q;
    Rep(i,N){
        cin >> p[i];
        a[i] = i+1;
    }
    Rep(i,N)cin >> q[i];
    int cnt = 0;
    do{
        Rep(i,N+1){
            if(i == N)P = cnt;
            else if(p[i] == a[i]);
            else break;
        }
        Rep(i,N+1){
            if(i == N)Q = cnt;
            else if(q[i] == a[i]);
            else break;
        }
        cnt++;
    }while(next_permutation(All(a)));
    cout << abs(P-Q) << endl;
    //cin >> N;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long

typedef struct{
	int parent;
	int right;
	int left;
	int dep;
	int h;
	int ch;
	//子供って房全部じゃないんかーーい
	int realch;
} node2;

node2 t[50];
int depcnt[50],deep;
int Preorder(int now,int dep){/*
	cout<<dep<<endl;
	fordebug*/
	depcnt[dep]++;
	t[now].dep=dep;
	deep=max(dep,deep);
	int cnr=0,cnl=0,realcn=0;
	if(t[now].left!=-1)cnr=Preorder(t[now].left,dep+1),realcn++;
	if(t[now].right!=-1)cnl=Preorder(t[now].right,dep+1),realcn++;
	t[now].ch=realcn;
	t[now].h=max(cnr,cnl);
	return max(cnr,cnl)+1;
}

int sib(int now){
	if(t[now].parent==-1) return -1;
	int p=t[now].parent;
	if(t[p].right==now) return t[p].left;
	else return t[p].right;
}

signed main(){
	int n;
	cin>>n;
	lp(i,50){
		t[i].parent=-1;
	}	
	lp(i,n){
		int id;
		cin>>id;
		int r,l;
		cin>>l>>r;
		t[id].right=r;
		t[id].left=l;
		if(r!=-1)t[r].parent=id;
		if(l!=-1)t[l].parent=id;
	}
	queue<int> q;
	int now=0;
	while(1){
		if(t[now].parent==-1) break;
		now=t[now].parent;
	}
	Preorder(now,0);
	lp(i,n){
		cout<<"node "<<i<<": parent = "<<t[i].parent<<", sibling = ";
		cout<<sib(i)<<", degree = "<<t[i].ch;
		cout<<", depth = "<<t[i].dep<<", height = "<<t[i].h<<", ";
		if(t[i].parent==-1) cout<<"root";
		else if(t[i].ch==0) cout<<"leaf";
		else cout<<"internal node";
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
ans = []

while (1) :
    word = input().strip()
    try :
        inputLen = int( input().strip() )
    except :
        break 

    for i in range(0, inputLen) :
        h = int( input().strip() )
        word = word[h:] + word[:h]

    ans.append(word)

for s in ans :
    print(s)



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

# 何回変えるか
count = 0

i = 0

while i < N - 1:
    j = 1
    while A[i + j] == A[i]:
        j += 1
        if i + j > N-1:
            break

    count += int(j / 2)
    i = i + j

print(count)
        


Measured memory_bytes: 2940
n = input()
m = len(n)
n = int(n)
if n%2==1:
    print(0)
else:
    if m==1:
        print(0)
    else:
        ans = 0
        i = 1
        while  True:
            ans_plus=n//(2*5**i)
            if ans_plus==0:
                break
            ans += ans_plus
            
            i += 1
        print(ans)

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool yes = false;
    for (int i = 1; i <= b; i++) {
        if (a*i%b == c) yes = true;
    }
    if (yes) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int main()
{
  int N, A, B;

  cin >> N >> A >> B;

  int ret = 0;
  for(int i = 0; i < N; i++) {
    int T;
    cin >> T;
    if(A <= T && T < B) ++ret;
  }

  cout << N - ret << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> Paint;

int main(){
  vector<Paint> a;
  for(int i = 0; 6 > i; i++){
    int te,mp;cin>>te>>mp;
    if(te < mp)swap(te,mp);
    a.push_back(make_pair(te,mp));
  }
  sort(a.begin(),a.end());
  vector<int> b;
  for(int i = 0; 6 > i; i+=2){
    if(!(a[i].first==a[i+1].first&&a[i].second==a[i+1].second)){
      cout << "no" << endl;
      return 0;
    }else{
      b.push_back(a[i].first);
      b.push_back(a[i].second);
    }
  }
  int x = b[0];
  int y = b[1];
  
  for(int i = 2; 4 > i; i++){//23
    for(int j = 4; 6 > j; j++){//45
      if(min(x,y) == min(b[i],b[j]) && max(x,y) == max(b[i],b[j])){
        if(b[(i==2?3:2)] == b[(j==4?5:4)]){
          cout << "yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "no" << endl;
}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A + B == C + D)
    {
        cout << "Balanced";
    }
    else if (A + B > C + D)
    {
        cout << "Left";
    }
    else
    {
        cout << "Right";
    }
}

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

int main() {
	int A, B, K;
	cin >> A >> B;
	if ((A + B) % 2 == 0){
		K = (A + B) / 2;
		cout << K << endl;
	}
	else {
		printf("IMPOSSIBLE");
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in6.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        string s; cin >> s;
        if(s[s.length()-1] == 's') cout << s + "es";
        else cout << s + "s";
        cout << '\n';
    }
    return 0;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

#define pi 3.1415926535897932384626433832
const int pinf=LLONG_MAX;
const int ninf=LLONG_MIN;
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("../in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int r,d,a;
    cin>>r>>d>>a;

    vector <int> ans(11);
    ans[0]=a;
    loop(i,1,11)
    {
        ans[i]=ans[i-1]*r-d;
        cout<<ans[i]<< "\n";
    }



    return 0;
}


Measured memory_bytes: 3608
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using  namespace std;
int main(void){
	int N=0,count=0,a[2],maxs=0;
	a[1]=0;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>a[0];
		if(a[0]<=a[1]){
			count++;
		}
		else{
			maxs=max(maxs,count);
			count=0;
		}
		a[1]=a[0];
	}
	maxs=max(maxs,count);
	cout<<maxs<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	//0140 start
	//0200 end
	//0430 restart
	//0442 sample match WA
	//0509 WA * 2
	//0920 WA * 2
	
	class C{
		int count, rest;
		ArrayList<Integer> list;
		public C(int count, int rest) {
			this.count = count;
			this.rest = rest;
			this.list = new ArrayList<Integer>();
		}
		
		private void sort(){
			Collections.sort(this.list);
		}

		@Override
		public String toString() {
			return "C [count=" + count + ", rest=" + rest + ", list=" + list.toString()
					+ "]";
		}
		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-- > 0){
			ArrayList<Integer> input = new ArrayList<Integer>();
			int inputnum = sc.nextInt();
			while(inputnum != 0){
				input.add(inputnum);
				inputnum = sc.nextInt();
			}
			
			ArrayList<C> rooms = new ArrayList<C>();
			int first = input.get(0);
			int nowroom = 0;
			rooms.add(new C(0, first));
			for(int i = 1; i < input.size(); i++){
				int nownum = input.get(i);
				if(nownum < 0){
					//nownumのcount を探す
					int find = rooms.get(nowroom).count + nownum;
					for(int j = nowroom - 1; j >= 0; j--){
						if(rooms.get(j).count == find){
							//つなげる
							rooms.get(nowroom).rest--;
							rooms.get(nowroom).list.add(j + 1);
							
							//反対側
							rooms.get(j).rest--;
							rooms.get(j).list.add(nowroom + 1);
							break;
						}
					}
					
				}
				else{
					int nextcount = rooms.get(nowroom).count + 1;
					rooms.add(new C(nextcount, nownum));
					int nextroomid = rooms.size() - 1;
					
					//つなげる
					rooms.get(nowroom).rest--;
					rooms.get(nowroom).list.add(nextroomid + 1);
					
					//反対側
					rooms.get(nextroomid).rest--;
					rooms.get(nextroomid).list.add(nowroom + 1);
				}
				//次のnowroomを探す
				for(int j = rooms.size() - 1; j >= 0; j--){
					if(rooms.get(j).rest > 0){
						nowroom = j;
						break;
					}
				}
			}
			
			for(int i = 0; i < rooms.size();i++){
				int rest = rooms.get(i).rest;
				if(rest > 0 && rest % 2 == 0){
					for(int j = 0; j < rest / 2; j++){
						rooms.get(i).list.add(i + 1);
					}
				}
			}
			
			for(int i = 0; i < rooms.size(); i++){
				rooms.get(i).sort();
			}
			
			//print
			for(int i = 0; i < rooms.size(); i++){
				System.out.print((i + 1));
				for(int j = 0; j < rooms.get(i).list.size(); j++){
					System.out.print(" " + rooms.get(i).list.get(j));
				}
				System.out.println();
			}
			
			//debug
//			System.out.println("debug = ");
//			for(int i = 0; i < rooms.size(); i++){
//				System.out.println(rooms.get(i));
//			}
		}
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 924844033;

vector<pii> G[MX];
int label[MX], vst[MX];
ll cnt[3];
int N, M, a, b;

void dfs(int x)
{
	for(pii c : G[x]){
		int u = c.first, v = c.second;
		if( label[u] != -1 ) continue;
		label[u] = (label[x] + v) % 3;
		dfs(u);
	}
}

ll ans = 0, ch = 0, cur = 0;

void solve(int x){
	if( vst[x] ) return;
	vst[x] = 1; cnt[label[x]] += 1;
	for(pii c : G[x]){
		cur++;
		int u = c.first, v = c.second;
		if( label[u] != (label[x] + v) % 3 ) ch = 1;
		solve(u);
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a].emplace_back(b, 1);
		G[b].emplace_back(a, 2);
	}
	for(int i = 1; i <= N; i++) label[i] = -1;
	for(int i = 1; i <= N; i++){
		if( label[i] != -1 ) continue;
		label[i] = 0;
		dfs(i);
	}
	for(int i = 1; i <= N; i++){
		if( vst[i] ) continue;
		ch = 0; cur = 0; cnt[0] = cnt[1] = cnt[2] = 0;
		
		solve(i);

		ll tot = cnt[0] + cnt[1] + cnt[2];
		if( ch ) ans += tot * tot;
		else if( cnt[0] && cnt[1] && cnt[2] ) ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
		else ans += cur/2;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 13568
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
  long N;
  cin >> N;
  vector<long> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  long cnt = 0;
  for(int i=0; i<N; i++){
    if(a[i] == cnt + 1){
      cnt = cnt + 1;
    }
  }
  if(cnt == 0){
    cout << -1;
    return 0;
  }
  cout << N - cnt;
  return 0;
  
}




Measured memory_bytes: 1792
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	
	int x = read.to!int;
	int y = read.to!int;
	int z = read.to!int;
	
	auto xh = new RedBlackTree!(X, "a.a-a.b>b.a-b.b", true);
	auto yh = new RedBlackTree!(X, "a.a-a.c>b.a-b.c", true);
	auto zh = new RedBlackTree!(X, "a.b-a.c>b.b-b.c", true);
	
	X[] ss;
	foreach(i; 0 .. x + y + z){
		X q = new X(i, read.to!long, read.to!long, read.to!long);
		ss ~= q;
		xh.insert(q);
		yh.insert(q);
		zh.insert(q);
		q.value = 3;
		log("i:", i);
		log("xh:", xh[]);
		log("yh:", yh[]);
		log("zh:", zh[]);
	}
	
	foreach(i; 0 .. y){
		X q = zh.front;
		q.value = 2, zh.removeFront;
	}
	log("ss:", ss);
	log("zh:", zh[]);
	
	foreach(i; 0 .. x){
		while(xh.front.value != 2) xh.removeFront;
		while(yh.front.value != 3) yh.removeFront;
		while(zh.front.value != 3) zh.removeFront;
		X p = xh.front, q = zh.front;
		X r = yh.front;
		if(p.a - p.b + q.b - q.c > r.a - r.c){
			p.value = 1, xh.removeFront;
			q.value = 2, zh.removeFront;
		}
		else{
			r.value = 1, yh.removeFront;
		}
		log("i:", i);
		log("p:", p, "q:", q, "r:", r, );
		log("ss:", ss);
		log("xh:", xh[]);
		log("yh:", yh[]);
		log("zh:", zh[]);
	}
	
	long ans;
	foreach(q; ss){
		if(q.value == 1) ans += q.a;
		else if(q.value == 2) ans += q.b;
		else ans += q.c;
	}
	
	ans.writeln;


}
class X{
	int id;
	long a, b, c;
	int value;
	this(int id, long a, long b, long c){
		this.id = id, this.a = a, this.b = b, this.c = c;
	}
	override string toString(){
		return [a, b, c].to!string ~ value.to!string;
	}
}

/*
定員を徐々に増やしていくと考える。

初めは銅だけがx+y+z人と決まっているとする。
もちろん全員が銅になる。

次に、銅をy人減らして銀をy人増やすとする。
(b - c)の大きいものからy人を移動の対象にすればよい。

最後に、銅をx人減らして金をx人増やすとする。
ここは難しいので1人ずつ増やしていく。
その際は、
　(a) 銅から1人を金に移動する
　(b) 銅から1人を銀に移動し、銀から1人を金に移動する
どちらかの動きをする。

(a)については、(a - c)の最も大きいもの。
(b)については、(b - c)の最も大きいものと(a - b)の最も大きいもの。

良い方をすればよい。

以下検索ワード
赤黒木 優先度付きキュー 優先度つきキュー rbt rbtree redblacktree

*/


Measured memory_bytes: 31100
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

int main(){
  string s,t;
  cin >> s >> t;
  int n = s.size();
  string ans = "No";
  for (int i = 0; i < n; i++) {
    if(s == t){
      ans = "Yes";
      break;
    }
    s = s.back() + s.substr(0,n-1);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
#include <tuple>
 
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (ll (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (ll (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (ll (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (ll (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'
 
#define test if(1)if(0)cerr
using namespace std;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
 
const int maxn = 1e2;
int n, m, cnt[maxn];
 
int main()
{
    cin >> n >> m;
    rep(i, m)
    {
        int a, b;   cin >> a >> b;
        cnt[a] += 1, cnt[b] += 1;
    }
    repn(i, n)
    {
        cout << cnt[i] << newline;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 998244353;
int main() {
  int N;
  cin >> N;
  vector<P> Robot(N);
  for (int i = 0; i < N; i++) {
    cin >> Robot[i].F >> Robot[i].S;
  }
  sort(Robot.begin(),Robot.end());
  ll DP[N+1];
  for (int i = 0; i <= N; i++) {
    DP[i] = 0;
  }
  int at[N];
  int depend[N];
  for (int i = 0; i < N; i++) {
    at[i] = -1;
    depend[i] = -1;
  }
  for (int i = 0; i < N-1; i++) {
    ll s = Robot[i].S;
    bool fin = false;
    for (int j = i + 1; j < N; j++) {
      ll d = Robot[j].F - Robot[j-1].F;
      s -= d;
      if (s <= 0) {
        at[i] = j-1;
        break;
      }
      if (s <= Robot[j].S) {
        depend[i] = j;
        break;
      }
      if (j == N-1) {
        fin = true;
      }
    }
    if (fin) {
      at[i] = N-1;
    }
  }
  at[N-1] = N-1;
  for (int i = 0; i < N-1; i++) {
    int a = i;
    vector<int> l = {};
    while (depend[a] != -1) {
      a = depend[a];
      l.push_back(a);
    }
    at[i] = at[a];
    for (int j = 0; j < (int)l.size() - 1; j++) {
      depend[l[j]] = a;
    }
  }
  DP[0] = 1;
  for (int i = 0; i < N; i++) {
    DP[i+1] += DP[i];
    DP[at[i]+1] += DP[i];
    DP[i+1] %= Mod;
    DP[at[i]+1] %= Mod;
  }
  cout << DP[N] << endl;
  return 0;
}

Measured memory_bytes: 9864
Num_list = list(map(int,list(input())))
ops = 3
Anser = 7


for i in range(2 ** ops):
  sum0 = Num_list[0]
  str0 = str(Num_list[0])
  k = 1

  for j in range(ops-1,-1,-1):
    if((i >> j) & 1):
      sum0 = sum0 + Num_list[k]
      str0 = str0 + '+' + str(Num_list[k])
      k = k + 1
    else:
      sum0 = sum0 - Num_list[k]
      str0 = str0 + '-' + str(Num_list[k])
      k = k + 1
  
#  print(sum0)
#  print(str0)
#  print('===')
  
  if(sum0 == Anser):
    print(str0 + '=7')
    break;



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

int main(){
  int N, X;
  cin >> N >> X;
  int L[N];
  for(int i=0; i<N; i++) cin>>L[i];
  int x=0,i;
  for(i=0; x<=X&&i<=N; i++) x+=L[i];
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
#define PI 3.141592
using namespace std;

struct ranp {
	bool adapt[10];
	int size;
	bool isOn(bool env[10], int m2, int n)
	{
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (adapt[i] && env[i]) {
				sum++;
			}
		}
		if (sum % 2 == m2) {
			return true;
		} else {
			return false;
		}
	}
	ranp()
	{
		for (int i = 0; i < 10; i++) {
			adapt[i] = false;
		}
	}
};

int ipow(int x, int y)
{
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}
	return z;
}

void bina(int x, bool f[10], int n)
{
	for (int i = 0; i < n; i++) {
		if (x % 2) {
			f[i] = true;
		} else {
			f[i] = false;
		}
		x /= 2;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	bool flag[10];
	int ans = 0;
	int max = ipow(2, n);
	ranp* ob = new ranp[m];
	vector<int> whitch(m);
	bool ok;

	for (int i = 0; i < m; i++) {
		cin >> ob[i].size;
		int num;
		for (int j = 0; j < ob[i].size; j++) {
			cin >> num;
			ob[i].adapt[num - 1] = true;
		}
	}

	for (int i = 0; i < m; i++) {
		cin >> whitch[i];
	}

	for (int i = 0; i < max; i++) {
		bina(i, flag, n);
		ok = true;
		for (int j = 0; j < m; j++) {
			if (!ob[j].isOn(flag, whitch[j], n)) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans++;
		}
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 256
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

// int num_val = 1e5 + 1;

int func(P arr[] , int n , int V){

    //base cases
    int num_val = n*1000;
    int dp[105][num_val + 1];

  
    for(int i = 0 ; i<=  num_val ; i++){

        // for(int j=1; j<=n; j++) {
            dp[1][i] = inf; // as it is impossible to fill with these weights

        // }
    }
  
    //db(dp[n][100001]);

    dp[1][0] = 0; //as no weights will be required
    dp[1][arr[1].S] = arr[1].F;
  
    //for(int i=1 ; i<= n ; i++)
      //dp[i][0] = 0;

    //now we need to write the recurrence

    for(int i=2 ; i<= n ; i++){

        // dp[i][j] = dp[i-1][]

        for(int j=0; j<= num_val; j++) {

            dp[i][j] = dp[i-1][j];

            if(j - arr[i].S < 0) continue;
                dp[i][j] =  min(dp[i][j] ,  arr[i].F + dp[i-1][j - arr[i].S]);
        }
    }

    int ans = 0;

    for(int i=0; i<=num_val; i++) {

        if(dp[n][i] <= V){
            ans = max(i , ans);
        }
    }
  
    // db(dp[n][10001]);

    return ans;

}

void solve(){

    int n,V ,a,b,c, ans=0, count=0, sum=0;
    cin>>n>>V;
    P arr[n +1];
    //F->weight , S->value

    for(int i=1;i<=n;i++){
      cin>>arr[i].F>>arr[i].S;
    }

    ans = func(arr , n , V);

    cout<<ans<<endl; 
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 81744
h, w = gets.chomp.split(' ').map(&:to_i)
A = []
h.times do
 A << gets.chomp.split('').push('x').unshift('x')
end
A.push(Array.new(w+2, "x"))
A.unshift(Array.new(w+2, "x"))

1.upto(h) do |i|
  0.upto(w) do |j|
    if A[i][j+1] == "."
      n = [A[i-1][j], A[i][j], A[i+1][j], A[i-1][j+1], A[i+1][j+1], A[i-1][j+2], A[i][j+2], A[i+1][j+2]]
      x = n.find_all{|item| item =="#"}.count
      A[i][j+1] = x
    end
  end
end

1.upto(h) do |i|
  A[i].pop
  A[i].shift
  puts A[i].join('')
end


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

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

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

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

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int I[100][20];

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	ll ans = 0;
	rep(i, n) {
		cin >> a[i];
		a[i]--;
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 1; i <= min(a, b); i++) {
		if (a % i == 0 && b % i == 0)ans = i;
	}



	
	cout << (a/ans)*(b/ans) * c << endl;
}



Measured memory_bytes: 3132
n=int(input())
A = list(map(int,input().split()))
from itertools import accumulate
S = [0] + list(accumulate(A))
dp = [[0]*(n+1) for _ in range(n+1)]
for d in range(2,n+1):
    for i in range(n-d+1):
        j = i+d
# for i in range(n+1):
#     for j in range(i+1,n+1):
        val = float('inf')
        for k in range(i+1,j):
            val = min(val,dp[i][k]+dp[k][j])
        dp[i][j] += S[j]-S[i] + val
print(dp[0][-1])

Measured memory_bytes: 75540
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
            --a[i][j];
        }
    }
    for (int lim = 1; lim <= n; ++lim) {
        vector<int> active(m, 1);
        vector<int> pt(n, 0);
        vector<int> cnt(m, 0);
        for (int i = 0; i < n; ++i)
            ++cnt[a[i][0]];
       
        vector<int> del;
        for (int i = 0; i < m; ++i) {
            if (cnt[i] > lim)
                del.push_back(i);
        }

        for (; sz(del) > 0;)  {
            for (int el : del)
                active[el] = 0;
            del.clear();
            cnt.assign(m, 0);
            for (int i = 0; i < n; ++i) {
                for (; pt[i] < m && !active[a[i][pt[i]]]; ++pt[i]);
                if (pt[0] == m)
                    break;
                ++cnt[a[i][pt[i]]];
            }
            if (pt[0] == m)
                break;

            for (int i = 0; i < m; ++i) {
                if (cnt[i] > lim)
                    del.push_back(i);
            }
        }
        if (pt[0] < m) {
            cout << lim << endl;
            return 0;
        }
    }

    assert(false);


}


Measured memory_bytes: 640
import sys

file_input = sys.stdin

H, W, N = map(int, file_input.readline().split())

town_map = 'X' * (W + 2)
for line in file_input:
    town_map += 'X' + line.rstrip() + 'X'
town_map += 'X' * (W + 2)

move = (1, -1, W + 2, -W - 2)

from collections import deque

def search(start_pos, goal_lot):
    mouse = [start_pos, 0] # [position, elapsed time]
    q = deque()
    unvisited = [True] * len(town_map)
    unvisited[start_pos] = False
    while True:
        cur_pos = mouse[0]
        for d in move:
            next_pos = cur_pos + d
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal_lot:
                    return (next_pos, mouse[1] + 1)
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        mouse = q.popleft()

def solve():
    start_pos = town_map.find('S')
    time = 0
    for i in range(1, N + 1):
        start_pos, t = search(start_pos, str(i))
        time += t
    print(time)

solve()


Measured memory_bytes: 14840