akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void) {
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0) break;
		int i,j,a[10+1][10+1]={};
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d ",&a[i][j]);				
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				printf("%5d",a[i][j]);
				a[i][n]=a[i][n]+a[i][j];
			}
			printf("%5d",a[i][n]);
			putchar('\n');
			a[i][n]=0;
		}
		for(j=0;j<n;j++){
			for(i=0;i<n;i++){
				a[n][j]=a[n][j]+a[i][j];
				a[n][n]=a[n][n]+a[i][j];
			}
			printf("%5d",a[n][j]);
			a[n][j]=0;
		}
		printf("%5d\n",a[n][n]);
	}
	return 0;
}


Measured memory_bytes: 2052
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


if __name__ == "__main__":
    l, r, d = arr_in()
    result = 0
    for i in range(l, r+1):
        if i % d == 0:
            result += 1
    out(result)

Measured memory_bytes: 61860
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	char a[3];
	cin >> a;
	sort(a,a+3);
	if(a[0] == 'a' && a[1] == 'b' && a[2] == 'c'){
		cout << "Yes";
	}else {
		cout << "No";
	}
	cout << endl;
}

int main(){
	solve();
	return 0;
}

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

using namespace std;

int main(){
	string o , e;

	cin >> o >> e;

	int i;
	for(i = 0; i < e.size();i++){
		cout << o[i] << e[i] ;
	}
	if(o.size() != e.size())cout << o[i];
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		int a = 0;
		int b = 0;

		try (Scanner scanner = new Scanner(System.in)) {
			a = scanner.nextInt();
			b = scanner.nextInt();
		}

		if (a >= -1000 && b <= 1000) {
			if (a > b) {
				System.out.println("a > b");
			} else if (a < b) {
				System.out.println("a < b");

			} else {
				System.out.println("a == b");

			}
		}

	}

}

Measured memory_bytes: 26268
import sys

H, W = map(int, input().split())

# H = 2
# W = 3

s = [["" for j in range(W)] for i in range(H)]

for i in range(H):
    tmp = input()
    for j in range(W):
        s[i][j] = tmp[j]

# print(s)

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if i != 0:
                if s[i-1][j] == "#":
                    continue
            if i != H-1:
                if s[i+1][j] == "#":
                    continue
            if j != 0:
                if s[i][j-1] == "#":
                    continue
            if j != W-1:
                if s[i][j+1] == "#":
                    continue
            print("No")
            sys.exit()
print("Yes")


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 200003;

int t[N], n, T;

int main() {
	scanf("%d%d", &n, &T);
	for (int i = 1; i <= n; ++i) scanf("%d", t + i);
	int ans = 0, top = 0;
	ans = t[n] + T;
	for (int i = 2; i <= n; ++i)
		if (t[i] - t[i - 1] > T)
			ans -= (t[i] - t[i - 1] - T);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, K = gets_i_list
h_list = gets_i_list

dp = Array.new(N, Float::INFINITY)
dp[0] = 0

(1...N).each do |i|
  min = Float::INFINITY
  k = i - K
  k = 0 if k < 0
  k.upto(i - 1) do |j|
    s = (h_list[i] - h_list[j]).abs + dp[j]
    min = min < s ? min : s
  end
  dp[i] = min
end

puts dp.last

# INF = 10**12
# dp = Array.new(N, Float::INFINITY)
# dp[0] = 0
# 
# (N-1).times do |i|
#   k = K < N - i - 1 ? K : N - i - 1
#   1.upto(k).each do |j|
#     s1 = dp[i] + (h_list[i] - h_list[i + j]).abs
#     # dp[i + k] = [dp[i + k], s1].min 
#     dp[i + j] = dp[i + j] < s1 ? dp[i + j] : s1
#   end
# end
# puts dp.last


Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[105];

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=1;i<n;i++)
		a[i] += a[i-1];
	int ans = INF;
	for(int i=0;i<n-1;i++) {
		ans = min(ans, abs(a[i] - (a[n-1] - a[i])));
	}
	cout << ans << endl;
}



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

