akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

pair<int, int> dp[303][303];

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

    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int>> dist(n, vector<int>(n, 1e18));
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = dist[b][a] = c;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i][j] = {1e18, 0};
        }
    }

    for (int i = 0; i < n; i++) {
        using P = tuple<int, int, int>;
        priority_queue<P, vector<P>, greater<>> que;
        que.emplace(0, -l, i);
        dp[i][i] = {0, -l};
        while (!que.empty()) {
            auto t = que.top();
            que.pop();
            int hokyu = get<0>(t);
            int nokori = get<1>(t);
            int v = get<2>(t);
            pair<int, int> now = {hokyu, nokori};
            if (dp[i][v] < now) continue;
            for (int j = 0; j < n; j++) {
                if (dist[v][j] != 1e18) {
                    if (nokori + dist[v][j] <= 0) {
                        if (make_pair(hokyu, nokori + dist[v][j]) < dp[i][j]) {
                            dp[i][j] = make_pair(hokyu, nokori + dist[v][j]);
                            que.emplace(hokyu, nokori + dist[v][j], j);
                        }
                    } else if (-l + dist[v][j] <= 0) {
                        if (make_pair(hokyu + 1, -l + dist[v][j]) < dp[i][j]) {
                            dp[i][j] = make_pair(hokyu + 1, -l + dist[v][j]);
                            que.emplace(hokyu + 1, -l + dist[v][j], j);
                        }
                    }
                }
            }
        }
    }

    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        int c = dp[a][b].first;
        if (c == 1e18) c = -1;
        cout << c << '\n';
    }
}


Measured memory_bytes: 2688
#include<stdio.h>
main(){
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c){
    tmp=b;
    b=c;
    c=tmp;
  }
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}


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

int main()
{
	string s, p;
	cin >> s >> p;

	bool match;
	for(size_t i=0; i<s.size(); ++i) {
		int i0 = i;
		match = true;
		for(auto c : p) match &= c==s[i0++ % s.size()];
		if(match) break;
	}

	cout << (match ? "Yes\n" : "No\n");

	return 0;
}



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

int main(){

  int i;
  
  int N;
  cin >> N;
  
  vector<string> blue(N);
  for(i = 0; i < N; i++)
    cin >> blue.at(i);
  
  int M;
  cin >> M;
  
  vector<string> red(M);
  for(i = 0; i < M; i++)
    cin >> red.at(i);
  
  int max = 0;
  int k;
  
  for(i = 0; i < N; i++){
    int sum = 0;
    
    for(k = 0; k < N; k++){ 
    if(blue.at(i) == blue.at(k)) sum++;
    }
    
    for(k = 0; k < M; k++){
      if(blue.at(i) == red.at(k)) sum--;
    }
    
    if(sum > max) max = sum;
  }
  
   for(i = 0; i < M; i++){
     int sum = 0;
    
    for(k = 0; k < N; k++){ 
    if(red.at(i) == blue.at(k)) sum++;
    }
    
    for(k = 0; k < M; k++){
      if(red.at(i) == red.at(k)) sum--;
    }
    
    if(sum > max) max = sum;
  }
  
  cout << max << endl;
}
    
    
  

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pi              pair<int,int>
#define vi              vector<int>
#define mi              map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1N
#define loop(i,a,b)     for(int i=a;i<b;i++)

void c_p_c(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin) ;
    // freopen("output.txt","w",stdout) ;
    // #endif
}

int32_t main(){
    c_p_c();
    int s,w; cin >> s >> w;
    if(w >= s) cout << "unsafe" ;
    else cout << "safe";

}























































































Measured memory_bytes: 3640
from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(lambda x:int(x)-1,input().split()))
edges = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b,c))
    edges[b].append((a,c))
V = N
INF = float("inf")
dp = [[INF]*V for _ in range(V)]
for i in range(V):
    for j, w in edges[i]:
        dp[i][j] = w
for k in range(V):
    for i in range(V):
        for j in range(V):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])

ans = INF
for p in permutations(r):
    t = 0
    for i in range(1, R):
        t += dp[p[i]][p[i-1]]
    ans = min(ans, t)
print(ans)

Measured memory_bytes: 76684
c = [list(map(int, input().split())) for _ in range(3)]

