akhauriyash/Code-Regression huggingface dataset:
/*Rajeev Ranjan
  CSE @MNNIT */

#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define S second
#define F first
#define boost ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long int ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N = 1e5 + 5;

ll dp[105][N];
ll w[105],v[105];

ll fun(ll i,ll wt)
{
    if(i<0)
        return 0;

    if(dp[i][wt]!=-1)
        return dp[i][wt];

    if(w[i]>wt)
        dp[i][wt] = fun(i-1,wt);
    else
        dp[i][wt] = max(fun(i-1,wt) , v[i]+fun(i-1,wt-w[i]));
    return dp[i][wt];
}

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

    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];

    memset(dp,-1,sizeof(dp));

    cout<<fun(n-1,wt)<<endl;
    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vll;
typedef vector<char> vc;
typedef vector<vector<char>> vcc;
typedef vector<string> vs;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()

int main() {
    ll a,b; cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main()
{
  long int x, ans = 0;
  /*int a = 1000000000;
  int b;
  int i = 0;
  int c[8];*/
  int y, z;
  scanf("%ld", &x);
  y = x / 500;
  x = x - y * 500;
  z = x / 5;
  printf("%ld\n", y * 1000 + z * 5);
  
  return 0;
}

Measured memory_bytes: 128
n = int(input())
m = int(input())
Map = [[1001]*n for _ in range(n)]
for _ in range(m):
    a,b,c,d = map(int,input().split(","))
    Map[a-1][b-1] = c
    Map[b-1][a-1] = d
s,g,V,P = map(int,input().split(","))


for k in range(n):
    for i in range(n):
        for j in range(n):
            if Map[i][j] > Map[i][k]+Map[k][j]:
                Map[i][j] = Map[i][k]+Map[k][j]

print(V-P-Map[s-1][g-1]-Map[g-1][s-1])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 1e9 + 7;
typedef std::vector<int> vec;
vec v[maxn];
int fac[maxn], ifac[maxn], inv[maxn];
int size[maxn], cnt[maxn];;
int n, x, y, c, w;
int main() {
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	rep(i, 2, maxn - 1) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> x >> y;
	rep(i, 1, n) cin >> c >> w, v[c].push_back(w);
	rep(i, 1, n + 1) {
		std::sort(v[i].begin(), v[i].end());
		if(v[i].size() == 0) v[i] = {int(1e9 + 1)};
	}
	std::sort(v + 1, v + n + 1, [](const vec & x,const vec & y){ return x.front() < y.front(); });
	if(v[1].front() + v[2].front() > y) return cout << 1 << '\n', 0;
	int ans = 1;
	rep(i, 1, n) {
		for(auto a : v[i]) if(a + v[i].front() <= x || a + v[i == 1 ? 2 : 1].front() <= y) ++ cnt[i];
		if(i == 1 || v[i].front() + v[1].front() <= y) size[1] += cnt[i], ans = (ll) ans * ifac[cnt[i]] % mod;
	}
	std::cout << int((ll) fac[size[1]] * ans % mod) << '\n';
}


Measured memory_bytes: 14720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 510000;
    private static int MOD = 1000000007;
    public static void main(String[] args) {
        Main main = new Main();
        main.COMinit();
        main.solve();
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n <0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        Map<Integer, Integer> factorization = new HashMap<>();
        for (int i = 2; i * i <= M; i++) {
            if (M % i != 0) {
                continue;
            }
            int count = 0;
            while (M % i == 0) {
                count += 1;
                M /= i;
            }
            factorization.put(i, count);
        }
        if (1 < M) {
            factorization.put(M, 1);
        }
        long ans = 1;
        for (int prime : factorization.keySet()) {
            ans *= COM(factorization.get(prime)+ N - 1, N - 1);
            ans %= MOD;
        }
        System.out.println(ans);
    }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  vector<char> res(n);
  vector<string> q(n);
  rep(i,n)cin >> q[i];
  rep(i,n){
    if(q[i] == "AB"){
      if(a == b && a == 0){
        cout << "No" << endl;
        return 0;
      }
      if(a == b){
        if(i+1 < n){
          if(q[i+1] == "AB")res[i] = 'A',a++,b--;
          else if(q[i+1] == "AC")res[i] = 'A',a++,b--;
          else res[i] = 'B',a--,b++;
          continue;
        }
      }
      if(a < b)res[i] = 'A',a++,b--;
      else res[i] = 'B',a--,b++;
    }
    if(q[i] == "AC"){
      if(a == c && a == 0){
        cout << "No" << endl;
        return 0;
      }
      if(a == c){
        if(i+1 < n){
          if(q[i+1] == "AB")res[i] = 'A',a++,c--;
          else if(q[i+1] == "AC")res[i] = 'A',a++,c--;
          else res[i] = 'C',a--,c++;
          continue;
        }
      }
      if(a <  c)res[i] = 'A',a++,c--;
      else res[i] = 'C',a--,c++;
    }
    if(q[i] == "BC"){
      if(b == c && b == 0){
        cout << "No" << endl;
        return 0;
      }
      if(b == c){
        if(i+1 < n){
          if(q[i+1] == "AB")res[i] = 'B',b++,c--;
          else if(q[i+1] == "AC")res[i] = 'C',b--,c++;
          else res[i] = 'B',b++,c--;
          continue;
        }
      }
      if(b < c)res[i] = 'B',b++,c--;
      else res[i] = 'C',b--,c++;
    }
  }
  cout << "Yes" << endl;
  rep(i,n)cout << res[i] << endl;


  return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int L[ N ] , R[ N ] , ans[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        string s;
        cin >> s;
        int r = 0 , l = s.size() - 1;
        for( int i = 0; i < s.size(); i++ ) {
                if( s[i] == 'R' ) r = i;
                if( s[i] == 'L' ) R[i] = r;
        }
        for( int i = s.size() - 1; i >= 0; i-- ) {
                if( s[i] == 'L' ) l = i;
                if( s[i] == 'R' ) L[i] = l;
        }
        memset( ans , 0 , sizeof( ans ) );
        for( int i = 0; i < s.size(); i++ ) {
                if( s[i] == 'R' ) {
                        int nxt = L[i];
                        if( ( nxt - i )%2 == 0 ) ans[nxt]++;
                        else ans[nxt-1]++;
                }
                else {
                        int nxt = R[i];
                        if( ( i - nxt )%2 == 0 ) ans[nxt]++;
                        else ans[nxt+1]++;
                }
        }
        for( int i = 0; i < s.size(); i++ ) cout << ans[i] << " ";
        return 0;
}










Measured memory_bytes: 1872
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DX1 = new int[] { -1, 1, 0, 1, 0, 1 };
	static int[] DX2 = new int[] { -1, 1, 0, -1, 0, -1 };
	static int[] DY = new int[] { 0, 0, 1, 1, -1, -1 };

	public static void main(String[] args) {
		int W = sc.nextInt();
		int H = sc.nextInt();
		boolean[][] m = new boolean[H + 2][W + 2];
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				m[i + 1][j + 1] = sc.next().charAt(0) == '1';
			}
		}
		int ans = 0;
		Queue<Point> q = new ArrayDeque<Point>();
		q.add(new Point(0, 0));
		boolean[][] visited = new boolean[H + 2][W + 2];
		while (!q.isEmpty()) {
			Point p = q.poll();
			int[] DX = p.y % 2 != 0 ? DX1 : DX2;
			for (int i = 0; i < 6; ++i) {
				int nx = p.x + DX[i];
				int ny = p.y + DY[i];
				if (nx < 0 || W + 1 < nx || ny < 0 || H + 1 < ny || visited[ny][nx]) continue;
				if (m[ny][nx]) {
					++ans;
					continue;
				}
				q.add(new Point(nx, ny));
				visited[ny][nx] = true;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28448
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGreedyTakahashi solver = new BGreedyTakahashi();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGreedyTakahashi {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long a = s.nextLong();
            long b = s.nextLong();
            long k = s.nextLong();

            long min = Math.min(a, k);

            k -= min;
            a -= min;

            min = Math.min(b, k);
            b -= min;
            k -= min;
            out.println(a + " " + b);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23508
from itertools import product
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
INF = float("inf")
ans = INF
for bit in product([0, 1], repeat=(n-1)):
    if sum(bit)+1 >= k:
        t = 0
        pre = al[0]
        for i, a in enumerate(al):
            if i != 0:
                if bit[i-1] == 1:
                    t += max(0, (pre+1)-al[i])
                    pre = max(al[i], pre+1)
                    continue
                pre = max(pre, al[i])
        ans = min(ans, t)
print(ans)


Measured memory_bytes: 73688
S = input()
K = int(input())

l = len(S)

dp0 = [[0 for j in range(K + 1)] for i in range(l + 1)] #　以下未確定
dp1 = [[0 for j in range(K + 1)] for i in range(l + 1)] # 以下確定

dp0[0][0] = 1
for i in range(l):
    n = int(S[i])
    for j in range(K + 1):
        for d in range(10):
            nk = j
            if j > K: # j == Kの場合は残りがすべて0なら配れるので
                continue

            if d > 0:
                nk += 1
                if nk > K:
                    continue
            # 確定済みdp1の配り
            dp1[i + 1][nk] += dp1[i][j]

            #　非確定dp0の配り
            if d > n:
                continue
            elif d == n:
                dp0[i + 1][nk] += dp0[i][j]
            elif d < n:
                dp1[i + 1][nk] += dp0[i][j]

print(dp0[-1][-1] + dp1[-1][-1])











Measured memory_bytes: 40048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 99999999;
int main(){
  ll h,w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];
  vector<vector<ll>> dist(h,vector<ll>(w,-1));
  queue<pair<ll,ll>>q;
  
  auto push = [&]( pair<ll,ll> v, ll d ){
    if( dist[v.first][v.second] != -1 ) return;
    dist[v.first][v.second] = d;
    q.push(v);
  };
  rep(i,h){
    rep(j,w){
      if( a[i][j] == '#' ) push(make_pair(i,j),0);
    }
  }
  while(!q.empty()){
    pair<ll,ll> v = q.front();q.pop();
    ll vf = v.first;
    ll vs = v.second;
    ll d = dist[vf][vs];
    if( vf-1 >= 0 ) push(make_pair(vf-1,vs),d+1);
    if( vf+1 <= h-1 ) push(make_pair(vf+1,vs),d+1);
    if( vs-1 >= 0 ) push(make_pair(vf,vs-1),d+1);
    if( vs+1 <= w-1 ) push(make_pair(vf,vs+1),d+1);
  }
  rep(i,h) sort(dist[i].begin(),dist[i].end());
  ll ans = 0;
  rep(i,h){
    ans = max(ans,dist[i][w-1]);
  }
  printf("%lld\n",ans);
  return 0;
}

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

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

#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; i++) cout << s << " ";
    for (int i = k; i < n; i++) {
        cout << (s == 1e9 ? 1 : s + 1) << " ";
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
            int t = scan.nextInt();
            int n;
            int a;
            int b;

            while (t != 0) {
                n = scan.nextInt();
                int g = 0;
                for (int i = 0; i < n; i++) {
                    a = scan.nextInt();
                    b = scan.nextInt();
                    g += (b - a);

                }

                if (t <= g) {
                    System.out.println("OK");
                } else if (t > g) {
                    System.out.println(t - g);
                }
                t = scan.nextInt();
                
            }

        }

    }




Measured memory_bytes: 31252
from itertools import permutations as per
n,c = map(int,input().split())
d = [tuple(map(int,input().split())) for i in range(c)]
g = [[0]*c,[0]*c,[0]*c]
for i in range(1,n+1):
  ci = tuple(map(int,input().split()))
  for j in range(1,n+1):
    g[(i+j)%3][int(ci[j-1])-1] += 1
m = 10 ** 10
for i in per(range(c),3):
  e = 0
  for j in range(3):
    for o in range(c):
      e += g[j][o]*d[o][i[j]-1]
  m = min(m,e)
print(m)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s;

int main(void){
	scanf("%d",&n);
	cin >> s;
	int v=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='('){
			if(v==0)s+=')';
			else v--;
		}else{
			v++;
		}
	}
	for(int i=0;i<v;i++){
		printf("(");
	}
	cout << s << endl;
	return 0;
}


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