int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a!=1){cout<<1;}
  if(b!=2){cout<<2;}
  if(c!=3){cout<<3;}
  if(d!=4){cout<<4;}
  if(e!=5){cout<<5;}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    int n,k,q;
    cin>>n>>k>>q;
    int s[n+1];
    for(int i=0;i<n+1;i++)s[i]=k-q;
    for(int i=0;i<q;i++)
    {
        int num;
        cin>>num;
        s[num]++;
    }
    for(int i=1;i<n+1;i++)
    {
        if(s[i]<=0)
        cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 4008
let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f
let n = (read int) - 1
let bs' = reads int
let as' = Array.append [| Array.head bs' |] bs'
for i = 0 to n-1 do
    if bs'.[i] < max as'.[i] as'.[i+1] then
        as'.[i] <- bs'.[i]
        as'.[i+1] <- bs'.[i]
printfn "%A" (Array.sum as')

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

int main(){
  char b,ans;
  cin >> b;
  
  if (b=='A') ans = 'T'; else
  if (b=='T') ans = 'A'; else
  if (b=='G') ans = 'C'; else
  if (b=='C') ans = 'G';
    
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans;
string s;
int main() {
	cin>>n>>s;
	for(int i=0;i<=n-3;i++) if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	cout<<ans;
	return 0;
}

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

ll euc(ll a, ll b, ll &x, ll &y) {
  ll xx = y = 0; ll yy = x = 1;
  while (b) {
    ll q = a / b; ll t = b; b = a % b;
    a = t; t = xx; xx = x - q * xx; x = t;
    t = yy; yy = y - q * yy; y = t;
  }
  return a;
}

ll ans, a = 2, n, l, i, j;

void upd(ll x, ll y) {
  if (euc(a*x,y,i,j) > 1) return;
  if ((i = (i % y + y) % y) > 0)
    ans = min({ans, i * x * a - 1, (y-i) * x * a});
}

int main() {
  cin >> n; ans = n + (n % 2 == 0);
  while (n % 2 == 0)
    a *= 2, n /= 2;
  for (ll d = 1; d * d <= n; d++)
    if (n % d == 0)
      upd(d, n / d), upd(n / d, d);
  cout << ans << "\n";
}

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

int main()
{
    int N,M;
    cin >> N>>M;
    int Mat[N][M];
    int n, m;
    for (n = 0; n<N; n++ ){
        for (m = 0; m<M; m++){
            cin >> Mat[n][m];
        }
    }

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

    int C;
    for (n=0; n<N;n++){
        C=0;
        for (m=0; m<M; m++ ){
            C += Mat[n][m]*b[m];
        }
        cout << C << endl;
    }


}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
int n;vector<P> v[15];
signed main(){
  cin>>n;
  rep(i,n){
    int a;cin>>a;
    rep(j,a){
      int x, y;cin>>x>>y;x--;v[i].push_back(P(x,y));
    }
  }
  int ans = 0;
  rep(i,1<<n){
    int cnt = 0;
    bool h[15];
    rep(i,15)h[i] = false;
    rep(j,n){
      if(i&(1<<j)){
        h[j] = true;
        cnt++;
      }
    }
    rep(j,n){
      if(!h[j])continue;
      rep(k,v[j].size()){
        if(v[j][k].second != h[v[j][k].first]){
          cnt = -INF;break;
        }
      }
    }
    chmax(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()) - 1)
cnt = 0
i = 0
flag = [False] * n
while not flag[i]:
    cnt += 1
    flag[i] = True
    i = a[i]
    if i == 1:
        print(cnt)
        break
else:
    print(-1)

Measured memory_bytes: 7852
def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    L_memo = [0]*N
    cnt=0
    for i, j in enumerate(L):
        if i+j<N:
            L_memo[i+j]+=1
        if i-j>0:
            cnt+=L_memo[i-j]        
    print(cnt)
main()

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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define inf 1e9+9
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()

const int mod=1e9+7; 

void solve(){
  int h,w,n; cin>>h>>w>>n; 
  map<pair<int,int>,int> cnt; 
  for(int i=0;i<n;i++){
    int a,b; cin>>a>>b; 
    for(int k:{-2,-1,0}){
      for(int l:{-2,-1,0}){
        int ta=a+k, tb=b+l; 
        if(ta>=1 && tb>=1 && ta<h-1 && tb<w-1){
          cnt[{ta,tb}]++; 
        }
      }
    }
  }
  vector<ll> ans(10,0); 
  ll sum=0; 
  for(auto p:cnt){
    ans[p.second]++; 
  }
  for(ll i:ans) sum+=i; 
  ans[0]=(ll)(h-2)*(w-2)- sum; 
  for(ll i:ans) cout<<i<<endl; 
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S; cin >> S;
    if(S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
const int N=100005;
string s;int d;
ll dp[10000][100][2];
ll fun(int  pos,int rem,int tight){
    if(pos==s.size()){
        if(rem==0)return 1;
        return 0;
    }
    if(dp[pos][rem][tight]!=-1)return dp[pos][rem][tight];
    int till=9;
    if(!tight)till=s[pos]-'0';
    ll res=0;
    for(int i=0;i<=till;i++){
        int newtight=1;
        if(!tight){
            if(i==till)newtight=0;
        }
        int newrem=(i+rem)%d;
        res=res+fun(pos+1,newrem,newtight);
        res%=p;
    }

    dp[pos][rem][tight]=res;
    // cout<<res<<endl;
    return res;
}
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);   
    // freopen("output.txt", "w", stdout);
    // #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    cin>>s>>d;
    memset(dp,-1,sizeof(dp));
    cout<<(fun(0,0,0)-1+p)%p;
    return 0;
}

Measured memory_bytes: 16896
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	long N;
	cin >> N;
	long digit = static_cast<long>(log10(N));
	long total = 0;
	if (N < 10)
	{
		total = N;
		cout << total << endl;
		return 0;
	}
	else
	{
		total = 9;
	}
	for (long i = 2; i < digit; i += 2)
	{
		total += pow(10, (i + 1)) - pow(10, i);
	}
	if (digit % 2 == 0)
	{
		total += N - pow(10, digit) + 1;
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) {
while (true) {
int n = sc.nextInt();
if (n == 0) { break; }
int[] scores = new int[n];
for (int i = 0; i < scores.length; i++) {
scores[i] = sc.nextInt();
}
double average = 0, variance = 0, sum = 0, ssum = 0;
for (int i = 0; i < scores.length; i++) {
    sum += scores[i];
}
average = sum/scores.length;
for (int i = 0; i < scores.length; i++) {
    ssum += ((scores[i] - average)*(scores[i] - average));
}
variance = ssum/scores.length;
// … 平均値averageと，分散varianceを計算しよう …
System.out.println(Math.sqrt(variance));
}
}
}
}


Measured memory_bytes: 31416
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	if (A <= 8 && B <= 8)
	{
		cout << "Yay!" << endl;
	}
	else
	{
		cout << ":(" << endl;
	}
}


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