flag = True
for i in range(1, 3):
    tmp_del = c[i][0] - c[i-1][0]
    for j in range(1, 3):
        if c[i-1][j]+tmp_del==c[i][j]:
            continue
        else:
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX_Bi = 100;
int main()
{
    int N, M, C;
    int cnt = 0;
    cin >> N >> M >> C;
    int B[MAX_Bi];
    int A[23][23];
    for (int i = 0; i < M; i++)
        cin >> B[i];

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < N; i++)
    {
        int tmp = 0;
        for (int j = 0; j < M; j++)
        {
            tmp += A[i][j] * B[j];
            //printf("%d\n", tmp);
        }
            if (tmp + C > 0) cnt++;
        
    }
    //printf("%d\n", s);

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int c,x,i,sum = 0,putop = 0,xtop = 0;
    int xstack[20000];
    int lefts[20000];
    int vols[20000];

    for(x = 0; (c = getchar()) != '\n'; x++){
        if(c == '\\'){
            xstack[xtop++] = x;
        } else if (c == '/'){
            if(xtop == 0) continue;
            int last_x = xstack[--xtop];
            int new_vol = x - last_x;
            while(putop > 0 && last_x < lefts[putop-1]){
                new_vol += vols[--putop];
            }
            lefts[putop] = x;
            vols[putop] = new_vol;
            putop++;
        }
    }
    for(i=0; i<putop; i++){
        sum += vols[i];
    }
    
    printf("%d\n%d", sum, putop);
    
    for(i=0; i<putop; i++){
        printf(" %d", vols[i]);
    }
    puts("");
}


Measured memory_bytes: 2108
n = int(input())
h = list(map(int, input().split()))

maxh = h[0]
flag = True
for i in range(1, n):
    if maxh - h[i] > 1:
        flag = False
    
    if h[i] > maxh:
        maxh = h[i]
        
if flag:
    print("Yes")
else :
    print("No")

Measured memory_bytes: 14276
import sys
import math
input = sys.stdin.readline

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

H.sort()
count = 0
try:
    for _ in range(K):
        H.pop()
        count += 1

except:
    pass

ans = sum(H)
print(ans)


Measured memory_bytes: 27276
def sub():
    N = int(input())
    buf_abc = [[int(e) for e in input().split()] for _ in range(N)]
    
    class ZeroDict(dict):
        def __missing__(self, key):
            self[key] = 0 
            return 0

    dp_table = ZeroDict()
    
    dp_table[(1, 0)] = buf_abc[0][0]
    dp_table[(1, 1)] = buf_abc[0][1]
    dp_table[(1, 2)] = buf_abc[0][2]
    for i in range(1, N):
        for j, (k,l) in enumerate([[1,2], [0,2], [0,1]]):
            candi = max(dp_table[(i, k)]+buf_abc[i][j], dp_table[(i, l)]+buf_abc[i][j])
            dp_table[(i+1,j)] = max(candi, dp_table[(i+1,j)])

    vv = [dp_table[(N, i)] for i in range(3)]
    print(max(vv))
    # tt = sorted([(k,v) for k, v in dp_table.items()])
    # for t in tt:
    #     print(t)

sub()


Measured memory_bytes: 95960
from collections import defaultdict


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

    color = defaultdict(int)

    for aa in a:
        if aa < 3200:
            color[aa//400] += 1
        else:
            color[8] += 1

    min_ans = len(color)
    max_ans = len(color)

    if 8 in color:
        min_ans = max(1, min_ans-1)
        max_ans += color[8] - 1

    print(min_ans, max_ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  const in inf=1e16;
  VI bst(3,-inf);
  VI nubst(3,-inf);
  cin>>bst[0];
  char sgn;
  in ta;
  forn(z,n-1){
    cin>>sgn;
    assert(sgn=='+' || sgn=='-');
    cin>>ta;
    nubst=VI(3,-inf);
    if(sgn=='+'){
      nubst[0]=max(nubst[0],bst[0]+ta);
      nubst[1]=max(nubst[1],bst[1]-ta);
      nubst[0]=max(nubst[0],bst[1]+ta);
      nubst[2]=max(nubst[2],bst[2]+ta);
    }
    else{
      nubst[1]=max(nubst[1],bst[0]-ta);
      nubst[2]=max(nubst[2],bst[1]+ta);
      nubst[2]=max(nubst[2],bst[2]+ta);
    }
    bst=nubst;
  }
  cout<<max(bst[0],max(bst[1],bst[2]))<<endl;
  return 0;
}


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

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	n%=10;
	if(n==2 || n==4 || n==5 || n==7 || n==9)
		printf("hon");
	else if(n==3) printf("bon");
	else printf("pon");
}


