akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.SoundHound2018.C
{
    class Program
    {
        static void Main ()
        {
            var sc = new Scanner ();
            var n = sc.Nextint ();
            var m = sc.Nextint ();
            var d = sc.Nextint ();

            var cnt = 0d;
            if (d == 0) cnt = n;
            else cnt = 2d * (n - d);
            var result = cnt * (m - 1d) / n / n;
            Console.WriteLine (result);
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner ()
        {
            s = new string[0];
            i = 0;
        }

        public string Next ()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine ();
            while (st == "") st = Console.ReadLine ();
            s = st.Split (cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next ();
            i = 0;
            return s[i++];
        }

        public int Nextint ()
        {
            return int.Parse (Next ());
        }
        public int[] Arrayint (int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint () + add;
            }
            return Array;
        }

        public long NextLong ()
        {
            return long.Parse (Next ());
        }

        public long[] ArrayLong (int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong () + add;
            }
            return Array;
        }

        public double NextDouble ()
        {
            return double.Parse (Next ());
        }

        public double[] ArrayDouble (long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble () + add;
            }
            return Array;
        }

        public decimal NextDecimal ()
        {
            return decimal.Parse (Next ());
        }

        public decimal[] ArrayDecimal (long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal ();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,d[256],i,j,k,l,r;
main(){
	cin>>n>>a>>b>>c;
	for(i=0;i<n;i++){
		cin>>l;
		for(j=0;j<=k;j++)d[j+k+1]=d[j]+l;
		k+=k+1;
	}
	r=d[0]=5e8;
	for(i=0;i<=k;i++)for(j=0;j<=k;j++)r=min(r,abs(d[i&j]-a)+abs(d[i&~j]-b)+abs(d[j&~i]-c)+__builtin_popcount(i|j)*10);
	cout<<r-30<<endl;
}


Measured memory_bytes: 256
//you**can**do**anything 
#include <bits/stdc++.h> 
#define ll long long
#define pk push_back		
const ll maxn=2e5+1;
using namespace std;   
void solve()
{
	
}

int main()
{

ll n , ans =0  ,cur ;
cin>>n ;
vector<ll>a(n) ;
for(int i=0 ;i< n ;i++)
{
	cin>>a[i] ;
	if(i>0)
	{
	//	cout<<""
		if(a[i-1]>a[i])
		{
			cur = (a[i-1] - a[i]);
			ans+=cur ;
			a[i]+=cur ;
		}
		
		//continue ;
	}
//	cout<<a[i]<<" ";
}

cout<<ans;  

}

Measured memory_bytes: 4836
#include <iostream>
#include <algorithm>

using namespace std;

int n,l;
int a[205];

int cmp(int a,int b){
	return abs(a)<abs(b);
}
int main(){
	cin>>n>>l;
	for(int i=1;i<=n;i++){
		a[i]=l+i-1;
	}
	sort(a+1,a+n+1,cmp);
	
	cout<<((n+1)*n)/2+(l-1)*n-a[1];
	return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    s = list(map(int, list(input())))

    # Cumulative Sum
    cs = [0]
    now = 1
    cnt = 0
    for i in s:
        if i == now:
            cnt += 1
        else:
            cs.append(cs[-1] + cnt)
            now = i
            cnt = 1
    cs.append(cs[-1] + cnt)
    if now == 0:
        cs.append(cs[-1])

    if len(cs) - 2*k - 1 < 1:
        print(n)
    else:
        ans = 0
        for i in range(0, len(cs)-2*k-1, 2):
            cnt = cs[i + 2*k + 1] - cs[i]
            if ans < cnt:
                ans = cnt
        print(ans)

main()

Measured memory_bytes: 87980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
typedef double db;
db pi=acos(-1.0);
const int N=3010;
int n,l,t[N];
db ansx,ansy;

int main() {
	scanf("%d%d",&n,&l);
	rep(i,0,n) scanf("%d",t+i);
	rep(i,0,n) rep(j,i+1,n) {
		db c=(t[i]+t[j])*pi/l;
		db px=cos(c),py=sin(c);
		ansx+=px*(2*(j-i)-n);
		ansy+=py*(2*(j-i)-n);
	}
	db tot=(db)n*(n-1)*(n-2)/6;
	printf("%.10f %.10f\n",-ansx/tot,-ansy/tot);
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long 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...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}
int disum(int n){
	int sum=0;

	while(n){

		sum+=n%10;
		n/=10;





	}
	return sum;




}
int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
  	string s;
  	cin>>s;


  	bool one=false,two=false,three=true;



  	if(s[0]=='A') one=true;

  	for (int i = 2; i < s.size()-1; ++i)
  	{
  		/* code */
  		if(s[i]=='C') c++;
  	}
  	if(c==1)
  		two=true;

  	for(char ch:s){

  		if(ch=='A' || ch=='C')
  			continue;
  		if(!islower(ch)) three =false;




  	}

  	// watch3(one,two,three);

  	if(one and two and three){
  		cout<<"AC"<<endl;
  	}else
  	cout<<"WA"<<endl;



}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[1000][1000]; 
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}
int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++)for (int j=1;j<=m;j++)while (s[i][j]!='.'&&s[i][j]!='#')s[i][j]=getchar();
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=m;j++)
			if ((i==1||(j&1)||s[i][j]=='#')&&i!=n)putchar('#');else putchar('.');
	puts("");
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=m;j++)
			if ((i==n||!(j&1)||s[i][j]=='#')&&i!=1)putchar('#');else putchar('.');
}