int main() {
	int e;
	while(cin >> e && !(e == 0)) {
		int x,min = e;
		for(int y = 0;y <= 1000;y++) {
			for(int z = 0;z <= 100;z++) {
				x = e - y * y - z * z * z;
				if(x < 0) break;
				
				if(x + y + z < min) {
					min = x + y + z;
				}
			}
		}
		cout << min << endl;
	}
}

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

long long MOD = 1000000007;

long long power(long long base, long long n)
{
    if (n == 0) return 1;
    if (n==1) return base;
    long long halfn = power(base, n/2);
    if (n % 2 == 0) return (halfn*halfn)%MOD;
    return (((halfn*halfn) % MOD) * base) % MOD;
}

long long inverse(long long n)
{
    return power(n, MOD-2);
}
long long binom(long long n, long long m)
{
    long long ans = 1;
    for (int i = 0; i < m; i++)
    {
        ans *= (n-i); ans %= MOD;
        ans *= inverse(m-i); ans %= MOD;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> graph[n+1];
    for (int i = 0; i < m; i++)
    {
        int u, v; cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int cnt = 0;
    vector<int> used(n+1);
    list<int> q;
    for (int i = 1; i <= n; i++)
    {
        if (used[i] == 1) continue;
        q.push_back(i); used[i] = 1;
        while (!q.empty())
        {
            int u = q.front(); q.pop_front();
            for (int v : graph[u])
            {
                if (used[v] == 1) continue;
                q.push_back(v); used[v] = 1;
            }
        }
        cnt++;
    }
    cout << cnt-1 << '\n';
    return 0;
}


Measured memory_bytes: 9328
#include <iostream>
using namespace std;
typedef long long ll;

ll h, n;
bool room[10004][4];
ll cnt[10004];

bool putable(ll sx, ll sy) {
    return !(room[sy][sx] || room[sy + 1][sx] || room[sy][sx + 1] || room[sy + 1][sx + 1]);
}

void put(ll sx, ll sy) {
    room[sy][sx] = room[sy][sx + 1] = room[sy + 1][sx] = room[sy + 1][sx + 1] = true;
}

int main() {
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        room[y][x] = true;
    }
    room[h][0] = room[h][1] = room[h][2] = room[h][3] = true;

    for (int i = h - 1; i >= 0; i--) {
        if (!(room[i][0] || room[i][1] || room[i][2] || room[i][3])) cnt[i] = cnt[i + 1] + 1;
        else cnt[i] = 0;
    }
    

    ll ans = 0;

    for (int i = 0; i < h; i++) {
        if (putable(0, i)) {
            put(0, i);
            ans++;
        }
        if (putable(2, i)) {
            put(2, i);
            ans++;
        }
        if (putable(1, i)) {
            if (cnt[i + 1] % 2 == 1 || cnt[i + 1] == 0) {
                put(1, i);
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int prim() {
	int d[MAX],
		p[MAX] = { -1 },
		color[MAX] = {};//WHITE
	fill(d, d + MAX, INF);
	d[0] = 0;

	while (true) {
		int u, minv = INF;
		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK&&d[i] < minv) {
				minv = d[i];
				u = i;
			}
		}

		if (minv == INF) { break; }

		color[u] = BLACK;

		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INF) {
				if (M[u][v] < d[v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1)sum += M[i][p[i]];
	}
	return sum;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int a; cin >> a;
			M[i][j] = (a == -1) ? INF : a;
		}
	}

	cout << prim() << endl;

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int N,Y;

int calc(int a,int b,int c){
  return 1000*a+5000*b+10000*c;
}
int main(){
  cin>>N>>Y;
  //2000*10000 10^7
  bool flag=false;
  for(int sen=0;sen<=2000;sen++){
    for(int go=0;go<=2000;go++){
      int man=(Y-(1000*sen+5000*go))/10000;
      if(calc(sen,go,man)==Y && sen+go+man==N && man>=0){
        cout<<man<<" "<<go<<" "<<sen<<endl;
        return 0;
        flag=true;
      }
    }
  }

 cout<<-1<<" "<<-1<<" "<<-1<<endl;

}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD = 1e9 + 7;
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983;
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017;
const ll p3 = 37;
const ll INF = 5e18;

int main() {
    fatnet;

    ll n, k, ans = 0, l = 0, r = 0, delta = 0;
    string s;
    cin >> n >> k;
    cin >> s;
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1])
            ++ans;
        else if (s[i] == 'L')
            ++r;
        else
            ++l;
    }
    while (k && l && r) {
        --k;
        --l;
        --r;
        delta += 2;
    }
    while (k && l) {
        --k;
        --l;
        ++delta;
    }
    while (k && r) {
        --k;
        --r;
        ++delta;
    }
    ans += delta;
    cout << ans << "\n";

    return 0;
}




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