Measured memory_bytes: 3828
#include<stdio.h>
int main()
{
    int a,b,c;
    int temp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    if(b>c){
        temp=c;
        c=b;
        b=temp;
    }
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int main() {
  vector<char> a(9);
    
  for (int j = 0; j < 9 ; j++) {
    cin >> a.at(j);
  }
  
  cout << a.at(0) << a.at(4) << a.at(8) << endl; 
}

Measured memory_bytes: 3452
import java.util.Arrays;
import java.util.Scanner;

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

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

	void run() throws Exception {
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		Hoge[] ds = new Hoge[m];
		Hoge[] cl = new Hoge[m];
		
		for(int i=0; i<m; i++) {
			int p = Integer.parseInt(sc.next());
			int y = Integer.parseInt(sc.next());
			ds[i] = cl[i] = new Hoge(p, y);
		}
		Arrays.sort(cl);

		int id = 0;
		for(int i=0; i<m; i++) {
			if(i==0 || cl[i].pref != cl[i-1].pref) id = 0;
			cl[i].setId(++id);
		}
		
		for(int i=0; i<m; i++) System.out.println(ds[i]);
	}
}
class Hoge implements Comparable<Hoge>{
	int pref;
	int year;
	int id;

	Hoge(int p, int y) {
		pref = p;
		year = y;
	}
	
	@Override
	public int compareTo(Hoge o)
	{
		return pref<o.pref ? 1 : pref>o.pref ? -1 : Integer.compare(year, o.year);
	}

	public void setId(int id)
	{
		this.id = id;
	}
	
	@Override
	public String toString()
	{
		return String.format("%06d%06d", pref, id);
	}
}

Measured memory_bytes: 115952
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vec;
typedef vector<vec> mat;
#define N 3
int po[N*N+10];
int m2i(mat m){
  int res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res+=m[i][j]*po[i*N+j];
  return res;
}
mat i2m(int x){
  mat res(N,vec(N));;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res[i][j]=(x%po[i*N+j+1])/po[i*N+j];
  return res;
}

signed main(){
  po[0]=1;
  for(int i=0;i<N*N;i++) po[i+1]=po[i]*10;
  mat p(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>p[i][j];
  mat e(p);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      e[i][j]=i*N+j+1;
  e[N-1][N-1]=0;
  int ans=m2i(e);
  //cout<<ans<<endl;
  queue<int> q;
  map<int,int> m;
  q.push(m2i(p));
  m[m2i(p)]=0;
  int ax[]={1,0,-1,0};
  int ay[]={0,1,0,-1};
  while(!q.empty()){
    int x=q.front();q.pop();
    if(x==ans) break;
    //cout<<x<<endl;
    p=i2m(x);
    int zy,zx;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	if(p[i][j]==0) zy=i,zx=j;
    //cout<<zy<<" "<<zx<<endl;
    for(int k=0;k<4;k++){
      int ny=zy+ay[k],nx=zx+ax[k];
      if(ny<0||N<=ny||nx<0||N<=nx) continue;
      swap(p[zy][zx],p[ny][nx]);
      int t=m2i(p);
      //cout<<t<<endl;
      if(!m.count(t)){
	m[t]=m[x]+1;
	q.push(t);
      }
      swap(p[zy][zx],p[ny][nx]);
    }
  }
  cout<<m[ans]<<endl;
  return 0;
}

Measured memory_bytes: 14448
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer>
inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar()) init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 0, INF = 1e9;

int main() {
	string s;
	cin >> s;
	rep (i, 1, 3) if (s[i] == s[i - 1]) {
		cout << "Bad" << endl;
		return 0;
	}
	cout << "Good" << endl;
	return 0;
}



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


