akhauriyash/Code-Regression huggingface dataset:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, wwl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    nwl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        for j in range(wn):
            if wl[i][j] <= wwl:
                nwl[i][j] = 1

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                nwl[j][k] = min(nwl[j][k], nwl[j][i] + nwl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        print(nwl[s-1][t-1] - 1 if nwl[s-1][t-1] != inf else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 57180
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

toTriple :: B.ByteString -> (Int, Int, Int)
toTriple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, bs'') = B.readInt $ B.dropWhile isSpace bs'
        Just (c, _) = B.readInt $ B.dropWhile isSpace bs''
    in
        (a, b, c)

solve :: VU.Vector (Int, Int, Int) -> Int -> VU.Vector Int
solve csfs n = 
    VU.generate n $ \i -> 
        if i == n
            then 0
            else scan (VU.drop i csfs)
    where
        scan vec = VU.foldl' step 0 vec
        step acc (c,s,f)
            | acc < s = acc + (s - acc) + c
            | acc `rem` f == 0 = acc + c
            | otherwise = acc + (f - acc `rem` f) + c

main = do
    n <- readLn :: IO Int
    csfs <- VU.replicateM (n-1) (toTriple <$> B.getLine)
    VU.mapM_ print $ solve csfs n 

Measured memory_bytes: 1020
x, y = map(int, input().split())
group = [[1,3,5,7,8,10,12], [4,6,9,11]]

if x == 2 or y == 2:
    print('No')
elif x in group[0]:
    if y in group[0]:
        print('Yes')
    else:
        print('No')
elif x in group[1]:
    if y in group[1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
# include<iostream>
using namespace std;
int main() {
    int n, m, l;
    int i, j, k;
    long long val = 0;
    cin >> n >> m >> l;
    int A[n][m], B[m][l];
    for (i=0;i<n;i++) {
        for (j=0;j<m;j++) {
            cin >> A[i][j];
        }
    }
    for (j=0;j<m;j++) {
        for (k=0;k<l;k++) {
            cin >> B[j][k];
        }
    }
    for (i=0;i<n;i++) {
        for (k=0;k<l;k++) {
            for (j=0;j<m;j++) {
                val += A[i][j]*B[j][k];
            }
            cout << val;
            val = 0;
            if (k<l-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
b_i = [0]*n
c_i = [0]*n
for i in range(n):
    b1 = bisect.bisect_left(a,b[i])
    if i==0:
        b_i[i]=b1
    else:
        b_i[i] = b_i[i-1]+b1
    c1 = bisect.bisect_left(b,c[i])
    c_i[i]= c1

ans = 0
for i in range(n):
    if c_i[i]<1:
        continue
    else:
        ans = ans + b_i[c_i[i]-1]
print(ans)

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

int main() {
  int r, D;
  vector<int> x(11);
  cin >> r >> D >> x.at(0);
  
  for (int i = 1; i <= 10; i++) {
    x.at(i) = r * x.at(i - 1) - D;
    cout << x.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;


int main() {
    int n, w;
    cin >> n >> w;
    vector<vector<long long>> values(4);

    long long w0;
    FOR(i, 0, n) {
        int ww, vv;
        cin >> ww >> vv;
        if (i == 0)
            w0 = ww;
        values[ww - w0].push_back(vv);
    }

    FOR(i, 0, 4)
        sort(values[i].begin(), values[i].end(), greater<long long>());

    vector <vector<long long>> accum(4);
    FOR(i, 0, 4) {
        accum[i].resize(values[i].size() + 1);
        accum[i][0] = 0;
        FOR(j, 1, accum[i].size()) {
            accum[i][j] = accum[i][j - 1] + values[i][j - 1];
        }
    }

    long long maxx = 0;
    IFOR(i, 1, n) {
        IFOR(x0, 0, i) {
            IFOR(x1, 0, i - x0) {
                IFOR(x2, 0, i - x0 - x1) {
                    IFOR(x3, 0, i - x0 - x1 - x2) {
                        long long totalweight = w0*i + x1 + 2 * x2 + 3 * x3;
                        if (totalweight > w)
                            continue;
                        if (values[0].size() < x0 || values[1].size() < x1 || values[2].size() < x2 || values[3].size() < x3)
                            continue;
                        long long res = accum[0][x0] + accum[1][x1] + accum[2][x2] + accum[3][x3];
                        maxx = max(maxx, res);
                    }
                }
            }
        }
    }

    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int n=a.size();
	int k=n/2;
	char c=a[n-k-1];
	for(int i=k+1;i<=n;++i)
	{
		//cout<<c<<" "<<a[n-i]<<" "<<a[i-1]<<endl;
		if(a[n-i]!=a[i-1]||a[n-i]!=c)
              break;
		else ++k;
	}
	cout<<k<<endl;
	return 0; 
 } 

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

int fie[210][210][51];

vector<int> d[]={{0,0,0,0},{2,3,5,4},{1,4,6,3},{1,2,6,5},{1,5,6,2},{1,3,6,4},{2,4,5,3}};

class dice{
public:
	int tp,ft;
	int x,y,z;
	dice(int t,int f):tp(t),ft(f),x(100),y(100),z(50){};
	bool fall(){
		if(z-1>=0 && fie[x][y][z-1]==-1){
			z--;
			return true;
		}
		return false;
	}
	
	bool move(){
		if(z==0)return false;
		vector<int> tmp = d[tp];
		int fpos=-1;
		int pos=-1,num=-1;
		rep(i,tmp.size()){
			if(tmp[i]==ft)fpos=i;
		}
		rep(i,tmp.size()){
			if(tmp[i]==4||tmp[i]==5||tmp[i]==6){
				int tdir = (i+4-fpos)%4;
				if(tdir==0 && fie[x][y-1][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==1 && fie[x+1][y][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==2 && fie[x][y+1][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==3 && fie[x-1][y][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
			}
		}
		if(pos==-1)return false;
		int dir = (pos+4-fpos)%4;
//		cout<<x<<" "<<y<<" "<<z<<" "<<dir<<" "<<fpos<<" "<<pos<<" "<<num<<endl;
		if(dir==0) y--,z--;
		if(dir==1) x++,z--;
		if(dir==2) y++,z--;
		if(dir==3) x--,z--;
//		cout<<x<<" "<<y<<" "<<z<<" "<<dir<<endl<<endl;
		if(dir==0)ft=tp;
		if(dir==1&&dir==3)ft=ft;
		if(dir==2)ft=7-tp;
		tp = 7-num;
		
		return true;
	}
};

int main(){
	int n;
	while(cin>>n&&n){
		rep(i,210)rep(j,210)rep(k,51)fie[i][j][k]=-1;
		vector<pii> inp(n);
		rep(i,n)cin>>inp[i].first>>inp[i].second;
		
		rep(i,n){
			dice a(inp[i].first,inp[i].second);
			while(1){
				bool f = a.fall();
				if(!f){
					bool m = a.move();
					if(!m){
//						cout<<a.x<<" "<<a.y<<" "<<a.z<<" "<<a.tp<<endl;
						fie[a.x][a.y][a.z] = a.tp;
						break;
					}
				}
			}
		}
		int ans[7]={};
		rep(i,210){
			rep(j,210){
				for(int k=50;k>=0;k--){
					if(fie[i][j][k]!=-1){
						ans[fie[i][j][k]]++;
						break;
					}
				}
			}
		}
		rep(i,6){
			if(i)cout<<" ";
			cout<<ans[i+1];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 11920
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	void kaijou_set(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	combi C;
	C.kaijou_set(10000001);
	
	int N;
	cin>>N;
	
	int k = N/2 + 1;
	
	int bb = beki(2,N-k);
	int sum = 0;
	int gya = gyakugen(2);
	for(int i=k;i<=N;i++){
		int a = C.combination(N,i);
		int b = mod(a * bb);
		
		sum = mod(sum + b);
		
		bb = mod(bb * gya);
	}
	
	sum = mod(sum * 2);
	
	int ans = beki(3,N);
	ans = mod(ans - sum);
	cout<<ans<<endl;
	
    return 0;
}



Measured memory_bytes: 82052
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String N=sc.next();
    char[] n=N.toCharArray();
    if(n[0]==n[2]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n-1);
  for (int i=0;i<n-1;i++) {
    cin>>a.at(i);
  }
  int p=a.at(0)+a.at(n-2);
  for (int i=0;i<n-2;i++) {
    p+=min(a.at(i),a.at(i+1));
  }
  cout<<p<<endl;
}

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

int main()
{
    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    reverse(a.begin(), a.end());

    vector<int> b;
    for (int i = 0; i < n; i += 2)
        b.push_back(a[i]);

    reverse(a.begin(), a.end());
    if (n % 2 == 0)
        for (int i = 0; i < n; i += 2)
            b.push_back(a[i]);
    else
        for (int i = 1; i < n; i += 2)
            b.push_back(a[i]);

    for (int i = 0; i < n - 1; i++)
    {
        cout << b[i] << " ";
    }
    cout << b[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include<queue>
using namespace std;

const int INF = 100000000;
typedef pair<int, int> P;

int main()
{
	char s;
	cin >> s;
	if (s == 'A') cout << 'T';
	if (s == 'T') cout << 'A';
	if (s == 'C') cout << 'G';
	if (s == 'G') cout << 'C';
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

input_tmp = [int(input()) for _ in range(6)]

n = input_tmp[0]

a2e = input_tmp[1:]

min_value = min(a2e)

if n <= min_value:
    print(5)
else:
    if n % min_value != 0:
        print(n // min_value + 5)
    else:
        print(n // min_value - 1 + 5)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    s[k-1] -= 'A' -'a';

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
const long long MAXN=1000005;

int n,m;
char S[MAXN],T[MAXN];
stack<int> s[30];
pair<int,int> que[MAXN];
int hd,tl;

int main()
{
    scanf("%d%s%s",&n,S+1,T+1);
	for(int i=1;i<=n;i++)
		s[S[i]-'a'].push(i);
	hd=1;tl=0;
	int now=n,last=n+1,c=0;
	int ans=0;
    for(int i=n;i>=1;i--)
	{
		now=min(now,i);
		while(!s[T[i]-'a'].empty()&&s[T[i]-'a'].top()>now)
			s[T[i]-'a'].pop();
		if(s[T[i]-'a'].empty())
		{
			puts("-1");
			return 0;
		}
		now=s[T[i]-'a'].top();
		if(now==i||now==last)
		{
			last=now;
			continue;
		}
		last=now;
		while(hd<=tl&&que[hd].first-que[hd].second-c+1>i)
		{
			ans=max(ans,que[hd].second+c);
			hd++;
		}
		c++;
		que[++tl]=make_pair(now,1-c);
	}
	for(int i=hd;i<=tl;i++)
		ans=max(ans,que[i].second+c);
	printf("%d\n",ans);

    return 0;
}


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

set<string> st;

int N;
void solve(string ans, int start, int ma, int cur) {

    // カーソルを左にずらすか
    // そのカーソルの値を変更するか
    if (cur == 0 or start == cur) {
        return;
    }

    // カーソルを左に移す
    solve(ans, start, ma, cur-1);

    for (int i=1; i<=(ma-'a'+1); ++i) {
        //char tmp = ans[cur];
        ans[cur] = (char)('a' + i);
        //cout << cur << ", " << (char)('a' + i) << ", " << ans << endl;
        st.insert(ans);
        solve(ans, cur, max(ma, (int)ans[cur]), N-1);
    }
    return;
}

// solve("aaaa", 1, N-1);

int main() {
    //int N;
    cin >> N;
    if (N == 1) {
        cout << "a" << endl;
        return 0;
    }
    if (N == 2) {
        cout << "aa" << endl;
        cout << "ab" << endl;
        return 0;
    }

    string ans(N, 'a'), tmp = ans;

    st.insert(ans);
    //cout << ans << endl;
    tmp[N-1] = 'b';
    st.insert(tmp);
    //cout << tmp << endl;
    tmp = ans;
    //
    for (int cur = N-2; cur > 0; --cur) {
        tmp = ans;
        tmp[cur] = 'b';
        //cout << tmp << endl;
        st.insert(tmp);
        solve(tmp, cur, tmp[cur], N-1);
    }

    for (auto & tmp : st) {
        cout << tmp << endl;
    }

    // ans[N-2] = 'b';
    // cout << ans << enel;
    // solve(ans, -1, N-1);

    //
    // // 何も使わないバージョン
    // cout << ans << endl;
    // tmp[N-1] = 'b';
    // cout << tmp << endl;
    //
    // tmp = ans;
    // for (int cur = N-2; cur > 0; --cur) {
    //     // 現在の文字を見る
    //     tmp[cur] = 'b';
    //     cout << tmp << endl;
    //
    //     string tmp2 = tmp;
    //     for (int cur2 = N-1; cur2 > cur; --cur2) {
    //         tmp2[cur2]++;
    //         while (tmp2[cur2 - 1] - 'a' + 1 >= tmp2[cur2] - 'a') {
    //             cout << tmp2 << endl;
    //             tmp2[cur]++;
    //         }
    //
    //     }
    //}

    // int cur = N;
    // rep(i, N) {
    //     if (cur < N) {
    //         tmp[cur] = 'b';
    //     }
    //     cout << tmp << endl;
    //
    //     if (cur < N) {
    //         for (int i=)
    //     }
    //
    //     tmp = ans;
    //     cur--;
    // }
}


Measured memory_bytes: 12416
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    tmp=[]
    t=s
    c=1
    for k in j:
      if k=="1":
        tmp.append(int(t[-c:]))
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      tmp.append(int(t))
    ans+=sum(tmp)
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

int main() {
    int x;
    cin >> x;
    int result = 0;
    result += x/500*1000;
    x %= 500;
    result += x/5*5;
    cout << result;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }
struct ford_fulkerson {
	using Matrix = std::vector<std::vector<Flow>>;
	int n, t;
	std::vector<int> vis;
	std::vector<std::vector<Flow>> cap, flow;
	std::vector<std::vector<int>> g;
	const Flow INF;
	ford_fulkerson(int n)
		: n(n),
		cap(n, std::vector<Flow>(n)),
		flow(n, std::vector<Flow>(n)),
		g(n, std::vector<int>()),
		INF(std::numeric_limits<Flow>::max() / 8) {}
	ford_fulkerson(const Graph &graph) : ford_fulkerson(graph.size()) {
		for (int i = 0; i < n; ++i)
			for (auto &e : graph[i]) add_edge(e.src, e.dst, e.cap);
	}
	void add_edge(int u, int v, Flow c) {
		cap[u][v] += c;
		cap[v][u] += c;
		flow[v][u] += c;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	Flow solve(int s, int t) {
		this->t = t;
		Flow res = 0, aug = 1;
		while (aug > 0) {
			vis.assign(n, false);
			res += (aug = augment(s, INF));
		}
		return res;
	}
	Flow augment(const int &v, const Flow &lim) {
		vis[v] = true;
		if (v == t) return lim;
		for (const int &d : g[v]) {
			if (vis[d] || flow[v][d] == cap[v][d]) continue;
			Flow aug = augment(d, std::min(lim, cap[v][d] - flow[v][d]));
			flow[v][d] += aug;
			flow[d][v] -= aug;
			if (aug > 0) return aug;
		}
		return 0;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, S, T;
	cin >> N >> M >> S >> T;
	S--;
	T--;
	ford_fulkerson ff(N);
	vector<int> A(N);
	vector<vector<int> >ed(N);
	vector<vector<int> >d(N);
	vector<vector<int> >c(N);
	int res = 0;
	int u, v, _d, _c;
	for (int i = 0; i < M; i++) {
		cin >> u >> v >> _d >> _c;
		u--;
		v--;
		ed[u].push_back(v);
		d[u].push_back(_d);
		c[u].push_back(_c);
	}
	vector<int> dist(N, (int)1 << 60);
	queue<int> qu;
	qu.push(S);
	dist[S] = 0;
	while ((int)qu.size() > 0) {
		int a = qu.front(); qu.pop();
		for (int i = 0; i < ed[a].size(); i++) {
			if (dist[ed[a][i]] > dist[a] + d[a][i]) {
				qu.push(ed[a][i]);
				dist[ed[a][i]] = dist[a] + d[a][i];
			}
		}
	}
	for (int a = 0; a < N; a++) {
		for (int i = 0; i < ed[a].size(); i++) {
			if (dist[ed[a][i]] == dist[a] + d[a][i]) {
				ff.add_edge(a, ed[a][i], c[a][i]);
			}
		}
	}
	cout << ff.solve(S, T) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++)
    cin >> s.at(i);
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++)
    cin >> t.at(i);
  int count = 0;
  
  for (int i = 0; i < N; i++){
    int a = 0;
    for (int j = 0; j < N; j++)
      if (s.at(i) == s.at(j))
        a++;
    for (int j = 0; j < M; j++)
      if (s.at(i) == t.at(j))
        a--;
    
    if (count < a)
      count = a;
  }
  cout << count << endl;
}


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

int main() {
    int a[3][3]={0};
    int c[3][3]={0};
    int N;
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    cin>>N;
    int b;
    for (size_t i = 0; i < N; i++)
    {
        cin>>b;
        for (size_t j = 0; j < 3; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                if(b==a[j][k]){
                    c[j][k]=1;
                }
            }            
        }
    }
    if (c[0][0]==1&&c[0][1]==1&&c[0][2]==1)cout<<"Yes"<<endl;
    else if (c[1][0]==1&&c[1][1]==1&&c[1][2]==1)cout<<"Yes"<<endl;
    else if (c[2][0]==1&&c[2][1]==1&&c[2][2]==1)cout<<"Yes"<<endl;
    else if (c[0][0]==1&&c[1][1]==1&&c[2][2]==1)cout<<"Yes"<<endl;
    else if (c[2][0]==1&&c[1][1]==1&&c[0][2]==1)cout<<"Yes"<<endl;
    else if (c[0][0]==1&&c[1][0]==1&&c[2][0]==1)cout<<"Yes"<<endl;
    else if (c[0][1]==1&&c[1][1]==1&&c[2][1]==1)cout<<"Yes"<<endl;
    else if (c[0][2]==1&&c[1][2]==1&&c[2][2]==1)cout<<"Yes"<<endl;
    else {cout<<"No"<<endl;}
    
    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 100000000000000
int main() {
	string s;
	cin >> s;
	REP(i, s.length()) {
		if (i == 5 || i == 13) {
			cout << " ";
		}
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a  

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let M = 1000000007L

let rec pow n m = 
  ((if (m&&&1L)=1L then n%M else 1L) * (if m=0L then 1L else (pow ((n*n)%M) (m>>>1))%M))%M

let rec permutation n r = if r=0L then 1L else (n*(permutation (n-1L) (r-1L))%M)%M

let inv a = pow a (M-2L)
let combination n r = ((permutation n r)*(inv (permutation r r)))%M

let (n, a, b) = readStr().Split() |> Array.map int64 |> triple
let r = (pow 2L n)-1L-(combination n a)-(combination n b)

printfn "%d" ((r+2L*M)%M)

Measured memory_bytes: 18012
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    ll N, A, B;
    cin >> N >> A >> B;

    if (A+B == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll q = N / (A+B);
    ll r = N % (A+B);
    if (r <= A) {
        cout << A*q + r << endl;
    } else {
        cout << A*(q+1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
int cnt[100010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	map<int, int>mp;
	rep(i, n)mp[a[i]]++;
	int ans = 0;
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second % 2 == 1)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7296
#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int op(int a, int b){return max(a, b);}
int e(){return -1;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    segtree<int,op,e> seg(300010);
    seg.set(a[0], 1);
    REP(i, n-1){
        int now = seg.prod(max(a[i]-k, 0), min(a[i]+k+1, 300001));
        if(now == -1)now = 0;
        seg.set(a[i], now+1);
    }
    cout << seg.all_prod() << endl;
}


Measured memory_bytes: 9604
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

l = list(i for i in range(1, n+1))
j = list(list(i) for i in itertools.permutations(l, n))

print(abs(j.index(p) - j.index(q)))

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



int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<long long> arr(a);
	vector<long long> brr(b);
	vector<long long> crr(c);
	for(long long i=0;i<a;i++)
		cin>>arr[i];
	for(long long i=0;i<b;i++)
		cin>>brr[i];
	for(long long i=0;i<c;i++)
		cin>>crr[i];
	sort(arr.rbegin(),arr.rend());
	sort(brr.rbegin(),brr.rend());
	for(long long i=0;i<x;i++)
		crr.push_back(arr[i]);
	for(long long i=0;i<y;i++)
		crr.push_back(brr[i]);
	long long ans=0;
	sort(crr.rbegin(),crr.rend());
	for(long long i=0;i<x+y;i++)
		ans+=crr[i];
	cout<<ans;

	return 0;
}


Measured memory_bytes: 6512
X=int(input())
if X<600:
    print(8)
elif X<800:
    print(7)
elif X<1000:
    print(6)
elif X<1200:
    print(5)
elif X<1400:
    print(4)
elif X<1600:
    print(3)
elif X<1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 61612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n;cin>>n;
  vvi v(n,vi(3));
  rep(i,n){
    rep(j,3){
      cin>>v[i][j];
    }
  }
  vector<vector<ll>> dp(n,vector<ll>(3));
  dp[0][0]=v[0][0];
  dp[0][1]=v[0][1];
  dp[0][2]=v[0][2];
  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1]+v[i][0],dp[i-1][2]+v[i][0]);
    dp[i][1]=max(dp[i-1][0]+v[i][1],dp[i-1][2]+v[i][1]);
    dp[i][2]=max(dp[i-1][1]+v[i][2],dp[i-1][0]+v[i][2]);
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 11136
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;


int main() {
	
	int num = 0;
	int size;

	int max;
	int min;
	
	long sum;

	cin >> size;

	cin >> max;
	min = max;
	sum = max;
	int ketaahure = 0;

	if (sum > 999999999) {
		ketaahure++;
		sum %= 1000000000;
	}

	for (int i = 1; i < size; i++) {
		cin >> num;

		if (max < num)max = num;
		if (min > num)min = num;
		sum += num;

		if (sum > 999999999) {
			ketaahure++;
			sum %= 1000000000;
		}


	}


	printf("%d %d ", min, max);

	if (ketaahure > 0) {
		printf("%d", ketaahure);
		printf("%09d", sum);
	}
	else printf("%d", sum);

	printf("\n");


	//system("pause");
	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;

#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



const int MAXD = 55;
const int MAXN = 55;
const int INF = 10000;

int price[MAXN][MAXD];

int Min[MAXD], MinSum;
bool canuse[MAXD][MAXN];

int dp[MAXD][MAXN];
int next[MAXD][MAXN];


int N, D, a;

int rec(int i, int j) {
	int res = INF, ind = -1;
	if (dp[i][j] < INF) return dp[i][j];
	
	if (i == D) return 0;
	if (!canuse[i][j]) {
		//cout << i << ", " << j << " : " << res << " ; " << ind << endl;
		return INF;
	}

	for (int k = 0; k < N; ++k) {
		int temp = rec(i+1, k);
		if (k != j) temp++;

		if (res > temp) {
			res = temp;
			ind = k;
		}
	}

	//cout << i << ", " << j << " : " << res << " ; " << ind << endl;

	dp[i][j] = res;
	next[i][j] = ind;

	return res;
}



int main() {
	while (cin >> N >> D) {
		for (int i = 0; i < N; ++i) for (int j = 0; j < D; ++j) cin >> price[i][j];
		memset(canuse, 0, sizeof(canuse));
		memset(next, -1, sizeof(next));

		MinSum = 0;
		for (int i = 0; i < D; ++i) {
			int temp = INF;
			for (int j = 0; j < N; ++j) {
				if (temp > price[j][i]) {
					temp = price[j][i];
				}
			}
			Min[i] = temp;
			MinSum += temp;
			for (int j = 0; j < N; ++j) {
				if (temp == price[j][i]) {
					//cout << i << ", " << j << endl;
					canuse[i][j] = true;
				}
			}
		}

		for (int i = 0; i < MAXD; ++i) for (int j = 0; j < MAXN; ++j) dp[i][j] = INF;


		int ans = INF, s = -1;
		for (int i = 0; i < N; ++i) {
			int temp = rec(0, i);
			if (temp < ans) {
				ans = temp;
				s = i;
			}
		}

		cout << MinSum << " " << ans << endl;
		for (int i = 0; i < D; ++i) {
			cout << s+1 << endl;
			s = next[i][s];
		}

	}
    
    return 0;
}


Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << a * 2 << endl;
	}
	else {
		cout << max(a, b) * 2 -1<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  string S;
  cin >> S;
  int ans = 1000;
  REP(i, S.size() - 2) {
    string s = S.substr(i, 3);
    int diff = abs(atoi(s.c_str()) - 753);
    ans = min(ans, diff);
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
/////////////////////////////////////////////////////////////
	

int main(){
	
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum =0;
	for(int i =0;i<n;i++) {
		cin >> a[i];
	    sum+=a[i];
	}
	
	ll av1,av2;
	
	av1 = ceil(sum/double(n));
	av2 = floor(sum/double(n));
	
	ll ans = 0;
	ll ans1 = 0;
	for(int i=0;i<n;i++){
		ans += (av1-a[i])*(av1-a[i]);
		ans1+=  (av2-a[i])*(av2-a[i]);
	} 
	
    cout << min(ans1,ans) << endl;
}
	


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(int argc, const char * argv[]) {
    int n,m,tmp;
    scanf("%d %d",&n,&m);
    int** A = new int*[n];
    for(int i = 0; i < n; i++) A[i] = new int[m];
    int b[m];

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d", &tmp);
            A[i][j] = tmp;
        }
    }
    for(int i = 0; i < m; i++){
        scanf("%d", &tmp);
        b[i] = tmp;
    }
    long long int sum;
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += A[i][j] * b[j];
        }
        printf("%lld\n", sum);
    }

    for(int i = 0; i < n; i++){
        delete[] A[i];
    }
      //  delete A;
    return 0;
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int x, res=0;
	cin >> x; 
	for(int i=0; i<x; ++i)
	{
		res=(res*10+7)%x;
		if(!res)
		{
			cout << i+1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
set<pair<ll,ll> > spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
vector<pair<ll,ll> > vh(ten53),vw(ten53);
//vector<ll> vll;
ll numh[ten53],numw[ten53];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,d,pre=0,now,h,w,inh,inw,bh=0,bw=0;
    string s;
    cin>>h>>w>>m;
    if(m==1)
    {
        cout<<1;
        return 0;
    }
    for(i=1;i<=m;i++)
    {
        cin>>inh>>inw;
        spll.insert(mkpr(inh,inw));
        vh[inh].first--;
        vh[inh].second=inh;
        vw[inw].first--;
        vw[inw].second=inw;
    }
    sort(all(vh));
    sort(all(vw));
    bh=-vh[0].first;
    bw=-vw[0].first;
    for(i=0;i<m;i++)
    {
        if(bh>-vh[i].first) break;
        bh=-vh[i].first;
        for(j=0;j<m;j++)
        {
            if(bw>-vw[j].first) break;
            bw=-vw[j].first;
            pre=bw+bh;
            if(spll.find(mkpr(vh[i].second,vw[j].second))!=spll.end())
            {
                pre--;
                k=max(k,pre);
            }
            else
            {
                cout<<pre;
                return 0;
            }
        }
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 31508
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

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

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

/// command for char arrays with spaces -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

const int N = 2e5+5;
ll h[N];

int main(){

	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++){
		scanf("%lld", &h[i]);
	}
	sort(h, h+n, greater<ll>());
	ll ans = 0;
	for(int i = k; i < n; i++){
		ans += h[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
a.insert(n+1,0)
total = 0
for i in range(n+1):
    total += abs(a[i+1] - a[i])
for i in range(1, n+1):
    print(total + abs(a[i+1] - a[i-1]) - abs(a[i+1] - a[i]) - abs(a[i-1] - a[i]))

Measured memory_bytes: 13920
lst = input().split()
N = int(lst[0])
M = int(lst[1])

A = []
B = []

for i in range(N):
   A.append(input())

for i in range(M):
   B.append(input())

if A == B:
   print('Yes')
   exit()

for x in range(N-M):
   for y in range(N-M):
      count = 1
      for i in range(M):
         if A[y+i][x:x+M] != B[i]:
            count = 0
      if count == 1:
         print('Yes')
         exit()

print('No')

Measured memory_bytes: 9220
n = int(input())
f = 0
k = 0
for i in range(n):
    a,b = map(int,input().split())
    if(a == b):
        f += 1
        if(f == 3):
            k = 1
    else:
        f = 0
    
if(k== 1):
    print("Yes")
else:
    print("No")


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


def solve(N: int):
    x=[[0]*10 for _ in range(10)]
    for i in range(N):
        h=int(str(i+1)[0])
        t=(i+1)%10
        x[h][t]+=1

    ans=0
    for i in range(9):
        ans+=x[i+1][i+1]**2

    for i in range(9):
        for j in range(8-i):
            ans+=x[i+1][j+i+2]*x[j+i+2][i+1]*2

    print(ans)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    
    int cur = 0;
    ll res = 0;
    int alen = 0;
    while(cur+1<S.size()){
        if(S[cur]=='A')alen++;
        string check = S.substr(cur,2);
        if(check=="BC"){
            res += alen;
            cur++;
        }else if(S[cur]!='A'){
            alen=0;
        }
        cur++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
function solve(N:number, A: number[]):number{
    const f=fact(N);
    let sum=0;
    for(let i=0;i<N;i++){
      sum+=mul(A[i],sub(add(tasuyatu(N-i),tasuyatu(i+1)),1));
    }
    sum=mul(sum,f);
    return sum;
  }
  function Main(raw: string) {
    const lines = raw.split("\n");
    const N = parseInt(lines[0], 10);
    const AB = lines[1].split(" ");
    const A = parseInt(AB[0], 10);
    const B = parseInt(AB[1], 10);
    const P = lines[2].split(" ").map(str=>parseInt(str, 10));
    
    let count=[0,0,0];
    P.forEach((p)=>{
        if(p<=A){
            count[0]++;
        }else if(p<=B){
            count[1]++;
        }else{
            count[2]++;
        }
    });
    const ans = count.reduce((x,y)=>Math.min(x,y),1000000);

    //出力
    console.log("%d", ans);
  }
  
  //DO NOT EDIT
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string S;
    cin >> S;
    int last = sz(S) - 1;
    if (S[last] == 's') {
        cout << S << "es" << '\n';
    }
    else {
        cout << S << "s" << '\n';
    }
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 3628
H,W=map(int,input().split())
C=[1001]*10
C[1]=0

c=[list(map(int,input().split())) for _ in range(10)]

for _ in range(10):
  for i in range(10):
    if i!=1:
      for j in range(10):
        if i!=j:
          if C[i]>c[i][j]+C[j]:
            C[i]=c[i][j]+C[j]
          
ans=0        
for i in range(H):
  for j in list(map(int,input().split())):
    if j!=-1:
      ans+=C[j]
print(ans)

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

using namespace std;

int Solve(int n, const vector<string> &op) {
    // + := -1, - := -2, * := -3
    vector<pair<int, int>> cur(n, make_pair<int, int>(0, 0));
    for (int i = 0; i < n; ++i) {
        cur[i].first = op[i].size() - 1;
        if (op[i].back() == '+')
            cur[i].second = -1;
        else if (op[i].back() == '*')
            cur[i].second = -2;
        else
            cur[i].second = (int)(op[i].back() - '0');
    }

    while (cur.size() != 1) {
        int h = -1, src = -1, dst = -1;

        for (size_t i = 0; i < cur.size(); ++i)
            if (h < cur[i].first)
                h = cur[i].first;
        for (size_t i = 0; i < cur.size(); ++i) {
            if (src == -1 && cur[i].first == h)
                src = i;
            else if (cur[i].first == h)
                dst = i;
            else if (dst != -1 && cur[i].first < h)
                break;
        }

        int res = 0;
        if (cur[src - 1].second == -1) { // +
            for (int i = src; i <= dst; ++i)
                res += cur[i].second;
            cur[src - 1].second = res;
        }
        else if (cur[src - 1].second == -2) { // *
            res = cur[src].second;
            for (int i = src + 1; i <= dst; ++i)
                res *= cur[i].second;
            cur[src - 1].second = res;
        }

        cur.erase(cur.begin() + src, cur.begin() + dst + 1);
    }

    return cur[0].second;
}

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

    int n;

    while (cin >> n, n) {
        vector<string> op(n);
        for (int i = 0; i < n; ++i)
            cin >> op[i];

        cout << Solve(n, op) << endl;
    }

    return 0;
}

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

struct edge {
    int to, w;
};

vector<int> color;
vector<vector<edge>> g;

bool dfs( int k, int c ) {
    color[k] = c;
    for ( int i = 0; i < g[k].size(); i++ ) {
        edge e = g[k][i];
        if ( color[e.to] < 0 ) {
            if( e.w%2 == 1 ) {
                dfs( e.to, 1 - c );
            } else {
                dfs( e.to, c );
            }
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    int u,v,w;
    g.resize(N, vector<edge>());
    for ( int i = 0; i < N - 1; i++ ) {
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].push_back(edge{ v, w });
        g[v].push_back(edge{ u, w });
    }
    
    color.resize(N, -1);
    for ( int i = 0; i < N; i++ ) {
        int c = 0;
        if ( color[i] < 0 ) {
            dfs(i, c);
        }
    }

    for ( int i = 0; i < N; i++ ) {
        cout << color[i] << '\n';
    }
    return 0;
}


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

typedef  vector< vector<int> > vector2d;

int main() {
  
    int H,W,count=0,kaisuu=0,kosuu,sum,judge;
    char map[20][20];
    vector2d nextx,nexty; //nextx[回数][個数]
    nextx.reserve(10000);
    nexty.reserve(10000);

  while(1){
    cin >>W>>H;
    if (W==0&&H==0)break;
    
    //マップの入力
    for(int cH=0;cH<H;cH++){
	for(int cW=0;cW<W;cW++){
	  cin >> map[cW][cH];
	  if (map[cW][cH]=='@'){
	    nextx[kaisuu].push_back(cW);
	    nexty[kaisuu].push_back(cH);
	  }
	}
    }
    sum = 1;
    while(1){
      judge = 0;
      for(kosuu=0;kosuu<nextx[kaisuu].size();kosuu++){
	if (nextx[kaisuu][kosuu]-1!=-1){
	  if(map[ nextx[kaisuu][kosuu]-1 ][ nexty[kaisuu][kosuu] ]=='.'){  //@の左側をチェック
	    //もし'@'だったらその座標を保存しそれを@に！
	    nextx[kaisuu+1].push_back(nextx[kaisuu][kosuu]-1);
	    nexty[kaisuu+1].push_back(nexty[kaisuu][kosuu]);
	    map[ nextx[kaisuu][kosuu]-1 ][ nexty[kaisuu][kosuu] ]='@';
	    sum++;
	    judge++;
	  }
	}
	if (nexty[kaisuu][kosuu]-1!=-1){
	  if(map[ nextx[kaisuu][kosuu] ][ nexty[kaisuu][kosuu]-1 ]=='.'){  //@の上側をチェック
	    //もし'@'だったらその座標を保存しそれを@に！
	    nextx[kaisuu+1].push_back(nextx[kaisuu][kosuu]);
	    nexty[kaisuu+1].push_back(nexty[kaisuu][kosuu]-1);
	    map[ nextx[kaisuu][kosuu] ][ nexty[kaisuu][kosuu]-1 ]='@';
	    sum++;
	    judge++;
	  }
	}
	if (nextx[kaisuu][kosuu]+1!=W){
	  if(map[ nextx[kaisuu][kosuu]+1 ][ nexty[kaisuu][kosuu] ]=='.'){  //@の右側をチェック
	    //もし'@'だったらその座標を保存しそれを@に！
	    nextx[kaisuu+1].push_back(nextx[kaisuu][kosuu]+1);
	    nexty[kaisuu+1].push_back(nexty[kaisuu][kosuu]);
	    map[ nextx[kaisuu][kosuu]+1 ][ nexty[kaisuu][kosuu] ]='@';
	    sum++;
	    judge++;
	  }
	}
	if (nexty[kaisuu][kosuu]+1!=H){
	  if(map[ nextx[kaisuu][kosuu] ][ nexty[kaisuu][kosuu]+1 ]=='.'){  //@の下側をチェック
	    //もし'@'だったらその座標を保存しそれを@に！
	    nextx[kaisuu+1].push_back(nextx[kaisuu][kosuu]);
	    nexty[kaisuu+1].push_back(nexty[kaisuu][kosuu]+1);
	    map[ nextx[kaisuu][kosuu] ][ nexty[kaisuu][kosuu]+1 ]='@';
	    sum++;
	    judge++;
	  }
	}
      }
      if (judge==0)break;
      kaisuu++;
    }
    kaisuu++;
    cout << sum <<endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 1640
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 4005
#define ll long long
#define mod 998244353
char s[N];int n,s1[N],s2[N],f[N][N];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		s1[i]=s1[i-1],s2[i]=s2[i-1];
		if(s[i]=='0')s1[i]+=2;
		else if(s[i]=='2')s2[i]+=2;
		else s1[i]++,s2[i]++;
	}
	f[0][0]=1;
	for(int i=1;i<=n*2;i++)
	{
		int t=min(i,n);
		for(int j=0;j<=i;j++)
		{
			if(j<=s1[t])(f[i][j]+=f[i-1][j-1])%=mod;
			if((i-j)<=s2[t])(f[i][j]+=f[i-1][j])%=mod;
		}
	}
	printf("%d\n",f[n*2][s1[n]]);
}


Measured memory_bytes: 61440