int check(char a){
    int ans = 0;
    if(a == 'A') ans++;
    if(a == 'C') ans++;
    if(a == 'G') ans++;
    if(a == 'T') ans++;
    return ans;
}

int main(){
    string s;
    int ans = 0, t = 0;
    cin >> s;
    int n = s.length();
    for (int i = 0; i < n; i++){
        if(check(s.at(i)) == 1) t++;
        if(check(s.at(i)) == 0) t = 0;
        ans = max(ans, t);
    }



    cout << ans << endl;

}

Measured memory_bytes: 3604
fun main(args : Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map { it.toLong() }

    if (a > b) {
        println(0)
        return
    }

    if (n == 1L && a != b) {
        println(0)
        return
    }

    val min = (a * (n-1)) + b
    val max = a + ((n-1) * b)

    println(2 + max - min - 1)
}



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



    int main(){
        string s;
        cin >> s;
        if(s[2]==s[3]&&s[4]==s[5]){
            cout << "Yes" <<endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long double ld;
typedef long long ll;

int32_t main() {
    IOS;
    ll t;
    // cin>>t;
    t=1;
    while(t--) {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++) {
            cin>>a[i];
        }
        int dp[n];
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++) {
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
        }

        cout<<dp[n-1];
    }
    return 0;
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


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


Measured memory_bytes: 3520
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   char S;
   bool four = false;
   for(int i=0; i<N; ++i){
      std::cin >> S;
      if(S=='Y'){
	 four = true;
      }
   }

   if(four) std::cout << "Four" << std::endl;
   else std::cout << "Three" << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int l;

int main(void){
	scanf("%d%d",&n,&l);
	int sum=0;
	int best=l;
	for(int i=0;i<n;i++){
		sum+=l+i;
		if(abs(best)>abs(l+i)){
			best=l+i;
		}
	}
	sum-=best;
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	string s; cin >> s;
	vector<int> e(n + 2), w(n + 2);
	int ans = 1e9;
	for (int i = 1; i <= n; i++) w[i] = w[i - 1] + (s[i - 1] == 'W');
	for (int i = n; i >= 1; i--) e[i] = e[i + 1] + (s[i - 1] == 'E');
	for (int i = 1; i <= n; i++) ans = min(ans, w[i - 1] + e[i + 1]);
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define reunique(a) (a).resize(unique(all(a)) - (a).begin())
#define ld long double
#define int long long

void SOLVE(){
    int n, m;
    cin >> n >> m;
    string s = "";
    for (int i = 0; i < n; i++){
        s += '#';
    }
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--;
        char t = (char)(y + '0');
        if (s[x] == t) continue;
        if (s[x] != '#'){
            cout << "-1\n";
            return;
        }
        s[x] = t;
    }
    if (n == 1){
        if (s[0] == '#') s[0] = '0';
        cout << s << '\n';
        return;
    }
    int pos = 0;
    if (s[0] == '#') s[0] = '1';
    for (char &now : s){
        if (now == '#')
            now = '0';
    }
    int chk = stoll(s);
    string kek = to_string(chk);
    if (kek.size() != n){
        cout << "-1\n";
        return;
    }
    cout << s << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int Q = 1;
    //cin >> Q;
    while (Q--){
        SOLVE();
    }

    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int h,w;
    char line[256];

    while (1) {

        if (!fgets(line, sizeof(line), stdin)) {
            fprintf(stderr, "error input val\n");
            return -1;
        }

        if (sscanf(line, "%d %d", &h, &w) != 2) {
            fprintf(stderr, "error input format\n");
            return -1;
        }

        if (!h && !w) {
            return 0;
        }

        int i;
        char buf[256];
        memset(buf, '\0', sizeof(buf));
        memset(buf, '#', w);

        for (i=0; i<h; i++){
            printf("%s\n", buf);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 608
#include<cstdio>
#include<map>
#include<cassert>
#include<functional>
#include<string>
#include<cassert>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<cctype>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n;
ll d[55][55][55*55], m;
int a[55];

ll go(int i, int c, int s) {
 if (i == n) return c && s == m*c;
 ll &ret = d[i][c][s];
 if (~ret) return ret;
 ret = 0;

 ret += go(i+1, c+1, s + a[i]);
 ret += go(i+1, c, s);

 return ret;
}
int main()
{
 scanf("%d%lld", &n, &m);
 memset(d, -1, sizeof d);
 for (int i = 0; i < n; i++) scanf("%d", a + i);
 printf("%lld\n", go(0, 0, 0));
 return 0;
}


Measured memory_bytes: 71680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w,K;
    cin>>h>>w>>K;
    vs v(h);
    rep(i,h)cin>>v[i];
    int ans=INF;


    for(int i=0;i<(1<<(h-1));++i){
        vi seq(1,-1);
        rep(j,(h-1))if((1<<j)&i)seq.pb(j);
        seq.pb(h-1);


        vi sum(seq.size()-1,0);
        int res=0;
        bool dame=false;
        rep(j,w){
            vi tmpS(sum.size());
            int pos=0;
            for(int k=0;k<seq.size()-1;++k){
                int l=seq[k];
                int r=seq[k+1];
                int lrSum=0;
                for(int m=l+1;m<=r;m++){
                    lrSum+=v[m][j]-'0';
                }
                if(lrSum>K){dame=true;break;}
                tmpS[pos]=lrSum;
                pos++;
            }

            if(dame){
                break;
            }

            bool ch=1;
            rep(k,sum.size()){
                sum[k]+=tmpS[k];
                if(sum[k]>K)ch=0;
            }
            if(!ch){
                sum=tmpS;
                res++;
            }
        }
        if(!dame)chmin(ans,res+(int)seq.size()-2);
    }
    fin(ans);

    
}


Measured memory_bytes: 256
n,m,c =map(int ,input().split())
b =list(map(int ,input().split()))
a =[]
count =0
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(n):
    ans =0
    for j in range(m):
        ans +=a[i][j]*b[j]
    if ans +c >0:
        count +=1
print(count)


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = (int) s.size();
  int ans = 0;
  for (int i = 0; i < n; ) {
    if (s[i] == 'S') {
      i++;
    } else {
      int j = i + 1;
      while (j < n && s[j] == s[i]) {
        j++;
      }
      ans = max(ans, j - i);
      i = j;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3644
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  auto res = int.max;
  foreach (i; 0..s.length-2) {
    res = min(res, abs(s[i..i+3].to!int - 753));
  }
  res.writeln;
}


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

int main() {
	int A,B;
  	cin>> A >> B;
  	int ans=-1;
  	
  	for(int i=0;i<2000;i++){
     if(int(i*0.08)==A&&int(i*0.1)==B){
      	ans=i;
       	break;
     }
    }
  	
  	cout<<ans<<endl;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
double a,b,c,d,e,f;
while(cin >> a >> b >> c >> d >> e >> f) {
printf("%.3f ",(e * c - b * f) / (a * e - b * d) + 0.0);
printf("%.3f\n",(a * f - d * c) / (a * e - b * d) + 0.0);
}
return 0;
}

Measured memory_bytes: 1236
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define MAXN 100000
#define LL long long
int tot,vis[MAXN],n,ans;
LL prim[MAXN],a[MAXN+5],b[MAXN+5];
map<LL,int>cnt;
void Pre()
{
	for(int i=2;i<MAXN;i++)
	{
		if(!vis[i]) prim[tot++]=i;
		for(int j=0;prim[j]*i<MAXN;j++)
		{
			vis[i*prim[j]]=1;
			if(i%prim[j]==0) break;
		}
	}
}
void Solve(int i,LL x)
{
	a[i]=b[i]=1;
	for(int j=0;prim[j]*prim[j]*prim[j]<=x;j++)
	{
		int c=0;
		while(x%prim[j]==0) x/=prim[j],c++;
		if(c%3==1) a[i]*=prim[j],b[i]*=prim[j]*prim[j];
		else if(c%3==2) a[i]*=prim[j]*prim[j],b[i]*=prim[j];
	}
	if(x!=1)
	{
		LL k=sqrt(x);
		if(k*k==x) a[i]*=k*k,b[i]*=k;
		else a[i]*=x,b[i]*=x*x;
	}
}
int main()
{
	Pre();
	scanf("%d",&n);
	LL x;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		Solve(i,x);
		cnt[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(cnt[a[i]]==0) continue;
		if(a[i]==b[i]) 	ans++,cnt[a[i]]=0;
		else ans+=max(cnt[a[i]],cnt[b[i]]),cnt[a[i]]=0,cnt[b[i]]=0;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 14720
# -*- coding: utf-8 -*-
N = int(input())

if N <= 12:
    print(N)
else:
    str_ans = "12"
    counter = 12
    while counter < N:
        len_ans = len(str_ans)
        low_nine_num = 0
        for i in range(len_ans):
            if str_ans[len_ans - i - 1] == "9":
                low_nine_num += 1
            else:
                break
        if low_nine_num == len_ans:
            str_ans = "1" + "0" * len_ans
        else:
            chenged_top_num = -1
            low_digit_num = -1
            if low_nine_num == len_ans - 1:
                chenged_top_num = int(str_ans[len_ans - low_nine_num - 1])
                low_digit_num = len_ans - 1
            else:
                for i in range(len_ans):
                    if i == len_ans - 1 :
                        if chenged_top_num == -1:
                            chenged_top_num = int(str_ans[0])
                            low_digit_num = len_ans - 1
                    elif str_ans[-1 * (i + 1)] == "9":
                        continue
                    else:
                        compare_high_num = int(str_ans[-1 * (i + 2)])
                        compare_low_num = int(str_ans[-1 * (i + 1)])
                        if compare_high_num - compare_low_num != 0 and compare_high_num - compare_low_num != 1:
                            chenged_top_num = compare_high_num
                            low_digit_num = i + 1
    #                         print("A", str_ans, compare_high_num, low_digit_num)
                        else:
                            chenged_top_num = compare_low_num
                            low_digit_num = i
    #                         print("B", str_ans, compare_high_num, low_digit_num)
                            break

                            
            temp_str_ans = str_ans[:len_ans - low_digit_num - 1] # not chenged
            temp_str_ans += str(chenged_top_num + 1)
            for i in range(low_digit_num):
                temp_str_ans += str(max(chenged_top_num - i, 0))
            str_ans = temp_str_ans
        
        counter += 1
#         print(counter, str_ans, low_nine_num, low_digit_num)
    
    print(int(str_ans))


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

int main(){
  int N;
  cin >> N;
  int x[100], y[100], h[100];
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  if(N==1){
    cout << x[0] << ' ' << y[0] << ' ' << h[0] << endl;
    return 0;
  }
  for(int i=0; i<=100; i++){
    for(int j=0; j<=100; j++){
      bool judge= true;
      int h1;
      for(int k=0; k<N; k++){
        if(h[k]==0) continue;
        h1 = max(h[k]+abs(x[k]-i)+abs(y[k]-j), 0);
        break;
      }
      for(int k=0; k<N; k++){
        int h2 = max(h1-abs(x[k]-i)-abs(y[k]-j), 0);
        if(h2 != h[k]){
          judge = false; break;
        }
      }
      if(judge){
        cout << i << ' ' << j << ' ' << h1 << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	int sx, sy, tx, ty;
	int i, j;
	string ans;

	cin >> sx >> sy >> tx >> ty;

	ans = "";

	rep(tx - sx) {
		ans += "R";
	}
	rep(ty - sy) {
		ans += "U";
	}
	rep(tx - sx) {
		ans += "L";
	}
	rep(ty - sy) {
		ans += "D";
	}
	ans += "D";
	rep(tx - sx + 1) {
		ans += "R";
	}
	rep(ty - sy + 1) {
		ans += "U";
	}
	ans += "LU";
	rep(tx - sx + 1) {
		ans += "L";
	}
	rep(ty - sy + 1) {
		ans += "D";
	}
	ans += "R";


	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
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;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long N = in.nextLong();
            long sqrt = (long) Math.sqrt(N);
            for (long i = sqrt; i >= 1; i--) {
                if (N % i == 0) {
                    long p = i;
                    long q = N / i;
                    out.printLine(p + q - 2);
                    return;
                }
            }

        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<vector<ll>>ed(n,vector<ll>(n,-1));
  function<void(ll,ll,ll)>dfs=[&](ll l,ll r,ll id){
    if(r-l==1)return;

    repi(i,l,r)repi(j,l,r){
      ed[i][j]=id;
    }
    ll m=(l+r)/2;
    dfs(l,m,id+1);
    dfs(m,r,id+1);
  };
  dfs(0,n,1);
  rep(i,n){
    repi(j,i+1,n){
      cout<<ed[i][j]<<" ";
    }
    cout<<endl;
  }

  return 0;

}


Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int A, B, C;
	cin >> A >> B >> C;
	set<int>st;
	st.insert(A);
	st.insert(B);
	st.insert(C);
	if (st.size() == 2)puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  int s = digsum(n);
  if(n % s == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int N=100+10;
char s[N];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int ans=0;
	for(int i=1;i<n+1-i;++i)
		ans+=(s[i]!=s[n+1-i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	s := io.Next()
	for i := range s {
		if s[i] == '7' {
			io.Println("Yes")
			return
		}
	}
	io.Println("No")
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAXN = 2505;

struct Edge {
  int f, t;
  ll c;
};

int n, m;

vector<Edge> E;
vector<int> G[MAXN];

vector<ll> d(MAXN, INF);
bool reach[MAXN];

void dfs(int u) {
  if (reach[u]) return;
  reach[u] = true;
  for (int v: G[u]) {
    dfs(v);
  }
}

void BellmanFord() {
  rep(i, 2 * n) {
    bool flag = false;
    rep(j, m) {
      Edge e = E[j];
      if (reach[e.f] && d[e.f] + e.c < d[e.t]) {
        flag = true;
        if (i < n) d[e.t] = d[e.f] + e.c;
        else d[e.t] = -INF;
      }
    }
    if (!flag) return;
  }
}

int main() {
  ll p;
  cin >> n >> m >> p;
  Edge e;
  rep(i, m) {
    cin >> e.f >> e.t >> e.c;
    e.f--;
    e.t--;
    e.c = p - e.c;
    E.push_back(e);
    G[e.f].push_back(e.t);
  }

  dfs(0);

  d[0] = 0;
  BellmanFord();

  cout << (d[n - 1] == -INF || d[n - 1] == INF ? -1 : max((ll)0, -d[n - 1]));




  
  return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {

    val (A, B, K) = readLine()!!.split(" ").map { it.toLong() }
    if (K > A + B) {
        println("0 0")
        return
    }

    if (K < A) {
        println("${A - K} $B")
        return
    }

    println("0 ${A + B - K}")
}


Measured memory_bytes: 37912
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        n = IO_for_Contest.read_int()
        k = IO_for_Contest.read_int()
        x = IO_for_Contest.read_int()
        y = IO_for_Contest.read_int()
        return n, k, x, y

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    buf = IO_for_Contest.read_from_input()
    n = buf[0]
    k = buf[1]
    x = buf[2]
    y = buf[3]
    if n <= k:
        print(x * n)
    else:
        rem = n - k
        print(x * k + y * rem)


if __name__ == '__main__':
    # doctest.testmod()
    solve()

Measured memory_bytes: 8296
#include <stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  int a[N];
  for(int i = 0; i < N; i++){
    scanf("%d", &a[i]);
  }
  
  int ans = 10000000, cand, tmp;
  //printf("%d\n", ans);
  for(int i = -100; i < 101; i++){
    cand = 0;
    for(int j = 0; j < N; j++){
      tmp = a[j] - i;
      //printf("%d\n", tmp);
      cand += (tmp*tmp);
      //printf("%d\n", cand);
    }
    if(ans > cand) ans = cand;
  }
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;

ll a[105];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll mn = 2e9;
    for(int i = 0; i <= 100; i++){
        ll sum = 0;
        for(int j = 0; j < n; j++){
            sum += ((a[j] - i) * (a[j] - i));
        }
        if(sum < mn){
            mn = sum;
        }
    }
    cout << mn;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> W >> H;
    while(H != 0){
        vector<vector<int>> G(H*W);
        for(int i=0; i<H*2-1; i++){
            for(int j=0; j<(i%2 ? W : W-1); j++){
                int a;
                cin >> a;
                if(!a){
                    int h = i/2;
                    if(i%2 == 0){
                        G[h*W+j].push_back(h*W+j+1);
                        G[h*W+j+1].push_back(h*W+j);
                    }else{
                        G[(h+1)*W+j].push_back(h*W+j);
                        G[h*W+j].push_back((h+1)*W+j);
                    }
                }
            }
        }
        vector<int> dist(H*W,-1);
        dist[0] = 1;
        queue<int> que;
        que.push(0);
        while(que.size()){
            int v = que.front();
            que.pop();
            for(int nv: G[v]){
                if(dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        // for(int i=0; i<H; i++){
        //     for(int j=0; j<W; j++){
        //         cout << dist[i*H+j] << " ";
        //     }
        //     cout << enld;
        // }
        // for(int i=0; i<W*H; i++){
        //     cout << i << " check: ";
        //     for(int j=0; j<G[i].size(); j++){
        //         cout << G[i][j] << " ";
        //     }
        //     cout << enld;
        // }
        if(dist[H*W-1] != -1){
            cout << dist[H*W-1] << enld;
        }else{
            cout << 0 << enld;
        }
        cin >> W >> H;
    }
    return 0;
}


Measured memory_bytes: 3132