int main() {
    int n;
    cin >> n;
    vector< vector< vector<int>>> data(4,vector< vector<int>>(3,vector<int>(10,0)));
    int b,f,r,v;
    rep(i,n){
        cin >> b >> f >> r >> v;
        data.at(b-1).at(f-1).at(r-1) += v;
    }
    rep(i,4){
        rep(j,3){
            rep(k,10){
                cout << ' ' << data.at(i).at(j).at(k);
            }
            cout << endl;
        }
        if(i!=3)cout << "####################" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3172
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    int fl=0;
    scanf("%d",&n);
    for(int i=1;i<=9;i++){
        if(n%i==0 && (n/i)>=1 && (n/i)<=9)fl=1;
    }
    if(fl)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 15;
const int INF = 19191919;
int dp[1<<N];

int main(){
    int n,m;
    while(scanf(" %d %d", &n, &m),n){
        vector<int> s(n),d(m);
        rep(i,n) cin >>s[i];
        rep(i,m) cin >>d[i];
        sort(all(d));

        vector<int> nuk(1<<n);
        rep(mask,1<<n){
            rep(i,n)if(mask>>i&1) nuk[mask] += s[i];
        }

        fill(dp, dp+(1<<N), INF);
        dp[0] = 0;
        rep(mask,1<<n){
            rep(i,n)if(!(mask>>i&1)){
                int nx = mask|(1<<i);

                int lidx = lower_bound(all(d), nuk[mask]) - d.begin();
                int ridx = upper_bound(all(d), nuk[nx]) - d.begin();
                int add = 0;
                for(int j=lidx; j<ridx; ++j){
                    add += min(d[j]-nuk[mask], nuk[nx]-d[j]);
                }
                dp[nx] = min(dp[nx], dp[mask]+add);
            }
        }

        int add = 0;
        rep(i,m)if(nuk[(1<<n)-1] < d[i]) add += d[i]-nuk[(1<<n)-1];
        printf("%d\n", dp[(1<<n)-1]+add);
    }
    return 0;
}



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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i=0;i<N; ++i) cin >> a[i];
  
  sort(a,a+N,greater<int>());
  int Alice =0;
  int Bob = 0;
  for(int i = 0;i < N; ++i)
    if(i%2==0){//先手で0からカウントなので
    	Alice +=a[i];
    }
  	else{//後手
    	Bob +=a[i];
    }
	
	cout<<Alice - Bob <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  string S;
  while(cin >> N >> S){

    int ans = 0;
    REP(i,N-2){
      if(S.substr(i,3) == "ABC") ++ans;
    }

    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    int A,B,a,b;
    cin>>A>>B>>a>>b;
    if(A%a==0&&B%b==0) return puts("No"),0;
    int k=999999999/(a*b-1);
    puts("Yes");
    for(int i=1;i<=A;i++) {
	for(int j=1;j<=B;j++) {
	    if(i%a==0&&j%b==0) printf("%d ",-(a*b-1)*k-1);
	    else printf("%d ",k);
	}
	puts("");
    }
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  int N; cin>>N;

  char S[N][N];

  rep(i,N){
    rep(j,N){
      cin>>S[i][j];
    }
  }

  int iszero[N]; //0,1, -1mada
  rep(i,N) iszero[i]=-1;

  bool isup=true;
  bool update[N]={};
  iszero[0]=0;
  int now=0;
  update[now]=true;
  deque<int> dq;
  dq.push_back(0);
  while(!dq.empty()){
    now=dq.front();
    dq.pop_front();
    rep(j,N){
      if(S[now][j]=='0') continue;
      if(iszero[j]== -1){
        iszero[j]=1-iszero[now];
      }
      else{
        if(iszero[j]==iszero[now]){
          cout<< -1<<"\n";
          return;
        }
      }
      if(update[j]==false){
        update[j]=true;
        dq.push_back(j);
      }
    }

  }

  const int MAXN=N; // 変える // warshall_floyd
  int dist[MAXN][MAXN];
  rep(i,MAXN){
    rep(j,MAXN){
      dist[i][j]=INF;
    }
    dist[i][i]=0;
  }

  rep(i,N){
    rep(j,N){
      if(S[i][j]=='1') dist[i][j]=1;
    }
  }
  rep(k,MAXN) rep(i,MAXN) rep(j,MAXN) dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
  //warshall_floyd end

  int ans=0;
  rep(i,N){
    rep(j,N){
      maxi(ans,dist[i][j]);
    }
  }

  cout<< ans+1<<"\n";




}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))

ans = 0
mod = 1000000007

a = [-1] + a
pre = [0]

for i in range(1, n+1):
    pre.append((pre[i-1] + a[i]) % mod)
pre.append(0)

for i in range(1, n+1):
    now = (pre[n] - pre[i]) * a[i] % mod
    ans = (ans + now) % mod

print(ans)

Measured memory_bytes: 31520
a,b=map(int,input().split())
masu=list(map(int,input()))
i=0
m=[]
while i<len(masu)-1:
  k=masu.index(0,i+1)-i
  m+=[k]
  i+=k
if max(m)>b:print(-1)
else:
  i=len(m)-1
  while i:
    if m[i]+m[i-1]<=b:
      m[i]+=m[i-1]
      del m[i-1]
    i-=1
  print(' '.join(map(str,m)))