Measured memory_bytes: 1280
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
a, b, n = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

def calc(x):
    return (math.floor(a*x/b)-a*math.floor(x/b))

    
if b > n:
    print(calc(n))
else:
    print(calc(b-1))
    


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    //各マスまでの到達コストの初期値を定義
    const int INF = pow(10, 9);
    //各マスからの移動方法を定義
    const vector<int> di = {-1, 0, 1, 0};
    const vector<int> dj = {0, -1, 0, 1};
    //入力
    int H, W;
    cin >> H >> W;
    int si, sj;
    int gi, gj;
    cin >> si >> sj;
    cin >> gi >> gj;
    //配列で扱うため、0-indexに直す
    si--; sj--; gi--; gj--;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vector<vector<int>> dist(H, vector<int>(W, INF));
    //dequeのデータ構造を用意
    deque<pair<int, int>> q;
    //始点の情報を更新、dequeに格納
    dist[si][sj] = 0;
    q.emplace_back(si, sj);

    //01-BFS開始
    while(!q.empty()){
        //dequeから、探索開始点の情報を取得し、dequeから消去
        int i = q.front().first;
        int j = q.front().second;
        //探索開始点の距離情報を取得
        int d = dist[i][j];
        q.pop_front();
        //壁に邪魔されずに移動できる時の方法（縦横に1マスだけ動く場合の動き方）
        rep(v, 4){
            int ni = i + di[v];
            int nj = j + dj[v];
            if(ni >= H || nj >= W || ni < 0 || nj < 0) continue;
            if(s[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            //dequeの先頭から入れる
            q.emplace_front(ni, nj);
        }

        //ワープを用いての移動の方法（周囲5x5マスに移動可能）
        for(int ei = -2; ei <= 2; ei++){
            for(int ej = -2; ej <= 2; ej++){
                int ni = i + ei;
                int nj = j + ej;
                if(ni >= H || nj >= W || ni < 0 || nj < 0) continue;
                if(s[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                //dequeの末尾から入れる
                q.emplace_back(ni, nj);
            }
        }
    }
    int ans = dist[gi][gj];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 9476
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
 int k;
 cin>>k;
 string s;
 cin>>s;
 long long int r[s.size()],g[s.size()],b[s.size()],cnt=0;
 for(int i=0;i<s.size();i++)
 {
     r[i]=0;
     g[i]=0;
     b[i]=0;
 }
 for(int i=s.size()-1;i>=0;i--)
 {
     if(s[i]=='R')
         r[i]++;
         if(s[i]=='G')
             g[i]++;
             if(s[i]=='B')
                 b[i]++;
        if(i<s.size()-1)
        {
        r[i]+=r[i+1];
        g[i]+=g[i+1];
        b[i]+=b[i+1];
        }
 }
 
 for(int i=0;i<s.size()-1;i++)
 {
     for(int j=i+1;j<s.size();j++)
     {
         if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&& s[j]=='R'))
         {
             if(j+1<s.size())
             {
                 cnt+=g[j+1];
             }
             if(2*j-i<s.size())
             {
                 if(s[2*j-i]=='G')
                     cnt--;
             }
         }
         
         if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&& s[j]=='R'))
         {
             if(j+1<s.size())
             {
                 cnt+=b[j+1];
             }
             if(2*j-i<s.size())
             {
                 if(s[2*j-i]=='B')
                     cnt--;
             }
         }
         
         if((s[i]=='G'&&s[j]=='B')||(s[i]=='B'&& s[j]=='G'))
         {
             if(j+1<s.size())
             {
                 cnt+=r[j+1];
             }
             if(2*j-i<s.size())
             {
                 if(s[2*j-i]=='R')
                     cnt--;
             }
         }
     }
 }
     
    cout<<cnt;
 