bool prime(int n){
	if(n <= 1) return false;
	for(int i = 2; i * i < n; i++)
	    if(n % i == 0) return false;
	return true;
}     

signed main() {
	int X;	
	cin >> X;
	while(!prime(X))  X++;
	   
      
    cout << X << endl;
 
   return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a, b;
	while(scanf("%d %d",&a, &b) != EOF)
	{
		if(1 <= a && a <= 9 && 1 <= b && b <= 9)
			printf("%d\n",a * b);
		else
			printf("-1\n");
		
	}
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

int h,w;
string board[510];

string red[510],blue[510];

bool check(){
	rep(i,1,h-1)rep(j,1,w-1){
		if(red[i][j]=='#'){
			bool ok=false;
			rep(d,4){
				int ni=i+dy[d],nj=j+dx[d];
				if(red[ni][nj]=='#') ok=true;
			}
			if(ok==false) return false;
		}
		if(blue[i][j]=='#'){
			bool ok=false;
			rep(d,4){
				int ni=i+dy[d],nj=j+dx[d];
				if(blue[ni][nj]=='#') ok=true;
			}
			if(ok==false) return false;
		}
	}
	return true;
}

int main(void){
	cin >> h >> w;
	rep(i,h) cin >> board[i];

	rep(i,h) red[i]=blue[i]=board[i];

	rep(i,h) red[i][0]='#';

	rep(i,h){
		if(i%2!=0) continue;
		rep(j,1,w-1) red[i][j]='#';
	}

	rep(i,h) blue[i][w-1]='#';

	rep(i,h){
		if(i%2!=1) continue;
		rep(j,1,w-1) blue[i][j]='#';
	}	
	
	if(check()){
		rep(i,h) cout << red[i] << endl;
		cout << endl;
		rep(i,h) cout << blue[i] << endl;
	}
	
	return 0;
}

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


//vector<vector<int>> z(n,vector<int>(2));
//n番目から数えてm個の文字列をXに置換したい場合はreplace(n,m,X) teWttest
//s1.substr(3,3);
//n番目以降の文字列をm個取り出す、上だとtte

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

  vector<vector<int>> d(n+1,vector<int> (n+1,0));
  for(int i=n-1;i>=0;i--){
    for (int j=n-1;j>=0;j--){
      if (i==j)continue;
      if (s[i]==s[j]){
        d[i][j]=max(d[i][j],d[i+1][j+1]+1);
      //  cout<<d[i][j]<<endl;
      }
    }
  }
  int ans=0;
  for(int i=n-1;i>=0;i--){
    for (int j=i-1;j>=0;j--){
      ans=max(ans,min(d[i][j],i-j));

    }
  }
  cout<<ans;
  }