Measured memory_bytes: 11168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans[305][305];
bool b[305][305];
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            char c;
            cin>>c;
            if(c=='#')
                b[i][j]=1;
            else b[i][j]=0;
        }
    }
    int cnt=1,maxa=-1;
    for(int i=0;i<h;i++)
    {
        bool x=0;
        int maxj=-1;
        for(int j=0;j<w;j++)
        {
            for(int k=maxa+1;k<=i;k++)
            {
                ans[k][j]=cnt;
            }
            if(b[i][j])
                {
                    cnt++;
                    x=1;
                    maxj=j;
                }
        }

        if(maxj!=-1)
        {
            for(int j=maxj+1;j<w;j++)
            {
                for(int k=maxa+1;k<=i;k++)
                    ans[k][j]=ans[i][maxj];
            }
        }
        if(x)
        {
            maxa=i;
        }
    }
    for(int i=maxa+1;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            ans[i][j]=ans[maxa][j];
        }
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cout<<ans[i][j]<<' ';
        }
        cout<<'\n';
    }
}



Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main() {
	long long int N;
	cin >> N;
	bool hh = false;
	for (long long int h = 1; h <= 3500; h++) {
		for (long long int n = 1; n <= 3500; n++) {
			if (4 * h*n - N*h - N*n == 0) {

			} else if (N*h*n % (4 * h*n - N*h - N*n) == 0 && ((N*h*n) / (4 * h*n - N*h - N*n)) > 0) {
				cout << h << ' ' << n << ' ' << (N*h*n) / (4 * h*n - N*h - N*n) << endl;
				hh = true;
				break;
			}
		}
		if (hh) {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))

ll n,W;
ll w[101],v[101];
ll dp[101][100010];
ll totalV=0;

ll minWeight(ll end, ll Val)
{
  if(Val<=0)
  return 0;
  if(end==0)
  return INT_MAX;
  if(dp[end][Val]!=1000000010)
  return dp[end][Val];
  // if(v[end-1]>Val)
  // return dp[end][Val]=minWeight(end-1,Val);
  // else
  return dp[end][Val]=min(w[end-1]+minWeight(end-1,Val-v[end-1]), minWeight(end-1,Val));
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j;
    cin>>n>>W;
    for(i=0;i<n;i++)
    {
      cin>>w[i]>>v[i];
      totalV+=v[i];
    }

    for(i=0;i<=n;i++)
      for(j=0;j<=totalV;j++)
        dp[i][j]=1000000010;

    for(i=totalV;i>=1;i--)
    {
      if(minWeight(n,i)<=W)
      break;
    }
    cout<<i;
    return 0;
}

Measured memory_bytes: 82504
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class UnionFind {
public:
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int m) {
        n = m;
        parent.resize(n);
        rank.resize(n, 0);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    int find(int node) {
        if (parent[node] == node) {
            return node;
        } else {
            parent[node] = find(parent[node]);
            return parent[node];
        }
    }

    void unite(int node1, int node2) {
        node1 = find(node1);
        node2 = find(node2);
        if (node1 == node2) {
            return;
        } else {
            if (rank[node1] < rank[node2]) {
                parent[node1] = node2;
            } else if (rank[node1] > rank[node2]) {
                parent[node2] = node1;
            } else {
                parent[node1] = node2;
                rank[node1] += 1;
            }
        }
    }

    bool same(int node1, int node2) {
        node1 = find(node1);
        node2 = find(node2);
        if (node1 == node2) {
            return true;
        } else {
            return false;
        }
    }
};

struct edge {int u, v, cost;};
vector<edge> g;
bool compare(const edge &a, const edge &b) {
    return a.cost < b.cost;
}

int main() {
    int n;
    cin >> n;
    vector<P> x(n), y(n);
    rep(i, n) {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    rep(i, n-1) {
        g.push_back({x[i].second, x[i+1].second, x[i+1].first - x[i].first});
        g.push_back({y[i].second, y[i+1].second, y[i+1].first - y[i].first});
    }

    sort(g.begin(), g.end(), compare);

    UnionFind uf(n);
    int ans = 0;
    rep(i, g.size()) {
        if (!uf.same(g[i].u, g[i].v)) {
            uf.unite(g[i].u, g[i].v);
            ans += g[i].cost;
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6516
N = int(input())
seq = list(map(int, input().split()))
count = 0

for i in range(len(seq)):
    min = i
    for j in range(i, len(seq)):
        if seq[j] < seq[min]:
            min = j
    if seq[i] != seq[min]:
        seq[i], seq[min] = seq[min], seq[i]
        count += 1
    if seq == sorted(seq):
        print(*seq)
        print(count)
        break



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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<LL> VI;
typedef unsigned long long ULL;

#define MP make_pair
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define f first
#define s second
#define FILL(a, b) memset(a, b, sizeof(a))
#define mytype __int128

const int MAX = 1*100 + 7;
const int INF = 1000*1000*1000;
const LL LINF = 1LL*INF*INF;
const int MOD = INF + 7;
const double PI = acos(-1.);

PII a[MAX];
PII b[MAX];
VI g[MAX];

int u[MAX];
int col;
int p[MAX];
bool dfs(int v)
{
	if(u[v] == col)
		return 0;
	u[v] = col;
	FOR(i,0,SZ(g[v]))
	{
		if(p[g[v][i]]==-1 || dfs(p[g[v][i]]))
		{
			p[g[v][i]] = v;
			return 1;
		}
	}
	return 0;
}
int dokun(int n)
{
	FILL(p,-1);
	col = 0;
	int ans = 0;
	FOR(i,0,n)
	{
		col++;
		ans += dfs(i);
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	FOR(i,0,n)
		cin >> a[i].f >> a[i].s;
	FOR(i,0,n)
		cin >> b[i].f >> b[i].s;
	FOR(i,0,n)
	{
		FOR(j,0,n)
		{
			if(a[i].f < b[j].f && a[i].s < b[j].s)
			{
				g[j].PB(i);
			}
		}
	}
	cout << dokun(n);
	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
    
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a==0&&b==0) break;
            for(int i=0;i<a;i++){
                for(int j=0;j<b;j++){
                if(i==0||i==a-1||j==0||j==b-1){
                    System.out.printf("#");
                }else{
                    System.out.printf(".");
                }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
        sc.close();
    }
}


Measured memory_bytes: 60752
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A, B = map(int, readline().split())
print(min(N*A,B))


Measured memory_bytes: 3060
N, K, Q = map(int, input().split())

lst = [(K-Q) for i in range(N)]

for i in range(Q):
	num = int(input())
	lst[num-1] += 1

for i in range(N):
	if lst[i] > 0:
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 7892
#include<iostream>
#include<string>
#include<algorithm>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
bool visited[100005];
const int max_N = 1e5 + 10;
int N;
int Y;
int flag = 0;
int money;
int d[105];
int main(void) {
	cin >> N >> Y;

	money = Y;
	int i=0, j=0, k=0;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N-i; j++) {
			money = Y - 10000*i - 5000*j;
			if (money % 1000 == 0){
				k = money / 1000;
				if (k >= 0 && N-i-j-k == 0) {
					flag = 1;
					break;
				}
			}
		}
		if (flag == 1)break;
	}
	if (flag == 0) {
		i = -1, j = -1, k = -1;
	}

	
	cout << i << ' ' << j << ' ' << k << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[100000], b[100000], c[100000];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%d", &a[i]);
	for (int i = 0; i < num; i++)scanf("%d", &b[i]);
	for (int i = 0; i < num; i++)scanf("%d", &c[i]);
	sort(a, a + num);
	sort(c, c + num);
	ll ans = 0;
	for (int i = 0; i < num; i++)
	{
		ll s = upper_bound(a, a + num, b[i] - 1) - a;
		ll t = lower_bound(c, c + num, b[i] + 1) - c;
		ans += s*(num - t);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1280
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby, combinations
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return list(map(lambda x: x + d, A))
def ldec(A, d=1): return list(map(lambda x: x - d, A))

def modinv(a, n):
    (x, lastx) = (0, 1); (y, lasty) = (1, 0); p = n
    while p != 0:
       q = a // p; (a, p) = (p, a % p)
       (x, lastx) = (lastx - q * x, x); (y, lasty) = (lasty - q * y, y)
    return lastx % n

N = n1()
A = nn()

mod = 10**9 + 7

s = sum(A) % mod

ans = 0
for i in range(len(A)):
    ans += ((s - A[i]) * A[i]) % mod

print((ans * modinv(2, mod)) % mod)


Measured memory_bytes: 98352
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int n,x,t;
    cin>>n>>x>>t;
    int ans=(n/x+(n%x>0))*t;
    cout<<ans;
    return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long s = 0;
    for (long x : a) s ^= x;
    vector<long> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        b[i] = a[i] & (~s);
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    vector<long> q;
    long c = 0;
    for (long x : b) {
        for (long y : q) {
            x = min(x, x ^ y);
        }
        if (x > 0) {
            q.push_back(x);
            c = max(c, c ^ x);
        }
    }
    s += c * 2;
    cout << s;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	bool arr[26];
	fill(arr,arr+26,0);
	string s;
	cin>>s;
	for(char c:s) {
		if(arr[(c-'a')]){
			cout<<"no";
			return;
		}
		arr[c-'a']=1;
	}
	cout<<"yes";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


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

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;

  int ans;
  for (int i = 0; i < N; i++) {
    ans = N + i;
    for (int j = 0; i + j < N; j++) {
      if (s[i+j] != t[j])break;
      if (i + j == N - 1) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << 2 * N << endl;
}

Measured memory_bytes: 256
program joker
  implicit none
  integer :: n, p(250000) = 0, h(0:501, 0:501) = 0, i, j, k
  integer :: di(4) = (/0, 1, 0, -1/), dj(4) = (/1, 0, -1, 0/)
  logical :: u(0:501, 0:501) = .false.
  integer(8) :: m = 0
  read(*,*) n
  read(*,*) p(1:n * n)
  do i = 1, n
    do j = 1, n
      h(i, j) = min(i - 1, n - i, j - 1, n - j)
      u(i, j) = .true.
    end do
  end do
  do k = 1, n * n
    i = (p(k) - 1) / n + 1
    j = mod(p(k) - 1, n) + 1
    m = m + h(i, j)
    u(i, j) = .false.
    call dfs(i, j)
  end do
  write(*,'(i0)') m
contains
  recursive subroutine dfs(i, j)
    integer, intent(in) :: i, j
    integer :: k, x, y, d
    d = h(i, j) + merge(1, 0, u(i, j))
    do k = 1, 4
      x = i + di(k)
      y = j + dj(k)
      if (h(x, y) > d) then
        h(x, y) = d
        call dfs(x, y)
      end if
    end do
  end
end program joker

Measured memory_bytes: 29128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll N,M;
	cin>>N>>M;
	vector<vector<ll>> from(N);
	REP(i,M){
		ll a,b;
		cin>>a>>b;
		from[a-1].push_back(b-1);
	}
	REP(i,from[0].size()){
		auto tmp=from[0][i];
		REP(j,from[tmp].size()){
			if(from[tmp][j]==N-1){
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 8960
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

int main () {
    // N
    // A_1 ...... A_N
    int N;
    cin >> N;
    vi vec(N);
    int a;
    for (int i=0; i < N-1; i++) {
        cin >> a;
        vec[a-1]++;
    }
    for (const auto& v: vec) {
        std::cout << v << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>
#include<sstream>
#include<bitset>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll> x(n);
    REP(i,0,n) cin>>x[i];
    
    ll ans=0;
    REP(i,0,n-1){
        ans += min((x[i+1]-x[i])*a,b);
    }
    cout<<ans<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
lo a,b,c,d,e,x,n,m,t,y,a1[100005],a2[100005],a3[100005],bir,sifir;
char c1,c2,c3,c4; 
string s1,s2,s3,s4,s[1005];
lo der[100]={60,90,108,120};
bool av=false;
// pair <lo, pair <lo, lo> > a3[105];
vector <pair<lo, lo> > v;
map <lo,lo> mp1;
int main() {
    // freopen("gir.gir","r",stdin);
    // freopen("cik.cik","w",stdout);
    cin>>s1;
    char ch[1000];
    for(lo i=1;i<=s1.size();i++){
        ch[i]=s1[a];
        a++;
    }
    for(lo i=1;i<=s1.size();i++){
        if(i%2==0){
            if(ch[i]=='R'){
                cout<<"No\n";
                return 0;
            }
        }
        else{
            if(ch[i]=='L'){
                cout<<"No\n";
                return 0;
            }
        }
    }
    cout<<"Yes\n";
    return 0;
}
//54 + 40 = 94
//10 + 3 = 13

Measured memory_bytes: 384
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#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 imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
int n ; 
vector<ll> v ; 
vector<ll> dp ; 
ll dfs(int x){
	if ( x == n-1 )
		return 0 ; 
	if ( dp[x] != 1e18 ) return dp[x] ; 
	ll first = abs(v[x] - v[x+1]) + dfs(x+1) ; 
	ll second = 1e18 ; 
	if ( x + 2 < n )
		second = abs(v[x]-v[x+2]) + dfs(x+2) ; 
	dp[x] = min(first,second) ; 
	return dp[x] ; 
}

int main(){
	cin >> n ; 
	v.resize(n) ; 
	dp.resize(n,1e18) ; 
	for(ll &x : v){
		cin >> x ; 
	}
	cout << dfs(0) << endl;
    return 0 ;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long int;

int main() {
	int n;
	ll ans = 0;
	vector<int>::iterator pos1, pos2;
	cin >> n;
	vector<int>a(n), b(n), c(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < n; ++i) cin >> c[i];
	sort(a.begin(), a.end());
	sort(c.begin(), c.end());
	for (int i = 0;i < n; ++i) {
		pos1=lower_bound(a.begin(),a.end(),b[i]);
		pos2=upper_bound(c.begin(),c.end(),b[i]);//aとcは互いに独立
		ans +=distance(a.begin(),pos1)*abs(distance(c.end(),pos2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
 
int main(void){
	
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if( b+c == a || a+c == b || a+b == c ){
  printf("Yes\n");
  } else {
  printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int n_half = n/2;

    int[] d = new int[n];

    for(int i=0; i<n; i++){
      d[i] = sc.nextInt();
    }
    //配列のソート
    Arrays.sort(d);


    int small_diff = d[n_half-1];
    int big_diff = d[n_half];
    int ans = d[n_half]-d[n_half-1];

    System.out.println(ans);


  }
}

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

using namespace std;

char c[1010][1010];
int d[1010][1010];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int main() {

    ios::sync_with_stdio(false); cin.tie(0);
    for (int i = 0; i < 1010; ++i)
        for (int j = 0; j < 1010; ++j) 
            d[i][j] = 1e9;

    int n,m;
    cin >> n >> m;

    int a,b,s,t;
    cin >> a >> b >> s >> t;
    a--,b--,s--,t--;


    for (int i = 0; i < n; ++i) 
        for (int j = 0; j < m; ++j)
            cin >> c[i][j];

    deque<pair<int,int> > q;
    
    q.push_front({a,b});
    d[a][b] = 0;
    while(!q.empty()) {
        auto [x,y] = q.front();
        q.pop_front();

        if(x == s and y == t) break;

        for (int i = 0; i < 4; ++i) {
            int u = dx[i] + x;
            int v = dy[i] + y;
            if(u >= 0 and u < n and v >= 0 and v < m and c[u][v] == '.') {
                if(d[x][y] < d[u][v]) {
                    d[u][v] = d[x][y];
                    q.push_front({u,v});
                }
            }
        }

        for (int i = x - 2; i <= x + 2; ++i) {
            for (int j = y - 2; j <= y + 2; ++j) {
                int u = i, v = j;
                if(u >= 0 and u < n and v >= 0 and v < m and c[u][v] == '.') {
                    if(d[x][y] + 1 < d[u][v]) {
                        d[u][v] = d[x][y] + 1;
                        q.push_back({u,v});
                    }
                }
            }
        }

    }
    if(d[s][t] == 1e9) cout << "-1\n";
    else cout << d[s][t] << "\n";
    return 0;
}


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

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

int main() {
    int h, w;
    cin >> h >> w;
    string str[h];
    rep(i, h) cin >> str[i];
    int bomb[h][w];
    rep(i, h) rep(j, w) bomb[i][j] = 0;
    rep(i, h) {
        rep(j, w) {
            if (str[i][j] == '#') {
                rep(k, 8) {
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
                    if (str[ny][nx] == '#') continue;
                    bomb[ny][nx]++;
                }
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (str[i][j] == '#') cout << "#";
            else cout << bomb[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define trav(e, x) for (auto &e : x)
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
//#define int long long
using namespace std;
typedef pair<int, int> ii;

int n, k;
int stones[100], dp[100001];

int f(int x) {
    if (x < 0) return 0;
    if (x == 0) return 1;
    if (dp[x] > -1) return dp[x];
    int res = 0;
    for (int i = 0; i < n; i++) res = res || f(x - stones[i]);
    return dp[x] = res ^ 1;
}

signed main() {
    FAST_IO;
    //FILE_IO;

    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> stones[i];
    for (int i = 0; i <= k; i++) dp[i] = -1;
    cout << (!f(k) ? "First" : "Second");
}


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

int main() {
  int n,m,c; cin >>n >>m >>c;
  int ans;
  int sum;
  vector<int> b(m);
  for (int i=0; i<m; i++) cin >>b.at(i);
  int buf;
  
  for (int i=0; i<n; i++){
    sum=0;
    for (int j=0; j<m; j++){
      cin >>buf; sum += buf*b.at(j);
    }
    sum += c;
    if (sum>0) ans++;
  }
      
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int,x)

function main()
  N = parseInt(readline())
  A = map(parseInt, split(readline()))
  B = map(parseInt, split(readline()))
  k = 0
  for i = 1:N
    if A[i] < B[i]
      l = A[i]
    else
      l = B[i]
    end
    k = k + l
    B[i] = B[i] - l 
    if A[i+1] < B[i]
      l = A[i+1]
    else
      l = B[i]
    end
    k = k + l
    A[i+1] = A[i+1] - l
  end
  println(k)
end

main()

Measured memory_bytes: 166404
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
i=int(raw_input())
n=map(int, raw_input().split())
ans=0
chk=10
#サンプルリスト
#n=[2,5,3,1,7,9,10,4,6,8]
#n=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#リストの長さ、要素の個数分の繰り返し回数設定
#リストの長さ、要素の個数分の繰り返し回数設定
for m in range(len(n)):
    for j in range(len(n)-1, m, -1):
        if n[j]<n[j-1]:
            n[j],n[j-1]=n[j-1],n[j]
            ans+=1
#        print ans
    if ans==chk: break
    chk=ans
print ' '.join(map(str,n))
print ans

Measured memory_bytes: 4228