return 0;   
}

Measured memory_bytes: 3688
#!/usr/bin/env python3
 
# 以下を記述しないとTLEになる, 何故？
import math
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
# ---- ここまで -----------------------

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


Measured memory_bytes: 3972
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Approximate Circle
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n;
	double[] xs, ys;

	void run(){
		n=sc.nextInt();
		xs=new double[n];
		ys=new double[n];
		for(int i=0; i<n; i++){
			xs[i]=sc.nextInt();
			ys[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		double[][] A=new double[3][3];
		double[] b=new double[3];
		for(int i=0; i<n; i++){
			A[0][0]+=sq(xs[i]);
			A[0][1]+=xs[i]*ys[i];
			A[0][2]+=xs[i];
			A[1][0]+=xs[i]*ys[i];
			A[1][1]+=sq(ys[i]);
			A[1][2]+=ys[i];
			A[2][0]+=xs[i];
			A[2][1]+=ys[i];
			A[2][2]+=1;
			b[0]-=xs[i]*(sq(xs[i])+sq(ys[i]));
			b[1]-=ys[i]*(sq(xs[i])+sq(ys[i]));
			b[2]-=sq(xs[i])+sq(ys[i]);
		}
		double[] x=gaussianElimination(A, b);
		println(String.format("%.9f %.9f %.9f", x[0], x[1], x[2]));
	}

	double[] gaussianElimination(double[][] A_, double[] b){
		int n=A_.length;
		double[][] A=new double[n][n+1];
		for(int i=0; i<n; i++){
			System.arraycopy(A_[i], 0, A[i], 0, n);
			A[i][n]=b[i];
		}
		for(int j=0; j<n; j++){
			int pivot=j;
			for(int i=j+1; i<n; i++)
				if(abs(A[i][j])>abs(A[pivot][j]))
					pivot=i;
			double[] t=A[j];
			A[j]=A[pivot];
			A[pivot]=t;
			if(abs(A[j][j])<EPS)
				return null;
			for(int k=j+1; k<n; k++){
				double r=A[k][j]/A[j][j];
				for(int i=j; i<=n; i++)
					A[k][i]-=A[j][i]*r;
			}
		}
		double[] x=new double[n];
		for(int j=n-1; j>=0; j--){
			x[j]=A[j][n];
			for(int i=j+1; i<n; i++)
				x[j]-=x[i]*A[j][i];
			x[j]/=A[j][j];
		}
		return x;
	}

	double sq(double x){
		return x*x;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main() {
    string a,b,c;
    cin>>a>>b>>c;
    string ans="NO";
    if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)) ans="YES";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]


s = set()
for x in ab:
    if n in x:
        if x.index(n) == 0:
            s.add(x[1])
        else:
            s.add(x[0])

for a, b in ab:
    if a in s:
        if b == 1:
            print('POSSIBLE')
            exit()
    if b in s:
        if a == 1:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')


Measured memory_bytes: 84952
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
 
int main() {
	string S;
	cin >> S;
	ll sum=0,N=0;
	REP(i,S.length()){
		sum+=S[i]-'0';
		N+=(S[i]-'0')*pow(10, S.length()-i-1);
	}
	if(N%sum==0) cout <<"Yes"<<endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

int main() {
	ll a, b;
	cin >> a >> b;
	ll r, x, tmp;
	x = a * b;

	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	x /= b;
	cout << x;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
ll h, m;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h;
    ll ans=0;
    ll count=1;
    while(h!=1){
        ans+=count;
        if(h%2==1){
            //ans++;
            h/=2;
            count*=2;
        }
        else{
            h/=2;
            count*=2;
        }
        //cout<<ans<<" "<<count<<"\n";
    }
    cout<<ans+count<<"\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
#define ff first
#define ss second
const int limit= 1e3+1;
ll m[limit][limit];
const int inf = 1e7;
const ll modulo = 1e9 + 7;
int main(){
    int h, w;
    cin>>h>>w;
    char g[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>g[i][j];
        }
    }
    for(int i=1; i<= h; i++){
        for(int j=1; j<= w; j++){
            if(i==1 && j== 1){
                m[i][j] = 1;
            }
            else if(g[i-1][j-1] == '.'){
                m[i][j] = (m[i-1][j]%modulo + m[i][j-1]%modulo)%modulo;
            }
            else{
                m[i][j] = 0;
            }
        }
    }

    cout<<m[h][w]<<endl;
    
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int m, d, cnt = 0;
    cin>>m>>d;
    FOR(i,1,m+1) {
        FOR(j,1,d+1) {
            if ((j%10) > 1 && (j/10) > 1 && i == (j%10) * (j/10))
                cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
#define N 2010

int a,b;
ll C[N][N],pw[N],sum[N][N],ss[N][N],ans;

int main()
{
	scanf("%d%d",&a,&b);
	for (int i=0;i<=b;i++) {
		C[i][0]=1; for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		sum[i][0]=1; for (int j=1;j<=max(a,b);j++) sum[i][j]=(sum[i][j-1]+C[i][j])%mod;
		ss[i][0]=1; for (int j=1;j<=max(a,b);j++) ss[i][j]=(ss[i][j-1]+sum[i][j])%mod;
	}
	
	pw[0]=1; for (int i=1;i<=b;i++) pw[i]=pw[i-1]*2%mod;
	for (int t=1;t<=a+1;t++)
		for (int i=0;i<min(t,b);i++) {
			if (!i) {ans++; continue;}
			ans=(ans+C[b-1][i]*ss[i-1][t-i-1])%mod;
		}
	printf("%lld\n",ans);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    string s;
    cin >> s;
    int ans;
    if(s == "RRR") ans=3;
    else if(s == "RRS" || s == "SRR") ans=2;
    else if(s == "SSS") ans=0;
    else ans=1;

    cout << ans << endl;

    return 0;
}

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

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

int main(){
  int H, W; cin >> H >> W;
  vector<string> glid(H);
  vector<vector<int> > stp(H, vector<int>(W, -1) );
  int whi = 0;
  
  for(int i = 0; i < H; i++){
    cin >> glid[i];
    for(int j = 0; j < W; j++){
      if(glid[i][j] == '.') whi++;
    }
  }
  queue<pair<int, int> > que;
  que.push(make_pair(0, 0) );
  stp[0][0] = 1;
  
  while(!que.empty() ){
    int y = que.front().first;
    int x = que.front().second;
    que.pop();
    
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      
      if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if(stp[ny][nx] != -1 || glid[ny][nx] == '#') continue;
      
      stp[ny][nx] = stp[y][x] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  int ans = 0;
  if(stp[H-1][W-1] == -1) ans = -1;
  else ans = whi - stp[H-1][W-1];
  
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

ans = 0
for i in range(N):
    tmp = A1[0]
    l, d = 0, 0
    while l+d < i:
        l += 1
        tmp += A1[l]
    d += 1
    while l+d < N:
        tmp += A2[l]
        l += 1
    tmp += A2[-1]
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=1; i<n; i++)
using namespace std;
using vi = vector<int>;

int main(){
    int n, k, m, c=0;
    cin >> n;
    vi ps(n);
    vi pmin(n);
    cin >> ps.at(0);
    m = ps.at(0);
    pmin.at(0) = m;
    rrep(i,n){
        cin >> k;
        ps.at(i) = k;
        m = min(m, k);
        pmin.at(i) = m;
    }
    rep(i,n){
        if (ps.at(i) == pmin.at(i))c += 1;
    }
    cout << c << '\n';
}

Measured memory_bytes: 4780
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<vector<int>> graph(n);
  FOR(i, 1, n) {
    int a; cin >> a; --a;
    graph[a].emplace_back(i);
  }
  REP(i, n) cout << graph[i].size() << '\n';
  return 0;
}


Measured memory_bytes: 14272
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  string S; cin >> S;
  list<char> L;
  REP(i,S.size()) {
    L.push_back(S[i]);
  }
  auto p = L.begin();
  while(true) {
    if(p == L.end()) {
      break;
    }
    auto r = p;
    ++r;
    if(r == L.end()) {
      break;
    }
    if(*p == 'S' && *r == 'T') {
      L.erase(r);
      if(p != L.begin()) {
        auto q = p;
        --q;
        L.erase(p);
        p = q;
      }
      else {
        auto q = p;
        ++q;
        L.erase(p);
        p = q;
      }
    }
    else {
      p = r;
    }
  }
  cout << L.size() << endl;
}


Measured memory_bytes: 6676
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

def solve():
    n = ni()
    X = list(map(int, list(ns())))
    p = sum(X)
    pl, ps = p+1, p-1

    g = [-1] * (n+5)
    g[0] = 0
    for i in range(1, n+5):
        g[i] = g[i % popcount(i)] + 1
    ql = qs = 0
    for x in X:
        ql = (ql * 2 + x) % pl
        if ps > 0:
            qs = (qs * 2 + x) % ps
    vl = vs = 1
    ans = [0]*n
    for i in range(n-1, -1, -1):
        if X[i]:
            if ps > 0:
                ans[i] = g[(qs-vs)%ps] + 1
        else:
            ans[i] = g[(ql+vl)%pl] + 1
        if ps > 0:
            vs = vs * 2 % ps
        vl = vl * 2 % pl
    prn(ans)
    return

solve()


Measured memory_bytes: 17128
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    for(int i=0;i<a.size();i++){
		for(int j=0;j<a.size();j++){
			if(a[i]==a[j]){
				if(i!=j){
					cout<<"no"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"yes"<<endl;
}


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

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

    int n, k, s;
    cin >> n >> k >> s;

    vector<int> res(n);
    rep(i, n){
        if(i < k) res[i] = s;
        else{
            if(s == 1000000000) res[i] = s-1;
            else res[i] = s+1;
        }
    }

    rep(i, n) cout << res[i] << " ";
    cout << endl;


    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L > R) cout << "Left" << endl;
  else if (L < R) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

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

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int X, N;

	cin >> X >> N;
		
	unordered_set<int> s;
	int a[N];
	
	
	for(int i =0; i< N; i++){
		cin >> a[i];
		s.insert(a[i]);
	}
	
	
	for(int i = 0; i<102; i++) {
		if(!s.count(X-i)) {
			cout << X-i << "\n";
			return 0;
		}
		if(!s.count(X+i)) {
			cout << X+i << "\n";
			return 0;
		}
		
	}
	
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


ll areaA,areaB,areaC;

int main() {
  ll H,W;
  scanf("%lld%lld", &H,&W);

  ll ans = pow(10,12);
  
  FOR(i,1,H-1){
    ll mw = ceil((float)W/2.0);

    areaA = i*W;
    areaB = (H-i)/2 * W;
    areaC = ((H-i)-(H-i)/2)*W;

    ll max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

    areaB = mw*(H-i);
    areaC = (W-mw)*(H-i);
    max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

  }

  int change = H;
  H = W;
  W = change;

  FOR(i,1,H-1){
    ll mw = ceil((float)W/2.0);

    areaA = i*W;
    areaB = (H-i)/2 * W;
    areaC = ((H-i)-(H-i)/2)*W;

    ll max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

    areaB = mw*(H-i);
    areaC = (W-mw)*(H-i);
    max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

  }

  cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    int n, i, j, f, q, t;
    bool rev = 0;
    string s;
    char c;
    cin >> s;
    cin >> q;
    deque<char> dq;
    //dq.eb(s);
    for (i = 0; i < s.size(); i++){
        dq.eb(s[i]);
    }
        while (q--)
        {
            cin >> t;
            if (t == 1)
            {
                if (rev == 0)
                {
                    rev = 1;
                }
                else{
                rev = 0;
            }
        }
        else{
            cin >> f >> c;
            if(f == 1){
                if(rev == 1){
                    dq.eb(c);
                }
                else{
                    dq.emplace_front(c);
                }
            }
            else{
                if(rev == 1){
                    dq.emplace_front(c);
                }
                else{
                    dq.eb(c);
                }
            }
        }
    }
    //  deque<string>::iterator it;
    // for (auto it = dq.begin(); it != dq.end(); it++){
    //     cout << *it;
    // }
    cout << nl; 
    if (rev){
        for (auto it = dq.rbegin(); it != dq.rend(); it++)
        {
            cout << *it;
        }
        cout << nl;
        return 0;
    }
    for (auto it = dq.begin(); it != dq.end(); it++){
        cout << *it;
    }
    cout << nl; 
}

Measured memory_bytes: 896
n,c,k = map(int,input().split())
t = [int(input()) for _ in range(n)]
t.sort()

p = 0
w = t[0]
res = 0

for i in range(n):
    p += 1
    if t[i]-w > k:
        p = 1
        res += 1
        w = t[i]
        if i==n-1:
            res += 1
    elif c == p:
        p = 0
        res += 1
        if i != n-1:
            w = t[i+1]
    else:
        if i==n-1:
            res += 1
print(res)

Measured memory_bytes: 7488
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next; //番兵の次の要素から辿る
	while ( cur != nil && cur->key != key ){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while(1){
		if( cur== nil) break;
		if( isf++ >0 ) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if( t ==nil ) return; //tが番兵の場合は処理しない
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	//検索したノードを削除
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	//番兵の直後に要素を追加
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0, nd =0;
	scanf("%d",&n);
	init();
	for( i=0; i<n; i++){
		scanf("%s%d", com, &key); //より高速な入力関数を使用
		if( com[0] == 'i'){ insert(key); np++; size++; }
		else if ( com[0] == 'd'){
			if( strlen(com) > 6){
				if ( com[6] == 'F' ) deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define Loop(i, a, b) for(int i = a ; i < b ; ++i)
#define loop(i, n) Loop(i, 0, n)
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define vl vector<ll>
#define vvl vector<vl>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vvll vector<vll>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18+5
#define inf 1e9+5
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

template <typename T> T max(T a, T b, T c){ return max(a, max(b, c));}
template <typename T> T min(T a, T b, T c){ return min(a, min(b, c));}

const int M = 1e9+7; //check
int h, w;
char maze[25][25];


int main() {
	_69e27;
	cin >> h >> w;
	map<int, pii> mp;
	int cnt = 0;
	loop(i, h)
		loop(j, w)
		{
			mp[cnt++] = mkp(i, j);
			cin >> maze[i][j];
		}		
	int dist[500][500];
	loop(i, cnt+5)
	{
		loop(j, cnt+5)
		{
			if(mp.count(i) == 0 || mp.count(j) == 0) continue;
			pii p1 = mp[i], p2 = mp[j];
			if(maze[p1.ff][p1.ss] == '#' || maze[p2.ff][p2.ss] == '#') dist[i][j] = inf;
			else if(abs(p1.ss-p2.ss)+abs(p1.ff-p2.ff) == 1) dist[i][j] = 1;
			else dist[i][j] = inf;
		}
	}
	loop(k, cnt)
	{
		loop(i, cnt)
		{
			loop(j, cnt)
			{
				if(dist[i][j] > dist[i][k] + dist[k][j]) dist[i][j] = dist[i][k] + dist[k][j];
			}
		}
	}
	int ans = 0;
	loop(i, cnt)
	{
		loop(j, cnt)
		{
			if(i == j) continue;
			if(dist[i][j] < inf) ans = max(ans, dist[i][j]);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {

	int K, T, a[105], ans;
	cin >> K >> T;
	for (int i = 0; i < T; i++) cin >> a[i];

	sort(a, a+T);

	int amax = a[T-1], other = 0;
	for (int i = 0; i < T - 1; i++) other += a[i];

	cout << max((amax - 1) - other, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cost[n];
    cost[0]=0;
    for(int i=1;i<=min(n-1,k);i++){
        cost[i]=abs(a[i]-a[0]);
    }
    if(n-1<=k){
        cout<<cost[n-1]<<endl;
        return 0;
    }
    for(int i=k+1;i<n;i++){
        cost[i] = cost[i-1]+abs(a[i]-a[i-1]);
        for(int j=2;j<=k;j++){
            cost[i]=min(cost[i],cost[i-j]+abs(a[i]-a[i-j]));
        }
    }
    cout<<cost[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>

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


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	if (N & 1) {
		int s = 1, e = 2 * M;
		for (int i = 0; i < M; i++) {
			cout << s << ' ' << e << '\n';
			s++, e--;
		}
	}
	else {
		int mxi = 0;
		for (int i = M, j = 1; i >= 1; i--) {
			if (i & 1) {
				cout << j << ' ' << j + i << '\n';
				j++;
				mxi = max(mxi, j + i);
			}
		}
		for (int i = M, j = mxi; i >= 1; i--) {
			if (~i & 1) {
				cout << j << ' ' << j + i << '\n';
				j++;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<int>> f(N);
    for(int i=0; i<N; i++) {
        int a;
        cin >> a;
        A[i] = a-1;
        f[a-1].push_back(i);
    }
    int count = 0;
    for(int i=0; i<N; i++) {
        if(find(f[i].begin(), f[i].end(), A[i]) != f[i].end()) count++;
    }
    cout << count/2 << endl;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main() {
    int g,r;
    cin >> g >> r;
    vector<vector<int> > table(g+1, vector<int>(r+1,0));
    for(int i = 0; i < g; i++) {
        for(int j = 0; j < r; j++) {
            cin >> table.at(i).at(j);
        }
    }
    int sumall = 0;
    for(int i = 0; i < g; i++) {
        int sumg = 0;
        for(int j = 0; j < r; j++) {
            sumg += table.at(i).at(j);
        }
        table.at(i).at(r) = sumg;
        sumall += sumg;
    }
    for(int j = 0; j < r; j++) {
        int sumr = 0;
        for(int i = 0; i < g; i++) {
            sumr += table.at(i).at(j);
        }
        table.at(g).at(j) = sumr;
    }
    table.at(g).at(r) = sumall;
    for(int i = 0; i < g+1; i++) {
        for(int j = 0; j < r+1; j++) {
            if(j == r) {
                cout << table.at(i).at(j) << endl;
            }
            else {
                cout << table.at(i).at(j) << " ";
            }
        }
    }
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(){
    int i;
    int c[3];
    scanf("%d %d %d",&c[0],&c[1],&c[2]);
    for(i=0;i<10;i++){
        c[2] = c[0]*c[2]-c[1];
        printf("%d\n",c[2]);
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
x = [1]
i = 6
while i < 100000:
    x.append(i)
    i *= 6
i = 9
while i < 100000:
    x.append(i)
    i *= 9

dp = [0] * 100001
for i in range(1, 100001):
    tmp = []
    for xx in x:
        if i - xx >= 0:
            tmp.append(dp[i-xx]+1)
    dp[i] = min(tmp)
print(dp[n])

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

int main(){
    int n;
    cin >> n;
    int a[n];
    int che[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        che[i] = 0;
    }

    int cou = 0;
    int now = 1;
    int frag = 0;
    for(int i = 0; i < n; i++){
        che[now - 1] = 1;
        cou++;
        now = a[now - 1];
        if(che[now - 1] == 1){
            frag = -1;
            break;
        }
        if(now == 2){
            frag = 1;
            break;
        }
    }

    if(frag == 1){
        cout << cou << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;


/** ワーシャル・フロイド法による全点対最短路探索

    経路を逐次最小化していく。

    知らないパスにはコスト大きめを設定しておくこと。
    O(|V|^3)

    @param[in] V  頂点数
    @param[in, out] distance[i][j]: 頂点i -> jのコスト
 */
template<typename T, typename M>
void warshall_floyd(T V, M& distance)
{
    for (T k = 0; k < V; ++k) {
        for (T i = 0; i < V; ++i) {
            for (T j = 0; j < V; ++j) {
                distance[i][j] = std::min(distance[i][j],
                                          distance[i][k] + distance[k][j]);
            }
        }
    }
}

/* 2倍しても桁溢れしない最大数

   almost_max<uint64_t>() とか
 */
template<typename T>
constexpr T almost_max() {
    return std::numeric_limits<T>::max() / 2 - 1;
}


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

    struct Path {
        int from;
        int to;
        int cost;
    };
    std::vector<Path> pathes;

    boost::multi_array<int, 2> mat(boost::extents[N][N]);
    std::fill(mat.data(), mat.data() + mat.num_elements(), almost_max<int>());
    for (int i = 0; i < N; ++i) {
        mat[i][i] = 0;
    }

    for (int i = 0; i < M; ++i) {
        Path p;
        std::cin >> p.from >> p.to >> p.cost;
        p.from--;
        p.to--;
        mat[p.from][p.to] = mat[p.to][p.from] = p.cost;
        pathes.push_back(p);
    }

    warshall_floyd(N, mat);

    int ans = M;
    for (int i = 0; i < M; ++i) {
        // このパスは...
        auto& p = pathes[i];
        for (int j = 0; j < N; ++j) {
            // とある頂点に向かうためのパスのうち、
            if (mat[j][p.from] + p.cost == mat[j][p.to]) {
                // 最短経路であった
                ans -= 1;
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}



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

const int MAX = 100000;

int search(long long dp[], long long num, int begin, int end) {
	if (begin == end - 1)return end;

	int mid = (begin + end) / 2;
	if (dp[mid] == num)return mid;

	if (dp[mid] > num) {
		return search(dp, num, begin, mid);
	}
	else {
		return search(dp, num, mid, end);
	}
}

int main() {
	int n;
	long long ary[MAX];
	long long dp[MAX] = { 0 };
	int len = 0;

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

	for (int i = 0; i < n; i++) {
		int j = search(dp, ary[i], 0, len + 1);
		if (j <= len) {
			dp[j] = ary[i];
		}
		else {
			dp[++len] = ary[i];
		}
	}

	cout << len << endl;

	return 0;
}

Measured memory_bytes: 4656
# T - Permutation
n = int(input())
s = input()
MOD = 10**9+7

# dp[i][j]:i番目まで決めたとき、i番目の数よりも大きい数がj個残っている場合の数。
dp = [[0 for _ in range(n)] for _ in range(n+1)]

# 今i-1番目の数より大きい数が3個残っているとする。
# s[i]=='<'のとき、i番目の数として、その3個すべてが使える。
# そうすると、i番目の数より大きい数が2個、1個、0個残っている場合に遷移する。
# つまり、i番目の数より大きい数がj個残っている場合には、
# i-1番目の数より大きい数がj+1,j+2...n-i+1個残っている場合から遷移する。
# s[i]=='>'のとき、i番目の数として、その3個を除いた数字が使える。
# そうすると、i+1番目の数より大きい数が3個、4個...n-i-1個残っている場合に遷移する。
# つまり、i番目の数より大きい数がj個残っている場合には、
# i-1番目の数より大きい数がj,j-1...0個残っている場合から遷移する。

# ただし、下記のプログラムでは計算量がO(n**3)になってしまう。
# kのループで累積和を使用することで、O(n**2)にできる。
#
# for i in range(n):
#   dp[1][i] = 1
# for i in range(2,n+1):
#   if s[i-2] == '<':
#     for j in range(n-i+1):
#       for k in range(j+1,n-i+2):
#         dp[i][j] += dp[i-1][k]
#         dp[i][j] %= MOD
#   else:
#     for j in range(n-i+1):
#       for k in range(j+1):
#         dp[i][j] += dp[i-1][k]
#         dp[i][j] %= MOD

for i in range(n):
  dp[1][i] = 1
for i in range(2,n+1):
  csum = [0 for _ in range(n-i+2)]
  csum[0] = dp[i-1][0]
  for k in range(1,n-i+2):
    csum[k] += csum[k-1]+dp[i-1][k]
  if s[i-2] == '<':
    for j in range(n-i+1):
      dp[i][j] += csum[n-i+1]-csum[j]
      dp[i][j] %= MOD
  else:
    for j in range(n-i+1):
      dp[i][j] += csum[j]
      dp[i][j] %= MOD
print(dp[n][0])

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

int main(){
int n,Sum,Ans ;

while(1){

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n),vec2(n+1,0) ;

for(int i=0;i<n;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec2.at(j+1)=vec.at(j)+vec2.at(j) ;
}
    
Ans=vec2.at(n) ;

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec2.at(l)-vec2.at(k);
    Ans=max(Sum,Ans) ;
    }
}

cout << Ans << endl ;

}

}



Measured memory_bytes: 3124
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input() + "0"*K
#T = T.replace("r",P).replace("s",R).replace("p",S)
#print(T)
#rn, sn, pn = 0, 0, 0
r, s, p = 0, 0, 0

for i in range(N):
    i = int(i)
    if T[i] == T[i+K]:
        T = T[:i+K] + "0" + T[i+K+1:]
        """
        if T[i] == "r":
            rn += 1


        elif T[i] == "s":
            sn += 1

        else:
            pn += 1
        """
    else:
        if T[i] == "r":
            r += 1

        elif T[i] == "s":
            s += 1

        elif T[i] == "p":
            p += 1

#for i in [rn, sn, pn,r, s, p]:
    #print(i)
#sum = P*(r+(rn//2)) + R*(s+(sn//2)) + S*(p+(pn//2))
#print(T)
sum = P*T.count("r") + R*T.count("s") + S*T.count("p")
print(sum)

Measured memory_bytes: 11676
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
int a[N],b[N];
int ans,n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",&b[i]);
	a[1]=b[1];
	for(int i=2;i<n;i++)
		a[i]=min(b[i-1],b[i]);
	a[n]=b[n-1];
	for(int i=1;i<=n;i++)
		ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256