Measured memory_bytes: 98176
#include <stdio.h>
#include <limits.h>

#define SIZE 10000

int main(void) {
  int n = 0;
  long min = LONG_MAX;
  long max = LONG_MIN;
  long sum = 0;
  long v = 0;
  int i = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &v);

    sum += v;

    if (v < min) {
      min = v;
    }
    
    if (v > max) {
      max = v;
    }
  }

  printf("%ld %ld %ld\n", min, max, sum);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	char a[4];
	a[0] = s1[0]+('A'-'a');
	a[1] = s2[0]+('A'-'a');
	a[2] = s3[0]+('A'-'a');
	a[3] = '\0';
	co(a);

	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[0]*N
B=[0]*N
C=[0]*N
for i in range(N):
    a, b = map(int,input().split())
    A[i], B[i], C[i] = a, b, a+b

index = sorted(range(len(C)), key=lambda k: C[k], reverse=True)

sum_=0
for i,idx in enumerate(index):
    if i % 2 ==0:
        sum_+=A[idx]
    else:
        sum_-=B[idx]

print(sum_)

Measured memory_bytes: 20504
# import numpy as np
from sys import exit, stdin
import copy
from collections import deque, Counter


class BIT:
    def __init__(self, a=0):
        self.n = a
        self.d = [0] * (a + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.d[i] += x
            i += i & (-i)

    def sum(self, *i):
        if len(i) == 1:
            x = 0
            tmp = i[0] + 1
            while tmp:
                x += self.d[tmp]
                tmp -= tmp & (-tmp)
            return x
        else:
            return sum(self, i[1] - 1) - sum(self, i[0] - 1)


N, Q = map(int, stdin.readline().split())
C = list(map(int, stdin.readline().split()))

app = [-1] * (N + 1)
ps = [[] for _ in range(N)]
for i in range(N):
    tmp = app[C[i]]
    if tmp != -1:
        ps[tmp].append(i)
    app[C[i]] = i

qs = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, stdin.readline().split())
    l -= 1
    r -= 1
    qs[l].append(copy.deepcopy([r, i]))

ans = [0] * Q
d = BIT(N)
for x in range(N - 1, -1, -1):
    for y in ps[x]:
        d.add(y, 1)
    for p in qs[x]:
        r = p[0]
        i = p[1]
        ans[i] = (r - x + 1) - d.sum(r)

for re in ans:
    print(re)


Measured memory_bytes: 250312
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
//i->jへ行くコストがcの時、集合adj[i]にはpair(i->jのコスト、j)が含まれる
vector<vector<pair<LL,LL>>> adj;
LL Q,K;
LL x[100000],y[100000];

LL ans[100000];

void solve(){
	priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,greater<pair<LL,LL>>> pq;
	pq.push(pair<LL,LL>(0,K));
	vector<LL> dist(N+1,INF);
	dist[K] = 0;
	while(!pq.empty()){
		LL now = pq.top().second;
		LL cost = pq.top().first;
		pq.pop();
		if(dist[now]<cost) continue;
		for(pair<LL,LL> next_info:adj[now]){
			LL diff_cost = next_info.first;
			LL next = next_info.second;
			if(dist[next]>=dist[now]+diff_cost){
				dist[next] = dist[now]+diff_cost;
				pq.push(pair<LL,LL>(dist[next],next));
			}
		}
	}

	for(int i=0;i<Q;i++){
		ans[i] = dist[x[i]] + dist[y[i]];
	}
}

int main(){
    cin >> N;
    adj = vector<vector<pair<LL,LL>>>(N+1);
    for(int i=0;i<N-1;i++){
    	LL a,b,c;cin >> a >> b >> c;
    	adj[a].push_back(pair<LL,LL>(c,b));
    	adj[b].push_back(pair<LL,LL>(c,a));
    }
    cin >> Q >> K;
	for(int i=0;i<Q;i++) cin >> x[i] >> y[i];

    solve();

    for(int i=0;i<Q;i++)cout << ans[i] << endl;
    return 0;
}

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

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

using namespace std;

int main(){
	int n; cin>>n;
	string B[300];
	rep(i,n) cin>>B[i];

	int ans=0;
	rep(b,n){
		bool ok=true;
		rep(i,n) rep(j,n) if(B[i][(j+b)%n]!=B[j][(i+b)%n]) ok=false;
		if(ok) ans+=n;
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
	int n,k,x[110],ans=0,some1,some2;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	for(int i=0;i<n;i++){
		some1=x[i]*2;
		some2=(k-x[i])*2;
		ans+=(some1<some2)? some1:some2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define MAX 3'234'566'667
int K;
// set<ll> S;
set<string> S;

void dfs(string s, int d){
	if(s.size() >= 10){
		ll l = stoll(s);
		if(l <= MAX) S.insert(s);
		// if(l <= MAX) S.insert(l);
		return;
	}
	// s = to_string(d) + s;
	s += to_string(d);

	rp(i, -1, 2){//{-1,0,+1}
		int k = d + i;
		if(k < 0 || 9 < k) continue;
		// if(k < 0 || 9 < k) k=0;
		dfs(s, k);
	}
}

ll solve(){
	// rp(i, 0, 10){//[0,9]
	// 	string s = "";
	// 	dfs(s, i);
	// }

	vector<ll> candidate;
	queue<ll> q;
	rp(i, 1, 10) q.push(i);

	while(q.size()){
		ll n = q.front(); q.pop();
		// cout<<n<<"\n";//
		candidate.push_back(n);
		if(candidate.size() >= K) break;

		int n1 = n%10;//nの第一位

		rp(i, -1, 2){//{-1,0,+1}
			int m = n1 + i;//次の第一位
			if(m < 0 || 9 < m) continue;
			q.push(n*10+m);
		}

	}

	// for(auto x:candidate)cout<<">"<<x<<"<\n";puts("");//
	// while(q.size()){cout<<">"<<q.front()<<"<\n";q.pop();}///

	ll ans = 0;
	sort(all(candidate));
	ans = candidate[K-1];
	return ans;
}

int main(){
	cin>>K;
	cout<< solve() <<endl;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;
int main(){ 
  int n, k;
  cin >> n >> k;
  vector<ll> cum(n + 2, 0);

  for (int i = 0; i <= n; i++) {
    cum[i + 1] = cum[i] + i;
  }
  int res = 0;
  for (int i = k; i <= n + 1; i++) {
    ll l = cum[i];
    ll r = cum[n + 1] - cum[n + 1 - i];
    res += (r - l + 1 + mod) % mod;
    res %= mod;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define PI 2*acos(0)
#define INF 1e17
#define mx 200005
using namespace std;
//const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,j,k,sum,cnt,ans;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++) cin>>a[i];
  cnt=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(a[i]!=a[j]){
        for(k=j+1;k<n;k++){
          if(a[i]!=a[k] && a[j]!=a[k]){
            if(a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[k]+a[i]>a[j]) cnt++;
          }
        }
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}
//1028C


Measured memory_bytes: 3652
def solve(A,N,K):
    for k in range(K):
        C = [0 for _ in range(N+1)]
        #C[i]:i番目の電球を照らす電球の数
        for i in range(N):
            C[max(i-A[i],0)] += 1
            C[min(i+A[i]+1,N)] -= 1
        for i in range(1,N):
            C[i] += C[i-1]

        if C[0] == N or C[N-1] == N:
            for i in range(N):
                A[i] = N
            break
        else:
            for i in range(N):
                A[i] = C[i]
    return A

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

    ans = solve(A,N,K)

    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 172032
def solve():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0
    for i in range(1, n-1):
        now = i
        if p[now - 1] < p[now] < p[now + 1]:
            count += 1
        elif p[now + 1] < p[now] < p[now - 1]:
            count += 1
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, m = li()
a = [ni() for _ in range(m)]
aset = set(a)

MOD = 10**9+7

dp = [0]*(n+1)
dp[0] = 1

for i in range(n):
    if i+1 in aset:
        continue

    if i == 0:
        dp[1] = 1

    else:
        dp[i+1] = dp[i] + dp[i-1]
        dp[i+1] %= MOD

print(dp[n])

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

int main() {
  int x1, x2, x3, x4, y1, y2, y3, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  int a, b;
  a = y2-y1;
  b = x2-x1;
  x3 = x2-a;
  y3 = y2+b;
  x4 = x1-a;
  y4 = y1+b;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
flag=0
for i in range(0,N):
    if A[i]%2==0 and A[i]%3!=0 and A[i]%5!=0:
        flag=1
if flag==0:
    print('APPROVED')
else:
    print('DENIED')

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

int main() {
    int n,m;
    cin >> n >> m;
    int a[m];
    int count=0;
    for(int i=0;i<m;i++){
        cin >> a[i];
        count+=a[i];
    }
    if(n-count>=0) cout << n-count << endl;
    else cout << -1 << endl;
}

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

int main(){
  int n,i;
  int m[50],f[50],r[50],t[50];
  for (i=0;i>=0;i++){
    if(m[i-1]==-1 && f[i-1]==-1 && r[i-1]==-1){
      break;
    } else {
      cin >> m[i] >> f[i] >> r[i];
      t[i]=m[i]+f[i];
    }
  }
  for(i=0;i>=0;i++){
   if(m[i]==-1 && f[i]==-1 && r[i]==-1){
     break;
   } else if (m[i]==-1 || f[i]== -1){
     cout << "F" << endl;
   } else if (t[i]>=80){
     cout << "A" << endl;
   } else if (t[i]<80 && t[i]>=65){
     cout << "B" << endl;
   } else if (t[i]<65 && t[i] >=50 || r[i]>=50){
     cout << "C" << endl;
   } else if (t[i]>=30 && t[i]<50){
     cout << "D" << endl;
   } else {
     cout << "F" << endl;
   }
 }
 return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
    int x, a, b;
    int out;
    
    cin >> x >> a >> b;
    
    out = (x-a) % b;
    
    cout << out << endl;
    
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
	READARR(x, n);
	
	int a = 0;
	FOR (i, 1, n)
		if (i % 2) a += x[i];
		else a -= x[i];
	
	FOR (i, 1, n)
	{
		cout << a << " ";
		a = 2*x[i] - a;
	}
}

Measured memory_bytes: 2176
N,M,C = map(int,input().split(' '))

Bn = list(map(int,input().split(' ')))
Anm =[ list(map(int,input().split(' '))) for _ in range(N)]  

output = 0
for An in Anm:
    sum_amount = C
    for i in range(M):
        sum_amount += An[i]*Bn[i]
    if sum_amount > 0:
        output += 1
print(output)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;


//D
int main(void) {
	ll n;
	cin >> n;
	double upper = sqrt(n);// +0.5;
	ll ans = 0;
	vector<ll> div = vector<ll>();
	for(ll s = 1; s <= upper; s++) {
		if (n % s == 0) {
			div.push_back(s);
			div.push_back(n / s);
			
		}
	}
	for(ll &k:div) {
		if (k == 1) continue;
		else {
			ll m = k - 1;
			ll r = n % m;
			if (r == (n - r) / m) ans += m;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e5+10;
int a[N],n,ans=0;
int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) {
		if(a[i]==i) {
			if(i==n) swap(a[i],a[i-1]);
			else swap(a[i],a[i+1]);
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N+2);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    while (K--) {
        vector<ll> B(N+2, 0);
        for (int i = 1; i <= N; i++) {
            ll a = max(1LL, i-A[i]), b = min(N, i+A[i])+1;
            B[a]++, B[b]--;
        }
        bool flag = 0;
        for (int i = 1; i <= N+1; i++) {
            B[i] += B[i-1];
            if (A[i] != B[i]) {
                flag = 1;
            }
        }
        if (!flag) {
            break;
        }
        swap(A, B);
    }
    for (int i = 1; i <= N; i++) {
        cout << A[i];
        if (i == N) {
            cout << endl;
        }
        else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 6584
#include<stdio.h>

int main(void) {
	int N, M;
	int i,j;
	int count;

	scanf("%d%d", &N, &M);

	int L[M], R[M];

	for (i = 0;i < M;i++) {
		scanf("%d%d", &L[i], &R[i]);
		if (i > 0) {
			if (L[i] < L[i - 1]) {
				L[i] = L[i - 1];
			}

			if (R[i] > R[i - 1]) {
				R[i] = R[i - 1];
			}
		}
	}

	count = R[M - 1] - L[M - 1] + 1;

	if (count < 0) {
		count = 0;
	}
	printf("%d", count);

	return 0;
}

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

using namespace std;

using ll = long long;

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

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

void Reduce_Each_to_x(vector<ll>& Candies, ll x)
{
    for(auto& y : Candies)
    {
        y = min(x,y);
    }
}

void Reduce_Each_to_Ans(ll N, vector<ll>& Candies, ll x)
{
    for(ll i=1;i<N;i++)
    {
        Candies[i] -= max(Candies[i-1]+Candies[i]-x,0LL);
    }
}

int main()
{
    ll N,x;
    cin >> N >> x;

    vector<ll> Candies(N);
    ALLIN1_NUMBER(Candies);
    vector<ll> Candies_def_copy = Candies;

    Reduce_Each_to_x(Candies,x);
    Reduce_Each_to_Ans(N,Candies,x);

    OUT0(accumulate(ALL(Candies_def_copy),0LL)-accumulate(ALL(Candies),0LL));

    return 0;
}

Measured memory_bytes: 4836
fn main() {
    let n: usize = read();
  	let mut v : Vec<usize> = vec![];
  	for i in 0..n {
      v.push(read());
    }
  	v.sort();
  	let mut total : usize = 1;
  	for i in 0..n {
      match total.checked_mul(v[i]) {
      	Some(v) => total = v,
        None => {println!("-1"); exit(0);}
      }
    }
  	if total <= 1000000000000000000{
  		println!("{}", total);
  	}else {
  		println!("-1");
  	}
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int k, a, b;
  cin >> k >> a >> b;
  if (a <= b/k*k) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3608